Datasets:
AI4M
/

text
stringlengths
0
3.34M
(* Title: HOL/Auth/n_german_lemma_inv__43_on_rules.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_german Protocol Case Study*} theory n_german_lemma_inv__43_on_rules imports n_german_lemma_on_inv__43 begin section{*All lemmas on causal relation between inv__43*} lemma lemma_inv__43_on_rules: assumes b1: "r \<in> rules N" and b2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__43 p__Inv2)" shows "invHoldForRule s f r (invariants N)" proof - have c1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_SendGntE N i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntS i)\<or> (\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" apply (cut_tac b1, auto) done moreover { assume d1: "(\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_StoreVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqSVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__0Vsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendReqE__part__1Vsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqS N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqSVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvReqE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvReqEVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__0Vsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInv__part__1Vsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendInvAckVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvInvAckVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntSVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_SendGntEVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntSVsinv__43) done } moreover { assume d1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" have "invHoldForRule s f r (invariants N)" apply (cut_tac b2 d1, metis n_RecvGntEVsinv__43) done } ultimately show "invHoldForRule s f r (invariants N)" by satx qed end
#' Fitting Weibull-log-normal model to wave data #' #' @description #' This function fits a Weibull-log-normal (\code{wln}) model to the given wave data, such that the wave height #' \code{hs} follows a translated (or 3-parameter) Weibull distribution, and the wave period given the wave #' follows a conditional log-normal distributuion with the location and scale parameters as functions #' of the corresponding \code{hs} value. #' #' @param data the wave data in the form a \code{data.table} with wave height \code{hs} and wave period #' \code{tp} as columns. #' #' @param npy the number of data points per year, usually estimated by the number of rows in the #' supplied wave data divided by the total period of data coverage (in years). #' #' @param weibull_method the method for fitting the Weibull distribution to the \code{hs} column in the wave data. Choose #' between \code{"lmom"} for L-moment or \code{"mle"} for maximum likelihood estimator. The default option #' is \code{"lmom"}. #' #' @details #' The input \code{data} must be a \code{data.table} object with \code{hs} and \code{tp} columns. This can be #' generated by reading a CSV file using function \code{\link[data.table]{fread}}. #' #' The formulation of the conditional distribution is given by #' \deqn{log(tp | hs=h) ~ N(\mu(h), \sigma(h)^2)} #' where the mean and the standard deviation are #' \deqn{\mu(h) = a_0 + a_1 h^a_2 and \sigma(h) = b_0 + b_1 exp(h * b_2)} #' #' A two-step regression-based estimation method is used for fitting the conditional distribution of #' \code{tp} given \code{hs}. The conditonal means and standard deviations are #' estimated over fixed-width bands of \code{hs} in the first step, and regressed onto the above #' functions of \code{hs} in the second step. #' #' @return A joint distribution object of class \code{wln} containing the key information of a fitted #' Weibull-log-normal model, including the three parameters of the Weibull distribution for \code{hs} (as a named #' numeric vector) and the six parameters of the conditional log-normal distribution for \code{tp} given \code{hs} #' (as an unamed numeric vector, in the order of \eqn{{a_0, a_1, a_2, b_0, b_1, b_2}}). #' #' It is possible to replace one or multiple \code{hs} or \code{tp} parameters in an existing \code{wln} object #' (see the examples provided below). The current version of the package does not automatically check the #' validity of these user-input parameters. Therefore users are advised to perform the check independently. #' #' @examples #' # Load data #' data(ww3_pk) #' #' # Fit Weibull-log-normal distribution #' wln1 = fit_wln(data = ww3_pk, npy = nrow(ww3_pk)/10, weibull_method = "mle") #' #' # Fit Weibull-log-normal distribution using the alternative method #' wln2 = fit_wln(data = ww3_pk, npy = nrow(ww3_pk)/10, weibull_method = "lmom") #' #' # Update the hs parameters for object wln1 #' wln3 = copy(wln1) #' wln3$hs$par[["loc"]] = 0.66 #' wln3$hs$par[["scale"]] = 2.2 #' wln3$hs$par[["shape"]] = 1.8 #' #' @references #' Haver, Sverre & Winterstein, Steven. (2009). Environmental Contour Lines: A Method for Estimating Long #' Term Extremes by a Short Term Analysis. Transactions - Society of Naval Architects and Marine Engineers. 116. #' #' @seealso \code{\link{fit_ht}}, \code{\link{sample_jdistr}} #' #' @export fit_wln = function(data, npy, weibull_method="lmom"){ res = list() class(res) = "wln" res$npy = npy res$hs = .fit_weibull(data = data$hs, weibull_method = weibull_method) res$tp = .fit_iform_lnorm(hs = data$hs, tp = data$tp) return(res) } # Conditional log-normal used for IFROM ----------------------------------- .fit_iform_lnorm = function(hs, tp){ input_data = data.table(hs, tp)[sort.list(-hs)] mod_data = input_data[, .(log_mean=mean(log(tp)), log_sd=sd(log(tp))), .(hs=round(hs/.hs_res)*.hs_res)] mod_mean = nls( formula = log_mean~.cond_norm_mean(hs, a0, a1, a2), data = mod_data, start = list(a0=1, a1=1, a2=.1), algorithm = "port", control = list(maxiter = 1e3, warnOnly=T)) mod_sd = nls( formula = log_sd~.cond_norm_sd(hs, b0, b1, b2), data = mod_data, lower = c(0, 0, -Inf), start = list(b0=0.25, b1=0.1, b2=-0.1), algorithm = "port", control = list(maxiter = 1e3, warnOnly=T)) res = list(par = c(coef(mod_mean), coef(mod_sd))) class(res) = "iform_lnorm" return(res) } .cond_norm_mean = function(hs, a0, a1, a2){ a0+a1*hs^a2 } .cond_norm_sd = function(hs, b0, b1, b2){ b0+b1*exp(b2*hs) } # Weibull fit ---------------------------------------------------- .fit_weibull = function(data, weibull_method){ res = list() if(weibull_method=="lmom"){ out = as.numeric(lmom::pelwei(lmom::samlmu(data))) res$par = c(loc=out[1], scale=out[2], shape=out[3]) res$conv = NA }else if(weibull_method=="mle"){ theta0 = c(min(data-min(data))/2, sd(data), 1) op = nlminb( start = theta0, objective = .nll_weibull3, data = data, lower = c(.limit_zero, .limit_zero, .limit_zero), upper = c(min(data)-.limit_zero, .limit_inf, .limit_inf)) res$par = c(loc=op$par[1], scale=op$par[2], shape=op$par[3]) res$conv = op$convergence }else{ stop("Only \"lmom\" and \"mle\" are supported.") } class(res) = "weibull" return(res) } .nll_weibull3 = function(theta, data) { if(theta[1]>=min(data) || theta[2]<=0 || theta[3]<=0){ res = .limit_inf }else{ nll = dweibull(data-theta[1], scale=theta[2], shape=theta[3], log = TRUE) res = -sum(nll) } return(res) }
[STATEMENT] lemma spair_sigs_alt_spp: "spair_sigs p q = spair_sigs_spp (spp_of p) (spp_of q)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. spair_sigs p q = spair_sigs_spp (spp_of p) (spp_of q) [PROOF STEP] by (simp add: spair_sigs_def spair_sigs_spp_def Let_def fst_spp_of snd_spp_of)
function v = s2v(s,a) % s2v - structure array to vector % % v = s2v(s,a); % % v(i) = getfield(s(i), a); % % Copyright (c) 2010 Gabriel Peyre v = zeros(length(s),1); for i=1:length(s) v(i) = getfield(s(i), a); end
State Before: R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ ↑(convexHull R).toOrderHom s = ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t State After: case refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ ↑(convexHull R).toOrderHom s ⊆ ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t case refine'_2 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ (⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t) ⊆ ↑(convexHull R).toOrderHom s Tactic: refine' Subset.antisymm _ _ State Before: case refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ ↑(convexHull R).toOrderHom s ⊆ ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t State After: case refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ {x | ∃ ι t w z x_1 x_2 x_3, centerMass t w z = x} ⊆ ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t Tactic: rw [_root_.convexHull_eq] State Before: case refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ {x | ∃ ι t w z x_1 x_2 x_3, centerMass t w z = x} ⊆ ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t State After: case refine'_1.intro.intro.intro.intro.intro.intro.intro R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ centerMass t w z ∈ ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t Tactic: rintro x ⟨ι : Type u_1, t, w, z, hw₀, hw₁, hz, rfl⟩ State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ centerMass t w z ∈ ⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t State After: case refine'_1.intro.intro.intro.intro.intro.intro.intro R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ∃ i i_1, centerMass t w z ∈ ↑(convexHull R).toOrderHom ↑i Tactic: simp only [mem_iUnion] State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ∃ i i_1, centerMass t w z ∈ ↑(convexHull R).toOrderHom ↑i State After: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ↑(Finset.image z t) ⊆ s case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_2 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ centerMass t w z ∈ ↑(convexHull R).toOrderHom ↑(Finset.image z t) Tactic: refine' ⟨t.image z, _, _⟩ State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ↑(Finset.image z t) ⊆ s State After: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ↑t ⊆ z ⁻¹' s Tactic: rw [coe_image, Set.image_subset_iff] State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_1 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ↑t ⊆ z ⁻¹' s State After: no goals Tactic: exact hz State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_2 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ centerMass t w z ∈ ↑(convexHull R).toOrderHom ↑(Finset.image z t) State After: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_2.hws R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ 0 < ∑ i in t, w i case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_2.hz R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ∀ (i : ι), i ∈ t → z i ∈ ↑(Finset.image z t) Tactic: apply t.centerMass_mem_convexHull hw₀ State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_2.hws R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ 0 < ∑ i in t, w i State After: no goals Tactic: simp only [hw₁, zero_lt_one] State Before: case refine'_1.intro.intro.intro.intro.intro.intro.intro.refine'_2.hz R : Type u_2 E : Type u_1 F : Type ?u.239379 ι✝ : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι✝ c : R t✝ : Finset ι✝ w✝ : ι✝ → R z✝ : ι✝ → E s : Set E ι : Type u_1 t : Finset ι w : ι → R z : ι → E hw₀ : ∀ (i : ι), i ∈ t → 0 ≤ w i hw₁ : ∑ i in t, w i = 1 hz : ∀ (i : ι), i ∈ t → z i ∈ s ⊢ ∀ (i : ι), i ∈ t → z i ∈ ↑(Finset.image z t) State After: no goals Tactic: exact fun i hi => Finset.mem_coe.2 (Finset.mem_image_of_mem _ hi) State Before: case refine'_2 R : Type u_2 E : Type u_1 F : Type ?u.239379 ι : Type ?u.239382 ι' : Type ?u.239385 α : Type ?u.239388 inst✝⁷ : LinearOrderedField R inst✝⁶ : AddCommGroup E inst✝⁵ : AddCommGroup F inst✝⁴ : LinearOrderedAddCommGroup α inst✝³ : Module R E inst✝² : Module R F inst✝¹ : Module R α inst✝ : OrderedSMul R α s✝ : Set E i j : ι c : R t : Finset ι w : ι → R z : ι → E s : Set E ⊢ (⋃ (t : Finset E) (_ : ↑t ⊆ s), ↑(convexHull R).toOrderHom ↑t) ⊆ ↑(convexHull R).toOrderHom s State After: no goals Tactic: exact iUnion_subset fun i => iUnion_subset convexHull_mono
(** * Matrices Operations on vectors and matrices. Author: Langston Barrett (@siddharthist) (March 2018) *) Require Import UniMath.Foundations.PartA. Require Import UniMath.MoreFoundations.PartA. Require Import UniMath.Combinatorics.FiniteSequences. Require Import UniMath.Algebra.BinaryOperations. Require Import UniMath.Algebra.IteratedBinaryOperations. Require Import UniMath.Algebra.RigsAndRings. (** ** Contents - Vectors - Standard conditions on one binary operation - Standard conditions on a pair of binary operations - Structures - Matrices - Standard conditions on one binary operation - Structures - Matrix rig *) (** ** Vectors *) Definition pointwise {X : UU} (n : nat) (op : binop X) : binop (Vector X n) := λ v1 v2 i, op (v1 i) (v2 i). (** *** Standard conditions on one binary operation *) (** Most features of binary operations (associativity, unity, etc) carry over to pointwise operations. *) Section OneOp. Context {X : UU} {n : nat} {op : binop X}. Definition pointwise_assoc (assocax : isassoc op) : isassoc (pointwise n op). Proof. intros ? ? ?; apply funextfun; intro; apply assocax. Defined. Definition pointwise_lunit (lun : X) (lunax : islunit op lun) : islunit (pointwise n op) (const_vec lun). Proof. intros ?; apply funextfun; intro; apply lunax. Defined. Definition pointwise_runit (run : X) (runax : isrunit op run) : isrunit (pointwise n op) (const_vec run). Proof. intros ?; apply funextfun; intro; apply runax. Defined. Definition pointwise_unit (un : X) (unax : isunit op un) : isunit (pointwise n op) (const_vec un). Proof. use make_isunit. - apply pointwise_lunit; exact (pr1 unax). - apply pointwise_runit; exact (pr2 unax). Defined. Definition pointwise_comm (commax : iscomm op) : iscomm (pointwise n op). Proof. intros ? ?; apply funextfun; intro; apply commax. Defined. Definition pointwise_monoidop (monoidax : ismonoidop op) : ismonoidop (pointwise n op). Proof. use make_ismonoidop. - apply pointwise_assoc, assocax_is; assumption. - use make_isunital. + apply (const_vec (unel_is monoidax)). + apply pointwise_unit, unax_is. Defined. Definition pointwise_abmonoidop (abmonoidax : isabmonoidop op) : isabmonoidop (pointwise n op). Proof. use make_isabmonoidop. - apply pointwise_monoidop; exact (pr1isabmonoidop _ _ abmonoidax). - apply pointwise_comm; exact (pr2 abmonoidax). Defined. End OneOp. (** *** Standard conditions on a pair of binary operations *) Section TwoOps. Context {X : UU} {n : nat} {op : binop X} {op' : binop X}. Definition pointwise_ldistr (isldistrax : isldistr op op') : isldistr (pointwise n op) (pointwise n op'). Proof. intros ? ? ?; apply funextfun; intro; apply isldistrax. Defined. Definition pointwise_rdistr (isrdistrax : isrdistr op op') : isrdistr (pointwise n op) (pointwise n op'). Proof. intros ? ? ?; apply funextfun; intro; apply isrdistrax. Defined. Definition pointwise_distr (isdistrax : isdistr op op') : isdistr (pointwise n op) (pointwise n op'). Proof. use make_dirprod. - apply pointwise_ldistr; apply (dirprod_pr1 isdistrax). - apply pointwise_rdistr; apply (dirprod_pr2 isdistrax). Defined. End TwoOps. (** *** Structures *) Section Structures. Definition pointwise_hSet (X : hSet) (n : nat) : hSet. Proof. use make_hSet. - exact (Vector X n). - change isaset with (isofhlevel 2). apply vector_hlevel, setproperty. Defined. Definition pointwise_setwithbinop (X : setwithbinop) (n : nat) : setwithbinop. Proof. use make_setwithbinop. - apply pointwise_hSet; [exact X|assumption]. - exact (pointwise n op). Defined. Definition pointwise_setwith2binop (X : setwith2binop) (n : nat) : setwith2binop. Proof. use make_setwith2binop. - apply pointwise_hSet; [exact X|assumption]. - split. + exact (pointwise n op1). + exact (pointwise n op2). Defined. Definition pointwise_monoid (X : monoid) (n : nat) : monoid. Proof. use make_monoid. - apply pointwise_setwithbinop; [exact X|assumption]. - apply pointwise_monoidop; exact (pr2 X). Defined. Definition pointwise_abmonoid (X : abmonoid) (n : nat) : abmonoid. Proof. use make_abmonoid. - apply pointwise_setwithbinop; [exact X|assumption]. - apply pointwise_abmonoidop; exact (pr2 X). Defined. End Structures. (** ** Matrices *) Definition entrywise {X : UU} (n m : nat) (op : binop X) : binop (Matrix X n m) := λ mat1 mat2 i, pointwise _ op (mat1 i) (mat2 i). (** *** Standard conditions on one binary operation *) Section OneOpMat. Context {X : UU} {n m : nat} {op : binop X}. Definition entrywise_assoc (assocax : isassoc op) : isassoc (entrywise n m op). Proof. intros ? ? ?; apply funextfun; intro; apply pointwise_assoc, assocax. Defined. Definition entrywise_lunit (lun : X) (lunax : islunit op lun) : islunit (entrywise n m op) (const_matrix lun). Proof. intros ?; apply funextfun; intro; apply pointwise_lunit, lunax. Defined. Definition entrywise_runit (run : X) (runax : isrunit op run) : isrunit (entrywise n m op) (const_matrix run). Proof. intros ?; apply funextfun; intro; apply pointwise_runit, runax. Defined. Definition entrywise_unit (un : X) (unax : isunit op un) : isunit (entrywise n m op) (const_matrix un). Proof. use make_isunit. - apply entrywise_lunit; exact (pr1 unax). - apply entrywise_runit; exact (pr2 unax). Defined. Definition entrywise_comm (commax : iscomm op) : iscomm (entrywise n m op). Proof. intros ? ?; apply funextfun; intro; apply pointwise_comm, commax. Defined. Definition entrywise_monoidop (monoidax : ismonoidop op) : ismonoidop (entrywise n m op). Proof. use make_ismonoidop. - apply entrywise_assoc, assocax_is; assumption. - use make_isunital. + apply (const_matrix (unel_is monoidax)). + apply entrywise_unit, unax_is. Defined. Definition entrywise_abmonoidop (abmonoidax : isabmonoidop op) : isabmonoidop (entrywise n m op). Proof. use make_isabmonoidop. - apply entrywise_monoidop; exact (pr1isabmonoidop _ _ abmonoidax). - apply entrywise_comm; exact (pr2 abmonoidax). Defined. End OneOpMat. (** It is uncommon to consider two entrywise binary operations on matrices, so we don't derive "standard conditions on a pair of binar operations" for matrices. *) (** *** Structures *) (** *** Matrix rig *) Section MatrixMult. Context {R : rig}. (** Summation and pointwise multiplication *) Local Notation Σ := (iterop_fun rigunel1 op1). Local Notation "R1 ^ R2" := ((pointwise _ op2) R1 R2). (** If A is m × n (so B is n × p), << AB(i, j) = A(i, 1) * B(1, j) + A(i, 2) * B(2, j) + ⋯ + A(i, n) * B(n, j) >> The order of the arguments allows currying the first matrix. *) Definition matrix_mult {m n : nat} (mat1 : Matrix R m n) {p : nat} (mat2 : Matrix R n p) : (Matrix R m p) := λ i j, Σ ((row mat1 i) ^ (col mat2 j)). Local Notation "A ** B" := (matrix_mult A B) (at level 80). Lemma identity_matrix {n : nat} : (Matrix R n n). Proof. intros i j. induction (stn_eq_or_neq i j). - exact (rigunel2). (* The multiplicative identity *) - exact (rigunel1). (* The additive identity *) Defined. End MatrixMult. Local Notation Σ := (iterop_fun rigunel1 op1). Local Notation "R1 ^ R2" := ((pointwise _ op2) R1 R2). Local Notation "A ** B" := (matrix_mult A B) (at level 80). (** The following is based on "The magnitude of metric spaces" by Tom Leinster (arXiv:1012.5857v3). *) Section Weighting. Context {R : rig}. (** Definition 1.1.1 in arXiv:1012.5857v3 *) Definition weighting {m n : nat} (mat : Matrix R m n) : UU := ∑ vec : Vector R n, (mat ** (col_vec vec)) = col_vec (const_vec (1%rig)). Definition coweighting {m n : nat} (mat : Matrix R m n) : UU := ∑ vec : Vector R m, ((row_vec vec) ** mat) = row_vec (const_vec (1%rig)). Lemma matrix_mult_vectors {n : nat} (vec1 vec2 : Vector R n) : ((row_vec vec1) ** (col_vec vec2)) = weq_matrix_1_1 (Σ (vec1 ^ vec2)). Proof. apply funextfun; intro i; apply funextfun; intro j; reflexivity. Defined. (** Multiplying a column vector by the identity row vector is the same as taking the sum of its entries. *) Local Lemma sum_entries1 {n : nat} (vec : Vector R n) : weq_matrix_1_1 (Σ vec) = ((row_vec (const_vec (1%rig))) ** (col_vec vec)). Proof. refine (_ @ !matrix_mult_vectors _ _). do 2 apply maponpaths. apply pathsinv0. refine (pointwise_lunit 1%rig _ vec). apply riglunax2. Defined. Local Lemma sum_entries2 {n : nat} (vec : Vector R n) : weq_matrix_1_1 (Σ vec) = (row_vec vec ** col_vec (const_vec 1%rig)). Proof. refine (_ @ !matrix_mult_vectors _ _). do 2 apply maponpaths. apply pathsinv0. refine (pointwise_runit 1%rig _ vec). apply rigrunax2. Defined. (** TODO: prove this so that the below isn't hypothetical *) Definition matrix_mult_assoc_statement : UU := ∏ (m n : nat) (mat1 : Matrix R m n) (p : nat) (mat2 : Matrix R n p) (q : nat) (mat3 : Matrix R p q), ((mat1 ** mat2) ** mat3) = (mat1 ** (mat2 ** mat3)). (** Lemma 1.1.2 in arXiv:1012.5857v3 *) Lemma weighting_coweighting_sum {m n : nat} (mat : Matrix R m n) (wei : weighting mat) (cowei : coweighting mat) (assocax : matrix_mult_assoc_statement) : Σ (pr1 wei) = Σ (pr1 cowei). Proof. apply (invmaponpathsweq weq_matrix_1_1). intermediate_path ((row_vec (const_vec (1%rig))) ** (col_vec (pr1 wei))). - apply sum_entries1. - refine (!maponpaths (λ z, z ** _) (pr2 cowei) @ _). refine (assocax _ _ _ _ _ _ _ @ _). refine (maponpaths (λ z, _ ** z) (pr2 wei) @ _). apply pathsinv0, sum_entries2 . Defined. (** Definition 1.1.3 in arXiv:1012.5857v3 *) Definition has_magnitude {n m : nat} (mat : Matrix R m n) : UU := (weighting mat) × (coweighting mat). Definition magnitude {n m : nat} (m : Matrix R m n) (has : has_magnitude m) : R := Σ (pr1 (dirprod_pr1 has)). End Weighting.
import data.fintype.basic import data.finset import tactic import finset_extra noncomputable theory open_locale classical open set universes u v def size {γ : Type u} (X: set γ) := (sorry : ℤ) -- need to fix this to actually be the size lemma finsize {γ : Type u} {hfin: fintype γ} (X: set γ) : size X = (fintype.card ↥X : ℤ) := sorry structure matroid_on (γ : Type u)[fintype γ] := (r : set γ → ℤ) (R1l : ∀ (X : set γ), 0 ≤ r X) (R1u : ∀ (X: set γ), r X ≤ size X) (R2 : ∀ {X Y : set γ}, X ⊆ Y → r X ≤ r Y) (R3 : ∀ (X Y : set γ), r (X ∪ Y) + r (X ∩ Y) ≤ r X + r Y) class matroids (α : Type v) := (type_map : α → Σ (γ : Type u), fintype γ) (to_matroid : Π (M : α), @matroid_on (type_map M).1 (type_map M).2) -- M is the name of the matroid and has type α. -- (γ M) is the 'ground type' of the matroid M; --the function to_matroid maps the name M to the structure of -- matroid M (i.e. a rank function and proofs of axioms). instance matroid_on.matroids (γ : Type u)[h: fintype γ] : matroids (matroid_on γ) := { type_map := λ (M: matroid_on γ), ⟨γ, h⟩, to_matroid := id } namespace matroid local attribute [simp] image_union image_inter variables {α : Type v} [matroids α] -- Accessor functions for terms that have a matroid representation def γ (M : α) := (matroids.type_map M).1 -- matroid elements have type γ def E (M: α) : (set (γ M)) := set.univ -- E is the ground set viewed as a set, not a type. def r (M : α) (X : set (γ M) ) : ℤ := (matroids.to_matroid M).r X def R1l (M : α) (X : set (γ M)) : 0 ≤ r M X := (matroids.to_matroid M).R1l X def R1u (M: α) (X: set (γ M)) : r M X ≤ size X := (matroids.to_matroid M).R1u X def R2 (M : α) {X Y : set (γ M)} (h : X ⊆ Y) : r M X ≤ r M Y := (matroids.to_matroid M).R2 h def R3 (M : α) (X Y : set (γ M)) : r M (X ∪ Y) + r M (X ∩ Y) ≤ r M X + r M Y := (matroids.to_matroid M).R3 X Y @[simp] lemma r_empty_eq_zero (M : α) : r M (∅ : set (γ M)) = 0 := begin have := R1u M ∅, have := R1l M ∅, have := finsize (∅ : set (γ M)), sorry, --simp only [card_empty, int.coe_nat_zero] at this, --linarith, end --by { have h := R1 M ∅, rwa [card_empty, le_zero_iff_eq] at h } lemma rank_subadditive (M : α) (X Y : set (γ M)) : r M (X ∪ Y) ≤ r M X + r M Y := by linarith [R3 M X Y, (R1 M (X ∩ Y)).1] lemma r_le_union (M : α) (X Y : set (γ M)) : r M X ≤ r M (X ∪ Y) := by { apply R2 M, apply subset_union_left } lemma r_le_union_right (M : α) (X Y : set (γ M)) : r M Y ≤ r M (X ∪ Y) := by { rw union_comm, apply r_le_union } instance coe_subtype_set {α : Type*} {Y: set α} : has_coe (set Y) (set α) := ⟨λ X, X.image subtype.val⟩ @[simp] lemma coe_subtype_size {α : Type*} {Y: set α} (X: set Y) : size X = size (X: set α) := sorry @[simp] lemma coe_subtype_union {α: Type*} {Y: set α} (X₁ X₂ : set Y) : (((X₁ ∪ X₂ : set Y)) :set α ) = X₁ ∪ X₂ := by apply image_union @[simp] lemma coe_subtype_inter {α: Type*} {Y: set α} (X₁ X₂ : set Y) : (((X₁ ∩ X₂ : set Y)) :set α) = X₁ ∩ X₂ := begin sorry, end structure submatroid (M : α) := (F : set (γ M)) --set_option pp.beta true --set_option pp.universes true instance submatroid.matroid (M : α) : matroids (submatroid M) := { γ := λ (M' : submatroid M), ↥(M'.F), to_matroid := λ (M' : submatroid M), { r := λ X, r M X, R1 := λ X, begin split, apply (R1 M X).1, simp only [coe_subtype_size], exact (R1 M X).2, end, R2 := λ X₁ X₂ h, R2 M (image_subset _ h), R3 := λ X₁ X₂, begin convert (R3 M X₁ X₂), simp, simp, end, }} def delete (M : α) (F : set (γ M)) : submatroid M := submatroid.mk F structure matroid_contraction (M : α) := (C : set (γ M)) --def contract (M : α) (C : set (γ M)) : matroid_contraction M := --matroid_contraction.mk C instance matroid_contraction.matroid (M : α) : matroids (matroid_contraction M) := { γ := λ M', ↥((M'.C : set (γ M))ᶜ), to_matroid := λ M', { r := λ X, r M (X ∪ M'.C) - r M M'.C, R1 := λ X, begin split, linarith [R2 M (subset_union_right ↑X M'.C)], have h1 := rank_subadditive M X M'.C, have := (R1 M X).2, rw coe_subtype_size X, --unfold size, linarith, end, R2 := λ X, begin intros Y hXY, have hXYC: (X ∪ M'.C: set (γ M)) ⊆ (Y ∪ M'.C: set (γ M)), { apply union_subset_union_left, apply image_subset, exact hXY, }, linarith [R2 M hXYC], end, R3 := begin intros X Y, --rw ← coe_subtype_union, suffices : r M (↑(X ∪ Y) ∪ M'.C) + r M (↑(X ∩ Y) ∪ M'.C) ≤ r M (↑X ∪ M'.C) + r M (↑Y ∪ M'.C), by linarith, --calc r M (↑(X ∪ Y) ∪ M'.C) - r M M'.C + (r M (↑(X ∩ Y) ∪ M'.C) - r M M'.C) ≤ r M (↑(X ∪ Y) ∪ M'.C) + (r M (↑(X ∩ Y) ∪ M'.C) - 2*(r M M'.C) : by linarith --... = r M (↑X ∪ M'.C) - r M M'.C + (r M (↑Y ∪ M'.C) - r M M'.C) : sorry, --... = --sorry, --exact this, --{linarith,}, --rw @image_union (finset (↑(M'.C))ᶜ) () _ _ _ X Y , --sorry, /-intros X Y, let X' := X.image subtype.val, let Y' := Y.image subtype.val, rw [image_union, image_inter], have := R3 M (X' ∪ M'.C) (Y' ∪ M'.C), simp only [@union_unions _ _ X' Y' _, inter_unions] at this, linarith, intros x y, exact subtype.eq,-/ end, } } def dual (M : α) [fintype (γ M)] : matroid_on (γ M) := { r := λ X, size X - r M (E M) + r M (Xᶜ), R1 := begin sorry, /-intros X, split, have h1 : r X ≤ size X := (R1 M X).2, have h2 := rank_subadditive M X (Xᶜ), have h3 := lambda_conn_nonegative M X, --unfold lambda_conn at h3, calc size X - r (E M) + r Xᶜ = size X - r X + (r X + r Xᶜ - r (E M)) : by linarith ... ≥ size X - r X : by linarith [lambda_conn_nonegative M X] ... ≥ 0 : by linarith [(R1 M X).2], linarith[ R2 M ((by simp) :(Xᶜ ⊆ E M))], -/ end, R2 := sorry, R3 := sorry } end matroid
-- {-# OPTIONS --without-K #-} module F2a where open import Agda.Prim open import Data.Unit open import Data.Nat hiding (_⊔_) open import Data.Sum open import Data.Product open import Function open import Relation.Binary.PropositionalEquality open import Paths open import Evaluator ------------------------------------------------------------------------------ -- -- General structure and idea -- -- We have pointed types (Paths.agda) -- We have paths between pointed types (Paths.agda) -- We have functions between pointed types (that use ≡ to make sure the -- basepoint is respected) (F2a.agda) -- Then we use univalence to connect these two independently developed -- notions (F2a.agda) -- Because our paths are richer than just refl and our functions are -- more restricted than arbitrary functions, and in fact because our -- path constructors are sound and complete for the class of functions -- we consider, we hope to _prove_ univalence -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- Equivalences between raw functions and types -- This is generalized below to pointed types -- Two functions are ∼ is they map each argument to related results _∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} → (f g : (x : A) → P x) → Set (ℓ ⊔ ℓ') _∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x -- quasi-inverses record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkqinv field g : B → A α : (f ∘ g) ∼ id β : (g ∘ f) ∼ id idqinv : ∀ {ℓ} → {A : Set ℓ} → qinv {ℓ} {ℓ} {A} {A} id idqinv = record { g = id ; α = λ b → refl ; β = λ a → refl } -- equivalences record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkisequiv field g : B → A α : (f ∘ g) ∼ id h : B → A β : (h ∘ f) ∼ id equiv₁ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f equiv₁ (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ _≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ') A ≃ B = Σ (A → B) isequiv idequiv : ∀ {ℓ} {A : Set ℓ} → A ≃ A idequiv = (id , equiv₁ idqinv) -- Function extensionality {-- happly : ∀ {ℓ} {A B : Set ℓ} {f g : A → B} → (Path f g) → (f ∼ g) happly {ℓ} {A} {B} {f} {g} p = (pathInd (λ _ → f ∼ g) -- f ∼ g (λ {AA} a x → {!!}) {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} (λ a b x → {!cong (evalB p) (eval-resp-• (p))!}) {!!} {!!} {!!} {!!} {!!} {!!} (λ a x → {!!}) (λ p₁ q x x₁ x₂ → x x₂) (λ p₁ q x x₁ x₂ → x x₂) (λ p₁ q x x₁ x₂ → x x₂) (λ p₁ q x x₁ x₂ → x₁ x₂)) {A → B} {A → B} {f} {g} p postulate funextP : {A B : Set} {f g : A → B} → isequiv {A = Path f g} {B = f ∼ g} happly funext : {A B : Set} {f g : A → B} → (f ∼ g) → (Path f g) funext = isequiv.g funextP -- Universes; univalence idtoeqv : {A B : Set} → (Path A B) → (A ≃ B) idtoeqv {A} {B} p = {!!} {-- (pathInd (λ {S₁} {S₂} {A} {B} p → {!!}) {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!} {!!}) {Set} {Set} {A} {B} p --} postulate univalence : {ℓ : Level} {A B : Set ℓ} → (Path A B) ≃ (A ≃ B) --} path2fun : {ℓ : Level} {A B : Set ℓ} → (Path A B) → (A ≃ B) path2fun p = ( {!!} , {!!}) ------------------------------------------------------------------------------ -- Functions and equivalences between pointed types -- Univalence as a postulate for now but hopefully we can actually prove it -- since the pi-combinators are sound and complete for isomorphisms between -- finite types --postulate -- univalence• : {ℓ : Level} {A• B• : Set• {ℓ}} → (Path A• B•) ≃• (A• ≃• B•) {-- record isequiv• {ℓ} {A B : Set} {A• B• : Set• {ℓ}} (f• : A• →• B•) : Set (lsuc ℓ) where constructor mkisequiv• field equi : isequiv (fun f•) path' : Path (• A•) (• B•) _≈•_ : ∀ {ℓ} {A B : Set} (A• B• : Set• {ℓ}) → Set (lsuc ℓ) _≈•_ {_} {A} {B} A• B• = Σ (A• →• B•) (isequiv• {_} {A} {B}) --} ------------------------------------------------------------------------------ -- Univalence for pointed types eval• : {ℓ : Level} {A• B• : Set• {ℓ}} → A• ⇛ B• → (A• →• B•) eval• c = record { fun = eval c ; resp• = eval-resp-• c } evalB• : {ℓ : Level} {A• B• : Set• {ℓ}} → A• ⇛ B• → (B• →• A•) evalB• c = record { fun = evalB c ; resp• = evalB-resp-• c } -- This is at the wrong level... We need to define equivalences ≃ between -- pointed sets too... {-- path2iso : {ℓ : Level} {A• B• : Set• {ℓ}} → A• ⇛ B• → ∣ A• ∣ ≃ ∣ B• ∣ path2iso {ℓ} {a} {b} p = (eval p , mkisequiv (evalB p) (λ x → {!!}) (evalB p) (λ x → {!eval∘evalB p!})) --} ------------------------------------------------------------------------------ --}
! Copyright 2021 Matthew Zettergren ! Licensed under the Apache License, Version 2.0 (the "License"); ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! ! http://www.apache.org/licenses/LICENSE-2.0 ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! See the License for the specific language governing permissions and ! limitations under the License. module gemini3d ! top-level module for Gemini3D use, intrinsic :: iso_c_binding, only : c_char, c_null_char, c_int, c_bool use, intrinsic :: iso_fortran_env, only : stderr=>error_unit use gemini_init, only : find_config, check_input_files use gemini_cli, only : cli use config, only : read_configfile use sanity_check, only : check_finite_output use phys_consts, only : lnchem, lwave, lsp, wp, debug use grid, only: grid_size,read_grid,grid_drift, lx1,lx2,lx3,lx2all,lx3all use meshobj, only: curvmesh use config, only : gemini_cfg use io, only : input_plasma,create_outdir,output_plasma,create_outdir_aur,output_aur,find_milestone use pathlib, only : expanduser use mpimod, only : mpisetup, mpibreakdown, mpi_manualgrid, process_grid_auto, mpi_cfg use multifluid, only : fluid_adv use msis_interface, only : msisinit use neutral, only : neutral_atmos,make_dneu,neutral_perturb,clear_dneu,init_neutrals, neutral_winds use potentialBCs_mumps, only: clear_potential_fileinput, init_Efieldinput use potential_comm,only : electrodynamics,pot2perpfield,velocities, get_BGEfields use collisions, only: conductivities use precipBCs_mod, only: clear_precip_fileinput, init_precipinput use temporal, only : dt_comm use timeutils, only: dateinc, find_lastdate implicit none (type, external) contains subroutine gemini_main(out_dir, Lout_dir, lid2in, lid3in, use_cli) bind(C, name="gemini_main") !! NOTE: if use_cli=.true., then {out_dir, lid2in, lid3in} are ignored and CLI is used instead. !! !! the 'name="gemini_main"' is implicit, but put explicitly here for clarity and !! for if someone wanted to change the name C/C++ sees. character(kind=c_char), intent(in) :: out_dir(Lout_dir) integer(c_int), intent(in) :: Lout_dir !! output directory for Gemini3D to write simulation data to (can be large files GB, TB, ...) integer(c_int), intent(inout) :: lid2in, lid3in !< inout to allow optional CLI !! FOR HANDLING OUTPUT logical(c_bool), intent(in) :: use_cli integer :: ierr logical :: exists !> VARIABLES READ IN FROM CONFIG FILE real(wp) :: UTsec !! UT (s) integer, dimension(3) :: ymd !! year, month, day (current, not to be confused with starting year month and day in gemini_cfg structure) type(gemini_cfg) :: cfg !! holds many user simulation parameters !> grid type (polymorphic) containing geometric information and associate procedures class(curvmesh), allocatable :: x !> STATE VARIABLES !> MZ note: it is likely that there could be a plasma and neutral derived type containing these data... May be worth considering in a refactor... real(wp), dimension(:,:,:,:), allocatable :: ns,vs1,vs2,vs3,Ts !! fluid state variables real(wp), dimension(:,:,:), allocatable :: E1,E2,E3,J1,J2,J3,Phi !! electrodynamic state variables real(wp), dimension(:,:,:), allocatable :: rhov2,rhov3,B1,B2,B3 !! inductive state vars. (for future use - except for B1 which is used for the background field) real(wp), dimension(:,:,:), allocatable :: rhom,v1,v2,v3 !! inductive auxiliary real(wp), dimension(:,:,:,:), allocatable :: nn !! neutral density array real(wp), dimension(:,:,:), allocatable :: Tn,vn1,vn2,vn3 !! neutral temperature and velocities real(wp), dimension(:,:,:), allocatable :: Phiall !! full-grid potential solution. To store previous time step value real(wp), dimension(:,:,:), allocatable :: iver !! integrated volume emission rate of aurora calculated by GLOW !TEMPORAL VARIABLES real(wp) :: t=0, dt=1e-6_wp,dtprev !! time from beginning of simulation (s) and time step (s) real(wp) :: tout !! time for next output and time between outputs real(wp) :: tstart,tfin !! temp. vars. for measuring performance of code blocks integer :: it,isp, iupdate !! time and species loop indices real(wp) :: tneuBG !for testing whether we should re-evaluate neutral background !> WORK ARRAYS real(wp), allocatable :: dl1,dl2,dl3 !these are grid distances in [m] used to compute Courant numbers real(wp) :: tglowout !! time for next GLOW output !> TO CONTROL THROTTLING OF TIME STEP real(wp), parameter :: dtscale=2 !> Temporary variable for toggling full vs. other output integer :: flagoutput real(wp) :: tmilestone = 0 !> Milestone information integer, dimension(3) :: ymdtmp real(wp) :: UTsectmp,ttmp,tdur character(:), allocatable :: filetmp !> For reproducing initial drifts; these are allocated and the deallocated since they can be large real(wp), dimension(:,:,:), allocatable :: sig0,sigP,sigH,sigPgrav,sigHgrav real(wp), dimension(:,:,:,:), allocatable :: muP,muH,nusn real(wp), dimension(:,:,:), allocatable :: E01,E02,E03 !> Describing Lagrangian grid (if used) real(wp) :: v2grid,v3grid !> INITIALIZE MESSING PASSING VARIABLES, IDS ETC. call mpisetup() if(mpi_cfg%lid < 1) error stop 'number of MPI processes must be >= 1. Was MPI initialized properly?' if(use_cli) then call cli(cfg, lid2in, lid3in, debug) else block character(Lout_dir) :: buf integer :: i buf = "" !< ensure buf has no garbage characters do i = 1, Lout_dir if (out_dir(i) == c_null_char) exit buf(i:i) = out_dir(i) enddo cfg%outdir = expanduser(buf) end block endif call find_config(cfg) call read_configfile(cfg, verbose=.false.) call check_input_files(cfg) !> CHECK THE GRID SIZE AND ESTABLISH A PROCESS GRID call grid_size(cfg%indatsize) !> MPI gridding cannot be done until we know the grid size if (lid2in==-1) then call process_grid_auto(lx2all, lx3all) !! grid_size defines lx2all and lx3all else call mpi_manualgrid(lx2all, lx3all, lid2in, lid3in) endif print '(A, I0, A1, I0)', 'process grid (Number MPI processes) x2, x3: ',mpi_cfg%lid2, ' ', mpi_cfg%lid3 print '(A, I0, A, I0, A1, I0)', 'Process:',mpi_cfg%myid,' at process grid location: ',mpi_cfg%myid2,' ',mpi_cfg%myid3 !> LOAD UP THE GRID STRUCTURE/MODULE VARS. FOR THIS SIMULATION call read_grid(cfg%indatsize,cfg%indatgrid,cfg%flagperiodic, x) !! read in a previously generated grid from filenames listed in input file !> CREATE/PREP OUTPUT DIRECTORY AND OUTPUT SIMULATION SIZE AND GRID DATA !> ONLY THE ROOT PROCESS WRITES OUTPUT DATA if (mpi_cfg%myid==0) then call create_outdir(cfg) if (cfg%flagglow /= 0) call create_outdir_aur(cfg%outdir) end if !> ALLOCATE ARRAYS (AT THIS POINT ALL SIZES ARE SET FOR EACH PROCESS SUBGRID) allocate(ns(-1:lx1+2,-1:lx2+2,-1:lx3+2,lsp),vs1(-1:lx1+2,-1:lx2+2,-1:lx3+2,lsp),vs2(-1:lx1+2,-1:lx2+2,-1:lx3+2,lsp), & vs3(-1:lx1+2,-1:lx2+2,-1:lx3+2,lsp), Ts(-1:lx1+2,-1:lx2+2,-1:lx3+2,lsp)) allocate(rhov2(-1:lx1+2,-1:lx2+2,-1:lx3+2),rhov3(-1:lx1+2,-1:lx2+2,-1:lx3+2),B1(-1:lx1+2,-1:lx2+2,-1:lx3+2), & B2(-1:lx1+2,-1:lx2+2,-1:lx3+2),B3(-1:lx1+2,-1:lx2+2,-1:lx3+2)) allocate(v1(-1:lx1+2,-1:lx2+2,-1:lx3+2),v2(-1:lx1+2,-1:lx2+2,-1:lx3+2), & v3(-1:lx1+2,-1:lx2+2,-1:lx3+2),rhom(-1:lx1+2,-1:lx2+2,-1:lx3+2)) allocate(E1(lx1,lx2,lx3),E2(lx1,lx2,lx3),E3(lx1,lx2,lx3),J1(lx1,lx2,lx3),J2(lx1,lx2,lx3),J3(lx1,lx2,lx3)) allocate(Phi(lx1,lx2,lx3)) allocate(nn(lx1,lx2,lx3,lnchem),Tn(lx1,lx2,lx3),vn1(lx1,lx2,lx3), vn2(lx1,lx2,lx3),vn3(lx1,lx2,lx3)) !> ALLOCATE MEMORY FOR ROOT TO STORE CERTAIN VARS. OVER ENTIRE GRID if (mpi_cfg%myid==0) then allocate(Phiall(lx1,lx2all,lx3all)) end if !> ALLOCATE MEMORY FOR AURORAL EMISSIONS, IF CALCULATED if (cfg%flagglow /= 0) then allocate(iver(lx2,lx3,lwave)) iver = 0 end if !> FIXME: Zero out all state variables here - the corner ghost cells otherwise never get set and could contain garbage whicgh may make the sanity check fail since it does look at ghost cells, as well. !ns=0; vs1=0; Ts=0; ! oddly this doesn't seem to help our issue... !> Set initial time variables to simulation; this requires detecting whether we are trying to restart a simulation run !> LOAD ICS AND DISTRIBUTE TO WORKERS (REQUIRES GRAVITY FOR INITIAL GUESSING) !> ZZZ - this also should involve setting of Phiall... Either to zero or what the input file specifies... ! does not technically need to be broadcast to workers (since root sets up electrodynamics), but perhaps ! should be anyway since that is what the user probably would expect and there is little performance penalty. call find_milestone(cfg, ttmp, ymdtmp, UTsectmp, filetmp) if ( ttmp > 0 ) then !! restart scenario if (mpi_cfg%myid==0) then print*, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' print*, '! Restarting simulation from time: ',ymdtmp,UTsectmp print*, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' end if !! Set start variables accordingly and read in the milestone UTsec=UTsectmp ymd=ymdtmp tdur=cfg%tdur-ttmp ! subtract off time that has elapsed to milestone if (mpi_cfg%myid==0) then print*, 'Treating the following file as initial conditions: ',filetmp print*, ' full duration: ',cfg%tdur,'; remaining simulation time: ',tdur end if if (tdur <= 1e-6_wp .and. mpi_cfg%myid==0) error stop 'Cannot restart simulation from the final time step!' cfg%tdur=tdur ! just to insure consistency call input_plasma(x%x1,x%x2all,x%x3all,cfg%indatsize,filetmp,ns,vs1,Ts,Phi,Phiall) else !! start at the beginning UTsec = cfg%UTsec0 ymd = cfg%ymd0 tdur = cfg%tdur if (tdur <= 1e-6_wp .and. mpi_cfg%myid==0) error stop 'Simulation is of zero time duration' call input_plasma(x%x1,x%x2all,x%x3all,cfg%indatsize,cfg%indatfile,ns,vs1,Ts,Phi,Phiall) end if it = 1 t = 0 tout = t tglowout = t tneuBG=t !ROOT/WORKERS WILL ASSUME THAT THE MAGNETIC FIELDS AND PERP FLOWS START AT ZERO !THIS KEEPS US FROM HAVING TO HAVE FULL-GRID ARRAYS FOR THESE STATE VARS (EXCEPT !FOR IN OUTPUT FNS.). IF A SIMULATIONS IS DONE WITH INERTIAL CAPACITANCE THERE !WILL BE A FINITE AMOUNT OF TIME FOR THE FLOWS TO 'START UP', BUT THIS SHOULDN'T !BE TOO MUCH OF AN ISSUE. WE ALSO NEED TO SET THE BACKGROUND MAGNETIC FIELD STATE !VARIABLE HERE TO WHATEVER IS SPECIFIED IN THE GRID STRUCTURE (THESE MUST BE CONSISTENT) rhov2 = 0 rhov3 = 0 v2 = 0 v3 = 0 B2 = 0 B3 = 0 B1(1:lx1,1:lx2,1:lx3) = x%Bmag !! this assumes that the grid is defined s.t. the x1 direction corresponds !! to the magnetic field direction (hence zero B2 and B3). !> Inialize neutral atmosphere, note the use of fortran's weird scoping rules to avoid input args. Must occur after initial time info setup if(mpi_cfg%myid==0) print*, 'Priming electric field input' call init_Efieldinput(dt,t,cfg,ymd,UTsec,x) allocate(E01(lx1,lx2,lx3),E02(lx1,lx2,lx3),E03(lx1,lx2,lx3)) E01=0; E02=0; E03=0; if (cfg%flagE0file==1) then call get_BGEfields(x,E01,E02,E03) end if if (cfg%flaglagrangian) then ! Lagrangian (moving) grid; compute from input background electric fields call grid_drift(x,E02,E03,v2grid,v3grid) if (mpi_cfg%myid==0) print*, mpi_cfg%myid,' using Lagrangian grid moving at: ',v2grid,v3grid else ! stationary grid v2grid = 0 v3grid = 0 E1 = E1 + E01 E2 = E2 + E02 E3 = E3 + E03 end if if(mpi_cfg%myid==0) print*, 'Priming precipitation input' call init_precipinput(dt,t,cfg,ymd,UTsec,x) !> Neutral atmosphere setup if(cfg%msis_version == 20) then inquire(file='msis20.parm', exist=exists) if(.not.exists) error stop 'could not find MSIS 2.0 msis20.parm. ' // & 'This should be at gemini3d/build/msis20.parm and run gemini.bin from same directory' call msisinit(parmfile='msis20.parm') end if if(mpi_cfg%myid==0) print*, 'Computing background and priming neutral perturbation input (if used)' call init_neutrals(dt,t,cfg,ymd,UTsec,x,v2grid,v3grid,nn,Tn,vn1,vn2,vn3) !> Recompute electrodynamic quantities needed for restarting !> these do not include background E1 = 0 call pot2perpfield(Phi,x,E2,E3) if(mpi_cfg%myid==0) then print '(A)', 'Recomputed initial dist. fields:' print*, ' gemini ',minval(E1),maxval(E1) print*, ' gemini ',minval(E2),maxval(E2) print*, ' gemini ',minval(E3),maxval(E3) print*, 'Recomputed initial BG fields:' print*, ' ',minval(E01),maxval(E01) print*, ' ',minval(E02),maxval(E02) print*, ' ',minval(E03),maxval(E03) end if !> Recompute drifts and make some decisions about whether to invoke a Lagrangian grid allocate(sig0(lx1,lx2,lx3),sigP(lx1,lx2,lx3),sigH(lx1,lx2,lx3),sigPgrav(lx1,lx2,lx3),sigHgrav(lx1,lx2,lx3)) allocate(muP(lx1,lx2,lx3,lsp),muH(lx1,lx2,lx3,lsp),nusn(lx1,lx2,lx3,lsp)) call conductivities(nn,Tn,ns,Ts,vs1,B1,sig0,sigP,sigH,muP,muH,nusn,sigPgrav,sigHgrav) call velocities(muP,muH,nusn,E2,E3,vn2,vn3,ns,Ts,x,cfg%flaggravdrift,cfg%flagdiamagnetic,vs2,vs3) deallocate(sig0,sigP,sigH,muP,muH,nusn,sigPgrav,sigHgrav) deallocate(E01,E02,E03) if(mpi_cfg%myid==0) then print*, 'Recomputed initial drifts: ' print*, ' ',minval(vs2(1:lx1,1:lx2,1:lx3,1:lsp)),maxval(vs2(1:lx1,1:lx2,1:lx3,1:lsp)) print*, ' ',minval(vs3(1:lx1,1:lx2,1:lx3,1:lsp)),maxval(vs3(1:lx1,1:lx2,1:lx3,1:lsp)) end if !> control update rate from excessive console printing !! considering small vs. large simulations !! these are arbitrary levels, so feel free to finesse if (lx1*lx2*lx3 < 20000) then iupdate = 50 elseif (lx1*lx2*lx3 < 100000) then iupdate = 10 else iupdate = 1 endif !> Main time loop main : do while (t < tdur) !> TIME STEP CALCULATION, requires workers to report their most stringent local stability constraint dtprev = dt call dt_comm(t,tout,tglowout,cfg,ns,Ts,vs1,vs2,vs3,B1,B2,B3,x,dt) if (it>1) then if(dt/dtprev > dtscale) then !! throttle how quickly we allow dt to increase dt=dtscale*dtprev if (mpi_cfg%myid == 0) then print '(A,EN14.3)', 'Throttling dt to: ',dt end if end if end if !> COMPUTE BACKGROUND NEUTRAL ATMOSPHERE USING MSIS00. if ( it/=1 .and. cfg%flagneuBG .and. t>tneuBG) then !we dont' throttle for tneuBG so we have to do things this way to not skip over... call cpu_time(tstart) call neutral_atmos(ymd,UTsec,x%glat,x%glon,x%alt,cfg%activ,nn,Tn,cfg%msis_version) call neutral_winds(ymd, UTsec, Ap=cfg%activ(3), x=x, v2grid=v2grid,v3grid=v3grid,vn1=vn1, vn2=vn2, vn3=vn3) tneuBG=tneuBG+cfg%dtneuBG; if (mpi_cfg%myid==0) then call cpu_time(tfin) print *, 'Neutral background at time: ',t,' calculated in time: ',tfin-tstart end if end if !> GET NEUTRAL PERTURBATIONS FROM ANOTHER MODEL if (cfg%flagdneu==1) then call cpu_time(tstart) call neutral_perturb(cfg,dt,cfg%dtneu,t,ymd,UTsec,x,v2grid,v3grid,nn,Tn,vn1,vn2,vn3) if (mpi_cfg%myid==0 .and. debug) then call cpu_time(tfin) print *, 'Neutral perturbations calculated in time: ',tfin-tstart endif end if !> POTENTIAL SOLUTION call cpu_time(tstart) call electrodynamics(it,t,dt,nn,vn2,vn3,Tn,cfg,ns,Ts,vs1,B1,vs2,vs3,x,E1,E2,E3,J1,J2,J3,Phiall,ymd,UTsec) if (mpi_cfg%myid==0 .and. debug) then call cpu_time(tfin) print *, 'Electrodynamics total solve time: ',tfin-tstart endif !> UPDATE THE FLUID VARIABLES if (mpi_cfg%myid==0 .and. debug) call cpu_time(tstart) call fluid_adv(ns,vs1,Ts,vs2,vs3,J1,E1,cfg,t,dt,x,nn,vn1,vn2,vn3,Tn,iver,ymd,UTsec, first=(it==1) ) if (mpi_cfg%myid==0 .and. debug) then call cpu_time(tfin) print *, 'Multifluid total solve time: ',tfin-tstart endif !> Sanity check key variables before advancing ! FIXME: for whatever reason, it is just a fact that vs1 has trash in ghost cells after fluid_adv; I don't know why... call check_finite_output(t, mpi_cfg%myid, vs2,vs3,ns,vs1,Ts, Phi,J1,J2,J3) !> NOW OUR SOLUTION IS FULLY UPDATED SO UPDATE TIME VARIABLES TO MATCH... it = it + 1 t = t + dt if (mpi_cfg%myid==0 .and. debug) print *, 'Moving on to time step (in sec): ',t,'; end time of simulation: ',cfg%tdur call dateinc(dt,ymd,UTsec) if (mpi_cfg%myid==0 .and. (modulo(it, iupdate) == 0 .or. debug)) then !! print every 10th time step to avoid extreme amounts of console printing print '(A,I4,A1,I0.2,A1,I0.2,A1,F12.6,A5,F8.6)', 'Current time ',ymd(1),'-',ymd(2),'-',ymd(3),' ',UTsec,'; dt=',dt endif if (cfg%dryrun) then ierr = mpibreakdown() if (ierr /= 0) error stop 'Gemini dry run MPI shutdown failure' block character(8) :: date character(10) :: time call date_and_time(date,time) print '(/,A)', 'DONE: ' // date(1:4) // '-' // date(5:6) // '-' // date(7:8) // 'T' & // time(1:2) // ':' // time(3:4) // ':' // time(5:) stop "OK: Gemini dry run" end block endif !> File output if (abs(t-tout) < 1d-5) then tout = tout + cfg%dtout if (cfg%nooutput ) then if (mpi_cfg%myid==0) write(stderr,*) 'WARNING: skipping file output at sim time (sec)',t cycle main endif !! close enough to warrant an output now... if (mpi_cfg%myid==0 .and. debug) call cpu_time(tstart) !! We may need to adjust flagoutput if we are hitting a milestone flagoutput=cfg%flagoutput if (cfg%mcadence>0 .and. abs(t-tmilestone) < 1d-5) then flagoutput=1 !force a full output at the milestone call output_plasma(cfg%outdir,flagoutput,ymd, & UTsec,vs2,vs3,ns,vs1,Ts,Phiall,J1,J2,J3, & cfg%out_format) tmilestone = t + cfg%dtout * cfg%mcadence if(mpi_cfg%myid==0) print*, 'Milestone output triggered.' else call output_plasma(cfg%outdir,flagoutput,ymd, & UTsec,vs2,vs3,ns,vs1,Ts,Phiall,J1,J2,J3, & cfg%out_format) end if if (mpi_cfg%myid==0 .and. debug) then call cpu_time(tfin) print *, 'Plasma output done for time step: ',t,' in cpu_time of: ',tfin-tstart endif end if !> GLOW file output if ((cfg%flagglow /= 0) .and. (abs(t-tglowout) < 1d-5)) then !same as plasma output call cpu_time(tstart) call output_aur(cfg%outdir, cfg%flagglow, ymd, UTsec, iver, cfg%out_format) if (mpi_cfg%myid==0) then call cpu_time(tfin) print *, 'Auroral output done for time step: ',t,' in cpu_time of: ',tfin-tstart end if tglowout = tglowout + cfg%dtglowout end if end do main !> DEALLOCATE module data. We haven't verified it's strictly necessary, but it's been our practice. deallocate(ns,vs1,vs2,vs3,Ts) deallocate(E1,E2,E3,J1,J2,J3) deallocate(nn,Tn,vn1,vn2,vn3) if (mpi_cfg%myid==0) deallocate(Phiall) if (cfg%flagglow/=0) deallocate(iver) !> DEALLOCATE MODULE VARIABLES (MAY HAPPEN AUTOMATICALLY IN F2003???) !call clear_grid(x) call clear_dneu() call clear_precip_fileinput() call clear_potential_fileinput() !call clear_BGfield() end subroutine gemini_main end module gemini3d
section \<open>Monotone Formulas\<close> text \<open>We define monotone formulas, i.e., without negation, and show that usually the constant TRUE is not required.\<close> theory Monotone_Formula imports Main begin subsection \<open>Definition\<close> datatype 'a mformula = TRUE | FALSE | \<comment> \<open>True and False\<close> Var 'a | \<comment> \<open>propositional variables\<close> Conj "'a mformula" "'a mformula" | \<comment> \<open>conjunction\<close> Disj "'a mformula" "'a mformula" \<comment> \<open>disjunction\<close> text \<open>the set of subformulas of a mformula\<close> fun SUB :: "'a mformula \<Rightarrow> 'a mformula set" where "SUB (Conj \<phi> \<psi>) = {Conj \<phi> \<psi>} \<union> SUB \<phi> \<union> SUB \<psi>" | "SUB (Disj \<phi> \<psi>) = {Disj \<phi> \<psi>} \<union> SUB \<phi> \<union> SUB \<psi>" | "SUB (Var x) = {Var x}" | "SUB FALSE = {FALSE}" | "SUB TRUE = {TRUE}" text \<open>the variables of a mformula\<close> fun vars :: "'a mformula \<Rightarrow> 'a set" where "vars (Var x) = {x}" | "vars (Conj \<phi> \<psi>) = vars \<phi> \<union> vars \<psi>" | "vars (Disj \<phi> \<psi>) = vars \<phi> \<union> vars \<psi>" | "vars FALSE = {}" | "vars TRUE = {}" lemma finite_SUB[simp, intro]: "finite (SUB \<phi>)" by (induct \<phi>, auto) text \<open>The circuit-size of a mformula: number of subformulas\<close> definition cs :: "'a mformula \<Rightarrow> nat" where "cs \<phi> = card (SUB \<phi>)" text \<open>variable assignments\<close> type_synonym 'a VAS = "'a \<Rightarrow> bool" text \<open>evaluation of mformulas\<close> fun eval :: "'a VAS \<Rightarrow> 'a mformula \<Rightarrow> bool" where "eval \<theta> FALSE = False" | "eval \<theta> TRUE = True" | "eval \<theta> (Var x) = \<theta> x" | "eval \<theta> (Disj \<phi> \<psi>) = (eval \<theta> \<phi> \<or> eval \<theta> \<psi>)" | "eval \<theta> (Conj \<phi> \<psi>) = (eval \<theta> \<phi> \<and> eval \<theta> \<psi>)" lemma eval_vars: assumes "\<And> x. x \<in> vars \<phi> \<Longrightarrow> \<theta>1 x = \<theta>2 x" shows "eval \<theta>1 \<phi> = eval \<theta>2 \<phi>" using assms by (induct \<phi>, auto) subsection \<open>Conversion of mformulas to true-free mformulas\<close> inductive_set tf_mformula :: "'a mformula set" where tf_False: "FALSE \<in> tf_mformula" | tf_Var: "Var x \<in> tf_mformula" | tf_Disj: "\<phi> \<in> tf_mformula \<Longrightarrow> \<psi> \<in> tf_mformula \<Longrightarrow> Disj \<phi> \<psi> \<in> tf_mformula" | tf_Conj: "\<phi> \<in> tf_mformula \<Longrightarrow> \<psi> \<in> tf_mformula \<Longrightarrow> Conj \<phi> \<psi> \<in> tf_mformula" fun to_tf_formula where "to_tf_formula (Disj phi psi) = (let phi' = to_tf_formula phi; psi' = to_tf_formula psi in (if phi' = TRUE \<or> psi' = TRUE then TRUE else Disj phi' psi'))" | "to_tf_formula (Conj phi psi) = (let phi' = to_tf_formula phi; psi' = to_tf_formula psi in (if phi' = TRUE then psi' else if psi' = TRUE then phi' else Conj phi' psi'))" | "to_tf_formula phi = phi" lemma eval_to_tf_formula: "eval \<theta> (to_tf_formula \<phi>) = eval \<theta> \<phi>" by (induct \<phi> rule: to_tf_formula.induct, auto simp: Let_def) lemma to_tf_formula: "to_tf_formula \<phi> \<noteq> TRUE \<Longrightarrow> to_tf_formula \<phi> \<in> tf_mformula" by (induct \<phi>, auto simp: Let_def intro: tf_mformula.intros) lemma vars_to_tf_formula: "vars (to_tf_formula \<phi>) \<subseteq> vars \<phi>" by (induct \<phi> rule: to_tf_formula.induct, auto simp: Let_def) lemma SUB_to_tf_formula: "SUB (to_tf_formula \<phi>) \<subseteq> to_tf_formula ` SUB \<phi>" by (induct \<phi> rule: to_tf_formula.induct, auto simp: Let_def) lemma cs_to_tf_formula: "cs (to_tf_formula \<phi>) \<le> cs \<phi>" proof - have "cs (to_tf_formula \<phi>) \<le> card (to_tf_formula ` SUB \<phi>)" unfolding cs_def by (rule card_mono[OF finite_imageI[OF finite_SUB] SUB_to_tf_formula]) also have "\<dots> \<le> cs \<phi>" unfolding cs_def by (rule card_image_le[OF finite_SUB]) finally show "cs (to_tf_formula \<phi>) \<le> cs \<phi>" . qed lemma to_tf_mformula: assumes "\<not> eval \<theta> \<phi>" shows "\<exists> \<psi> \<in> tf_mformula. (\<forall> \<theta>. eval \<theta> \<phi> = eval \<theta> \<psi>) \<and> vars \<psi> \<subseteq> vars \<phi> \<and> cs \<psi> \<le> cs \<phi>" proof (intro bexI[of _ "to_tf_formula \<phi>"] conjI allI eval_to_tf_formula[symmetric] vars_to_tf_formula to_tf_formula) from assms have "\<not> eval \<theta> (to_tf_formula \<phi>)" by (simp add: eval_to_tf_formula) thus "to_tf_formula \<phi> \<noteq> TRUE" by auto show "cs (to_tf_formula \<phi>) \<le> cs \<phi>" by (rule cs_to_tf_formula) qed end
Formal statement is: lemma s_le_p: "a \<in> s \<Longrightarrow> a j \<le> p" Informal statement is: If $a$ is an element of $s$, then $a_j \leq p$.
using ExprTools using Test @testset "ExprTools.jl" begin include("function.jl") end
[STATEMENT] lemma measure_lim_emb: "J \<subseteq> I \<Longrightarrow> finite J \<Longrightarrow> X \<in> sets (\<Pi>\<^sub>M i\<in>J. borel) \<Longrightarrow> measure lim (emb I J X) = measure (P J) X" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>J \<subseteq> I; finite J; X \<in> sets (Pi\<^sub>M J (\<lambda>i. borel))\<rbrakk> \<Longrightarrow> Sigma_Algebra.measure local.lim (emb I J X) = Sigma_Algebra.measure (P J) X [PROOF STEP] unfolding measure_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>J \<subseteq> I; finite J; X \<in> sets (Pi\<^sub>M J (\<lambda>i. borel))\<rbrakk> \<Longrightarrow> enn2real (emeasure local.lim (emb I J X)) = enn2real (emeasure (P J) X) [PROOF STEP] by (subst emeasure_lim_emb) auto
\subsection{Overview} The SAGA C++ sources include an adaptor generator, which allows to easily create stubs for custom adaptors. The script is located in \shift |adaptors/generator/generator.pl| and is installed into |\$SAGA_LOCATION/bin/|. Calling that script without any arguments will print a help screen, which provides a number of details on the command line arguments etc. The exemplary shell session shown below demonstrates the use of the adaptor generator, and results in a complete file adaptor: \begin{mycode} # cd saga-core-src/adaptors/ # ./generator/saga-adaptor-generator.pl -s ssh -n sshfs -t file -d . suite: ssh type: file ftype: sshfs_file name: sshfs directory: ./ssh/ssh_sshfs_file copying files: ... fixing file names: .............. fixing files: .................... You can now cd to ./ssh/ssh_sshfs_file, and run 'make; make install'. Note that you need to set SAGA_LOCATION before, and point it to your SAGA installation tree. # cd ssh/ssh_sshfs_file # make compiling ssh_sshfs_file_adaptor.o compiling ssh_sshfs_file_dir_impl.o compiling ssh_sshfs_file_dir_nsdir_impl.o compiling ssh_sshfs_file_dir_nsentry_impl.o compiling ssh_sshfs_file_dir_perm_impl.o compiling ssh_sshfs_file_file_impl.o compiling ssh_sshfs_file_file_nsentry_impl.o compiling ssh_sshfs_file_file_perm_impl.o liblinking libsaga_adaptor_ssh_sshfs_file.so liblinking libsaga_adaptor_ssh_sshfs_file.a (static) # make install installing lib installing lib (static) installing adaptor ini \end{mycode} When running any SAGA application, that adaptor will get loaded and will receive requests to perform remote operations. That can be confirmed by setting |SAGA_VERBOSE| in the application environment (see SAGA installation guide). Of course, that adaptor will not be able to perform any meaningful operation -- it is just a stub, and will simply throw |NotImplemented| exceptions for all calls. However, it is now straight forward to fill the stub with the respective functionality. \F{Need to add details about class hierarchy, adaptor data, and instance data. Also, some details about adaptor makefiles, configure support etc might be useful.} Note that each adaptor will end up in a separate shared library. Since a typical SAGA installation will use multiple adaptors, and thus multiple adaptor libraries will be loaded into the same address space, the adaptor programmer needs to make sure to choose unique symbole names (i.e. to choose a unique and descriptive symbol name space), to avoid runtime symbol clashes.
State Before: R : Type u_1 A : Type ?u.2929 inst✝¹ : Semigroup R inst✝ : StarSemigroup R x : R ⊢ IsSelfAdjoint (x * star x) State After: no goals Tactic: simpa only [star_star] using star_mul_self (star x)
lemma bounded_linearI': fixes f ::"'a::euclidean_space \<Rightarrow> 'b::real_normed_vector" assumes "\<And>x y. f (x + y) = f x + f y" and "\<And>c x. f (c *\<^sub>R x) = c *\<^sub>R f x" shows "bounded_linear f"
-- ------------------------------------------------- [ InteractivePrograms.idr ] -- Module : Exercises.InteractivePrograms -- Description : Solutions to the Chapter 5 exercises in Edwin Brady's -- book, "Type-Driven Development with Idris." -- --------------------------------------------------------------------- [ EOH ] module Exercises.InteractivePrograms import Control.Arrow import Control.Category import Data.Morphisms import Data.Vect import Effects import Effect.Random %access export -- --------------------------------------------------------- [ 5.2.4 Exercises ] ||| Attempt to convert a string to a natural number. ||| ||| If `s` contains only digits, return `Just` the natural number it represents, ||| otherwise `Nothing`. ||| ||| ```idris example ||| stringToNat "123" ||| ``` ||| ```idris example ||| stringToNat "bad" ||| ``` ||| ||| @ string the string to try to convert stringToNat : (string : String) -> Maybe Nat stringToNat s = if all isDigit (unpack s) then Just (cast s) else Nothing handleGuess : Nat -> IO () -> Maybe Nat -> IO () handleGuess _ loop Nothing = putStrLn "Invalid number" *> loop handleGuess target loop (Just guess) = case compare guess target of LT => putStrLn "Too low!" *> loop EQ => putStrLn "Correct!" GT => putStrLn "Too high!" *> loop readNumber : IO (Maybe Nat) readNumber = stringToNat <$> getLine namespace Simple ||| A simple "guess the number" game. ||| ||| Repeatedly ask the user to guess a number and display whether the guess ||| is too high, too low, or correct. When the guess is correct, exit. ||| ||| @ target the number to be guessed partial guess : (target : Nat) -> IO () guess target = putStrLn "===> Guess the number" *> loop where partial loop : IO () loop = putStr "> " *> handleGuess target loop !readNumber partial main : IO () main = guess $ fromIntegerNat !(run (rndInt 1 100)) namespace Counting partial guess : (target, guesses : Nat) -> IO () guess target guesses = putStrLn "===> Guess the number" *> loop where partial loop : IO () loop = do putStrLn $ "Guesses so far: " ++ show guesses putStr "> " *> handleGuess target loop !readNumber partial main : IO () main = guess $ fromIntegerNat !(run (rndInt 1 100)) namespace DIY %hide Prelude.Interactive.replWith partial replWith : a -> String -> (a -> String -> Maybe (String, a)) -> IO () replWith state prompt func = do putStr prompt case func state !getLine of Just (output, newState) => do putStr output replWith newState prompt func Nothing => pure () %hide Prelude.Interactive.repl partial repl : String -> (String -> String) -> IO () repl prompt func = replWith () prompt (flip (curry go)) where go : (String, a) -> Maybe (String, a) go = applyMor $ first (arrow func) >>> arrow pure -- --------------------------------------------------------- [ 5.3.5 Exercises ] ||| Read input from the console until the user enters a blank line. partial readToBlank : IO (List String) readToBlank = case !getLine of "" => pure [] x => pure (x :: !readToBlank) ||| Read input from the console until the user enters a blank line, ||| then read a file name from the console, and write the input to the file. partial readAndSave : IO () readAndSave = do putStrLn "Input:" contents <- unlines <$> readToBlank putStr "Filename: " Right file <- writeFile !getLine contents | Left err => printLn err putStrLn "done" namespace ReadVectFile ||| Read the contents of a file into a dependent pair containing a length ||| and a `Vect` of that length. ||| If there are any errors, return the empty vector. partial readVectFile : (filename : String) -> IO (n ** Vect n String) readVectFile filename = do Right xs <- map lines <$> readFile filename | Left err => (printLn err *> pure (_ ** [])) pure (_ ** fromList xs) main : IO () main = putStr "Filename: " *> printLn !(readVectFile !getLine) -- --------------------------------------------------------------------- [ EOF ]
[STATEMENT] lemma closure_linear_image_subset: fixes f :: "'m::euclidean_space \<Rightarrow> 'n::real_normed_vector" assumes "linear f" shows "f ` (closure S) \<subseteq> closure (f ` S)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. f ` closure S \<subseteq> closure (f ` S) [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: linear f goal (1 subgoal): 1. f ` closure S \<subseteq> closure (f ` S) [PROOF STEP] unfolding linear_conv_bounded_linear [PROOF STATE] proof (prove) using this: bounded_linear f goal (1 subgoal): 1. f ` closure S \<subseteq> closure (f ` S) [PROOF STEP] by (rule closure_bounded_linear_image_subset)
[STATEMENT] lemma ennsqrt_bij: "bij ennsqrt" [PROOF STATE] proof (prove) goal (1 subgoal): 1. bij ennsqrt [PROOF STEP] by (rule bij_betw_byWitness[of _ "\<lambda>x. x * x"], auto)
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of permutation ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Permutation.Inductive.Properties where open import Algebra open import Algebra.FunctionProperties open import Algebra.Structures open import Data.List.Base as List open import Data.List.Relation.Binary.Permutation.Inductive open import Data.List.Relation.Unary.Any using (Any; here; there) open import Data.List.Relation.Unary.All using (All; []; _∷_) open import Data.List.Membership.Propositional open import Data.List.Membership.Propositional.Properties open import Data.List.Relation.Binary.BagAndSetEquality using (bag; _∼[_]_; empty-unique; drop-cons; commutativeMonoid) import Data.List.Properties as Lₚ open import Data.Product using (_,_; _×_; ∃; ∃₂) open import Function using (_∘_) open import Function.Equality using (_⟨$⟩_) open import Function.Inverse as Inv using (inverse) open import Relation.Unary using (Pred) open import Relation.Binary open import Relation.Binary.PropositionalEquality as ≡ using (_≡_ ; refl ; cong; cong₂; _≢_; inspect) open PermutationReasoning ------------------------------------------------------------------------ -- sym module _ {a} {A : Set a} where ↭-sym-involutive : ∀ {xs ys : List A} (p : xs ↭ ys) → ↭-sym (↭-sym p) ≡ p ↭-sym-involutive refl = refl ↭-sym-involutive (prep x ↭) = cong (prep x) (↭-sym-involutive ↭) ↭-sym-involutive (swap x y ↭) = cong (swap x y) (↭-sym-involutive ↭) ↭-sym-involutive (trans ↭₁ ↭₂) = cong₂ trans (↭-sym-involutive ↭₁) (↭-sym-involutive ↭₂) ------------------------------------------------------------------------ -- Relationships to other predicates module _ {a} {A : Set a} where All-resp-↭ : ∀ {ℓ} {P : Pred A ℓ} → (All P) Respects _↭_ All-resp-↭ refl wit = wit All-resp-↭ (prep x p) (px ∷ wit) = px ∷ All-resp-↭ p wit All-resp-↭ (swap x y p) (px ∷ py ∷ wit) = py ∷ px ∷ All-resp-↭ p wit All-resp-↭ (trans p₁ p₂) wit = All-resp-↭ p₂ (All-resp-↭ p₁ wit) Any-resp-↭ : ∀ {ℓ} {P : Pred A ℓ} → (Any P) Respects _↭_ Any-resp-↭ refl wit = wit Any-resp-↭ (prep x p) (here px) = here px Any-resp-↭ (prep x p) (there wit) = there (Any-resp-↭ p wit) Any-resp-↭ (swap x y p) (here px) = there (here px) Any-resp-↭ (swap x y p) (there (here px)) = here px Any-resp-↭ (swap x y p) (there (there wit)) = there (there (Any-resp-↭ p wit)) Any-resp-↭ (trans p p₁) wit = Any-resp-↭ p₁ (Any-resp-↭ p wit) ∈-resp-↭ : ∀ {x : A} → (x ∈_) Respects _↭_ ∈-resp-↭ = Any-resp-↭ ------------------------------------------------------------------------ -- map module _ {a b} {A : Set a} {B : Set b} (f : A → B) where map⁺ : ∀ {xs ys} → xs ↭ ys → map f xs ↭ map f ys map⁺ refl = refl map⁺ (prep x p) = prep _ (map⁺ p) map⁺ (swap x y p) = swap _ _ (map⁺ p) map⁺ (trans p₁ p₂) = trans (map⁺ p₁) (map⁺ p₂) ------------------------------------------------------------------------ -- _++_ module _ {a} {A : Set a} where ++⁺ˡ : ∀ xs {ys zs : List A} → ys ↭ zs → xs ++ ys ↭ xs ++ zs ++⁺ˡ [] ys↭zs = ys↭zs ++⁺ˡ (x ∷ xs) ys↭zs = prep x (++⁺ˡ xs ys↭zs) ++⁺ʳ : ∀ {xs ys : List A} zs → xs ↭ ys → xs ++ zs ↭ ys ++ zs ++⁺ʳ zs refl = refl ++⁺ʳ zs (prep x ↭) = prep x (++⁺ʳ zs ↭) ++⁺ʳ zs (swap x y ↭) = swap x y (++⁺ʳ zs ↭) ++⁺ʳ zs (trans ↭₁ ↭₂) = trans (++⁺ʳ zs ↭₁) (++⁺ʳ zs ↭₂) ++⁺ : _++_ Preserves₂ _↭_ ⟶ _↭_ ⟶ _↭_ ++⁺ ws↭xs ys↭zs = trans (++⁺ʳ _ ws↭xs) (++⁺ˡ _ ys↭zs) -- Some useful lemmas zoom : ∀ h {t xs ys : List A} → xs ↭ ys → h ++ xs ++ t ↭ h ++ ys ++ t zoom h {t} = ++⁺ˡ h ∘ ++⁺ʳ t inject : ∀ (v : A) {ws xs ys zs} → ws ↭ ys → xs ↭ zs → ws ++ [ v ] ++ xs ↭ ys ++ [ v ] ++ zs inject v ws↭ys xs↭zs = trans (++⁺ˡ _ (prep v xs↭zs)) (++⁺ʳ _ ws↭ys) shift : ∀ v (xs ys : List A) → xs ++ [ v ] ++ ys ↭ v ∷ xs ++ ys shift v [] ys = refl shift v (x ∷ xs) ys = begin x ∷ (xs ++ [ v ] ++ ys) <⟨ shift v xs ys ⟩ x ∷ v ∷ xs ++ ys <<⟨ refl ⟩ v ∷ x ∷ xs ++ ys ∎ drop-mid-≡ : ∀ {x} ws xs {ys} {zs} → ws ++ [ x ] ++ ys ≡ xs ++ [ x ] ++ zs → ws ++ ys ↭ xs ++ zs drop-mid-≡ [] [] eq with cong tail eq drop-mid-≡ [] [] eq | refl = refl drop-mid-≡ [] (x ∷ xs) refl = shift _ xs _ drop-mid-≡ (w ∷ ws) [] refl = ↭-sym (shift _ ws _) drop-mid-≡ (w ∷ ws) (x ∷ xs) eq with Lₚ.∷-injective eq ... | refl , eq′ = prep w (drop-mid-≡ ws xs eq′) drop-mid : ∀ {x} ws xs {ys zs} → ws ++ [ x ] ++ ys ↭ xs ++ [ x ] ++ zs → ws ++ ys ↭ xs ++ zs drop-mid {x} ws xs p = drop-mid′ p ws xs refl refl where drop-mid′ : ∀ {l′ l″ : List A} → l′ ↭ l″ → ∀ ws xs {ys zs : List A} → ws ++ [ x ] ++ ys ≡ l′ → xs ++ [ x ] ++ zs ≡ l″ → ws ++ ys ↭ xs ++ zs drop-mid′ refl ws xs refl eq = drop-mid-≡ ws xs (≡.sym eq) drop-mid′ (prep x p) [] [] refl eq with cong tail eq drop-mid′ (prep x p) [] [] refl eq | refl = p drop-mid′ (prep x p) [] (x ∷ xs) refl refl = trans p (shift _ _ _) drop-mid′ (prep x p) (w ∷ ws) [] refl refl = trans (↭-sym (shift _ _ _)) p drop-mid′ (prep x p) (w ∷ ws) (x ∷ xs) refl refl = prep _ (drop-mid′ p ws xs refl refl) drop-mid′ (swap y z p) [] [] refl refl = prep _ p drop-mid′ (swap y z p) [] (x ∷ []) refl eq with cong {B = List _} (λ { (x ∷ _ ∷ xs) → x ∷ xs ; _ → [] }) eq drop-mid′ (swap y z p) [] (x ∷ []) refl eq | refl = prep _ p drop-mid′ (swap y z p) [] (x ∷ _ ∷ xs) refl refl = prep _ (trans p (shift _ _ _)) drop-mid′ (swap y z p) (w ∷ []) [] refl eq with cong tail eq drop-mid′ (swap y z p) (w ∷ []) [] refl eq | refl = prep _ p drop-mid′ (swap y z p) (w ∷ x ∷ ws) [] refl refl = prep _ (trans (↭-sym (shift _ _ _)) p) drop-mid′ (swap y y p) (y ∷ []) (y ∷ []) refl refl = prep _ p drop-mid′ (swap y z p) (y ∷ []) (z ∷ y ∷ xs) refl refl = begin _ ∷ _ <⟨ p ⟩ _ ∷ (xs ++ _ ∷ _) <⟨ shift _ _ _ ⟩ _ ∷ _ ∷ xs ++ _ <<⟨ refl ⟩ _ ∷ _ ∷ xs ++ _ ∎ drop-mid′ (swap y z p) (y ∷ z ∷ ws) (z ∷ []) refl refl = begin _ ∷ _ ∷ ws ++ _ <<⟨ refl ⟩ _ ∷ (_ ∷ ws ++ _) <⟨ ↭-sym (shift _ _ _) ⟩ _ ∷ (ws ++ _ ∷ _) <⟨ p ⟩ _ ∷ _ ∎ drop-mid′ (swap y z p) (y ∷ z ∷ ws) (z ∷ y ∷ xs) refl refl = swap y z (drop-mid′ p _ _ refl refl) drop-mid′ (trans p₁ p₂) ws xs refl refl with ∈-∃++ (∈-resp-↭ p₁ (∈-insert ws)) ... | (h , t , refl) = trans (drop-mid′ p₁ ws h refl refl) (drop-mid′ p₂ h xs refl refl) -- Algebraic properties ++-identityˡ : LeftIdentity {A = List A} _↭_ [] _++_ ++-identityˡ xs = refl ++-identityʳ : RightIdentity {A = List A} _↭_ [] _++_ ++-identityʳ xs = ↭-reflexive (Lₚ.++-identityʳ xs) ++-identity : Identity {A = List A} _↭_ [] _++_ ++-identity = ++-identityˡ , ++-identityʳ ++-assoc : Associative {A = List A} _↭_ _++_ ++-assoc xs ys zs = ↭-reflexive (Lₚ.++-assoc xs ys zs) ++-comm : Commutative _↭_ _++_ ++-comm [] ys = ↭-sym (++-identityʳ ys) ++-comm (x ∷ xs) ys = begin x ∷ xs ++ ys ↭⟨ prep x (++-comm xs ys) ⟩ x ∷ ys ++ xs ≡⟨ cong (λ v → x ∷ v ++ xs) (≡.sym (Lₚ.++-identityʳ _)) ⟩ (x ∷ ys ++ []) ++ xs ↭⟨ ++⁺ʳ xs (↭-sym (shift x ys [])) ⟩ (ys ++ [ x ]) ++ xs ↭⟨ ++-assoc ys [ x ] xs ⟩ ys ++ ([ x ] ++ xs) ≡⟨⟩ ys ++ (x ∷ xs) ∎ ++-isMagma : IsMagma _↭_ _++_ ++-isMagma = record { isEquivalence = ↭-isEquivalence ; ∙-cong = ++⁺ } ++-magma : Magma _ _ ++-magma = record { isMagma = ++-isMagma } ++-isSemigroup : IsSemigroup _↭_ _++_ ++-isSemigroup = record { isMagma = ++-isMagma ; assoc = ++-assoc } ++-semigroup : Semigroup a _ ++-semigroup = record { isSemigroup = ++-isSemigroup } ++-isMonoid : IsMonoid _↭_ _++_ [] ++-isMonoid = record { isSemigroup = ++-isSemigroup ; identity = ++-identity } ++-monoid : Monoid a _ ++-monoid = record { isMonoid = ++-isMonoid } ++-isCommutativeMonoid : IsCommutativeMonoid _↭_ _++_ [] ++-isCommutativeMonoid = record { isSemigroup = ++-isSemigroup ; identityˡ = ++-identityˡ ; comm = ++-comm } ++-commutativeMonoid : CommutativeMonoid _ _ ++-commutativeMonoid = record { isCommutativeMonoid = ++-isCommutativeMonoid } ------------------------------------------------------------------------ -- _∷_ module _ {a} {A : Set a} where drop-∷ : ∀ {x : A} {xs ys} → x ∷ xs ↭ x ∷ ys → xs ↭ ys drop-∷ = drop-mid [] [] ------------------------------------------------------------------------ -- _∷ʳ_ module _ {a} {A : Set a} where ∷↭∷ʳ : ∀ (x : A) xs → x ∷ xs ↭ xs ∷ʳ x ∷↭∷ʳ x xs = ↭-sym (begin xs ++ [ x ] ↭⟨ shift x xs [] ⟩ x ∷ xs ++ [] ≡⟨ Lₚ.++-identityʳ _ ⟩ x ∷ xs ∎) ------------------------------------------------------------------------ -- Relationships to other relations module _ {a} {A : Set a} where ↭⇒∼bag : _↭_ ⇒ _∼[ bag ]_ ↭⇒∼bag xs↭ys {v} = inverse (to xs↭ys) (from xs↭ys) (from∘to xs↭ys) (to∘from xs↭ys) where to : ∀ {xs ys} → xs ↭ ys → v ∈ xs → v ∈ ys to xs↭ys = Any-resp-↭ {A = A} xs↭ys from : ∀ {xs ys} → xs ↭ ys → v ∈ ys → v ∈ xs from xs↭ys = Any-resp-↭ (↭-sym xs↭ys) from∘to : ∀ {xs ys} (p : xs ↭ ys) (q : v ∈ xs) → from p (to p q) ≡ q from∘to refl v∈xs = refl from∘to (prep _ _) (here refl) = refl from∘to (prep _ p) (there v∈xs) = cong there (from∘to p v∈xs) from∘to (swap x y p) (here refl) = refl from∘to (swap x y p) (there (here refl)) = refl from∘to (swap x y p) (there (there v∈xs)) = cong (there ∘ there) (from∘to p v∈xs) from∘to (trans p₁ p₂) v∈xs rewrite from∘to p₂ (Any-resp-↭ p₁ v∈xs) | from∘to p₁ v∈xs = refl to∘from : ∀ {xs ys} (p : xs ↭ ys) (q : v ∈ ys) → to p (from p q) ≡ q to∘from p with from∘to (↭-sym p) ... | res rewrite ↭-sym-involutive p = res ∼bag⇒↭ : _∼[ bag ]_ ⇒ _↭_ ∼bag⇒↭ {[]} eq with empty-unique (Inv.sym eq) ... | refl = refl ∼bag⇒↭ {x ∷ xs} eq with ∈-∃++ (to ⟨$⟩ (here ≡.refl)) where open Inv.Inverse (eq {x}) ... | zs₁ , zs₂ , p rewrite p = begin x ∷ xs <⟨ ∼bag⇒↭ (drop-cons (Inv._∘_ (comm zs₁ (x ∷ zs₂)) eq)) ⟩ x ∷ (zs₂ ++ zs₁) <⟨ ++-comm zs₂ zs₁ ⟩ x ∷ (zs₁ ++ zs₂) ↭˘⟨ shift x zs₁ zs₂ ⟩ zs₁ ++ x ∷ zs₂ ∎ where open CommutativeMonoid (commutativeMonoid bag A) ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 1.0 ↭⇒~bag = ↭⇒∼bag {-# WARNING_ON_USAGE ↭⇒~bag "Warning: ↭⇒~bag was deprecated in v1.0. Please use ? instead (now typed with '\\sim' rather than '~')." #-} ~bag⇒↭ = ∼bag⇒↭ {-# WARNING_ON_USAGE ~bag⇒↭ "Warning: ~bag⇒↭ was deprecated in v1.0. Please use ? instead (now typed with '\\sim' rather than '~')." #-}
[STATEMENT] lemma fag_aGroup:"\<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> aGroup (fag_gen_by A f i z)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> aGroup (fag_gen_by A f i z) [PROOF STEP] apply (rule aGroup.intro) [PROOF STATE] proof (prove) goal (7 subgoals): 1. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> (\<plusminus>\<^bsub>fag_gen_by A f i z\<^esub>) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 2. \<And>a b c. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z); c \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> c = a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> (b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> c) 3. \<And>a b. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b = b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a 4. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 5. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 6. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 7. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def aug_bpp_closed) [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>a b c. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z); c \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> c = a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> (b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> c) 2. \<And>a b. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b = b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a 3. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 4. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 5. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 6. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def) [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>a b c. \<lbrakk>assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> addition_set f (aug_pm_set z i A); b \<in> addition_set f (aug_pm_set z i A); c \<in> addition_set f (aug_pm_set z i A)\<rbrakk> \<Longrightarrow> (a \<^sub>f+ b \<in> addition_set f (aug_pm_set z i A) \<longrightarrow> (b \<^sub>f+ c \<in> addition_set f (aug_pm_set z i A) \<longrightarrow> a \<^sub>f+ b \<^sub>f+ c = a \<^sub>f+ (b \<^sub>f+ c)) \<and> (b \<^sub>f+ c \<notin> addition_set f (aug_pm_set z i A) \<longrightarrow> a \<^sub>f+ b \<^sub>f+ c = undefined)) \<and> (a \<^sub>f+ b \<notin> addition_set f (aug_pm_set z i A) \<longrightarrow> (b \<^sub>f+ c \<in> addition_set f (aug_pm_set z i A) \<longrightarrow> undefined c = a \<^sub>f+ (b \<^sub>f+ c)) \<and> (b \<^sub>f+ c \<notin> addition_set f (aug_pm_set z i A) \<longrightarrow> undefined c = undefined)) 2. \<And>a b. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b = b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a 3. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 4. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 5. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 6. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:aug_bpp_closed) [PROOF STATE] proof (prove) goal (6 subgoals): 1. \<And>a b c. \<lbrakk>assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> addition_set f (aug_pm_set z i A); b \<in> addition_set f (aug_pm_set z i A); c \<in> addition_set f (aug_pm_set z i A)\<rbrakk> \<Longrightarrow> a \<^sub>f+ b \<^sub>f+ c = a \<^sub>f+ (b \<^sub>f+ c) 2. \<And>a b. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b = b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a 3. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 4. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 5. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 6. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:assoc_bpp_def) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>a b. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z); b \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> b = b \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a 2. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 3. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 4. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 5. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def) [PROOF STATE] proof (prove) goal (5 subgoals): 1. \<And>a b. \<lbrakk>assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> addition_set f (aug_pm_set z i A); b \<in> addition_set f (aug_pm_set z i A)\<rbrakk> \<Longrightarrow> a \<^sub>f+ b = b \<^sub>f+ a 2. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 3. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 4. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 5. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:aug_commute) [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> mop (fag_gen_by A f i z) \<in> carrier (fag_gen_by A f i z) \<rightarrow> carrier (fag_gen_by A f i z) 2. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 3. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 4. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def aug_ipp_closed) [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> -\<^sub>a\<^bsub>fag_gen_by A f i z\<^esub> a \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = \<zero>\<^bsub>fag_gen_by A f i z\<^esub> 2. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 3. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def inv_aug_addition aug_ipp_closed) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<in> carrier (fag_gen_by A f i z) 2. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def addition_set_inc_z) [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<And>a. \<lbrakk>commute_bpp f (aug_pm_set z i A); assoc_bpp (aug_pm_set z i A) f; ipp_cond1 A i; ipp_cond2 z A i f; ipp_cond3 z i; inv_ipp z i f A; commute_bpp f (aug_pm_set z i A); zeroA z i f A z; a \<in> carrier (fag_gen_by A f i z)\<rbrakk> \<Longrightarrow> \<zero>\<^bsub>fag_gen_by A f i z\<^esub> \<plusminus>\<^bsub>fag_gen_by A f i z\<^esub> a = a [PROOF STEP] apply (simp add:fag_gen_by_def addition_set_inc_z zeroA_def) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
| Aloha! Maluhia Massage is now open for business in Davis, CA. Maluhia means peaceful in Hawaiian. Experience the tranquility of the islands with a massage by Kerri. Its a touch of paradise. Maluhia Massage comes to you. Enjoy a relaxing massage in the comfort of your own home. Massages from Maluhia Massage incorporate swedish, deep tissue, joint mobility, and stretching to create a full body experience. Relaxation music is available to enhance your massage. Maluhia Massage is currently only doing business in Davis, but plans on expanding throughout the Sacramento area over the next year. Mahalo! Not sure what gift to get someone? Give them the gift of relaxation!!! Maluhia Massage is an out call business (they will travel to your Davis home) that provides massage services a massage in the comfort of your own home. They are owned and operated by Kerri Domingo. To schedule a visit, go to http://maluhiamassage.weebly.com See
theory T24 imports Main begin lemma "( (\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) & (\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) & (\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) & (\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) & (\<forall> x::nat. invo(invo(x)) = x) ) \<longrightarrow> (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) " nitpick[card nat=4,timeout=86400] oops end
(* Property from Productive Use of Failure in Inductive Proof, Andrew Ireland and Alan Bundy, JAR 1996. 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.*) theory TIP_prop_36 imports "../../Test_Base" begin datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Nat = Z | S "Nat" fun z :: "'a list => 'a list => 'a list" where "z (nil2) y2 = y2" | "z (cons2 z2 xs) y2 = cons2 z2 (z xs y2)" fun y :: "Nat => Nat => bool" where "y (Z) (Z) = True" | "y (Z) (S z2) = False" | "y (S x22) (Z) = False" | "y (S x22) (S y22) = y x22 y22" fun x :: "bool => bool => bool" where "x True y2 = True" | "x False y2 = y2" fun elem :: "Nat => Nat list => bool" where "elem x2 (nil2) = False" | "elem x2 (cons2 z2 xs) = x (y x2 z2) (elem x2 xs)" theorem property0 : "((elem x2 y2) ==> (elem x2 (z y2 z2)))" oops end
""" create_application_command(c::Client; kwargs...) -> ApplicationCommand Creates a global [`ApplicationCommand`](@ref). """ function create_application_command(c::Client; kwargs...) return Response{ApplicationCommand}(c, :POST, "/applications/$appid/commands"; body=kwargs) end """ create_application_command(c::Client, guild::Snowflake; kwargs...) -> ApplicationCommand Creates a guild [`ApplicationCommand`](@ref). """ function create_application_command(c::Client, guild::Snowflake; kwargs...) appid = c.application_id return Response{ApplicationCommand}(c, :POST, "/applications/$appid/guilds/$guild/commands"; body=kwargs) end """ get_application_commands(c::Client) -> Vector{ApplicationCommand} Gets all global [`ApplicationCommand`](@ref)s for the logged in client. """ function get_application_commands(c::Client) appid = c.application_id return Response{Vector{ApplicationCommand}}(c, :GET, "/applications/$appid/commands") end """ get_application_commands(c::Client, guild::Snowflake) -> Vector{ApplicationCommand} Gets all guild [`ApplicationCommand`](@ref)s for the logged in client. """ function get_application_commands(c::Client, guild::Snowflake) appid = c.application_id return Response{Vector{ApplicationCommand}}(c, :GET, "/applications/$appid/guilds/$guild/commands") end """ respond_to_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) -> Message Respond to an interaction with code 4. """ function respond_to_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) dict = Dict{Symbol, Any}( :data => kwargs, :type => 4, ) return Response{Message}(c, :POST, "/interactions/$int_id/$int_token/callback"; body=dict) end function respond_to_interaction_with_a_modal(c::Client, int_id::Snowflake, int_token::String; kwargs...) dict = Dict{Symbol, Any}( :data => kwargs, :type => 9, ) return Response{Message}(c, :POST, "/interactions/$int_id/$int_token/callback"; body=dict) end """ ack_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) Respond to an interaction with code 5. """ function ack_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) dict = Dict{Symbol, Any}( :type => 5, ) return Response(c, :POST, "/interactions/$int_id/$int_token/callback"; body=dict) end """ update_ack_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) -> Message Respond to an interaction with code 6. """ function update_ack_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) dict = Dict{Symbol, Any}( :type => 6, ) return Response{Message}(c, :POST, "/interactions/$int_id/$int_token/callback"; body=dict) end """ update_message_int(c::Client, int_id::Snowflake, int_token::String; kwargs...) Respond to an interaction with code 7. """ function update_message_int(c::Client, int_id::Snowflake, int_token::String; kwargs...) dict = Dict{Symbol, Any}( :data => kwargs, :type => 7, ) return Response(c, :POST, "/interactions/$int_id/$int_token/callback"; body=dict) end """ create_followup_message(c::Client, int_id::Snowflake, int_token::String; kwargs...) -> Message Creates a followup message for an interaction. """ function create_followup_message(c::Client, int_id::Snowflake, int_token::String; kwargs...) appid = c.application_id return Response{Message}(c, :POST, "/webhooks/$appid/$int_token)"; body=kwargs) end """ edit_interaction(c::Client, int_id::Snowflake, int_token::String; kwargs...) Edit a followup message for an interaction. """ function edit_interaction(c::Client, int_token::String, mid::Snowflake; kwargs...) appid = c.application_id return Response(c, :PATCH, "/webhooks/$appid/$int_token/messages/$mid"; body=kwargs) end """ bulk_overwrite_application_commands(c::Client, guild::Snowflake, cmds::Vector{ApplicationCommand}) -> Vector{ApplicationCommand} Overwrites global [`ApplicationCommand`](@ref)s with the given cmds vector. """ function bulk_overwrite_application_commands(c::Client, guild::Snowflake, cmds::Vector{ApplicationCommand}) appid = c.application_id return Response{Vector{ApplicationCommand}}(c, :PUT, "/applications/$appid/guilds/$guild/commands"; body=cmds) end """ bulk_overwrite_application_commands(c::Client, guild::Snowflake, cmds::Vector{ApplicationCommand}) -> Vector{ApplicationCommand} Overwrites guild [`ApplicationCommand`](@ref)s with the given cmds vector. """ function bulk_overwrite_application_commands(c::Client, cmds::Vector{ApplicationCommand}) appid = c.application_id return Response{Vector{ApplicationCommand}}(c, :PUT, "/applications/$appid/commands"; body=cmds) end
/* movstat/funcacc.c * * Moving window accumulator for arbitrary user-defined function * * Copyright (C) 2018 Patrick Alken * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <config.h> #include <gsl/gsl_math.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_movstat.h> #include <gsl/gsl_sort.h> #include <gsl/gsl_statistics.h> typedef double funcacc_type_t; typedef funcacc_type_t ringbuf_type_t; #include "ringbuf.c" typedef struct { funcacc_type_t *window; /* linear array for current window */ ringbuf *rbuf; /* ring buffer storing current window */ } funcacc_state_t; static size_t funcacc_size(const size_t n) { size_t size = 0; size += sizeof(funcacc_state_t); size += n * sizeof(funcacc_type_t); size += ringbuf_size(n); return size; } static int funcacc_init(const size_t n, void * vstate) { funcacc_state_t * state = (funcacc_state_t *) vstate; state->window = (funcacc_type_t *) ((unsigned char *) vstate + sizeof(funcacc_state_t)); state->rbuf = (ringbuf *) ((unsigned char *) state->window + n * sizeof(funcacc_type_t)); ringbuf_init(n, state->rbuf); return GSL_SUCCESS; } static int funcacc_insert(const funcacc_type_t x, void * vstate) { funcacc_state_t * state = (funcacc_state_t *) vstate; /* add new element to ring buffer */ ringbuf_insert(x, state->rbuf); return GSL_SUCCESS; } static int funcacc_delete(void * vstate) { funcacc_state_t * state = (funcacc_state_t *) vstate; if (!ringbuf_is_empty(state->rbuf)) ringbuf_pop_back(state->rbuf); return GSL_SUCCESS; } static int funcacc_get(void * params, funcacc_type_t * result, const void * vstate) { const funcacc_state_t * state = (const funcacc_state_t *) vstate; gsl_movstat_function *f = (gsl_movstat_function *) params; size_t n = ringbuf_copy(state->window, state->rbuf); *result = GSL_MOVSTAT_FN_EVAL(f, n, state->window); return GSL_SUCCESS; } static const gsl_movstat_accum func_accum_type = { funcacc_size, funcacc_init, funcacc_insert, funcacc_delete, funcacc_get }; const gsl_movstat_accum *gsl_movstat_accum_userfunc = &func_accum_type;
# ------- type SymbolNode sym parent children::Array{SymbolNode} SymbolNode(sym, parent = nothing) = new(sym, parent, SymbolNode[]) end type DataNode name value DataNode(name, value) = new(name, value) end global _g_records = SymbolNode(nothing, nothing) global _data_records = {} # ------- function getindex(sn::SymbolNode, keys...) haskey(sn, keys...) || error("Key not found: $(keys)") eval(Main, to_expr(keys...)) end function setindex!(sn::SymbolNode, keys...) key_count = length(keys) key_count > 0 || return did_allocate = false if sn.sym == nothing (sn, did_allocate) = push!(sn, keys[1]) end sn.sym != keys[1] && error("head symbol node does not match key $(keys[1])") curr_node = sn for i in 2:length(keys) # if a node higher in the tree was already a leaf # then this set of keys is already recorded if !did_allocate && length(curr_node.children) < 1 break end (curr_node, did_allocate) = push!(curr_node, keys[i]) end empty!(curr_node.children) nothing end function haskey(sn::SymbolNode, keys...) key_count = length(keys) key_count > 0 || return curr_index = 1 curr_node = sn while curr_index <= key_count && curr_node != nothing && curr_node.sym == keys[curr_index] if curr_index == key_count || length(curr_node.children) < 1 return true end curr_index += 1 curr_node = find_child(curr_node, keys[curr_index]) end false end function push!(sn::SymbolNode, child_sym) child = find_child(sn, child_sym) did_allocate = false if child == nothing did_allocate = true child = SymbolNode(child_sym, sn) push!(sn.children, child) end child, did_allocate end function store_data(name, value) node = DataNode(name, value) push!(_data_records, node) node end function delete!(sn::SymbolNode, keys...) key_count = length(keys) key_count == 0 && return sn if key_count == 1 return sn.sym == keys[1] ? nothing : sn end curr_index = 1 curr_node = sn while curr_index <= key_count && curr_node != nothing && curr_node.sym == keys[curr_index] if curr_index == key_count delete!(curr_node) return sn end curr_index += 1 curr_node = find_child(curr_node, keys[curr_index]) end sn end function delete!(sn::SymbolNode) parent = sn.parent if parent == nothing empty!(sn.children) return sn end index = find_child_index(parent, sn.sym) index == -1 && error("nodes parent does not contain node... something has gone horribly wrong") splice!(parent.children, index) parent end function show(io::IO, sn::SymbolNode, depth = 1) println(io, ">", sn.sym) for child in sn.children print(" "^depth) show(io, child, depth + 1) end println(" "^(depth - 1), "<") end # ------- function record(keys...) global _g_records setindex!(_g_records, keys...) end function fetch_records() build_record_tree() end function take_records() tree = build_record_tree() delete!(_g_records) for node = _data_records tree[node.name] = node.value end empty!(_data_records) tree end function hasrecord(keys...) if length(keys) > 0 global _g_records sub_head = find_child(_g_records, keys[1]) if sub_head != nothing return haskey(sub_head, keys...) end end false end function getrecord(keys...) if length(keys) > 0 global _g_records sub_head = find_child(_g_records, keys[1]) if sub_head != nothing return getindex(sub_head, keys...) end end error("Key not found: $(keys)") end # ------- function to_expr(syms...) # there might well be a better way to do this, for now we'll eval strings typeof(syms[1]) <: Symbol || error("first piece of key must be a Symbol") ex = string(syms[1]) for sym in syms[2:end] symtype = typeof(sym) if symtype <: Symbol ex *= ".$sym" elseif symtype <: Int ex *= "[$sym]" elseif symtype <: String ex *= "[$(repr(sym))]" else error("unrecognized key index: $sym") end end parse(ex) end function find_child_index(sn::SymbolNode, child_sym) isempty(sn.children) && return -1 for i in 1:length(sn.children) child_sym == sn.children[i].sym && return i end return -1 end find_child(n::SymbolNode, k) = get(n.children, find_child_index(n, k), nothing) function build_record_tree(sn::SymbolNode = _g_records, out = Dict(), keys = Any[]) keys = deepcopy(keys) sn.sym != nothing && push!(keys, sn.sym) # special case for _g_records for child in sn.children num_grandchildren = length(child.children) if num_grandchildren > 0 out[child.sym] = Dict() build_record_tree(child, out[child.sym], keys) else try out[child.sym] = eval(Main, to_expr(keys..., child.sym)) catch err out[child.sym] = err end end end out end # -------
module TAP import System import Data.Vect %default total %access private {- TAP v13 Test Output Producer and Runner -} comment : String -> IO () comment s = putStrLn ("# " ++ s) stamp : IO () -> IO () stamp rest = do t <- time comment ("t " ++ (show t)) rest printResult : String -> Bool -> IO () printResult n True = putStrLn ("ok " ++ n) printResult n False = putStrLn ("not ok " ++ n) runTests : Nat -> Vect n (Lazy (IO Bool)) -> IO () runTests k [] = pure () runTests k (x :: xs) = x >>= printResult (show k) >>= \_ => runTests (S k) xs export plan : (desc : String) -> Vect n (Lazy (IO Bool)) -> IO () plan desc tests {n} = do putStrLn "TAP version 13" comment desc putStrLn ("1.." ++ show n) runTests 1 tests stamp $ comment "done"
lemma strict_mono_Suc_iff: "strict_mono f \<longleftrightarrow> (\<forall>n. f n < f (Suc n))"
(*<*) theory TAO_1_Embedding imports Main begin (*>*) section\<open>Representation Layer\<close> text\<open>\label{TAO_Embedding}\<close> subsection\<open>Primitives\<close> text\<open>\label{TAO_Embedding_Primitives}\<close> typedecl i \<comment> \<open>possible worlds\<close> typedecl j \<comment> \<open>states\<close> consts dw :: i \<comment> \<open>actual world\<close> consts dj :: j \<comment> \<open>actual state\<close> typedecl \<omega> \<comment> \<open>ordinary objects\<close> typedecl \<sigma> \<comment> \<open>special urelements\<close> datatype \<upsilon> = \<omega>\<upsilon> \<omega> | \<sigma>\<upsilon> \<sigma> \<comment> \<open>urelements\<close> subsection\<open>Derived Types\<close> text\<open>\label{TAO_Embedding_Derived_Types}\<close> typedef \<o> = "UNIV::(j\<Rightarrow>i\<Rightarrow>bool) set" morphisms eval\<o> make\<o> .. \<comment> \<open>truth values\<close> type_synonym \<Pi>\<^sub>0 = \<o> \<comment> \<open>zero place relations\<close> typedef \<Pi>\<^sub>1 = "UNIV::(\<upsilon>\<Rightarrow>j\<Rightarrow>i\<Rightarrow>bool) set" morphisms eval\<Pi>\<^sub>1 make\<Pi>\<^sub>1 .. \<comment> \<open>one place relations\<close> typedef \<Pi>\<^sub>2 = "UNIV::(\<upsilon>\<Rightarrow>\<upsilon>\<Rightarrow>j\<Rightarrow>i\<Rightarrow>bool) set" morphisms eval\<Pi>\<^sub>2 make\<Pi>\<^sub>2 .. \<comment> \<open>two place relations\<close> typedef \<Pi>\<^sub>3 = "UNIV::(\<upsilon>\<Rightarrow>\<upsilon>\<Rightarrow>\<upsilon>\<Rightarrow>j\<Rightarrow>i\<Rightarrow>bool) set" morphisms eval\<Pi>\<^sub>3 make\<Pi>\<^sub>3 .. \<comment> \<open>three place relations\<close> type_synonym \<alpha> = "\<Pi>\<^sub>1 set" \<comment> \<open>abstract objects\<close> datatype \<nu> = \<omega>\<nu> \<omega> | \<alpha>\<nu> \<alpha> \<comment> \<open>individuals\<close> typedef \<kappa> = "UNIV::(\<nu> option) set" morphisms eval\<kappa> make\<kappa> .. \<comment> \<open>individual terms\<close> setup_lifting type_definition_\<o> setup_lifting type_definition_\<kappa> setup_lifting type_definition_\<Pi>\<^sub>1 setup_lifting type_definition_\<Pi>\<^sub>2 setup_lifting type_definition_\<Pi>\<^sub>3 subsection\<open>Individual Terms and Definite Descriptions\<close> text\<open>\label{TAO_Embedding_IndividualTerms}\<close> lift_definition \<nu>\<kappa> :: "\<nu>\<Rightarrow>\<kappa>" ("_\<^sup>P" [90] 90) is Some . lift_definition proper :: "\<kappa>\<Rightarrow>bool" is "(\<noteq>) None" . lift_definition rep :: "\<kappa>\<Rightarrow>\<nu>" is the . lift_definition that::"(\<nu>\<Rightarrow>\<o>)\<Rightarrow>\<kappa>" (binder "\<^bold>\<iota>" [8] 9) is "\<lambda> \<phi> . if (\<exists>! x . (\<phi> x) dj dw) then Some (THE x . (\<phi> x) dj dw) else None" . subsection\<open>Mapping from Individuals to Urelements\<close> text\<open>\label{TAO_Embedding_AbstractObjectsToSpecialUrelements}\<close> consts \<alpha>\<sigma> :: "\<alpha>\<Rightarrow>\<sigma>" axiomatization where \<alpha>\<sigma>_surj: "surj \<alpha>\<sigma>" definition \<nu>\<upsilon> :: "\<nu>\<Rightarrow>\<upsilon>" where "\<nu>\<upsilon> \<equiv> case_\<nu> \<omega>\<upsilon> (\<sigma>\<upsilon> \<circ> \<alpha>\<sigma>)" subsection\<open>Exemplification of n-place-Relations.\<close> text\<open>\label{TAO_Embedding_Exemplification}\<close> lift_definition exe0::"\<Pi>\<^sub>0\<Rightarrow>\<o>" ("\<lparr>_\<rparr>") is id . lift_definition exe1::"\<Pi>\<^sub>1\<Rightarrow>\<kappa>\<Rightarrow>\<o>" ("\<lparr>_,_\<rparr>") is "\<lambda> F x s w . (proper x) \<and> F (\<nu>\<upsilon> (rep x)) s w" . lift_definition exe2::"\<Pi>\<^sub>2\<Rightarrow>\<kappa>\<Rightarrow>\<kappa>\<Rightarrow>\<o>" ("\<lparr>_,_,_\<rparr>") is "\<lambda> F x y s w . (proper x) \<and> (proper y) \<and> F (\<nu>\<upsilon> (rep x)) (\<nu>\<upsilon> (rep y)) s w" . lift_definition exe3::"\<Pi>\<^sub>3\<Rightarrow>\<kappa>\<Rightarrow>\<kappa>\<Rightarrow>\<kappa>\<Rightarrow>\<o>" ("\<lparr>_,_,_,_\<rparr>") is "\<lambda> F x y z s w . (proper x) \<and> (proper y) \<and> (proper z) \<and> F (\<nu>\<upsilon> (rep x)) (\<nu>\<upsilon> (rep y)) (\<nu>\<upsilon> (rep z)) s w" . subsection\<open>Encoding\<close> text\<open>\label{TAO_Embedding_Encoding}\<close> lift_definition enc :: "\<kappa>\<Rightarrow>\<Pi>\<^sub>1\<Rightarrow>\<o>" ("\<lbrace>_,_\<rbrace>") is "\<lambda> x F s w . (proper x) \<and> case_\<nu> (\<lambda> \<omega> . False) (\<lambda> \<alpha> . F \<in> \<alpha>) (rep x)" . subsection\<open>Connectives and Quantifiers\<close> text\<open>\label{TAO_Embedding_Connectives}\<close> consts I_NOT :: "j\<Rightarrow>(i\<Rightarrow>bool)\<Rightarrow>i\<Rightarrow>bool" consts I_IMPL :: "j\<Rightarrow>(i\<Rightarrow>bool)\<Rightarrow>(i\<Rightarrow>bool)\<Rightarrow>(i\<Rightarrow>bool)" lift_definition not :: "\<o>\<Rightarrow>\<o>" ("\<^bold>\<not>_" [54] 70) is "\<lambda> p s w . s = dj \<and> \<not>p dj w \<or> s \<noteq> dj \<and> (I_NOT s (p s) w)" . lift_definition impl :: "\<o>\<Rightarrow>\<o>\<Rightarrow>\<o>" (infixl "\<^bold>\<rightarrow>" 51) is "\<lambda> p q s w . s = dj \<and> (p dj w \<longrightarrow> q dj w) \<or> s \<noteq> dj \<and> (I_IMPL s (p s) (q s) w)" . lift_definition forall\<^sub>\<nu> :: "(\<nu>\<Rightarrow>\<o>)\<Rightarrow>\<o>" (binder "\<^bold>\<forall>\<^sub>\<nu>" [8] 9) is "\<lambda> \<phi> s w . \<forall> x :: \<nu> . (\<phi> x) s w" . lift_definition forall\<^sub>0 :: "(\<Pi>\<^sub>0\<Rightarrow>\<o>)\<Rightarrow>\<o>" (binder "\<^bold>\<forall>\<^sub>0" [8] 9) is "\<lambda> \<phi> s w . \<forall> x :: \<Pi>\<^sub>0 . (\<phi> x) s w" . lift_definition forall\<^sub>1 :: "(\<Pi>\<^sub>1\<Rightarrow>\<o>)\<Rightarrow>\<o>" (binder "\<^bold>\<forall>\<^sub>1" [8] 9) is "\<lambda> \<phi> s w . \<forall> x :: \<Pi>\<^sub>1 . (\<phi> x) s w" . lift_definition forall\<^sub>2 :: "(\<Pi>\<^sub>2\<Rightarrow>\<o>)\<Rightarrow>\<o>" (binder "\<^bold>\<forall>\<^sub>2" [8] 9) is "\<lambda> \<phi> s w . \<forall> x :: \<Pi>\<^sub>2 . (\<phi> x) s w" . lift_definition forall\<^sub>3 :: "(\<Pi>\<^sub>3\<Rightarrow>\<o>)\<Rightarrow>\<o>" (binder "\<^bold>\<forall>\<^sub>3" [8] 9) is "\<lambda> \<phi> s w . \<forall> x :: \<Pi>\<^sub>3 . (\<phi> x) s w" . lift_definition forall\<^sub>\<o> :: "(\<o>\<Rightarrow>\<o>)\<Rightarrow>\<o>" (binder "\<^bold>\<forall>\<^sub>\<o>" [8] 9) is "\<lambda> \<phi> s w . \<forall> x :: \<o> . (\<phi> x) s w" . lift_definition box :: "\<o>\<Rightarrow>\<o>" ("\<^bold>\<box>_" [62] 63) is "\<lambda> p s w . \<forall> v . p s v" . lift_definition actual :: "\<o>\<Rightarrow>\<o>" ("\<^bold>\<A>_" [64] 65) is "\<lambda> p s w . p s dw" . text\<open> \begin{remark} The connectives behave classically if evaluated for the actual state @{term "dj"}, whereas their behavior is governed by uninterpreted constants for any other state. \end{remark} \<close> subsection\<open>Lambda Expressions\<close> text\<open>\label{TAO_Embedding_Lambda}\<close> text\<open> \begin{remark} Lambda expressions have to convert maps from individuals to propositions to relations that are represented by maps from urelements to truth values. \end{remark} \<close> lift_definition lambdabinder0 :: "\<o>\<Rightarrow>\<Pi>\<^sub>0" ("\<^bold>\<lambda>\<^sup>0") is id . lift_definition lambdabinder1 :: "(\<nu>\<Rightarrow>\<o>)\<Rightarrow>\<Pi>\<^sub>1" (binder "\<^bold>\<lambda>" [8] 9) is "\<lambda> \<phi> u s w . \<exists> x . \<nu>\<upsilon> x = u \<and> \<phi> x s w" . lift_definition lambdabinder2 :: "(\<nu>\<Rightarrow>\<nu>\<Rightarrow>\<o>)\<Rightarrow>\<Pi>\<^sub>2" ("\<^bold>\<lambda>\<^sup>2") is "\<lambda> \<phi> u v s w . \<exists> x y . \<nu>\<upsilon> x = u \<and> \<nu>\<upsilon> y = v \<and> \<phi> x y s w" . lift_definition lambdabinder3 :: "(\<nu>\<Rightarrow>\<nu>\<Rightarrow>\<nu>\<Rightarrow>\<o>)\<Rightarrow>\<Pi>\<^sub>3" ("\<^bold>\<lambda>\<^sup>3") is "\<lambda> \<phi> u v r s w . \<exists> x y z . \<nu>\<upsilon> x = u \<and> \<nu>\<upsilon> y = v \<and> \<nu>\<upsilon> z = r \<and> \<phi> x y z s w" . subsection\<open>Proper Maps\<close> text\<open>\label{TAO_Embedding_Proper}\<close> text\<open> \begin{remark} The embedding introduces the notion of \emph{proper} maps from individual terms to propositions. Such a map is proper if and only if for all proper individual terms its truth evaluation in the actual state only depends on the urelements corresponding to the individuals the terms denote. Proper maps are exactly those maps that - when used as matrix of a lambda-expression - unconditionally allow beta-reduction. \end{remark} \<close> lift_definition IsProperInX :: "(\<kappa>\<Rightarrow>\<o>)\<Rightarrow>bool" is "\<lambda> \<phi> . \<forall> x v . (\<exists> a . \<nu>\<upsilon> a = \<nu>\<upsilon> x \<and> (\<phi> (a\<^sup>P) dj v)) = (\<phi> (x\<^sup>P) dj v)" . lift_definition IsProperInXY :: "(\<kappa>\<Rightarrow>\<kappa>\<Rightarrow>\<o>)\<Rightarrow>bool" is "\<lambda> \<phi> . \<forall> x y v . (\<exists> a b . \<nu>\<upsilon> a = \<nu>\<upsilon> x \<and> \<nu>\<upsilon> b = \<nu>\<upsilon> y \<and> (\<phi> (a\<^sup>P) (b\<^sup>P) dj v)) = (\<phi> (x\<^sup>P) (y\<^sup>P) dj v)" . lift_definition IsProperInXYZ :: "(\<kappa>\<Rightarrow>\<kappa>\<Rightarrow>\<kappa>\<Rightarrow>\<o>)\<Rightarrow>bool" is "\<lambda> \<phi> . \<forall> x y z v . (\<exists> a b c . \<nu>\<upsilon> a = \<nu>\<upsilon> x \<and> \<nu>\<upsilon> b = \<nu>\<upsilon> y \<and> \<nu>\<upsilon> c = \<nu>\<upsilon> z \<and> (\<phi> (a\<^sup>P) (b\<^sup>P) (c\<^sup>P) dj v)) = (\<phi> (x\<^sup>P) (y\<^sup>P) (z\<^sup>P) dj v)" . subsection\<open>Validity\<close> text\<open>\label{TAO_Embedding_Validity}\<close> lift_definition valid_in :: "i\<Rightarrow>\<o>\<Rightarrow>bool" (infixl "\<Turnstile>" 5) is "\<lambda> v \<phi> . \<phi> dj v" . text\<open> \begin{remark} A formula is considered semantically valid for a possible world, if it evaluates to @{term "True"} for the actual state @{term "dj"} and the given possible world. \end{remark} \<close> subsection\<open>Concreteness\<close> text\<open>\label{TAO_Embedding_Concreteness}\<close> consts ConcreteInWorld :: "\<omega>\<Rightarrow>i\<Rightarrow>bool" abbreviation (input) OrdinaryObjectsPossiblyConcrete where "OrdinaryObjectsPossiblyConcrete \<equiv> \<forall> x . \<exists> v . ConcreteInWorld x v" abbreviation (input) PossiblyContingentObjectExists where "PossiblyContingentObjectExists \<equiv> \<exists> x v . ConcreteInWorld x v \<and> (\<exists> w . \<not> ConcreteInWorld x w)" abbreviation (input) PossiblyNoContingentObjectExists where "PossiblyNoContingentObjectExists \<equiv> \<exists> w . \<forall> x . ConcreteInWorld x w \<longrightarrow> (\<forall> v . ConcreteInWorld x v)" axiomatization where OrdinaryObjectsPossiblyConcreteAxiom: "OrdinaryObjectsPossiblyConcrete" and PossiblyContingentObjectExistsAxiom: "PossiblyContingentObjectExists" and PossiblyNoContingentObjectExistsAxiom: "PossiblyNoContingentObjectExists" text\<open> \begin{remark} Care has to be taken that the defined notion of concreteness coincides with the meta-logical distinction between abstract objects and ordinary objects. Furthermore the axioms about concreteness have to be satisfied. This is achieved by introducing an uninterpreted constant @{term "ConcreteInWorld"} that determines whether an ordinary object is concrete in a given possible world. This constant is axiomatized, such that all ordinary objects are possibly concrete, contingent objects possibly exist and possibly no contingent objects exist. \end{remark} \<close> lift_definition Concrete::"\<Pi>\<^sub>1" ("E!") is "\<lambda> u s w . case u of \<omega>\<upsilon> x \<Rightarrow> ConcreteInWorld x w | _ \<Rightarrow> False" . text\<open> \begin{remark} Concreteness of ordinary objects is now defined using this axiomatized uninterpreted constant. Abstract objects on the other hand are never concrete. \end{remark} \<close> subsection\<open>Collection of Meta-Definitions\<close> text\<open>\label{TAO_Embedding_meta_defs}\<close> named_theorems meta_defs declare not_def[meta_defs] impl_def[meta_defs] forall\<^sub>\<nu>_def[meta_defs] forall\<^sub>0_def[meta_defs] forall\<^sub>1_def[meta_defs] forall\<^sub>2_def[meta_defs] forall\<^sub>3_def[meta_defs] forall\<^sub>\<o>_def[meta_defs] box_def[meta_defs] actual_def[meta_defs] that_def[meta_defs] lambdabinder0_def[meta_defs] lambdabinder1_def[meta_defs] lambdabinder2_def[meta_defs] lambdabinder3_def[meta_defs] exe0_def[meta_defs] exe1_def[meta_defs] exe2_def[meta_defs] exe3_def[meta_defs] enc_def[meta_defs] inv_def[meta_defs] that_def[meta_defs] valid_in_def[meta_defs] Concrete_def[meta_defs] declare [[smt_solver = cvc4]] declare [[simp_depth_limit = 10]] (* prevent the simplifier from running forever *) declare [[unify_search_bound = 40]] (* prevent unification bound errors *) subsection\<open>Auxiliary Lemmata\<close> text\<open>\label{TAO_Embedding_Aux}\<close> named_theorems meta_aux declare make\<kappa>_inverse[meta_aux] eval\<kappa>_inverse[meta_aux] make\<o>_inverse[meta_aux] eval\<o>_inverse[meta_aux] make\<Pi>\<^sub>1_inverse[meta_aux] eval\<Pi>\<^sub>1_inverse[meta_aux] make\<Pi>\<^sub>2_inverse[meta_aux] eval\<Pi>\<^sub>2_inverse[meta_aux] make\<Pi>\<^sub>3_inverse[meta_aux] eval\<Pi>\<^sub>3_inverse[meta_aux] lemma \<nu>\<upsilon>_\<omega>\<nu>_is_\<omega>\<upsilon>[meta_aux]: "\<nu>\<upsilon> (\<omega>\<nu> x) = \<omega>\<upsilon> x" by (simp add: \<nu>\<upsilon>_def) lemma rep_proper_id[meta_aux]: "rep (x\<^sup>P) = x" by (simp add: meta_aux \<nu>\<kappa>_def rep_def) lemma \<nu>\<kappa>_proper[meta_aux]: "proper (x\<^sup>P)" by (simp add: meta_aux \<nu>\<kappa>_def proper_def) lemma no_\<alpha>\<omega>[meta_aux]: "\<not>(\<nu>\<upsilon> (\<alpha>\<nu> x) = \<omega>\<upsilon> y)" by (simp add: \<nu>\<upsilon>_def) lemma no_\<sigma>\<omega>[meta_aux]: "\<not>(\<sigma>\<upsilon> x = \<omega>\<upsilon> y)" by blast lemma \<nu>\<upsilon>_surj[meta_aux]: "surj \<nu>\<upsilon>" using \<alpha>\<sigma>_surj unfolding \<nu>\<upsilon>_def surj_def by (metis \<nu>.simps(5) \<nu>.simps(6) \<upsilon>.exhaust comp_apply) lemma lambda\<Pi>\<^sub>1_aux[meta_aux]: "make\<Pi>\<^sub>1 (\<lambda>u s w. \<exists>x. \<nu>\<upsilon> x = u \<and> eval\<Pi>\<^sub>1 F (\<nu>\<upsilon> x) s w) = F" proof - have "\<And> u s w \<phi> . (\<exists> x . \<nu>\<upsilon> x = u \<and> \<phi> (\<nu>\<upsilon> x) (s::j) (w::i)) \<longleftrightarrow> \<phi> u s w" using \<nu>\<upsilon>_surj unfolding surj_def by metis thus ?thesis apply transfer by simp qed lemma lambda\<Pi>\<^sub>2_aux[meta_aux]: "make\<Pi>\<^sub>2 (\<lambda>u v s w. \<exists>x . \<nu>\<upsilon> x = u \<and> (\<exists> y . \<nu>\<upsilon> y = v \<and> eval\<Pi>\<^sub>2 F (\<nu>\<upsilon> x) (\<nu>\<upsilon> y) s w)) = F" proof - have "\<And> u v (s ::j) (w::i) \<phi> . (\<exists> x . \<nu>\<upsilon> x = u \<and> (\<exists> y . \<nu>\<upsilon> y = v \<and> \<phi> (\<nu>\<upsilon> x) (\<nu>\<upsilon> y) s w)) \<longleftrightarrow> \<phi> u v s w" using \<nu>\<upsilon>_surj unfolding surj_def by metis thus ?thesis apply transfer by simp qed lemma lambda\<Pi>\<^sub>3_aux[meta_aux]: "make\<Pi>\<^sub>3 (\<lambda>u v r s w. \<exists>x. \<nu>\<upsilon> x = u \<and> (\<exists>y. \<nu>\<upsilon> y = v \<and> (\<exists>z. \<nu>\<upsilon> z = r \<and> eval\<Pi>\<^sub>3 F (\<nu>\<upsilon> x) (\<nu>\<upsilon> y) (\<nu>\<upsilon> z) s w))) = F" proof - have "\<And> u v r (s::j) (w::i) \<phi> . \<exists>x. \<nu>\<upsilon> x = u \<and> (\<exists>y. \<nu>\<upsilon> y = v \<and> (\<exists>z. \<nu>\<upsilon> z = r \<and> \<phi> (\<nu>\<upsilon> x) (\<nu>\<upsilon> y) (\<nu>\<upsilon> z) s w)) = \<phi> u v r s w" using \<nu>\<upsilon>_surj unfolding surj_def by metis thus ?thesis apply transfer apply (rule ext)+ by metis qed (*<*) end (*>*)
-- Idris 0.9.20 module Main import data.Vect import Data.List %default total -- Aliases Queen : Type Queen = (Nat, Nat) IsValid : Type IsValid = Bool Valid : IsValid Valid = True Invalid : IsValid Invalid = False Boardsize : Type Boardsize = Nat Queens : Nat -> Type Queens n = Vect n Queen -- Helper methods forAllPairsWithList : List a -> a -> (a -> a -> Bool) -> Bool forAllPairsWithList [] element p = True forAllPairsWithList (x :: xs) element p = if p element x then forAllPairsWithList xs element p else False forAllPairsInList : List a -> (a -> a -> Bool) -> Bool forAllPairsInList [] p = True forAllPairsInList (x :: xs) p = (forAllPairsWithList xs x p) && forAllPairsInList xs p -- NQueens isValidNQueens : {n : Boardsize} -> Queens n -> IsValid isValidNQueens {n=boardsize} queens = let queenList = toList queens isAllOnBoard = all (isOnBoard boardsize) queenList isAllDifferentRows = forAllPairsInList queenList isDifferentRows isAllDifferentCols = forAllPairsInList queenList isDifferentCols isAllDifferentDiags = forAllPairsInList queenList isDifferentDiags in isAllOnBoard && isAllDifferentRows && isAllDifferentCols && isAllDifferentDiags where isOnBoard : Boardsize -> Queen -> Bool isOnBoard boardsize (a, b) = a < boardsize && b < boardsize isDifferentRows : Queen -> Queen -> Bool isDifferentRows (a1, a2) (b1, b2) = a1 /= b1 isDifferentCols : Queen -> Queen -> Bool isDifferentCols (a1, a2) (b1, b2) = a2 /= b2 -- False if they're on the same diagonale looking from 0/0 to n/n; True otherwise isDifferentDiags1 : Queen -> Queen -> Bool isDifferentDiags1 ((S a1), (S a2)) b = assert_total (isDifferentDiags1 (a1, a2) b) -- meh isDifferentDiags1 a ((S b1), (S b2)) = assert_total (isDifferentDiags1 a (b1, b2)) -- meh isDifferentDiags1 (a1, a2) (b1, b2) = if (a1 == b1 && a2 == b2) then False else True -- False if they're on the same diagonale looking from 0/n to n/0; True otherwise isDifferentDiags2 : Queen -> Queen -> Bool isDifferentDiags2 ((S a1), a2) (b1, (S b2)) = assert_total (isDifferentDiags2 (a1, a2) (b1, b2)) -- meh isDifferentDiags2 (a1, (S a2)) ((S b1), b2) = assert_total (isDifferentDiags2 (a1, a2) (b1, b2)) -- meh isDifferentDiags2 (a1, a2) (b1, b2) = if (a1 == b1 && a2 == b2) then False else True isDifferentDiags : Queen -> Queen -> Bool isDifferentDiags a b = (isDifferentDiags1 a b) && (isDifferentDiags2 a b) data NQueens : Boardsize -> IsValid -> Type where MkNQueens : (queens : Queens n) -> NQueens n (isValidNQueens queens) MkInvalidNQueens : (n : Nat) -> NQueens n Invalid instance Show (NQueens n isValid) where show (MkNQueens queens) = if (isValidNQueens queens) then -- meh (show (length queens)) ++ "-Queens " ++ (show queens) else "Invalid " ++ (show (length queens)) ++ "-Queens" show (MkInvalidNQueens n) = "Invalid " ++ (show n) ++ "-Queens" -- (Compile) Tests queen1 : Queen queen1 = (3, 2) queen2 : Queen queen2 = (2, 0) queen3 : Queen queen3 = (1, 3) queen4 : Queen queen4 = (0, 1) nQueens1 : NQueens 1 Valid nQueens1 = MkNQueens [(0, 0)] invalidNQueens1 : NQueens 1 Invalid invalidNQueens1 = MkInvalidNQueens _ nQueens4 : NQueens 4 Valid nQueens4 = MkNQueens [queen1, queen2, queen3, queen4] invalidNQueens4 : NQueens 4 Invalid invalidNQueens4 = MkNQueens [queen1, (3, 3), queen3, queen4] invalidNQueens4b : NQueens 4 Invalid invalidNQueens4b = MkNQueens [(2, 2), (3, 0), queen3, queen4] ---- Does not compile! :-) --invalidNQueens1Error : NQueens 1 Invalid --invalidNQueens1Error = MkNQueens [(0, 0)] --invalidNQueens2Error : NQueens 2 Valid -- Does not even compile as Invalid! --invalidNQueens2Error = MkNQueens [(0, 0)] --invalidNQueens4Error : NQueens 4 Valid --invalidNQueens4Error = MkNQueens [queen1, (3, 3), queen3, queen4]
lemma continuous_onI_mono: fixes f :: "'a::linorder_topology \<Rightarrow> 'b::{dense_order,linorder_topology}" assumes "open (f`A)" and mono: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y" shows "continuous_on A f"
% signed velocity in the direction of the closest fly, according to type function [data,units] = compute_veltoward(trx,n,type) flies = trx.exp2flies{n}; nflies = numel(flies); data = cell(1,nflies); for i1 = 1:nflies, fly1 = flies(i1); % fly closest to fly1 according to type closestfly = trx(fly1).(['closestfly_',type]); % velocity of fly1 dx1 = diff(trx(fly1).x_mm,1,2); dy1 = diff(trx(fly1).y_mm,1,2); x_mm1 = trx(fly1).x_mm; y_mm1 = trx(fly1).y_mm; % loop over all flies for i2 = 1:nflies, fly2 = flies(i2); if i1 == i2, continue; end % frames where this fly is closest idx = find(closestfly(1:end-1) == fly2); % don't use the last frame of fly2 off = trx(fly1).firstframe - trx(fly2).firstframe; idx(idx+off == trx(fly2).nframes) = []; if isempty(idx), continue; end % unit vector in direction of fly2 from fly1 off = trx(fly1).firstframe - trx(fly2).firstframe; dx2 = trx(fly2).x_mm(off+idx)-x_mm1(idx); dy2 = trx(fly2).y_mm(off+idx)-y_mm1(idx); dz2 = sqrt(dx2.^2 + dy2.^2); dx2 = dx2 ./ dz2; dy2 = dy2 ./ dz2; dx2(dz2==0) = 0; dy2(dz2==0) = 0; % project velocity of fly1 onto this vector data{i1}(idx) = dx1(idx).*dx2 + dy1(idx).*dy2; end end units = parseunits('mm/s');
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import tactic.apply import control.fix import order.omega_complete_partial_order /-! # Lawful fixed point operators This module defines the laws required of a `has_fix` instance, using the theory of omega complete partial orders (ωCPO). Proofs of the lawfulness of all `has_fix` instances in `control.fix` are provided. ## Main definition * class `lawful_fix` -/ universes u v open_locale classical variables {α : Type*} {β : α → Type*} open omega_complete_partial_order /-- Intuitively, a fixed point operator `fix` is lawful if it satisfies `fix f = f (fix f)` for all `f`, but this is inconsistent / uninteresting in most cases due to the existence of "exotic" functions `f`, such as the function that is defined iff its argument is not, familiar from the halting problem. Instead, this requirement is limited to only functions that are `continuous` in the sense of `ω`-complete partial orders, which excludes the example because it is not monotone (making the input argument less defined can make `f` more defined). -/ class lawful_fix (α : Type*) [omega_complete_partial_order α] extends has_fix α := (fix_eq : ∀ {f : α →o α}, continuous f → has_fix.fix f = f (has_fix.fix f)) lemma lawful_fix.fix_eq' {α} [omega_complete_partial_order α] [lawful_fix α] {f : α → α} (hf : continuous' f) : has_fix.fix f = f (has_fix.fix f) := lawful_fix.fix_eq (hf.to_bundled _) namespace part open part nat nat.upto namespace fix variables (f : (Π a, part $ β a) →o (Π a, part $ β a)) lemma approx_mono' {i : ℕ} : fix.approx f i ≤ fix.approx f (succ i) := begin induction i, dsimp [approx], apply @bot_le _ _ _ (f ⊥), intro, apply f.monotone, apply i_ih end lemma approx_mono ⦃i j : ℕ⦄ (hij : i ≤ j) : approx f i ≤ approx f j := begin induction j with j ih, { cases hij, exact le_rfl }, cases hij, { exact le_rfl }, exact le_trans (ih ‹_›) (approx_mono' f) end lemma mem_iff (a : α) (b : β a) : b ∈ part.fix f a ↔ ∃ i, b ∈ approx f i a := begin by_cases h₀ : ∃ (i : ℕ), (approx f i a).dom, { simp only [part.fix_def f h₀], split; intro hh, exact ⟨_,hh⟩, have h₁ := nat.find_spec h₀, rw [dom_iff_mem] at h₁, cases h₁ with y h₁, replace h₁ := approx_mono' f _ _ h₁, suffices : y = b, subst this, exact h₁, cases hh with i hh, revert h₁, generalize : (succ (nat.find h₀)) = j, intro, wlog : i ≤ j := le_total i j using [i j b y,j i y b], replace hh := approx_mono f case _ _ hh, apply part.mem_unique h₁ hh }, { simp only [fix_def' ⇑f h₀, not_exists, false_iff, not_mem_none], simp only [dom_iff_mem, not_exists] at h₀, intro, apply h₀ } end lemma approx_le_fix (i : ℕ) : approx f i ≤ part.fix f := assume a b hh, by { rw [mem_iff f], exact ⟨_,hh⟩ } lemma exists_fix_le_approx (x : α) : ∃ i, part.fix f x ≤ approx f i x := begin by_cases hh : ∃ i b, b ∈ approx f i x, { rcases hh with ⟨i,b,hb⟩, existsi i, intros b' h', have hb' := approx_le_fix f i _ _ hb, have hh := part.mem_unique h' hb', subst hh, exact hb }, { simp only [not_exists] at hh, existsi 0, intros b' h', simp only [mem_iff f] at h', cases h' with i h', cases hh _ _ h' } end include f /-- The series of approximations of `fix f` (see `approx`) as a `chain` -/ def approx_chain : chain (Π a, part $ β a) := ⟨approx f, approx_mono f⟩ lemma le_f_of_mem_approx {x} (hx : x ∈ approx_chain f) : x ≤ f x := begin revert hx, simp [(∈)], intros i hx, subst x, apply approx_mono' end lemma approx_mem_approx_chain {i} : approx f i ∈ approx_chain f := stream.mem_of_nth_eq rfl end fix open fix variables {α} variables (f : (Π a, part $ β a) →o (Π a, part $ β a)) open omega_complete_partial_order open part (hiding ωSup) nat open nat.upto omega_complete_partial_order lemma fix_eq_ωSup : part.fix f = ωSup (approx_chain f) := begin apply le_antisymm, { intro x, cases exists_fix_le_approx f x with i hx, transitivity' approx f i.succ x, { transitivity', apply hx, apply approx_mono' f }, apply' le_ωSup_of_le i.succ, dsimp [approx], refl', }, { apply ωSup_le _ _ _, simp only [fix.approx_chain, order_hom.coe_fun_mk], intros y x, apply approx_le_fix f }, end lemma fix_le {X : Π a, part $ β a} (hX : f X ≤ X) : part.fix f ≤ X := begin rw fix_eq_ωSup f, apply ωSup_le _ _ _, simp only [fix.approx_chain, order_hom.coe_fun_mk], intros i, induction i, dsimp [fix.approx], apply' bot_le, transitivity' f X, apply f.monotone i_ih, apply hX end variables {f} (hc : continuous f) include hc lemma fix_eq : part.fix f = f (part.fix f) := begin rw [fix_eq_ωSup f,hc], apply le_antisymm, { apply ωSup_le_ωSup_of_le _, intros i, existsi [i], intro x, -- intros x y hx, apply le_f_of_mem_approx _ ⟨i, rfl⟩, }, { apply ωSup_le_ωSup_of_le _, intros i, existsi i.succ, refl', } end end part namespace part /-- `to_unit` as a monotone function -/ @[simps] def to_unit_mono (f : part α →o part α) : (unit → part α) →o (unit → part α) := { to_fun := λ x u, f (x u), monotone' := λ x y (h : x ≤ y) u, f.monotone $ h u } lemma to_unit_cont (f : part α →o part α) (hc : continuous f) : continuous (to_unit_mono f) | c := begin ext ⟨⟩ : 1, dsimp [omega_complete_partial_order.ωSup], erw [hc, chain.map_comp], refl end noncomputable instance : lawful_fix (part α) := ⟨λ f hc, show part.fix (to_unit_mono f) () = _, by rw part.fix_eq (to_unit_cont f hc); refl⟩ end part open sigma namespace pi noncomputable instance {β} : lawful_fix (α → part β) := ⟨λ f, part.fix_eq⟩ variables {γ : Π a : α, β a → Type*} section monotone variables (α β γ) /-- `sigma.curry` as a monotone function. -/ @[simps] def monotone_curry [∀ x y, preorder $ γ x y] : (Π x : Σ a, β a, γ x.1 x.2) →o (Π a (b : β a), γ a b) := { to_fun := curry, monotone' := λ x y h a b, h ⟨a,b⟩ } /-- `sigma.uncurry` as a monotone function. -/ @[simps] def monotone_uncurry [∀ x y, preorder $ γ x y] : (Π a (b : β a), γ a b) →o (Π x : Σ a, β a, γ x.1 x.2) := { to_fun := uncurry, monotone' := λ x y h a, h a.1 a.2 } variables [∀ x y, omega_complete_partial_order $ γ x y] open omega_complete_partial_order.chain lemma continuous_curry : continuous $ monotone_curry α β γ := λ c, by { ext x y, dsimp [curry,ωSup], rw [map_comp,map_comp], refl } lemma continuous_uncurry : continuous $ monotone_uncurry α β γ := λ c, by { ext x y, dsimp [uncurry,ωSup], rw [map_comp,map_comp], refl } end monotone open has_fix instance [has_fix $ Π x : sigma β, γ x.1 x.2] : has_fix (Π x (y : β x), γ x y) := ⟨ λ f, curry (fix $ uncurry ∘ f ∘ curry) ⟩ variables [∀ x y, omega_complete_partial_order $ γ x y] section curry variables {f : (Π x (y : β x), γ x y) →o (Π x (y : β x), γ x y)} variables (hc : continuous f) lemma uncurry_curry_continuous : continuous $ (monotone_uncurry α β γ).comp $ f.comp $ monotone_curry α β γ := continuous_comp _ _ (continuous_comp _ _ (continuous_curry _ _ _) hc) (continuous_uncurry _ _ _) end curry instance pi.lawful_fix' [lawful_fix $ Π x : sigma β, γ x.1 x.2] : lawful_fix (Π x y, γ x y) := { fix_eq := λ f hc, begin dsimp [fix], conv { to_lhs, erw [lawful_fix.fix_eq (uncurry_curry_continuous hc)] }, refl, end, } end pi
# This file contains the function generator tools to drive other tools of DsSimulator. import UUIDs: uuid4 """ @def_source ex where `ex` is the expression to define to define a new AbstractSource component type. The usage is as follows: ```julia @def_source struct MySource{T1,T2,T3,...,TN,OP, RO} <: AbstractSource param1::T1 = param1_default # optional field param2::T2 = param2_default # optional field param3::T3 = param3_default # optional field ⋮ paramN::TN = paramN_default # optional field output::OP = output_default # mandatory field readout::RO = readout_function # mandatory field end ``` Here, `MySource` has `N` parameters, an `output` port and a `readout` function. !!! warning `output` and `readout` are mandatory fields to define a new source. The rest of the fields are the parameters of the source. !!! warning `readout` must be a single-argument function, i.e. a function of time `t`. !!! warning New source must be a subtype of `AbstractSource` to function properly. # Example ```julia julia> @def_source struct MySource{OP, RO} <: AbstractSource a::Int = 1 b::Float64 = 2. output::OP = Outport() readout::RO = t -> (a + b) * sin(t) end julia> gen = MySource(); julia> gen.a 1 julia> gen.output 1-element Outport{Outpin{Float64}}: Outpin(eltype:Float64, isbound:false) ``` """ macro def_source(ex) ex.args[2].head == :(<:) && ex.args[2].args[2] == :AbstractSource || error("Invalid usage. The type should be a subtype of AbstractSource.\n$ex") foreach(nex -> appendex!(ex, nex), [ :( trigger::$TRIGGER_TYPE_SYMBOL = Inpin() ), :( handshake::$HANDSHAKE_TYPE_SYMBOL = Outpin{Bool}() ), :( callbacks::$CALLBACKS_TYPE_SYMBOL = nothing ), :( name::Symbol = Symbol() ), :( id::$ID_TYPE_SYMBOL = Causal.uuid4() ) ]) quote Base.@kwdef $ex end |> esc end ##### Define Sources library """ $TYPEDEF Constructs a generic function generator with `readout` function and `output` port. # Fields $TYPEDFIELDS # Example ```jldoctest julia> gen = FunctionGenerator(readout = t -> [t, 2t], output = Outport(2)); julia> gen.readout(1.) 2-element Array{Float64,1}: 1.0 2.0 ``` """ @def_source struct FunctionGenerator{RO, OP<:Outport} <: AbstractSource "Readout function" readout::RO "Output port" output::OP = Outport(1) end """ $SIGNATURES Constructs a `SinewaveGenerator` with output of the form ```math x(t) = A sin(2 \\pi f (t - \\tau) + \\phi) + B ``` where ``A`` is `amplitude`, ``f`` is `frequency`, ``\\tau`` is `delay` and ``\\phi`` is `phase` and ``B`` is `offset`. # Fields $TYPEDFIELDS """ @def_source struct SinewaveGenerator{T1 <: Real, T2 <: Real, T3 <: Real, T4 <: Real, T5 <: Real, OP <: Outport, RO} <: AbstractSource "Amplitude" amplitude::T1 = 1. "Frequency" frequency::T2 = 1. "Phase" phase::T3 = 0. "Delay in seconds" delay::T4 = 0. "Offset" offset::T5 = 0. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, amplitude=amplitude, frequency=frequency, delay=delay, offset=offset) -> amplitude * sin(2 * pi * frequency * (t - delay) + phase) + offset end """ $TYPEDEF Constructs a `DampedSinewaveGenerator` which generates outputs of the form ```math x(t) = A e^{\\alpha t} sin(2 \\pi f (t - \\tau) + \\phi) + B ``` where ``A`` is `amplitude`, ``\\alpha`` is `decay`, ``f`` is `frequency`, ``\\phi`` is `phase`, ``\\tau`` is `delay` and ``B`` is `offset`. # Fields $TYPEDFIELDS """ @def_source struct DampedSinewaveGenerator{T1 <: Real, T2 <: Real, T3 <: Real, T4 <: Real, T5 <: Real, T6 <: Real, OP <: Outport, RO} <: AbstractSource "Amplitude" amplitude::T1 = 1. "Attenuation rate" decay::T2 = 0.5 "Frequency" frequency::T3 = 1. "Phase" phase::T4 = 0. "Delay in seconds" delay::T5 = 0. "Offset" offset::T6 = 0. "Output port" output::OP = Outport() "Readout funtion" readout::RO = (t, amplitude=amplitude, decay=decay, frequency=frequency, phase=phase, delay=delay, offset=offset) -> amplitude * exp(decay * t) * sin(2 * pi * frequency * (t - delay)) + offset end """ $TYPEDEF Constructs a `SquarewaveGenerator` with output of the form ```math x(t) = \\left\\{\\begin{array}{lr} A_1 + B, & kT + \\tau \\leq t \\leq (k + \\alpha) T + \\tau \\\\ A_2 + B, & (k + \\alpha) T + \\tau \\leq t \\leq (k + 1) T + \\tau \\end{array} \\right. \\quad k \\in Z ``` where ``A_1``, ``A_2`` is `level1` and `level2`, ``T`` is `period`, ``\\tau`` is `delay` ``\\alpha`` is `duty`. # Fields $TYPEDFIELDS """ @def_source struct SquarewaveGenerator{T1 <: Real, T2 <: Real, T3 <: Real, T4 <: Real, T5 <: Real, OP <: Outport, RO} <: AbstractSource "High level" high::T1 = 1. "Low level" low::T2 = 0. "Period" period::T3 = 1. "Duty cycle given in range (0, 1)" duty::T4 = 0.5 "Delay in seconds" delay::T5 = 0. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, high=high, low=low, period=period, duty=duty, delay=delay) -> t <= delay ? low : ( ((t - delay) % period <= duty * period) ? high : low ) end """ $TYPEDEF Constructs a `TriangularwaveGenerator` with output of the form ```math x(t) = \\left\\{\\begin{array}{lr} \\dfrac{A t}{\\alpha T} + B, & kT + \\tau \\leq t \\leq (k + \\alpha) T + \\tau \\\\[0.25cm] \\dfrac{A (T - t)}{T (1 - \\alpha)} + B, & (k + \\alpha) T + \\tau \\leq t \\leq (k + 1) T + \\tau \\end{array} \\right. \\quad k \\in Z ``` where ``A`` is `amplitude`, ``T`` is `period`, ``\\tau`` is `delay` ``\\alpha`` is `duty`. # Fields $TYPEDFIELDS """ @def_source struct TriangularwaveGenerator{T1 <: Real, T2 <: Real, T3 <: Real, T4 <: Real, T5 <: Real, OP <: Outport, RO} <: AbstractSource "Amplitude" amplitude::T1 = 1. "Period" period::T2 = 1. "Duty cycle" duty::T3 = 0.5 "Delay in seconds" delay::T4 = 0. "Offset" offset::T5 = 0. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, amplitude=amplitude, period=period, duty=duty, delay=delay, offset=offset) -> begin if t <= delay return offset else t = (t - delay) % period if t <= duty * period amplitude / (duty * period) * t + offset else (amplitude * (period - t)) / (period * (1 - duty)) + offset end end end end """ $TYPEDEF Constructs a `ConstantGenerator` with output of the form ```math x(t) = A ``` where ``A`` is `amplitude. # Fields $TYPEDFIELDS """ @def_source struct ConstantGenerator{T1 <: Real, OP <: Outport, RO} <: AbstractSource "Amplitude" amplitude::T1 = 1. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, amplitude=amplitude) -> amplitude end """ $TYPEDEF Constructs a `RampGenerator` with output of the form ```math x(t) = \\alpha (t - \\tau) ``` where ``\\alpha`` is the `scale` and ``\\tau`` is `delay`. # Fields $TYPEDFIELDS """ @def_source struct RampGenerator{T1 <: Real, T2 <: Real, T3 <: Real, OP <: Outport, RO} <: AbstractSource "Scale" scale::T1 = 1. "Delay in seconds" delay::T2 = 0. "Offset" offset::T3 = 0. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, scale=scale, delay=delay, offset=offset) -> scale * (t - delay) + offset end """ $TYPEDEF Constructs a `StepGenerator` with output of the form ```math x(t) = \\left\\{\\begin{array}{lr} B, & t \\leq \\tau \\\\ A + B, & t > \\tau \\end{array} \\right. ``` where ``A`` is `amplitude`, ``B`` is the `offset` and ``\\tau`` is the `delay`. # Fields $TYPEDFIELDS """ @def_source struct StepGenerator{T1 <: Real, T2 <: Real, T3 <: Real, OP <: Outport, RO} <: AbstractSource "Amplitude" amplitude::T1 = 1. "Delay in seconds" delay::T2 = 0. "Offset" offset::T3 = 0. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, amplitude=amplitude, delay=delay, offset=offset) -> t - delay >= 0 ? amplitude + offset : offset end """ $TYPEDEF Constructs an `ExponentialGenerator` with output of the form ```math x(t) = A e^{\\alpha (t - \\tau)} ``` where ``A`` is `scale`, ``\\alpha`` is `decay` and ``\\tau`` is `delay`. # Fields $TYPEDFIELDS """ @def_source struct ExponentialGenerator{T1 <: Real, T2 <: Real, T3 <: Real, T4 <: Real, OP <: Outport, RO} <: AbstractSource "Scale" scale::T1 = 1. "Attenuation decay" decay::T2 = -1. "Delay in seconds" delay::T3 = 0. "Offset" offset::T4 = 0. "Output port" output::OP = Outport() "Readout function" readout::RO = (t, scale=scale, decay=decay, delay=delay, offset=offset) -> scale * exp(decay * (t - delay)) + offset end """ $TYPEDEF Constructs an `DampedExponentialGenerator` with outpsuts of the form ```math x(t) = A (t - \\tau) e^{\\alpha (t - \\tau)} ``` where ``A`` is `scale`, ``\\alpha`` is `decay`, ``\\tau`` is `delay`. # Fields $TYPEDFIELDS """ @def_source struct DampedExponentialGenerator{T1 <: Real, T2 <: Real, T3 <: Real, T4 <: Real, OP <: Outport, RO} <: AbstractSource "Scale" scale::T1 = 1. "Attenuation rate" decay::T2 = -1. "Delay in seconds" delay::T3 = 0. "Offet" offset::T4 = 0. "Output port" output::OP = Outport() "Reaodout function" readout::RO = (t, scale=scale, decay=decay, delay=delay, offset=offset) -> scale * (t - delay) * exp(decay * (t - delay)) + offset end ##### Pretty-Printing of generators. show(io::IO, gen::FunctionGenerator) = print(io, "FunctionGenerator(readout:$(gen.readout), output:$(gen.output))") show(io::IO, gen::SinewaveGenerator) = print(io, "SinewaveGenerator(amp:$(gen.amplitude), freq:$(gen.frequency), phase:$(gen.phase), ", "offset:$(gen.offset), delay:$(gen.delay))") show(io::IO, gen::DampedSinewaveGenerator) = print(io, "DampedSinewaveGenerator(amp:$(gen.amplitude), decay:$(gen.delay), freq:$(gen.frequency), ", "phase:$(gen.phase), delay:$(gen.delay), offset:$(gen.offset))") show(io::IO, gen::SquarewaveGenerator) = print(io, "SquarewaveGenerator(high:$(gen.high), low:$(gen.low), period:$(gen.period), duty:$(gen.duty), ", "delay:$(gen.delay))") show(io::IO, gen::TriangularwaveGenerator) = print(io, "TriangularwaveGenerator(amp:$(gen.amplitude), period:$(gen.period), duty:$(gen.duty), ", "delay:$(gen.delay), offset:$(gen.offset))") show(io::IO, gen::ConstantGenerator) = print(io, "ConstantGenerator(amp:$(gen.amplitude))") show(io::IO, gen::RampGenerator) = print(io, "RampGenerator(scale:$(gen.scale), delay:$(gen.delay))") show(io::IO, gen::StepGenerator) = print(io, "StepGenerator(amp:$(gen.amplitude), delay:$(gen.delay), offset:$(gen.offset))") show(io::IO, gen::ExponentialGenerator) = print(io, "ExponentialGenerator(scale:$(gen.scale), decay:$(gen.decay), delay:$(gen.delay))") show(io::IO, gen::DampedExponentialGenerator) = print(io, "DampedExponentialGenerator(scale:$(gen.scale), decay:$(gen.decay), delay:$(gen.delay))")
get.expectation <- function(mix.par, mu1, mu2){ #Purpose: # compute the expected value of a mixture with # mix proportion = mix.par # means = mu1 and mu2 expected.value <- mix.par*mu1+(1-mix.par)*mu2 return(expected.value) }
import order.filter.basic /- # tendsto Here's an overview of the main definition we're learning today. If `X` and `Y` are types, `φ : X → Y` is a function, and `F : filter X` and `G : filter Y` are filters, then `filter.tendsto φ F G` is a true-false statement, which is pronounced something like "`F` tends to `G` along `φ`". Of course we will `open filter` in this file, so you can just write `tendsto φ F G`, or if you like the dot notation you can even write `F.tendsto φ G`. ## Geometric meaning of `tendsto`. Let's start by thinking about the easy case where `F` and `G` are actually subsets of `X` and `Y` (that is, principal filters, associated to sets which we will also call `F` and `G`). In this case, `tendsto φ F G` simply means "`φ` restricts to a function from `F` to `G`", or in other words `∀ x ∈ F, φ(x) ∈ G`. There are two other ways of writing this predicate. The first involves pushing a set forward along a map. If `F` is a subset of `X` then let `φ(F)` denote the image of `F` under `φ`, that is, the subset `{y : Y | ∃ x : X, φ x = y}` of `Y`. Then `tendsto φ F G` simply means `φ(F) ⊆ G`. The second involves pulling a set back along a map. If `G` is a subset of `Y` then let `φ⁻¹(G)` denote the preimage of `G` under `φ`, that is, the subset `{x : X | φ x ∈ G}` of `Y`. Then `tendsto φ F G` simply means `F ⊆ φ⁻¹(G)`. This is how it all works in the case of sets. What we need to do today is to figure out how to push forward and pull back filters along a map `φ`. Once we have done this, then we can prove `φ(F) ≤ G ↔ F ≤ φ⁻¹(G)` and use either one of these as our definition of `tendsto φ F G` -- it doesn't matter which. ## Digression : adjoint functors. The discussion below is not needed to be able to do this week's problems, but it might provide some helpful background for some. Also note that anyone who still doens't like the word "type" can literally just change it for the word "set" (and change "term of type" to "element of set"), which is how arguments of the below kind would appear in the traditional mathematical literature. Partially ordered types, such as the type of subsets of a fixed type `X` or the type of filters on `X`, are actually very simple examples of categories. In general if `P` is a partially ordered type and `x,y` are terms of type `P` then the idea is that we can define `Hom(x,y)` to have exactly one element if `x ≤ y` is true, and no elements at all if `x ≤ y` is false. The structure/axioms for a category are that `Hom(x,x)` is supposed to have an identity element, which follows from reflexivity of `≤`, and that one can compose morphisms, which follows from transitivity of `≤`. Antisymmetry states that if two objects are isomorphic (i.e., in this case, if `Hom(x,y)` and `Hom(y,x)` are both nonempty), then they are equal. If `φ : X → Y` is a map of types, then pushing forward subsets and pulling back subsets are both functors from `set X` to `set Y`, because `S ⊆ T → φ(S) ⊆ φ(T)` and `U ⊆ V → φ⁻¹(U) ⊆ φ⁻¹(V)`. The statement that `φ(S) ≤ U ↔ S ≤ φ⁻¹(U)` is simply the statement that these functors are adjoint to each other. Today we will define pushforward and pullback of filters, and show that they are also a pair of adjoint functors, but we will not use this language. In fact there is a special language for adjoint functors in this simple situation: we will say that pushforward and pullback form a Galois connection. -/ /- ## Warm-up: pushing forward and pulling back subsets. Say `X` and `Y` are types, and `f : X → Y`. -/ variables (X Y : Type) (f : X → Y) /- ### images In Lean, the image `f(S)` of a subset `S : set X` cannot be denoted `f S`, because `f` expects an _element_ of `X` as an input, not a subset of `X`, so we need new notation. Notation : `f '' S` is the image of `S` under `f`. Let's check this. -/ example (S : set X) : f '' S = {y : Y | ∃ x : X, x ∈ S ∧ f x = y} := begin -- true by definition refl end /- ### preimages In Lean, the preimage `f⁻¹(T)` of a subset `T : set Y` cannot be denoted `f⁻¹ T` because `⁻¹` is the inverse notation in group theory, so if anything would be a function from `Y` to `X`, not a function on subsets of `Y`. Notation : `f ⁻¹' T` is the preimage of `T` under `f`. Let's check this. Pro shortcut: `\-'` for `⁻¹'` -/ example (T : set Y) : f ⁻¹' T = {x : X | f x ∈ T} := begin -- true by definition refl end /- I claim that the following conditions on `S : set X` and `T : set Y` are equivalent: 1) `f '' S ⊆ T` 2) `S ⊆ f⁻¹' T` Indeed, they both say that `f` restricts to a function from `S` to `T`. Let's check this. You might find `mem_preimage : a ∈ f ⁻¹' s ↔ f a ∈ s` and -/ open set example (S : set X) (T : set Y) : f '' S ⊆ T ↔ S ⊆ f⁻¹' T := begin sorry, end /- ## Pushing forward filters. Pushing forward is easy, so let's do that first. It's called `filter.map` in Lean. We define the pushforward filter `map f F` on `Y` to be the obvious thing: a subset of `Y` is in the filter iff `f⁻¹(Y)` is in `F`. Let's check this is a filter. Reminder of some helpful lemmas: In `set`: `mem_set_of_eq : a ∈ {x : α | p x} = p a` -- definitional In `filter`: `univ_mem_sets : univ ∈ F` `mem_sets_of_superset : S ∈ F → S ⊆ T → T ∈ F` `inter_mem_sets : S ∈ F → T ∈ F → S ∩ T ∈ F` -/ open filter -- this is called `F.map f` or `filter.map f F` -- or just `map f F` if `filter` is open. example (F : filter X) : filter Y := { sets := {T : set Y | f ⁻¹' T ∈ F }, univ_sets := begin sorry end, sets_of_superset := begin sorry, end, inter_sets := begin sorry end, } -- this is `filter.mem_map` and it's true by definition. -- It's useful in the form `rw mem_map` if you want to figure out -- what's going on in a proof, but often you'll find you can -- delete it at the end. example (F : filter X) (T : set Y) : T ∈ F.map f ↔ f ⁻¹' T ∈ F := begin -- true by definition refl end -- Let's check that `map` satisfies some basic functorialities. -- Recall that if your goal is to check two filters are -- equal then you can use the `ext` tactic, e.g. with `ext S`. -- pushing along the identity map id : X → X doesn't change the filter. -- this is `filter.map_id` but see if you can prove it yourself. example (F : filter X) : F.map id = F := begin sorry end -- pushing along g ∘ f is the same as pushing along f and then g -- for some reason this isn't in mathlib, instead they have `map_map` which -- has the equality the other way. variables (Z : Type) (g : Y → Z) -- this isn't in mathlib, but `filter.map_map` is the equality the other -- way around. See if you can prove it yourself. example (F : filter X) : F.map (g ∘ f) = (F.map f).map g := begin sorry, end open_locale filter -- for 𝓟 notation -- pushing the principal filter `𝓟 S` along `f` gives `𝓟 (f '' S)` -- this is `filter.map_principal` but see if you can prove it yourself. example (S : set X) : (𝓟 S).map f = 𝓟 (f '' S) := begin sorry, end /- ## tendsto The definition: if `f : X → Y` and `F : filter X` and `G : filter Y` then `tendsto f F G : Prop := map f F ≤ G`. It's pronounced something like "`F` tends to `G` along `f`". This is a *definition* (it has type `Prop`), not the proof of a theorem. It is a true-false statement attached to `f`, `F` and `G`, it's a bit like saying "f is continuous at x" or something like that, it might be true and it might be false. The mental model you might want to have of the definition is that `tendsto f F G` means that the function `f` restricts to a function from the generalized set `F` to the generalized set `G`. -/ -- this is `filter.tendsto_def` example (F : filter X) (G : filter Y) : tendsto f F G ↔ ∀ T : set Y, T ∈ G → f ⁻¹' T ∈ F := begin -- true by definition refl end -- Let's make a basic API for `tendsto` -- this is `tendsto_id` but see if you can prove it yourself. example (F : filter X) : tendsto id F F := begin sorry, end -- this is `tendsto.comp` but see if you can prove it yourself example (F : filter X) (G : filter Y) (H : filter Z) (f : X → Y) (g : Y → Z) (hf : tendsto f F G) (hg : tendsto g G H) : tendsto (g ∘ f) F H := begin sorry, end -- I would recommend looking at the model answer to this one if -- you get stuck. lemma tendsto_comp_map (g : Y → Z) (F : filter X) (G : filter Z) : tendsto (g ∘ f) F G ↔ tendsto g (F.map f) G := begin sorry, end /- ## Pulling back filters We don't use this in the next part. Say `f : X → Y` and `G : filter Y`, and we want a filter on `X`. Let's make a naive definition. We want a collection of subsets of `X` corresponding to the filter obtained by pulling back `G` along `f`. When should `S : set X` be in this filter? Perhaps it is when `f '' S ∈ G`. However, there is no reason that the collection of `S` satisfying this property should be a filter on `X`. For example, there is no reason to espect that `f '' univ ∈ G` if `f` is not surjective. Our naive guess doesn't work. Here's a way of fixing this, by coming up with a less naive guess which is informed by our mental model. Remember that our model of a filter `G` is some kind of generalised notion of a set. If `T : set Y` then `T ∈ G` is supposed to mean that the "set" `G` is a subset of `T`. So this should imply that `f⁻¹(G) ⊆ f⁻¹(T)`. In particular, if `T ∈ G` and `f⁻¹(T) ⊆ S` then this should mean `f⁻¹(G) ⊆ S` and hence `S ∈ f⁻¹(G)`. Let's try this condition (defining `S ∈ f⁻¹(G)` to mean `∃ T ∈ G, f⁻¹(T) ⊆ S`) and see if it works. Random useful lemmas (you might be getting to the point where you can guess the names of the lemmas): `subset_univ S : S ⊆ univ` `subset.trans : A ⊆ B → B ⊆ C → A ⊆ C` -/ -- this is called filter.comap example (G : filter Y) : filter X := { sets := {S : set X | ∃ T ∈ G, f ⁻¹' T ⊆ S}, univ_sets := begin sorry end, sets_of_superset := begin sorry end, inter_sets := begin sorry end } -- Let's call this mem_comap lemma mem_comap (f : X → Y) (G : filter Y) (S : set X) : S ∈ comap f G ↔ ∃ T ∈ G, f ⁻¹' T ⊆ S := begin -- true by definition refl end -- If you want to, you can check some preliminary properties of `comap`. -- this is comap_id example (G : filter Y) : comap id G = G := begin sorry end -- this is comap_comap but the other way around lemma comap_comp (H : filter Z) : comap (g ∘ f) H = comap f (comap g H) := begin sorry end -- this is comap_principal. Remember `mem_principal_sets`! It's true by definition... example (T : set Y) : comap f (𝓟 T) = 𝓟 (f ⁻¹' T) := begin sorry end -- This is the proof that `map f` and `comap f` are adjoint functors, -- or in other words form a Galois connection. It is the "generalised set" -- analogue of the assertion that if S is a subset of X and T is a subset of Y -- then f(S) ⊆ T ↔ S ⊆ f⁻¹(T), these both being ways to say that `f` restricts -- to a function from `S` to `T`. lemma filter.galois_connection (F : filter X) (G : filter Y) : map f F ≤ G ↔ F ≤ comap f G := begin sorry, end -- indeed, `map f` and `comap f` form a Galois connection. example : galois_connection (map f) (comap f) := filter.galois_connection X Y f
import Base: LineEdit, REPL mutable struct SQLCompletionProvider <: LineEdit.CompletionProvider l::REPL.LineEditREPL end function return_callback(p::LineEdit.PromptState) # TODO ... something less dumb buf = take!(copy(LineEdit.buffer(p))) # local sp = 0 # for c in buf # c == '(' && (sp += 1; continue) # c == ')' && (sp -= 1; continue) # end # sp <= 0 return true end function evaluate_sql(s::String) global odbcdf global dsn try odbcdf = ODBC.query(dsn, s) catch e println(STDOUT, "error during sql evaluation: ", e) return nothing end println(STDOUT, odbcdf) end function setup_repl(enabled::Bool) # bail out if we don't have a repl !isdefined(Base, :active_repl) && return repl = Base.active_repl main_mode = Base.active_repl.interface.modes[1] # disable repl if requested if (!enabled) delete!(main_mode.keymap_dict, ']') return end panel = LineEdit.Prompt("sql> "; prompt_prefix = Base.text_colors[:white], prompt_suffix = main_mode.prompt_suffix, on_enter = return_callback) hp = main_mode.hist hp.mode_mapping[:sql] = panel panel.hist = hp panel.on_done = REPL.respond(evaluate_sql, repl, panel; pass_empty = false) panel.complete = nothing sql_keymap = Dict{Any,Any}( ']' => function (s,args...) if isempty(s) || position(LineEdit.buffer(s)) == 0 buf = copy(LineEdit.buffer(s)) LineEdit.transition(s, panel) do LineEdit.state(s, panel).input_buffer = buf end else LineEdit.edit_insert(s, ']') end end) search_prompt, skeymap = LineEdit.setup_search_keymap(hp) mk = REPL.mode_keymap(main_mode) b = Dict{Any,Any}[skeymap, mk, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults] panel.keymap_dict = LineEdit.keymap(b) main_mode.keymap_dict = LineEdit.keymap_merge(main_mode.keymap_dict, sql_keymap) nothing end toggle_sql_repl(; enabled::Bool = true) = setup_repl(enabled)
-- 2011-04-12 AIM XIII fixed this issue by freezing metas after declaration (Andreas & Ulf) module Issue399 where open import Common.Prelude data Maybe (A : Set) : Set where nothing : Maybe A just : A → Maybe A -- now in Common.Prelude -- _++_ : {A : Set} → List A → List A → List A -- [] ++ ys = ys -- (x ∷ xs) ++ ys = x ∷ (xs ++ ys) record MyMonadPlus m : Set₁ where field mzero : {a : Set} → m a → List a mplus : {a : Set} → m a → m a → List a -- this produces an unsolved meta variable, because it is not clear which -- level m has. m could be in Set -> Set or in Set -> Set1 -- if you uncomment the rest of the files, you get unsolved metas here {- Old error, without freezing: --Emacs error: and the 10th line is the above line --/home/j/dev/apps/haskell/agda/learn/bug-in-record.agda:10,36-39 --Set != Set₁ --when checking that the expression m a has type Set₁ -} mymaybemzero : {a : Set} → Maybe a → List a mymaybemzero nothing = [] mymaybemzero (just x) = x ∷ [] mymaybemplus : {a : Set} → Maybe a → Maybe a → List a mymaybemplus x y = (mymaybemzero x) ++ (mymaybemzero y) -- the following def gives a type error because of unsolved metas in MyMonadPlus -- if you uncomment it, you see m in MyMonadPlus yellow mymaybeMonadPlus : MyMonadPlus Maybe mymaybeMonadPlus = record { mzero = mymaybemzero ; mplus = mymaybemplus }
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import combinatorics.simple_graph.basic import data.finset.pairwise /-! # Graph cliques This file defines cliques in simple graphs. A clique is a set of vertices that are pairwise adjacent. ## Main declarations * `simple_graph.is_clique`: Predicate for a set of vertices to be a clique. * `simple_graph.is_n_clique`: Predicate for a set of vertices to be a `n`-clique. * `simple_graph.clique_finset`: Finset of `n`-cliques of a graph. * `simple_graph.clique_free`: Predicate for a graph to have no `n`-cliques. ## TODO * Clique numbers * Going back and forth between cliques and complete subgraphs or embeddings of complete graphs. * Do we need `clique_set`, a version of `clique_finset` for infinite graphs? -/ open finset fintype namespace simple_graph variables {α : Type*} (G H : simple_graph α) /-! ### Cliques -/ section clique variables {s t : set α} /-- A clique in a graph is a set of vertices that are pairwise adjacent. -/ abbreviation is_clique (s : set α) : Prop := s.pairwise G.adj lemma is_clique_iff : G.is_clique s ↔ s.pairwise G.adj := iff.rfl instance [decidable_eq α] [decidable_rel G.adj] {s : finset α} : decidable (G.is_clique s) := decidable_of_iff' _ G.is_clique_iff variables {G H} lemma is_clique.mono (h : G ≤ H) : G.is_clique s → H.is_clique s := by { simp_rw is_clique_iff, exact set.pairwise.mono' h } lemma is_clique.subset (h : t ⊆ s) : G.is_clique s → G.is_clique t := by { simp_rw is_clique_iff, exact set.pairwise.mono h } @[simp] lemma is_clique_bot_iff : (⊥ : simple_graph α).is_clique s ↔ (s : set α).subsingleton := set.pairwise_bot_iff alias is_clique_bot_iff ↔ simple_graph.is_clique.subsingleton _ end clique /-! ### `n`-cliques -/ section n_clique variables {n : ℕ} {s : finset α} /-- A `n`-clique in a graph is a set of `n` vertices which are pairwise connected. -/ structure is_n_clique (n : ℕ) (s : finset α) : Prop := (clique : G.is_clique s) (card_eq : s.card = n) lemma is_n_clique_iff : G.is_n_clique n s ↔ G.is_clique s ∧ s.card = n := ⟨λ h, ⟨h.1, h.2⟩, λ h, ⟨h.1, h.2⟩⟩ instance [decidable_eq α] [decidable_rel G.adj] {n : ℕ} {s : finset α} : decidable (G.is_n_clique n s) := decidable_of_iff' _ G.is_n_clique_iff variables {G H} lemma is_n_clique.mono (h : G ≤ H) : G.is_n_clique n s → H.is_n_clique n s := by { simp_rw is_n_clique_iff, exact and.imp_left (is_clique.mono h) } @[simp] lemma is_n_clique_bot_iff : (⊥ : simple_graph α).is_n_clique n s ↔ n ≤ 1 ∧ s.card = n := begin rw [is_n_clique_iff, is_clique_bot_iff], refine and_congr_left _, rintro rfl, exact card_le_one.symm, end variables [decidable_eq α] {a b c : α} lemma is_3_clique_triple_iff : G.is_n_clique 3 {a, b, c} ↔ G.adj a b ∧ G.adj a c ∧ G.adj b c := begin simp only [is_n_clique_iff, is_clique_iff, set.pairwise_insert_of_symmetric G.symm, coe_insert], have : ¬ 1 + 1 = 3 := by norm_num, by_cases hab : a = b; by_cases hbc : b = c; by_cases hac : a = c; subst_vars; simp [G.ne_of_adj, and_rotate, *], end lemma is_3_clique_iff : G.is_n_clique 3 s ↔ ∃ a b c, G.adj a b ∧ G.adj a c ∧ G.adj b c ∧ s = {a, b, c} := begin refine ⟨λ h, _, _⟩, { obtain ⟨a, b, c, -, -, -, rfl⟩ := card_eq_three.1 h.card_eq, refine ⟨a, b, c, _⟩, rw is_3_clique_triple_iff at h, tauto }, { rintro ⟨a, b, c, hab, hbc, hca, rfl⟩, exact is_3_clique_triple_iff.2 ⟨hab, hbc, hca⟩ } end end n_clique /-! ### Graphs without cliques -/ section clique_free variables {m n : ℕ} /-- `G.clique_free n` means that `G` has no `n`-cliques. -/ def clique_free (n : ℕ) : Prop := ∀ t, ¬ G.is_n_clique n t variables {G H} lemma clique_free_bot (h : 2 ≤ n) : (⊥ : simple_graph α).clique_free n := begin rintro t ht, rw is_n_clique_bot_iff at ht, linarith, end lemma clique_free.mono (h : m ≤ n) : G.clique_free m → G.clique_free n := begin rintro hG s hs, obtain ⟨t, hts, ht⟩ := s.exists_smaller_set _ (h.trans hs.card_eq.ge), exact hG _ ⟨hs.clique.subset hts, ht⟩, end lemma clique_free.anti (h : G ≤ H) : H.clique_free n → G.clique_free n := forall_imp $ λ s, mt $ is_n_clique.mono h end clique_free /-! ### Set of cliques -/ section clique_set variables (G) {n : ℕ} {a b c : α} {s : finset α} /-- The `n`-cliques in a graph as a set. -/ def clique_set (n : ℕ) : set (finset α) := {s | G.is_n_clique n s} lemma mem_clique_set_iff : s ∈ G.clique_set n ↔ G.is_n_clique n s := iff.rfl @[simp] lemma clique_set_eq_empty_iff : G.clique_set n = ∅ ↔ G.clique_free n := by simp_rw [clique_free, set.eq_empty_iff_forall_not_mem, mem_clique_set_iff] alias clique_set_eq_empty_iff ↔ _ simple_graph.clique_free.clique_set attribute [protected] clique_free.clique_set variables {G H} @[mono] lemma clique_set_mono (h : G ≤ H) : G.clique_set n ⊆ H.clique_set n := λ _, is_n_clique.mono h lemma clique_set_mono' (h : G ≤ H) : G.clique_set ≤ H.clique_set := λ _, clique_set_mono h end clique_set /-! ### Finset of cliques -/ section clique_finset variables (G) [fintype α] [decidable_eq α] [decidable_rel G.adj] {n : ℕ} {a b c : α} {s : finset α} /-- The `n`-cliques in a graph as a finset. -/ def clique_finset (n : ℕ) : finset (finset α) := univ.filter $ G.is_n_clique n lemma mem_clique_finset_iff : s ∈ G.clique_finset n ↔ G.is_n_clique n s := mem_filter.trans $ and_iff_right $ mem_univ _ @[simp] lemma coe_clique_finset (n : ℕ) : (G.clique_finset n : set (finset α)) = G.clique_set n := set.ext $ λ _, mem_clique_finset_iff _ @[simp] lemma clique_finset_eq_empty_iff : G.clique_finset n = ∅ ↔ G.clique_free n := by simp_rw [clique_free, eq_empty_iff_forall_not_mem, mem_clique_finset_iff] alias clique_finset_eq_empty_iff ↔ _ simple_graph.clique_free.clique_finset attribute [protected] clique_free.clique_finset variables {G} [decidable_rel H.adj] @[mono] lemma clique_finset_mono (h : G ≤ H) : G.clique_finset n ⊆ H.clique_finset n := monotone_filter_right _ $ λ _, is_n_clique.mono h end clique_finset end simple_graph
[STATEMENT] lemma msgrel_imp_eqv_freeright_aux: shows "freeright U \<sim> freeright U" [PROOF STATE] proof (prove) goal (1 subgoal): 1. freeright U \<sim> freeright U [PROOF STEP] by (fact msgrel_refl)
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import order.complete_lattice import order.cover import order.iterate /-! # Successor and predecessor > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `fin n`, but also `enat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `succ_order`: Order equipped with a sensible successor function. * `pred_order`: Order equipped with a sensible predecessor function. * `is_succ_archimedean`: `succ_order` where `succ` iterated to an element gives all the greater ones. * `is_pred_archimedean`: `pred_order` where `pred` iterated to an element gives all the smaller ones. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class naive_succ_order (α : Type*) [preorder α] := (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `order_top` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `succ_order α` and `no_max_order α`. ## TODO Is `galois_connection pred succ` always true? If not, we should introduce ```lean class succ_pred_order (α : Type*) [preorder α] extends succ_order α, pred_order α := (pred_succ_gc : galois_connection (pred : α → α) succ) ``` `covby` should help here. -/ open function order_dual set variables {α : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class succ_order (α : Type*) [preorder α] := (succ : α → α) (le_succ : ∀ a, a ≤ succ a) (max_of_succ_le {a} : succ a ≤ a → is_max a) (succ_le_of_lt {a b} : a < b → succ a ≤ b) (le_of_lt_succ {a b} : a < succ b → a ≤ b) /-- Order equipped with a sensible predecessor function. -/ @[ext] class pred_order (α : Type*) [preorder α] := (pred : α → α) (pred_le : ∀ a, pred a ≤ a) (min_of_le_pred {a} : a ≤ pred a → is_min a) (le_pred_of_lt {a b} : a < b → a ≤ pred b) (le_of_pred_lt {a b} : pred a < b → a ≤ b) instance [preorder α] [succ_order α] : pred_order αᵒᵈ := { pred := to_dual ∘ succ_order.succ ∘ of_dual, pred_le := succ_order.le_succ, min_of_le_pred := λ _, succ_order.max_of_succ_le, le_pred_of_lt := λ a b h, succ_order.succ_le_of_lt h, le_of_pred_lt := λ a b, succ_order.le_of_lt_succ } instance [preorder α] [pred_order α] : succ_order αᵒᵈ := { succ := to_dual ∘ pred_order.pred ∘ of_dual, le_succ := pred_order.pred_le, max_of_succ_le := λ _, pred_order.min_of_le_pred, succ_le_of_lt := λ a b h, pred_order.le_pred_of_lt h, le_of_lt_succ := λ a b, pred_order.le_of_pred_lt } section preorder variables [preorder α] /-- A constructor for `succ_order α` usable when `α` has no maximal element. -/ def succ_order.of_succ_le_iff_of_le_lt_succ (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (hle_of_lt_succ : ∀ {a b}, a < succ b → a ≤ b) : succ_order α := { succ := succ, le_succ := λ a, (hsucc_le_iff.1 le_rfl).le, max_of_succ_le := λ a ha, (lt_irrefl a $ hsucc_le_iff.1 ha).elim, succ_le_of_lt := λ a b, hsucc_le_iff.2, le_of_lt_succ := λ a b, hle_of_lt_succ } /-- A constructor for `pred_order α` usable when `α` has no minimal element. -/ def pred_order.of_le_pred_iff_of_pred_le_pred (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) (hle_of_pred_lt : ∀ {a b}, pred a < b → a ≤ b) : pred_order α := { pred := pred, pred_le := λ a, (hle_pred_iff.1 le_rfl).le, min_of_le_pred := λ a ha, (lt_irrefl a $ hle_pred_iff.1 ha).elim, le_pred_of_lt := λ a b, hle_pred_iff.2, le_of_pred_lt := λ a b, hle_of_pred_lt } end preorder section linear_order variables [linear_order α] /-- A constructor for `succ_order α` for `α` a linear order. -/ @[simps] def succ_order.of_core (succ : α → α) (hn : ∀ {a}, ¬ is_max a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, is_max a → succ a = a) : succ_order α := { succ := succ, succ_le_of_lt := λ a b, classical.by_cases (λ h hab, (hm a h).symm ▸ hab.le) (λ h, (hn h b).mp), le_succ := λ a, classical.by_cases (λ h, (hm a h).symm.le) (λ h, le_of_lt $ by simpa using (hn h a).not), le_of_lt_succ := λ a b hab, classical.by_cases (λ h, hm b h ▸ hab.le) (λ h, by simpa [hab] using (hn h a).not), max_of_succ_le := λ a, not_imp_not.mp $ λ h, by simpa using (hn h a).not } /-- A constructor for `pred_order α` for `α` a linear order. -/ @[simps] def pred_order.of_core {α} [linear_order α] (pred : α → α) (hn : ∀ {a}, ¬ is_min a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, is_min a → pred a = a) : pred_order α := { pred := pred, le_pred_of_lt := λ a b, classical.by_cases (λ h hab, (hm b h).symm ▸ hab.le) (λ h, (hn h a).mpr), pred_le := λ a, classical.by_cases (λ h, (hm a h).le) (λ h, le_of_lt $ by simpa using (hn h a).not), le_of_pred_lt := λ a b hab, classical.by_cases (λ h, hm a h ▸ hab.le) (λ h, by simpa [hab] using (hn h b).not), min_of_le_pred := λ a, not_imp_not.mp $ λ h, by simpa using (hn h a).not } /-- A constructor for `succ_order α` usable when `α` is a linear order with no maximal element. -/ def succ_order.of_succ_le_iff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : succ_order α := { succ := succ, le_succ := λ a, (hsucc_le_iff.1 le_rfl).le, max_of_succ_le := λ a ha, (lt_irrefl a $ hsucc_le_iff.1 ha).elim, succ_le_of_lt := λ a b, hsucc_le_iff.2, le_of_lt_succ := λ a b h, le_of_not_lt ((not_congr hsucc_le_iff).1 h.not_le) } /-- A constructor for `pred_order α` usable when `α` is a linear order with no minimal element. -/ def pred_order.of_le_pred_iff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : pred_order α := { pred := pred, pred_le := λ a, (hle_pred_iff.1 le_rfl).le, min_of_le_pred := λ a ha, (lt_irrefl a $ hle_pred_iff.1 ha).elim, le_pred_of_lt := λ a b, hle_pred_iff.2, le_of_pred_lt := λ a b h, le_of_not_lt ((not_congr hle_pred_iff).1 h.not_le) } end linear_order /-! ### Successor order -/ namespace order section preorder variables [preorder α] [succ_order α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := succ_order.succ lemma le_succ : ∀ a : α, a ≤ succ a := succ_order.le_succ lemma max_of_succ_le {a : α} : succ a ≤ a → is_max a := succ_order.max_of_succ_le lemma succ_le_of_lt {a b : α} : a < b → succ a ≤ b := succ_order.succ_le_of_lt lemma le_of_lt_succ {a b : α} : a < succ b → a ≤ b := succ_order.le_of_lt_succ @[simp] lemma succ_le_iff_is_max : succ a ≤ a ↔ is_max a := ⟨max_of_succ_le, λ h, h $ le_succ _⟩ @[simp] lemma lt_succ_iff_not_is_max : a < succ a ↔ ¬ is_max a := ⟨not_is_max_of_lt, λ ha, (le_succ a).lt_of_not_le $ λ h, ha $ max_of_succ_le h⟩ alias lt_succ_iff_not_is_max ↔ _ lt_succ_of_not_is_max lemma wcovby_succ (a : α) : a ⩿ succ a := ⟨le_succ a, λ b hb, (succ_le_of_lt hb).not_lt⟩ lemma covby_succ_of_not_is_max (h : ¬ is_max a) : a ⋖ succ a := (wcovby_succ a).covby_of_lt $ lt_succ_of_not_is_max h lemma lt_succ_iff_of_not_is_max (ha : ¬ is_max a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, λ h, h.trans_lt $ lt_succ_of_not_is_max ha⟩ lemma succ_le_iff_of_not_is_max (ha : ¬ is_max a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_is_max ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_iff_of_not_is_max (ha : ¬ is_max a) (hb : ¬ is_max b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_is_max hb, succ_le_iff_of_not_is_max ha] lemma succ_le_succ_iff_of_not_is_max (ha : ¬ is_max a) (hb : ¬ is_max b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_is_max ha, lt_succ_iff_of_not_is_max hb] @[simp, mono] lemma succ_le_succ (h : a ≤ b) : succ a ≤ succ b := begin by_cases hb : is_max b, { by_cases hba : b ≤ a, { exact (hb $ hba.trans $ le_succ _).trans (le_succ _) }, { exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le $ le_succ b) } }, { rwa [succ_le_iff_of_not_is_max (λ ha, hb $ ha.mono h), lt_succ_iff_of_not_is_max hb] } end lemma succ_mono : monotone (succ : α → α) := λ a b, succ_le_succ lemma le_succ_iterate (k : ℕ) (x : α) : x ≤ (succ^[k] x) := begin conv_lhs { rw (by simp only [function.iterate_id, id.def] : x = (id^[k] x)) }, exact monotone.le_iterate_of_le succ_mono le_succ k x, end lemma is_max_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : (succ^[n] a) = (succ^[m] a)) (h_lt : n < m) : is_max (succ^[n] a) := begin refine max_of_succ_le (le_trans _ h_eq.symm.le), have : succ (succ^[n] a) = (succ^[n + 1] a), by rw function.iterate_succ', rw this, have h_le : n + 1 ≤ m := nat.succ_le_of_lt h_lt, exact monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le, end lemma is_max_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : (succ^[n] a) = (succ^[m] a)) (h_ne : n ≠ m) : is_max (succ^[n] a) := begin cases le_total n m, { exact is_max_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne), }, { rw h_eq, exact is_max_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm), }, end lemma Iio_succ_of_not_is_max (ha : ¬ is_max a) : Iio (succ a) = Iic a := set.ext $ λ x, lt_succ_iff_of_not_is_max ha lemma Ici_succ_of_not_is_max (ha : ¬ is_max a) : Ici (succ a) = Ioi a := set.ext $ λ x, succ_le_iff_of_not_is_max ha lemma Ioo_succ_right_of_not_is_max (hb : ¬ is_max b) : Ioo a (succ b) = Ioc a b := by rw [←Ioi_inter_Iio, Iio_succ_of_not_is_max hb, Ioi_inter_Iic] lemma Icc_succ_left_of_not_is_max (ha : ¬ is_max a) : Icc (succ a) b = Ioc a b := by rw [←Ici_inter_Iic, Ici_succ_of_not_is_max ha, Ioi_inter_Iic] lemma Ico_succ_left_of_not_is_max (ha : ¬ is_max a) : Ico (succ a) b = Ioo a b := by rw [←Ici_inter_Iio, Ici_succ_of_not_is_max ha, Ioi_inter_Iio] section no_max_order variables [no_max_order α] lemma lt_succ (a : α) : a < succ a := lt_succ_of_not_is_max $ not_is_max a @[simp] lemma lt_succ_iff : a < succ b ↔ a ≤ b := lt_succ_iff_of_not_is_max $ not_is_max b @[simp] lemma succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_is_max $ not_is_max a lemma succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp lemma succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp alias succ_le_succ_iff ↔ le_of_succ_le_succ _ alias succ_lt_succ_iff ↔ lt_of_succ_lt_succ succ_lt_succ lemma succ_strict_mono : strict_mono (succ : α → α) := λ a b, succ_lt_succ lemma covby_succ (a : α) : a ⋖ succ a := covby_succ_of_not_is_max $ not_is_max a @[simp] lemma Iio_succ (a : α) : Iio (succ a) = Iic a := Iio_succ_of_not_is_max $ not_is_max _ @[simp] lemma Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_is_max $ not_is_max _ @[simp] lemma Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b := Ico_succ_right_of_not_is_max $ not_is_max _ @[simp] lemma Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b := Ioo_succ_right_of_not_is_max $ not_is_max _ @[simp] lemma Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_is_max $ not_is_max _ @[simp] lemma Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_is_max $ not_is_max _ end no_max_order end preorder section partial_order variables [partial_order α] [succ_order α] {a b : α} @[simp] lemma succ_eq_iff_is_max : succ a = a ↔ is_max a := ⟨λ h, max_of_succ_le h.le, λ h, h.eq_of_ge $ le_succ _⟩ alias succ_eq_iff_is_max ↔ _ _root_.is_max.succ_eq lemma succ_eq_succ_iff_of_not_is_max (ha : ¬ is_max a) (hb : ¬ is_max b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_is_max ha hb, succ_lt_succ_iff_of_not_is_max ha hb] lemma le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := begin refine ⟨λ h, or_iff_not_imp_left.2 $ λ hba : b ≠ a, h.2.antisymm (succ_le_of_lt $ h.1.lt_of_ne $ hba.symm), _⟩, rintro (rfl | rfl), { exact ⟨le_rfl, le_succ b⟩ }, { exact ⟨le_succ a, le_rfl⟩ } end lemma _root_.covby.succ_eq (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).eq_of_not_lt $ λ h', h.2 (lt_succ_of_not_is_max h.lt.not_is_max) h' lemma _root_.wcovby.le_succ (h : a ⩿ b) : b ≤ succ a := begin obtain h | rfl := h.covby_or_eq, { exact h.succ_eq.ge }, { exact le_succ _ } end lemma le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := begin by_cases hb : is_max b, { rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] }, { rw [←lt_succ_iff_of_not_is_max hb, le_iff_eq_or_lt] } end lemma lt_succ_iff_eq_or_lt_of_not_is_max (hb : ¬ is_max b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_is_max hb).trans le_iff_eq_or_lt lemma Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) := ext $ λ _, le_succ_iff_eq_or_le lemma Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by simp_rw [←Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)] lemma Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by simp_rw [←Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)] lemma Iio_succ_eq_insert_of_not_is_max (h : ¬is_max a) : Iio (succ a) = insert a (Iio a) := ext $ λ _, lt_succ_iff_eq_or_lt_of_not_is_max h lemma Ico_succ_right_eq_insert_of_not_is_max (h₁ : a ≤ b) (h₂ : ¬is_max b) : Ico a (succ b) = insert b (Ico a b) := by simp_rw [←Iio_inter_Ici, Iio_succ_eq_insert_of_not_is_max h₂, insert_inter_of_mem (mem_Ici.2 h₁)] lemma Ioo_succ_right_eq_insert_of_not_is_max (h₁ : a < b) (h₂ : ¬is_max b) : Ioo a (succ b) = insert b (Ioo a b) := by simp_rw [←Iio_inter_Ioi, Iio_succ_eq_insert_of_not_is_max h₂, insert_inter_of_mem (mem_Ioi.2 h₁)] section no_max_order variables [no_max_order α] @[simp] lemma succ_eq_succ_iff : succ a = succ b ↔ a = b := succ_eq_succ_iff_of_not_is_max (not_is_max a) (not_is_max b) lemma succ_injective : injective (succ : α → α) := λ a b, succ_eq_succ_iff.1 lemma succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b := succ_injective.ne_iff alias succ_ne_succ_iff ↔ _ succ_ne_succ lemma lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b := lt_succ_iff.trans le_iff_eq_or_lt lemma succ_eq_iff_covby : succ a = b ↔ a ⋖ b := ⟨by { rintro rfl, exact covby_succ _ }, covby.succ_eq⟩ lemma Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) := Iio_succ_eq_insert_of_not_is_max $ not_is_max a lemma Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) := Ico_succ_right_eq_insert_of_not_is_max h $ not_is_max b lemma Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) := Ioo_succ_right_eq_insert_of_not_is_max h $ not_is_max b end no_max_order section order_top variables [order_top α] @[simp] lemma succ_top : succ (⊤ : α) = ⊤ := is_max_top.succ_eq @[simp] lemma succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_is_max.trans is_max_iff_eq_top @[simp] lemma lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_is_max.trans not_is_max_iff_ne_top end order_top section order_bot variable [order_bot α] @[simp] lemma lt_succ_bot_iff [no_max_order α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff] lemma le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm] variable [nontrivial α] lemma bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_is_max not_is_max_bot).trans_le $ succ_mono bot_le lemma succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' end order_bot end partial_order /-- There is at most one way to define the successors in a `partial_order`. -/ instance [partial_order α] : subsingleton (succ_order α) := ⟨begin introsI h₀ h₁, ext a, by_cases ha : is_max a, { exact (@is_max.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm }, { exact @covby.succ_eq _ _ h₀ _ _ (covby_succ_of_not_is_max ha) } end⟩ section complete_lattice variables [complete_lattice α] [succ_order α] lemma succ_eq_infi (a : α) : succ a = ⨅ b (h : a < b), b := begin refine le_antisymm (le_infi (λ b, le_infi succ_le_of_lt)) _, obtain rfl | ha := eq_or_ne a ⊤, { rw succ_top, exact le_top }, exact infi₂_le _ (lt_succ_iff_ne_top.2 ha), end end complete_lattice /-! ### Predecessor order -/ section preorder variables [preorder α] [pred_order α] {a b : α} /-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less than `a`. If `a` is minimal, then `pred a = a`. -/ def pred : α → α := pred_order.pred lemma pred_le : ∀ a : α, pred a ≤ a := pred_order.pred_le lemma min_of_le_pred {a : α} : a ≤ pred a → is_min a := pred_order.min_of_le_pred lemma le_pred_of_lt {a b : α} : a < b → a ≤ pred b := pred_order.le_pred_of_lt lemma le_of_pred_lt {a b : α} : pred a < b → a ≤ b := pred_order.le_of_pred_lt @[simp] lemma le_pred_iff_is_min : a ≤ pred a ↔ is_min a := ⟨min_of_le_pred, λ h, h $ pred_le _⟩ @[simp] lemma pred_lt_iff_not_is_min : pred a < a ↔ ¬ is_min a := ⟨not_is_min_of_lt, λ ha, (pred_le a).lt_of_not_le $ λ h, ha $ min_of_le_pred h⟩ alias pred_lt_iff_not_is_min ↔ _ pred_lt_of_not_is_min lemma pred_wcovby (a : α) : pred a ⩿ a := ⟨pred_le a, λ b hb, (le_of_pred_lt hb).not_lt⟩ lemma pred_covby_of_not_is_min (h : ¬ is_min a) : pred a ⋖ a := (pred_wcovby a).covby_of_lt $ pred_lt_of_not_is_min h lemma pred_lt_iff_of_not_is_min (ha : ¬ is_min a) : pred a < b ↔ a ≤ b := ⟨le_of_pred_lt, (pred_lt_of_not_is_min ha).trans_le⟩ lemma le_pred_iff_of_not_is_min (ha : ¬ is_min a) : b ≤ pred a ↔ b < a := ⟨λ h, h.trans_lt $ pred_lt_of_not_is_min ha, le_pred_of_lt⟩ @[simp, mono] lemma pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b := succ_le_succ h.dual lemma pred_mono : monotone (pred : α → α) := λ a b, pred_le_pred lemma pred_iterate_le (k : ℕ) (x : α) : (pred^[k] x) ≤ x := begin conv_rhs { rw (by simp only [function.iterate_id, id.def] : x = (id^[k] x)) }, exact monotone.iterate_le_of_le pred_mono pred_le k x, end lemma is_min_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : (pred^[n] a) = (pred^[m] a)) (h_lt : n < m) : is_min (pred^[n] a) := @is_max_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt lemma is_min_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : (pred^[n] a) = (pred^[m] a)) (h_ne : n ≠ m) : is_min (pred^[n] a) := @is_max_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne lemma Ioi_pred_of_not_is_min (ha : ¬ is_min a) : Ioi (pred a) = Ici a := set.ext $ λ x, pred_lt_iff_of_not_is_min ha lemma Iic_pred_of_not_is_min (ha : ¬ is_min a) : Iic (pred a) = Iio a := set.ext $ λ x, le_pred_iff_of_not_is_min ha lemma Ioc_pred_left_of_not_is_min (ha : ¬ is_min a) : Ioc (pred a) b = Icc a b := by rw [←Ioi_inter_Iic, Ioi_pred_of_not_is_min ha, Ici_inter_Iic] lemma Ioo_pred_left_of_not_is_min (ha : ¬ is_min a) : Ioo (pred a) b = Ico a b := by rw [←Ioi_inter_Iio, Ioi_pred_of_not_is_min ha, Ici_inter_Iio] lemma Icc_pred_right_of_not_is_min (ha : ¬ is_min b) : Icc a (pred b) = Ico a b := by rw [←Ici_inter_Iic, Iic_pred_of_not_is_min ha, Ici_inter_Iio] lemma Ioc_pred_right_of_not_is_min (ha : ¬ is_min b) : Ioc a (pred b) = Ioo a b := by rw [←Ioi_inter_Iic, Iic_pred_of_not_is_min ha, Ioi_inter_Iio] section no_min_order variables [no_min_order α] lemma pred_lt (a : α) : pred a < a := pred_lt_of_not_is_min $ not_is_min a @[simp] lemma pred_lt_iff : pred a < b ↔ a ≤ b := pred_lt_iff_of_not_is_min $ not_is_min a @[simp] lemma le_pred_iff : a ≤ pred b ↔ a < b := le_pred_iff_of_not_is_min $ not_is_min b lemma pred_le_pred_iff : pred a ≤ pred b ↔ a ≤ b := by simp lemma pred_lt_pred_iff : pred a < pred b ↔ a < b := by simp alias pred_le_pred_iff ↔ le_of_pred_le_pred _ alias pred_lt_pred_iff ↔ lt_of_pred_lt_pred pred_lt_pred lemma pred_strict_mono : strict_mono (pred : α → α) := λ a b, pred_lt_pred lemma pred_covby (a : α) : pred a ⋖ a := pred_covby_of_not_is_min $ not_is_min a @[simp] lemma Ioi_pred (a : α) : Ioi (pred a) = Ici a := Ioi_pred_of_not_is_min $ not_is_min a @[simp] lemma Iic_pred (a : α) : Iic (pred a) = Iio a := Iic_pred_of_not_is_min $ not_is_min a @[simp] lemma Ioc_pred_left (a b : α) : Ioc (pred a) b = Icc a b := Ioc_pred_left_of_not_is_min $ not_is_min _ @[simp] lemma Ioo_pred_left (a b : α) : Ioo (pred a) b = Ico a b := Ioo_pred_left_of_not_is_min $ not_is_min _ @[simp] lemma Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b := Icc_pred_right_of_not_is_min $ not_is_min _ @[simp] lemma Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b := Ioc_pred_right_of_not_is_min $ not_is_min _ end no_min_order end preorder section partial_order variables [partial_order α] [pred_order α] {a b : α} @[simp] lemma pred_eq_iff_is_min : pred a = a ↔ is_min a := ⟨λ h, min_of_le_pred h.ge, λ h, h.eq_of_le $ pred_le _⟩ alias pred_eq_iff_is_min ↔ _ _root_.is_min.pred_eq lemma pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := begin refine ⟨λ h, or_iff_not_imp_left.2 $ λ hba : b ≠ a, (le_pred_of_lt $ h.2.lt_of_ne hba).antisymm h.1, _⟩, rintro (rfl | rfl), { exact ⟨pred_le b, le_rfl⟩ }, { exact ⟨le_rfl, pred_le a⟩ } end lemma _root_.covby.pred_eq {a b : α} (h : a ⋖ b) : pred b = a := (le_pred_of_lt h.lt).eq_of_not_gt $ λ h', h.2 h' $ pred_lt_of_not_is_min h.lt.not_is_min lemma _root_.wcovby.pred_le (h : a ⩿ b) : pred b ≤ a := begin obtain h | rfl := h.covby_or_eq, { exact h.pred_eq.le }, { exact pred_le _ } end lemma pred_le_iff_eq_or_le : pred a ≤ b ↔ b = pred a ∨ a ≤ b := begin by_cases ha : is_min a, { rw [ha.pred_eq, or_iff_right_of_imp ge_of_eq] }, { rw [←pred_lt_iff_of_not_is_min ha, le_iff_eq_or_lt, eq_comm] } end lemma pred_lt_iff_eq_or_lt_of_not_is_min (ha : ¬ is_min a) : pred a < b ↔ a = b ∨ a < b := (pred_lt_iff_of_not_is_min ha).trans le_iff_eq_or_lt lemma Ici_pred (a : α) : Ici (pred a) = insert (pred a) (Ici a) := ext $ λ _, pred_le_iff_eq_or_le lemma Ioi_pred_eq_insert_of_not_is_min (ha : ¬ is_min a) : Ioi (pred a) = insert a (Ioi a) := begin ext x, simp only [insert, mem_set_of, @eq_comm _ x a], exact pred_lt_iff_eq_or_lt_of_not_is_min ha end lemma Icc_pred_left (h : pred a ≤ b) : Icc (pred a) b = insert (pred a) (Icc a b) := by simp_rw [←Ici_inter_Iic, Ici_pred, insert_inter_of_mem (mem_Iic.2 h)] lemma Ico_pred_left (h : pred a < b) : Ico (pred a) b = insert (pred a) (Ico a b) := by simp_rw [←Ici_inter_Iio, Ici_pred, insert_inter_of_mem (mem_Iio.2 h)] section no_min_order variables [no_min_order α] @[simp] lemma pred_eq_pred_iff : pred a = pred b ↔ a = b := by simp_rw [eq_iff_le_not_lt, pred_le_pred_iff, pred_lt_pred_iff] lemma pred_injective : injective (pred : α → α) := λ a b, pred_eq_pred_iff.1 lemma pred_ne_pred_iff : pred a ≠ pred b ↔ a ≠ b := pred_injective.ne_iff alias pred_ne_pred_iff ↔ _ pred_ne_pred lemma pred_lt_iff_eq_or_lt : pred a < b ↔ a = b ∨ a < b := pred_lt_iff.trans le_iff_eq_or_lt lemma pred_eq_iff_covby : pred b = a ↔ a ⋖ b := ⟨by { rintro rfl, exact pred_covby _ }, covby.pred_eq⟩ lemma Ioi_pred_eq_insert (a : α) : Ioi (pred a) = insert a (Ioi a) := ext $ λ _, pred_lt_iff_eq_or_lt.trans $ or_congr_left' eq_comm lemma Ico_pred_right_eq_insert (h : a ≤ b) : Ioc (pred a) b = insert a (Ioc a b) := by simp_rw [←Ioi_inter_Iic, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iic.2 h)] lemma Ioo_pred_right_eq_insert (h : a < b) : Ioo (pred a) b = insert a (Ioo a b) := by simp_rw [←Ioi_inter_Iio, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iio.2 h)] end no_min_order section order_bot variables [order_bot α] @[simp] lemma pred_bot : pred (⊥ : α) = ⊥ := is_min_bot.pred_eq @[simp] lemma le_pred_iff_eq_bot : a ≤ pred a ↔ a = ⊥ := @succ_le_iff_eq_top αᵒᵈ _ _ _ _ @[simp] lemma pred_lt_iff_ne_bot : pred a < a ↔ a ≠ ⊥ := @lt_succ_iff_ne_top αᵒᵈ _ _ _ _ end order_bot section order_top variable [order_top α] @[simp] lemma pred_top_lt_iff [no_min_order α] : pred ⊤ < a ↔ a = ⊤ := @lt_succ_bot_iff αᵒᵈ _ _ _ _ _ lemma pred_top_le_iff : pred ⊤ ≤ a ↔ a = ⊤ ∨ a = pred ⊤ := @le_succ_bot_iff αᵒᵈ _ _ _ _ variable [nontrivial α] lemma pred_lt_top (a : α) : pred a < ⊤ := (pred_mono le_top).trans_lt $ pred_lt_of_not_is_min not_is_min_top lemma pred_ne_top (a : α) : pred a ≠ ⊤ := (pred_lt_top a).ne end order_top end partial_order /-- There is at most one way to define the predecessors in a `partial_order`. -/ instance [partial_order α] : subsingleton (pred_order α) := ⟨begin introsI h₀ h₁, ext a, by_cases ha : is_min a, { exact (@is_min.pred_eq _ _ h₀ _ ha).trans ha.pred_eq.symm }, { exact @covby.pred_eq _ _ h₀ _ _ (pred_covby_of_not_is_min ha) } end⟩ section complete_lattice variables [complete_lattice α] [pred_order α] lemma pred_eq_supr (a : α) : pred a = ⨆ b (h : b < a), b := begin refine le_antisymm _ (supr_le (λ b, supr_le le_pred_of_lt)), obtain rfl | ha := eq_or_ne a ⊥, { rw pred_bot, exact bot_le }, { exact @le_supr₂ _ _ (λ b, b < a) _ (λ a _, a) (pred a) (pred_lt_iff_ne_bot.2 ha) } end end complete_lattice /-! ### Successor-predecessor orders -/ section succ_pred_order variables [partial_order α] [succ_order α] [pred_order α] {a b : α} @[simp] lemma succ_pred_of_not_is_min (h : ¬ is_min a) : succ (pred a) = a := (pred_covby_of_not_is_min h).succ_eq @[simp] lemma pred_succ_of_not_is_max (h : ¬ is_max a) : pred (succ a) = a := (covby_succ_of_not_is_max h).pred_eq @[simp] lemma succ_pred [no_min_order α] (a : α) : succ (pred a) = a := (pred_covby _).succ_eq @[simp] lemma pred_succ [no_max_order α] (a : α) : pred (succ a) = a := (covby_succ _).pred_eq lemma pred_succ_iterate_of_not_is_max (i : α) (n : ℕ) (hin : ¬ is_max (succ^[n-1] i)) : pred^[n] (succ^[n] i) = i := begin induction n with n hn, { simp only [function.iterate_zero, id.def], }, rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at hin, have h_not_max : ¬ is_max (succ^[n - 1] i), { cases n, { simpa using hin, }, rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at hn ⊢, have h_sub_le : (succ^[n] i) ≤ (succ^[n.succ] i), { rw function.iterate_succ', exact le_succ _, }, refine λ h_max, hin (λ j hj, _), have hj_le : j ≤ (succ^[n] i) := h_max (h_sub_le.trans hj), exact hj_le.trans h_sub_le, }, rw [function.iterate_succ, function.iterate_succ'], simp only [function.comp_app], rw pred_succ_of_not_is_max hin, exact hn h_not_max, end lemma succ_pred_iterate_of_not_is_min (i : α) (n : ℕ) (hin : ¬ is_min (pred^[n-1] i)) : succ^[n] (pred^[n] i) = i := @pred_succ_iterate_of_not_is_max αᵒᵈ _ _ _ i n hin end succ_pred_order end order open order /-! ### `with_bot`, `with_top` Adding a greatest/least element to a `succ_order` or to a `pred_order`. As far as successors and predecessors are concerned, there are four ways to add a bottom or top element to an order: * Adding a `⊤` to an `order_top`: Preserves `succ` and `pred`. * Adding a `⊤` to a `no_max_order`: Preserves `succ`. Never preserves `pred`. * Adding a `⊥` to an `order_bot`: Preserves `succ` and `pred`. * Adding a `⊥` to a `no_min_order`: Preserves `pred`. Never preserves `succ`. where "preserves `(succ/pred)`" means `(succ/pred)_order α → (succ/pred)_order ((with_top/with_bot) α)`. -/ namespace with_top /-! #### Adding a `⊤` to an `order_top` -/ section succ variables [decidable_eq α] [partial_order α] [order_top α] [succ_order α] instance : succ_order (with_top α) := { succ := λ a, match a with | ⊤ := ⊤ | (some a) := ite (a = ⊤) ⊤ (some (succ a)) end, le_succ := λ a, begin cases a, { exact le_top }, change _ ≤ ite _ _ _, split_ifs, { exact le_top }, { exact some_le_some.2 (le_succ a) } end, max_of_succ_le := λ a ha, begin cases a, { exact is_max_top }, change ite _ _ _ ≤ _ at ha, split_ifs at ha with ha', { exact (not_top_le_coe _ ha).elim }, { rw [some_le_some, succ_le_iff_eq_top] at ha, exact (ha' ha).elim } end, succ_le_of_lt := λ a b h, begin cases b, { exact le_top }, cases a, { exact (not_top_lt h).elim }, rw some_lt_some at h, change ite _ _ _ ≤ _, split_ifs with ha, { rw ha at h, exact (not_top_lt h).elim }, { exact some_le_some.2 (succ_le_of_lt h) } end, le_of_lt_succ := λ a b h, begin cases a, { exact (not_top_lt h).elim }, cases b, { exact le_top }, change _ < ite _ _ _ at h, rw some_le_some, split_ifs at h with hb, { rw hb, exact le_top }, { exact le_of_lt_succ (some_lt_some.1 h) } end } @[simp] lemma succ_coe_top : succ ↑(⊤ : α) = (⊤ : with_top α) := dif_pos rfl lemma succ_coe_of_ne_top {a : α} (h : a ≠ ⊤) : succ (↑a : with_top α) = ↑(succ a) := dif_neg h end succ section pred variables [preorder α] [order_top α] [pred_order α] instance : pred_order (with_top α) := { pred := λ a, match a with | ⊤ := some ⊤ | (some a) := some (pred a) end, pred_le := λ a, match a with | ⊤ := le_top | (some a) := some_le_some.2 (pred_le a) end, min_of_le_pred := λ a ha, begin cases a, { exact ((coe_lt_top (⊤ : α)).not_le ha).elim }, { exact (min_of_le_pred $ some_le_some.1 ha).with_top } end, le_pred_of_lt := λ a b h, begin cases a, { exact ((le_top).not_lt h).elim }, cases b, { exact some_le_some.2 le_top }, exact some_le_some.2 (le_pred_of_lt $ some_lt_some.1 h), end, le_of_pred_lt := λ a b h, begin cases b, { exact le_top }, cases a, { exact (not_top_lt $ some_lt_some.1 h).elim }, { exact some_le_some.2 (le_of_pred_lt $ some_lt_some.1 h) } end } @[simp] lemma pred_top : pred (⊤ : with_top α) = ↑(⊤ : α) := rfl @[simp] lemma pred_coe (a : α) : pred (↑a : with_top α) = ↑(pred a) := rfl @[simp] lemma pred_untop : ∀ (a : with_top α) (ha : a ≠ ⊤), pred (a.untop ha) = (pred a).untop (by induction a using with_top.rec_top_coe; simp) | ⊤ ha := (ha rfl).elim | (a : α) ha := rfl end pred /-! #### Adding a `⊤` to a `no_max_order` -/ section succ variables [preorder α] [no_max_order α] [succ_order α] instance succ_order_of_no_max_order : succ_order (with_top α) := { succ := λ a, match a with | ⊤ := ⊤ | (some a) := some (succ a) end, le_succ := λ a, begin cases a, { exact le_top }, { exact some_le_some.2 (le_succ a) } end, max_of_succ_le := λ a ha, begin cases a, { exact is_max_top }, { exact (not_is_max _ $ max_of_succ_le $ some_le_some.1 ha).elim } end, succ_le_of_lt := λ a b h, begin cases a, { exact (not_top_lt h).elim }, cases b, { exact le_top}, { exact some_le_some.2 (succ_le_of_lt $ some_lt_some.1 h) } end, le_of_lt_succ := λ a b h, begin cases a, { exact (not_top_lt h).elim }, cases b, { exact le_top }, { exact some_le_some.2 (le_of_lt_succ $ some_lt_some.1 h) } end } @[simp] lemma succ_coe (a : α) : succ (↑a : with_top α) = ↑(succ a) := rfl end succ section pred variables [preorder α] [no_max_order α] instance [hα : nonempty α] : is_empty (pred_order (with_top α)) := ⟨begin introI, cases h : pred (⊤ : with_top α) with a ha, { exact hα.elim (λ a, (min_of_le_pred h.ge).not_lt $ coe_lt_top a) }, { obtain ⟨c, hc⟩ := exists_gt a, rw [←some_lt_some, ←h] at hc, exact (le_of_pred_lt hc).not_lt (some_lt_none _) } end⟩ end pred end with_top namespace with_bot /-! #### Adding a `⊥` to an `order_bot` -/ section succ variables [preorder α] [order_bot α] [succ_order α] instance : succ_order (with_bot α) := { succ := λ a, match a with | ⊥ := some ⊥ | (some a) := some (succ a) end, le_succ := λ a, match a with | ⊥ := bot_le | (some a) := some_le_some.2 (le_succ a) end, max_of_succ_le := λ a ha, begin cases a, { exact ((none_lt_some (⊥ : α)).not_le ha).elim }, { exact (max_of_succ_le $ some_le_some.1 ha).with_bot } end, succ_le_of_lt := λ a b h, begin cases b, { exact (not_lt_bot h).elim }, cases a, { exact some_le_some.2 bot_le }, { exact some_le_some.2 (succ_le_of_lt $ some_lt_some.1 h) } end, le_of_lt_succ := λ a b h, begin cases a, { exact bot_le }, cases b, { exact (not_lt_bot $ some_lt_some.1 h).elim }, { exact some_le_some.2 (le_of_lt_succ $ some_lt_some.1 h) } end } @[simp] lemma succ_bot : succ (⊥ : with_bot α) = ↑(⊥ : α) := rfl @[simp] lemma succ_coe (a : α) : succ (↑a : with_bot α) = ↑(succ a) := rfl @[simp] lemma succ_unbot : ∀ (a : with_bot α) (ha : a ≠ ⊥), succ (a.unbot ha) = (succ a).unbot (by induction a using with_bot.rec_bot_coe; simp) | ⊥ ha := (ha rfl).elim | (a : α) ha := rfl end succ section pred variables [decidable_eq α] [partial_order α] [order_bot α] [pred_order α] instance : pred_order (with_bot α) := { pred := λ a, match a with | ⊥ := ⊥ | (some a) := ite (a = ⊥) ⊥ (some (pred a)) end, pred_le := λ a, begin cases a, { exact bot_le }, change ite _ _ _ ≤ _, split_ifs, { exact bot_le }, { exact some_le_some.2 (pred_le a) } end, min_of_le_pred := λ a ha, begin cases a, { exact is_min_bot }, change _ ≤ ite _ _ _ at ha, split_ifs at ha with ha', { exact (not_coe_le_bot _ ha).elim }, { rw [some_le_some, le_pred_iff_eq_bot] at ha, exact (ha' ha).elim } end, le_pred_of_lt := λ a b h, begin cases a, { exact bot_le }, cases b, { exact (not_lt_bot h).elim }, rw some_lt_some at h, change _ ≤ ite _ _ _, split_ifs with hb, { rw hb at h, exact (not_lt_bot h).elim }, { exact some_le_some.2 (le_pred_of_lt h) } end, le_of_pred_lt := λ a b h, begin cases b, { exact (not_lt_bot h).elim }, cases a, { exact bot_le }, change ite _ _ _ < _ at h, rw some_le_some, split_ifs at h with ha, { rw ha, exact bot_le }, { exact le_of_pred_lt (some_lt_some.1 h) } end } @[simp] lemma pred_coe_bot : pred ↑(⊥ : α) = (⊥ : with_bot α) := dif_pos rfl lemma pred_coe_of_ne_bot {a : α} (h : a ≠ ⊥) : pred (↑a : with_bot α) = ↑(pred a) := dif_neg h end pred /-! #### Adding a `⊥` to a `no_min_order` -/ section succ variables [preorder α] [no_min_order α] instance [hα : nonempty α] : is_empty (succ_order (with_bot α)) := ⟨begin introI, cases h : succ (⊥ : with_bot α) with a ha, { exact hα.elim (λ a, (max_of_succ_le h.le).not_lt $ bot_lt_coe a) }, { obtain ⟨c, hc⟩ := exists_lt a, rw [←some_lt_some, ←h] at hc, exact (le_of_lt_succ hc).not_lt (none_lt_some _) } end⟩ end succ section pred variables [preorder α] [no_min_order α] [pred_order α] instance pred_order_of_no_min_order : pred_order (with_bot α) := { pred := λ a, match a with | ⊥ := ⊥ | (some a) := some (pred a) end, pred_le := λ a, begin cases a, { exact bot_le }, { exact some_le_some.2 (pred_le a) } end, min_of_le_pred := λ a ha, begin cases a, { exact is_min_bot }, { exact (not_is_min _ $ min_of_le_pred $ some_le_some.1 ha).elim } end, le_pred_of_lt := λ a b h, begin cases b, { exact (not_lt_bot h).elim }, cases a, { exact bot_le }, { exact some_le_some.2 (le_pred_of_lt $ some_lt_some.1 h) } end, le_of_pred_lt := λ a b h, begin cases b, { exact (not_lt_bot h).elim }, cases a, { exact bot_le }, { exact some_le_some.2 (le_of_pred_lt $ some_lt_some.1 h) } end } @[simp] lemma pred_coe (a : α) : pred (↑a : with_bot α) = ↑(pred a) := rfl end pred end with_bot /-! ### Archimedeanness -/ /-- A `succ_order` is succ-archimedean if one can go from any two comparable elements by iterating `succ` -/ class is_succ_archimedean (α : Type*) [preorder α] [succ_order α] : Prop := (exists_succ_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, succ^[n] a = b) /-- A `pred_order` is pred-archimedean if one can go from any two comparable elements by iterating `pred` -/ class is_pred_archimedean (α : Type*) [preorder α] [pred_order α] : Prop := (exists_pred_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, pred^[n] b = a) export is_succ_archimedean (exists_succ_iterate_of_le) export is_pred_archimedean (exists_pred_iterate_of_le) section preorder variables [preorder α] section succ_order variables [succ_order α] [is_succ_archimedean α] {a b : α} instance : is_pred_archimedean αᵒᵈ := ⟨λ a b h, by convert exists_succ_iterate_of_le h.of_dual⟩ lemma has_le.le.exists_succ_iterate (h : a ≤ b) : ∃ n, succ^[n] a = b := exists_succ_iterate_of_le h lemma exists_succ_iterate_iff_le : (∃ n, succ^[n] a = b) ↔ a ≤ b := begin refine ⟨_, exists_succ_iterate_of_le⟩, rintro ⟨n, rfl⟩, exact id_le_iterate_of_id_le le_succ n a, end /-- Induction principle on a type with a `succ_order` for all elements above a given element `m`. -/ @[elab_as_eliminator] lemma succ.rec {P : α → Prop} {m : α} (h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (succ n)) ⦃n : α⦄ (hmn : m ≤ n) : P n := begin obtain ⟨n, rfl⟩ := hmn.exists_succ_iterate, clear hmn, induction n with n ih, { exact h0 }, { rw [function.iterate_succ_apply'], exact h1 _ (id_le_iterate_of_id_le le_succ n m) ih } end lemma succ.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) {a b : α} (h : a ≤ b) : p a ↔ p b := begin obtain ⟨n, rfl⟩ := h.exists_succ_iterate, exact iterate.rec (λ b, p a ↔ p b) (λ c hc, hc.trans (hsucc _)) iff.rfl n, end end succ_order section pred_order variables [pred_order α] [is_pred_archimedean α] {a b : α} instance : is_succ_archimedean αᵒᵈ := ⟨λ a b h, by convert exists_pred_iterate_of_le h.of_dual⟩ lemma has_le.le.exists_pred_iterate (h : a ≤ b) : ∃ n, pred^[n] b = a := exists_pred_iterate_of_le h lemma exists_pred_iterate_iff_le : (∃ n, pred^[n] b = a) ↔ a ≤ b := @exists_succ_iterate_iff_le αᵒᵈ _ _ _ _ _ /-- Induction principle on a type with a `pred_order` for all elements below a given element `m`. -/ @[elab_as_eliminator] lemma pred.rec {P : α → Prop} {m : α} (h0 : P m) (h1 : ∀ n, n ≤ m → P n → P (pred n)) ⦃n : α⦄ (hmn : n ≤ m) : P n := @succ.rec αᵒᵈ _ _ _ _ _ h0 h1 _ hmn lemma pred.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) {a b : α} (h : a ≤ b) : p a ↔ p b := (@succ.rec_iff αᵒᵈ _ _ _ _ hsucc _ _ h).symm end pred_order end preorder section linear_order variables [linear_order α] section succ_order variables [succ_order α] [is_succ_archimedean α] {a b : α} lemma exists_succ_iterate_or : (∃ n, succ^[n] a = b) ∨ ∃ n, succ^[n] b = a := (le_total a b).imp exists_succ_iterate_of_le exists_succ_iterate_of_le lemma succ.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) (a b : α) : p a ↔ p b := (le_total a b).elim (succ.rec_iff hsucc) (λ h, (succ.rec_iff hsucc h).symm) end succ_order section pred_order variables [pred_order α] [is_pred_archimedean α] {a b : α} lemma exists_pred_iterate_or : (∃ n, pred^[n] b = a) ∨ ∃ n, pred^[n] a = b := (le_total a b).imp exists_pred_iterate_of_le exists_pred_iterate_of_le lemma pred.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) (a b : α) : p a ↔ p b := (le_total a b).elim (pred.rec_iff hsucc) (λ h, (pred.rec_iff hsucc h).symm) end pred_order end linear_order section is_well_order variables [linear_order α] @[priority 100] instance is_well_order.to_is_pred_archimedean [h : is_well_order α (<)] [pred_order α] : is_pred_archimedean α := ⟨λ a, begin refine well_founded.fix h.wf (λ b ih hab, _), replace hab := hab.eq_or_lt, rcases hab with rfl | hab, { exact ⟨0, rfl⟩ }, cases le_or_lt b (pred b) with hb hb, { cases (min_of_le_pred hb).not_lt hab }, obtain ⟨k, hk⟩ := ih (pred b) hb (le_pred_of_lt hab), refine ⟨k + 1, _⟩, rw [iterate_add_apply, iterate_one, hk], end⟩ @[priority 100] instance is_well_order.to_is_succ_archimedean [h : is_well_order α (>)] [succ_order α] : is_succ_archimedean α := by convert @order_dual.is_succ_archimedean αᵒᵈ _ _ _ end is_well_order section order_bot variables [preorder α] [order_bot α] [succ_order α] [is_succ_archimedean α] lemma succ.rec_bot (p : α → Prop) (hbot : p ⊥) (hsucc : ∀ a, p a → p (succ a)) (a : α) : p a := succ.rec hbot (λ x _ h, hsucc x h) (bot_le : ⊥ ≤ a) end order_bot section order_top variables [preorder α] [order_top α] [pred_order α] [is_pred_archimedean α] lemma pred.rec_top (p : α → Prop) (htop : p ⊤) (hpred : ∀ a, p a → p (pred a)) (a : α) : p a := pred.rec htop (λ x _ h, hpred x h) (le_top : a ≤ ⊤) end order_top
{-# OPTIONS --cubical --no-import-sorts #-} module MoreAlgebra where open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero) private variable ℓ ℓ' ℓ'' : Level open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Cubical.Relation.Nullary.Base -- ¬_ open import Cubical.Relation.Binary.Base open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_) open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_) open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim` open import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_; inl to inlᵖ; inr to inrᵖ) open import Utils hPropRel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ')) hPropRel A B ℓ' = A → B → hProp ℓ' module Definitions where -- NOTE: one needs these "all-lowercase constructors" to make use of copatterns _Preserves_⟶_ : ∀{Aℓ Bℓ ℓ ℓ'} {A : Type Aℓ} {B : Type Bℓ} → (A → B) → Rel A A ℓ → Rel B B ℓ' → Set _ f Preserves P ⟶ Q = ∀{x y} → P x y → Q (f x) (f y) _Reflects_⟶_ : ∀{Aℓ Bℓ ℓ ℓ'} {A : Type Aℓ} {B : Type Bℓ} → (A → B) → Rel A A ℓ → Rel B B ℓ' → Set _ f Reflects P ⟶ Q = ∀{x y} → Q (f x) (f y) → P x y -- https://en.wikipedia.org/wiki/Complete_partial_order -- A partially ordered set is a directed-complete partial order (dcpo) if each of its directed subsets has a supremum. -- A subset of a partial order is directed if it is non-empty and every pair of elements has an upper bound in the subset. -- In the literature, dcpos sometimes also appear under the label up-complete poset. -- https://ncatlab.org/nlab/show/dcpo -- A DCPO, or directed-complete partial order, is a poset with all directed joins. -- Often a DCPO is required to have a bottom element ⊥\bot; then it is called a pointed DCPO or a CPO (but this term is ambiguous). -- In this chapter we develop the theory of directed-complete partial orders (dcpo), namely -- partially ordered sets in which only certain joins are required to exist. -- -- ... -- -- 3.1 Dcpos -- -- We start by defining partial orders. By a binary relation R on a set X , we mean a map X → X → HProp, as in Definition 2.7.1. -- We can specify which universe the binary relation lands in by saying that R is HPropᵢ-valued or is a relation in universe i if R : X → X → HPropᵢ. -- -- Definition 3.1.1. A binary relation R on a set X is -- -- 1. reflexive if (∀ x : X) R x x; -- 2. irreflexive if (∀ x : X) ¬ R x x; -- 3. symmetric if (∀ x, y : X) R x y ⇒ R y x; -- 4. antisymmetric if (∀ x, y : X) R x y ⇒ R y x ⇒ x = y; -- 5. transitive if (∀ x, y, z : X) R x y ⇒ R y z ⇒ R x z; -- 6. cotransitive if (∀ x, y, z : X) R x y ⇒ (R x z) ∨ (R z y). -- -- Remark 3.1.2. Cotransitivity is also known as weak linearity [91, Definition 11.2.7] or the approximate splitting principle [84]. -- -- Definition 3.1.3. -- -- A preorder, denoted by ≤, is a reflexive transitive relation. -- A partial order is an antisymmetric preorder. -- Definition 4.1.4. -- - An apartness relation, denoted by #, is an irreflexive symmetric cotransitive relation. -- - A strict partial order, denoted by <, is an irreflexive transitive cotransitive relation. IsIrrefl : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ') IsIrrefl {A = A} R = (a : A) → ¬(R a a) IsCotrans : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ') IsCotrans {A = A} R = (a b : A) → R a b → (∀(x : A) → (R a x) ⊎ (R x b)) -- NOTE: see Cubical.Algebra.Poset IsSymᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → Type (ℓ-max ℓ ℓ') IsSymᵖ {A = A} R = (a b : A) → [ R a b ] → [ R b a ] IsIrreflᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → Type (ℓ-max ℓ ℓ') IsIrreflᵖ {A = A} R = (a : A) → [ ¬ᵖ(R a a) ] IsCotransᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → Type (ℓ-max ℓ ℓ') IsCotransᵖ {A = A} R = (a b : A) → [ R a b ] → (∀(x : A) → [ (R a x) ⊔ (R x b) ]) {- NOTE: formulating the properties on witnesses with `[_]` is similar to the previous Propositions-as-types formalism but it is not the way to proceed with hProps the idea is, to produce an hProp again e.g. from `Cubical.Algebra.Poset` isTransitive : {A : Type ℓ₀} → Order ℓ₁ A → hProp (ℓ-max ℓ₀ ℓ₁) isTransitive {ℓ₀ = ℓ₀} {ℓ₁ = ℓ₁} {A = X} _⊑_ = φ , φ-prop where φ : Type (ℓ-max ℓ₀ ℓ₁) φ = ((x y z : X) → [ x ⊑ y ⇒ y ⊑ z ⇒ x ⊑ z ]) φ-prop : isProp φ φ-prop = isPropΠ3 λ x y z → snd (x ⊑ y ⇒ y ⊑ z ⇒ x ⊑ z) -} IsTransᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → Type (ℓ-max ℓ ℓ') IsTransᵖ {A = A} R = (a b c : A) → [ R a b ] → [ R b c ] → [ R a c ] -- NOTE: this is starting with a lower-case, because `hProp (ℓ-max ℓ ℓ')` is not a type but an element isTransᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → hProp (ℓ-max ℓ ℓ') isTransᵖ {ℓ} {ℓ'} {A = A} R = φ , φ-prop where φ : Type (ℓ-max ℓ ℓ') φ = (a b c : A) → [ R a b ⇒ R b c ⇒ R a c ] φ-prop : isProp φ φ-prop = isPropΠ3 λ a b c → snd (R a b ⇒ R b c ⇒ R a c) isIrreflᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → hProp (ℓ-max ℓ ℓ') isIrreflᵖ {ℓ} {ℓ'} {A = A} R = φ , φ-prop where φ : Type (ℓ-max ℓ ℓ') φ = (a : A) → [ ¬ᵖ (R a a) ] φ-prop : isProp φ φ-prop = isPropΠ λ a → snd (¬ᵖ (R a a)) isCotransᵖ : {ℓ ℓ' : Level} {A : Type ℓ} → (R : hPropRel A A ℓ') → hProp (ℓ-max ℓ ℓ') isCotransᵖ {ℓ} {ℓ'} {A = A} R = φ , φ-prop where φ : Type (ℓ-max ℓ ℓ') φ = (a b : A) → [ R a b ⇒ (∀[ x ∶ A ] (R a x) ⊔ (R x b)) ] φ-prop : isProp φ φ-prop = isPropΠ2 λ a b → snd (R a b ⇒ (∀[ x ∶ A ] (R a x) ⊔ (R x b))) record IsApartnessRel {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where field isIrrefl : IsIrrefl R isSym : BinaryRelation.isSym R isCotrans : IsCotrans R record IsApartnessRelᵖ {ℓ ℓ' : Level} {A : Type ℓ} (R : hPropRel A A ℓ') : Type (ℓ-max ℓ ℓ') where field isIrrefl : IsIrreflᵖ R isSym : IsSymᵖ R isCotrans : IsCotransᵖ R record IsStrictPartialOrder {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where constructor isstrictpartialorder field isIrrefl : IsIrrefl R isTrans : BinaryRelation.isTrans R isCotrans : IsCotrans R record IsStrictPartialOrderᵖ {ℓ ℓ' : Level} {A : Type ℓ} (R : hPropRel A A ℓ') : Type (ℓ-max ℓ ℓ') where constructor isstrictpartialorderᵖ field isIrrefl : IsIrreflᵖ R isTrans : IsTransᵖ R isCotrans : IsCotransᵖ R {- NOTE: here again, the previous-way-interpretation would be to put witnesses into the struct with `[_]` but with hProps, we would have `isStrictPartialOrder : hProp` and use `[ isStrictPartialOrder ]` as the witness type with hProps we would need to make heavy use of `Cubical.Foundations.HLevels` isProp×, isProp×2, isProp×3 to show the record's `isProp` do we have pathes on records? in order to use `isProp` on records? yes, with record constructors -} record [IsStrictPartialOrder] {ℓ ℓ' : Level} {A : Type ℓ} (R : hPropRel A A ℓ') : Type (ℓ-max ℓ ℓ') where constructor isstrictpartialorderᵖ field isIrrefl : [ isIrreflᵖ R ] isTrans : [ isTransᵖ R ] isCotrans : [ isCotransᵖ R ] isStrictParialOrder : {ℓ ℓ' : Level} {A : Type ℓ} (R : hPropRel A A ℓ') → hProp (ℓ-max ℓ ℓ') isStrictParialOrder R = [IsStrictPartialOrder] R , φ-prop where φ-prop : isProp ([IsStrictPartialOrder] R) φ-prop (isstrictpartialorderᵖ isIrrefl₀ isTrans₀ isCotrans₀) (isstrictpartialorderᵖ isIrrefl₁ isTrans₁ isCotrans₁) = λ i → isstrictpartialorderᵖ (isProp[] (isIrreflᵖ R) isIrrefl₀ isIrrefl₁ i) (isProp[] (isTransᵖ R) isTrans₀ isTrans₁ i) (isProp[] (isCotransᵖ R) isCotrans₀ isCotrans₁ i) record IsPreorder {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where constructor ispreorder field isRefl : BinaryRelation.isRefl R isTrans : BinaryRelation.isTrans R -- NOTE: there is already -- isAntisym : {A : Type ℓ₀} → isSet A → Order ℓ₁ A → hProp (ℓ-max ℓ₀ ℓ₁) -- in Cubical.Algebra.Poset. Can we use this? -- import Cubical.Algebra.Poset IsAntisym : {ℓ ℓ' : Level} {A : Type ℓ} → (R : Rel A A ℓ') → Type (ℓ-max ℓ ℓ') IsAntisym {A = A} R = ∀ a b → R a b → R b a → a ≡ b record IsPartialOrder {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') : Type (ℓ-max ℓ ℓ') where constructor ispartialorder field isRefl : BinaryRelation.isRefl R isAntisym : IsAntisym R isTrans : BinaryRelation.isTrans R _#'_ : ∀{X : Type ℓ} {_<_ : Rel X X ℓ'} → Rel X X ℓ' _#'_ {_<_ = _<_} x y = (x < y) ⊎ (y < x) _≤'_ : ∀{X : Type ℓ} {_<_ : Rel X X ℓ'} → Rel X X ℓ' _≤'_ {_<_ = _<_} x y = ¬ (y < x) -- NOTE: there is `Properties` and `Consequences` -- the difference somehow is, that we do want to open `Consequences` directly -- but we do not want to open `Properties` directly, because it might have a name clash -- e.g. there is `Properties.Group` which clashes with `Cubical.Algebra.Group.Group` when opening `Properties` -- but it is totally fine to open `Properties.Group` directly because it does not export a `Group` -- TODO: check whether this matches the wording of the (old) standard library module Consequences where open Definitions -- Lemma 4.1.7. -- Given a strict partial order < on a set X: -- 1. we have an apartness relation defined by -- x # y := (x < y) ∨ (y < x), and #'-isApartnessRel : ∀{X : Type ℓ} {_<_ : Rel X X ℓ'} → (isSPO : IsStrictPartialOrder _<_) → IsApartnessRel (_#'_ {_<_ = _<_}) #'-isApartnessRel {X = X} {_<_ = _<_} isSPO = let (isstrictpartialorder <-irrefl <-trans <-cotrans) = isSPO in λ where .IsApartnessRel.isIrrefl a (inl a<a) → <-irrefl _ a<a .IsApartnessRel.isIrrefl a (inr a<a) → <-irrefl _ a<a .IsApartnessRel.isSym a b p → ⊎-swap p .IsApartnessRel.isCotrans a b (inl a<b) x → case (<-cotrans _ _ a<b x) of λ where -- case x of f = f x (inl a<x) → inl (inl a<x) (inr x<b) → inr (inl x<b) .IsApartnessRel.isCotrans a b (inr b<a) x → case (<-cotrans _ _ b<a x) of λ where (inl b<x) → inr (inr b<x) (inr x<a) → inl (inr x<a) -- variant without copatterns: "just" move the `λ where` "into" the record #'-isApartnessRel' : ∀{X : Type ℓ} {_<_ : Rel X X ℓ'} → {IsStrictPartialOrder _<_} → IsApartnessRel (_#'_ {_<_ = _<_}) #'-isApartnessRel' {X = X} {_<_ = _<_} {isSPO} = let (isstrictpartialorder <-irrefl <-trans <-cotrans) = isSPO in record { isIrrefl = λ where a (inl a<a) → <-irrefl _ a<a a (inr a<a) → <-irrefl _ a<a ; isSym = λ where a b p → ⊎-swap p ; isCotrans = λ where a b (inl a<b) x → case (<-cotrans _ _ a<b x) of λ where (inl a<x) → inl (inl a<x) (inr x<b) → inr (inl x<b) a b (inr b<a) x → case (<-cotrans _ _ b<a x) of λ where (inl b<x) → inr (inr b<x) (inr x<a) → inl (inr x<a) } -- 2. we have a preorder defined by -- x ≤ y := ¬(y < x). ≤-isPreorder' : ∀{X : Type ℓ} {_<_ : Rel X X ℓ'} → {IsStrictPartialOrder _<_} → IsPreorder (_≤'_ {_<_ = _<_}) ≤-isPreorder' {X = X} {_<_ = _<_} {isSPO} = let (isstrictpartialorder <-irrefl <-trans <-cotrans) = isSPO in λ where .IsPreorder.isRefl → <-irrefl .IsPreorder.isTrans a b c ¬b<a ¬c<b c<a → case (<-cotrans _ _ c<a b) of λ where (inl c<b) → ¬c<b c<b (inr b<a) → ¬b<a b<a module _ {X : Type ℓ} (_<_ : Rel X X ℓ') (isSPO : IsStrictPartialOrder _<_) (<-isProp : ∀ x y → isProp (x < y)) (let _#_ = _#'_ {_<_ = _<_}) (let (isstrictpartialorder <-irrefl <-trans <-cotrans) = isSPO) where -- open IsStrictPartialOrder isSPO #-from-<-isProp : ∀ x y → isProp (x # y) #-from-<-isProp x y (inl x<y₁) (inl x<y₂) = cong inl (<-isProp x y x<y₁ x<y₂) -- NOTE: ⊥-elim could not resolve the level here and needed some hint on `A` #-from-<-isProp x y (inl x<y ) (inr y<x ) = ⊥-elim {A = λ _ → inl x<y ≡ inr y<x} (<-irrefl y (<-trans y x y y<x x<y)) #-from-<-isProp x y (inr y<x ) (inl x<y ) = ⊥-elim {A = λ _ → inr y<x ≡ inl x<y} (<-irrefl y (<-trans y x y y<x x<y)) #-from-<-isProp x y (inr y<x₁) (inr y<x₂) = cong inr (<-isProp y x y<x₁ y<x₂) module Properties where module _ where open import Cubical.Algebra.Group -- import Cubical.Algebra.Group.Properties module GroupProperties (G : Group {ℓ}) where open Group G private simplR = GroupLemmas.simplR G invUniqueL : {g h : Carrier} → g + h ≡ 0g → g ≡ - h invUniqueL {g} {h} p = simplR h (p ∙ sym (invl h)) -- ported from `Algebra.Properties.Group` right-helper : ∀ x y → y ≡ - x + (x + y) right-helper x y = ( y ≡⟨ sym (snd (identity y)) ⟩ 0g + y ≡⟨ cong₂ _+_ (sym (snd (inverse x))) refl ⟩ ((- x) + x) + y ≡⟨ sym (assoc (- x) x y) ⟩ (- x) + (x + y) ∎) -- alternative: -- follows from uniqueness of - -- (a + -a) ≡ 0 -- ∃! b . a + b = 0 -- show that a is an additive inverse of - a then it must be THE additive inverse of - a and has to be called - - a which is a by uniqueness -involutive : ∀ x → - - x ≡ x -involutive x = ( (- (- x)) ≡⟨ sym (fst (identity _)) ⟩ (- (- x)) + 0g ≡⟨ cong₂ _+_ refl (sym (snd (inverse _))) ⟩ (- (- x)) + (- x + x) ≡⟨ sym (right-helper (- x) x) ⟩ x ∎) module _ where open import Cubical.Algebra.Ring module RingProperties (R : Ring {ℓ}) where open Ring R open Cubical.Algebra.Ring.Theory R -- NOTE: a few facts about rings that might be collected from elsewhere a+b-b≡a : ∀ a b → a ≡ (a + b) - b a+b-b≡a a b = let P = sym (fst (+-inv b)) Q = sym (fst (+-identity a)) R = transport (λ i → a ≡ a + P i) Q S = transport (λ i → a ≡ (+-assoc a b (- b)) i ) R in S -- NOTE: this is called `simplL` and `simplL` in `Cubical.Algebra.Group.Properties.GroupLemmas` +-preserves-≡ : ∀{a b} → ∀ c → a ≡ b → a + c ≡ b + c +-preserves-≡ c a≡b i = a≡b i + c +-preserves-≡-l : ∀{a b} → ∀ c → a ≡ b → c + a ≡ c + b +-preserves-≡-l c a≡b i = c + a≡b i a+b≡0→a≡-b : ∀{a b} → a + b ≡ 0r → a ≡ - b a+b≡0→a≡-b {a} {b} a+b≡0 = transport (λ i → let RHS = snd (+-identity (- b)) LHS₁ : a + (b + - b) ≡ a + 0r LHS₁ = +-preserves-≡-l a (fst (+-inv b)) LHS₂ : (a + b) - b ≡ a LHS₂ = transport (λ j → (+-assoc a b (- b)) j ≡ fst (+-identity a) j) LHS₁ in LHS₂ i ≡ RHS i ) (+-preserves-≡ (- b) a+b≡0) -- NOTE: there is already -- -commutesWithRight-· : (x y : R) → x · (- y) ≡ - (x · y) a·-b≡-a·b : ∀ a b → a · (- b) ≡ - (a · b) a·-b≡-a·b a b = let P : a · 0r ≡ 0r P = 0-rightNullifies a Q : a · (- b + b) ≡ 0r Q = transport (λ i → a · snd (+-inv b) (~ i) ≡ 0r) P R : a · (- b) + a · b ≡ 0r R = transport (λ i → ·-rdist-+ a (- b) b i ≡ 0r) Q in a+b≡0→a≡-b R a·b-a·c≡a·[b-c] : ∀ a b c → a · b - (a · c) ≡ a · (b - c) a·b-a·c≡a·[b-c] a b c = let P : a · b + a · (- c) ≡ a · (b + - c) P = sym (·-rdist-+ a b (- c)) Q : a · b - a · c ≡ a · (b + - c) Q = transport (λ i → a · b + a·-b≡-a·b a c i ≡ a · (b + - c) ) P in Q -- exports module Group = GroupProperties module Ring = RingProperties
module Minecraft.Data.Type.As import public Minecraft.Data.Type.Ctx import public Minecraft.Data.Type.Vtbl %default total public export record As kind where constructor New ctx : Ctx kind val : ctx.type {auto vtbl : Vtbl ctx.type} export new : {kind : Type -> Type} -> (type : Type) -> (val : type) -> (impl : kind type) => (vtbl : Vtbl type) => As kind new {kind} type val @{impl} @{vtbl} = New ((#) type @{impl}) val @{vtbl} export app : forall r. {kind : Type -> Type} -> (x : As kind) -> (f : kind x.ctx.type => x.ctx.type -> r) -> r app {kind} x f = f @{x.ctx.impl} x.val export cast : (kind : Type -> Type) -> As _ -> Maybe (As kind) cast kind (New ctx val {vtbl}) = case vtable @{vtbl} (kind ctx.type) of Just impl => Just (New ((#) ctx.type {impl}) val @{vtbl}) Nothing => Nothing export castApp : forall r. (kind : Type -> Type) -> (x : As _) -> (f : kind x.ctx.type => x.ctx.type -> r) -> Maybe r castApp kind (New ctx val {vtbl}) f = case vtable @{vtbl} (kind ctx.type) of Just impl => Just (f @{impl} val) Nothing => Nothing
Require Import Coq.Lists.List. Require Import Coq.micromega.Lia. Require Import Coq.Init.Peano. Require Import Coq.Arith.PeanoNat. Require Import Coq.Arith.Compare_dec. Require Import Coq.PArith.BinPosDef. Require Import Coq.ZArith.BinInt Coq.ZArith.ZArith Coq.ZArith.Zdiv Coq.ZArith.Znumtheory Coq.NArith.NArith. (* import Zdiv before Znumtheory *) Require Import Coq.NArith.Nnat. Require Import Crypto.Algebra.Hierarchy Crypto.Algebra.Field. Require Import Crypto.Spec.ModularArithmetic. Require Import Crypto.Arithmetic.ModularArithmeticTheorems Crypto.Arithmetic.PrimeFieldTheorems. Require Import Crypto.Util.Decidable. (* Crypto.Util.Notations. *) Require Import Coq.setoid_ring.Ring_theory Coq.setoid_ring.Field_theory Coq.setoid_ring.Field_tac. Require Import Ring. Require Import Coq.Logic.FunctionalExtensionality. Require Import Coq.Logic.PropExtensionality. From Circom Require Import Circom Default Util DSL Tuple ListUtil LibTactics Simplify. From Circom Require Import Repr ReprZ. From Circom.CircomLib Require Import Bitify Comparators Gates. (* Circuit: * https://github.com/yi-sun/circom-pairing/blob/master/circuits/bigint.circom *) Module Split. Module B := Bitify. Module D := DSL. Module R := Repr. Import R. Import B. Local Open Scope list_scope. Local Open Scope Z_scope. Local Open Scope F_scope. Local Open Scope circom_scope. Local Open Scope tuple_scope. Local Coercion Z.of_nat: nat >-> Z. Local Coercion N.of_nat: nat >-> N. Section _Split. Context {n m: nat}. (* // split a n + m bit input into two outputs template Split(n, m) { assert(n <= 126); signal input in; signal output small; signal output big; small <-- in % (1 << n); big <-- in \ (1 << n); component n2b_small = Num2Bits(n); n2b_small.in <== small; component n2b_big = Num2Bits(m); n2b_big.in <== big; in === small + big * (1 << n); } *) Definition cons (_in: F) (small: F) (big: F) := exists (n2b_small: @Num2Bits.t n) (n2b_big: @Num2Bits.t m), n2b_small.(Num2Bits._in) = small /\ n2b_big.(Num2Bits._in) = big /\ _in = small + big * 2^n. Local Close Scope F_scope. Record t := { _in: F; small: F; big: F; _cons: cons _in small big }. End _Split. End Split. Module SplitThree. Module B := Bitify. Module D := DSL. Module R := Repr. Import R. Import B. Local Open Scope list_scope. Local Open Scope Z_scope. Local Open Scope F_scope. Local Open Scope circom_scope. Local Open Scope tuple_scope. Local Coercion Z.of_nat: nat >-> Z. Local Coercion N.of_nat: nat >-> N. Section _SplitThree. Context {n m k: nat}. (* // split a n + m + k bit input into three outputs template SplitThree(n, m, k) { assert(n <= 126); signal input in; signal output small; signal output medium; signal output big; small <-- in % (1 << n); medium <-- (in \ (1 << n)) % (1 << m); big <-- in \ (1 << n + m); component n2b_small = Num2Bits(n); n2b_small.in <== small; component n2b_medium = Num2Bits(m); n2b_medium.in <== medium; component n2b_big = Num2Bits(k); n2b_big.in <== big; in === small + medium * (1 << n) + big * (1 << n + m); } *) Definition cons (_in: F) (small: F) (medium: F) (big: F) := exists (n2b_small: @Num2Bits.t n) (n2b_medium: @Num2Bits.t m) (n2b_big: @Num2Bits.t k), n2b_small.(Num2Bits._in) = small /\ n2b_medium.(Num2Bits._in) = medium /\ n2b_big.(Num2Bits._in) = big /\ _in = small + medium * 2^n + big * 2^(n+m). Local Close Scope F_scope. Record t := { _in: F; small: F; medium: F; big: F; _cons: cons _in small medium big }. End _SplitThree. End SplitThree.
Blush pink and ivory roses make a romantic wedding boutonniere for your groom. Ivory and blush roses are accented with white berries and lamb's ear, and are wrapped in ivory satin. This is an excellent wedding boutonniere choice for a garden wedding or spring wedding. The satin color on these boutonnieres can be customized to coordinate with your wedding colors.
import algebra.group.pi /-! # Pi instances for groups and monoids This file defines instances for group, monoid, semigroup and related structures on Pi types. -/ universes u v w variables {I : Prop} {f : I → Type v} namespace pi_Prop /-! `1`, `0`, `+`, `*`, `-`, `⁻¹`, and `/` are defined pointwise. -/ @[to_additive] instance has_one [Π i, has_one $ f i] : has_one (Π i, f i) := ⟨λ _, 1⟩ @[to_additive] instance has_mul [Π i, has_mul $ f i] : has_mul (Π i, f i) := ⟨λ f g i, f i * g i⟩ @[to_additive] instance has_inv [Π i, has_inv $ f i] : has_inv (Π i, f i) := ⟨λ f i, (f i)⁻¹⟩ @[to_additive] instance has_div [Π i, has_div $ f i] : has_div (Π i, f i) := ⟨λ f g i, f i / g i⟩ @[simp, to_additive] lemma one_apply [Π i, has_one $ f i] (i : I) : (1 : Π i, f i) i = 1 := rfl @[to_additive] instance semigroup [Π i, semigroup $ f i] : semigroup (Π i, f i) := by refine_struct { mul := (*), .. }; tactic.pi_instance_derive_field instance semigroup_with_zero [Π i, semigroup_with_zero $ f i] : semigroup_with_zero (Π i, f i) := by refine_struct { zero := (0 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field @[to_additive] instance comm_semigroup [Π i, comm_semigroup $ f i] : comm_semigroup (Π i, f i) := by refine_struct { mul := (*), .. }; tactic.pi_instance_derive_field @[to_additive] instance mul_one_class [Π i, mul_one_class $ f i] : mul_one_class (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field @[to_additive] instance monoid [Π i, monoid $ f i] : monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), npow := λ n x i, (x i) ^ n }; tactic.pi_instance_derive_field @[to_additive] instance comm_monoid [Π i, comm_monoid $ f i] : comm_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), npow := monoid.npow }; tactic.pi_instance_derive_field @[to_additive pi_Prop.sub_neg_monoid] instance div_inv_monoid [Π i, div_inv_monoid $ f i] : div_inv_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, div := has_div.div, npow := monoid.npow, zpow := λ z x i, (x i) ^ z }; tactic.pi_instance_derive_field @[to_additive] instance has_involutive_inv [Π i, has_involutive_inv $ f i] : has_involutive_inv (Π i, f i) := by refine_struct { inv := has_inv.inv }; tactic.pi_instance_derive_field @[to_additive pi_Prop.subtraction_monoid] instance division_monoid [Π i, division_monoid $ f i] : division_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, div := has_div.div, npow := monoid.npow, zpow := λ z x i, (x i) ^ z }; tactic.pi_instance_derive_field @[to_additive pi_Prop.subtraction_comm_monoid] instance division_comm_monoid [Π i, division_comm_monoid $ f i] : division_comm_monoid (Π i, f i) := { ..pi_Prop.division_monoid, ..pi_Prop.comm_semigroup } @[to_additive] instance group [Π i, group $ f i] : group (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, div := has_div.div, npow := monoid.npow, zpow := div_inv_monoid.zpow }; tactic.pi_instance_derive_field @[to_additive] instance comm_group [Π i, comm_group $ f i] : comm_group (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, div := has_div.div, npow := monoid.npow, zpow := div_inv_monoid.zpow }; tactic.pi_instance_derive_field @[to_additive add_left_cancel_semigroup] instance left_cancel_semigroup [Π i, left_cancel_semigroup $ f i] : left_cancel_semigroup (Π i, f i) := by refine_struct { mul := (*) }; tactic.pi_instance_derive_field @[to_additive add_right_cancel_semigroup] instance right_cancel_semigroup [Π i, right_cancel_semigroup $ f i] : right_cancel_semigroup (Π i, f i) := by refine_struct { mul := (*) }; tactic.pi_instance_derive_field @[to_additive add_left_cancel_monoid] instance left_cancel_monoid [Π i, left_cancel_monoid $ f i] : left_cancel_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), npow := monoid.npow }; tactic.pi_instance_derive_field @[to_additive add_right_cancel_monoid] instance right_cancel_monoid [Π i, right_cancel_monoid $ f i] : right_cancel_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), npow := monoid.npow, .. }; tactic.pi_instance_derive_field @[to_additive add_cancel_monoid] instance cancel_monoid [Π i, cancel_monoid $ f i] : cancel_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), npow := monoid.npow }; tactic.pi_instance_derive_field @[to_additive add_cancel_comm_monoid] instance cancel_comm_monoid [Π i, cancel_comm_monoid $ f i] : cancel_comm_monoid (Π i, f i) := by refine_struct { one := (1 : Π i, f i), mul := (*), npow := monoid.npow }; tactic.pi_instance_derive_field instance mul_zero_class [Π i, mul_zero_class $ f i] : mul_zero_class (Π i, f i) := by refine_struct { zero := (0 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field instance mul_zero_one_class [Π i, mul_zero_one_class $ f i] : mul_zero_one_class (Π i, f i) := by refine_struct { zero := (0 : Π i, f i), one := (1 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field instance monoid_with_zero [Π i, monoid_with_zero $ f i] : monoid_with_zero (Π i, f i) := by refine_struct { zero := (0 : Π i, f i), one := (1 : Π i, f i), mul := (*), npow := monoid.npow }; tactic.pi_instance_derive_field instance comm_monoid_with_zero [Π i, comm_monoid_with_zero $ f i] : comm_monoid_with_zero (Π i, f i) := by refine_struct { zero := (0 : Π i, f i), one := (1 : Π i, f i), mul := (*), npow := monoid.npow }; tactic.pi_instance_derive_field end pi_Prop
""" PlasmaProperties, a simple plasma calculator module in Julia The module contains basic functions to compute common plasma properties, such as characteristic frequencies and lengths. It builds on Unitful, which provides a simple unit system for physical quantities. """ module PlasmaProperties using Unitful import Unitful: Length, Time, Mass, Energy, Temperature, BField, EField using PhysicalConstants ε0 = PhysicalConstants.CODATA2018.ε_0 |> u"F/m" μ0 = PhysicalConstants.CODATA2018.μ_0 |> u"N/A^2" me = PhysicalConstants.CODATA2018.m_e |> u"kg" qe = PhysicalConstants.CODATA2018.e |> u"C" kB = PhysicalConstants.CODATA2018.k_B |> u"J/K" mu = PhysicalConstants.CODATA2018.m_u |> u"kg" export QuasineutralPlasma # Plasma object type and constructors export atomic_masses # Atomic masses export f_ce, f_pe, r_Le, r_Lsi, λ_De, c_s, c_the, ν_ei, ν_ie, ν_ee, χ # Calculator functions export ε0, μ0, me, qe, kB # Physical constants, reexported from PhysicalConstants include("auxiliary.jl") include("types.jl") include("functions.jl") end # module
// https://www.boost.org/doc/libs/1_67_0/libs/python/doc/html/tutorial/tutorial/exposing.html #include <boost/python.hpp> struct World { void set(std::string msg) { this->msg = msg; } std::string greet() { return msg; } std::string msg; }; struct Var { Var(std::string name) : name(name), value() {} std::string const name; float value; }; #include <boost/python.hpp> using namespace boost::python; BOOST_PYTHON_MODULE(libdemo2) { class_<World>("World").def("greet", &World::greet).def("set", &World::set); class_<Var>("Var", init<std::string>()) .def_readonly("name", &Var::name) .def_readwrite("value", &Var::value); }
C----------------------------------------------------------------------- SUBROUTINE GETGI(LUGI,MNUM,MBUF,CBUF,NLEN,NNUM,IRET) C$$$ SUBPROGRAM DOCUMENTATION BLOCK C C SUBPROGRAM: GETGI READS A GRIB INDEX FILE C PRGMMR: IREDELL ORG: W/NMC23 DATE: 95-10-31 C C ABSTRACT: READ A GRIB INDEX FILE AND RETURN ITS CONTENTS. C VERSION 1 OF THE INDEX FILE HAS THE FOLLOWING FORMAT: C 81-BYTE S.LORD HEADER WITH 'GB1IX1' IN COLUMNS 42-47 FOLLOWED BY C 81-BYTE HEADER WITH NUMBER OF BYTES TO SKIP BEFORE INDEX RECORDS, C NUMBER OF BYTES IN EACH INDEX RECORD, NUMBER OF INDEX RECORDS, C AND GRIB FILE BASENAME WRITTEN IN FORMAT ('IX1FORM:',3I10,2X,A40). C EACH FOLLOWING INDEX RECORD CORRESPONDS TO A GRIB MESSAGE C AND HAS THE INTERNAL FORMAT: C BYTE 001-004: BYTES TO SKIP IN DATA FILE BEFORE GRIB MESSAGE C BYTE 005-008: BYTES TO SKIP IN MESSAGE BEFORE PDS C BYTE 009-012: BYTES TO SKIP IN MESSAGE BEFORE GDS (0 IF NO GDS) C BYTE 013-016: BYTES TO SKIP IN MESSAGE BEFORE BMS (0 IF NO BMS) C BYTE 017-020: BYTES TO SKIP IN MESSAGE BEFORE BDS C BYTE 021-024: BYTES TOTAL IN THE MESSAGE C BYTE 025-025: GRIB VERSION NUMBER C BYTE 026-053: PRODUCT DEFINITION SECTION (PDS) C BYTE 054-095: GRID DEFINITION SECTION (GDS) (OR NULLS) C BYTE 096-101: FIRST PART OF THE BIT MAP SECTION (BMS) (OR NULLS) C BYTE 102-112: FIRST PART OF THE BINARY DATA SECTION (BDS) C BYTE 113-172: (OPTIONAL) BYTES 41-100 OF THE PDS C BYTE 173-184: (OPTIONAL) BYTES 29-40 OF THE PDS C BYTE 185-320: (OPTIONAL) BYTES 43-178 OF THE GDS C C PROGRAM HISTORY LOG: C 95-10-31 IREDELL C 96-10-31 IREDELL AUGMENTED OPTIONAL DEFINITIONS TO BYTE 320 C C USAGE: CALL GETGI(LUGI,MNUM,MBUF,CBUF,NLEN,NNUM,IRET) C INPUT ARGUMENTS: C LUGI INTEGER UNIT OF THE UNBLOCKED GRIB INDEX FILE C MNUM INTEGER NUMBER OF INDEX RECORDS TO SKIP (USUALLY 0) C MBUF INTEGER LENGTH OF CBUF IN BYTES C OUTPUT ARGUMENTS: C CBUF CHARACTER*1 (MBUF) BUFFER TO RECEIVE INDEX DATA C NLEN INTEGER LENGTH OF EACH INDEX RECORD IN BYTES C NNUM INTEGER NUMBER OF INDEX RECORDS C IRET INTEGER RETURN CODE C 0 ALL OK C 1 CBUF TOO SMALL TO HOLD INDEX BUFFER C 2 ERROR READING INDEX FILE BUFFER C 3 ERROR READING INDEX FILE HEADER C C SUBPROGRAMS CALLED: C BAREAD BYTE-ADDRESSABLE READ C C REMARKS: SUBPROGRAM CAN BE CALLED FROM A MULTIPROCESSING ENVIRONMENT. C DO NOT ENGAGE THE SAME LOGICAL UNIT FROM MORE THAN ONE PROCESSOR. C C ATTRIBUTES: C LANGUAGE: FORTRAN 77 C MACHINE: CRAY, WORKSTATIONS C C$$$ CHARACTER CBUF(MBUF) CHARACTER CHEAD*162 C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NLEN=0 NNUM=0 IRET=3 CALL BAREAD(LUGI,0,162,LHEAD,CHEAD) IF(LHEAD.EQ.162.AND.CHEAD(42:47).EQ.'GB1IX1') THEN READ(CHEAD(82:162),'(8X,3I10,2X,A40)',IOSTAT=IOS) NSKP,NLEN,NNUM IF(IOS.EQ.0) THEN NSKP=NSKP+MNUM*NLEN NNUM=NNUM-MNUM NBUF=NNUM*NLEN IRET=0 IF(NBUF.GT.MBUF) THEN NNUM=MBUF/NLEN NBUF=NNUM*NLEN IRET=1 ENDIF IF(NBUF.GT.0) THEN CALL BAREAD(LUGI,NSKP,NBUF,LBUF,CBUF) IF(LBUF.NE.NBUF) IRET=2 ENDIF ENDIF ENDIF C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RETURN END
Formal statement is: lemma convex_linear_image_eq [simp]: fixes f :: "'a::real_vector \<Rightarrow> 'b::real_vector" shows "\<lbrakk>linear f; inj f\<rbrakk> \<Longrightarrow> convex (f ` s) \<longleftrightarrow> convex s" Informal statement is: If $f$ is a linear injection, then $f(S)$ is convex if and only if $S$ is convex.
import .datatypes .additive .reconstruction_theorems tactic.norm_num namespace polya open expr tactic diseq_proof --#check mk_nat_val_ne_proof use something like this below? theorem fake_ne_zero_pf (q : ℚ) : q ≠ 0 := sorry theorem fake_gt_zero_pf (q : ℚ) : q > 0 := sorry theorem fake_lt_zero_pf (q : ℚ) : q < 0 := sorry theorem fake_eq_zero_pf (q : ℚ) : q = 0 := sorry theorem fake_ne_pf (q1 q2 : ℚ) : q1 ≠ q2 := sorry private meta def solve_by_norm_num (e : expr) : tactic expr := do (_, pf) ← solve_aux e `[norm_num, tactic.done], return pf meta def mk_ne_zero_pf (q : ℚ) : tactic expr := --do qe ← to_expr ``(%%(quote q) : ℚ), -- to_expr ``(fake_ne_zero_pf (%%qe : ℚ)) --return `(fake_ne_zero_pf q) solve_by_norm_num `(q ≠ 0) -- proves that q > 0, q < 0, or q = 0 meta def mk_sign_pf (q : ℚ) : tactic expr := /-do qe ← to_expr `(%%(quote q) : ℚ), if q > 0 then to_expr `(fake_gt_zero_pf (%%qe : ℚ)) else if q < 0 then to_expr `(fake_lt_zero_pf (%%qe : ℚ)) else to_expr ``(fake_eq_zero_pf (%%qe : ℚ))-/ if q > 0 then --return `(fake_gt_zero_pf q) solve_by_norm_num `(q > 0) else if q < 0 then --return `(fake_lt_zero_pf q) solve_by_norm_num `(q < 0) else --return `(fake_eq_zero_pf q) solve_by_norm_num `(q = 0) meta def mk_ne_pf (q1 q2 : ℚ) : tactic expr := /-do q1e ← to_expr ``(%%(quote q1) : ℚ), q2e ← to_expr ``(%%(quote q2) : ℚ), to_expr `(fake_ne_pf %%q1e %%q2e)-/ --return `(fake_ne_pf q1 q2) solve_by_norm_num `(q1 ≠ q2) meta def mk_int_sign_pf (z : ℤ) : tactic expr := if z > 0 then solve_by_norm_num `(z > 0) --return `(sorry : z > 0) else if z < 0 then solve_by_norm_num `(z < 0)--return `(sorry : z < 0) else solve_by_norm_num `(z = 0) --return `(sorry : z = 0) -- proves z % 2 = 0 or z % 2 = 1 meta def mk_int_mod_pf (z : ℤ) : tactic expr := if z % 2 = 0 then return `(sorry : z % 2 = 0) else return `(sorry : z % 2 = 1) namespace diseq_proof private meta def reconstruct_hyp (lhs rhs : expr) (c : ℚ) (pf : expr) : tactic expr := do mvc ← mk_mvar, pft ← infer_type pf, to_expr ``(%%lhs ≠ %%mvc * %%rhs) >>= unify pft, c' ← eval_expr rat mvc, if c = c' then return pf else fail "diseq_proof.reconstruct_hyp failed" private meta def reconstruct_sym (rc : Π {lhs rhs : expr} {c : ℚ}, diseq_proof lhs rhs c → tactic expr) {lhs rhs c} (dp : diseq_proof lhs rhs c) : tactic expr := do symp ← rc dp, cnep ← mk_ne_zero_pf c, mk_mapp ``diseq_sym [none, none, none, cnep, symp] -- why doesn't mk_app work? meta def reconstruct : Π {lhs rhs : expr} {c : ℚ}, diseq_proof lhs rhs c → tactic expr | .(_) .(_) .(_) (hyp (lhs) (rhs) (c) e) := reconstruct_hyp lhs rhs c e | .(_) .(_) .(_) (@sym lhs rhs c dp) := reconstruct_sym @reconstruct dp end diseq_proof namespace eq_proof private meta def reconstruct_hyp (lhs rhs : expr) (c : ℚ) (pf : expr) : tactic expr := do mvc ← mk_mvar, pft ← infer_type pf, to_expr ``(%%lhs = %%mvc * %%rhs) >>= unify pft, c' ← eval_expr rat mvc, if c = c' then return pf else fail "eq_proof.reconstruct_hyp failed" private meta def reconstruct_sym (rc : Π {lhs rhs : expr} {c : ℚ}, eq_proof lhs rhs c → tactic expr) {lhs rhs c} (dp : eq_proof lhs rhs c) : tactic expr := do symp ← rc dp, cnep ← mk_ne_zero_pf c, -- 5/1 ≠ 0 -- infer_type symp >>= trace, -- infer_type cnep >>= trace, mk_mapp ``eq_sym [none, none, none, cnep, symp] -- why doesn't mk_app work? variable iepr_fn : Π {lhs rhs i}, ineq_proof lhs rhs i → tactic expr private meta def reconstruct_of_opp_ineqs_aux {lhs rhs i} (c : ℚ) (iep : ineq_proof lhs rhs i) (iepr : ineq_proof lhs rhs i.reverse) : tactic expr := do guard (bnot i.strict), pr1 ← iepr_fn iep, pr2 ← iepr_fn iepr, if i.to_comp.is_less then mk_mapp ``op_ineq [none, none, none, some pr1, some pr2] else mk_mapp ``op_ineq [none, none, none, some pr2, some pr1] private theorem eq_sub_of_add_eq_facs {c1 c2 e1 e2 : ℚ} (hc1 : c1 ≠ 0) (h : c1 * e1 + c2 * e2 = 0) : e1 = -(c2/c1) * e2 := sorry private meta def reconstruct_of_sum_form_proof (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) : expr → expr → ℚ → Π {sf}, Π (sp : sum_form_proof ⟨sf, spec_comp.eq⟩), tactic expr | lhs rhs c sf sp := if lhs.lt rhs then -- flipped? reconstruct_of_sum_form_proof rhs lhs (1/c) sp else do guard $ (sf.contains lhs) && (sf.contains rhs), let a := sf.get_coeff lhs in let b := sf.get_coeff rhs in do guard $ c = -(b/a), pf ← sfpr sp, nez ← mk_ne_zero_pf a, mk_app ``eq_sub_of_add_eq_facs [nez, pf] -- fail "eq_proof.reconstruct_of_sum_proof not implemented yet" meta def reconstruct_aux (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) : Π {lhs rhs : expr} {c : ℚ}, eq_proof lhs rhs c → tactic expr | .(_) .(_) .(_) (hyp (lhs) (rhs) (c) e) := reconstruct_hyp lhs rhs c e | .(_) .(_) .(_) (@sym lhs rhs c dp) := reconstruct_sym @reconstruct_aux dp | .(_) .(_) .(_) (@of_opp_ineqs lhs rhs i c iep iepr) := reconstruct_of_opp_ineqs_aux @iepr_fn c iep iepr | .(_) .(_) .(_) (@of_sum_form_proof lhs rhs c _ sp) := reconstruct_of_sum_form_proof @sfpr lhs rhs c sp | .(_) .(_) .(_) (adhoc _ _ _ _ t) := t end eq_proof namespace ineq_proof meta def guard_is_ineq (lhs rhs : expr) (iq : ineq) (pf : expr) : tactic expr := do mvc ← mk_mvar, pft ← infer_type pf, match iq.to_comp with | comp.lt := to_expr ``(%%lhs < %%mvc * %%rhs) >>= unify pft >> return mvc | comp.le := to_expr ``(%%lhs ≤ %%mvc * %%rhs) >>= unify pft >> return mvc | comp.gt := to_expr ``(%%lhs > %%mvc * %%rhs) >>= unify pft >> return mvc | comp.ge := to_expr ``(%%lhs ≥ %%mvc * %%rhs) >>= unify pft >> return mvc end private meta def reconstruct_hyp (lhs rhs : expr) (iq : ineq) (pf : expr) : tactic expr := match iq.to_slope with | slope.horiz := do tp ← infer_type pf, --trace "unifying tp in reconstruct_hyp1", trace tp, to_expr ``( %%(iq.to_comp.to_pexpr) %%rhs 0) >>= unify tp, return pf | slope.some c := do m ← guard_is_ineq lhs rhs iq pf, m' ← eval_expr rat m, if m' = c then return pf else fail "ineq_proof.reconstruct_hyp failed" end section variable (rc : Π {lhs rhs : expr} {iq : ineq}, ineq_proof lhs rhs iq → tactic expr) include rc private meta def reconstruct_sym {lhs rhs iq} (ip : ineq_proof lhs rhs iq) : tactic expr := match iq.to_slope with | slope.horiz := do p ← pp (lhs, rhs), fail $ "reconstruct_sym failed on horiz slope: " ++ p.to_string | slope.some m := do --trace "in reconstruct sym", trace (lhs, rhs, m), symp ← rc ip, sgnp ← mk_sign_pf m, --trace "have proof of:", infer_type symp >>= trace, --trace ("m", m), trace ("lhs, rhs", lhs, rhs), trace "sgnp", infer_type sgnp >>= trace, trace "symp", trace ip, infer_type symp >>= trace, --mk_mapp (name_of_c_and_comp m iq.to_comp) [none, none, none, some sgnp, some symp] mk_app (if m < 0 then ``sym_op_neg else ``sym_op_pos) [sgnp, symp] end -- x ≥ 2y and x ≠ 2y implies x > 2y private meta def reconstruct_ineq_diseq {lhs rhs iq c} (ip : ineq_proof lhs rhs iq) (dp : diseq_proof lhs rhs c) : tactic expr := match iq.to_slope with | slope.horiz := fail "reconstruct_ineq_diseq needs non-horiz slope" | slope.some m := if bnot (m=c) then fail "reconstruct_ineq_diseq found non-matching slopes" else if iq.strict then rc ip else do ipp ← rc ip, dpp ← dp.reconstruct, /-if iq.to_comp.is_less then mk_mapp ``ineq_diseq_le [none, none, none, some dpp, some ipp] else mk_mapp ``ineq_diseq_ge [none, none, none, some dpp, some ipp]-/ mk_app ``ineq_diseq [dpp, ipp] end variable (rcs : Π {e gc}, sign_proof e gc → tactic expr) include rcs -- x ≤ 0y and x ≠ 0 implies x < 0y private meta def reconstruct_ineq_sign_lhs {lhs rhs iq c} (ip : ineq_proof lhs rhs iq) (sp : sign_proof lhs c) : tactic expr := if iq.strict || bnot (c = gen_comp.ne) then fail "reconstruct_ineq_sign_lhs assumes a weak ineq and a diseq-0" else match iq.to_slope with | slope.horiz := fail "reconstruct_ineq_sign_lhs assumes a 0 slope" | slope.some m := if m = 0 then do ipp ← rc ip, spp ← rcs sp, -- mk_app (if iq.to_comp.is_less then ``ineq_diseq_sign_lhs_le else ``ineq_diseq_sign_lhs_ge) [spp, ipp] mk_app ``ineq_diseq_sign_lhs [spp, ipp] else fail "reconstruct_ineq_sign_lhs assumes a 0 slope" end -- this might be wrong: should we produce proofs of y < 0? private meta def reconstruct_ineq_sign_rhs {lhs rhs iq c} (ip : ineq_proof lhs rhs iq) (sp : sign_proof rhs c) : tactic expr := if iq.strict || bnot (c = gen_comp.ne) then fail "reconstruct_ineq_sign_rhs assumes a weak ineq and a diseq-0" else match iq.to_slope with | slope.horiz := do ipp ← rc ip, spp ← rcs sp, -- mk_app (if iq.to_comp.is_less then ``ineq_diseq_sign_rhs_le else ``ineq_diseq_sign_rhs_ge) [spp, ipp] mk_app ``ineq_diseq_sign_rhs [spp, ipp] | _ := fail "reconstruct_ineq_sign_rhs assumes a horizontal slope" end omit rc -- x ≥ 0 implies x ≥ 0*y private meta def reconstruct_zero_comp_of_sign {lhs c} (rhs : expr) (iq : ineq) (sp : sign_proof lhs c) : tactic expr := if bnot ((iq.to_comp.to_gen_comp = c) && (iq.is_zero_slope)) then fail $ "reconstruct_zero_comp_of_sign only produces comps with zero" ++ (to_fmt iq).to_string ++ (to_fmt iq.to_comp.to_gen_comp).to_string ++ (to_fmt c).to_string --else do spp ← rcs sp, mk_app (zero_mul_name_of_comp iq.to_comp) [rhs, spp] else do spp ← rcs sp, mk_mapp ``op_zero_mul [none, some rhs, none, none, some spp] private meta def reconstruct_horiz_of_sign {rhs c} (lhs : expr) (iq : ineq) (sp : sign_proof rhs c) : tactic expr := if bnot ((iq.to_comp.to_gen_comp = c) && (iq.is_horiz)) then fail $ "reconstruct_horiz_of_sign failed" else rcs sp end /- private theorem eq_sub_of_add_eq_facs {c1 c2 e1 e2 : ℚ} (hc1 : c1 ≠ 0) (h : c1 * e1 + c2 * e2 = 0) : e1 = -(c2/c1) * e2 := sorry private meta def reconstruct_of_sum_form_proof (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) : expr → expr → ℚ → Π {sf}, Π (sp : sum_form_proof ⟨sf, spec_comp.eq⟩), tactic expr | lhs rhs c sf sp := if rhs.lt lhs then reconstruct_of_sum_form_proof rhs lhs (1/c) sp else do guard $ (sf.contains lhs) && (sf.contains rhs), let a := sf.get_coeff lhs in let b := sf.get_coeff rhs in do guard $ c = -(b/a), pf ← sfpr sp, nez ← mk_ne_zero_pf a, mk_app ``eq_sub_of_add_eq_facs [nez, pf] -/ private meta def reconstruct_of_sum_form_proof (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) : expr → expr → ineq → Π {sfc}, sum_form_proof sfc → tactic expr | lhs rhs i sfc sp := if lhs.lt rhs then -- flipped? reconstruct_of_sum_form_proof rhs lhs i.reverse sp else (match i.to_slope with | slope.some m := do { guard $ (sfc.sf.contains lhs) && (sfc.sf.contains rhs), guard $ sfc.sf.keys.length = 2, let a := sfc.sf.get_coeff lhs in let b := sfc.sf.get_coeff rhs in do guard $ m = -(b/a), guard $ if a < 0 then sfc.c.to_comp = i.to_comp.reverse else sfc.c.to_comp = i.to_comp, rhs' ← to_expr ``(%%(↑(rat.reflect m) : expr) * %%rhs), -- better way to do this? tp ← i.to_comp.to_function lhs rhs', sgnp ← mk_sign_pf a, pf ← sfpr sp, --trace "have: ", infer_type pf >>= trace, trace ("lhs: ", lhs), trace ("rhs: ", rhs), let thnm := if a < 0 then ``op_of_sum_op_zero_neg else ``op_of_sum_op_zero_pos in mk_app thnm [pf, sgnp]} --to_expr ``(sorry : %%tp) -- fail "ineq_proof.reconstruct_of_sum_proof not implemented yet" | slope.horiz := fail "ineq_proof.reconstruct_of_sum_proof failed, cannot turn a sum into a horiz slope" end) meta def reconstruct_aux (rcs : Π {e gc}, sign_proof e gc → tactic expr) (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) : Π {lhs rhs : expr} {iq : ineq}, ineq_proof lhs rhs iq → tactic expr | _ _ _ (hyp lhs rhs iq e) := reconstruct_hyp lhs rhs iq e | _ _ _ (sym ip) := reconstruct_sym @reconstruct_aux ip | _ _ _ (of_ineq_proof_and_diseq ip dp) := reconstruct_ineq_diseq @reconstruct_aux ip dp | _ _ _ (of_ineq_proof_and_sign_lhs ip sp) := reconstruct_ineq_sign_lhs @reconstruct_aux @rcs ip sp | _ _ _ (of_ineq_proof_and_sign_rhs ip sp) := reconstruct_ineq_sign_rhs @reconstruct_aux @rcs ip sp | _ _ _ (zero_comp_of_sign_proof rhs iq sp) := reconstruct_zero_comp_of_sign @rcs rhs iq sp | _ _ _ (horiz_of_sign_proof lhs iq sp) := reconstruct_horiz_of_sign @rcs lhs iq sp | _ _ _ (of_sum_form_proof lhs rhs i sp) := reconstruct_of_sum_form_proof @sfpr lhs rhs i sp | _ _ _ (adhoc _ _ _ _ t) := t end ineq_proof namespace sign_proof private meta def reconstruct_hyp (e : expr) (gc : gen_comp) (pf : expr) : tactic expr := let pex := match gc with | gen_comp.ge := ``(%%e ≥ 0) | gen_comp.gt := ``(%%e > 0) | gen_comp.le := ``(%%e ≤ 0) | gen_comp.lt := ``(%%e < 0) | gen_comp.eq := ``(%%e = 0) | gen_comp.ne := ``(%%e ≠ 0) end in do tp ← infer_type pf, to_expr pex >>= unify tp >> return pf private meta def reconstruct_scaled_hyp (e : expr) (gc : gen_comp) (pf : expr) (q : ℚ) : tactic expr := do sp ← mk_sign_pf q, if q > 0 then mk_mapp ``op_zero_of_mul_op_zero_of_pos [none, none, none, none, pf, sp] else mk_mapp ``op_zero_of_mul_op_zero_of_neg [none, none, none, none, pf, sp] section parameter rc : Π {e c}, sign_proof e c → tactic expr parameter sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr private meta def rci := @ineq_proof.reconstruct_aux @rc @sfpr private meta def rce := @eq_proof.reconstruct_aux @rci @sfpr -- x ≤ 0*y to x ≤ 0 private meta def reconstruct_ineq_lhs (c : gen_comp) {lhs rhs iqp} (ip : ineq_proof lhs rhs iqp) : tactic expr := if bnot ((iqp.to_comp.to_gen_comp = c) && (iqp.is_zero_slope)) then fail "reconstruct_ineq_lhs must take a comparison with 0" --else do ipp ← rci ip, mk_app (zero_mul'_name_of_comp iqp.to_comp) [ipp] else do ipp ← rci ip, mk_app ``op_zero_mul' [ipp] private meta def reconstruct_ineq_rhs (c : gen_comp) {lhs rhs iqp} (ip : ineq_proof lhs rhs iqp) : tactic expr := if bnot ((iqp.to_comp.to_gen_comp = c) && (iqp.is_horiz)) then fail "reconstruct_ineq_rhs must take a horiz comp" else rci ip private meta def reconstruct_eq_of_two_eqs_lhs {lhs rhs eqp1 eqp2} (ep1 : eq_proof lhs rhs eqp1) (ep2 : eq_proof lhs rhs eqp2) : tactic expr := if h : eqp1 = eqp2 then fail "reconstruct_eq_of_two_eqs lhs cannot infer anything from the same equality twice" else do epp1 ← rce ep1, epp2 ← rce ep2, nep ← mk_ne_pf eqp1 eqp2, mk_app ``eq_zero_of_two_eqs_lhs [epp1, epp2, nep] private meta def reconstruct_eq_of_two_eqs_rhs {lhs rhs eqp1 eqp2} (ep1 : eq_proof lhs rhs eqp1) (ep2 : eq_proof lhs rhs eqp2) : tactic expr := if h : eqp1 = eqp2 then fail "reconstruct_eq_of_two_eqs lhs cannot infer anything from the same equality twice" else do epp1 ← rce ep1, epp2 ← rce ep2, nep ← mk_ne_pf eqp1 eqp2, mk_app ``eq_zero_of_two_eqs_rhs [epp1, epp2, nep] private meta def reconstruct_diseq_of_diseq_zero {lhs rhs} (dp : diseq_proof lhs rhs 0) : tactic expr := do dpp ← dp.reconstruct, mk_app ``ne_zero_of_ne_mul_zero [dpp] private meta def reconstruct_eq_of_eq_zero {lhs rhs} (ep : eq_proof lhs rhs 0) : tactic expr := do epp ← rce ep, mk_app ``eq_zero_of_eq_mul_zero [epp] /- private meta def reconstruct_ineqs (rct : contrad → tactic expr) {lhs rhs} (ii : ineq_info lhs rhs) (id : ineq_data lhs rhs) : tactic expr := do trace "ineqs!!", match ii with | ineq_info.no_comps := fail "reconstruct_ineqs cannot find a contradiction with no known comps" | ineq_info.one_comp id2 := reconstruct_two_ineq_data rct id id2 | ineq_info.equal ed := reconstruct_eq_ineq ed id | ineq_info.two_comps id1 id2 := let sfid := sum_form_comp_data.of_ineq_data id, sfid1 := sum_form_comp_data.of_ineq_data id1, sfid2 := sum_form_comp_data.of_ineq_data id2 in match find_contrad_in_sfcd_list [sfid, sfid1, sfid2] with | some ctr := rct ctr | option.none := fail "reconstruct_ineqs failed to find contr" end end -/ private theorem {u} ge_of_not_lt {α : Type u} [linear_order α] {a b : α} (h : ¬ a < b) : (a ≥ b) := le_of_not_gt h private theorem {u} gt_of_not_le {α : Type u} [linear_order α] {a b : α} (h : ¬ a ≤ b) : (a > b) := lt_of_not_ge h private meta def neg_op_lemma_name : comp → name | comp.lt := ``lt_of_not_ge | comp.le := ``le_of_not_gt | comp.ge := ``ge_of_not_lt | comp.gt := ``gt_of_not_le meta def reconstruct_ineq_of_eq_and_ineq_aux -- (sfpr : Π {sf : sum_form_comp}, Π (sp : sum_form_proof sf), tactic.{0} (expr tt)) {lhs rhs iq c} (c' : gen_comp) (ep : eq_proof lhs rhs c) (ip : ineq_proof lhs rhs iq) (pvt : expr) : tactic expr := do negt ← c'.to_comp.to_function pvt `(0 : ℚ), (_, notpf) ← solve_aux negt (do applyc $ neg_op_lemma_name c'.to_comp, hypv ← intro `h, let sfid := sum_form_comp_data.of_ineq_data ⟨_, ip⟩ in let sfed := sum_form_comp_data.of_eq_data ⟨_, ep⟩ in let sfsd := sum_form_comp_data.of_sign_data ⟨c'.negate, hyp pvt _ hypv⟩ in match find_contrad_sfcd_in_sfcd_list [sfid, sfed, sfsd] with | none := fail "reconstruct_ineq_of_eq_and_ineq failed to find proof" | some ⟨_, sfp, _⟩ := do ctrp ← sfpr sfp, fp ← mk_mapp ``lt_irrefl [none, none, none, ctrp], apply fp --applyc ``lt_irrefl, trace "apply3", apply ctrp, trace "apply4" end), return notpf --#check @reconstruct_ineq_of_eq_and_ineq_aux -- these are the hard cases. Is this the right place to handle them? private meta def reconstruct_ineq_of_eq_and_ineq_lhs {lhs rhs iq c} (c' : gen_comp) (ep : eq_proof lhs rhs c) (ip : ineq_proof lhs rhs iq) : tactic expr := reconstruct_ineq_of_eq_and_ineq_aux c' ep ip lhs --fail "reconstruct_ineq_of_eq_and_ineq not implemented" private meta def reconstruct_ineq_of_eq_and_ineq_rhs {lhs rhs iq c} (c' : gen_comp) (ep : eq_proof lhs rhs c) (ip : ineq_proof lhs rhs iq) : tactic expr := reconstruct_ineq_of_eq_and_ineq_aux c' ep ip rhs /-do negt ← c'.to_comp.to_function rhs `(0 : ℚ), (_, notpf) ← solve_aux negt (do applyc $ neg_op_lemma_name c'.to_comp, hypv ← intro `h, let sfid := sum_form_comp_data.of_ineq_data ⟨_, ip⟩ in let sfed := sum_form_comp_data.of_eq_data ⟨_, ep⟩ in let sfsd := sum_form_comp_data.of_sign_data ⟨c', hyp rhs _ hypv⟩ in match find_contrad_sfcd_in_sfcd_list [sfid, sfed, sfsd] with | none := fail "reconstruct_ineq_of_eq_and_ineq_rhs failed to find proof" | some ⟨_, sfp, _⟩ := do ctrp ← sfpr sfp, applyc ``lt_irrefl, apply ctrp end), return notpf-/ -- fail "reconstruct_ineq_of_eq_and_ineq not implemented" -- TODO private meta def reconstruct_ineq_of_ineq_and_eq_zero_rhs {lhs rhs iq} (c : gen_comp) (ip : ineq_proof lhs rhs iq) (sp : sign_proof lhs gen_comp.eq) : tactic expr := fail "reconstruct_ineq_of_ineq_and_eq_zero not implemented" private meta def reconstruct_diseq_of_strict_ineq {e c} (sp : sign_proof e c) : tactic expr := if c.is_strict then do spp ← rc sp, mk_app ``ne_of_strict_op [spp] else fail "reconstruct_diseq_of_strict_ineq failed, comp is not strict" end -- TODO private meta def reconstruct_of_sum_form_proof (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) (e : expr) (c : gen_comp) {sfc} (sp : sum_form_proof sfc) : tactic expr := do pf' ← sfpr sp, --trace "in sign_proof.reconstruct_of_sum_form_proof", --infer_type e >>= trace, --trace c, let coeff := sfc.sf.get_coeff e, if coeff = 0 then fail "sign_proof.reconstruct_of_sum_form_proof failed, zero coeff" else do coeff_sign_pr ← mk_sign_pf coeff, -- if coeff < 0 then mk_mapp (if coeff < 0 then ``rev_op_zero_of_neg_mul_op_zero else ``op_zero_of_pos_mul_op_zero) [none, none, none, none, coeff_sign_pr, pf'] -- else if coeff > 0 then -- mk_mapp ``op_zero_of_pos_mul_op_zero [none, none, none, none, coeff_sign_] -- fail "sign_proof.reconstruct_of_sum_form_proof failed, not implemented yet" meta def reconstruct_eq_of_le_of_ge (rct : Π {e c}, sign_proof e c → tactic expr) {e} (lep : sign_proof e gen_comp.le) (gep : sign_proof e gen_comp.ge) : tactic expr := do lep' ← rct lep, gep' ← rct gep, mk_app ``le_antisymm' [lep', gep'] meta def reconstruct_aux (sfpr : Π {sf}, Π (sp : sum_form_proof sf), tactic expr) : Π {e c}, sign_proof e c → tactic expr | .(_) .(_) (hyp e c pf) := reconstruct_hyp e c pf | .(_) .(_) (scaled_hyp e c pf q) := reconstruct_scaled_hyp e c pf q | .(_) .(_) (@ineq_lhs c _ _ _ ip) := reconstruct_ineq_lhs @reconstruct_aux @sfpr c ip | .(_) .(_) (@ineq_rhs c _ _ _ ip) := reconstruct_ineq_rhs @reconstruct_aux @sfpr c ip | .(_) .(_) (@eq_of_two_eqs_lhs _ _ _ _ ep1 ep2) := reconstruct_eq_of_two_eqs_lhs @reconstruct_aux @sfpr ep1 ep2 | .(_) .(_) (@eq_of_two_eqs_rhs _ _ _ _ ep1 ep2) := reconstruct_eq_of_two_eqs_rhs @reconstruct_aux @sfpr ep1 ep2 | .(_) .(_) (@diseq_of_diseq_zero _ _ dp) := reconstruct_diseq_of_diseq_zero dp | .(_) .(_) (@eq_of_eq_zero _ _ ep) := reconstruct_eq_of_eq_zero @reconstruct_aux @sfpr ep | .(_) .(_) (eq_of_le_of_ge lep gep) := reconstruct_eq_of_le_of_ge @reconstruct_aux lep gep | .(_) .(_) (@ineq_of_eq_and_ineq_lhs _ _ _ _ c' ep ip) := reconstruct_ineq_of_eq_and_ineq_lhs @sfpr c' ep ip | .(_) .(_) (@ineq_of_eq_and_ineq_rhs _ _ _ _ c' ep ip) := reconstruct_ineq_of_eq_and_ineq_rhs @sfpr c' ep ip | .(_) .(_) (@ineq_of_ineq_and_eq_zero_rhs _ _ _ c ip sp) := reconstruct_ineq_of_ineq_and_eq_zero_rhs c ip sp | .(_) .(_) (@diseq_of_strict_ineq _ _ sp) := reconstruct_diseq_of_strict_ineq @reconstruct_aux sp | .(_) .(_) (@of_sum_form_proof e c _ sp) := reconstruct_of_sum_form_proof @sfpr e c sp | .(_) .(_) (adhoc _ _ _ t) := t end sign_proof namespace sum_form_proof section parameter sfrc : Π {sfc}, sum_form_proof sfc → tactic expr private meta def sprc := @sign_proof.reconstruct_aux @sfrc private meta def iprc := @ineq_proof.reconstruct_aux @sprc @sfrc private meta def eprc := @eq_proof.reconstruct_aux @iprc @sfrc -- assumes lhs < rhs private meta def reconstruct_of_ineq_proof : Π {lhs rhs iq}, ineq_proof lhs rhs iq → tactic expr | lhs rhs iq ip := if expr.lt lhs rhs then reconstruct_of_ineq_proof ip.sym else --trace "ipp is:" >> iprc ip >>= infer_type >>= trace >> trace "const is:" >> infer_type ↑`(@polya.mul_lt_of_lt) >>= trace >> match iq.to_slope with | slope.horiz := do ipp ← iprc ip, tactic.mk_mapp (sum_form_name_of_comp_single iq.to_comp) [none, none, ipp] | slope.some m := do ipp ← iprc ip, --trace ("ipp", ip, ipp), infer_type ipp >>= trace, trace ("comp", iq.to_comp), trace ("iq", iq), if m = 0 then tactic.mk_mapp (sum_form_name_of_comp_single iq.to_comp) [none, none, ipp] else tactic.mk_mapp (sum_form_name_of_comp iq.to_comp) [none, none, none, ipp] -- tactic.mk_mapp ((if m = 0 then sum_form_name_of_comp_single else sum_form_name_of_comp) iq.to_comp) [none, none, ipp] end --include sfrc private meta def reconstruct_of_eq_proof : Π {lhs rhs c}, eq_proof lhs rhs c → tactic expr | lhs rhs c ep := if expr.lt lhs rhs then reconstruct_of_eq_proof ep.sym else do ipp ← eprc ep, mk_app ``sub_eq_zero_of_eq [ipp] --fail "sum_form_proof.reconstruct_of_eq_proof not implemented yet" private meta def reconstruct_of_sign_proof : Π {e c}, sign_proof e c → tactic expr | e c sp := if c.is_less then sprc sp else do spp ← sprc sp, --trace "spp type is", infer_type spp >>= trace, mk_mapp ``rev_op_zero_of_op [none, none, none, some spp] --fail "sum_form_proof.reconstruct_of_sign_proof not implemented yet" -- sum_form_proof ⟨lhs.add_factor rhs m, spec_comp.strongest c1 c2⟩ -- wait for algebraic normalizer? -- TODO private theorem reconstruct_of_add_factor_aux (P : Prop) {Q R : Prop} (h : Q) (h2 : R) : P := sorry private meta def reconstruct_of_add_factor_same_comp {lhs rhs c1 c2} (m : ℚ) (sfpl : sum_form_proof ⟨lhs, c1⟩) (sfpr : sum_form_proof ⟨rhs, c2⟩) : tactic expr := let sum := lhs + rhs.scale m in do tp ← sum_form.to_expr sum, tp' ← (spec_comp.strongest c1 c2).to_comp.to_function tp `(0 : ℚ), pf1 ← sfrc sfpl, pf2 ← sfrc sfpr, mk_mapp ``reconstruct_of_add_factor_aux [some tp', none, none, some pf1, some pf2] --to_expr `(sorry : %%tp) --fail "reconstruct_of_add_factor_same_comp failed, not implemented yet" private theorem reconstruct_of_add_eq_factor_op_comp_aux (P : Prop) {Q R : Prop} (h : Q) (h2 : R) : P := sorry /- m is negative -/ private meta def reconstruct_of_add_eq_factor_op_comp {lhs rhs c1} (m : ℚ) (sfpl : sum_form_proof ⟨lhs, c1⟩) (sfpr : sum_form_proof ⟨rhs, spec_comp.eq⟩) : tactic expr := let sum := lhs + rhs.scale m in do tp ← sum_form.to_expr sum, tp' ← c1.to_comp.to_function tp `(0 : ℚ), pf1 ← sfrc sfpl, pf2 ← sfrc sfpr, mk_mapp ``reconstruct_of_add_eq_factor_op_comp_aux [some tp', none, none, some pf1, some pf2] --fail "reconstruct_of_add_eq_factor_op_comp not implemented yet" private theorem reconstruct_of_scale_aux (P : Prop) {Q : Prop} (h : Q) : P := sorry private meta def reconstruct_of_scale (rct : Π {sfc}, sum_form_proof sfc → tactic expr) {sfc} (m : ℚ) (sfp : sum_form_proof sfc) : tactic expr := do tp ← sum_form.to_expr (sfc.sf.scale m), tp' ← sfc.c.to_comp.to_function tp `(0 : ℚ), pf ← rct sfp, mk_mapp ``reconstruct_of_scale_aux [some tp', none, some pf] -- to_expr `(sorry : %%tp') end -- TODO (alg norm) theorem reconstruct_of_expr_def_aux (P : Prop) : P := sorry private meta def reconstruct_of_expr_def (e : expr) (sf : sum_form) : tactic expr := do tp ← sum_form.to_expr sf, tp' ← to_expr ``(%%tp = 0), -- (_, pf) ← solve_aux tp' (simp >> done), mk_app ``reconstruct_of_expr_def_aux [tp'] -- instantiate_mvars pf --fail "reconstruct_of_expr_def failed, not implemented yet" meta def reconstruct : Π {sfc}, sum_form_proof sfc → tactic expr | _ (of_ineq_proof ip) := reconstruct_of_ineq_proof @reconstruct ip | _ (of_eq_proof ep) := reconstruct_of_eq_proof @reconstruct ep | _ (of_sign_proof sp) := reconstruct_of_sign_proof @reconstruct sp | _ (of_add_factor_same_comp m sfpl sfpr) := reconstruct_of_add_factor_same_comp @reconstruct m sfpl sfpr | _ (of_add_eq_factor_op_comp m sfpl sfpr) := reconstruct_of_add_eq_factor_op_comp @reconstruct m sfpl sfpr | _ (of_scale m sfp) := reconstruct_of_scale @reconstruct m sfp | _ (of_expr_def e sf) := reconstruct_of_expr_def e sf | _ (fake sd) := fail "cannot reconstruct a fake proof" /-meta def reconstruct : Π {sfc}, sum_form_proof sfc → tactic expr | sfc sfp := if sfc.sf.keys.length = 0 then do ex ← sfc.c.to_comp.to_function ```(0 : ℚ) ```(0 : ℚ), to_expr `(sorry : %%ex) else let sfcd : sum_form_comp_data := ⟨_, sfp, mk_rb_set⟩ in match sfcd.to_ineq_data with | option.some ⟨lhs, rhs, id⟩ := do ex ← ineq_data.to_expr id, to_expr `(sorry : %%ex) | none := trace sfc >> fail "fake sum_form_proof.reconstruct failed, no ineq data" end-/ end sum_form_proof meta def sign_proof.reconstruct := @sign_proof.reconstruct_aux @sum_form_proof.reconstruct meta def ineq_proof.reconstruct := @ineq_proof.reconstruct_aux @sign_proof.reconstruct @sum_form_proof.reconstruct meta def eq_proof.reconstruct := @eq_proof.reconstruct_aux @ineq_proof.reconstruct @sum_form_proof.reconstruct meta def ineq_data.to_expr {lhs rhs} (id : ineq_data lhs rhs) : tactic expr := match id.inq.to_slope with | slope.horiz := id.inq.to_comp.to_function rhs `(0 : ℚ) | slope.some m := if m = 0 then id.inq.to_comp.to_function lhs `(0 : ℚ) else do rhs' ← to_expr ``(%%(m.reflect : expr)*%%rhs), id.inq.to_comp.to_function lhs rhs' end namespace contrad private meta def reconstruct_eq_diseq {lhs rhs} (ed : eq_data lhs rhs) (dd : diseq_data lhs rhs) : tactic expr := if bnot (ed.c = dd.c) then fail "reconstruct_eq_diseq failed: given different coefficients" else do ddp ← dd.prf.reconstruct, edp ← ed.prf.reconstruct, return $ ddp.app edp private meta def reconstruct_two_ineq_data {lhs rhs} (rct : contrad → tactic expr) (id1 id2 : ineq_data lhs rhs) : tactic expr := let sfid1 := sum_form_comp_data.of_ineq_data id1, sfid2 := sum_form_comp_data.of_ineq_data id2 in match find_contrad_in_sfcd_list [sfid1, sfid2] with | some ctr := rct ctr | option.none := fail "reconstruct_two_ineq_data failed to find contr" end private meta def reconstruct_eq_ineq {lhs rhs} (ed : eq_data lhs rhs) (id : ineq_data lhs rhs) : tactic expr := fail "reconstruct_eq_ineq not implemented" -- TODO: this is the hard part. Should this be refactored into smaller pieces? private meta def reconstruct_ineqs (rct : contrad → tactic expr) {lhs rhs} (ii : ineq_info lhs rhs) (id : ineq_data lhs rhs) : tactic expr := --do trace "ineqs!!", match ii with | ineq_info.no_comps := fail "reconstruct_ineqs cannot find a contradiction with no known comps" | ineq_info.one_comp id2 := reconstruct_two_ineq_data rct id id2 | ineq_info.equal ed := reconstruct_eq_ineq ed id | ineq_info.two_comps id1 id2 := let sfid := sum_form_comp_data.of_ineq_data id, sfid1 := sum_form_comp_data.of_ineq_data id1, sfid2 := sum_form_comp_data.of_ineq_data id2 in match find_contrad_in_sfcd_list [sfid, sfid1, sfid2] with | some ctr := rct ctr | option.none := fail "reconstruct_ineqs failed to find contr" end end private meta def reconstruct_sign_ne_eq {e} (nepr : sign_proof e gen_comp.ne) (eqpr : sign_proof e gen_comp.eq) : tactic expr := do neprp ← nepr.reconstruct, eqprp ← eqpr.reconstruct, return $ neprp.app eqprp private meta def reconstruct_sign_le_gt {e} (lepr : sign_proof e gen_comp.le) (gtpr : sign_proof e gen_comp.gt) : tactic expr := do leprp ← lepr.reconstruct, gtprp ← gtpr.reconstruct, mk_app ``le_gt_contr [leprp, gtprp] private meta def reconstruct_sign_ge_lt {e} (gepr : sign_proof e gen_comp.ge) (ltpr : sign_proof e gen_comp.lt) : tactic expr := do geprp ← gepr.reconstruct, ltprp ← ltpr.reconstruct, mk_app ``ge_lt_contr [geprp, ltprp] private meta def reconstruct_sign_gt_lt {e} (gtpr : sign_proof e gen_comp.gt) (ltpr : sign_proof e gen_comp.lt) : tactic expr := do gtprp ← gtpr.reconstruct, ltprp ← ltpr.reconstruct, mk_app ``gt_lt_contr [gtprp, ltprp] private meta def reconstruct_sign {e} : sign_data e → sign_data e → tactic expr | ⟨gen_comp.ne, prf1⟩ ⟨gen_comp.eq, prf2⟩ := reconstruct_sign_ne_eq prf1 prf2 | ⟨gen_comp.eq, prf1⟩ ⟨gen_comp.ne, prf2⟩ := reconstruct_sign_ne_eq prf2 prf1 | ⟨gen_comp.le, prf1⟩ ⟨gen_comp.gt, prf2⟩ := reconstruct_sign_le_gt prf1 prf2 | ⟨gen_comp.gt, prf1⟩ ⟨gen_comp.le, prf2⟩ := reconstruct_sign_le_gt prf2 prf1 | ⟨gen_comp.lt, prf1⟩ ⟨gen_comp.ge, prf2⟩ := reconstruct_sign_ge_lt prf2 prf1 | ⟨gen_comp.ge, prf1⟩ ⟨gen_comp.lt, prf2⟩ := reconstruct_sign_ge_lt prf1 prf2 | ⟨gen_comp.gt, prf1⟩ ⟨gen_comp.lt, prf2⟩ := reconstruct_sign_gt_lt prf1 prf2 | ⟨gen_comp.lt, prf1⟩ ⟨gen_comp.gt, prf2⟩ := reconstruct_sign_gt_lt prf2 prf1 | s1 s2 := trace e >> trace s1.c >> trace s2.c >> fail "reconstruct_sign failed: given non-opposite comps" private meta def reconstruct_strict_ineq_self {e} (id : ineq_data e e) : tactic expr := match id.inq.to_comp, id.inq.to_slope with | comp.gt, slope.some m := if bnot (m = 1) then fail "reconstruct_strict_ineq_self failed: given non-one slope" else do idp ← id.prf.reconstruct, mk_app ``gt_self_contr [idp] | comp.lt, slope.some m := if bnot (m = 1) then fail "reconstruct_strict_ineq_self failed: given non-one slope" else do idp ← id.prf.reconstruct, mk_app ``lt_self_contr [idp] | _, _ := fail "reconstruct_strict_ineq_self failed: given non-strict comp or non-one slope" end meta def reconstruct_sum_form {sfc} (sfp : sum_form_proof sfc) : tactic expr := if sfc.is_contr then do zltz ← sfp.reconstruct, mk_mapp ``lt_irrefl [option.none, option.none, option.none, some zltz] else fail "reconstruct_sum_form requires proof of 0 < 0" meta def reconstruct : contrad → tactic expr | none := fail "cannot reconstruct contr: no contradiction is known" | (@eq_diseq lhs rhs ed dd) := reconstruct_eq_diseq ed dd | (@ineqs lhs rhs ii id) := reconstruct_ineqs reconstruct ii id | (@sign e sd1 sd2) := reconstruct_sign sd1 sd2 | (@strict_ineq_self e id) := reconstruct_strict_ineq_self id | (@sum_form _ sfp) := reconstruct_sum_form sfp end contrad namespace prod_form_proof /-private meta def mk_prod_ne_zero_prf_aux : expr → list (Σ e : expr, sign_proof e gen_comp.ne) → tactic expr | e [] := return e | e (⟨e', sp⟩::t) := do ene ← sp.reconstruct, pf ← mk_app ``mul_ne_zero [e, ene], mk_prod_ne_zero_prf_aux pf t private meta def mk_prod_ne_zero_prf (c : ℚ) : list (Σ e : expr, sign_proof e gen_comp.ne) → tactic expr | [] := if c = 0 then fail "mk_prod_ne_zero_prf failed, c = 0" else mk_app ``fake_ne_zero_pf [`(c)] | (⟨e, sp⟩::t) := if c = 0 then fail "mk_prod_ne_zero_prf failed, c = 0" else do cprf ← mk_app ``fake_ne_zero_pf [`(c)], hpf ← sp.reconstruct, prodprf ← mk_prod_ne_zero_prf_aux hpf t, mk_app ``mul_ne_zero [hpf, prodprf] -/ /-#check spec_comp_and_flipped_of_comp -- not finished: need to orient c private meta def reconstruct_of_ineq_proof_pos_lhs {lhs rhs iq} (id : ineq_proof lhs rhs iq) (sp : sign_proof lhs gen_comp.gt) (nzprs : hash_map expr (λ e, sign_proof e gen_comp.ne)) : tactic expr := match (spec_comp_and_flipped_of_comp iq.to_comp), iq.to_slope with | _, slope.horiz := fail "reconstruct_of_ineq_proof_pos_lhs failed, cannot make a prod_form with 0 slope" | (c, flipped), slope.some m := if m = 0 then fail "reconstruct_of_ineq_proof_pos_lhs failed, cannot make a prod_form with 0 slope" else do -- lhs c m*rhs --> 1 c m*(lhs⁻¹*rhs) idp ← id.reconstruct, spp ← sp.reconstruct, opp ← mk_app ``one_op_inv_mul_of_op_of_pos [idp, spp], -- 1 r lhs⁻¹*rhs if bnot flipped then return opp else do mprf ← mk_sign_pf m, failed end-/ private meta def reconstruct_of_ineq_proof_aux {lhs rhs iq c1 c2} (id : ineq_proof lhs rhs iq) (spl : sign_proof lhs c1) (spr : sign_proof rhs c2) (fail_cond : ℚ → bool) (unflipped_name flipped_name : name) --flipped_lt_name flipped_le_name : name) : tactic expr := match (spec_comp_and_flipped_of_comp iq.to_comp), iq.to_slope with | _, slope.horiz := fail "reconstruct_of_ineq_proof_pos_pos failed, cannot make a prod_form with 0 slope" | (c, flipped), slope.some m := --trace "okay, roipa" >> trace flipped >> trace iq >> if fail_cond m then fail "reconstruct_of_ineq_proof_aux failed check" else do idp ← id.reconstruct, --trace "idp_type:", infer_type idp >>= trace, splp ← spl.reconstruct, --trace "splp_type:", infer_type splp >>= trace, trace "c1 is:", trace c1, trace spl, opp ← mk_app unflipped_name [idp, splp], --trace "opp", infer_type opp >>= trace, if bnot flipped then return opp else do msgn ← mk_sign_pf m, sprp ← spr.reconstruct, trace "HERE", infer_type opp >>= trace, infer_type splp >>= trace, infer_type sprp >>= trace, infer_type msgn >>= trace, trace unflipped_name, trace iq, mk_app flipped_name-- (if c=spec_comp.lt then flipped_lt_name else flipped_le_name) [opp, splp, sprp, msgn] end private meta def reconstruct_of_ineq_proof_pos_pos {lhs rhs iq} (id : ineq_proof lhs rhs iq) (spl : sign_proof lhs gen_comp.gt) (spr : sign_proof rhs gen_comp.gt) : tactic expr := reconstruct_of_ineq_proof_aux id spl spr (λ m, m ≤ 0) ``one_op_inv_mul_of_op_of_pos ``one_op_inv_mul_of_lt_of_pos_pos_flipped' -- ``one_le_inv_mul_of_le_of_pos_pos_flipped /-match (spec_comp_and_flipped_of_comp iq.to_comp), iq.to_slope with | _, slope.horiz := fail "reconstruct_of_ineq_proof_pos_pos failed, cannot make a prod_form with 0 slope" | (c, flipped), slope.some m := if m ≤ 0 then fail "reconstruct_of_ineq_proof_pos_pos failed, m ≤ 0" else do idp ← id.reconstruct, splp ← spl.reconstruct, opp ← mk_app ``one_op_inv_mul_of_op_of_pos [idp, splp], if bnot flipped then return opp else do msgn ← mk_sign_pf m, sprp ← spr.reconstruct, mk_app (if c=spec_comp.lt then ``one_lt_inv_mul_of_lt_of_pos_flipped else ``one_le_inv_mul_of_le_of_pos_flipped) [opp, splp, sprp, msgn] end-/ private meta def reconstruct_of_ineq_proof_pos_neg {lhs rhs iq} (id : ineq_proof lhs rhs iq) (spl : sign_proof lhs gen_comp.gt) (spr : sign_proof rhs gen_comp.lt) : tactic expr := reconstruct_of_ineq_proof_aux id spl spr (λ m, m ≥ 0) ``one_op_inv_mul_of_op_of_pos ``one_op_inv_mul_of_lt_of_pos_neg_flipped -- ``one_le_inv_mul_of_le_of_pos_neg_flipped private meta def reconstruct_of_ineq_proof_neg_pos {lhs rhs iq} (id : ineq_proof lhs rhs iq) (spl : sign_proof lhs gen_comp.lt) (spr : sign_proof rhs gen_comp.gt) : tactic expr := reconstruct_of_ineq_proof_aux id spl spr (λ m, m ≥ 0) ``one_op_inv_mul_of_op_of_neg ``one_op_inv_mul_of_lt_of_neg_pos_flipped -- ``one_le_inv_mul_of_le_of_neg_flipped private meta def reconstruct_of_ineq_proof_neg_neg {lhs rhs iq} (id : ineq_proof lhs rhs iq) (spl : sign_proof lhs gen_comp.lt) (spr : sign_proof rhs gen_comp.lt) : tactic expr := reconstruct_of_ineq_proof_aux id spl spr (λ m, m ≤ 0) ``one_op_inv_mul_of_op_of_neg ``one_op_inv_mul_of_lt_of_neg_neg_flipped /- pos_neg cmatch (spec_comp_and_flipped_of_comp iq.to_comp), iq.to_slope with | _, slope.horiz := fail "reconstruct_of_ineq_proof_pos_pos failed, cannot make a prod_form with 0 slope" | (c, flipped), slope.some m := if m ≥ 0 then fail "reconstruct_of_ineq_proof_pos_neg failed, m ≥ 0" else do idp ← id.reconstruct, splp ← spl.reconstruct, opp ← mk_app ``one_op_inv_mul_of_op_of_pos [idp, splp], if bnot flipped then return opp else do msgn ← mk_sign_pf m, sprp ← spr.reconstruct, mk_app (if c=spec_comp.lt then ``one_lt_inv_mul_of_lt_of_pos_flipped else ``one_le_inv_mul_of_le_of_pos_flipped) [opp, splp, sprp, msgn] end -/ private meta def reconstruct_of_ineq_proof {lhs rhs iq} (id : ineq_proof lhs rhs iq) : Π {cl cr}, sign_proof lhs cl → sign_proof rhs cr → tactic expr | gen_comp.gt gen_comp.gt spl spr := reconstruct_of_ineq_proof_pos_pos id spl spr | gen_comp.gt gen_comp.lt spl spr := reconstruct_of_ineq_proof_pos_neg id spl spr | gen_comp.lt gen_comp.gt spl spr := reconstruct_of_ineq_proof_neg_pos id spl spr | gen_comp.lt gen_comp.lt spl spr := reconstruct_of_ineq_proof_neg_neg id spl spr | _ _ _ _ := fail "reconstruct_of_ineq_proof failed, need to know signs of components" /- -- TODO private meta def reconstruct_of_ineq_proof_neg_lhs {lhs rhs iq} (id : ineq_proof lhs rhs iq) (sp : sign_proof lhs gen_comp.lt) (nzprs : hash_map expr (λ e, sign_proof e gen_comp.ne)) : tactic expr := match iq.to_slope with | slope.horiz := fail "reconstruct_of_ineq_proof_neg_lhs failed, cannot make a prod_form with 0 slope" | slope.some m := if m = 0 then fail "reconstruct_of_ineq_proof_pos_lhs failed, cannot make a prod_form with 0 slope" else failed end-/ private meta def reconstruct_of_eq_proof {lhs rhs c} (id : eq_proof lhs rhs c) (lhsne : sign_proof lhs gen_comp.ne) : tactic expr := if c = 0 then fail "reconstruct_of_eq_proof failed, cannot make a prod_form with 0 slope" else do lhsnep ← lhsne.reconstruct, idpf ← id.reconstruct, mk_app ``one_eq_div_of_eq [idpf, lhsnep] theorem reconstruct_of_expr_def_aux (P : Prop) : P := sorry /- -- TODO private meta def reconstruct_of_expr_def (e : expr) (sf : sum_form) : tactic expr := do tp ← sum_form.to_expr sf, tp' ← to_expr ``(%%tp = 0), -- (_, pf) ← solve_aux tp' (simp >> done), mk_app ``reconstruct_of_expr_def_aux [tp'] -- instantiate_mvars pf --fail "reconstruct_of_expr_def failed, not implemented yet" -/ -- TODO (alg_nom) private meta def reconstruct_of_expr_def (e : expr) (pf : prod_form) : tactic expr := do --trace "in reconstruct_of_expr_def", tp ← prod_form.to_expr pf, -- trace "tp:", trace tp, tp' ← to_expr ``(1 = %%tp), -- trace "tp':", trace tp', -- (_, pf) ← solve_aux tp' (simp >> done), mk_app ``reconstruct_of_expr_def_aux [tp'] section variable (rct : Π {pfc}, prod_form_proof pfc → tactic expr) -- Given an expr of the form e := (p1^e1)^k, produces a proof that -- e = p1^(e1*k) private meta def simp_pow_aux_aux (p e k : expr) : tactic expr := mk_app ``rat.pow_pow [p, e, k] /-private meta def simp_pow_aux_aux : expr → tactic expr | `(rat.pow (rat.pow %%p %%e) %%k) := mk_app ``rat.pow_pow [p, e, k] | _ := failed -/ -- Given an expr of the form e := (p1^e1*...*pn^en)^k, produces a proof that -- e = (p1^(e1*k) * ... * pn^(en*k) private meta def simp_pow_aux : expr → tactic expr | e := match e with | `(rat.pow (%%a * (rat.pow %%b %%n)) %%k) := let prod' := `(rat.pow %%a %%k) in do prod_pf ← simp_pow_aux prod', pow_pf ← mk_app ``rat.mul_pow [a, `(rat.pow %%b %%n), k], one_pow_pf ← simp_pow_aux_aux b n k, -- trace "doing rewrite", -- infer_type pow_pf >>= trace, trace e, (e', pf1, []) ← rewrite pow_pf e, (e'', pf2, []) ← rewrite one_pow_pf e', (e''', pf3, []) ← rewrite prod_pf e'', t1 ← mk_app ``eq.trans [pf1, pf2], mk_app ``eq.trans [t1, pf3] | `(rat.pow (rat.pow %%a %%n) %%k) := simp_pow_aux_aux a n k | e := do f ← pp e, fail $ "simp_pow_aux failed on " ++ f.to_string end -- Given an expr of the form e := (c*(p1^e1*...*pn^en))^k, produces a proof that -- e = c^k * (p1^(e1*k) * ... * pn^(en*k)) meta def simp_pow (e : expr) : tactic expr := --do trace "simp pow called on:", trace e, match e with | `(rat.pow (%%coeff * %%prod) %%k) := let prod' := `(rat.pow %%prod %%k) in do prod_pf ← simp_pow_aux prod', pow_pf ← mk_app ``rat.mul_pow [coeff, prod, k], --trace "doing rewrite", (e', pf1, []) ← rewrite pow_pf e, (e'', pf2, []) ← rewrite prod_pf e', mk_app ``eq.trans [pf1, pf2] | _ := fail "simp_pow got malformed arg" end /-example (a b c : ℚ) (m n k : ℤ) : rat.pow (a * (rat.pow b m * rat.pow c n)) k = rat.pow a k * (rat.pow b (m*k) * rat.pow c (n*k)) := by do (lhs, rhs) ← target >>= match_eq, e ← simp_pow lhs, infer_type e >>= trace, exact e-/ private meta def simp_pow_expr (pf tgt : expr) : tactic expr := do sls ← (simp_lemmas.mk.add_simp ``rat.mul_pow_rev) >>= λ t, t.add pf, --trace "target", trace tgt, --trace "pf tp", infer_type pf >>= trace, (do (_, npf) ← simplify sls [] tgt,-- <|> do rpr ← to_expr ``(eq.refl %%tgt), return (`(()), rpr), --(_, npf) ← solve_aux tgt (simp_target sls >> done), return npf) <|> to_expr ``(eq.refl %%tgt) meta def simp_lemmas.add_simp_list : simp_lemmas → list name → tactic simp_lemmas | s [] := return s | s (h::t) := s.add_simp h >>= λ s', simp_lemmas.add_simp_list s' t private meta def simp_pow_expr' (tgt : expr) : tactic expr := do --sls ← (simp_lemmas.mk.add_simp ``rat.mul_pow) >>= (λ s, simp_lemmas.add_simp s ``rat.pow_one) >>= (λ s, simp_lemmas.add_simp s ``rat.pow_neg_one), sls ← simp_lemmas.add_simp_list simp_lemmas.mk [``rat.mul_pow, ``rat.pow_one, ``rat.pow_neg_one, ``rat.one_pow, ``rat.pow_pow, ``rat.one_div_pow], --trace "target", trace tgt, -- trace "pf tp", infer_type pf >>= trace, -- (do (_, npf) ← simplify sls [] tgt,-- <|> do rpr ← to_expr ``(eq.refl %%tgt), return (`(()), rpr), (_, npf) ← solve_aux tgt ( /-trace_state >>-/ simp_target sls >>/- trace "!!!" >> trace_state >>-/ reflexivity), -- `[simp [rat.mul_pow_rev, rat.pow_one], done], return npf section open expr private meta def reconstruct_of_pow_pos {pfc} (z : ℤ) (pfp : prod_form_proof pfc) : tactic expr := if z ≤ 0 then fail "reconstruct_of_pow_pos failed, given negative exponent" else do zsn ← mk_int_sign_pf z, pf1 ← rct pfp, --trace "here", /-trace pfc,-/ trace pfp, trace z, infer_type pf1 >>= trace, pf2 ← mk_mapp (if pfc.c = spec_comp.lt then ``lt_pos_pow' else ``le_pos_pow') [none, pf1, none, zsn], --trace "pf2tp", infer_type pf2 >>= trace, pf2tp ← infer_type pf2, match pf2tp with | (app (app (app o i) lhs) rhs) := do eqp ← simp_pow rhs, (new_type, prf, []) ← rewrite eqp pf2tp, mk_eq_mp prf pf2 -- failed | _ := fail "reconstruct_of_pow_pos failed" end /- match pf2tp with | app (app (app o i) lhs) rhs := do tgt ← prod_form.to_expr (pfc.pf.pow z), pf ← to_expr ``(%%rhs = %%tgt) >>= simp_pow_expr', trace "pf2tp", trace pf2tp, trace "pftp", infer_type pf >>= trace, trace "o", trace o, -- trace `(%%o %%lhs %%tgt), tgt' ← return $ app (app (app o i) lhs) tgt,--to_expr ``(%%o %%lhs %%tgt), trace "new tgt:", trace tgt', pf1 ← to_expr ``(eq.symm %%pf), (_, pf') ← solve_aux tgt' (rewrite_target pf1 >> apply pf2), trace "proved", infer_type pf' >>= trace, return pf' | _ := failed end -- tgt ← prod_form.to_expr (pfc.pf.pow z), -- simp_pow_expr pf2 tgt -/ end /-private meta def reconstruct_of_pow_neg {pfc} (z : ℤ) (pfp : prod_form_proof pfc) : tactic expr := if z ≥ 0 then fail "reconstruct_of_pow_neg failed, given positive exponent" else failed-/ private meta def reconstruct_of_pow_eq {pfc} (z : ℤ) (pfp : prod_form_proof pfc) : tactic expr := do --trace "pfp is:", trace pfp, pf1 ← rct pfp, --trace "reconstructed", infer_type pf1 >>= trace, tpf ← mk_app ``eq_pow [pf1, `(z)], tpf' ← mk_app ``eq_pow' [tpf], tpf_tp ← infer_type tpf', tgt ← prod_form.to_expr (pfc.pf.pow z), --trace "target is:", trace tgt, tgt' ← to_expr ``(1 = %%tgt), --trace "tgt', tpf", trace tgt', infer_type tpf >>= trace, (_, pf') ← solve_aux tgt' (assertv `h tpf_tp tpf' >> `[simp only [rat.mul_pow, rat.pow_pow], simp only [rat.mul_pow, rat.pow_pow] at h, apply h] >> done), return pf' -- simp_pow_expr tpf tgt private meta def reconstruct_of_pow {pfc} (z : ℤ) (pfp : prod_form_proof pfc) : tactic expr := if pfc.c = spec_comp.eq then reconstruct_of_pow_eq @rct z pfp else reconstruct_of_pow_pos @rct z pfp private theorem reconstruct_of_mul_aux (P : Prop) {Q R : Prop} : Q → R → P := sorry private meta def reconstruct_of_mul (rct : Π {pfc}, prod_form_proof pfc → tactic expr) {lhs rhs c1 c2} (pfp1 : prod_form_proof ⟨lhs, c1⟩) (pfp2 : prod_form_proof ⟨rhs, c2⟩) (sgns : list Σ e : expr, sign_proof e gen_comp.ne) : tactic expr := let prod := lhs * rhs in do /-trace "in reconstruct_of_mul", trace prod,-/ tp ← prod_form.to_expr prod, --trace tp, tp' ← (spec_comp.strongest c1 c2).to_comp.to_function `(1 : ℚ) tp, --trace tp', pf1 ← rct pfp1, pf2 ← rct pfp2,-- trace "**", mk_mapp ``reconstruct_of_mul_aux [tp', none, none, pf1, pf2] /- let sum := lhs + rhs.scale m in do tp ← sum_form.to_expr sum, tp' ← (spec_comp.strongest c1 c2).to_comp.to_function tp `(0 : ℚ), pf1 ← sfrc sfpl, pf2 ← sfrc sfpr, mk_mapp ``reconstruct_of_add_factor_aux [some tp', none, none, some pf1, some pf2] -/ end meta def reconstruct : Π {pfc}, prod_form_proof pfc → tactic expr --| .(_) (@of_ineq_proof_pos_lhs _ _ _ id sp nzprs) := reconstruct_of_ineq_proof_pos_lhs id sp nzprs --| .(_) (@of_ineq_proof_neg_lhs _ _ _ id sp nzprs) := reconstruct_of_ineq_proof_neg_lhs id sp nzprs | .(_) (@of_ineq_proof _ _ _ _ _ id spl spr) := reconstruct_of_ineq_proof id spl spr | .(_) (@of_eq_proof _ _ _ id lhsne) := reconstruct_of_eq_proof id lhsne | .(_) (@of_expr_def e pf) := reconstruct_of_expr_def e pf | .(_) (@of_pow _ z pfp) := reconstruct_of_pow @reconstruct z pfp | .(_) (@of_mul _ _ _ _ pfp1 pfp2 sgns) := reconstruct_of_mul @reconstruct pfp1 pfp2 sgns | .(_) (adhoc _ _ t) := t | .(_) (fake _) := fail "prod_form_proof.reconstruct failed: cannot reconstruct fake" end prod_form_proof end polya
[STATEMENT] lemma inc_matrix_point_not_in_block_zero: "i < length Vs \<Longrightarrow> j < length Bs \<Longrightarrow> Vs ! i \<notin> Bs ! j \<Longrightarrow> (inc_mat_of Vs Bs) $$ (i, j) = 0" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>i < length Vs; j < length Bs; Vs ! i \<notin> Bs ! j\<rbrakk> \<Longrightarrow> inc_mat_of Vs Bs $$ (i, j) = (0::'b) [PROOF STEP] by(simp add: inc_mat_of_def)
function new_files = remove_disdaq_vols(img_files, num_vols_per_run, num_disdaq_vols, varargin) % :Usage: % :: % % new_files = remove_disdaq_vols(img_files, num_vols_per_run, num_disdaq_vols, ['overwrite', 0|1], ['FSLOUTPUTTYPE', fsl_output_type], ['strict', 0|1]) % % :Inputs: % % **img_files:** % cellstr of files to remove disdaqs from - each cell represents a run % % **num_vols_per_run:** % vector of volume counts per run, *not* including disdaq vols % % **num_disdaq_vols:** % constant describing how many data points to remove from the beginning of each run % % **'overwrite':** % if set, will overwriting images in place - defaults to 0 % % **'FSLOUTPUTTYPE':** % outputfile type - defaults to 'NIFTI' % % **'strict':** % if set, will error out unless data given to it is % exactly proper length - defaults to 1 - turn off ONLY with good reason % % :Output: % % **new_files:** % input files, but with a 'd' prepended, unless 'overwriting' was specified % % NB: Not set up for 3d files yet!!! % % :Examples: % :: % % % for an experiment % num_vols_per_run = [124 140 109]; % NOT including disdaqs % num_disdaq_vols = 4; global FSLDIR; scn_setup(); % Flags strict = 1; overwriting = 0; return_char = 0; fsl_output_type = 'NIFTI'; % Check inputs if ~isempty(varargin) for i = 1:length(varargin) if ischar(varargin{i}) switch(varargin{i}) case {'overwrite' 'overwriting'} overwriting = varargin{i+1}; case 'strict' strict = varargin{i+1}; case {'fsl_output_type', 'FSLOUTPUTTYPE'} fsl_output_type = varargin{i+1}; end end end end if(ischar(img_files)) disp('Cellstr not passed in, changing...') img_files = cellstr(img_files); return_char = 1; end % Use FSL to remove disdaqs new_files = cell(size(img_files)); for i=1:length(img_files) current_file = img_files{i}; num_frames = scn_num_volumes(current_file); if(strict && (num_frames ~= num_vols_per_run(i) + num_disdaq_vols(i))) error('The number of vols (%d) + disdaqs (%d) don''t add up to the length (%d) of the file (''%s'') passed in.', num_vols_per_run, num_disdaq_vols, num_frames, current_file); else if(overwriting) output_file = current_file; else [d f e] = fileparts(current_file); output_file = fullfile(d, ['d' f]); end fslroi_command = sprintf('export FSLDIR=%s && . %s/etc/fslconf/fsl.sh && FSLOUTPUTTYPE=%s && %s/bin/fslroi %s %s %d %d', ... FSLDIR, FSLDIR, fsl_output_type, FSLDIR, current_file, output_file, num_disdaq_vols, num_vols_per_run); disp(fslroi_command); system(fslroi_command); end new_files{i} = [output_file e]; end % Convert output back to char is only a single file was passed in if(return_char) new_files = char(new_files); end end
The Cache Creek Inn is a hotels bed & breakfast near Davis (in Rumsey). It is a lovely craftsman style inn with full wraparound porch, surrounded by large grassy yards with a hot tub and towering valley oaks. Bedrooms are large and sunny with private bathrooms. In the winter, fireplaces make the lobby cheerful. In the summer, rafting, kayaking and swimming holes and picnic spots are nearby on Cache Creek. Hiking trails are just up the road, leading to frog ponds along creeks. Birders will like the bluebirds, several species of woodpecker, and others. The coastal hills surround the property. The Cache Creek Inn accepts Davis Dollars community currency.
[STATEMENT] lemma ordinal_order_trans: "(x::ordinal) \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>x \<le> y; y \<le> z\<rbrakk> \<Longrightarrow> x \<le> z [PROOF STEP] by (cases x, cases y, cases z, auto elim: ord0_order_trans)
\name{get.all.sector.index} \alias{get.all.sector.index} \title{ Get index for all sectors } \description{ Get index for all sectors } \usage{ get.all.sector.index() } \details{ It simply returns a vector of all sector index. } \references{ Gu, Z. (2014) circlize implements and enhances circular visualization in R. Bioinformatics. } \examples{ \dontrun{ library(circlize) factors = letters[1:4] circos.initialize(factors, xlim = c(0, 1)) circos.trackPlotRegion(ylim = c(0, 1)) get.all.sector.index() circos.clear() } }
theory Coloring imports Main Permutation begin lemma MaxAtLeastLessThan [simp]: fixes k :: nat assumes "k > 0" shows "Max {0..<k} = k - 1" proof (subst Max_eq_iff) show "finite {0..<k}" using finite_atLeastLessThan by auto next show "{0..<k} \<noteq> {}" using assms by simp next show "k - 1 \<in> {0..<k} \<and> (\<forall>a\<in>{0..<k}. a \<le> k - 1)" using assms by auto qed text\<open>colors are represented by natural numbers\<close> type_synonym color = nat typedef coloring = "{cs :: color list. (\<exists> k. set cs = {0..<k})}" morphisms color_list coloring by (rule_tac x="[0]" in exI, auto) setup_lifting type_definition_coloring lift_definition length :: "coloring \<Rightarrow> nat" is List.length done lift_definition max_color :: "coloring \<Rightarrow> color" is "\<lambda> cs. Max (set cs)" done definition num_colors :: "coloring \<Rightarrow> nat" where "num_colors \<pi> = (if color_list \<pi> = [] then 0 else max_color \<pi> + 1)" definition colors :: "coloring \<Rightarrow> color list" where "colors \<pi> = [0..<num_colors \<pi>]" lemma distinct_colors: shows "distinct (colors \<pi>)" by (simp add: colors_def) lemma ex_color: assumes "c < num_colors \<pi>" shows "c \<in> set (colors \<pi>)" using assms unfolding colors_def num_colors_def by auto lift_definition color_fun :: "coloring => (nat => color)" is "\<lambda> cs v. cs ! v" done lemma color_fun_in_colors: assumes "v < length \<pi>" shows "color_fun \<pi> v \<in> set (colors \<pi>)" using assms unfolding colors_def num_colors_def by transfer (smt (verit, ccfv_SIG) MaxAtLeastLessThan One_nat_def Suc_pred add.commute empty_iff list.set(1) not_gr_zero nth_mem plus_1_eq_Suc set_upt upt_0) lemma ex_color_color_fun: assumes "c \<in> set (colors \<pi>)" shows "\<exists> v < length \<pi>. color_fun \<pi> v = c" using assms unfolding colors_def num_colors_def by transfer (metis (mono_tags, opaque_lifting) MaxAtLeastLessThan Suc_eq_plus1 Suc_pred' add_lessD1 atLeastLessThan_iff atLeastLessThan_upt comm_monoid_add_class.add_0 in_set_conv_nth length_greater_0_conv not_less0) lemma all_colors: shows "set (colors \<pi>) = set (map (color_fun \<pi>) [0..<length \<pi>])" unfolding colors_def num_colors_def by transfer (smt (verit, del_insts) MaxAtLeastLessThan Suc_eq_plus1_left Suc_pred' add.commute atLeastLessThan_iff atLeastLessThan_upt gr_zeroI length_greater_0_conv length_pos_if_in_set map_nth nth_mem) lemma all_colors_list: shows "colors \<pi> = remdups (sort (map (color_fun \<pi>) [0..<length \<pi>]))" by (metis all_colors colors_def remdups_upt set_sort sort_upt sorted_list_of_set_sort_remdups sorted_remdups sorted_sort sorted_sort_id) lemma color_fun_all_colors [simp]: shows "\<exists>k. color_fun \<pi> ` {0..<length \<pi>} = {0..<k}" by transfer (metis list.set_map map_nth set_upt) lemma coloring_eqI: assumes "length \<pi> = length \<pi>'" "\<forall> v < length \<pi>. color_fun \<pi> v = color_fun \<pi>' v" shows "\<pi> = \<pi>'" proof- have "color_list \<pi> = color_list \<pi>'" by (metis assms(1) assms(2) color_fun.rep_eq length.rep_eq nth_equalityI) then show ?thesis by (simp add: color_list_inject) qed definition color_fun_to_coloring :: "nat \<Rightarrow> (nat \<Rightarrow> color) \<Rightarrow> coloring" where "color_fun_to_coloring n \<pi> = coloring (map \<pi> [0..<n])" lemma color_fun_to_coloring [simp]: assumes "\<exists>k. \<pi> ` {0..<n} = {0..<k}" "v < n" shows "color_fun (color_fun_to_coloring n \<pi>) v = \<pi> v" using assms unfolding color_fun_to_coloring_def by (subst color_fun.abs_eq) (simp_all add: eq_onp_def) lemma color_fun_to_coloring_length [simp]: assumes "\<exists> k. \<pi> ` {0..<n} = {0..<k}" shows "length (color_fun_to_coloring n \<pi>) = n" using assms unfolding color_fun_to_coloring_def by transfer (simp add: coloring_inverse length.rep_eq) lemma color_fun_to_coloring_eq_conv: assumes "\<forall> v < n. \<pi>1 v = \<pi>2 v" shows "color_fun_to_coloring n \<pi>1 = color_fun_to_coloring n \<pi>2" unfolding color_fun_to_coloring_def by (smt (verit, best) assms ex_nat_less_eq linorder_not_less map_eq_conv set_upt) text\<open>------------------------------------------------------\<close> subsection\<open>Cells\<close> text\<open>------------------------------------------------------\<close> text \<open>Cell of a coloring is the set of all vertices colored by the given color\<close> definition cell :: "coloring \<Rightarrow> color \<Rightarrow> nat set" where "cell \<pi> c = {v. v < length \<pi> \<and> color_fun \<pi> v = c}" text \<open>The list of all cells of a given coloring\<close> definition cells :: "coloring \<Rightarrow> (nat set) list" where "cells \<pi> = map (\<lambda> c. cell \<pi> c) (colors \<pi>)" lemma cell_finite [simp]: shows "finite (cell \<pi> c)" unfolding cell_def by auto lemma length_cells [simp]: shows "List.length (cells \<pi>) = num_colors \<pi>" by (simp add: cells_def colors_def num_colors_def) lemma nth_cells [simp]: assumes "c < num_colors \<pi>" shows "cells \<pi> ! c = cell \<pi> c" using assms unfolding colors_def num_colors_def cells_def by auto lemma cells_disjunct: assumes "i < num_colors \<pi>" "j < num_colors \<pi>" "i \<noteq> j" shows "cells \<pi> ! i \<inter> cells \<pi> ! j = {}" using assms by (auto simp add: cell_def) lemma cells_non_empty: assumes "c \<in> set (cells \<pi>)" shows "c \<noteq> {}" using assms ex_color_color_fun unfolding cells_def cell_def by auto lemma cell_non_empty: assumes "c < num_colors \<pi>" shows "cell \<pi> c \<noteq> {}" by (metis assms cells_non_empty length_cells nth_cells nth_mem) definition cells_ok where "cells_ok n cs \<longleftrightarrow> (\<forall> i j. i < List.length cs \<and> j < List.length cs \<and> i \<noteq> j \<longrightarrow> cs ! i \<inter> cs ! j = {}) \<and> (\<forall> c \<in> set cs. c \<noteq> {}) \<and> (\<Union> (set cs) = {0..<n})" lemma cells_ok: shows "cells_ok (length \<pi>) (cells \<pi>)" unfolding cells_ok_def proof safe fix i j x assume "i < List.length (cells \<pi>)" "j < List.length (cells \<pi>)" "i \<noteq> j" "x \<in> (cells \<pi>) ! i" "x \<in> (cells \<pi>) ! j" then show "x \<in> {}" using cells_disjunct by auto next assume "{} \<in> set (cells \<pi>)" then show False using cells_non_empty by blast next fix v Cell assume "v \<in> Cell" "Cell \<in> set (cells \<pi>)" then show "v \<in> {0..<length \<pi>}" unfolding cells_def all_colors cell_def by auto next fix v assume "v \<in> {0..<length \<pi>}" then have "v \<in> cell \<pi> (color_fun \<pi> v)" unfolding cell_def by simp then show "v \<in> \<Union> (set (cells \<pi>))" using `v \<in> {0..<length \<pi>}` by (simp add: cells_def cell_def color_fun_in_colors) qed lemma cells_ok_finite [simp]: fixes n :: nat assumes "cells_ok n cs" "x \<in> set cs" shows "finite x" using assms unfolding cells_ok_def by (metis List.finite_set Union_upper finite_subset set_upt) lemma distinct_cells: shows "distinct (cells \<pi>)" using cells_ok[of \<pi>] unfolding cells_ok_def by (metis distinct_conv_nth in_set_conv_nth le_iff_inf order.refl) text\<open>------------------------------------------------------\<close> subsection \<open>Cells to coloring\<close> text\<open>------------------------------------------------------\<close> text\<open>determine coloring fun or the coloring given by its cells\<close> text\<open>function given by a set of ordered pairs\<close> definition tabulate :: "('a \<times> 'b) set \<Rightarrow> 'a \<Rightarrow> 'b" where "tabulate A x = (THE y. (x, y) \<in> A)" lemma tabulate: assumes "\<exists>! y. (x, y) \<in> A" "(x, y) \<in> A" shows "tabulate A x = y" using assms by (metis tabulate_def the_equality) lemma tabulate_codomain: assumes "\<exists>! y. (x, y) \<in> A" shows "(x, tabulate A x) \<in> A" using assms by (metis tabulate) lemma tabulate_value: assumes "y = tabulate A x" "\<exists>! y. (x, y) \<in> A" shows "(x, y) \<in> A" using assms by (metis tabulate) abbreviation cells_to_color_fun_pairs :: "nat set list \<Rightarrow> (nat \<times> color) set" where "cells_to_color_fun_pairs cs \<equiv> (\<Union> (set (map2 (\<lambda>cl c. (\<lambda>v. (v, c)) ` cl) cs [0..<List.length cs])))" definition cells_to_color_fun :: "nat set list \<Rightarrow> nat \<Rightarrow> color" where "cells_to_color_fun cs = tabulate (cells_to_color_fun_pairs cs)" lemma ex1_cells_to_color_fun_pairs: assumes "cells_ok n cs" shows "\<forall> v < n. \<exists>! c. (v, c) \<in> cells_to_color_fun_pairs cs" proof (rule allI, rule impI) fix v assume "v < n" then obtain c where "c < List.length cs" "v \<in> cs ! c" using assms unfolding cells_ok_def by (metis Union_iff atLeastLessThan_iff in_set_conv_nth zero_le) then have *: "(cs ! c, c) \<in> set (zip cs [0..<List.length cs])" "(v, c) \<in> (\<lambda>v. (v, c)) ` (cs ! c)" by (auto simp add: set_zip) let ?A = "cells_to_color_fun_pairs cs" show "\<exists>! c. (v, c) \<in> ?A" proof show "(v, c) \<in> ?A" using * by auto next fix c' assume "(v, c') \<in> ?A" then have "c' < List.length cs" "v \<in> cs ! c'" by (auto simp add: set_zip) then show "c' = c" using * `c < List.length cs` assms unfolding cells_ok_def by auto qed qed lemma cells_to_color_fun: assumes "cells_ok n cs" "c < List.length cs" "v \<in> cs ! c" shows "cells_to_color_fun cs v = c" unfolding cells_to_color_fun_def proof (rule tabulate) let ?A = "cells_to_color_fun_pairs cs" have "(cs ! c, c) \<in> set (zip cs [0..<List.length cs])" by (metis add_cancel_right_left assms(2) in_set_zip length_map map_nth nth_upt prod.sel(1) prod.sel(2)) then show "(v, c) \<in> ?A" using `v \<in> cs ! c` by auto have "v < n" using `cells_ok n cs` `c < List.length cs` `v \<in> cs ! c` unfolding cells_ok_def by auto then show "\<exists>!c. (v, c) \<in> ?A" using ex1_cells_to_color_fun_pairs[OF assms(1), rule_format, of v] by simp qed lemma cells_to_color_fun': assumes "cells_ok n cs" "c < List.length cs" "v < n" "cells_to_color_fun cs v = c" shows "v \<in> cs ! c" proof- have "(v, c) \<in> cells_to_color_fun_pairs cs" using assms using tabulate_value[of c "cells_to_color_fun_pairs cs" v] ex1_cells_to_color_fun_pairs unfolding cells_to_color_fun_def by presburger then show ?thesis by (auto simp add: set_zip) qed lemma cells_to_color_fun_image: assumes "cells_ok n cs" shows "cells_to_color_fun cs ` {0..<n} = {0..<List.length cs}" proof safe fix v assume "v \<in> {0..<n}" then obtain c where "c < List.length cs" "cells_to_color_fun cs v = c" using assms cells_to_color_fun unfolding cells_ok_def by (smt (verit, ccfv_SIG) Union_iff in_set_conv_nth) then show "cells_to_color_fun cs v \<in> {0..<List.length cs}" by simp next fix c assume "c \<in> {0..<List.length cs}" then obtain v where "v \<in> {0..<n}" "v \<in> cs ! c" using assms unfolding cells_ok_def by (metis Union_iff atLeastLessThan_iff equals0I nth_mem) then show "c \<in> cells_to_color_fun cs ` {0..<n}" using \<open>c \<in> {0..<List.length cs}\<close> assms cells_to_color_fun by fastforce qed definition cells_to_coloring where "cells_to_coloring n cs = color_fun_to_coloring n (cells_to_color_fun cs)" lemma color_list_cells_to_coloring [simp]: assumes "cells_ok n cs" shows "color_list (cells_to_coloring n cs) = map (cells_to_color_fun cs) [0..<n]" unfolding cells_to_coloring_def color_fun_to_coloring_def proof (rule coloring_inverse) show "map (cells_to_color_fun cs) [0..<n] \<in> {cs. \<exists>k. set cs = {0..<k}}" using assms cells_to_color_fun_image by auto qed lemma length_cells_to_coloring [simp]: assumes "cells_ok n cs" shows "length (cells_to_coloring n cs) = n" using assms by (simp add: length.rep_eq) lemma max_color_cells_to_coloring [simp]: assumes "cells_ok n cs" "cs \<noteq> []" shows "max_color (cells_to_coloring n cs) = List.length cs - 1" by (simp add: assms(1) assms(2) cells_to_color_fun_image max_color.rep_eq) lemma colors_cells_to_coloring [simp]: assumes "cells_ok n cs" shows "colors (cells_to_coloring n cs) = [0..<List.length cs]" using assms unfolding colors_def num_colors_def by (smt (verit, ccfv_threshold) MaxAtLeastLessThan One_nat_def Suc_pred add.commute cells_to_color_fun_image color_list_cells_to_coloring last_in_set length_pos_if_in_set list.set_map list.size(3) max_color.rep_eq plus_1_eq_Suc set_upt upt_0) lemma num_colors_cells_to_coloring [simp]: assumes "cells_ok n cs" shows "num_colors (cells_to_coloring n cs) = List.length cs" by (metis assms colors_cells_to_coloring colors_def length_upt minus_nat.diff_0) lemma cell_cells_to_coloring: assumes "cells_ok n cs" "c < List.length cs" shows "cell (cells_to_coloring n cs) c = cs ! c" proof safe fix v let ?cl = "cells_to_coloring n cs" assume "v \<in> cell ?cl c" then have "v < length ?cl" "color_fun ?cl v = c" unfolding cell_def by auto then show "v \<in> cs ! c" using assms(1) cells_to_color_fun'[OF assms, of v] by (simp add:color_fun.rep_eq) next fix v assume "v \<in> cs ! c" then have "v \<in> \<Union> (set cs)" using assms(2) nth_mem by auto then have "v < n" using assms unfolding cells_ok_def by simp then show "v \<in> cell (cells_to_coloring n cs) c" using assms unfolding cell_def using \<open>v \<in> cs ! c\<close> cells_to_color_fun color_fun.rep_eq by force qed lemma cells_cells_to_coloring: assumes "cells_ok n cs" shows "cells (cells_to_coloring n cs) = cs" using assms unfolding cells_def by (metis cell_cells_to_coloring cells_def colors_cells_to_coloring length_cells length_map map_nth nth_cells nth_equalityI) text\<open>------------------------------------------------------\<close> subsection\<open>Finer colorings\<close> text\<open>------------------------------------------------------\<close> text \<open>Check if the color \<pi>' refines the coloring \<pi> - each cells of \<pi>' is a subset of a cell of \<pi>\<close> definition finer :: "coloring \<Rightarrow> coloring \<Rightarrow> bool" (infixl "\<preceq>" 100) where "finer \<pi>' \<pi> \<longleftrightarrow> length \<pi>' = length \<pi> \<and> (\<forall> v1 < length \<pi>. \<forall> v2 < length \<pi>. color_fun \<pi> v1 < color_fun \<pi> v2 \<longrightarrow> color_fun \<pi>' v1 < color_fun \<pi>' v2)" definition finer_strict :: "coloring \<Rightarrow> coloring \<Rightarrow> bool" (infixl "\<prec>" 100) where "finer_strict \<pi> \<pi>' \<longleftrightarrow> \<pi> \<preceq> \<pi>' \<and> \<pi> \<noteq> \<pi>'" lemma finer_length: assumes "finer \<pi>' \<pi>" shows "length \<pi>' = length \<pi>" using assms by (simp add: finer_def) lemma finer_refl: shows "finer \<pi> \<pi>" unfolding finer_def by auto lemma finer_trans: assumes "finer \<pi>1 \<pi>2" "finer \<pi>2 \<pi>3" shows "finer \<pi>1 \<pi>3" using assms using finer_def by auto lemma finer_same_color: assumes "\<pi>' \<preceq> \<pi>" "v1 < length \<pi>" "v2 < length \<pi>" "color_fun \<pi>' v1 = color_fun \<pi>' v2" shows "color_fun \<pi> v1 = color_fun \<pi> v2" using assms unfolding finer_def by (metis less_imp_not_eq less_linear) lemma finer_cell_subset: assumes "finer \<pi>' \<pi>" shows "\<forall> C' \<in> set (cells \<pi>'). \<exists> C \<in> set (cells \<pi>). C' \<subseteq> C" proof safe fix C' assume "C' \<in> set (cells \<pi>')" then obtain c' where "c' < num_colors \<pi>'" "C' = cell \<pi>' c'" by (metis index_of_in_set length_cells nth_cells) then obtain v where "v \<in> cell \<pi>' c'" using cell_non_empty by auto then have "v < length \<pi>'" "color_fun \<pi>' v = c'" unfolding cell_def by auto have "length \<pi>' = length \<pi>" using assms finer_length by simp let ?C = "cell \<pi> (color_fun \<pi> v)" have "color_fun \<pi> v \<in> set (colors \<pi>)" using `v < length \<pi>'` `length \<pi>' = length \<pi>` using color_fun_in_colors by simp then have "?C \<in> set (cells \<pi>)" unfolding cells_def by simp moreover have "C' \<subseteq> ?C" proof fix v' assume "v' \<in> C'" then have "v' < length \<pi>'" "color_fun \<pi>' v' = color_fun \<pi>' v" using \<open>C' \<in> set (cells \<pi>')\<close> \<open>C' = cell \<pi>' c'\<close> \<open>v \<in> cell \<pi>' c'\<close> \<open>v' \<in> C'\<close> by (auto simp add: cell_def) then have "color_fun \<pi> v' = color_fun \<pi> v" using \<open>v < length \<pi>'\<close> \<open>finer \<pi>' \<pi>\<close> finer_same_color by (metis finer_def) then show "v' \<in> ?C" using \<open>v' < length \<pi>'\<close> \<open>length \<pi>' = length \<pi>\<close> unfolding cell_def by simp qed ultimately show "\<exists> C \<in> set (cells \<pi>). C' \<subseteq> C" by blast qed lemma finer_cell_subset1: assumes "finer \<pi>' \<pi>" shows "\<forall> C' \<in> set (cells \<pi>'). \<exists>! C \<in> set (cells \<pi>). C' \<subseteq> C" proof fix C' assume "C' \<in> set (cells \<pi>')" { fix C1 C2 assume "C1 \<in> set (cells \<pi>)" "C2 \<in> set (cells \<pi>)" "C' \<subseteq> C1" "C' \<subseteq> C2" then have "C1 = C2" by (smt (verit, best) Int_empty_right Int_left_commute \<open>C' \<in> set (cells \<pi>')\<close> cell_non_empty cells_disjunct index_of_in_set inf.absorb_iff2 le_iff_inf length_cells nth_cells) } then show "\<exists>! C \<in> set (cells \<pi>). C' \<subseteq> C" using finer_cell_subset[OF assms] by (meson \<open>C' \<in> set (cells \<pi>')\<close>) qed lemma finer_cell_subset': assumes "finer \<pi>' \<pi>" shows "\<forall> C \<in> set (cells \<pi>). \<exists> Cs \<subseteq> set (cells \<pi>'). Cs \<noteq> {} \<and> C = \<Union> Cs" proof safe fix C assume "C \<in> set (cells \<pi>)" then obtain c where "c < num_colors \<pi>" "C = cell \<pi> c" by (metis index_of_in_set length_cells nth_cells) let ?Cs = "(\<lambda> v. cell \<pi>' (color_fun \<pi>' v)) ` C" have "?Cs \<subseteq> set (cells \<pi>')" proof safe fix v assume "v \<in> C" then show "cell \<pi>' (color_fun \<pi>' v) \<in> set (cells \<pi>')" unfolding cells_def using \<open>C = cell \<pi> c\<close> assms cell_def color_fun_in_colors finer_length by auto qed moreover have "?Cs \<noteq> {}" using \<open>C \<in> set (cells \<pi>)\<close> cells_non_empty by blast moreover have "C = \<Union> ?Cs" proof safe fix v assume "v \<in> C" have "v \<in> cell \<pi>' (color_fun \<pi>' v)" using finer_length[OF assms] `v \<in> C` `C = cell \<pi> c` unfolding cell_def by auto then show "v \<in> \<Union> ?Cs" using `v \<in> C` by auto next fix v v' assume "v \<in> C" "v' \<in> cell \<pi>' (color_fun \<pi>' v)" then show "v' \<in> C" using finer_same_color[OF assms, of v v'] `C = cell \<pi> c` `c < num_colors \<pi>` finer_length[OF assms] unfolding cell_def by auto qed ultimately show "\<exists> Cs \<subseteq> set (cells \<pi>'). Cs \<noteq> {} \<and> C = \<Union> Cs" by blast qed lemma cell_subset_finer: assumes "length \<pi>' = length \<pi>" "\<forall> C' \<in> set (cells \<pi>'). \<exists> C \<in> set (cells \<pi>). C' \<subseteq> C" "\<forall> p1 p2 c1 c2. c1 < num_colors \<pi>' \<and> p1 < num_colors \<pi> \<and> c2 < num_colors \<pi>' \<and> p2 < num_colors \<pi> \<and> cell \<pi>' c1 \<subseteq> cell \<pi> p1 \<and> cell \<pi>' c2 \<subseteq> cell \<pi> p2 \<and> c1 \<le> c2 \<longrightarrow> p1 \<le> p2" shows "finer \<pi>' \<pi>" unfolding finer_def proof safe show "length \<pi>' = length \<pi>" by fact next fix v1 v2 assume "v1 < length \<pi>" "v2 < length \<pi>" "color_fun \<pi> v1 < color_fun \<pi> v2" show "color_fun \<pi>' v1 < color_fun \<pi>' v2" proof- let ?p1 = "color_fun \<pi> v1" let ?p2 = "color_fun \<pi> v2" let ?c1 = "color_fun \<pi>' v1" let ?c2 = "color_fun \<pi>' v2" let ?C1' = "cell \<pi>' ?c1" let ?C2' = "cell \<pi>' ?c2" have "?C1' \<in> set (cells \<pi>')" by (simp add: \<open>v1 < length \<pi>\<close> assms(1) cells_def color_fun_in_colors) then obtain C1 where "?C1' \<subseteq> C1" "C1 \<in> set (cells \<pi>)" using assms(2) by fastforce have "?C2' \<in> set (cells \<pi>')" by (simp add: \<open>v2 < length \<pi>\<close> assms(1) cells_def color_fun_in_colors) then obtain C2 where "?C2' \<subseteq> C2" "C2 \<in> set (cells \<pi>)" using assms(2) by fastforce have "v1 \<in> C1" using \<open>cell \<pi>' (color_fun \<pi>' v1) \<subseteq> C1\<close> \<open>v1 < length \<pi>\<close> assms(1) cell_def by auto then have "C1 = cell \<pi> ?p1" using `C1 \<in> set (cells \<pi>)` unfolding cells_def cell_def by auto moreover have "v2 \<in> C2" using \<open>cell \<pi>' (color_fun \<pi>' v2) \<subseteq> C2\<close> \<open>v2 < length \<pi>\<close> assms(1) cell_def by auto then have "C2 = cell \<pi> ?p2" using `C2 \<in> set (cells \<pi>)` unfolding cells_def cell_def by auto moreover have "?c1 < num_colors \<pi>'" using \<open>v1 < length \<pi>\<close> assms(1) by (metis atLeast0LessThan atLeastLessThan_upt color_fun_in_colors colors_def lessThan_iff) moreover have "?c2 < num_colors \<pi>'" using \<open>v2 < length \<pi>\<close> assms(1) by (metis atLeast0LessThan atLeastLessThan_upt color_fun_in_colors colors_def lessThan_iff) moreover have "?p1 < num_colors \<pi>" "?p2 < num_colors \<pi>" using \<open>v1 < length \<pi>\<close> \<open>v2 < Coloring.length \<pi>\<close> color_fun_in_colors colors_def by auto ultimately show "?c1 < ?c2" using `?C1' \<subseteq> C1` `?C2' \<subseteq> C2` using `color_fun \<pi> v1 < color_fun \<pi> v2` using assms(3) by (meson leD linorder_le_less_linear) qed qed lemma finer_color_fun_non_decreasing: assumes "\<pi>' \<preceq> \<pi>" "v < length \<pi>" shows "color_fun \<pi>' v \<ge> color_fun \<pi> v" using assms proof (induction "color_fun \<pi> v" arbitrary: v rule: nat_less_induct) case 1 show ?case proof (cases "color_fun \<pi> v = 0") case True then show ?thesis by simp next case False then have "color_fun \<pi> v - 1 \<in> set (colors \<pi>)" using "1.prems"(2) color_fun_in_colors colors_def less_imp_diff_less by auto then obtain v' where "v' < length \<pi>" "color_fun \<pi> v' = color_fun \<pi> v - 1" using ex_color_color_fun[of "color_fun \<pi> v - 1" \<pi>] False by blast then have "color_fun \<pi>' v' \<ge> color_fun \<pi> v'" using 1 False by (metis bot_nat_0.not_eq_extremum diff_less zero_less_one) moreover have "color_fun \<pi>' v' < color_fun \<pi>' v" using `color_fun \<pi> v' = color_fun \<pi> v - 1` False using assms `v < length \<pi>` `v' < length \<pi>` unfolding finer_def by simp ultimately show ?thesis using `color_fun \<pi> v' = color_fun \<pi> v - 1` False by linarith qed qed lemma finer_singleton: assumes "{v} \<in> set (cells \<pi>1)" "v < length \<pi>1" "finer \<pi>2 \<pi>1" shows "{v} \<in> set (cells \<pi>2)" proof- have "length \<pi>1 = length \<pi>2" using `finer \<pi>2 \<pi>1` unfolding finer_def by simp obtain c where c: "c \<in> set (colors \<pi>1)" "color_fun \<pi>1 v = c" "cell \<pi>1 c = {v}" using assms by (smt (verit) cell_def color_fun_in_colors in_set_conv_nth length_cells mem_Collect_eq nth_cells singletonI) let ?c = "color_fun \<pi>2 v" have "cell \<pi>2 ?c = {v}" proof- have "\<forall> v' < length \<pi>1. v' \<noteq> v \<longrightarrow> color_fun \<pi>2 v' \<noteq> ?c" proof safe fix v' assume "v' < length \<pi>1" "color_fun \<pi>2 v' = color_fun \<pi>2 v" "v' \<noteq> v" then have "color_fun \<pi>1 v' = color_fun \<pi>1 v" using assms(2-3) finer_same_color by blast then have "v' \<in> cell \<pi>1 c" by (simp add: \<open>v' < length \<pi>1\<close> c(2) cell_def) then show False using assms c \<open>v' \<noteq> v\<close> by blast qed then show ?thesis using c(3) `length \<pi>1 = length \<pi>2` unfolding cell_def by auto qed then show ?thesis using `v < length \<pi>1` `length \<pi>1 = length \<pi>2` color_fun_in_colors unfolding cells_def by auto qed lemma cells_inj: assumes "length \<pi> = length \<pi>'" "cells \<pi> = cells \<pi>'" shows "\<pi> = \<pi>'" proof (rule coloring_eqI) show "length \<pi> = length \<pi>'" by fact next show "\<forall>v<Coloring.length \<pi>. color_fun \<pi> v = color_fun \<pi>' v" proof safe fix v assume "v < length \<pi>" have "cell \<pi> (color_fun \<pi> v) = cell \<pi>' (color_fun \<pi> v)" using assms unfolding cells_def by (metis \<open>v < Coloring.length \<pi>\<close> assms(2) color_fun_in_colors colors_def length_cells map_eq_conv) then show "color_fun \<pi> v = color_fun \<pi>' v" using assms(1) cells_ok[of \<pi>'] by (metis (mono_tags, lifting) \<open>v < Coloring.length \<pi>\<close> cell_def mem_Collect_eq) qed qed lemma finer_cells_order: assumes "\<pi>' \<preceq> \<pi>" "c < num_colors \<pi>" "c' < num_colors \<pi>'" "cell \<pi>' c' = cell \<pi> c" shows "c \<le> c'" proof- obtain v where "v < length \<pi>" "color_fun \<pi> v = c" using \<open>c < num_colors \<pi>\<close> ex_color ex_color_color_fun by blast then have "color_fun \<pi>' v = c'" using \<open>cell \<pi>' c' = cell \<pi> c\<close> unfolding cell_def by auto show ?thesis using finer_color_fun_non_decreasing[OF assms(1)] using \<open>color_fun \<pi> v = c\<close> \<open>color_fun \<pi>' v = c'\<close> \<open>v < Coloring.length \<pi>\<close> by blast qed lemma finer_cell_set_eq: assumes "\<pi>' \<preceq> \<pi>" "set (cells \<pi>) = set (cells \<pi>')" shows "cells \<pi> = cells \<pi>'" proof- have "num_colors \<pi> = num_colors \<pi>'" by (metis assms(2) distinct_card distinct_cells length_cells) show ?thesis proof (rule ccontr) assume "\<not> ?thesis" then obtain c where "c < num_colors \<pi>" "cell \<pi> c \<noteq> cell \<pi>' c" by (metis \<open>num_colors \<pi> = num_colors \<pi>'\<close> length_cells nth_cells nth_equalityI) then obtain c' where "c' < num_colors \<pi>" "cell \<pi> c = cell \<pi>' c'" by (metis \<open>num_colors \<pi> = num_colors \<pi>'\<close> assms(2) in_set_conv_nth length_cells nth_cells) have "c < c'" by (metis \<open>c < num_colors \<pi>\<close> \<open>c' < num_colors \<pi>\<close> \<open>cell \<pi> c = cell \<pi>' c'\<close> \<open>cell \<pi> c \<noteq> cell \<pi>' c\<close> \<open>num_colors \<pi> = num_colors \<pi>'\<close> assms(1) finer_cells_order order_le_neq_trans) have *: "\<forall> cc. c < cc \<and> cc < num_colors \<pi> \<longrightarrow> (\<exists> cc'. c' < cc' \<and> cc' < num_colors \<pi>' \<and> cell \<pi> cc = cell \<pi>' cc')" proof safe fix cc assume "c < cc" "cc < num_colors \<pi>" then obtain cc' where "cc' < num_colors \<pi>'" "cell \<pi> cc = cell \<pi>' cc'" by (metis assms(2) in_set_conv_nth length_cells nth_cells) obtain v where "v < length \<pi>" "color_fun \<pi> v = c" "color_fun \<pi>' v = c'" by (metis (mono_tags, lifting) \<open>c' < num_colors \<pi>\<close> \<open>cell \<pi> c = cell \<pi>' c'\<close> \<open>num_colors \<pi> = num_colors \<pi>'\<close> atLeast0LessThan cell_def colors_def ex_color_color_fun lessThan_iff mem_Collect_eq set_upt) obtain v' where "v' < length \<pi>" "color_fun \<pi> v' = cc" "color_fun \<pi>' v' = cc'" by (smt (verit, ccfv_threshold) \<open>cc' < num_colors \<pi>'\<close> \<open>cell \<pi> cc = cell \<pi>' cc'\<close> atLeast0LessThan cell_def colors_def ex_color_color_fun lessThan_iff mem_Collect_eq set_upt) have "c' < cc'" using \<open>\<pi>' \<preceq> \<pi>\<close> \<open>c < cc\<close> unfolding finer_def using \<open>color_fun \<pi> v = c\<close> \<open>color_fun \<pi> v' = cc\<close> \<open>color_fun \<pi>' v = c'\<close> \<open>color_fun \<pi>' v' = cc'\<close> \<open>v < Coloring.length \<pi>\<close> \<open>v' < Coloring.length \<pi>\<close> by blast then show "\<exists>cc'>c'. cc' < num_colors \<pi>' \<and> cell \<pi> cc = cell \<pi>' cc'" using \<open>cc' < num_colors \<pi>'\<close> \<open>cell \<pi> cc = cell \<pi>' cc'\<close> by blast qed let ?f = "\<lambda> cc. SOME cc'. c' < cc' \<and> cc' < num_colors \<pi>' \<and> cell \<pi> cc = cell \<pi>' cc'" have **: "\<forall> cc. c < cc \<and> cc < num_colors \<pi> \<longrightarrow> c' < ?f cc \<and> ?f cc < num_colors \<pi>' \<and> cell \<pi> cc = cell \<pi>' (?f cc)" using * by (smt tfl_some) have "card {c+1..<num_colors \<pi>} \<le> card {c'+1..<num_colors \<pi>'}" proof (rule card_inj_on_le) show "inj_on ?f {c + 1..<num_colors \<pi>}" unfolding inj_on_def proof safe fix x y assume "x \<in> {c + 1..<num_colors \<pi>}" "y \<in> {c + 1..<num_colors \<pi>}" "?f x = ?f y" then have "c < x" "x < num_colors \<pi>" "c < y" "y < num_colors \<pi>" by auto then have "cell \<pi> x = cell \<pi>' (?f x)" "cell \<pi> y = cell \<pi>' (?f y)" using ** by blast+ then have "cell \<pi> x = cell \<pi> y" using `?f x = ?f y` by simp then show "x = y" by (metis \<open>x < num_colors \<pi>\<close> \<open>y < num_colors \<pi>\<close> distinct_cells length_cells nth_cells nth_eq_iff_index_eq) qed next show "?f ` {c + 1..<num_colors \<pi>} \<subseteq> {c' + 1..<num_colors \<pi>'}" proof safe fix cc assume "cc \<in> {c + 1..<num_colors \<pi>}" then have "cc > c" "cc < num_colors \<pi>" by auto then show "?f cc \<in> {c' + 1..<num_colors \<pi>'}" using ** by fastforce qed next show "finite {c' + 1..<num_colors \<pi>'}" by simp qed then show False using `c < c'` `c < num_colors \<pi>` `c' < num_colors \<pi>` `num_colors \<pi> = num_colors \<pi>'` using card_atLeastLessThan[of "c+1" "num_colors \<pi>"] using card_atLeastLessThan[of "c'+1" "num_colors \<pi>'"] by auto qed qed lemma num_colors_finer_strict: assumes "\<pi>' \<prec> \<pi>" shows "num_colors \<pi>' > num_colors \<pi>" proof- have "cells \<pi> \<noteq> cells \<pi>'" using assms cells_inj[of \<pi> \<pi>'] using finer_length finer_strict_def by fastforce let ?f = "\<lambda> C. SOME C'. C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C" have *: "\<forall> C \<in> set (cells \<pi>). ?f C \<in> set (cells \<pi>') \<and> ?f C \<subseteq> C" proof fix C assume "C \<in> set (cells \<pi>)" then obtain Cs where "C = \<Union> Cs" "Cs\<subseteq>set (cells \<pi>')" "Cs \<noteq> {}" using finer_cell_subset'[of \<pi>' \<pi>] assms unfolding finer_strict_def by meson then have "\<exists> C' \<in> set (cells \<pi>'). C' \<subseteq> C" by auto then show "?f C \<in> set (cells \<pi>') \<and> ?f C \<subseteq> C" by (metis (no_types, lifting) verit_sko_ex') qed have "inj_on ?f (set (cells \<pi>))" unfolding inj_on_def proof (rule ballI, rule ballI, rule impI) fix C1 C2 assume **: "C1 \<in> set (cells \<pi>)" "C2 \<in> set (cells \<pi>)" "?f C1 = ?f C2" let ?C' = "(SOME C'. C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C1)" have "?C' \<in> set (cells \<pi>')" "?C' \<subseteq> C1" "?C' \<subseteq> C2" using * ** by auto then show "C1 = C2" using cells_ok[of \<pi>] cells_ok[of \<pi>'] unfolding cells_ok_def by (metis (no_types, lifting) "**"(1) "**"(2) Int_subset_iff index_of_in_set subset_empty) qed have "?f ` set (cells \<pi>) \<subset> set (cells \<pi>')" proof show "?f ` set (cells \<pi>) \<subseteq> set (cells \<pi>')" proof safe fix C assume "C \<in> set (cells \<pi>)" then obtain Cs where "C = \<Union> Cs" "Cs\<subseteq>set (cells \<pi>')" "Cs \<noteq> {}" using finer_cell_subset'[of \<pi>' \<pi>] assms unfolding finer_strict_def by meson then have "\<exists> C' \<in> set (cells \<pi>'). C' \<subseteq> C" by auto then show "?f C \<in> set (cells \<pi>')" by (smt (verit, ccfv_SIG) tfl_some) qed next show "?f ` set (cells \<pi>) \<noteq> set (cells \<pi>')" proof (rule ccontr) assume contr: "\<not> ?thesis" then have "card (set (cells \<pi>)) = card (set (cells \<pi>'))" using \<open>inj_on ?f (set (cells \<pi>))\<close> card_image by fastforce have ex1: "\<forall> C \<in> set (cells \<pi>). \<exists>! C' \<in> set (cells \<pi>'). C' \<subseteq> C" proof (rule, rule) fix C assume "C \<in> set (cells \<pi>)" then show "?f C \<in> set (cells \<pi>') \<and> ?f C \<subseteq> C" using "*" by blast next fix C C' assume "C \<in> set (cells \<pi>)" "C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C" let ?g = "\<lambda> C'. THE C. C \<in> set (cells \<pi>) \<and> C \<supseteq> C'" have gex1: "\<forall> C' \<in> set (cells \<pi>'). \<exists>! C \<in> set (cells \<pi>). C \<supseteq> C'" by (meson assms finer_cell_subset1 finer_strict_def) have "inj_on ?g (set (cells \<pi>'))" proof- have "?g ` (set (cells \<pi>')) = set (cells \<pi>)" proof safe fix C' assume "C' \<in> set (cells \<pi>')" then show "?g C' \<in> set (cells \<pi>)" using gex1 the_eq_trivial by (smt (verit, ccfv_threshold) the_equality) next fix C assume "C \<in> set (cells \<pi>)" then have "?g (?f C) = C" by (smt (verit, ccfv_threshold) "*" gex1 someI_ex the_equality) then show "C \<in> ?g ` set (cells \<pi>')" using \<open>C \<in> set (cells \<pi>)\<close> contr by blast qed then show ?thesis using `card (set (cells \<pi>)) = card (set (cells \<pi>'))` by (simp add: eq_card_imp_inj_on) qed moreover have "?g C' = ?g (?f C)" proof- have "?g (?f C) = C" by (smt (verit, del_insts) \<open>C \<in> set (cells \<pi>)\<close> \<open>C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C\<close> gex1 someI_ex the_equality) moreover have "?g C' = C" by (simp add: \<open>C \<in> set (cells \<pi>)\<close> \<open>C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C\<close> gex1 the1_equality) ultimately show ?thesis by simp qed ultimately show "C' = ?f C" using `C \<in> set (cells \<pi>)` * `C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C` unfolding inj_on_def by blast qed have "\<forall> C \<in> set (cells \<pi>). ?f C = C" proof fix C assume "C \<in> set (cells \<pi>)" then obtain Cs where "Cs \<subseteq> set (cells \<pi>')" "\<Union>Cs = C" by (metis assms finer_cell_subset' finer_strict_def) then have "\<forall> C' \<in> Cs. C' \<in> set (cells \<pi>') \<and> C' \<subseteq> C" by auto then have "\<exists>! C'. C' \<in> Cs" using `C \<in> set (cells \<pi>)` ex1 by (metis Sup_bot_conv(1) \<open>\<Union> Cs = C\<close> cells_non_empty) then have "Cs = {C}" by (metis \<open>\<Union> Cs = C\<close> cSup_singleton empty_iff is_singletonI' is_singleton_the_elem) then have "C \<in> set (cells \<pi>')" using \<open>Cs \<subseteq> set (cells \<pi>')\<close> by auto moreover have "?f C \<in> set (cells \<pi>')" "?f C \<subseteq> C" using * \<open>C \<in> set (cells \<pi>)\<close> by auto ultimately show "?f C = C" using ex1 using \<open>C \<in> set (cells \<pi>)\<close> by blast qed then have "set (cells \<pi>) = set (cells \<pi>')" using contr by force then show False using `cells \<pi> \<noteq> cells \<pi>'` using assms finer_cell_set_eq finer_strict_def by blast qed qed then have "card (?f ` set (cells \<pi>)) < card (set (cells \<pi>'))" by (meson List.finite_set psubset_card_mono) moreover have "card (?f ` set (cells \<pi>)) = card (set (cells \<pi>))" proof (rule card_image) show "inj_on ?f (set (cells \<pi>))" by fact qed ultimately have "card (set (cells \<pi>)) < card (set (cells \<pi>'))" by simp then have "List.length (cells \<pi>') > List.length (cells \<pi>)" using distinct_card[of "cells \<pi>"] distinct_card[of "cells \<pi>'"] by (simp add: distinct_cells) then show ?thesis by auto qed text \<open>A coloring is discrete if each vertex is colored by a different color {0..<n}\<close> definition discrete :: "coloring \<Rightarrow> bool" where "discrete \<pi> \<longleftrightarrow> set (colors \<pi>) = {0..<length \<pi>}" lemma discrete_coloring_is_permutation [simp]: assumes "discrete \<pi>" shows "is_perm_fun (length \<pi>) (color_fun \<pi>)" using assms finite_surj_inj[of "{0..<length \<pi>}" "color_fun \<pi>"] all_colors unfolding discrete_def is_perm_fun_def unfolding bij_betw_def by auto lemma discrete_singleton: assumes "discrete \<pi>" "v < length \<pi>" shows "cell \<pi> (color_fun \<pi> v) = {v}" proof- have f: "inj_on (color_fun \<pi>) {0..<length \<pi>}" "color_fun \<pi> ` {0..<length \<pi>} = {0..<length \<pi>}" using \<open>discrete \<pi>\<close> by (meson bij_betw_def discrete_coloring_is_permutation is_perm_fun_def)+ then show ?thesis using \<open>v < length \<pi>\<close> unfolding cell_def inj_on_def by auto qed lemma discrete_cells_card1: assumes "discrete \<pi>" "C \<in> set (cells \<pi>)" shows "card C = 1" proof- obtain c where "c \<in> set (colors \<pi>)" "C = cell \<pi> c" by (metis assms(2) ex_color index_of_in_set length_cells nth_cells) then obtain v where "C = {v}" by (metis assms(1) discrete_singleton ex_color_color_fun) thus ?thesis by simp qed lemma non_discrete_cells_card_gt1: assumes "\<not> discrete \<pi>" shows "\<exists> c \<in> set (colors \<pi>). card (cell \<pi> c) > 1" proof (rule ccontr) assume "\<not> ?thesis" moreover have "\<forall> c \<in> set (colors \<pi>). card (cell \<pi> c) \<ge> 1" by (metis atLeast0LessThan atLeastLessThan_upt card_0_eq cell_finite cell_non_empty colors_def lessThan_iff less_one linorder_le_less_linear) ultimately have *: "\<forall> c \<in> set (colors \<pi>). card (cell \<pi> c) = 1" by force have "card ({0..<length \<pi>}) = card (set (colors \<pi>))" proof (rule bij_betw_same_card) show "bij_betw (color_fun \<pi>) {0..<length \<pi>} (set (colors \<pi>))" unfolding bij_betw_def proof show "inj_on (color_fun \<pi>) {0..<Coloring.length \<pi>}" unfolding inj_on_def proof safe fix v1 v2 assume "v1 \<in> {0..<length \<pi>}" "v2 \<in> {0..<length \<pi>}" "color_fun \<pi> v1 = color_fun \<pi> v2" then have "v1 \<in> cell \<pi> (color_fun \<pi> v1)" "v2 \<in> cell \<pi> (color_fun \<pi> v1)" unfolding cell_def by auto moreover have "card (cell \<pi> (color_fun \<pi> v1)) = 1" using * \<open>v1 \<in> {0..<length \<pi>}\<close> color_fun_in_colors by force ultimately show "v1 = v2" using card_le_Suc0_iff_eq[of "cell \<pi> (color_fun \<pi> v1)"] by auto qed next show "color_fun \<pi> ` {0..<Coloring.length \<pi>} = set (colors \<pi>)" proof safe fix v assume "v \<in> {0..<length \<pi>}" then show "color_fun \<pi> v \<in> set (colors \<pi>)" using color_fun_in_colors by force next fix c assume "c \<in> set (colors \<pi>)" then obtain v where "v \<in> cell \<pi> c" using * by fastforce then show "c \<in> color_fun \<pi> ` {0..<Coloring.length \<pi>}" unfolding cell_def by auto qed qed qed then have "length \<pi> = num_colors \<pi>" by (simp add: colors_def) then have "discrete \<pi>" unfolding discrete_def colors_def by auto then show False using assms by auto qed definition discrete_coloring_perm :: "coloring \<Rightarrow> perm" where "discrete_coloring_perm \<alpha> = make_perm (length \<alpha>) (color_fun \<alpha>)" lemma perm_dom_discrete_coloring_perm [simp]: assumes "discrete \<alpha>" shows "perm_dom (discrete_coloring_perm \<alpha>) = length \<alpha>" using assms unfolding discrete_coloring_perm_def by simp lemma perm_fun_discrete_coloring_perm [simp]: assumes "discrete \<alpha>" "v < length \<alpha>" shows "perm_fun (discrete_coloring_perm \<alpha>) v = color_fun \<alpha> v" using assms unfolding discrete_coloring_perm_def by simp text\<open>------------------------------------------------------\<close> subsection\<open>Permute coloring\<close> text\<open>------------------------------------------------------\<close> text\<open>The effect of vertices perm on colors\<close> definition perm_coloring :: "perm \<Rightarrow> coloring \<Rightarrow> coloring" where "perm_coloring p \<pi> = coloring (perm_reorder p (color_list \<pi>))" lemma length_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "length (perm_coloring p \<pi>) = length \<pi>" using assms by (smt (verit) color_list eq_onp_same_args length.abs_eq length.rep_eq length_perm_reorder mem_Collect_eq perm_coloring_def set_perm_reorder) lemma color_fun_perm_coloring: assumes "perm_dom p = length \<pi>" shows "color_fun (perm_coloring p \<pi>) = (!) (perm_reorder p (color_list \<pi>))" using assms by (smt (verit) color_fun.abs_eq color_list eq_onp_same_args length.rep_eq list.set_map map_nth mem_Collect_eq perm_coloring_def perm_dom_perm_inv perm_list_set perm_reorder set_upt) lemma color_fun_perm_coloring_app: assumes "perm_dom p = length \<pi>" assumes "v < length \<pi>" shows "color_fun (perm_coloring p \<pi>) v = ((color_fun \<pi>) \<circ> (perm_fun (perm_inv p))) v" using assms color_fun.rep_eq color_fun_perm_coloring length.rep_eq by auto lemma perm_coloring_perm_fun [simp]: assumes "perm_dom p = length \<pi>" "v < length \<pi>" shows "color_fun (perm_coloring p \<pi>) (perm_fun p v) = color_fun \<pi> v" by (metis assms(1) assms(2) color_fun_perm_coloring_app comp_apply perm_dom_perm_inv perm_fun_perm_inv2 perm_fun_perm_inv_range perm_inv_inv) lemma max_color_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "max_color (perm_coloring p \<pi>) = max_color \<pi>" using assms by (metis color_fun.rep_eq color_fun_perm_coloring length.rep_eq length_perm_coloring length_perm_reorder list.set_map map_nth max_color.rep_eq perm_dom_perm_inv perm_list_set perm_reorder set_upt) lemma num_colors_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "num_colors (perm_coloring p \<pi>) = num_colors \<pi>" using assms unfolding num_colors_def using length.rep_eq length_perm_coloring by fastforce lemma colors_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "colors (perm_coloring p \<pi>) = colors \<pi>" using assms num_colors_def num_colors_perm_coloring unfolding colors_def by simp lemma perm_coloring_perm_id [simp]: shows "perm_coloring (perm_id (length \<pi>)) \<pi> = \<pi>" by (simp add: color_list_inverse length.rep_eq perm_coloring_def) lemma perm_coloring_perm_comp: assumes "perm_dom p1 = length \<pi>" "perm_dom p2 = length \<pi>" shows "perm_coloring (perm_comp p1 p2) \<pi> = perm_coloring p1 (perm_coloring p2 \<pi>)" using assms unfolding perm_coloring_def by (smt (verit, del_insts) color_list coloring_inverse length.rep_eq mem_Collect_eq perm_reorder_comp set_perm_reorder) lemma perm_coloring_perm_inv_comp1 [simp]: assumes "perm_dom p = length \<pi>" shows "perm_coloring (perm_inv p) (perm_coloring p \<pi>) = \<pi>" using assms by (metis perm_coloring_perm_comp perm_coloring_perm_id perm_comp_perm_inv1 perm_dom_perm_inv) lemma perm_coloring_perm_inv_comp2 [simp]: assumes "perm_dom p = length \<pi>" shows "perm_coloring p (perm_coloring (perm_inv p) \<pi>) = \<pi>" using assms by (metis perm_coloring_perm_inv_comp1 perm_dom_perm_inv perm_inv_inv) lemma perm_coloring_inj: assumes "length \<pi> = perm_dom p" "length \<pi>' = perm_dom p" "perm_coloring p \<pi> = perm_coloring p \<pi>'" shows "\<pi> = \<pi>'" using assms by (metis perm_coloring_perm_inv_comp1) lemma cell_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "cell (perm_coloring p \<pi>) c = perm_fun_set p (cell \<pi> c)" (is "?lhs = ?rhs") proof safe fix x assume "x \<in> ?lhs" then show "x \<in> ?rhs" using assms color_fun_perm_coloring_app unfolding cell_def by (smt (verit) comp_apply image_iff length_perm_coloring mem_Collect_eq perm_fun_perm_inv1 perm_fun_perm_inv_range perm_fun_set_def) next fix x assume "x \<in> ?rhs" then show "x \<in> ?lhs" by (smt (verit, ccfv_SIG) assms cell_def image_iff length_perm_coloring mem_Collect_eq perm_coloring_perm_fun perm_comp_perm_inv2 perm_dom_perm_inv perm_fun_perm_inv_range perm_fun_set_def perm_inv_solve) qed lemma cells_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "cells (perm_coloring p \<pi>) = map (perm_fun_set p) (cells \<pi>)" using assms colors_perm_coloring unfolding cells_def by simp lemma discrete_perm_coloring [simp]: assumes "perm_dom p = length \<pi>" shows "discrete (perm_coloring p \<pi>) \<longleftrightarrow> discrete \<pi>" using assms unfolding discrete_def by auto lemma perm_coloring_finer: assumes "\<pi> \<preceq> \<pi>0" "perm_coloring \<sigma> \<pi> = \<pi>" "perm_dom \<sigma> = length \<pi>" "perm_dom \<sigma> = length \<pi>0" shows "perm_coloring \<sigma> \<pi>0 = \<pi>0" proof (rule coloring_eqI) show "\<forall>v<length (perm_coloring \<sigma> \<pi>0). Coloring.color_fun (perm_coloring \<sigma> \<pi>0) v = Coloring.color_fun \<pi>0 v" proof safe fix v assume "v < length (perm_coloring \<sigma> \<pi>0)" then have "Coloring.color_fun \<pi> (perm_fun \<sigma> v) = Coloring.color_fun \<pi> v" using assms by (metis length_perm_coloring perm_coloring_perm_fun) then show "Coloring.color_fun (perm_coloring \<sigma> \<pi>0) v = Coloring.color_fun \<pi>0 v" using assms \<open>v < Coloring.length (perm_coloring \<sigma> \<pi>0)\<close> by (smt (verit) color_fun_perm_coloring_app comp_def finer_same_color length_perm_coloring perm_fun_perm_inv_range) qed next show "Coloring.length (perm_coloring \<sigma> \<pi>0) = Coloring.length \<pi>0" using assms using length_perm_coloring by blast qed lemma color_fun_to_coloring_perm [simp]: assumes "perm_dom p = n" "\<exists> k. \<pi> ` {0..<n} = {0..<k}" shows "color_fun_to_coloring n (\<pi> \<circ> perm_fun (perm_inv p)) = perm_coloring p (color_fun_to_coloring n \<pi>)" (is "?lhs = ?rhs") proof (rule coloring_eqI) have *: "\<exists> k. (\<pi> \<circ> perm_fun (perm_inv p)) ` {0..<n} = {0..<k}" using assms by (metis image_comp list.set_map perm_dom_perm_inv perm_fun_list_def perm_inv_perm_list perm_list_set set_upt) then show "length ?lhs = length ?rhs" using assms by simp show "\<forall> v < length ?lhs. color_fun ?lhs v = color_fun ?rhs v" using assms * by (simp add: color_fun_perm_coloring_app perm_fun_perm_inv_range) qed lemma color_fun_to_coloring_perm': assumes "perm_dom p = n" "\<exists> k. \<pi> ` {0..<n} = {0..<k}" "\<forall> w < n. \<pi>' (perm_fun p w) = \<pi> w" shows "color_fun_to_coloring n \<pi>' = perm_coloring p (color_fun_to_coloring n \<pi>)" (is "?lhs = ?rhs") proof (rule coloring_eqI) obtain k where k: "\<pi> ` {0..<n} = {0..<k}" using assms by auto moreover have "\<forall> w < n. \<pi>' w = \<pi> (perm_fun (perm_inv p) w)" using assms by (metis perm_fun_perm_inv1 perm_fun_perm_inv_range) moreover have "\<forall> w < n. perm_fun (perm_inv p) w < n" using assms(1) by (simp add: perm_fun_perm_inv_range) ultimately have "\<forall> w < n. \<pi>' w < k" by auto moreover have "\<forall> c < k. \<exists> w < n. \<pi>' w = c" proof safe fix c assume "c < k" then obtain w where "w < n" "\<pi> w = c" using k by (metis (mono_tags, opaque_lifting) atLeastLessThan_iff image_iff le0) then have "\<pi>' (perm_fun p w) = c" using assms(3) by blast then show "\<exists>w<n. \<pi>' w = c" using `w < n` assms(1) by (metis perm_dom_perm_inv perm_fun_perm_inv_range perm_inv_inv) qed ultimately have *: "\<pi>' ` {0..<n} = {0..<k}" by auto then have *: "\<exists> k. \<pi>' ` {0..<n} = {0..<k}" by auto show "length ?lhs = length ?rhs" using assms * by auto show "\<forall> v < length ?lhs. color_fun ?lhs v = color_fun ?rhs v" using assms * \<open>\<forall>w<n. \<pi>' w = \<pi> (perm_fun (perm_inv p) w)\<close> by (simp add: color_fun_perm_coloring_app perm_fun_perm_inv_range) qed lemma tabulate_eq: assumes "(x1, y) \<in> f1" "(x2, y) \<in> f2" "\<exists>! y. (x1, y) \<in> f1" "\<exists>! y. (x2, y) \<in> f2" shows "tabulate f1 x1 = tabulate f2 x2" using assms by (metis tabulate_value) lemma cells_to_color_fun_perm_perm [simp]: assumes "cells_ok n cs" "perm_dom p = n" "w < n" shows "cells_to_color_fun (map (perm_fun_set p) cs) (perm_fun p w) = cells_to_color_fun cs w" unfolding cells_to_color_fun_def proof (rule tabulate_eq) let ?c = "THE c. (w, c) \<in> cells_to_color_fun_pairs cs" show "(w, ?c) \<in> cells_to_color_fun_pairs cs" using ex1_cells_to_color_fun_pairs[OF assms(1)] assms(3) by (smt (verit, ccfv_threshold) the_equality) show "\<exists>!y. (w, y) \<in> cells_to_color_fun_pairs cs" using ex1_cells_to_color_fun_pairs[OF assms(1)] assms(3) by simp have "cells_ok n (map (perm_fun_set p) cs)" (is "cells_ok n ?cs") unfolding cells_ok_def proof safe fix c assume "{} \<in> set ?cs" then show False using assms by (metis cells_cells_to_coloring cells_non_empty cells_perm_coloring length_cells_to_coloring) next fix v C assume "v \<in> C" "C \<in> set ?cs" then obtain C' where "v \<in> perm_fun_set p C'" "C' \<in> set cs" by auto then obtain v' where "v = perm_fun p v'" "v' \<in> \<Union> (set cs)" by (auto simp add: perm_fun_set_def) then show "v \<in> {0..<n}" using assms unfolding cells_ok_def by (metis atLeastLessThan_iff in_set_conv_nth perm_dom.rep_eq perm_list_nth perm_list_set) next fix v assume "v \<in> {0..<n}" then have "perm_fun (perm_inv p) v \<in> {0..<n}" using assms(2) by (simp add: atLeast0LessThan perm_fun_perm_inv_range) then obtain i where "i < List.length cs" "perm_fun (perm_inv p) v \<in> cs ! i" using `cells_ok n cs` unfolding cells_ok_def by (metis Union_iff index_of_in_set) then show "v \<in> \<Union> (set ?cs)" using assms(2) by (smt (verit, ccfv_SIG) UnionI \<open>v \<in> {0..<n}\<close> image_eqI in_set_conv_nth length_map nth_map nth_mem perm_comp_perm_inv2 perm_dom.rep_eq perm_dom_perm_inv perm_fun_perm_inv1 perm_fun_set_def perm_inv_solve perm_list_nth perm_list_set) next fix i j x assume *: "i < List.length ?cs" "j < List.length ?cs" "i \<noteq> j" "x \<in> map (perm_fun_set p) cs ! i" "x \<in> map (perm_fun_set p) cs ! j" then have "\<forall> x \<in> cs ! i. x < n" "\<forall> x \<in> cs ! j. x < n" using `cells_ok n cs` unfolding cells_ok_def by auto then have "perm_fun (perm_inv p) x \<in> cs ! i" "perm_fun (perm_inv p) x \<in> cs ! j" using assms(1) perm_fun_inj[OF assms(2)] * unfolding perm_fun_set_def by (smt (verit) assms(2) image_iff length_map nth_map perm_dom_perm_inv perm_fun_perm_inv1 perm_inv_inv)+ then show "x \<in> {}" using assms * unfolding cells_ok_def by auto qed have "perm_fun p w < n" using assms(2) assms(3) by (metis perm_comp_perm_inv2 perm_dom_perm_inv perm_fun_perm_inv_range perm_inv_solve) show "\<exists>!y. (perm_fun p w, y) \<in> cells_to_color_fun_pairs (map (perm_fun_set p) cs)" using \<open>cells_ok n (map (perm_fun_set p) cs)\<close> \<open>perm_fun p w < n\<close> ex1_cells_to_color_fun_pairs by presburger show "(perm_fun p w, ?c) \<in> cells_to_color_fun_pairs (map (perm_fun_set p) cs)" proof- have "?c < List.length cs" using `(w, ?c) \<in> cells_to_color_fun_pairs cs` by (auto simp add: set_zip) then have "w \<in> cs ! ?c" using assms(1) assms(3) \<open>(w, THE c. (w, c) \<in> cells_to_color_fun_pairs cs) \<in> cells_to_color_fun_pairs cs\<close> \<open>\<exists>!y. (w, y) \<in> cells_to_color_fun_pairs cs\<close> by (metis cells_to_color_fun' cells_to_color_fun_def tabulate_value) then have "perm_fun p w \<in> (map (perm_fun_set p) cs) ! ?c" using `?c < List.length cs` unfolding perm_fun_set_def by simp then show ?thesis using `?c < List.length cs` using \<open>\<exists>!y. (perm_fun p w, y) \<in> cells_to_color_fun_pairs (map (perm_fun_set p) cs)\<close> \<open>cells_ok n (map (perm_fun_set p) cs)\<close> by (metis cells_to_color_fun cells_to_color_fun_def length_map tabulate_value) qed qed lemma cells_to_coloring_perm: assumes "cells_ok n cs" "perm_dom p = n" shows "cells_to_coloring n (map (perm_fun_set p) cs) = perm_coloring p (cells_to_coloring n cs)" using assms unfolding cells_to_coloring_def by (subst color_fun_to_coloring_perm') (auto simp add: cells_to_color_fun_image) lemma finer_perm_coloring [simp]: assumes "\<pi> \<preceq> \<pi>'" "length \<pi> = length \<pi>'" "length \<pi> = perm_dom p" shows "perm_coloring p \<pi> \<preceq> perm_coloring p \<pi>'" using assms using color_fun.rep_eq color_fun_perm_coloring finer_def length.rep_eq length_perm_coloring perm_fun_perm_inv_range by fastforce lemma finer_strict_perm_coloring: assumes "length \<pi> = length \<pi>'" "length \<pi> = perm_dom p" "\<pi> \<prec> \<pi>'" shows "perm_coloring p \<pi> \<prec> perm_coloring p \<pi>'" proof- have "perm_coloring p \<pi> \<noteq> perm_coloring p \<pi>'" using assms by (metis finer_strict_def perm_coloring_inj) then show ?thesis using assms unfolding finer_strict_def by auto qed lemma finer_strict_perm_coloring': assumes "length \<pi> = length \<pi>'" "length \<pi> = perm_dom p" "perm_coloring p \<pi> \<prec> perm_coloring p \<pi>'" shows "\<pi> \<prec> \<pi>'" using assms finer_strict_perm_coloring[of "perm_coloring p \<pi>" "perm_coloring p \<pi>'" "perm_inv p"] by auto subsection\<open>Permute coloring based on its discrete refinement\<close> definition \<C> :: "coloring \<Rightarrow> coloring \<Rightarrow> coloring" where "\<C> \<pi> \<alpha> \<equiv> perm_coloring (discrete_coloring_perm \<alpha>) \<pi>" lemma length_\<C>: assumes "length \<alpha> = length \<pi>" "discrete \<alpha>" shows "length (\<C> \<pi> \<alpha>) = length \<pi>" using assms length_perm_coloring perm_dom_discrete_coloring_perm unfolding \<C>_def by force lemma color_fun_\<C>: assumes "length \<alpha> = length \<pi>" "discrete \<alpha>" "v < length \<pi>" shows "color_fun (\<C> \<pi> \<alpha>) v = (color_fun \<pi> \<circ> inv_n (length \<alpha>) (color_fun \<alpha>)) v" proof- have "color_fun (\<C> \<pi> \<alpha>) v = (color_fun \<pi> \<circ> perm_fun (perm_inv (make_perm (length \<alpha>) (color_fun \<alpha>)))) v" using assms using color_fun_perm_coloring_app[of "make_perm (length \<alpha>) (color_fun \<alpha>)" \<pi> v] unfolding \<C>_def discrete_coloring_perm_def by (metis discrete_coloring_is_permutation perm_dom_make_perm) then show ?thesis by (smt (verit, best) assms(1) assms(2) assms(3) comp_apply discrete_coloring_is_permutation finer_length inv_n_def inv_perm_fun_def inv_perm_fun_perm_fun make_perm_inv_perm_fun perm_fun_make_perm) qed lemma color_fun_\<C>': assumes "length \<alpha> = length \<pi>" "discrete \<alpha>" "v < length \<pi>" shows "color_fun (\<C> \<pi> \<alpha>) (color_fun \<alpha> v) = color_fun \<pi> v" using assms by (metis \<C>_def discrete_coloring_is_permutation discrete_coloring_perm_def perm_coloring_perm_fun perm_dom_make_perm perm_fun_discrete_coloring_perm) lift_definition id_coloring :: "nat => coloring" is "\<lambda> n. [0..<n]" by auto lemma length_id_coloring [simp]: shows "length (id_coloring n) = n" by transfer auto lemma color_fun_id_coloring_app [simp]: assumes "v < n" shows "color_fun (id_coloring n) v = v" using assms by transfer auto lemma \<C>_id_finer: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" shows "finer (id_coloring (length \<alpha>)) (\<C> \<pi> \<alpha>)" unfolding finer_def proof safe show "length (id_coloring (length \<alpha>)) = length (\<C> \<pi> \<alpha>)" by (simp add: \<C>_def assms(1) assms(2) discrete_coloring_perm_def finer_length) next fix v w assume lt: "v < length (\<C> \<pi> \<alpha>)" "w < length (\<C> \<pi> \<alpha>)" assume "color_fun (\<C> \<pi> \<alpha>) v < color_fun (\<C> \<pi> \<alpha>) w" then have "v < w" by (smt (verit, ccfv_threshold) \<C>_def assms(1) assms(2) color_fun_perm_coloring_app comp_apply discrete_coloring_is_permutation discrete_coloring_perm_def finer_def length_\<C> lt(1) lt(2) perm_dom_make_perm perm_fun_perm_inv_range perm_inv_make_perm1) then show "color_fun (id_coloring (length \<alpha>)) v < color_fun (id_coloring (length \<alpha>)) w" using assms(1) assms(2) finer_def length_\<C> lt(2) by auto qed lemma \<C>_mono: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" assumes "v < length \<pi>" "w < length \<pi>" "v \<le> w" shows "color_fun (\<C> \<pi> \<alpha>) v \<le> color_fun (\<C> \<pi> \<alpha>) w" using assms by (smt (verit, ccfv_SIG) \<C>_def color_fun_perm_coloring_app comp_apply discrete_coloring_is_permutation discrete_coloring_perm_def finer_def le_antisym linorder_cases order.order_iff_strict perm_dom_make_perm perm_fun_perm_inv_range perm_inv_make_perm1) lemma \<C>_colors [simp]: assumes "length \<pi> = length \<alpha>" "discrete \<alpha>" shows "colors (\<C> \<pi> \<alpha>) = colors \<pi>" using assms unfolding \<C>_def by simp lemma \<C>_0: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" "length \<pi> > 0" shows "color_fun (\<C> \<pi> \<alpha>) 0 = 0" using assms proof- let ?c = "color_fun (\<C> \<pi> \<alpha>)" have "0 \<in> set (colors \<pi>)" using `length \<pi> > 0` by (metis color_fun_in_colors colors_def empty_iff ex_color gr_zeroI list.set(1) upt_eq_Nil_conv) then have "0 \<in> set (colors (\<C> \<pi> \<alpha>))" using assms by (simp add: finer_def) then obtain v where "v < length (\<C> \<pi> \<alpha>)" "?c v = 0" using ex_color_color_fun by blast then show ?thesis using \<C>_mono[OF assms(1-2)] by (metis (full_types) assms(1) assms(2) finer_length leI le_zero_eq length_\<C> less_nat_zero_code) qed lemma \<C>_consecutive_colors: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" assumes "v + 1 < length \<pi>" shows "color_fun (\<C> \<pi> \<alpha>) (v + 1) = (color_fun (\<C> \<pi> \<alpha>) v) \<or> color_fun (\<C> \<pi> \<alpha>) (v + 1) = (color_fun (\<C> \<pi> \<alpha>) v) + 1" proof- let ?\<alpha> = "discrete_coloring_perm \<alpha>" let ?c = "color_fun (perm_coloring ?\<alpha> \<pi>)" have "?c (v + 1) \<ge> ?c v" using \<C>_mono[OF assms(1-2)] assms(3) unfolding \<C>_def by auto moreover have "?c (v + 1) \<le> ?c v + 1" proof (rule ccontr) assume "\<not> ?thesis" then have "?c (v + 1) > ?c v + 1" by simp have "\<exists> w. w < length \<pi> \<and> ?c w = ?c v + 1" proof- have "?c (v + 1) \<in> set (colors \<pi>)" using \<open>v + 1 < length \<pi>\<close> by (metis assms(1) assms(2) color_fun_in_colors colors_perm_coloring finer_length length_perm_coloring perm_dom_discrete_coloring_perm) then have "?c v + 1 \<in> set (colors \<pi>)" using \<open>?c v + 1 < ?c (v + 1)\<close> by (simp add: colors_def) then show ?thesis by (smt (verit, del_insts) assms(1) assms(2) colors_perm_coloring ex_color_color_fun finer_length length_perm_coloring perm_dom_discrete_coloring_perm) qed then obtain w where "w < length \<pi>" "?c w = ?c v + 1" by auto have "?c v < ?c w" "?c w < ?c (v + 1)" using \<open>?c w = ?c v + 1\<close> using \<open>?c v + 1 < ?c (v + 1)\<close> by auto then have "v < w \<and> w < v + 1" by (metis \<C>_def \<C>_mono \<open>w < length \<pi>\<close> add.commute assms(1) assms(2) assms(3) linorder_not_less trans_le_add2) then show False by auto qed ultimately show ?thesis using \<C>_def by fastforce qed lemma \<C>_cell: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" shows "cell (\<C> \<pi> \<alpha>) c = color_fun \<alpha> ` cell \<pi> c" proof- have "is_perm_fun (length \<alpha>) (color_fun \<alpha>)" by (simp add: assms(2)) let ?c = "color_fun (\<C> \<pi> \<alpha>)" have "cell (\<C> \<pi> \<alpha>) c = {v. v < length (\<C> \<pi> \<alpha>) \<and> ?c v = c}" unfolding cell_def by simp also have "... = {v. v < length \<alpha> \<and> ?c v = c}" using assms(1) assms(2) finer_length length_\<C> by presburger also have "... = {color_fun \<alpha> t | t. color_fun \<alpha> t < length \<alpha> \<and> ?c (color_fun \<alpha> t) = c}" using `is_perm_fun (length \<alpha>) (color_fun \<alpha>)` by (metis perm_inv_make_perm1) also have "... = {color_fun \<alpha> t | t. t < length \<alpha> \<and> ?c (color_fun \<alpha> t) = c}" using `is_perm_fun (length \<alpha>) (color_fun \<alpha>)` unfolding is_perm_fun_def bij_betw_def by (metis (no_types, lifting) \<open>is_perm_fun (length \<alpha>) (color_fun \<alpha>)\<close> assms(2) atLeastLessThan_iff bot_nat_0.extremum discrete_coloring_perm_def image_eqI perm_dom_discrete_coloring_perm perm_fun_perm_inv_range perm_inv_make_perm1) also have "... = {color_fun \<alpha> t | t. t < length \<alpha> \<and> color_fun \<pi> t = c}" by (metis assms(1) assms(2) color_fun_\<C>' finer_length) also have "... = color_fun \<alpha> ` (cell \<pi> c)" unfolding cell_def using assms(1) finer_length by auto finally show ?thesis . qed lemma \<C>_card_cell: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" shows "card (cell (\<C> \<pi> \<alpha>) c) = card (cell \<pi> c)" proof (rule bij_betw_same_card[symmetric]) show "bij_betw (color_fun \<alpha>) (cell \<pi> c) (cell (\<C> \<pi> \<alpha>) c)" by (smt (verit) \<C>_cell assms(1) assms(2) bij_betwI' cell_def discrete_coloring_is_permutation discrete_coloring_perm_def finer_length image_iff mem_Collect_eq perm_dom_discrete_coloring_perm perm_dom_perm_inv perm_fun_perm_inv1 perm_fun_perm_inv_range perm_inv_make_perm1) qed lemma \<C>_\<alpha>_independent': assumes "finer \<alpha> \<pi>" "discrete \<alpha>" assumes "finer \<beta> \<pi>" "discrete \<beta>" assumes "\<forall> w \<le> v. color_fun (\<C> \<pi> \<alpha>) w = color_fun (\<C> \<pi> \<beta>) w" "v + 1 < length \<pi>" assumes "color_fun (\<C> \<pi> \<alpha>) (v + 1) = color_fun (\<C> \<pi> \<alpha>) v + 1" shows "color_fun (\<C> \<pi> \<beta>) (v + 1) = color_fun (\<C> \<pi> \<beta>) v + 1" proof (rule ccontr) let ?\<alpha> = "color_fun (\<C> \<pi> \<alpha>)" let ?\<beta> = "color_fun (\<C> \<pi> \<beta>)" assume "\<not> ?thesis" then have "?\<beta> (v + 1) = ?\<beta> v" using \<C>_consecutive_colors assms by blast let ?cell = "\<lambda> n C c. {v. v < n \<and> color_fun C v = c}" have "card (cell (\<C> \<pi> \<beta>) (?\<alpha> v)) > card (?cell (v + 1) (\<C> \<pi> \<beta>) (?\<alpha> v))" proof- have "?cell (v + 1) (\<C> \<pi> \<beta>) (?\<alpha> v) \<union> {v + 1} \<subseteq> cell (\<C> \<pi> \<beta>) (?\<alpha> v)" using \<open>?\<beta> (v + 1) = ?\<beta> v\<close> using assms(3-6) using finer_length length_\<C> unfolding cell_def by auto moreover have "finite (cell (\<C> \<pi> \<beta>) (?\<alpha> v))" unfolding cell_def by auto ultimately have "card (?cell (v + 1) (\<C> \<pi> \<beta>) (?\<alpha> v) \<union> {v + 1}) \<le> card (cell (\<C> \<pi> \<beta>) (?\<alpha> v))" by (meson card_mono) thus ?thesis unfolding cell_def by auto qed moreover have "\<forall> y. v < y \<and> y < length \<pi> \<longrightarrow> ?\<alpha> v < ?\<alpha> y" using assms by (metis \<C>_mono discrete) then have "card (cell (\<C> \<pi> \<alpha>) (?\<alpha> v)) = card (?cell (v + 1) (\<C> \<pi> \<alpha>) (?\<alpha> v))" unfolding cell_def by (metis (no_types, lifting) assms(1) assms(2) assms(6) finer_length leD leI length_\<C> less_add_one less_or_eq_imp_le order_less_le_trans) moreover have "card (cell (\<C> \<pi> \<alpha>) (?\<alpha> v)) = card (cell (\<C> \<pi> \<beta>) (?\<alpha> v))" using assms by (simp add: \<C>_card_cell) moreover have "?cell (v + 1) (\<C> \<pi> \<alpha>) (?\<alpha> v) = ?cell (v + 1) (\<C> \<pi> \<beta>) (?\<alpha> v)" using \<open>\<forall> w \<le> v. color_fun (\<C> \<pi> \<alpha>) w = color_fun (\<C> \<pi> \<beta>) w\<close> unfolding cell_def by auto then have "card (?cell (v + 1) (\<C> \<pi> \<alpha>) (?\<alpha> v)) = card (?cell (v + 1) (\<C> \<pi> \<beta>) (?\<alpha> v))" by simp ultimately show False by simp qed lemma \<C>_\<alpha>_independent: assumes "finer \<alpha> \<pi>" "discrete \<alpha>" assumes "finer \<beta> \<pi>" "discrete \<beta>" assumes "v < length \<pi>" shows "color_fun (\<C> \<pi> \<alpha>) v = color_fun (\<C> \<pi> \<beta>) v" using \<open>v < length \<pi>\<close> proof (induction v rule: less_induct) case (less v') show ?case proof (cases "v' = 0") case True then have "Min {c. c < length \<pi>} = 0" by (metis \<open>v' < length \<pi>\<close> empty_Collect_eq eq_Min_iff finite_Collect_less_nat mem_Collect_eq zero_le) then show ?thesis using assms \<C>_0 True by simp next case False then obtain v where "v' = v + 1" by (metis add.commute add.left_neutral canonically_ordered_monoid_add_class.lessE less_one linorder_neqE_nat) have ih: "\<forall> w \<le> v. color_fun (\<C> \<pi> \<alpha>) w = color_fun (\<C> \<pi> \<beta>) w" using less.IH using \<open>v' = v + 1\<close> less.prems by force show ?thesis proof (cases "color_fun (\<C> \<pi> \<alpha>) (v + 1) = color_fun (\<C> \<pi> \<alpha>) v + 1") case True then have "color_fun (\<C> \<pi> \<beta>) (v + 1) = color_fun (\<C> \<pi> \<beta>) v + 1" using \<C>_\<alpha>_independent'[OF assms(1-4) ih] using \<open>v' = v + 1\<close> less.prems by blast thus ?thesis using True \<open>v' = v + 1\<close> using less.IH less.prems by auto next case False then have "color_fun (\<C> \<pi> \<alpha>) (v + 1) = color_fun (\<C> \<pi> \<alpha>) v" using \<C>_consecutive_colors \<open>v' = v + 1\<close> assms(1) assms(2) assms(3) less.prems by blast have "color_fun (\<C> \<pi> \<beta>) (v + 1) = color_fun (\<C> \<pi> \<beta>) v" proof (rule ccontr) assume "\<not> ?thesis" then have "color_fun (\<C> \<pi> \<beta>) (v + 1) = color_fun (\<C> \<pi> \<beta>) v + 1" using \<C>_consecutive_colors \<open>v' = v + 1\<close> assms(1) assms(3) assms(4) less.prems by blast then have "color_fun (\<C> \<pi> \<alpha>) (v + 1) = color_fun (\<C> \<pi> \<alpha>) v + 1" using \<C>_\<alpha>_independent'[OF assms(3-4) assms(1-2)] ih using \<open>v' = v + 1\<close> less.prems by presburger then show False using `color_fun (\<C> \<pi> \<alpha>) (v + 1) = color_fun (\<C> \<pi> \<alpha>) v` by auto qed then show ?thesis using \<open>color_fun (\<C> \<pi> \<alpha>) (v + 1) = color_fun (\<C> \<pi> \<alpha>) v\<close> \<open>v' = v + 1\<close> ih by auto qed qed qed subsection \<open> Individualize \<close> definition individualize_fun :: "nat \<Rightarrow> (nat \<Rightarrow> color) \<Rightarrow> nat \<Rightarrow> (nat \<Rightarrow> color)" where "individualize_fun n \<pi> v = (if (\<forall> w < n. w \<noteq> v \<longrightarrow> \<pi> w \<noteq> \<pi> v) then \<pi> else (\<lambda> w. (if \<pi> w < \<pi> v \<or> w = v then \<pi> w else \<pi> w + 1)))" definition individualize :: "coloring \<Rightarrow> nat \<Rightarrow> coloring" where "individualize \<pi> v = color_fun_to_coloring (length \<pi>) (individualize_fun (length \<pi>) (color_fun \<pi>) v)" lemma individualize_fun_all_colors [simp]: assumes "\<exists> k. \<pi> ` {0..<n} = {0..<k}" "v < n" shows "\<exists> k. individualize_fun n \<pi> v ` {0..<n} = {0..<k}" using assms proof- obtain k where k: "\<pi> ` {0..<n} = {0..<k}" using assms by auto show ?thesis proof (cases "\<forall> w < n. w \<noteq> v \<longrightarrow> \<pi> w \<noteq> \<pi> v") case True then show ?thesis using k by (rule_tac x="k" in exI) (simp add: individualize_fun_def) next case False show ?thesis proof (cases "\<forall> w < n. \<pi> w < \<pi> v \<or> w = v") case True then show ?thesis using k unfolding individualize_fun_def by auto next case False show ?thesis proof (rule_tac x="k+1" in exI, safe) fix x assume x: "x \<in> {0..<n}" show "individualize_fun n \<pi> v x \<in> {0..<k + 1}" proof- have "individualize_fun n \<pi> v x \<le> \<pi> x + 1" unfolding individualize_fun_def by auto moreover have "\<pi> x + 1 < k + 1" using x k by auto ultimately show ?thesis by simp qed next fix c assume "c \<in> {0..<k+1}" have "\<pi> v < k" using `v < n` k by auto show "c \<in> individualize_fun n \<pi> v ` {0..<n}" proof (cases "c < \<pi> v") case True then show ?thesis using `\<not> (\<forall>w<n. \<pi> w < \<pi> v \<or> w = v)` \<open>\<pi> v < k\<close> k by (auto simp add: individualize_fun_def) next case False show ?thesis proof (cases "c = \<pi> v") case True then have "individualize_fun n \<pi> v v = c" using `\<not> (\<forall>w<n. \<pi> w < \<pi> v \<or> w = v)` by (simp add: individualize_fun_def) then show ?thesis using `v < n` by auto next case False then have "c > 0" "c > \<pi> v" using `\<not> (c < \<pi> v)` by auto then have "c - 1 \<in> {0..<k}" using `c \<in> {0..<k+1}` by auto then obtain w where "w < n" "\<pi> w = c - 1" "w \<noteq> v" using k `\<not> (\<forall>w<n. w \<noteq> v \<longrightarrow> \<pi> w \<noteq> \<pi> v)` `c > \<pi> v` `c > 0` by (smt (verit) add_0 diff_zero imageE in_set_conv_nth length_upt nth_upt set_upt) then have "individualize_fun n \<pi> v w = c" using `\<not> (\<forall>w<n. w \<noteq> v \<longrightarrow> \<pi> w \<noteq> \<pi> v)` `c > 0` \<open>\<pi> v < c\<close> by (auto simp add: individualize_fun_def) then show ?thesis using `w < n` by auto qed qed qed qed qed qed lemma individualize_fun_finer [simp]: assumes "v < n" "v1 < n" "v2 < n" "\<pi> v1 < \<pi> v2" shows "individualize_fun n \<pi> v v1 < individualize_fun n \<pi> v v2" using assms unfolding individualize_fun_def by auto lemma individualize_finer [simp]: assumes "v < length \<pi>" shows "finer (individualize \<pi> v) \<pi>" using assms unfolding finer_def individualize_def by auto lemma individualize_length [simp]: assumes "v < length \<pi>" shows "length (individualize \<pi> v) = length \<pi>" using assms using finer_length individualize_finer by blast lemma individualize_fun_retains_color [simp]: assumes "v < n" shows "individualize_fun n \<pi> v v = \<pi> v" using assms by (simp add: individualize_fun_def) lemma individualize_retains_color: assumes "v < length \<pi>" shows "color_fun \<pi> v \<in> set (colors (individualize \<pi> v))" using assms unfolding individualize_def all_colors by force lemma individualize_fun_cell_v [simp]: assumes "v < n" shows "{w. w < n \<and> individualize_fun n \<pi> v w = \<pi> v} = {v}" using assms by (auto simp add: individualize_fun_def) lemma individualize_fun_cell_v': assumes "v < n" "w < n" "individualize_fun n \<pi> v w = \<pi> v" shows "w = v" proof- have "w \<in> {w. w < n \<and> individualize_fun n \<pi> v w = \<pi> v}" using assms by blast then show ?thesis using `v < n` by simp qed lemma individualize_cell_v [simp]: assumes "v < length \<pi>" shows "cell (individualize \<pi> v) (color_fun \<pi> v) = {v}" using \<open>v < length \<pi>\<close> unfolding cell_def individualize_def by (auto simp add: individualize_fun_cell_v') lemma individualize_singleton: assumes "v < length \<pi>" shows "{v} \<in> set (cells (individualize \<pi> v))" using assms individualize_retains_color unfolding cells_def by force lemma individualize_singleton_preserve: assumes "{v'} \<in> set (cells \<pi>)" "v' < length \<pi>" "v < length \<pi>" shows "{v'} \<in> set (cells (individualize \<pi> v))" using assms finer_singleton individualize_finer by blast lemma individualize_fun_perm [simp]: assumes "perm_dom p = length \<pi>" "v < length \<pi>" "w < length \<pi>" shows "individualize_fun (length (perm_coloring p \<pi>)) (color_fun (perm_coloring p \<pi>)) (perm_fun p v) (perm_fun p w) = individualize_fun (length \<pi>) (color_fun \<pi>) v w" using assms unfolding individualize_fun_def by (smt (verit, ccfv_SIG) color_fun_perm_coloring_app comp_apply length_perm_coloring perm_dom_perm_inv perm_fun_perm_inv1 perm_fun_perm_inv_range) lemma individualize_perm [simp]: assumes "perm_dom p = length \<pi>" "v < length \<pi>" shows "individualize (perm_coloring p \<pi>) (perm_fun p v) = perm_coloring p (individualize \<pi> v)" using assms individualize_fun_perm color_fun_to_coloring_perm' color_fun_all_colors individualize_fun_all_colors unfolding individualize_def by auto end
#ifndef OPENMC_TALLIES_FILTER_COLLISIONS_H #define OPENMC_TALLIES_FILTER_COLLISIONS_H #include <vector> #include <unordered_map> #include <gsl/gsl> #include "openmc/tallies/filter.h" namespace openmc { //============================================================================== //! Bins the incident neutron energy. //============================================================================== class CollisionFilter : public Filter { public: //---------------------------------------------------------------------------- // Constructors, destructors ~CollisionFilter() = default; //---------------------------------------------------------------------------- // Methods std::string type() const override { return "collision"; } void from_xml(pugi::xml_node node) override; void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const override; void to_statepoint(hid_t filter_group) const override; std::string text_label(int bin) const override; //---------------------------------------------------------------------------- // Accessors const std::vector<int>& bins() const { return bins_; } void set_bins(gsl::span<const int> bins); protected: //---------------------------------------------------------------------------- // Data members std::vector<int> bins_; std::unordered_map<int,int> map_; }; } // namespace openmc #endif // OPENMC_TALLIES_FILTER_COLLISIONS_H
With Infinity , Townsend began to label all albums outside of Strapping Young Lad under his own name , dropping the Ocean Machine moniker , to reduce confusion . He wanted to show that despite the highly varied nature of his projects , they are all simply aspects of his identity . The album Biomech was relabeled and redistributed as Ocean Machine : Biomech , under Townsend 's name , to reflect the new arrangement . Townsend 's bandmates began to play two sets at their shows , one as Strapping Young Lad , and one as the Devin Townsend Band , playing songs from Townsend 's solo albums .
-- @@stderr -- dtrace: failed to compile script test/unittest/builtinvar/err.D_XLATE_NOCONV.pr_size.d: [D_XLATE_NOCONV] line 19: translator does not define conversion for member: pr_size
module Old_Impl export MultiheadAttention const Abstract3DTensor{T} = AbstractArray{T, 3} include("batched_tril.jl") include("batchedmul.jl") # an multi-head attention used in Transformers.jl v0.1.13 include("./mh_atten.jl") include("./getmask.jl") end
(* Title: Infinite (Non-Well-Founded) Chains Author: Jasmin Blanchette <jasmin.blanchette at inria.fr>, 2016 Maintainer: Jasmin Blanchette <jasmin.blanchette at inria.fr> *) section \<open>Infinite (Non-Well-Founded) Chains\<close> theory Infinite_Chain imports Lambda_Free_Util begin text \<open> This theory defines the concept of a minimal bad (or non-well-founded) infinite chain, as found in the term rewriting literature to prove the well-foundedness of syntactic term orders. \<close> context fixes p :: "'a \<Rightarrow> 'a \<Rightarrow> bool" begin definition inf_chain :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where "inf_chain f \<longleftrightarrow> (\<forall>i. p (f i) (f (Suc i)))" lemma wfP_iff_no_inf_chain: "wfP (\<lambda>x y. p y x) \<longleftrightarrow> (\<nexists>f. inf_chain f)" unfolding wfP_def wf_iff_no_infinite_down_chain inf_chain_def by simp lemma inf_chain_offset: "inf_chain f \<Longrightarrow> inf_chain (\<lambda>j. f (j + i))" unfolding inf_chain_def by simp definition bad :: "'a \<Rightarrow> bool" where "bad x \<longleftrightarrow> (\<exists>f. inf_chain f \<and> f 0 = x)" lemma inf_chain_bad: assumes bad_f: "inf_chain f" shows "bad (f i)" unfolding bad_def by (rule exI[of _ "\<lambda>j. f (j + i)"]) (simp add: inf_chain_offset[OF bad_f]) context fixes gt :: "'a \<Rightarrow> 'a \<Rightarrow> bool" assumes wf: "wf {(x, y). gt y x}" begin primrec worst_chain :: "nat \<Rightarrow> 'a" where "worst_chain 0 = (SOME x. bad x \<and> (\<forall>y. bad y \<longrightarrow> \<not> gt x y))" | "worst_chain (Suc i) = (SOME x. bad x \<and> p (worst_chain i) x \<and> (\<forall>y. bad y \<and> p (worst_chain i) y \<longrightarrow> \<not> gt x y))" declare worst_chain.simps[simp del] context fixes x :: 'a assumes x_bad: "bad x" begin lemma bad_worst_chain_0: "bad (worst_chain 0)" and min_worst_chain_0: "\<not> gt (worst_chain 0) x" proof - obtain y where "bad y \<and> (\<forall>z. bad z \<longrightarrow> \<not> gt y z)" using wf_exists_minimal[OF wf, of bad, OF x_bad] by force hence "bad (worst_chain 0) \<and> (\<forall>z. bad z \<longrightarrow> \<not> gt (worst_chain 0) z)" unfolding worst_chain.simps by (rule someI) thus "bad (worst_chain 0)" and "\<not> gt (worst_chain 0) x" using x_bad by blast+ qed lemma bad_worst_chain_Suc: "bad (worst_chain (Suc i))" and worst_chain_pred: "p (worst_chain i) (worst_chain (Suc i))" and min_worst_chain_Suc: "p (worst_chain i) x \<Longrightarrow> \<not> gt (worst_chain (Suc i)) x" proof (induct i rule: less_induct) case (less i) have "bad (worst_chain i)" proof (cases i) case 0 thus ?thesis using bad_worst_chain_0 by simp next case (Suc j) thus ?thesis using less(1) by blast qed then obtain fa where fa_bad: "inf_chain fa" and fa_0: "fa 0 = worst_chain i" unfolding bad_def by blast have "\<exists>s0. bad s0 \<and> p (worst_chain i) s0" proof (intro exI conjI) let ?y0 = "fa (Suc 0)" show "bad ?y0" unfolding bad_def by (auto intro: exI[of _ "\<lambda>i. fa (Suc i)"] inf_chain_offset[OF fa_bad]) show "p (worst_chain i) ?y0" using fa_bad[unfolded inf_chain_def] fa_0 by metis qed then obtain y0 where y0: "bad y0 \<and> p (worst_chain i) y0" by blast obtain y1 where y1: "bad y1 \<and> p (worst_chain i) y1 \<and> (\<forall>z. bad z \<and> p (worst_chain i) z \<longrightarrow> \<not> gt y1 z)" using wf_exists_minimal[OF wf, of "\<lambda>y. bad y \<and> p (worst_chain i) y", OF y0] by force let ?y = "worst_chain (Suc i)" have conj: "bad ?y \<and> p (worst_chain i) ?y \<and> (\<forall>z. bad z \<and> p (worst_chain i) z \<longrightarrow> \<not> gt ?y z)" unfolding worst_chain.simps using y1 by (rule someI) show "bad ?y" by (rule conj[THEN conjunct1]) show "p (worst_chain i) ?y" by (rule conj[THEN conjunct2, THEN conjunct1]) show "p (worst_chain i) x \<Longrightarrow> \<not> gt ?y x" using x_bad conj[THEN conjunct2, THEN conjunct2, rule_format] by meson qed lemma bad_worst_chain: "bad (worst_chain i)" by (cases i) (auto intro: bad_worst_chain_0 bad_worst_chain_Suc) lemma worst_chain_bad: "inf_chain worst_chain" unfolding inf_chain_def using worst_chain_pred by metis end context fixes x :: 'a assumes x_bad: "bad x" and p_trans: "\<And>z y x. p z y \<Longrightarrow> p y x \<Longrightarrow> p z x" begin lemma worst_chain_not_gt: "\<not> gt (worst_chain i) (worst_chain (Suc i))" for i proof (cases i) case 0 show ?thesis unfolding 0 by (rule min_worst_chain_0[OF inf_chain_bad[OF worst_chain_bad[OF x_bad]]]) next case Suc show ?thesis unfolding Suc by (rule min_worst_chain_Suc[OF inf_chain_bad[OF worst_chain_bad[OF x_bad]]]) (rule p_trans[OF worst_chain_pred[OF x_bad] worst_chain_pred[OF x_bad]]) qed end end end lemma inf_chain_subset: "inf_chain p f \<Longrightarrow> p \<le> q \<Longrightarrow> inf_chain q f" unfolding inf_chain_def by blast hide_fact (open) bad_worst_chain_0 bad_worst_chain_Suc end
State Before: x y : PGame ⊢ x ≤ y ∨ y ⧏ x State After: x y : PGame ⊢ x ≤ y ∨ ¬x ≤ y Tactic: rw [← PGame.not_le] State Before: x y : PGame ⊢ x ≤ y ∨ ¬x ≤ y State After: no goals Tactic: apply em
module EvolutionaryStrategies using Cambrian using Random using LinearAlgebra abstract type ESState end include("individual.jl") include("exponential_nes.jl") include("separable_nes.jl") end
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import algebra.category.Module.basic import category_theory.linear.basic import category_theory.preadditive.yoneda.basic /-! # The Yoneda embedding for `R`-linear categories The Yoneda embedding for `R`-linear categories `C`, sends an object `X : C` to the `Module R`-valued presheaf on `C`, with value on `Y : Cᵒᵖ` given by `Module.of R (unop Y ⟶ X)`. TODO: `linear_yoneda R C` is `R`-linear. TODO: In fact, `linear_yoneda` itself is additive and `R`-linear. -/ universes w v u open opposite namespace category_theory variables (R : Type w) [ring R] (C : Type u) [category.{v} C] [preadditive C] [linear R C] /-- The Yoneda embedding for `R`-linear categories `C`, sending an object `X : C` to the `Module R`-valued presheaf on `C`, with value on `Y : Cᵒᵖ` given by `Module.of R (unop Y ⟶ X)`. -/ @[simps] def linear_yoneda : C ⥤ Cᵒᵖ ⥤ Module R := { obj := λ X, { obj := λ Y, Module.of R (unop Y ⟶ X), map := λ Y Y' f, linear.left_comp R _ f.unop, map_comp' := λ _ _ _ f g, linear_map.ext $ λ _, category.assoc _ _ _, map_id' := λ Y, linear_map.ext $ λ _, category.id_comp _ }, map := λ X X' f, { app := λ Y, linear.right_comp R _ f, naturality' := λ X Y f, linear_map.ext $ λ x, by simp only [category.assoc, Module.coe_comp, function.comp_app, linear.left_comp_apply, linear.right_comp_apply] }, map_id' := λ X, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _, by simp only [linear.right_comp_apply, category.comp_id, nat_trans.id_app, Module.id_apply], map_comp' := λ _ _ _ f g, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _, by simp only [category.assoc, linear.right_comp_apply, nat_trans.comp_app, Module.coe_comp, function.comp_app] } /-- The Yoneda embedding for `R`-linear categories `C`, sending an object `Y : Cᵒᵖ` to the `Module R`-valued copresheaf on `C`, with value on `X : C` given by `Module.of R (unop Y ⟶ X)`. -/ @[simps] def linear_coyoneda : Cᵒᵖ ⥤ C ⥤ Module R := { obj := λ Y, { obj := λ X, Module.of R (unop Y ⟶ X), map := λ Y Y', linear.right_comp _ _, map_id' := λ Y, linear_map.ext $ λ _, category.comp_id _, map_comp' := λ _ _ _ f g, linear_map.ext $ λ _, eq.symm (category.assoc _ _ _) }, map := λ Y Y' f, { app := λ X, linear.left_comp _ _ f.unop, naturality' := λ X Y f, linear_map.ext $ λ x, by simp only [category.assoc, Module.coe_comp, function.comp_app, linear.right_comp_apply, linear.left_comp_apply] }, map_id' := λ X, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _, by simp only [linear.left_comp_apply, unop_id, category.id_comp, nat_trans.id_app, Module.id_apply], map_comp' := λ _ _ _ f g, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _, by simp only [category.assoc, Module.coe_comp, function.comp_app, linear.left_comp_apply, unop_comp, nat_trans.comp_app]} instance linear_yoneda_obj_additive (X : C) : ((linear_yoneda R C).obj X).additive := {} instance linear_coyoneda_obj_additive (Y : Cᵒᵖ) : ((linear_coyoneda R C).obj Y).additive := {} @[simp] lemma whiskering_linear_yoneda : linear_yoneda R C ⋙ (whiskering_right _ _ _).obj (forget (Module.{v} R)) = yoneda := rfl @[simp] lemma whiskering_linear_yoneda₂ : linear_yoneda R C ⋙ (whiskering_right _ _ _).obj (forget₂ (Module.{v} R) AddCommGroup.{v}) = preadditive_yoneda := rfl @[simp] lemma whiskering_linear_coyoneda : linear_coyoneda R C ⋙ (whiskering_right _ _ _).obj (forget (Module.{v} R)) = coyoneda := rfl @[simp] lemma whiskering_linear_coyoneda₂ : linear_coyoneda R C ⋙ (whiskering_right _ _ _).obj (forget₂ (Module.{v} R) AddCommGroup.{v}) = preadditive_coyoneda := rfl instance linear_yoneda_full : full (linear_yoneda R C) := let yoneda_full : full (linear_yoneda R C ⋙ (whiskering_right _ _ _).obj (forget (Module.{v} R))) := yoneda.yoneda_full in by exactI full.of_comp_faithful (linear_yoneda R C) (((whiskering_right _ _ _)).obj (forget (Module.{v} R))) instance linear_coyoneda_full : full (linear_coyoneda R C) := let coyoneda_full : full (linear_coyoneda R C ⋙ (whiskering_right _ _ _).obj (forget (Module.{v} R))) := coyoneda.coyoneda_full in by exactI full.of_comp_faithful (linear_coyoneda R C) (((whiskering_right _ _ _)).obj (forget (Module.{v} R))) instance linear_yoneda_faithful : faithful (linear_yoneda R C) := faithful.of_comp_eq (whiskering_linear_yoneda R C) instance linear_coyoneda_faithful : faithful (linear_coyoneda R C) := faithful.of_comp_eq (whiskering_linear_coyoneda R C) end category_theory
[STATEMENT] lemma assert_seq: "{b}\<^sub>\<bottom> ;; {c}\<^sub>\<bottom> = {(b \<and> c)}\<^sub>\<bottom>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. {b}\<^sub>\<bottom> ;; {c}\<^sub>\<bottom> = {b \<and> c}\<^sub>\<bottom> [PROOF STEP] by (rel_auto)
#' @param name Name of a collection or core. Or leave as \code{NULL} if not needed. #' @param callopts Call options passed on to [crul::HttpClient] #' @param raw (logical) If TRUE, returns raw data in format specified by wt param #' @param parsetype (character) One of 'list' or 'df' #' @param concat (character) Character to concatenate elements of longer than length 1. #' Note that this only works reliably when data format is json (wt='json'). The parsing #' is more complicated in XML format, but you can do that on your own. #' @param progress a function with logic for printing a progress #' bar for an HTTP request, ultimately passed down to \pkg{curl}. only supports #' \code{httr::progress} for now. See the README for an example. #' @param ... Further args to be combined into query #' #' @section Group parameters: #' \itemize{ #' \item q Query terms, defaults to '*:*', or everything. #' \item fq Filter query, this does not affect the search, only what gets returned #' \item fl Fields to return #' \item wt (character) Data type returned, defaults to 'json'. One of json or xml. If json, #' uses \code{\link[jsonlite]{fromJSON}} to parse. If xml, uses \code{\link[XML]{xmlParse}} to #' parse. csv is only supported in \code{\link{solr_search}} and \code{\link{solr_all}}. #' \item key API key, if needed. #' \item group.field (fieldname) Group based on the unique values of a field. The #' field must currently be single-valued and must be either indexed, or be another #' field type that has a value source and works in a function query - such as #' ExternalFileField. Note: for Solr 3.x versions the field must by a string like #' field such as StrField or TextField, otherwise a http status 400 is returned. #' \item group.func (function query) Group based on the unique values of a function #' query. Solr4.0 This parameter only is supported on 4.0 #' \item group.query (query) Return a single group of documents that also match the #' given query. #' \item rows (number) The number of groups to return. Defaults to 10. #' \item start (number) The offset into the list of groups. #' \item group.limit (number) The number of results (documents) to return for each #' group. Defaults to 1. #' \item group.offset (number) The offset into the document list of each group. #' \item sort How to sort the groups relative to each other. For example, #' sort=popularity desc will cause the groups to be sorted according to the highest #' popularity doc in each group. Defaults to "score desc". #' \item group.sort How to sort documents within a single group. Defaults #' to the same value as the sort parameter. #' \item group.format One of grouped or simple. If simple, the grouped documents are #' presented in a single flat list. The start and rows parameters refer to numbers of #' documents instead of numbers of groups. #' \item group.main (logical) If true, the result of the last field grouping command #' is used as the main result list in the response, using group.format=simple #' \item group.ngroups (logical) If true, includes the number of groups that have #' matched the query. Default is false. Solr4.1 WARNING: If this parameter is set #' to true on a sharded environment, all the documents that belong to the same group #' have to be located in the same shard, otherwise the count will be incorrect. If you #' are using SolrCloud, consider using "custom hashing" #' \item group.cache.percent (0-100) If > 0 enables grouping cache. Grouping is executed #' actual two searches. This option caches the second search. A value of 0 disables #' grouping caching. Default is 0. Tests have shown that this cache only improves search #' time with boolean queries, wildcard queries and fuzzy queries. For simple queries like #' a term query or a match all query this cache has a negative impact on performance #' }
(* Title: HOL/Auth/n_germanSymIndex_lemma_on_inv__25.thy Author: Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences Copyright 2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences *) header{*The n_germanSymIndex Protocol Case Study*} theory n_germanSymIndex_lemma_on_inv__25 imports n_germanSymIndex_base begin section{*All lemmas on causal relation between inv__25 and some rule r*} lemma n_SendInv__part__0Vsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__0 i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__0 i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInv__part__1Vsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInv__part__1 i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInv__part__1 i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendInvAckVsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendInvAck i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendInvAck i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvInvAckVsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvInvAck i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvInvAck i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntSVsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntS i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntS i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendGntEVsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_SendGntE N i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_SendGntE N i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Ident ''Chan3'') p__Inv2) ''Cmd'')) (Const InvAck)) (eqn (IVar (Para (Ident ''ShrSet'') p__Inv2)) (Const false))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntSVsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntS i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntS i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_RecvGntEVsinv__25: assumes a1: "(\<exists> i. i\<le>N\<and>r=n_RecvGntE i)" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain i where a1:"i\<le>N\<and>r=n_RecvGntE i" apply fastforce done from a2 obtain p__Inv2 where a2:"p__Inv2\<le>N\<and>f=inv__25 p__Inv2" apply fastforce done have "(i=p__Inv2)\<or>(i~=p__Inv2)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(i=p__Inv2)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(i~=p__Inv2)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_SendReqE__part__1Vsinv__25: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__1 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__25: assumes a1: "\<exists> i d. i\<le>N\<and>d\<le>N\<and>r=n_Store i d" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqEVsinv__25: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqE N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqE__part__0Vsinv__25: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqE__part__0 i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_SendReqSVsinv__25: assumes a1: "\<exists> i. i\<le>N\<and>r=n_SendReqS i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_RecvReqSVsinv__25: assumes a1: "\<exists> i. i\<le>N\<and>r=n_RecvReqS N i" and a2: "(\<exists> p__Inv2. p__Inv2\<le>N\<and>f=inv__25 p__Inv2)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
(* Copyright (C) 2017 M.A.L. Marques This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. *) (* type: gga_exc *) cs1_gamma := 0.006: (* as in B88 *) cs1_d := 0.349: (* as in CS *) cs1_C1 := -0.018897: cs1_C2 := 0.155240: cs1_C3 := -0.159068: cs1_C4 := 0.007953: (* Equation (24) corrected in Equation (8) in Proynov2006_436 *) cs1_ess := (rs, z, xs) -> + opz_pow_n(z,1)/2 * n_spin(rs, z)^(1/3)/(n_spin(rs, z)^(1/3) + cs1_d) * (cs1_C1 + cs1_C2*cs1_gamma^2*xs^4/(1 + cs1_gamma*xs^2)^2): (* Equation (25) corrected in Equation (6) in Proynov2006_436 *) cs1_eab := (rs, z, xt) -> + (1 - z^2)/4 * 1/(1 + cs1_d*n_total(rs)^(-1/3)) * (cs1_C3 + cs1_C4*cs1_gamma^2*xt^4/(1 + cs1_gamma*xt^2)^2): f_cs1 := (rs, z, xt, xs0, xs1) -> + cs1_eab(rs, z, xt) + cs1_ess(rs, z, xs0) + cs1_ess(rs, -z, xs1): f := (rs, z, xt, xs0, xs1) -> f_cs1(rs, z, xt, xs0, xs1):
A 30-minute (ish) mini-episode in which we discuss hybrid reading lists, creating a reading and writing schedule, giving yourself permission to write, book voodoo, fluffing your bookshelves and Booker prize excitement. This month we will be giving away a copy of The Queen of Blood by Sarah Beth Durst and a bunch of adorable succulent bookmarks – we will explain how to enter toward the end of the post. Blue Lake and literary bliss! lot like existing in an extended read.write.repeat podcast. In short: heaven. Lyric Essay–this is an essay that often uses fragments and combines poetry, fiction, research, and other genre blending elements. Like a Liger! I have moved from a fiction focus to hybrid. This means I can now also write creative nonfiction and poetry. Make sure to check out Greenberg! On work days I read for four hours and write for four hours. Also, you must check out this short podcast skit that Kaisha referenced in our show today: Shoot, Whiskey, Older Women. The key to getting writing/reading time–act like a crazy person when you don’t get it!! If nothing else comes of it, the act of creation is a beautiful thing and something to be cherished. Nothing you have done is a waste of time, even if you never get published. Die Hard is essential to your mental health…wait, what?! Knock out a big book? Last year it was War and Peace. Attempt to read the Booker Longlist?–The Booker is awesome—Kaisha wants to be a Booker Prize judge (reading 100 books in 7 months–she’s geeking out). This prize rewards books that have the depth and complexity to sustain so many readings. The judges are looking for a book that reveals more on subsequent readings. To read the entire longlist, Kaisha will have to read 13 books between July 27th and September 13th. Leaves Kaisha a chunk of time before the longlist is announced. How would she tackle this first part of the summer? Fluffing TBR shelves and book droppings. Kaisha doesn’t keep all her books, gasp! The only two books Kelsey got rid of caused intense rage. It was best for everybody if they left the house to find their forever homes. Bookmarking? Yes? No? Do you write in your books? Book voodoo–if you give away a book that you have marked in, can it be used to cast spells against you? The mark of the Kaisha. Has Kaisha ever made it through an entire longlist? It sounds pretty cool and Kaisha did eventually read it. Here’s more info on the book and Kingsnorth, who is a great case study in never giving up as a writer. She’s read some great books through the longlist. The competition has a wide breadth of book types, even some speculative fiction. Nothing Epic though, and no literary fantasy so far. My theory is that a lot of literary speculative fiction is too short for the competition, or too long. I have encountered some literary fantasy, but it has been in short story form. Kelly Link is an excellent example of this. I have her book, Pretty Monsters, sitting on my TBR shelf. One speculative piece that was a novella did make the Booker longlist. Kaisha says that it was one of the best reading experiences she has had in awhile. She also warns us not to google it. Spoilers will ruin the experience. Side note: it took me a bit of digging to figure this one out. I would have asked Kaisha, but at two in the morning, it would probably have been rude to text her. Kaisha got the title right, but the author name wrong.–unless I misheard her, which is a possibility (Too many days on the firearms range as a cop has left me a tad hard of hearing). I thought she said Weir. What did you all think? Here’s a little bit more on Menmuir. I am excited to get to know this author better! Just when you thought we were finished with this podcast, we went off on another Tangent: sleep and Proust. Love doesn’t even begin to describe how we feel about In Search of Lost Time. (Just so you know, I linked to my copy of Swann’s Way–the first volume in the series–so that we can be book twins if you decide to buy a copy). We know that Proust may not be everyone’s cup of tea, but we think he’s fantastic. Just don’t read him like you would Dean Koontz. Read him like you would eat an ice cream sundae or enjoy a rainstorm while cozied next to the fire. For a long time I used to go to bed early. Sometimes, when I had put out my candle, my eyes would close so quickly that I had not even time to say “I’m going to sleep.” And half an hour later the thought that it was time to go to sleep would awaken me; I would try to put away the book which, I imagined, was still in my hands, and to blow out the light; I had been thinking all the time, while I was asleep, of what I had just been reading, but my thoughts had run into a channel of their own, until I myself seemed actually to have become the subject of my book: a church, a quartet, the rivalry between François I and Charles V. This impression would persist for some moments after I was awake; it did not disturb my mind, but it lay like scales upon my eyes and prevented them from registering the fact that the candle was no longer burning. Then it would begin to seem unintelligible, as the thoughts of a former existence must be to a reincarnate spirit; the subject of my book would separate itself from me, leaving me free to choose whether I would form part of it or no; and at the same time my sight would return and I would be astonished to find myself in a state of darkness, pleasant and restful enough for the eyes, and even more, perhaps, for my mind, to which it appeared incomprehensible, without a cause, a matter dark indeed. I would ask myself what o’clock it could be; I could hear the whistling of trains, which, now nearer and now farther off, punctuating the distance like the note of a bird in a forest, shewed me in perspective the deserted countryside through which a traveller would be hurrying towards the nearest station: the path that he followed being fixed for ever in his memory by the general excitement due to being in a strange place, to doing unusual things, to the last words of conversation, to farewells exchanged beneath an unfamiliar lamp which echoed still in his ears amid the silence of the night; and to the delightful prospect of being once again at home. Additionally, check out the graphic novel version, if you are as much a Proust nerd as us! I bought this for Kaisha and myself last Christmas. What? Don’t you buy yourself Christmas presents? No? Oh, well, ahem, my husband bought if for me under my direction, then. Don’t forget to enter our giveaway for July. This month we will be giving away The Queen of Blood by Sarah Beth Durst and some adorable succulent bookmarks! To enter, rate us and leave a review on Itunes, and then go to the giveaway tab on our website and let us know how to get in touch with you if you win. A winner will be drawn at random on July first. Thanks for listening to Read Write Repeat! Talk with you next time! Featured photo by Aaron Burden on Unsplash; design by me!
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Categories.Functor where open import Cubical.Categories.Functor.Base public open import Cubical.Categories.Functor.Properties public open import Cubical.Categories.Functor.Compose public
It is a requirement that all participants who wish to train in Basic Counselling skills have first completed the LifeLine/ChildLine Personal Growth Course and been selected by the facilitators to as suitable candidates to be trained as counsellors. In this module the emphasis is on skills based training. The inward focus on the self in Personal Growth changes to the outward focus on the other. The theoretical underpinning of LifeLine’s approach to counselling is based on the Rogerian, non-directive, client-centred involvement, interwoven with problem management methods in the helping process. Our philosophy revolves around articulating feelings and how they affect the way people behave and handle their problems. We try to help by caring, listening and sharing; by trying to be “good news” to people at the point of their pain. We respect the dignity of the client, pledge absolute confidentiality and encourage the client’s self-determination. The Trainees are introduced to the core skills in counselling and they repeatedly role-play these various skills until the required standard is reached. A range of issue based counselling such as HIV and AIDS, child abuse, domestic violence etc. also feature strongly here. The third and final stage of training is geared completely to the needs of the individual trainee. Each potential volunteer participates in more role-plays, which allow for constructive feedback. Each probationer must also present individual research to demonstrate understanding of the core counselling skills as well as knowledge on other onward referral organisations. Only when all three stages of training have been successfully completed is it possible for a probationer to become a LifeLine approved counsellor. A number of the tertiary institutions in Namibia (including UNAM and IUM) encourage their psychology, social work and HIV management students to enrol in this course to acquire practical or broader skills to add to and enrich their course work.
module Postgres.Data import public Postgres.Data.Conn import public Postgres.Data.ConnectionStatus import public Postgres.Data.ResultStatus import public Postgres.Data.PostgresType
The coefficients of the sum of two polynomials are the sum of the coefficients of the two polynomials.
theory T92 imports Main begin lemma "( (\<forall> x::nat. \<forall> y::nat. meet(x, y) = meet(y, x)) & (\<forall> x::nat. \<forall> y::nat. join(x, y) = join(y, x)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, meet(y, z)) = meet(meet(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(x, join(y, z)) = join(join(x, y), z)) & (\<forall> x::nat. \<forall> y::nat. meet(x, join(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. join(x, meet(x, y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, join(y, z)) = join(mult(x, y), mult(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(join(x, y), z) = join(mult(x, z), mult(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(x, over(join(mult(x, y), z), y)) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. meet(y, undr(x, join(mult(x, y), z))) = y) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(over(x, y), y), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. join(mult(y, undr(y, x)), x) = x) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(x, meet(y, z)) = meet(mult(x, y), mult(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. mult(meet(x, y), z) = meet(mult(x, z), mult(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(join(x, y), z) = join(over(x, z), over(y, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. over(x, meet(y, z)) = join(over(x, y), over(x, z))) & (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(meet(x, y), z) = join(undr(x, z), undr(y, z))) & (\<forall> x::nat. \<forall> y::nat. invo(join(x, y)) = meet(invo(x), invo(y))) & (\<forall> x::nat. \<forall> y::nat. invo(meet(x, y)) = join(invo(x), invo(y))) & (\<forall> x::nat. invo(invo(x)) = x) ) \<longrightarrow> (\<forall> x::nat. \<forall> y::nat. \<forall> z::nat. undr(x, join(y, z)) = join(undr(x, y), undr(x, z))) " nitpick[card nat=4,timeout=86400] oops end
module rrsw_cld use parkind, only : im => kind_im, rb => kind_rb implicit none save !------------------------------------------------------------------ ! rrtmg_sw cloud property coefficients ! ! Initial: J.-J. Morcrette, ECMWF, oct1999 ! Revised: J. Delamere/MJIacono, AER, aug2005 ! Revised: MJIacono, AER, nov2005 ! Revised: MJIacono, AER, jul2006 ! Revised: MJIacono, AER, aug2008 ! Revised: MJIacono, AER, dec2013: Updated xxxliq1 look-up tables !------------------------------------------------------------------ ! ! name type purpose ! ----- : ---- : ---------------------------------------------- ! xxxliq1 : real : optical properties (extinction coefficient, single ! scattering albedo, assymetry factor) based on ! Hu & Stamnes, j. clim., 6, 728-742, 1993. Derived ! from Mie scattering calculations at higher spectral ! resolution than Hu & Stamnes. Used in CIRC (Continuous ! Intercomparison of Radiation Codes) project. ! xxxice2 : real : optical properties (extinction coefficient, single ! scattering albedo, assymetry factor) from streamer v3.0, ! Key, streamer user's guide, cooperative institude ! for meteorological studies, 95 pp., 2001. ! xxxice3 : real : optical properties (extinction coefficient, single ! scattering albedo, assymetry factor) from ! Fu, j. clim., 9, 1996. ! xbari : real : optical property coefficients for five spectral ! intervals (2857-4000, 4000-5263, 5263-7692, 7692-14285, ! and 14285-40000 wavenumbers) following ! Ebert and Curry, jgr, 97, 3831-3836, 1992. !------------------------------------------------------------------ real(kind=rb) :: extliq1(58,16:29), ssaliq1(58,16:29), asyliq1(58,16:29) real(kind=rb) :: extice2(43,16:29), ssaice2(43,16:29), asyice2(43,16:29) real(kind=rb) :: extice3(46,16:29), ssaice3(46,16:29), asyice3(46,16:29) real(kind=rb) :: fdlice3(46,16:29) real(kind=rb) :: abari(5),bbari(5),cbari(5),dbari(5),ebari(5),fbari(5) end module rrsw_cld
@timed_testset "data_constructors" begin @testset "data_response" begin @testset "NamedTuples" begin expected = [2, 3, 4, 5] f = @formula y_int ~ 0 + x_float + x_cat y = T.data_response(f, nt_str) @test y == expected y = T.data_response(f, nt_cat) @test y == expected f = @formula y_int ~ 1 + x_float + x_cat y = T.data_response(f, nt_str) @test y == expected y = T.data_response(f, nt_cat) @test y == expected expected = [2.3, 3.4, 4.5, 5.4] f = @formula y_float ~ 0 + x_float + x_cat y = T.data_response(f, nt_str) @test y == expected y = T.data_response(f, nt_cat) @test y == expected f = @formula y_float ~ 1 + x_float + x_cat @test y == expected y = T.data_response(f, nt_str) @test y == expected y = T.data_response(f, nt_cat) @test y == expected end @testset "DataFrames" begin expected = [2, 3, 4, 5] f = @formula y_int ~ 0 + x_float + x_cat y = T.data_response(f, df_str) @test y == expected y = T.data_response(f, df_cat) @test y == expected f = @formula y_int ~ 1 + x_float + x_cat y = T.data_response(f, df_str) @test y == expected y = T.data_response(f, df_cat) @test y == expected expected = [2.3, 3.4, 4.5, 5.4] f = @formula y_float ~ 0 + x_float + x_cat y = T.data_response(f, df_str) @test y == expected y = T.data_response(f, df_cat) @test y == expected f = @formula y_float ~ 1 + x_float + x_cat y = T.data_response(f, df_str) @test y == expected y = T.data_response(f, df_cat) @test y == expected end end @testset "data_fixed_effects" begin @testset "NamedTuples" begin expected = [ 1.1 0.0 0.0 0.0 2.3 1.0 0.0 0.0 3.14 0.0 1.0 0.0 3.65 0.0 0.0 1.0 ] f = @formula y_int ~ 0 + x_float + x_cat X = T.data_fixed_effects(f, nt_str) @test X == expected f = @formula y_int ~ 1 + x_float + x_cat X = T.data_fixed_effects(f, nt_str) @test X == expected f = @formula y_float ~ 0 + x_float + x_cat X = T.data_fixed_effects(f, nt_str) @test X == expected f = @formula y_float ~ 1 + x_float + x_cat X = T.data_fixed_effects(f, nt_str) @test X == expected f = @formula y_int ~ 0 + x_float + x_cat_ordered X = T.data_fixed_effects(f, nt_cat) @test X == expected f = @formula y_int ~ 1 + x_float + x_cat_ordered X = T.data_fixed_effects(f, nt_cat) @test X == expected f = @formula y_float ~ 0 + x_float + x_cat_ordered X = T.data_fixed_effects(f, nt_cat) @test X == expected f = @formula y_float ~ 1 + x_float + x_cat_ordered X = T.data_fixed_effects(f, nt_cat) @test X == expected # Interactions expected = [ 1.0 0.0 0.0 0.0 0.0 0.0 0.0 2.0 1.0 0.0 0.0 2.0 0.0 0.0 3.0 0.0 1.0 0.0 0.0 3.0 0.0 4.0 0.0 0.0 1.0 0.0 0.0 4.0 ] f = @formula y_float ~ 0 + x_int * x_cat X = T.data_fixed_effects(f, nt_str) @test X == expected f = @formula y_float ~ 1 + x_int * x_cat X = T.data_fixed_effects(f, nt_str) @test X == expected f = @formula y_float ~ 0 + x_int * x_cat X = T.data_fixed_effects(f, nt_cat) @test X == expected f = @formula y_float ~ 1 + x_int * x_cat X = T.data_fixed_effects(f, nt_cat) @test X == expected f = @formula y_float ~ 0 + x_int * x_cat_ordered X = T.data_fixed_effects(f, nt_cat) @test X == expected f = @formula y_float ~ 1 + x_int * x_cat_ordered X = T.data_fixed_effects(f, nt_cat) @test X == expected # Interactions coming first expected = [ 1.0 0.0 0.0 0.0 1.1 0.0 0.0 0.0 2.0 1.0 0.0 0.0 2.3 2.0 0.0 0.0 3.0 0.0 1.0 0.0 3.14 0.0 3.0 0.0 4.0 0.0 0.0 1.0 3.65 0.0 0.0 4.0 ] f = @formula y_float ~ 1 + x_int * x_cat + x_float X = T.data_fixed_effects(f, nt_str) @test X == expected end @testset "DataFrames" begin expected = [ 1.1 0.0 0.0 0.0 2.3 1.0 0.0 0.0 3.14 0.0 1.0 0.0 3.65 0.0 0.0 1.0 ] f = @formula(y_int ~ 0 + x_float + x_cat) X = T.data_fixed_effects(f, df_str) @test X == expected f = @formula(y_int ~ 1 + x_float + x_cat) X = T.data_fixed_effects(f, df_str) @test X == expected f = @formula(y_float ~ 0 + x_float + x_cat) X = T.data_fixed_effects(f, df_str) @test X == expected f = @formula(y_float ~ 1 + x_float + x_cat) X = T.data_fixed_effects(f, df_str) @test X == expected f = @formula(y_int ~ 0 + x_float + x_cat_ordered) X = T.data_fixed_effects(f, df_cat) @test X == expected f = @formula(y_int ~ 1 + x_float + x_cat_ordered) X = T.data_fixed_effects(f, df_cat) @test X == expected f = @formula(y_float ~ 0 + x_float + x_cat_ordered) X = T.data_fixed_effects(f, df_cat) @test X == expected f = @formula(y_float ~ 1 + x_float + x_cat_ordered) X = T.data_fixed_effects(f, df_cat) @test X == expected # Interactions expected = [ 1.0 0.0 0.0 0.0 0.0 0.0 0.0 2.0 1.0 0.0 0.0 2.0 0.0 0.0 3.0 0.0 1.0 0.0 0.0 3.0 0.0 4.0 0.0 0.0 1.0 0.0 0.0 4.0 ] f = @formula y_float ~ 0 + x_int * x_cat X = T.data_fixed_effects(f, df_str) @test X == expected f = @formula y_float ~ 1 + x_int * x_cat X = T.data_fixed_effects(f, df_str) @test X == expected f = @formula y_float ~ 0 + x_int * x_cat X = T.data_fixed_effects(f, df_cat) @test X == expected f = @formula y_float ~ 1 + x_int * x_cat X = T.data_fixed_effects(f, df_cat) @test X == expected f = @formula y_float ~ 0 + x_int * x_cat_ordered X = T.data_fixed_effects(f, df_cat) @test X == expected f = @formula y_float ~ 1 + x_int * x_cat_ordered X = T.data_fixed_effects(f, df_cat) @test X == expected # Interactions coming first expected = [ 1.0 0.0 0.0 0.0 1.1 0.0 0.0 0.0 2.0 1.0 0.0 0.0 2.3 2.0 0.0 0.0 3.0 0.0 1.0 0.0 3.14 0.0 3.0 0.0 4.0 0.0 0.0 1.0 3.65 0.0 0.0 4.0 ] f = @formula y_float ~ 1 + x_int * x_cat + x_float X = T.data_fixed_effects(f, df_str) @test X == expected end end @testset "data_random_effects" begin expected = nothing f = @formula y_float ~ 1 + x_int * x_cat + x_float Z = T.data_random_effects(f, nt_str) @test Z == expected Z = T.data_random_effects(f, nt_cat) @test Z == expected Z = T.data_random_effects(f, df_str) @test Z == expected Z = T.data_random_effects(f, df_cat) @test Z == expected f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | x_cat) Z = T.data_random_effects(f, nt_str) @test Z == expected Z = T.data_random_effects(f, nt_cat) @test Z == expected Z = T.data_random_effects(f, df_str) @test Z == expected Z = T.data_random_effects(f, df_cat) @test Z == expected expected = Dict("slope_x_int" => [1.0, 2.0, 3.0, 4.0]) f = @formula y_float ~ 1 + (1 + x_int | x_cat) Z = T.data_random_effects(f, nt_str) @test Z == expected Z = T.data_random_effects(f, nt_cat) @test Z == expected Z = T.data_random_effects(f, df_str) @test Z == expected Z = T.data_random_effects(f, df_cat) @test Z == expected expected = Dict( "slope_x_float" => [1.1, 2.3, 3.14, 3.65], "slope_x_int" => [1.0, 2.0, 3.0, 4.0] ) f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) Z = T.data_random_effects(f, nt_str) @test Z == expected Z = T.data_random_effects(f, nt_cat) @test Z == expected Z = T.data_random_effects(f, df_str) @test Z == expected Z = T.data_random_effects(f, df_cat) @test Z == expected expected = Dict( "slope_x_float" => [1.1, 2.3, 3.14, 3.65], "slope_x_int" => [1.0, 2.0, 3.0, 4.0] ) f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) + (1 + x_int + x_float | group) Z = T.data_random_effects(f, nt_str) @test Z == expected Z = T.data_random_effects(f, nt_cat) @test Z == expected Z = T.data_random_effects(f, df_str) @test Z == expected Z = T.data_random_effects(f, df_cat) @test Z == expected end @testset "has_ranef" begin f = @formula y_float ~ 1 + x_int + x_cat @test T.has_ranef(f) == false f = @formula y_float ~ 1 + x_int + (1 | x_cat) @test T.has_ranef(f) == true f = @formula y_float ~ 0 + x_int + x_cat @test T.has_ranef(f) == false f = @formula y_float ~ 0 + x_int + (1 | x_cat) @test T.has_ranef(f) == true f = @formula y_float ~ x_int + x_cat @test T.has_ranef(f) == false f = @formula y_float ~ x_int + (1 | x_cat) @test T.has_ranef(f) == true end @testset "ranef" begin f = @formula y_float ~ 1 + x_int + x_cat @test T.ranef(f) === nothing f = @formula y_float ~ x_int + (1 | x_cat) @test T.ranef(f) isa Tuple{T.RandomEffectsTerm} f = @formula y_float ~ x_int + (1 + x_float | x_cat) @test T.ranef(f) isa Tuple{T.RandomEffectsTerm} end @testset "n_ranef" begin f = @formula y_float ~ 1 + x_int + x_cat @test T.n_ranef(f) == 0 f = @formula y_float ~ x_int + (1 | x_cat) @test T.n_ranef(f) == 1 f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | x_cat) @test T.n_ranef(f) == 1 f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | group) @test T.n_ranef(f) == 2 f = @formula y_float ~ x_int + (1 + x_float | x_cat) @test T.n_ranef(f) == 2 f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) @test T.n_ranef(f) == 3 f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) + (1 + x_int + x_float | group) @test T.n_ranef(f) == 6 end @testset "intercept_per_ranef" begin f = @formula y_float ~ 1 + x_int + xcat + (1 | x_cat) @test T.intercept_per_ranef(T.ranef(f)) == ["x_cat"] f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) @test T.intercept_per_ranef(T.ranef(f)) == ["x_cat"] f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | x_cat) @test T.intercept_per_ranef(T.ranef(f)) == ["x_cat"] f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | group) @test T.intercept_per_ranef(T.ranef(f)) == ["x_cat", "group"] f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) @test T.intercept_per_ranef(T.ranef(f)) == ["x_cat"] f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) + (1 + x_int + x_float | group) @test T.intercept_per_ranef(T.ranef(f)) == ["x_cat", "group"] end @testset "slope_per_ranef" begin f = @formula y_float ~ 1 + x_int + xcat + (1 | x_cat) @test T.slope_per_ranef(T.ranef(f)) == T.SlopePerRanEf() f = @formula y_float ~ 2 + (1 + x_int + x_float | x_cat) @test T.slope_per_ranef(T.ranef(f)) == T.SlopePerRanEf(Dict("x_cat" => ["x_int", "x_float"])) f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | x_cat) @test T.slope_per_ranef(T.ranef(f)) == T.SlopePerRanEf() f = @formula y_float ~ 1 + x_float + (1 | x_cat) + (1 | group) @test T.slope_per_ranef(T.ranef(f)) == T.SlopePerRanEf() f = @formula y_float ~ 1 + (1 + x_int + x_float | x_cat) + (1 + x_int + x_float | group) @test T.slope_per_ranef(T.ranef(f)) == T.SlopePerRanEf( Dict("x_cat" => ["x_int", "x_float"], "group" => ["x_int", "x_float"]) ) end @testset "get_idx" begin expected = ([1, 2, 3, 4], Dict(1.1 => 1, 3.65 => 4, 2.3 => 2, 3.14 => 3)) @test T.get_idx(T.term("x_float"), nt_str) == expected @test T.get_idx(T.term("x_float"), df_str) == expected @test T.get_idx(T.term("x_float"), nt_cat) == expected @test T.get_idx(T.term("x_float"), df_cat) == expected expected = ([1, 2, 3, 4], Dict("4" => 4, "1" => 1, "2" => 2, "3" => 3)) @test T.get_idx(T.term("x_cat"), nt_str) == expected @test T.get_idx(T.term("x_cat"), df_str) == expected cv = categorical([1, 2, 3, 4]) expected = ( [1, 2, 3, 4], Dict( CategoricalValue(4, cv) => 4, CategoricalValue(2, cv) => 2, CategoricalValue(3, cv) => 3, CategoricalValue(1, cv) => 1, ), ) @test T.get_idx(T.term("x_cat"), nt_cat) == expected @test T.get_idx(T.term("x_cat"), df_cat) == expected end @testset "get_var" begin expected = [1.1, 2.3, 3.14, 3.65] @test T.get_var(T.term("x_float"), nt_str) == expected @test T.get_var(T.term("x_float"), df_str) == expected expected = [1.1, 2.3, 3.14, 3.65] @test T.get_var(T.term("x_float"), nt_cat) == expected @test T.get_var(T.term("x_float"), df_cat) == expected expected = ["1", "2", "3", "4"] @test T.get_var(T.term("x_cat"), nt_str) == expected @test T.get_var(T.term("x_cat"), df_str) == expected expected = categorical([1, 2, 3, 4]) @test T.get_var(T.term("x_cat"), nt_cat) == expected @test T.get_var(T.term("x_cat"), df_cat) == expected end end
[STATEMENT] lemma toplevel_inters_Full: "\<lbrakk>toplevel_inters r = {Full}; wf n r\<rbrakk> \<Longrightarrow> lang n r = lists (\<Sigma> n)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>toplevel_inters r = {Full}; local.wf n r\<rbrakk> \<Longrightarrow> lang n r = lists (\<Sigma> n) [PROOF STEP] by (metis antisym lang.simps(2) subsetI toplevel_inters.simps(3) toplevel_inters_in_lang)
theory Riscv_duopod_lemmas imports Sail.Sail2_values_lemmas Sail.Sail2_state_lemmas Riscv_duopod begin abbreviation liftS ("\<lbrakk>_\<rbrakk>\<^sub>S") where "liftS \<equiv> liftState (get_regval, set_regval)" lemmas register_defs = get_regval_def set_regval_def Xs_ref_def nextPC_ref_def PC_ref_def lemma regval_vector_64_dec_bit[simp]: "vector_64_dec_bit_of_regval (regval_of_vector_64_dec_bit v) = Some v" by (auto simp: regval_of_vector_64_dec_bit_def) lemma vector_of_rv_rv_of_vector[simp]: assumes "\<And>v. of_rv (rv_of v) = Some v" shows "vector_of_regval of_rv (regval_of_vector rv_of len is_inc v) = Some v" proof - from assms have "of_rv \<circ> rv_of = Some" by auto then show ?thesis by (auto simp: vector_of_regval_def regval_of_vector_def) qed lemma option_of_rv_rv_of_option[simp]: assumes "\<And>v. of_rv (rv_of v) = Some v" shows "option_of_regval of_rv (regval_of_option rv_of v) = Some v" using assms by (cases v) (auto simp: option_of_regval_def regval_of_option_def) lemma list_of_rv_rv_of_list[simp]: assumes "\<And>v. of_rv (rv_of v) = Some v" shows "list_of_regval of_rv (regval_of_list rv_of v) = Some v" proof - from assms have "of_rv \<circ> rv_of = Some" by auto with assms show ?thesis by (induction v) (auto simp: list_of_regval_def regval_of_list_def) qed lemma liftS_read_reg_Xs[liftState_simp]: "\<lbrakk>read_reg Xs_ref\<rbrakk>\<^sub>S = readS (Xs \<circ> regstate)" by (auto simp: liftState_read_reg_readS register_defs) lemma liftS_write_reg_Xs[liftState_simp]: "\<lbrakk>write_reg Xs_ref v\<rbrakk>\<^sub>S = updateS (regstate_update (Xs_update (\<lambda>_. v)))" by (auto simp: liftState_write_reg_updateS register_defs) lemma liftS_read_reg_nextPC[liftState_simp]: "\<lbrakk>read_reg nextPC_ref\<rbrakk>\<^sub>S = readS (nextPC \<circ> regstate)" by (auto simp: liftState_read_reg_readS register_defs) lemma liftS_write_reg_nextPC[liftState_simp]: "\<lbrakk>write_reg nextPC_ref v\<rbrakk>\<^sub>S = updateS (regstate_update (nextPC_update (\<lambda>_. v)))" by (auto simp: liftState_write_reg_updateS register_defs) lemma liftS_read_reg_PC[liftState_simp]: "\<lbrakk>read_reg PC_ref\<rbrakk>\<^sub>S = readS (PC \<circ> regstate)" by (auto simp: liftState_read_reg_readS register_defs) lemma liftS_write_reg_PC[liftState_simp]: "\<lbrakk>write_reg PC_ref v\<rbrakk>\<^sub>S = updateS (regstate_update (PC_update (\<lambda>_. v)))" by (auto simp: liftState_write_reg_updateS register_defs) end
-- Occurs when different mixfix patterns use similar names. module Issue147b where data X : Set where f : X -> X f_ : X -> X x : X bad : X -> X bad (f x) = x bad _ = x
(** The identity pseudo functor on a bicategory. Authors: Dan Frumin, Niels van der Weide Ported from: https://github.com/nmvdw/groupoids *) Require Import UniMath.Foundations.All. Require Import UniMath.MoreFoundations.All. Require Import UniMath.CategoryTheory.Core.Categories. Require Import UniMath.CategoryTheory.Core.Functors. Require Import UniMath.CategoryTheory.PrecategoryBinProduct. Require Import UniMath.Bicategories.Core.Bicat. Import Bicat.Notations. Require Import UniMath.Bicategories.Core.Invertible_2cells. Require Import UniMath.Bicategories.Core.BicategoryLaws. Require Import UniMath.Bicategories.PseudoFunctors.Display.PseudoFunctorBicat. Require Import UniMath.Bicategories.PseudoFunctors.PseudoFunctor. Import PseudoFunctor.Notations. Section IdentityFunctor. Variable (C : bicat). Definition id_functor_d : psfunctor_data C C. Proof. use make_psfunctor_data. - exact (λ x, x). - exact (λ _ _ x, x). - exact (λ _ _ _ _ x, x). - exact (λ x, id2 _). - exact (λ _ _ _ _ _, id2 _). Defined. Definition id_functor_laws : psfunctor_laws id_functor_d. Proof. repeat split. - intros a b f ; cbn in *. rewrite id2_rwhisker. rewrite !id2_left. reflexivity. - intros a b f ; cbn in *. rewrite lwhisker_id2. rewrite !id2_left. reflexivity. - intros a b c d f g h ; cbn in *. rewrite lwhisker_id2, id2_rwhisker. rewrite !id2_left, !id2_right. reflexivity. - intros a b c f g h α ; cbn in *. rewrite !id2_left, !id2_right. reflexivity. - intros a b c f g h α ; cbn in *. rewrite !id2_left, !id2_right. reflexivity. Qed. Definition id_psfunctor : psfunctor C C. Proof. use make_psfunctor. - exact id_functor_d. - exact id_functor_laws. - split ; cbn ; intros ; is_iso. Defined. End IdentityFunctor.
// vim: awa:sts=4:ts=4:sw=4:et:cin:fdm=manual:tw=120:ft=cpp #include "common/include/algorithm.h" #include "common/include/information_definitions.h" #include "common/include/information_objects.h" #include "common/include/logging.h" #include "lib/include/computer_information.h" #include "lib/include/information_provider.h" #include <algorithm> #include <iterator> #include <thread> #include <boost/asio.hpp> #include <fmt/format.h> using namespace std; using fmt::format; using mmotd::algorithms::transform_if; namespace { using InformationProviderCreators = vector<mmotd::information::InformationProviderCreator>; InformationProviderCreators &GetInformationProviderCreators() { static InformationProviderCreators computer_information_provider_creators; return computer_information_provider_creators; } } // namespace namespace mmotd::information { ComputerInformation::ComputerInformation() : information_providers_(), information_cache_() { SetInformationProviders(); } ComputerInformation &ComputerInformation::Instance() { static auto computer_information = ComputerInformation{}; return computer_information; } void ComputerInformation::SetInformationProviders() { auto &creators = GetInformationProviderCreators(); information_providers_.resize(creators.size()); transform(begin(creators), end(creators), begin(information_providers_), [](auto &creator) { return creator(); }); LOG_INFO("created {} information providers", information_providers_.size()); } bool RegisterInformationProvider(InformationProviderCreator creator) { auto &information_provider_creators = GetInformationProviderCreators(); information_provider_creators.emplace_back(creator); return true; } optional<Information> ComputerInformation::FindInformation(InformationId id) const { if (!IsInformationCached()) { CacheAllInformation(); } auto i = find_if(begin(information_cache_), end(information_cache_), [id](const Information &info) { return id == info.GetId(); }); return i == end(information_cache_) ? nullopt : make_optional(*i); } const Informations &ComputerInformation::GetAllInformation() const { if (!IsInformationCached()) { CacheAllInformation(); } return information_cache_; } bool ComputerInformation::IsInformationCached() const { return !information_cache_.empty(); } void ComputerInformation::CacheAllInformationAsync() const { auto thread_pool = boost::asio::thread_pool{std::thread::hardware_concurrency()}; for (auto &&provider : information_providers_) { boost::asio::post(thread_pool, [&provider]() { provider->LookupInformation(); }); } thread_pool.join(); } void ComputerInformation::CacheAllInformationSerial() const { for (auto &&provider : information_providers_) { provider->LookupInformation(); } } void ComputerInformation::CacheAllInformation() const { #if defined(MMOTD_ASYNC_DISABLED) CacheAllInformationSerial(); #else CacheAllInformationAsync(); #endif for (const auto &provider : information_providers_) { const auto &informations = provider->GetInformations(); copy(begin(informations), end(informations), back_inserter(information_cache_)); } } } // namespace mmotd::information
[STATEMENT] lemma cong_mult_poly: "[(a::'b::{field_gcd} poly) = b] (mod m) \<Longrightarrow> [c = d] (mod m) \<Longrightarrow> [a * c = b * d] (mod m)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>[a = b] (mod m); [c = d] (mod m)\<rbrakk> \<Longrightarrow> [a * c = b * d] (mod m) [PROOF STEP] by (fact cong_mult)
State Before: 𝕜 : Type u_1 inst✝⁸ : NontriviallyNormedField 𝕜 E : Type u_2 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : NormedSpace 𝕜 E F : Type u_3 inst✝⁵ : NormedAddCommGroup F inst✝⁴ : NormedSpace 𝕜 F G : Type ?u.38206 inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace 𝕜 G G' : Type ?u.38301 inst✝¹ : NormedAddCommGroup G' inst✝ : NormedSpace 𝕜 G' f f₀ f₁ g : E → F f' f₀' f₁' g' e : E →L[𝕜] F x : E s t : Set E L L₁ L₂ : Filter E hxs : UniqueDiffWithinAt 𝕜 s x ⊢ fderivWithin 𝕜 (↑e) s x = e State After: 𝕜 : Type u_1 inst✝⁸ : NontriviallyNormedField 𝕜 E : Type u_2 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : NormedSpace 𝕜 E F : Type u_3 inst✝⁵ : NormedAddCommGroup F inst✝⁴ : NormedSpace 𝕜 F G : Type ?u.38206 inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace 𝕜 G G' : Type ?u.38301 inst✝¹ : NormedAddCommGroup G' inst✝ : NormedSpace 𝕜 G' f f₀ f₁ g : E → F f' f₀' f₁' g' e : E →L[𝕜] F x : E s t : Set E L L₁ L₂ : Filter E hxs : UniqueDiffWithinAt 𝕜 s x ⊢ fderiv 𝕜 (↑e) x = e Tactic: rw [DifferentiableAt.fderivWithin e.differentiableAt hxs] State Before: 𝕜 : Type u_1 inst✝⁸ : NontriviallyNormedField 𝕜 E : Type u_2 inst✝⁷ : NormedAddCommGroup E inst✝⁶ : NormedSpace 𝕜 E F : Type u_3 inst✝⁵ : NormedAddCommGroup F inst✝⁴ : NormedSpace 𝕜 F G : Type ?u.38206 inst✝³ : NormedAddCommGroup G inst✝² : NormedSpace 𝕜 G G' : Type ?u.38301 inst✝¹ : NormedAddCommGroup G' inst✝ : NormedSpace 𝕜 G' f f₀ f₁ g : E → F f' f₀' f₁' g' e : E →L[𝕜] F x : E s t : Set E L L₁ L₂ : Filter E hxs : UniqueDiffWithinAt 𝕜 s x ⊢ fderiv 𝕜 (↑e) x = e State After: no goals Tactic: exact e.fderiv
{-# LANGUAGE CPP #-} {-# LANGUAGE DerivingVia #-} {-# OPTIONS_GHC -fno-warn-deprecations #-} -- | -- Module : Data.Functor.Invariant.Inplicative -- Copyright : (c) Justin Le 2021 -- License : BSD3 -- -- Maintainer : [email protected] -- Stability : experimental -- Portability : non-portable -- -- Contains the classes 'Inply' and 'Inplicative', the invariant -- counterparts to 'Apply'/'Divise' and 'Applicative'/'Divisible'. -- -- @since 0.4.0.0 module Data.Functor.Invariant.Inplicative ( -- * Typeclass Inply(..) , Inplicative(..) -- * Deriving , WrappedApplicativeOnly(..) , WrappedDivisibleOnly(..) -- * Invariant 'Day' , runDay , dather , runDayApply , runDayDivise -- * Assembling Helpers , gatheredN , gatheredNMap , gatheredN1 , gatheredN1Map , gatheredNRec , gatheredNMapRec , gatheredN1Rec , gatheredN1MapRec , gatherN , gatherN1 ) where import Control.Applicative import Control.Applicative.Backwards (Backwards(..)) import Control.Applicative.Lift (Lift(Pure, Other)) import Control.Arrow (Arrow) import Control.Monad.Trans.Cont (ContT) import Control.Monad.Trans.Error (ErrorT(..)) import Control.Monad.Trans.Except (ExceptT(..)) import Control.Monad.Trans.Identity (IdentityT(..)) import Control.Monad.Trans.List (ListT(..)) import Control.Monad.Trans.Maybe (MaybeT(..)) import Control.Monad.Trans.RWS (RWST(..)) import Control.Monad.Trans.Reader (ReaderT(..)) import Control.Monad.Trans.State (StateT) import Control.Monad.Trans.Writer (WriterT(..)) import Control.Natural import Data.Complex (Complex) import Data.Deriving import Data.Functor.Apply import Data.Functor.Bind.Class (Bind) import Data.Functor.Constant (Constant) import Data.Functor.Contravariant import Data.Functor.Contravariant.Divise import Data.Functor.Contravariant.Divisible import Data.Functor.Identity import Data.Functor.Invariant import Data.Functor.Invariant.Day import Data.Functor.Product (Product(..)) import Data.Functor.Reverse (Reverse(..)) import Data.Hashable (Hashable) import Data.Kind import Data.List.NonEmpty (NonEmpty) import Data.SOP hiding (hmap) import Data.Sequence (Seq) import Data.StateVar (SettableStateVar) import Data.Tagged (Tagged) import Data.Tree (Tree) import GHC.Generics (Generic) import qualified Control.Monad.Trans.RWS.Strict as Strict (RWST(..)) import qualified Control.Monad.Trans.State.Strict as Strict (StateT) import qualified Control.Monad.Trans.Writer.Strict as Strict (WriterT(..)) import qualified Data.HashMap.Lazy as HM import qualified Data.IntMap as IM import qualified Data.Map as M import qualified Data.Monoid as Monoid import qualified Data.Semigroup as Semigroup import qualified Data.Sequence.NonEmpty as NESeq import qualified Data.Vinyl as V import qualified Data.Vinyl.Curry as V import qualified Data.Vinyl.Functor as V import qualified GHC.Generics as Generics -- | The invariant counterpart of 'Apply' and 'Divise'. -- -- Conceptually you can think of 'Apply' as, given a way to "combine" @a@ and -- @b@ to @c@, lets you merge @f a@ (producer of @a@) and @f b@ (producer -- of @b@) into a @f c@ (producer of @c@). 'Divise' can be thought of as, -- given a way to "split" a @c@ into an @a@ and a @b@, lets you merge @f -- a@ (consumer of @a@) and @f b@ (consumder of @b@) into a @f c@ (consumer -- of @c@). -- -- 'Inply', for 'gather', requires both a combining function and -- a splitting function in order to merge @f b@ (producer and consumer of -- @b@) and @f c@ (producer and consumer of @c@) into a @f a@. You can -- think of it as, for the @f a@, it "splits" the a into @b@ and @c@ with -- the @a -> (b, c)@, feeds it to the original @f b@ and @f c@, and then -- re-combines the output back into a @a@ with the @b -> c -> a@. -- -- @since 0.4.0.0 class Invariant f => Inply f where -- | Like '<.>', '<*>', 'divise', or 'divide', but requires both -- a splitting and a recombining function. '<.>' and '<*>' require -- only a combining function, and 'divise' and 'divide' require only -- a splitting function. -- -- It is used to merge @f b@ (producer and consumer of @b@) and @f c@ -- (producer and consumer of @c@) into a @f a@. You can think of it -- as, for the @f a@, it "splits" the a into @b@ and @c@ with the @a -> -- (b, c)@, feeds it to the original @f b@ and @f c@, and then -- re-combines the output back into a @a@ with the @b -> c -> a@. -- -- An important property is that it will always use @both@ of the -- ccomponents given in order to fulfil its job. If you gather an @f -- a@ and an @f b@ into an @f c@, in order to consume/produdce the @c@, -- it will always use both the @f a@ or the @f b@ -- exactly one of -- them. -- -- @since 0.4.0.0 gather :: (b -> c -> a) -> (a -> (b, c)) -> f b -> f c -> f a gather f g x y = invmap (uncurry f) g (gathered x y) -- | A simplified version of 'gather' that combines into a tuple. You -- can then use 'invmap' to reshape it into the proper shape. -- -- @since 0.4.0.0 gathered :: f a -> f b -> f (a, b) gathered = gather (,) id {-# MINIMAL gather | gathered #-} -- | The invariant counterpart of 'Applicative' and 'Divisible'. -- -- The main important action is described in 'Inply', but this adds 'knot', -- which is the counterpart to 'pure' and 'conquer'. It's the identity to -- 'gather'; if combine two @f a@s with 'gather', and one of them is -- 'knot', it will leave the structure unchanged. -- -- Conceptually, if you think of 'gather' as "splitting and re-combining" -- along multiple forks, then 'knot' introduces a fork that is never taken. -- -- @since 0.4.0.0 class Inply f => Inplicative f where knot :: a -> f a -- | Interpret out of a contravariant 'Day' into any instance of 'Inply' by -- providing two interpreting functions. -- -- This should go in "Data.Functor.Invariant.Day", but that module is in -- a different package. -- -- @since 0.4.0.0 runDay :: Inply h => (f ~> h) -> (g ~> h) -> Day f g ~> h runDay f g (Day x y a b) = gather a b (f x) (g y) -- | Squash the two items in a 'Day' using their natural 'Inply' -- instances. -- -- This should go in "Data.Functor.Invariant.Day", but that module is in -- a different package. -- -- @since 0.4.0.0 dather :: Inply f => Day f f ~> f dather (Day x y a b) = gather a b x y -- | Ignores the contravariant part of 'gather' instance Apply f => Inply (WrappedFunctor f) where gather f _ (WrapFunctor x) (WrapFunctor y) = WrapFunctor (liftF2 f x y) gathered (WrapFunctor x) (WrapFunctor y) = WrapFunctor (liftF2 (,) x y) -- | @'knot' = 'pure'@ instance (Applicative f, Apply f) => Inplicative (WrappedFunctor f) where knot = pure -- | Ignores the covariant part of 'gather' instance Divise f => Inply (WrappedContravariant f) where gather _ g (WrapContravariant x) (WrapContravariant y) = WrapContravariant (divise g x y) gathered (WrapContravariant x) (WrapContravariant y) = WrapContravariant (divised x y) -- | @'knot' _ = 'conquer'@ instance (Divisible f, Divise f) => Inplicative (WrappedContravariant f) where knot _ = conquer -- | Ignores the covariant part of 'gather' instance Divise f => Inply (WrappedDivisible f) where gather _ g (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divise g x y) gathered (WrapDivisible x) (WrapDivisible y) = WrapDivisible (divised x y) -- | @'knot' _ = 'conquer'@ instance (Divisible f, Divise f) => Inplicative (WrappedDivisible f) where knot _ = conquer -- | Wrap an 'Applicative' that is not necessarily an 'Apply'. newtype WrappedApplicativeOnly f a = WrapApplicativeOnly { unwrapApplicativeOnly :: f a } deriving (Generic, Eq, Show, Ord, Read, Functor, Foldable, Traversable) deriving newtype (Applicative, Monad) deriveShow1 ''WrappedApplicativeOnly deriveRead1 ''WrappedApplicativeOnly deriveEq1 ''WrappedApplicativeOnly deriveOrd1 ''WrappedApplicativeOnly instance Invariant f => Invariant (WrappedApplicativeOnly f) where invmap f g (WrapApplicativeOnly x) = WrapApplicativeOnly (invmap f g x) instance (Applicative f, Invariant f) => Apply (WrappedApplicativeOnly f) where x <.> y = x <*> y -- | Ignores the contravariant part of 'gather' instance (Applicative f, Invariant f) => Inply (WrappedApplicativeOnly f) where gather f _ (WrapApplicativeOnly x) (WrapApplicativeOnly y) = WrapApplicativeOnly (liftA2 f x y) gathered (WrapApplicativeOnly x) (WrapApplicativeOnly y) = WrapApplicativeOnly (liftA2 (,) x y) -- | @'knot' = 'pure'@ instance (Applicative f, Invariant f) => Inplicative (WrappedApplicativeOnly f) where knot = pure -- | Wrap an 'Divisible' that is not necessarily a 'Divise'. newtype WrappedDivisibleOnly f a = WrapDivisibleOnly { unwrapDivisibleOnly :: f a } deriving (Generic, Eq, Show, Ord, Read, Functor, Foldable, Traversable) deriving newtype (Divisible, Contravariant) deriveShow1 ''WrappedDivisibleOnly deriveRead1 ''WrappedDivisibleOnly deriveEq1 ''WrappedDivisibleOnly deriveOrd1 ''WrappedDivisibleOnly instance Invariant f => Invariant (WrappedDivisibleOnly f) where invmap f g (WrapDivisibleOnly x) = WrapDivisibleOnly (invmap f g x) instance (Divisible f, Invariant f) => Divise (WrappedDivisibleOnly f) where divise g (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divide g x y) -- | Ignores the covariant part of 'gather' instance (Divisible f, Invariant f) => Inply (WrappedDivisibleOnly f) where gather _ g (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divide g x y) gathered (WrapDivisibleOnly x) (WrapDivisibleOnly y) = WrapDivisibleOnly (divided x y) -- | @'knot' _ = 'conquer'@ instance (Divisible f, Invariant f) => Inplicative (WrappedDivisibleOnly f) where knot _ = conquer funzip :: Functor f => f (a, b) -> (f a, f b) funzip x = (fmap fst x, fmap snd x) -- | @since 0.4.1.0 instance Inply f => Inply (MaybeT f) where gather f g (MaybeT x) (MaybeT y) = MaybeT $ gather (liftA2 f) (funzip . fmap g) x y -- | @since 0.4.1.0 instance Inplicative f => Inplicative (MaybeT f) where knot x = MaybeT (knot (Just x)) -- | @since 0.4.1.0 instance (Inply f, Semigroup w) => Inply (WriterT w f) where gather f g (WriterT x) (WriterT y) = WriterT $ gather (\case (a, q) -> \case (b, r) -> (f a b, q <> r)) (\case (a, s) -> case g a of (b, c) -> ((b, s), (c, s))) x y -- | @since 0.4.1.0 instance (Inplicative f, Monoid w) => Inplicative (WriterT w f) where knot x = WriterT (knot (x, mempty)) -- | @since 0.4.1.0 instance (Inply f, Semigroup w) => Inply (Strict.WriterT w f) where gather f g (Strict.WriterT x) (Strict.WriterT y) = Strict.WriterT $ gather (\(~(a, q)) (~(b, r)) -> (f a b, q <> r)) (\(~(a, s)) -> let ~(b, c) = g a in ((b, s), (c, s))) x y -- | @since 0.4.1.0 instance (Inplicative f, Monoid w) => Inplicative (Strict.WriterT w f) where knot x = Strict.WriterT (knot (x, mempty)) -- | @since 0.4.1.0 instance Inply f => Inply (ReaderT r f) where gather f g (ReaderT x) (ReaderT y) = ReaderT $ \r -> gather f g (x r) (y r) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (ReaderT r f) where knot x = ReaderT (\_ -> knot x) -- | @since 0.4.1.0 instance Inply f => Inply (ExceptT e f) where gather f g (ExceptT x) (ExceptT y) = ExceptT $ gather (liftA2 f) (funzip . fmap g) x y -- | @since 0.4.1.0 instance Inplicative f => Inplicative (ExceptT e f) where knot x = ExceptT (knot (Right x)) -- | @since 0.4.1.0 instance Inply f => Inply (ErrorT e f) where gather f g (ErrorT x) (ErrorT y) = ErrorT $ gather (liftA2 f) (funzip . fmap g) x y -- | @since 0.4.1.0 instance Inplicative f => Inplicative (ErrorT e f) where knot x = ErrorT (knot (Right x)) -- | @since 0.4.1.0 instance Inply f => Inply (ListT f) where gather f g (ListT x) (ListT y) = ListT $ gather (liftA2 f) (funzip . fmap g) x y -- | @since 0.4.1.0 instance Inplicative f => Inplicative (ListT f) where knot x = ListT (knot [x]) -- | @since 0.4.1.0 deriving via WrappedFunctor (RWST r w s m) instance (Bind m, Invariant m, Semigroup w) => Inply (RWST r w s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (RWST r w s m) instance (Monad m, Bind m, Invariant m, Monoid w) => Inplicative (RWST r w s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (Strict.RWST r w s m) instance (Bind m, Invariant m, Semigroup w) => Inply (Strict.RWST r w s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (Strict.RWST r w s m) instance (Monad m, Bind m, Invariant m, Monoid w) => Inplicative (Strict.RWST r w s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (StateT s m) instance (Bind m, Invariant m) => Inply (StateT s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (StateT s m) instance (Monad m, Bind m, Invariant m) => Inplicative (StateT s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (Strict.StateT s m) instance (Bind m, Invariant m) => Inply (Strict.StateT s m) -- | @since 0.4.1.0 deriving via WrappedFunctor (Strict.StateT s m) instance (Monad m, Bind m, Invariant m) => Inplicative (Strict.StateT s m) -- | @since 0.4.1.0 instance Inply f => Inply (Generics.M1 i t f :: Type -> Type) where gather f g (Generics.M1 x) (Generics.M1 y) = Generics.M1 (gather f g x y) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Generics.M1 i t f :: Type -> Type) where knot = Generics.M1 . knot -- | @since 0.4.1.0 instance (Inply f, Inply g) => Inply (f Generics.:*: g) where gather f g (x1 Generics.:*: y1) (x2 Generics.:*: y2) = gather f g x1 x2 Generics.:*: gather f g y1 y2 -- | @since 0.4.1.0 instance (Inplicative f, Inplicative g) => Inplicative (f Generics.:*: g) where knot x = knot x Generics.:*: knot x -- | @since 0.4.1.0 instance (Inply f, Inply g) => Inply (Product f g) where gather f g (Pair x1 y1) (Pair x2 y2) = gather f g x1 x2 `Pair` gather f g y1 y2 -- | @since 0.4.1.0 instance (Inplicative f, Inplicative g) => Inplicative (Product f g) where knot x = knot x `Pair` knot x -- | @since 0.4.1.0 instance Inply f => Inply (Generics.Rec1 f :: Type -> Type) where gather f g (Generics.Rec1 x) (Generics.Rec1 y) = Generics.Rec1 (gather f g x y) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Generics.Rec1 f :: Type -> Type) where knot = Generics.Rec1 . knot -- | @since 0.4.1.0 instance Inply f => Inply (Monoid.Alt f) where gather f g (Monoid.Alt x) (Monoid.Alt y) = Monoid.Alt (gather f g x y) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Monoid.Alt f) where knot = Monoid.Alt . knot -- | @since 0.4.1.0 instance Inply f => Inply (IdentityT f :: Type -> Type) where gather f g (IdentityT x) (IdentityT y) = IdentityT (gather f g x y) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (IdentityT f :: Type -> Type) where knot = IdentityT . knot -- | @since 0.4.1.0 instance Inply f => Inply (Reverse f :: Type -> Type) where gather f g (Reverse x) (Reverse y) = Reverse (gather f g x y) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Reverse f :: Type -> Type) where knot = Reverse . knot -- | @since 0.4.1.0 instance Inply f => Inply (Backwards f :: Type -> Type) where gather f g (Backwards x) (Backwards y) = Backwards (gather f g x y) -- | @since 0.4.1.0 instance Inplicative f => Inplicative (Backwards f :: Type -> Type) where knot = Backwards . knot -- | @since 0.4.1.0 instance Inply f => Inply (Lift f) where gather f g = \case Pure x -> \case Pure y -> Pure (f x y) Other y -> Other (invmap (f x) (snd . g) y) Other x -> \case Pure y -> Other (invmap (`f` y) (fst . g) x) Other y -> Other (gather f g x y) -- | @since 0.4.1.0 instance Inply f => Inplicative (Lift f) where knot = Pure -- | @since 0.4.1.0 deriving via WrappedApplicativeOnly (Tagged a) instance Inply (Tagged a) -- | @since 0.4.1.0 deriving via WrappedApplicativeOnly (Tagged a) instance Inplicative (Tagged a) -- | @since 0.4.1.0 deriving via WrappedFunctor Identity instance Inply Identity -- | @since 0.4.1.0 deriving via WrappedFunctor Identity instance Inplicative Identity -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Inply Proxy -- | @since 0.4.1.0 deriving via WrappedFunctor (Proxy :: Type -> Type) instance Inplicative Proxy -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Inply [] -- | @since 0.4.1.0 deriving via WrappedFunctor [] instance Inplicative [] -- | @since 0.4.1.0 deriving via WrappedFunctor ((->) r) instance Inply ((->) r) -- | @since 0.4.1.0 deriving via WrappedFunctor ((->) r) instance Inplicative ((->) r) -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Inply Maybe -- | @since 0.4.1.0 deriving via WrappedFunctor Maybe instance Inplicative Maybe -- | @since 0.4.1.0 deriving via WrappedFunctor (Either e) instance Inply (Either e) -- | @since 0.4.1.0 deriving via WrappedFunctor (Either e) instance Inplicative (Either e) -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Inply IO -- | @since 0.4.1.0 deriving via WrappedFunctor IO instance Inplicative IO -- | @since 0.4.1.0 deriving via WrappedFunctor Generics.Par1 instance Inply Generics.Par1 -- | @since 0.4.1.0 deriving via WrappedFunctor Generics.Par1 instance Inplicative Generics.Par1 -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Inply Generics.U1 -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.U1 :: Type -> Type) instance Inplicative Generics.U1 -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.K1 i c :: Type -> Type) instance Semigroup c => Inply (Generics.K1 i c) -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.K1 i c :: Type -> Type) instance Monoid c => Inplicative (Generics.K1 i c) -- | @since 0.4.1.0 deriving via WrappedFunctor Complex instance Inply Complex -- | @since 0.4.1.0 deriving via WrappedFunctor Complex instance Inplicative Complex -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Min instance Inply Semigroup.Min -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Min instance Inplicative Semigroup.Min -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Max instance Inply Semigroup.Max -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Max instance Inplicative Semigroup.Max -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.First instance Inply Semigroup.First -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.First instance Inplicative Semigroup.First -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Last instance Inply Semigroup.Last -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Last instance Inplicative Semigroup.Last -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Option instance Inply Semigroup.Option -- | @since 0.4.1.0 deriving via WrappedFunctor Semigroup.Option instance Inplicative Semigroup.Option -- | @since 0.4.1.0 deriving via WrappedFunctor ZipList instance Inply ZipList -- | @since 0.4.1.0 deriving via WrappedFunctor ZipList instance Inplicative ZipList -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Inply Monoid.First -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.First instance Inplicative Monoid.First -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Inply Monoid.Last -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Last instance Inplicative Monoid.Last -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Dual instance Inply Monoid.Dual -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Dual instance Inplicative Monoid.Dual -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Sum instance Inply Monoid.Sum -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Sum instance Inplicative Monoid.Sum -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Product instance Inply Monoid.Product -- | @since 0.4.1.0 deriving via WrappedFunctor Monoid.Product instance Inplicative Monoid.Product -- | @since 0.4.1.0 deriving via WrappedFunctor NonEmpty instance Inply NonEmpty -- | @since 0.4.1.0 deriving via WrappedFunctor NonEmpty instance Inplicative NonEmpty -- | @since 0.4.1.0 deriving via WrappedFunctor Tree instance Inply Tree -- | @since 0.4.1.0 deriving via WrappedFunctor Tree instance Inplicative Tree -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Inply Seq -- | @since 0.4.1.0 deriving via WrappedFunctor Seq instance Inplicative Seq -- | @since 0.4.1.0 deriving via WrappedFunctor NESeq.NESeq instance Inply NESeq.NESeq -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedArrow a b) instance Arrow a => Inply (WrappedArrow a b) -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedArrow a b) instance Arrow a => Inplicative (WrappedArrow a b) -- | @since 0.4.1.0 deriving via WrappedFunctor (Generics.V1 :: Type -> Type) instance Inply Generics.V1 -- | @since 0.4.1.0 deriving via WrappedFunctor IM.IntMap instance Inply IM.IntMap -- | @since 0.4.1.0 deriving via WrappedFunctor (M.Map k) instance Ord k => Inply (M.Map k) -- | @since 0.4.1.0 deriving via WrappedFunctor (HM.HashMap k) instance (Hashable k, Eq k) => Inply (HM.HashMap k) -- | @since 0.4.1.0 deriving via WrappedFunctor (Const w :: Type -> Type) instance Semigroup w => Inply (Const w) -- | @since 0.4.1.0 deriving via WrappedFunctor (Const w :: Type -> Type) instance Monoid w => Inplicative (Const w) -- | @since 0.4.1.0 deriving via WrappedFunctor (Constant w :: Type -> Type) instance Semigroup w => Inply (Constant w) -- | @since 0.4.1.0 deriving via WrappedFunctor (Constant w :: Type -> Type) instance Monoid w => Inplicative (Constant w) -- | @since 0.4.1.0 deriving via WrappedFunctor (ContT r (m :: Type -> Type)) instance Inply (ContT r m) -- | @since 0.4.1.0 deriving via WrappedFunctor (ContT r (m :: Type -> Type)) instance Inplicative (ContT r m) -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance Monad m => Inply (WrappedMonad m) -- | @since 0.4.1.0 deriving via WrappedFunctor (WrappedMonad m) instance Monad m => Inplicative (WrappedMonad m) -- | @since 0.4.1.0 deriving via WrappedFunctor ((,) w :: Type -> Type) instance Semigroup w => Inply ((,) w) -- | @since 0.4.1.0 deriving via WrappedFunctor ((,) w :: Type -> Type) instance Monoid w => Inplicative ((,) w) -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Inply SettableStateVar -- | @since 0.4.1.0 deriving via WrappedDivisible SettableStateVar instance Inplicative SettableStateVar -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Inply Predicate -- | @since 0.4.1.0 deriving via WrappedDivisible Predicate instance Inplicative Predicate -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Inply Comparison -- | @since 0.4.1.0 deriving via WrappedDivisible Comparison instance Inplicative Comparison -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Inply Equivalence -- | @since 0.4.1.0 deriving via WrappedDivisible Equivalence instance Inplicative Equivalence -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Semigroup r => Inply (Op r) -- | @since 0.4.1.0 deriving via WrappedDivisible (Op r) instance Monoid r => Inplicative (Op r) -- | Convenient wrapper to build up an 'Inplicative' instance by providing -- each component of it. This makes it much easier to build up longer -- chains because you would only need to write the splitting/joining -- functions in one place. -- -- For example, if you had a data type -- -- @ -- data MyType = MT Int Bool String -- @ -- -- and an invariant functor and 'Inplicative' instance @Prim@ -- (representing, say, a bidirectional parser, where @Prim Int@ is -- a bidirectional parser for an 'Int'@), then you could assemble -- a bidirectional parser for a @MyType@ using: -- -- @ -- invmap (\(MyType x y z) -> I x :* I y :* I z :* Nil) -- (\(I x :* I y :* I z :* Nil) -> MyType x y z) $ -- gatheredN $ intPrim -- :* boolPrim -- :* stringPrim -- :* Nil -- @ -- -- Some notes on usefulness depending on how many components you have: -- -- * If you have 0 components, use 'knot' directly. -- * If you have 1 component, you don't need anything. -- * If you have 2 components, use 'gather' directly. -- * If you have 3 or more components, these combinators may be useful; -- otherwise you'd need to manually peel off tuples one-by-one. -- -- @since 0.4.1.0 gatheredN :: Inplicative f => NP f as -> f (NP I as) gatheredN = \case Nil -> knot Nil x :* xs -> gather (\y ys -> I y :* ys) (\case I y :* ys -> (y, ys)) x (gatheredN xs) -- | Given a function to "break out" a data type into a 'NP' (tuple) and one to -- put it back together from the tuple, 'gather' all of the components -- together. -- -- For example, if you had a data type -- -- @ -- data MyType = MT Int Bool String -- @ -- -- and an invariant functor and 'Inplicative' instance @Prim@ -- (representing, say, a bidirectional parser, where @Prim Int@ is -- a bidirectional parser for an 'Int'@), then you could assemble -- a bidirectional parser for a @MyType@ using: -- -- @ -- concaMapInplicative -- (\(MyType x y z) -> I x :* I y :* I z :* Nil) -- (\(I x :* I y :* I z :* Nil) -> MyType x y z) -- $ intPrim -- :* boolPrim -- :* stringPrim -- :* Nil -- @ -- -- See notes on 'gatheredNMap' for more details and caveats. -- -- @since 0.4.1.0 gatheredNMap :: Inplicative f => (NP I as -> b) -> (b -> NP I as) -> NP f as -> f b gatheredNMap f g = invmap f g . gatheredN -- | A version of 'gatheredN' for non-empty 'NP', but only -- requiring an 'Inply' instance. -- -- @since 0.4.1.0 gatheredN1 :: Inply f => NP f (a ': as) -> f (NP I (a ': as)) gatheredN1 (x :* xs) = case xs of Nil -> invmap ((:* Nil) . I) (\case I y :* _ -> y) x _ :* _ -> gather (\y ys -> I y :* ys) (\case I y :* ys -> (y, ys)) x (gatheredN1 xs) -- | A version of 'gatheredNMap' for non-empty 'NP', but only -- requiring an 'Inply' instance. -- -- @since 0.4.1.0 gatheredN1Map :: Inplicative f => (NP I (a ': as) -> b) -> (b -> NP I (a ': as)) -> NP f (a ': as) -> f b gatheredN1Map f g = invmap f g . gatheredN1 -- | A version of 'gatheredN' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't -- require manual unwrapping/wrapping of tuple components. -- -- @since 0.4.1.0 gatheredNRec :: Inplicative f => V.Rec f as -> f (V.XRec V.Identity as) gatheredNRec = \case V.RNil -> knot V.RNil x V.:& xs -> gather (V.::&) (\case y V.::& ys -> (y, ys)) x (gatheredNRec xs) -- | A version of 'gatheredNMap' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't -- require manual unwrapping/wrapping of tuple components. -- -- @since 0.4.1.0 gatheredNMapRec :: Inplicative f => (V.XRec V.Identity as -> b) -> (b -> V.XRec V.Identity as) -> V.Rec f as -> f b gatheredNMapRec f g = invmap f g . gatheredNRec -- | Convenient wrapper to 'gather' over multiple arguments using tine -- vinyl library's multi-arity uncurrying facilities. Makes it a lot more -- convenient than using 'gather' multiple times and needing to accumulate -- intermediate types. -- -- For example, if you had a data type -- -- @ -- data MyType = MT Int Bool String -- @ -- -- and an invariant functor and 'Inplicative' instance @Prim@ -- (representing, say, a bidirectional parser, where @Prim Int@ is -- a bidirectional parser for an 'Int'@), then you could assemble -- a bidirectional parser for a @MyType@ using: -- -- @ -- 'gatherN' -- MT -- ^ curried assembling function -- (\(MT x y z) -> x ::& y ::& z ::& XRNil) -- ^ disassembling function -- (intPrim :: Prim Int) -- (boolPrim :: Prim Bool) -- (stringPrim :: Prim String) -- @ -- -- Really only useful with 3 or more arguments, since with two arguments -- this is just 'gather' (and with zero arguments, you can just use -- 'knot'). -- -- The generic type is a bit tricky to understand, but it's easier to -- understand what's going on if you instantiate with concrete types: -- -- @ -- ghci> :t gatherN @MyInplicative @'[Int, Bool, String] -- (Int -> Bool -> String -> b) -- -> (b -> XRec Identity '[Int, Bool, String]) -- -> MyInplicative Int -- -> MyInplicative Bool -- -> MyInplicative String -- -> MyInplicative b -- @ -- -- @since 0.4.1.0 gatherN :: forall f as b. (Inplicative f, V.IsoXRec V.Identity as, V.RecordCurry as) => V.Curried as b -> (b -> V.XRec V.Identity as) -> V.CurriedF f as (f b) gatherN f g = V.rcurry @as @f $ invmap (V.runcurry' f . V.fromXRec) g . gatheredNRec -- | A version of 'gatheredN1' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't -- require manual unwrapping/wrapping of components. -- -- @since 0.4.1.0 gatheredN1Rec :: Inply f => V.Rec f (a ': as) -> f (V.XRec V.Identity (a ': as)) gatheredN1Rec (x V.:& xs) = case xs of V.RNil -> invmap (V.::& V.RNil) (\case z V.::& _ -> z) x _ V.:& _ -> gather (V.::&) (\case y V.::& ys -> (y, ys)) x (gatheredN1Rec xs) -- | A version of 'gatheredNMap' using 'V.XRec' from /vinyl/ instead of -- 'NP' from /sop-core/. This can be more convenient because it doesn't -- require manual unwrapping/wrapping of tuple components. -- -- @since 0.4.1.0 gatheredN1MapRec :: Inplicative f => (V.XRec V.Identity (a ': as) -> b) -> (b -> V.XRec V.Identity (a ': as)) -> V.Rec f (a ': as) -> f b gatheredN1MapRec f g = invmap f g . gatheredN1Rec -- | 'gatherN' but with at least one argument, so can be used with any -- 'Inply'. -- -- @since 0.4.1.0 gatherN1 :: forall f a as b. (Inply f, V.IsoXRec V.Identity as, V.RecordCurry as) => V.Curried (a ': as) b -> (b -> V.XRec V.Identity (a ': as)) -> V.CurriedF f (a ': as) (f b) gatherN1 f g = V.rcurry @(a ': as) @f $ invmap (V.runcurry' f . V.fromXRec) g . gatheredN1Rec -- | Interpret out of a contravariant 'Day' into any instance of 'Apply' by -- providing two interpreting functions. -- -- In theory, this should not need to exist, since you should always be -- able to use 'runDay' because every instance of 'Apply' is also an -- instance of 'Inply'. However, this can be handy if you are using an -- instance of 'Apply' that has no 'Inply' instance. Consider also -- 'unsafeInplyCo' if you are using a specific, concrete type for @h@. runDayApply :: forall f g h. Apply h => f ~> h -> g ~> h -> Day f g ~> h runDayApply f g (Day x y j _) = liftF2 j (f x) (g y) -- | Interpret out of a contravariant 'Day' into any instance of 'Divise' -- by providing two interpreting functions. -- -- In theory, this should not need to exist, since you should always be -- able to use 'runDay' because every instance of 'Divise' is also an -- instance of 'Inply'. However, this can be handy if you are using an -- instance of 'Divise' that has no 'Inply' instance. Consider also -- 'unsafeInplyContra' if you are using a specific, concrete type for @h@. runDayDivise :: forall f g h. Divise h => f ~> h -> g ~> h -> Day f g ~> h runDayDivise f g (Day x y _ h) = divise h (f x) (g y)
Benthic in nature , the plain maskray feeds mainly on caridean shrimp and polychaete worms , and to a lesser extent on small bony fishes . It is viviparous , with females producing litters of one or two young that are nourished during gestation via histotroph ( " uterine milk " ) . This species lacks economic value but is caught incidentally in bottom trawls , which it is thought to be less able to withstand than other maskrays due to its gracile build . As it also has a limited distribution and low fecundity , the International Union for Conservation of Nature ( IUCN ) has listed it as Near Threatened .
(* (c) Copyright Microsoft Corporation and Inria. All rights reserved. *) Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div choice fintype. Require Import bigop finset fingroup morphism quotient action. (******************************************************************************) (* Partial, semidirect, central, and direct products. *) (* ++ Internal products, with A, B : {set gT}, are partial operations : *) (* partial_product A B == A * B if A is a group normalised by the group B, *) (* and the empty set otherwise. *) (* A ><| B == A * B if this is a semi-direct product (i.e., if A *) (* is normalised by B and intersects it trivially). *) (* A \* B == A * B if this is a central product ([A, B] = 1). *) (* A \x B == A * B if this is a direct product. *) (* [complements to K in G] == set of groups H s.t. K * H = G and K :&: H = 1. *) (* [splits G, over K] == [complements to K in G] is not empty. *) (* remgr A B x == the right remainder in B of x mod A, i.e., *) (* some element of (A :* x) :&: B. *) (* divgr A B x == the "quotient" in B of x by A: for all x, *) (* x = divgr A B x * remgr A B x. *) (* ++ External products : *) (* pairg1, pair1g == the isomorphisms aT1 -> aT1 * aT2, aT2 -> aT1 * aT2. *) (* (aT1 * aT2 has a direct product group structure.) *) (* sdprod_by to == the semidirect product defined by to : groupAction H K. *) (* This is a finGroupType; the actual semidirect product is *) (* the total set [set: sdprod_by to] on that type. *) (* sdpair[12] to == the isomorphisms injecting K and H into *) (* sdprod_by to = sdpair1 to @* K ><| sdpair2 to @* H. *) (* External central products (with identified centers) will be defined later *) (* in file center.v. *) (* ++ Morphisms on product groups: *) (* pprodm nAB fJ fAB == the morphism extending fA and fB on A <*> B when *) (* nAB : B \subset 'N(A), *) (* fJ : {in A & B, morph_actj fA fB}, and *) (* fAB : {in A :&: B, fA =1 fB}. *) (* sdprodm defG fJ == the morphism extending fA and fB on G, given *) (* defG : A ><| B = G and *) (* fJ : {in A & B, morph_act 'J 'J fA fB}. *) (* xsdprodm fHKact == the total morphism on sdprod_by to induced by *) (* fH : {morphism H >-> rT}, fK : {morphism K >-> rT}, *) (* with to : groupAction K H, *) (* given fHKact : morph_act to 'J fH fK. *) (* cprodm defG cAB fAB == the morphism extending fA and fB on G, when *) (* defG : A \* B = G, *) (* cAB : fB @* B \subset 'C(fB @* A), *) (* and fAB : {in A :&: B, fA =1 fB}. *) (* dprodm defG cAB == the morphism extending fA and fB on G, when *) (* defG : A \x B = G and *) (* cAB : fA @* B \subset 'C(fA @* A) *) (* mulgm (x, y) == x * y; mulgm is an isomorphism from setX A B to G *) (* iff A \x B = G . *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section Defs. Variables gT : finGroupType. Implicit Types A B C : {set gT}. Definition partial_product A B := if A == 1 then B else if B == 1 then A else if [&& group_set A, group_set B & B \subset 'N(A)] then A * B else set0. Definition semidirect_product A B := if A :&: B \subset 1%G then partial_product A B else set0. Definition central_product A B := if B \subset 'C(A) then partial_product A B else set0. Definition direct_product A B := if A :&: B \subset 1%G then central_product A B else set0. Definition complements_to_in A B := [set K : {group gT} | A :&: K == 1 & A * K == B]. Definition splits_over B A := complements_to_in A B != set0. (* Product remainder functions -- right variant only. *) Definition remgr A B x := repr (A :* x :&: B). Definition divgr A B x := x * (remgr A B x)^-1. End Defs. Arguments Scope partial_product [_ group_scope group_scope]. Arguments Scope semidirect_product [_ group_scope group_scope]. Arguments Scope central_product [_ group_scope group_scope]. Arguments Scope complements_to_in [_ group_scope group_scope]. Arguments Scope splits_over [_ group_scope group_scope]. Arguments Scope remgr [_ group_scope group_scope group_scope]. Arguments Scope divgr [_ group_scope group_scope group_scope]. Implicit Arguments partial_product []. Implicit Arguments semidirect_product []. Implicit Arguments central_product []. Implicit Arguments direct_product []. Notation pprod := (partial_product _). Notation sdprod := (semidirect_product _). Notation cprod := (central_product _). Notation dprod := (direct_product _). Notation "G ><| H" := (sdprod G H)%g (at level 40, left associativity). Notation "G \* H" := (cprod G H)%g (at level 40, left associativity). Notation "G \x H" := (dprod G H)%g (at level 40, left associativity). Notation "[ 'complements' 'to' A 'in' B ]" := (complements_to_in A B) (at level 0, format "[ 'complements' 'to' A 'in' B ]") : group_scope. Notation "[ 'splits' B , 'over' A ]" := (splits_over B A) (at level 0, format "[ 'splits' B , 'over' A ]") : group_scope. (* Prenex Implicits remgl divgl. *) Prenex Implicits remgr divgr. Section InternalProd. Variable gT : finGroupType. Implicit Types A B C : {set gT}. Implicit Types G H K L M : {group gT}. Local Notation pprod := (partial_product gT). Local Notation sdprod := (semidirect_product gT) (only parsing). Local Notation cprod := (central_product gT) (only parsing). Local Notation dprod := (direct_product gT) (only parsing). Lemma pprod1g : left_id 1 pprod. Proof. by move=> A; rewrite /pprod eqxx. Qed. Lemma pprodg1 : right_id 1 pprod. Proof. by move=> A; rewrite /pprod eqxx; case: eqP. Qed. CoInductive are_groups A B : Prop := AreGroups K H of A = K & B = H. Lemma group_not0 G : set0 <> G. Proof. by move/setP/(_ 1); rewrite inE group1. Qed. Lemma mulg0 : right_zero (@set0 gT) mulg. Proof. by move=> A; apply/setP=> x; rewrite inE; apply/imset2P=> [[y z]]; rewrite inE. Qed. Lemma mul0g : left_zero (@set0 gT) mulg. Proof. by move=> A; apply/setP=> x; rewrite inE; apply/imset2P=> [[y z]]; rewrite inE. Qed. Lemma pprodP A B G : pprod A B = G -> [/\ are_groups A B, A * B = G & B \subset 'N(A)]. Proof. have Gnot0 := @group_not0 G; rewrite /pprod; do 2?case: eqP => [-> ->| _]. - by rewrite mul1g norms1; split; first exists 1%G G. - by rewrite mulg1 sub1G; split; first exists G 1%G. by case: and3P => // [[gA gB ->]]; split; first exists (Group gA) (Group gB). Qed. Lemma pprodE K H : H \subset 'N(K) -> pprod K H = K * H. Proof. move=> nKH; rewrite /pprod nKH !groupP /=. by do 2?case: eqP => [-> | _]; rewrite ?mulg1 ?mul1g. Qed. Lemma pprodEY K H : H \subset 'N(K) -> pprod K H = K <*> H. Proof. by move=> nKH; rewrite pprodE ?norm_joinEr. Qed. Lemma pprodW A B G : pprod A B = G -> A * B = G. Proof. by case/pprodP. Qed. Lemma pprodWC A B G : pprod A B = G -> B * A = G. Proof. by case/pprodP=> _ <- /normC. Qed. Lemma pprodWY A B G : pprod A B = G -> A <*> B = G. Proof. by case/pprodP=> [[K H -> ->] <- /norm_joinEr]. Qed. Lemma pprodJ A B x : pprod A B :^ x = pprod (A :^ x) (B :^ x). Proof. rewrite /pprod !conjsg_eq1 !group_setJ normJ conjSg -conjsMg. by do 3?case: ifP => // _; exact: conj0g. Qed. (* Properties of the remainders *) Lemma remgrMl K B x y : y \in K -> remgr K B (y * x) = remgr K B x. Proof. by move=> Ky; rewrite {1}/remgr rcosetM rcoset_id. Qed. Lemma remgrP K B x : (remgr K B x \in K :* x :&: B) = (x \in K * B). Proof. set y := _ x; apply/idP/mulsgP=> [|[g b Kg Bb x_gb]]. rewrite inE rcoset_sym mem_rcoset => /andP[Kxy' By]. by exists (x * y^-1) y; rewrite ?mulgKV. by apply: (mem_repr b); rewrite inE rcoset_sym mem_rcoset x_gb mulgK Kg. Qed. Lemma remgr1 K H x : x \in K -> remgr K H x = 1. Proof. by move=> Kx; rewrite /remgr rcoset_id ?repr_group. Qed. Lemma divgr_eq A B x : x = divgr A B x * remgr A B x. Proof. by rewrite mulgKV. Qed. Lemma divgrMl K B x y : x \in K -> divgr K B (x * y) = x * divgr K B y. Proof. by move=> Hx; rewrite /divgr remgrMl ?mulgA. Qed. Lemma divgr_id K H x : x \in K -> divgr K H x = x. Proof. by move=> Kx; rewrite /divgr remgr1 // invg1 mulg1. Qed. Lemma mem_remgr K B x : x \in K * B -> remgr K B x \in B. Proof. by rewrite -remgrP => /setIP[]. Qed. Lemma mem_divgr K B x : x \in K * B -> divgr K B x \in K. Proof. by rewrite -remgrP inE rcoset_sym mem_rcoset => /andP[]. Qed. Section DisjointRem. Variables K H : {group gT}. Hypothesis tiKH : K :&: H = 1. Lemma remgr_id x : x \in H -> remgr K H x = x. Proof. move=> Hx; apply/eqP; rewrite eq_mulgV1 (sameP eqP set1gP) -tiKH inE. rewrite -mem_rcoset groupMr ?groupV // -in_setI remgrP. by apply: subsetP Hx; exact: mulG_subr. Qed. Lemma remgrMid x y : x \in K -> y \in H -> remgr K H (x * y) = y. Proof. by move=> Kx Hy; rewrite remgrMl ?remgr_id. Qed. Lemma divgrMid x y : x \in K -> y \in H -> divgr K H (x * y) = x. Proof. by move=> Kx Hy; rewrite /divgr remgrMid ?mulgK. Qed. End DisjointRem. (* Intersection of a centraliser with a disjoint product. *) Lemma subcent_TImulg K H A : K :&: H = 1 -> A \subset 'N(K) :&: 'N(H) -> 'C_K(A) * 'C_H(A) = 'C_(K * H)(A). Proof. move=> tiKH /subsetIP[nKA nHA]; apply/eqP. rewrite group_modl ?subsetIr // eqEsubset setSI ?mulSg ?subsetIl //=. apply/subsetP=> _ /setIP[/mulsgP[x y Kx Hy ->] cAxy]. rewrite inE cAxy mem_mulg // inE Kx /=. apply/centP=> z Az; apply/commgP/conjg_fixP. move/commgP/conjg_fixP/(congr1 (divgr K H)): (centP cAxy z Az). by rewrite conjMg !divgrMid ?memJ_norm // (subsetP nKA, subsetP nHA). Qed. (* Complements, and splitting. *) Lemma complP H A B : reflect (A :&: H = 1 /\ A * H = B) (H \in [complements to A in B]). Proof. by apply: (iffP setIdP); case; split; apply/eqP. Qed. Lemma splitsP B A : reflect (exists H, H \in [complements to A in B]) [splits B, over A]. Proof. exact: set0Pn. Qed. Lemma complgC H K G : (H \in [complements to K in G]) = (K \in [complements to H in G]). Proof. rewrite !inE setIC; congr (_ && _). by apply/eqP/eqP=> defG; rewrite -(comm_group_setP _) // defG groupP. Qed. Section NormalComplement. Variables K H G : {group gT}. Hypothesis complH_K : H \in [complements to K in G]. Lemma remgrM : K <| G -> {in G &, {morph remgr K H : x y / x * y}}. Proof. case/normalP=> _; case/complP: complH_K => tiKH <- nK_KH x y KHx KHy. rewrite {1}(divgr_eq K H y) mulgA (conjgCV x) {2}(divgr_eq K H x) -2!mulgA. rewrite mulgA remgrMid //; last by rewrite groupMl mem_remgr. by rewrite groupMl !(=^~ mem_conjg, nK_KH, mem_divgr). Qed. Lemma divgrM : H \subset 'C(K) -> {in G &, {morph divgr K H : x y / x * y}}. Proof. move=> cKH; have /complP[_ defG] := complH_K. have nsKG: K <| G by rewrite -defG -cent_joinEr // normalYl cents_norm. move=> x y Gx Gy; rewrite {1}/divgr remgrM // invMg -!mulgA (mulgA y). by congr (_ * _); rewrite -(centsP cKH) ?groupV ?(mem_remgr, mem_divgr, defG). Qed. End NormalComplement. (* Semi-direct product *) Lemma sdprod1g : left_id 1 sdprod. Proof. by move=> A; rewrite /sdprod subsetIl pprod1g. Qed. Lemma sdprodg1 : right_id 1 sdprod. Proof. by move=> A; rewrite /sdprod subsetIr pprodg1. Qed. Lemma sdprodP A B G : A ><| B = G -> [/\ are_groups A B, A * B = G, B \subset 'N(A) & A :&: B = 1]. Proof. rewrite /sdprod; case: ifP => [trAB | _ /group_not0[] //]. case/pprodP=> gAB defG nBA; split=> {defG nBA}//. by case: gAB trAB => H K -> -> /trivgP. Qed. Lemma sdprodE K H : H \subset 'N(K) -> K :&: H = 1 -> K ><| H = K * H. Proof. by move=> nKH tiKH; rewrite /sdprod tiKH subxx pprodE. Qed. Lemma sdprodEY K H : H \subset 'N(K) -> K :&: H = 1 -> K ><| H = K <*> H. Proof. by move=> nKH tiKH; rewrite sdprodE ?norm_joinEr. Qed. Lemma sdprodWpp A B G : A ><| B = G -> pprod A B = G. Proof. by case/sdprodP=> [[K H -> ->] <- /pprodE]. Qed. Lemma sdprodW A B G : A ><| B = G -> A * B = G. Proof. by move/sdprodWpp/pprodW. Qed. Lemma sdprodWC A B G : A ><| B = G -> B * A = G. Proof. by move/sdprodWpp/pprodWC. Qed. Lemma sdprodWY A B G : A ><| B = G -> A <*> B = G. Proof. by move/sdprodWpp/pprodWY. Qed. Lemma sdprodJ A B x : (A ><| B) :^ x = A :^ x ><| B :^ x. Proof. rewrite /sdprod -conjIg sub_conjg conjs1g -pprodJ. by case: ifP => _ //; exact: imset0. Qed. Lemma sdprod_context G K H : K ><| H = G -> [/\ K <| G, H \subset G, K * H = G, H \subset 'N(K) & K :&: H = 1]. Proof. case/sdprodP=> _ <- nKH tiKH. by rewrite /normal mulG_subl mulG_subr mulG_subG normG. Qed. Lemma sdprod_compl G K H : K ><| H = G -> H \in [complements to K in G]. Proof. by case/sdprodP=> _ mulKH _ tiKH; exact/complP. Qed. Lemma sdprod_normal_complP G K H : K <| G -> reflect (K ><| H = G) (K \in [complements to H in G]). Proof. case/andP=> _ nKG; rewrite complgC. apply: (iffP idP); [case/complP=> tiKH mulKH | exact: sdprod_compl]. by rewrite sdprodE ?(subset_trans _ nKG) // -mulKH mulG_subr. Qed. Lemma sdprod_card G A B : A ><| B = G -> (#|A| * #|B|)%N = #|G|. Proof. by case/sdprodP=> [[H K -> ->] <- _ /TI_cardMg]. Qed. Lemma sdprod_isom G A B : A ><| B = G -> {nAB : B \subset 'N(A) | isom B (G / A) (restrm nAB (coset A))}. Proof. case/sdprodP=> [[K H -> ->] <- nKH tiKH]. by exists nKH; rewrite quotientMidl quotient_isom. Qed. Lemma sdprod_isog G A B : A ><| B = G -> B \isog G / A. Proof. by case/sdprod_isom=> nAB; apply: isom_isog. Qed. Lemma sdprod_subr G A B M : A ><| B = G -> M \subset B -> A ><| M = A <*> M. Proof. case/sdprodP=> [[K H -> ->] _ nKH tiKH] sMH. by rewrite sdprodEY ?(subset_trans sMH) //; apply/trivgP; rewrite -tiKH setIS. Qed. Lemma index_sdprod G A B : A ><| B = G -> #|B| = #|G : A|. Proof. case/sdprodP=> [[K H -> ->] <- _ tiHK]. by rewrite indexMg -indexgI setIC tiHK indexg1. Qed. Lemma index_sdprodr G A B M : A ><| B = G -> M \subset B -> #|B : M| = #|G : A <*> M|. Proof. move=> defG; case/sdprodP: defG (defG) => [[K H -> ->] mulKH nKH _] defG sMH. rewrite -!divgS //=; last by rewrite -genM_join gen_subG -mulKH mulgS. by rewrite -(sdprod_card defG) -(sdprod_card (sdprod_subr defG sMH)) divnMl. Qed. Lemma quotient_sdprodr_isom G A B M : A ><| B = G -> M <| B -> {f : {morphism B / M >-> coset_of (A <*> M)} | isom (B / M) (G / (A <*> M)) f & forall L, L \subset B -> f @* (L / M) = A <*> L / (A <*> M)}. Proof. move=> defG nsMH; have [defA defB]: A = <<A>>%G /\ B = <<B>>%G. by have [[K1 H1 -> ->] _ _ _] := sdprodP defG; rewrite /= !genGid. do [rewrite {}defA {}defB; move: {A}<<A>>%G {B}<<B>>%G => K H] in defG nsMH *. have [[nKH /isomP[injKH imKH]] sMH] := (sdprod_isom defG, normal_sub nsMH). have [[nsKG sHG mulKH _ _] nKM] := (sdprod_context defG, subset_trans sMH nKH). have nsKMG: K <*> M <| G. by rewrite -quotientYK // -mulKH -quotientK ?cosetpre_normal ?quotient_normal. have [/= f inj_f im_f] := third_isom (joing_subl K M) nsKG nsKMG. rewrite quotientYidl //= -imKH -(restrm_quotientE nKH sMH) in f inj_f im_f. have /domP[h [_ ker_h _ im_h]]: 'dom (f \o quotm _ nsMH) = H / M. by rewrite ['dom _]morphpre_quotm injmK. have{im_h} im_h L: L \subset H -> h @* (L / M) = K <*> L / (K <*> M). move=> sLH; have [sLG sKKM] := (subset_trans sLH sHG, joing_subl K M). rewrite im_h morphim_comp morphim_quotm [_ @* L]restrm_quotientE ?im_f //. rewrite quotientY ?(normsG sKKM) ?(subset_trans sLG) ?normal_norm //. by rewrite (quotientS1 sKKM) joing1G. exists h => //; apply/isomP; split; last by rewrite im_h //= (sdprodWY defG). by rewrite ker_h injm_comp ?injm_quotm. Qed. Lemma quotient_sdprodr_isog G A B M : A ><| B = G -> M <| B -> B / M \isog G / (A <*> M). Proof. move=> defG; case/sdprodP: defG (defG) => [[K H -> ->] _ _ _] => defG nsMH. by have [h /isom_isog->] := quotient_sdprodr_isom defG nsMH. Qed. Lemma sdprod_modl A B G H : A ><| B = G -> A \subset H -> A ><| (B :&: H) = G :&: H. Proof. case/sdprodP=> {A B} [[A B -> ->]] <- nAB tiAB sAH. rewrite -group_modl ?sdprodE ?subIset ?nAB //. by rewrite setIA tiAB (setIidPl _) ?sub1G. Qed. Lemma sdprod_modr A B G H : A ><| B = G -> B \subset H -> (H :&: A) ><| B = H :&: G. Proof. case/sdprodP=> {A B}[[A B -> ->]] <- nAB tiAB sAH. rewrite -group_modr ?sdprodE ?normsI // ?normsG //. by rewrite -setIA tiAB (setIidPr _) ?sub1G. Qed. Lemma subcent_sdprod B C G A : B ><| C = G -> A \subset 'N(B) :&: 'N(C) -> 'C_B(A) ><| 'C_C(A) = 'C_G(A). Proof. case/sdprodP=> [[H K -> ->] <- nHK tiHK] nHKA {B C G}. rewrite sdprodE ?subcent_TImulg ?normsIG //. by rewrite -setIIl tiHK (setIidPl (sub1G _)). Qed. Lemma sdprod_recl n G K H K1 : #|G| <= n -> K ><| H = G -> K1 \proper K -> H \subset 'N(K1) -> exists G1 : {group gT}, [/\ #|G1| < n, G1 \subset G & K1 ><| H = G1]. Proof. move=> leGn; case/sdprodP=> _ defG nKH tiKH ltK1K nK1H. have tiK1H: K1 :&: H = 1 by apply/trivgP; rewrite -tiKH setSI ?proper_sub. exists (K1 <*> H)%G; rewrite /= -defG sdprodE // norm_joinEr //. rewrite ?mulSg ?proper_sub ?(leq_trans _ leGn) //=. by rewrite -defG ?TI_cardMg // ltn_pmul2r ?proper_card. Qed. Lemma sdprod_recr n G K H H1 : #|G| <= n -> K ><| H = G -> H1 \proper H -> exists G1 : {group gT}, [/\ #|G1| < n, G1 \subset G & K ><| H1 = G1]. Proof. move=> leGn; case/sdprodP=> _ defG nKH tiKH ltH1H. have [sH1H _] := andP ltH1H; have nKH1 := subset_trans sH1H nKH. have tiKH1: K :&: H1 = 1 by apply/trivgP; rewrite -tiKH setIS. exists (K <*> H1)%G; rewrite /= -defG sdprodE // norm_joinEr //. rewrite ?mulgS // ?(leq_trans _ leGn) //=. by rewrite -defG ?TI_cardMg // ltn_pmul2l ?proper_card. Qed. Lemma mem_sdprod G A B x : A ><| B = G -> x \in G -> exists y, exists z, [/\ y \in A, z \in B, x = y * z & {in A & B, forall u t, x = u * t -> u = y /\ t = z}]. Proof. case/sdprodP=> [[K H -> ->{A B}] <- _ tiKH] /mulsgP[y z Ky Hz ->{x}]. exists y; exists z; split=> // u t Ku Ht eqyzut. move: (congr1 (divgr K H) eqyzut) (congr1 (remgr K H) eqyzut). by rewrite !remgrMid // !divgrMid. Qed. (* Central product *) Lemma cprod1g : left_id 1 cprod. Proof. by move=> A; rewrite /cprod cents1 pprod1g. Qed. Lemma cprodg1 : right_id 1 cprod. Proof. by move=> A; rewrite /cprod sub1G pprodg1. Qed. Lemma cprodP A B G : A \* B = G -> [/\ are_groups A B, A * B = G & B \subset 'C(A)]. Proof. by rewrite /cprod; case: ifP => [cAB /pprodP[] | _ /group_not0[]]. Qed. Lemma cprodE G H : H \subset 'C(G) -> G \* H = G * H. Proof. by move=> cGH; rewrite /cprod cGH pprodE ?cents_norm. Qed. Lemma cprodEY G H : H \subset 'C(G) -> G \* H = G <*> H. Proof. by move=> cGH; rewrite cprodE ?cent_joinEr. Qed. Lemma cprodWpp A B G : A \* B = G -> pprod A B = G. Proof. by case/cprodP=> [[K H -> ->] <- /cents_norm/pprodE]. Qed. Lemma cprodW A B G : A \* B = G -> A * B = G. Proof. by move/cprodWpp/pprodW. Qed. Lemma cprodWC A B G : A \* B = G -> B * A = G. Proof. by move/cprodWpp/pprodWC. Qed. Lemma cprodWY A B G : A \* B = G -> A <*> B = G. Proof. by move/cprodWpp/pprodWY. Qed. Lemma cprodJ A B x : (A \* B) :^ x = A :^ x \* B :^ x. Proof. by rewrite /cprod centJ conjSg -pprodJ; case: ifP => _ //; exact: imset0. Qed. Lemma cprod_normal2 A B G : A \* B = G -> A <| G /\ B <| G. Proof. case/cprodP=> [[K H -> ->] <- cKH]; rewrite -cent_joinEr //. by rewrite normalYl normalYr !cents_norm // centsC. Qed. Lemma bigcprodW I (r : seq I) P F G : \big[cprod/1]_(i <- r | P i) F i = G -> \prod_(i <- r | P i) F i = G. Proof. elim/big_rec2: _ G => // i A B _ IH G /cprodP[[_ H _ defB] <- _]. by rewrite (IH H) defB. Qed. Lemma bigcprodWY I (r : seq I) P F G : \big[cprod/1]_(i <- r | P i) F i = G -> << \bigcup_(i <- r | P i) F i >> = G. Proof. elim/big_rec2: _ G => [|i A B _ IH G]; first by rewrite gen0. case /cprodP => [[K H -> defB] <- cKH]. by rewrite -[<<_>>]joing_idr (IH H) ?cent_joinEr -?defB. Qed. Lemma triv_cprod A B : (A \* B == 1) = (A == 1) && (B == 1). Proof. case A1: (A == 1); first by rewrite (eqP A1) cprod1g. apply/eqP=> /cprodP[[G H defA ->]] /eqP. by rewrite defA trivMg -defA A1. Qed. Lemma cprod_ntriv A B : A != 1 -> B != 1 -> A \* B = if [&& group_set A, group_set B & B \subset 'C(A)] then A * B else set0. Proof. move=> A1 B1; rewrite /cprod; case: ifP => cAB; rewrite ?cAB ?andbF //=. by rewrite /pprod -if_neg A1 -if_neg B1 cents_norm. Qed. Lemma trivg0 : (@set0 gT == 1) = false. Proof. by rewrite eqEcard cards0 cards1 andbF. Qed. Lemma group0 : group_set (@set0 gT) = false. Proof. by rewrite /group_set inE. Qed. Lemma cprod0g A : set0 \* A = set0. Proof. by rewrite /cprod centsC sub0set /pprod group0 trivg0 !if_same. Qed. Lemma cprodC : commutative cprod. Proof. rewrite /cprod => A B; case: ifP => cAB; rewrite centsC cAB // /pprod. by rewrite andbCA normC !cents_norm // 1?centsC //; do 2!case: eqP => // ->. Qed. Lemma cprodA : associative cprod. Proof. move=> A B C; case A1: (A == 1); first by rewrite (eqP A1) !cprod1g. case B1: (B == 1); first by rewrite (eqP B1) cprod1g cprodg1. case C1: (C == 1); first by rewrite (eqP C1) !cprodg1. rewrite !(triv_cprod, cprod_ntriv) ?{}A1 ?{}B1 ?{}C1 //. case: isgroupP => [[G ->{A}] | _]; last by rewrite group0. case: (isgroupP B) => [[H ->{B}] | _]; last by rewrite group0. case: (isgroupP C) => [[K ->{C}] | _]; last by rewrite group0 !andbF. case cGH: (H \subset 'C(G)); case cHK: (K \subset 'C(H)); last first. - by rewrite group0. - by rewrite group0 /= mulG_subG cGH andbF. - by rewrite group0 /= centM subsetI cHK !andbF. rewrite /= mulgA mulG_subG centM subsetI cGH cHK andbT -(cent_joinEr cHK). by rewrite -(cent_joinEr cGH) !groupP. Qed. Canonical cprod_law := Monoid.Law cprodA cprod1g cprodg1. Canonical cprod_abelaw := Monoid.ComLaw cprodC. Lemma cprod_modl A B G H : A \* B = G -> A \subset H -> A \* (B :&: H) = G :&: H. Proof. case/cprodP=> [[U V -> -> {A B}]] defG cUV sUH. by rewrite cprodE; [rewrite group_modl ?defG | rewrite subIset ?cUV]. Qed. Lemma cprod_modr A B G H : A \* B = G -> B \subset H -> (H :&: A) \* B = H :&: G. Proof. by rewrite -!(cprodC B) !(setIC H); exact: cprod_modl. Qed. Lemma bigcprodYP (I : finType) (P : pred I) (H : I -> {group gT}) : reflect (forall i j, P i -> P j -> i != j -> H i \subset 'C(H j)) (\big[cprod/1]_(i | P i) H i == (\prod_(i | P i) H i)%G). Proof. apply: (iffP eqP) => [defG i j Pi Pj neq_ij | cHH]. rewrite (bigD1 j) // (bigD1 i) /= ?cprodA in defG; last exact/andP. by case/cprodP: defG => [[K _ /cprodP[//]]]. set Q := P; have: subpred Q P by []. elim: {Q}_.+1 {-2}Q (ltnSn #|Q|) => // n IHn Q leQn sQP. have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0. rewrite (cardD1x Qi) add1n ltnS !(bigD1 i Qi) /= in leQn *. rewrite {}IHn {n leQn}// => [|j /andP[/sQP //]]. rewrite bigprodGE cprodEY // gen_subG; apply/bigcupsP=> j /andP[neq_ji Qj]. by rewrite cHH ?sQP. Qed. Lemma bigcprodEY I r (P : pred I) (H : I -> {group gT}) G : abelian G -> (forall i, P i -> H i \subset G) -> \big[cprod/1]_(i <- r | P i) H i = (\prod_(i <- r | P i) H i)%G. Proof. move=> cGG sHG; apply/eqP; rewrite !(big_tnth _ _ r). by apply/bigcprodYP=> i j Pi Pj _; rewrite (sub_abelian_cent2 cGG) ?sHG. Qed. Lemma perm_bigcprod (I : eqType) r1 r2 (A : I -> {set gT}) G x : \big[cprod/1]_(i <- r1) A i = G -> {in r1, forall i, x i \in A i} -> perm_eq r1 r2 -> \prod_(i <- r1) x i = \prod_(i <- r2) x i. Proof. elim: r1 r2 G => [|i r1 IHr] r2 G defG Ax eq_r12. by rewrite perm_eq_sym in eq_r12; rewrite (perm_eq_small _ eq_r12) ?big_nil. have /rot_to[n r3 Dr2]: i \in r2 by rewrite -(perm_eq_mem eq_r12) mem_head. transitivity (\prod_(j <- rot n r2) x j). rewrite Dr2 !big_cons in defG Ax *; have [[_ G1 _ defG1] _ _] := cprodP defG. rewrite (IHr r3 G1) //; first by case/allP/andP: Ax => _ /allP. by rewrite -(perm_cons i) -Dr2 perm_eq_sym perm_rot perm_eq_sym. rewrite -{-2}(cat_take_drop n r2) in eq_r12 *. rewrite (eq_big_perm _ eq_r12) !big_cat /= !(big_nth i) !big_mkord in defG *. have /cprodP[[G1 G2 defG1 defG2] _ /centsP-> //] := defG. rewrite defG2 -(bigcprodW defG2) mem_prodg // => k _; apply: Ax. by rewrite (perm_eq_mem eq_r12) mem_cat orbC mem_nth. rewrite defG1 -(bigcprodW defG1) mem_prodg // => k _; apply: Ax. by rewrite (perm_eq_mem eq_r12) mem_cat mem_nth. Qed. Lemma reindex_bigcprod (I J : finType) (h : J -> I) P (A : I -> {set gT}) G x : {on SimplPred P, bijective h} -> \big[cprod/1]_(i | P i) A i = G -> {in SimplPred P, forall i, x i \in A i} -> \prod_(i | P i) x i = \prod_(j | P (h j)) x (h j). Proof. case=> h1 hK h1K; rewrite -!(big_filter _ P) filter_index_enum => defG Ax. rewrite -(big_map h P x) -(big_filter _ P) filter_map filter_index_enum. apply: perm_bigcprod defG _ _ => [i|]; first by rewrite mem_enum => /Ax. apply: uniq_perm_eq (enum_uniq P) _ _ => [|i]. by apply/dinjectiveP; apply: (can_in_inj hK). rewrite mem_enum; apply/idP/imageP=> [Pi | [j Phj ->//]]. by exists (h1 i); rewrite ?inE h1K. Qed. (* Direct product *) Lemma dprod1g : left_id 1 dprod. Proof. by move=> A; rewrite /dprod subsetIl cprod1g. Qed. Lemma dprodg1 : right_id 1 dprod. Proof. by move=> A; rewrite /dprod subsetIr cprodg1. Qed. Lemma dprodP A B G : A \x B = G -> [/\ are_groups A B, A * B = G, B \subset 'C(A) & A :&: B = 1]. Proof. rewrite /dprod; case: ifP => trAB; last by case/group_not0. by case/cprodP=> gAB; split=> //; case: gAB trAB => ? ? -> -> /trivgP. Qed. Lemma dprodE G H : H \subset 'C(G) -> G :&: H = 1 -> G \x H = G * H. Proof. by move=> cGH trGH; rewrite /dprod trGH sub1G cprodE. Qed. Lemma dprodEY G H : H \subset 'C(G) -> G :&: H = 1 -> G \x H = G <*> H. Proof. by move=> cGH trGH; rewrite /dprod trGH subxx cprodEY. Qed. Lemma dprodEcp A B : A :&: B = 1 -> A \x B = A \* B. Proof. by move=> trAB; rewrite /dprod trAB subxx. Qed. Lemma dprodEsd A B : B \subset 'C(A) -> A \x B = A ><| B. Proof. by rewrite /dprod /cprod => ->. Qed. Lemma dprodWcp A B G : A \x B = G -> A \* B = G. Proof. by move=> defG; have [_ _ _ /dprodEcp <-] := dprodP defG. Qed. Lemma dprodWsd A B G : A \x B = G -> A ><| B = G. Proof. by move=> defG; have [_ _ /dprodEsd <-] := dprodP defG. Qed. Lemma dprodW A B G : A \x B = G -> A * B = G. Proof. by move/dprodWsd/sdprodW. Qed. Lemma dprodWC A B G : A \x B = G -> B * A = G. Proof. by move/dprodWsd/sdprodWC. Qed. Lemma dprodWY A B G : A \x B = G -> A <*> B = G. Proof. by move/dprodWsd/sdprodWY. Qed. Lemma cprod_card_dprod G A B : A \* B = G -> #|A| * #|B| <= #|G| -> A \x B = G. Proof. by case/cprodP=> [[K H -> ->] <- cKH] /cardMg_TI; exact: dprodE. Qed. Lemma dprodJ A B x : (A \x B) :^ x = A :^ x \x B :^ x. Proof. rewrite /dprod -conjIg sub_conjg conjs1g -cprodJ. by case: ifP => _ //; exact: imset0. Qed. Lemma dprod_normal2 A B G : A \x B = G -> A <| G /\ B <| G. Proof. by move/dprodWcp/cprod_normal2. Qed. Lemma dprodYP K H : reflect (K \x H = K <*> H) (H \subset 'C(K) :\: K^#). Proof. rewrite subsetD -setI_eq0 setDE setIA -setDE setD_eq0 setIC. apply: (iffP andP) => [[cKH tiKH] | /dprodP[_ _ -> ->] //]. by rewrite dprodEY // (trivgP tiKH). Qed. Lemma dprodC : commutative dprod. Proof. by move=> A B; rewrite /dprod setIC cprodC. Qed. Lemma dprodWsdC A B G : A \x B = G -> B ><| A = G. Proof. by rewrite dprodC => /dprodWsd. Qed. Lemma dprodA : associative dprod. Proof. move=> A B C; case A1: (A == 1); first by rewrite (eqP A1) !dprod1g. case B1: (B == 1); first by rewrite (eqP B1) dprod1g dprodg1. case C1: (C == 1); first by rewrite (eqP C1) !dprodg1. rewrite /dprod (fun_if (cprod A)) (fun_if (cprod^~ C)) -cprodA. rewrite -(cprodC set0) !cprod0g cprod_ntriv ?B1 ?{}C1 //. case: and3P B1 => [[] | _ _]; last by rewrite cprodC cprod0g !if_same. case/isgroupP=> H ->; case/isgroupP=> K -> {B C}; move/cent_joinEr=> eHK H1. rewrite cprod_ntriv ?trivMg ?{}A1 ?{}H1 // mulG_subG. case: and4P => [[] | _]; last by rewrite !if_same. case/isgroupP=> G ->{A} _ cGH _; rewrite cprodEY // -eHK. case trGH: (G :&: H \subset _); case trHK: (H :&: K \subset _); last first. - by rewrite !if_same. - rewrite if_same; case: ifP => // trG_HK; case/negP: trGH. by apply: subset_trans trG_HK; rewrite setIS ?joing_subl. - rewrite if_same; case: ifP => // trGH_K; case/negP: trHK. by apply: subset_trans trGH_K; rewrite setSI ?joing_subr. do 2![case: ifP] => // trGH_K trG_HK; [case/negP: trGH_K | case/negP: trG_HK]. apply: subset_trans trHK; rewrite subsetI subsetIr -{2}(mulg1 H) -mulGS. rewrite setIC group_modl ?joing_subr //= cent_joinEr // -eHK. by rewrite -group_modr ?joing_subl //= setIC -(normC (sub1G _)) mulSg. apply: subset_trans trGH; rewrite subsetI subsetIl -{2}(mul1g H) -mulSG. rewrite setIC group_modr ?joing_subl //= eHK -(cent_joinEr cGH). by rewrite -group_modl ?joing_subr //= setIC (normC (sub1G _)) mulgS. Qed. Canonical dprod_law := Monoid.Law dprodA dprod1g dprodg1. Canonical dprod_abelaw := Monoid.ComLaw dprodC. Lemma bigdprodWcp I (r : seq I) P F G : \big[dprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) F i = G. Proof. elim/big_rec2: _ G => // i A B _ IH G /dprodP[[K H -> defB] <- cKH _]. by rewrite (IH H) // cprodE -defB. Qed. Lemma bigdprodW I (r : seq I) P F G : \big[dprod/1]_(i <- r | P i) F i = G -> \prod_(i <- r | P i) F i = G. Proof. by move/bigdprodWcp; exact: bigcprodW. Qed. Lemma bigdprodWY I (r : seq I) P F G : \big[dprod/1]_(i <- r | P i) F i = G -> << \bigcup_(i <- r | P i) F i >> = G. Proof. by move/bigdprodWcp; exact: bigcprodWY. Qed. Lemma bigdprodYP (I : finType) (P : pred I) (F : I -> {group gT}) : reflect (forall i, P i -> (\prod_(j | P j && (j != i)) F j)%G \subset 'C(F i) :\: (F i)^#) (\big[dprod/1]_(i | P i) F i == (\prod_(i | P i) F i)%G). Proof. apply: (iffP eqP) => [defG i Pi | dxG]. rewrite !(bigD1 i Pi) /= in defG; have [[_ G' _ defG'] _ _ _] := dprodP defG. by apply/dprodYP; rewrite -defG defG' bigprodGE (bigdprodWY defG'). set Q := P; have: subpred Q P by []. elim: {Q}_.+1 {-2}Q (ltnSn #|Q|) => // n IHn Q leQn sQP. have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0. rewrite (cardD1x Qi) add1n ltnS !(bigD1 i Qi) /= in leQn *. rewrite {}IHn {n leQn}// => [|j /andP[/sQP //]]. apply/dprodYP; apply: subset_trans (dxG i (sQP i Qi)); rewrite !bigprodGE. by apply: genS; apply/bigcupsP=> j /andP[Qj ne_ji]; rewrite (bigcup_max j) ?sQP. Qed. Lemma dprod_modl A B G H : A \x B = G -> A \subset H -> A \x (B :&: H) = G :&: H. Proof. case/dprodP=> [[U V -> -> {A B}]] defG cUV trUV sUH. rewrite dprodEcp; first by apply: cprod_modl; rewrite ?cprodE. by rewrite setIA trUV (setIidPl _) ?sub1G. Qed. Lemma dprod_modr A B G H : A \x B = G -> B \subset H -> (H :&: A) \x B = H :&: G. Proof. by rewrite -!(dprodC B) !(setIC H); exact: dprod_modl. Qed. Lemma subcent_dprod B C G A : B \x C = G -> A \subset 'N(B) :&: 'N(C) -> 'C_B(A) \x 'C_C(A) = 'C_G(A). Proof. move=> defG; have [_ _ cBC _] := dprodP defG; move: defG. by rewrite !dprodEsd 1?(centSS _ _ cBC) ?subsetIl //; exact: subcent_sdprod. Qed. Lemma dprod_card A B G : A \x B = G -> (#|A| * #|B|)%N = #|G|. Proof. by case/dprodP=> [[H K -> ->] <- _]; move/TI_cardMg. Qed. Lemma bigdprod_card I r (P : pred I) E G : \big[dprod/1]_(i <- r | P i) E i = G -> (\prod_(i <- r | P i) #|E i|)%N = #|G|. Proof. elim/big_rec2: _ G => [G <- | i A B _ IH G defG]; first by rewrite cards1. have [[_ H _ defH] _ _ _] := dprodP defG. by rewrite -(dprod_card defG) (IH H) defH. Qed. Lemma bigcprod_card_dprod I r (P : pred I) (A : I -> {set gT}) G : \big[cprod/1]_(i <- r | P i) A i = G -> \prod_(i <- r | P i) #|A i| <= #|G| -> \big[dprod/1]_(i <- r | P i) A i = G. Proof. elim: r G => [|i r IHr]; rewrite !(big_nil, big_cons) //; case: ifP => _ // G. case/cprodP=> [[K H -> defH]]; rewrite defH => <- cKH leKH_G. have /implyP := leq_trans leKH_G (dvdn_leq _ (dvdn_cardMg K H)). rewrite muln_gt0 leq_pmul2l !cardG_gt0 //= => /(IHr H defH){defH}defH. by rewrite defH dprodE // cardMg_TI // -(bigdprod_card defH). Qed. Lemma bigcprod_coprime_dprod (I : finType) (P : pred I) (A : I -> {set gT}) G : \big[cprod/1]_(i | P i) A i = G -> (forall i j, P i -> P j -> i != j -> coprime #|A i| #|A j|) -> \big[dprod/1]_(i | P i) A i = G. Proof. move=> defG coA; set Q := P in defG *; have: subpred Q P by []. elim: {Q}_.+1 {-2}Q (ltnSn #|Q|) => // m IHm Q leQm in G defG * => sQP. have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0 in defG *. move: defG; rewrite !(bigD1 i Qi) /= => /cprodP[[Hi Gi defAi defGi] <-]. rewrite defAi defGi => cHGi. have{defGi} defGi: \big[dprod/1]_(j | Q j && (j != i)) A j = Gi. by apply: IHm => [||j /andP[/sQP]] //; rewrite (cardD1x Qi) in leQm. rewrite defGi dprodE // coprime_TIg // -defAi -(bigdprod_card defGi). elim/big_rec: _ => [|j n /andP[neq_ji Qj] IHn]; first exact: coprimen1. by rewrite coprime_mulr coprime_sym coA ?sQP. Qed. Lemma mem_dprod G A B x : A \x B = G -> x \in G -> exists y, exists z, [/\ y \in A, z \in B, x = y * z & {in A & B, forall u t, x = u * t -> u = y /\ t = z}]. Proof. move=> defG; have [_ _ cBA _] := dprodP defG. by apply: mem_sdprod; rewrite -dprodEsd. Qed. Lemma mem_bigdprod (I : finType) (P : pred I) F G x : \big[dprod/1]_(i | P i) F i = G -> x \in G -> exists c, [/\ forall i, P i -> c i \in F i, x = \prod_(i | P i) c i & forall e, (forall i, P i -> e i \in F i) -> x = \prod_(i | P i) e i -> forall i, P i -> e i = c i]. Proof. move=> defG; rewrite -(bigdprodW defG) => /prodsgP[c Fc ->]. exists c; split=> // e Fe eq_ce i Pi. set r := index_enum _ in defG eq_ce. have: i \in r by rewrite -[r]enumT mem_enum. elim: r G defG eq_ce => // j r IHr G; rewrite !big_cons inE. case Pj: (P j); last by case: eqP (IHr G) => // eq_ij; rewrite eq_ij Pj in Pi. case/dprodP=> [[K H defK defH] _ _]; rewrite defK defH => tiFjH eq_ce. suffices{i Pi IHr} eq_cej: c j = e j. case/predU1P=> [-> //|]; apply: IHr defH _. by apply: (mulgI (c j)); rewrite eq_ce eq_cej. rewrite !(big_nth j) !big_mkord in defH eq_ce. move/(congr1 (divgr K H)) : eq_ce; move/bigdprodW: defH => defH. by rewrite !divgrMid // -?defK -?defH ?mem_prodg // => *; rewrite ?Fc ?Fe. Qed. End InternalProd. Implicit Arguments complP [gT H A B]. Implicit Arguments splitsP [gT A B]. Implicit Arguments sdprod_normal_complP [gT K H G]. Implicit Arguments dprodYP [gT K H]. Implicit Arguments bigdprodYP [gT I P F]. Section MorphimInternalProd. Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}). Section OneProd. Variables G H K : {group gT}. Hypothesis sGD : G \subset D. Lemma morphim_pprod : pprod K H = G -> pprod (f @* K) (f @* H) = f @* G. Proof. case/pprodP=> _ defG mKH; rewrite pprodE ?morphim_norms //. by rewrite -morphimMl ?(subset_trans _ sGD) -?defG // mulG_subl. Qed. Lemma morphim_coprime_sdprod : K ><| H = G -> coprime #|K| #|H| -> f @* K ><| f @* H = f @* G. Proof. rewrite /sdprod => defG coHK; move: defG. by rewrite !coprime_TIg ?coprime_morph // !subxx; exact: morphim_pprod. Qed. Lemma injm_sdprod : 'injm f -> K ><| H = G -> f @* K ><| f @* H = f @* G. Proof. move=> inj_f; case/sdprodP=> _ defG nKH tiKH. by rewrite /sdprod -injmI // tiKH morphim1 subxx morphim_pprod // pprodE. Qed. Lemma morphim_cprod : K \* H = G -> f @* K \* f @* H = f @* G. Proof. case/cprodP=> _ defG cKH; rewrite /cprod morphim_cents // morphim_pprod //. by rewrite pprodE // cents_norm // centsC. Qed. Lemma injm_dprod : 'injm f -> K \x H = G -> f @* K \x f @* H = f @* G. Proof. move=> inj_f; case/dprodP=> _ defG cHK tiKH. by rewrite /dprod -injmI // tiKH morphim1 subxx morphim_cprod // cprodE. Qed. Lemma morphim_coprime_dprod : K \x H = G -> coprime #|K| #|H| -> f @* K \x f @* H = f @* G. Proof. rewrite /dprod => defG coHK; move: defG. by rewrite !coprime_TIg ?coprime_morph // !subxx; exact: morphim_cprod. Qed. End OneProd. Implicit Type G : {group gT}. Lemma morphim_bigcprod I r (P : pred I) (H : I -> {group gT}) G : G \subset D -> \big[cprod/1]_(i <- r | P i) H i = G -> \big[cprod/1]_(i <- r | P i) f @* H i = f @* G. Proof. elim/big_rec2: _ G => [|i fB B Pi def_fB] G sGD defG. by rewrite -defG morphim1. case/cprodP: defG (defG) => [[Hi Gi -> defB] _ _]; rewrite defB => defG. rewrite (def_fB Gi) //; first exact: morphim_cprod. by apply: subset_trans sGD; case/cprod_normal2: defG => _ /andP[]. Qed. Lemma injm_bigdprod I r (P : pred I) (H : I -> {group gT}) G : G \subset D -> 'injm f -> \big[dprod/1]_(i <- r | P i) H i = G -> \big[dprod/1]_(i <- r | P i) f @* H i = f @* G. Proof. move=> sGD injf; elim/big_rec2: _ G sGD => [|i fB B Pi def_fB] G sGD defG. by rewrite -defG morphim1. case/dprodP: defG (defG) => [[Hi Gi -> defB] _ _ _]; rewrite defB => defG. rewrite (def_fB Gi) //; first exact: injm_dprod. by apply: subset_trans sGD; case/dprod_normal2: defG => _ /andP[]. Qed. Lemma morphim_coprime_bigdprod (I : finType) P (H : I -> {group gT}) G : G \subset D -> \big[dprod/1]_(i | P i) H i = G -> (forall i j, P i -> P j -> i != j -> coprime #|H i| #|H j|) -> \big[dprod/1]_(i | P i) f @* H i = f @* G. Proof. move=> sGD /bigdprodWcp defG coH; have def_fG := morphim_bigcprod sGD defG. by apply: bigcprod_coprime_dprod => // i j *; rewrite coprime_morph ?coH. Qed. End MorphimInternalProd. Section QuotientInternalProd. Variables (gT : finGroupType) (G K H M : {group gT}). Hypothesis nMG: G \subset 'N(M). Lemma quotient_pprod : pprod K H = G -> pprod (K / M) (H / M) = G / M. Proof. exact: morphim_pprod. Qed. Lemma quotient_coprime_sdprod : K ><| H = G -> coprime #|K| #|H| -> (K / M) ><| (H / M) = G / M. Proof. exact: morphim_coprime_sdprod. Qed. Lemma quotient_cprod : K \* H = G -> (K / M) \* (H / M) = G / M. Proof. exact: morphim_cprod. Qed. Lemma quotient_coprime_dprod : K \x H = G -> coprime #|K| #|H| -> (K / M) \x (H / M) = G / M. Proof. exact: morphim_coprime_dprod. Qed. End QuotientInternalProd. Section ExternalDirProd. Variables gT1 gT2 : finGroupType. Definition extprod_mulg (x y : gT1 * gT2) := (x.1 * y.1, x.2 * y.2). Definition extprod_invg (x : gT1 * gT2) := (x.1^-1, x.2^-1). Lemma extprod_mul1g : left_id (1, 1) extprod_mulg. Proof. case=> x1 x2; congr (_, _); exact: mul1g. Qed. Lemma extprod_mulVg : left_inverse (1, 1) extprod_invg extprod_mulg. Proof. by move=> x; congr (_, _); exact: mulVg. Qed. Lemma extprod_mulgA : associative extprod_mulg. Proof. by move=> x y z; congr (_, _); exact: mulgA. Qed. Definition extprod_groupMixin := Eval hnf in FinGroup.Mixin extprod_mulgA extprod_mul1g extprod_mulVg. Canonical extprod_baseFinGroupType := Eval hnf in BaseFinGroupType (gT1 * gT2) extprod_groupMixin. Canonical prod_group := FinGroupType extprod_mulVg. Lemma group_setX (H1 : {group gT1}) (H2 : {group gT2}) : group_set (setX H1 H2). Proof. apply/group_setP; split; first by rewrite inE !group1. case=> [x1 x2] [y1 y2]; rewrite !inE; case/andP=> Hx1 Hx2; case/andP=> Hy1 Hy2. by rewrite /= !groupM. Qed. Canonical setX_group H1 H2 := Group (group_setX H1 H2). Definition pairg1 x : gT1 * gT2 := (x, 1). Definition pair1g x : gT1 * gT2 := (1, x). Lemma pairg1_morphM : {morph pairg1 : x y / x * y}. Proof. by move=> x y /=; rewrite {2}/mulg /= /extprod_mulg /= mul1g. Qed. Canonical pairg1_morphism := @Morphism _ _ setT _ (in2W pairg1_morphM). Lemma pair1g_morphM : {morph pair1g : x y / x * y}. Proof. by move=> x y /=; rewrite {2}/mulg /= /extprod_mulg /= mul1g. Qed. Canonical pair1g_morphism := @Morphism _ _ setT _ (in2W pair1g_morphM). Lemma fst_morphM : {morph (@fst gT1 gT2) : x y / x * y}. Proof. by move=> x y. Qed. Lemma snd_morphM : {morph (@snd gT1 gT2) : x y / x * y}. Proof. by move=> x y. Qed. Canonical fst_morphism := @Morphism _ _ setT _ (in2W fst_morphM). Canonical snd_morphism := @Morphism _ _ setT _ (in2W snd_morphM). Lemma injm_pair1g : 'injm pair1g. Proof. by apply/subsetP=> x /morphpreP[_ /set1P[->]]; exact: set11. Qed. Lemma injm_pairg1 : 'injm pairg1. Proof. by apply/subsetP=> x /morphpreP[_ /set1P[->]]; exact: set11. Qed. Lemma morphim_pairg1 (H1 : {set gT1}) : pairg1 @* H1 = setX H1 1. Proof. by rewrite -imset2_pair imset2_set1r morphimEsub ?subsetT. Qed. Lemma morphim_pair1g (H2 : {set gT2}) : pair1g @* H2 = setX 1 H2. Proof. by rewrite -imset2_pair imset2_set1l morphimEsub ?subsetT. Qed. Lemma morphim_fstX (H1: {set gT1}) (H2 : {group gT2}) : [morphism of fun x => x.1] @* setX H1 H2 = H1. Proof. apply/eqP; rewrite eqEsubset morphimE setTI /=. apply/andP; split; apply/subsetP=> x. by case/imsetP=> x0; rewrite inE; move/andP=> [Hx1 _] ->. move=> Hx1; apply/imsetP; exists (x, 1); last by trivial. by rewrite in_setX Hx1 /=. Qed. Lemma morphim_sndX (H1: {group gT1}) (H2 : {set gT2}) : [morphism of fun x => x.2] @* setX H1 H2 = H2. Proof. apply/eqP; rewrite eqEsubset morphimE setTI /=. apply/andP; split; apply/subsetP=> x. by case/imsetP=> x0; rewrite inE; move/andP=> [_ Hx2] ->. move=>Hx2; apply/imsetP; exists (1, x); last by []. by rewrite in_setX Hx2 andbT. Qed. Lemma setX_prod (H1 : {set gT1}) (H2 : {set gT2}) : setX H1 1 * setX 1 H2 = setX H1 H2. Proof. apply/setP=> [[x y]]; rewrite !inE /=. apply/imset2P/andP=> [[[x1 u1] [v1 y1]] | [Hx Hy]]. rewrite !inE /= => /andP[Hx1 /eqP->] /andP[/eqP-> Hx] [-> ->]. by rewrite mulg1 mul1g. exists (x, 1 : gT2) (1 : gT1, y); rewrite ?inE ?Hx ?eqxx //. by rewrite /mulg /= /extprod_mulg /= mulg1 mul1g. Qed. Lemma setX_dprod (H1 : {group gT1}) (H2 : {group gT2}) : setX H1 1 \x setX 1 H2 = setX H1 H2. Proof. rewrite dprodE ?setX_prod //. apply/centsP=> [[x u]]; rewrite !inE /= => /andP[/eqP-> _] [v y]. by rewrite !inE /= => /andP[_ /eqP->]; congr (_, _); rewrite ?mul1g ?mulg1. apply/trivgP; apply/subsetP=> [[x y]]; rewrite !inE /= -!andbA. by case/and4P=> _ /eqP-> /eqP->; rewrite eqxx. Qed. Lemma isog_setX1 (H1 : {group gT1}) : isog H1 (setX H1 1). Proof. apply/isogP; exists [morphism of restrm (subsetT H1) pairg1]. by rewrite injm_restrm ?injm_pairg1. by rewrite morphim_restrm morphim_pairg1 setIid. Qed. Lemma isog_set1X (H2 : {group gT2}) : isog H2 (setX 1 H2). Proof. apply/isogP; exists [morphism of restrm (subsetT H2) pair1g]. by rewrite injm_restrm ?injm_pair1g. by rewrite morphim_restrm morphim_pair1g setIid. Qed. Lemma setX_gen (H1 : {set gT1}) (H2 : {set gT2}) : 1 \in H1 -> 1 \in H2 -> <<setX H1 H2>> = setX <<H1>> <<H2>>. Proof. move=> H1_1 H2_1; apply/eqP. rewrite eqEsubset gen_subG setXS ?subset_gen //. rewrite -setX_prod -morphim_pair1g -morphim_pairg1 !morphim_gen ?subsetT //. by rewrite morphim_pair1g morphim_pairg1 mul_subG // genS // setXS ?sub1set. Qed. End ExternalDirProd. Section ExternalSDirProd. Variables (aT rT : finGroupType) (D : {group aT}) (R : {group rT}). (* The pair (a, x) denotes the product sdpair2 a * sdpair1 x *) Inductive sdprod_by (to : groupAction D R) : predArgType := SdPair (ax : aT * rT) of ax \in setX D R. Coercion pair_of_sd to (u : sdprod_by to) := let: SdPair ax _ := u in ax. Variable to : groupAction D R. Notation sdT := (sdprod_by to). Notation sdval := (@pair_of_sd to). Canonical sdprod_subType := Eval hnf in [subType for sdval]. Definition sdprod_eqMixin := Eval hnf in [eqMixin of sdT by <:]. Canonical sdprod_eqType := Eval hnf in EqType sdT sdprod_eqMixin. Definition sdprod_choiceMixin := [choiceMixin of sdT by <:]. Canonical sdprod_choiceType := ChoiceType sdT sdprod_choiceMixin. Definition sdprod_countMixin := [countMixin of sdT by <:]. Canonical sdprod_countType := CountType sdT sdprod_countMixin. Canonical sdprod_subCountType := Eval hnf in [subCountType of sdT]. Definition sdprod_finMixin := [finMixin of sdT by <:]. Canonical sdprod_finType := FinType sdT sdprod_finMixin. Canonical sdprod_subFinType := Eval hnf in [subFinType of sdT]. Definition sdprod_one := SdPair to (group1 _). Lemma sdprod_inv_proof (u : sdT) : (u.1^-1, to u.2^-1 u.1^-1) \in setX D R. Proof. by case: u => [[a x]] /= /setXP[Da Rx]; rewrite inE gact_stable !groupV ?Da. Qed. Definition sdprod_inv u := SdPair to (sdprod_inv_proof u). Lemma sdprod_mul_proof (u v : sdT) : (u.1 * v.1, to u.2 v.1 * v.2) \in setX D R. Proof. case: u v => [[a x] /= /setXP[Da Rx]] [[b y] /= /setXP[Db Ry]]. by rewrite inE !groupM //= gact_stable. Qed. Definition sdprod_mul u v := SdPair to (sdprod_mul_proof u v). Lemma sdprod_mul1g : left_id sdprod_one sdprod_mul. Proof. move=> u; apply: val_inj; case: u => [[a x] /=]; case/setXP=> Da _. by rewrite gact1 // !mul1g. Qed. Lemma sdprod_mulVg : left_inverse sdprod_one sdprod_inv sdprod_mul. Proof. move=> u; apply: val_inj; case: u => [[a x] /=]; case/setXP=> Da _. by rewrite actKVin ?mulVg. Qed. Lemma sdprod_mulgA : associative sdprod_mul. Proof. move=> u v w; apply: val_inj; case: u => [[a x]] /=; case/setXP=> Da Rx. case: v w => [[b y]] /=; case/setXP=> Db Ry [[c z]] /=; case/setXP=> Dc Rz. by rewrite !(actMin to) // gactM ?gact_stable // !mulgA. Qed. Canonical sdprod_groupMixin := FinGroup.Mixin sdprod_mulgA sdprod_mul1g sdprod_mulVg. Canonical sdprod_baseFinGroupType := Eval hnf in BaseFinGroupType sdT sdprod_groupMixin. Canonical sdprod_groupType := FinGroupType sdprod_mulVg. Definition sdpair1 x := insubd sdprod_one (1, x) : sdT. Definition sdpair2 a := insubd sdprod_one (a, 1) : sdT. Lemma sdpair1_morphM : {in R &, {morph sdpair1 : x y / x * y}}. Proof. move=> x y Rx Ry; apply: val_inj. by rewrite /= !val_insubd !inE !group1 !groupM ?Rx ?Ry //= mulg1 act1. Qed. Lemma sdpair2_morphM : {in D &, {morph sdpair2 : a b / a * b}}. Proof. move=> a b Da Db; apply: val_inj. by rewrite /= !val_insubd !inE !group1 !groupM ?Da ?Db //= mulg1 gact1. Qed. Canonical sdpair1_morphism := Morphism sdpair1_morphM. Canonical sdpair2_morphism := Morphism sdpair2_morphM. Lemma injm_sdpair1 : 'injm sdpair1. Proof. apply/subsetP=> x /setIP[Rx]. by rewrite !inE -val_eqE val_insubd inE Rx group1 /=; case/andP. Qed. Lemma injm_sdpair2 : 'injm sdpair2. Proof. apply/subsetP=> a /setIP[Da]. by rewrite !inE -val_eqE val_insubd inE Da group1 /=; case/andP. Qed. Lemma sdpairE (u : sdT) : u = sdpair2 u.1 * sdpair1 u.2. Proof. apply: val_inj; case: u => [[a x] /= /setXP[Da Rx]]. by rewrite !val_insubd !inE Da Rx !(group1, gact1) // mulg1 mul1g. Qed. Lemma sdpair_act : {in R & D, forall x a, sdpair1 (to x a) = sdpair1 x ^ sdpair2 a}. Proof. move=> x a Rx Da; apply: val_inj. rewrite /= !val_insubd !inE !group1 gact_stable ?Da ?Rx //=. by rewrite !mul1g mulVg invg1 mulg1 actKVin ?mul1g. Qed. Lemma sdpair_setact (G : {set rT}) a : G \subset R -> a \in D -> sdpair1 @* (to^~ a @: G) = (sdpair1 @* G) :^ sdpair2 a. Proof. move=> sGR Da; have GtoR := subsetP sGR; apply/eqP. rewrite eqEcard cardJg !(card_injm injm_sdpair1) //; last first. by apply/subsetP=> _ /imsetP[x Gx ->]; rewrite gact_stable ?GtoR. rewrite (card_imset _ (act_inj _ _)) leqnn andbT. apply/subsetP=> _ /morphimP[xa Rxa /imsetP[x Gx def_xa ->]]. rewrite mem_conjg -morphV // -sdpair_act ?groupV // def_xa actKin //. by rewrite mem_morphim ?GtoR. Qed. Lemma im_sdpair_norm : sdpair2 @* D \subset 'N(sdpair1 @* R). Proof. apply/subsetP=> _ /morphimP[a _ Da ->]. rewrite inE -sdpair_setact // morphimS //. by apply/subsetP=> _ /imsetP[x Rx ->]; rewrite gact_stable. Qed. Lemma im_sdpair_TI : (sdpair1 @* R) :&: (sdpair2 @* D) = 1. Proof. apply/trivgP; apply/subsetP=> _ /setIP[/morphimP[x _ Rx ->]]. case/morphimP=> a _ Da /eqP; rewrite inE -!val_eqE. by rewrite !val_insubd !inE Da Rx !group1 /eq_op /= eqxx; case/andP. Qed. Lemma im_sdpair : (sdpair1 @* R) * (sdpair2 @* D) = setT. Proof. apply/eqP; rewrite -subTset -(normC im_sdpair_norm). apply/subsetP=> /= u _; rewrite [u]sdpairE. by case: u => [[a x] /= /setXP[Da Rx]]; rewrite mem_mulg ?mem_morphim. Qed. Lemma sdprod_sdpair : sdpair1 @* R ><| sdpair2 @* D = setT. Proof. by rewrite sdprodE ?(im_sdpair_norm, im_sdpair, im_sdpair_TI). Qed. Variables (A : {set aT}) (G : {set rT}). Lemma gacentEsd : 'C_(|to)(A) = sdpair1 @*^-1 'C(sdpair2 @* A). Proof. apply/setP=> x; apply/idP/idP. case/setIP=> Rx /afixP cDAx; rewrite mem_morphpre //. apply/centP=> _ /morphimP[a Da Aa ->]; red. by rewrite conjgC -sdpair_act // cDAx // inE Da. case/morphpreP=> Rx cAx; rewrite inE Rx; apply/afixP=> a /setIP[Da Aa]. apply: (injmP _ injm_sdpair1); rewrite ?gact_stable /= ?sdpair_act //=. by rewrite /conjg (centP cAx) ?mulKg ?mem_morphim. Qed. Hypotheses (sAD : A \subset D) (sGR : G \subset R). Lemma astabEsd : 'C(G | to) = sdpair2 @*^-1 'C(sdpair1 @* G). Proof. have ssGR := subsetP sGR; apply/setP=> a; apply/idP/idP=> [cGa|]. rewrite mem_morphpre ?(astab_dom cGa) //. apply/centP=> _ /morphimP[x Rx Gx ->]; symmetry. by rewrite conjgC -sdpair_act ?(astab_act cGa) ?(astab_dom cGa). case/morphpreP=> Da cGa; rewrite !inE Da; apply/subsetP=> x Gx; rewrite inE. apply/eqP; apply: (injmP _ injm_sdpair1); rewrite ?gact_stable ?ssGR //=. by rewrite sdpair_act ?ssGR // /conjg -(centP cGa) ?mulKg ?mem_morphim ?ssGR. Qed. Lemma astabsEsd : 'N(G | to) = sdpair2 @*^-1 'N(sdpair1 @* G). Proof. apply/setP=> a; apply/idP/idP=> [nGa|]. have Da := astabs_dom nGa; rewrite mem_morphpre // inE sub_conjg. apply/subsetP=> _ /morphimP[x Rx Gx ->]. by rewrite mem_conjgV -sdpair_act // mem_morphim ?gact_stable ?astabs_act. case/morphpreP=> Da nGa; rewrite !inE Da; apply/subsetP=> x Gx. have Rx := subsetP sGR _ Gx; have Rxa: to x a \in R by rewrite gact_stable. rewrite inE -sub1set -(injmSK injm_sdpair1) ?morphim_set1 ?sub1set //=. by rewrite sdpair_act ?memJ_norm ?mem_morphim. Qed. Lemma actsEsd : [acts A, on G | to] = (sdpair2 @* A \subset 'N(sdpair1 @* G)). Proof. by rewrite sub_morphim_pre -?astabsEsd. Qed. End ExternalSDirProd. Section ProdMorph. Variables gT rT : finGroupType. Implicit Types A B : {set gT}. Implicit Types G H K : {group gT}. Implicit Types C D : {set rT}. Implicit Type L : {group rT}. Section defs. Variables (A B : {set gT}) (fA fB : gT -> FinGroup.sort rT). Definition pprodm of B \subset 'N(A) & {in A & B, morph_act 'J 'J fA fB} & {in A :&: B, fA =1 fB} := fun x => fA (divgr A B x) * fB (remgr A B x). End defs. Section Props. Variables H K : {group gT}. Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}). Hypothesis nHK : K \subset 'N(H). Hypothesis actf : {in H & K, morph_act 'J 'J fH fK}. Hypothesis eqfHK : {in H :&: K, fH =1 fK}. Notation Local f := (pprodm nHK actf eqfHK). Lemma pprodmE x a : x \in H -> a \in K -> f (x * a) = fH x * fK a. Proof. move=> Hx Ka; have: x * a \in H * K by rewrite mem_mulg. rewrite -remgrP inE /f rcoset_sym mem_rcoset /divgr -mulgA groupMl //. case/andP; move: (remgr H K _) => b Hab Kb; rewrite morphM // -mulgA. have Kab: a * b^-1 \in K by rewrite groupM ?groupV. by congr (_ * _); rewrite eqfHK 1?inE ?Hab // -morphM // mulgKV. Qed. Lemma pprodmEl : {in H, f =1 fH}. Proof. by move=> x Hx; rewrite -(mulg1 x) pprodmE // morph1 !mulg1. Qed. Lemma pprodmEr : {in K, f =1 fK}. Proof. by move=> a Ka; rewrite -(mul1g a) pprodmE // morph1 !mul1g. Qed. Lemma pprodmM : {in H <*> K &, {morph f: x y / x * y}}. Proof. move=> xa yb; rewrite norm_joinEr //. move=> /imset2P[x a Ha Ka ->{xa}] /imset2P[y b Hy Kb ->{yb}]. have Hya: y ^ a^-1 \in H by rewrite -mem_conjg (normsP nHK). rewrite mulgA -(mulgA x) (conjgCV a y) (mulgA x) -mulgA !pprodmE 1?groupMl //. by rewrite 2?morphM // actf ?groupV ?morphV // !mulgA mulgKV invgK. Qed. Canonical pprodm_morphism := Morphism pprodmM. Lemma morphim_pprodm A B : A \subset H -> B \subset K -> f @* (A * B) = fH @* A * fK @* B. Proof. move=> sAH sBK; rewrite [f @* _]morphimEsub /=; last first. by rewrite norm_joinEr // mulgSS. apply/setP=> y; apply/imsetP/idP=> [[_ /mulsgP[x a Ax Ba ->] ->{y}] |]. have Hx := subsetP sAH x Ax; have Ka := subsetP sBK a Ba. by rewrite pprodmE // mem_imset2 ?mem_morphim. case/mulsgP=> _ _ /morphimP[x Hx Ax ->] /morphimP[a Ka Ba ->] ->{y}. by exists (x * a); rewrite ?mem_mulg ?pprodmE. Qed. Lemma morphim_pprodml A : A \subset H -> f @* A = fH @* A. Proof. by move=> sAH; rewrite -{1}(mulg1 A) morphim_pprodm ?sub1G // morphim1 mulg1. Qed. Lemma morphim_pprodmr B : B \subset K -> f @* B = fK @* B. Proof. by move=> sBK; rewrite -{1}(mul1g B) morphim_pprodm ?sub1G // morphim1 mul1g. Qed. Lemma ker_pprodm : 'ker f = [set x * a^-1 | x in H, a in K & fH x == fK a]. Proof. apply/setP=> y; rewrite 3!inE {1}norm_joinEr //=. apply/andP/imset2P=> [[/mulsgP[x a Hx Ka ->{y}]]|[x a Hx]]. rewrite pprodmE // => fxa1. by exists x a^-1; rewrite ?invgK // inE groupVr ?morphV // eq_mulgV1 invgK. case/setIdP=> Kx /eqP fx ->{y}. by rewrite mem_imset2 ?pprodmE ?groupV ?morphV // fx mulgV. Qed. Lemma injm_pprodm : 'injm f = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == fH @* K]. Proof. apply/idP/and3P=> [injf | [injfH injfK]]. rewrite eq_sym -{1}morphimIdom -(morphim_pprodml (subsetIl _ _)) injmI //. rewrite morphim_pprodml // morphim_pprodmr //=; split=> //. apply/injmP=> x y Hx Hy /=; rewrite -!pprodmEl //. by apply: (injmP _ injf); rewrite ?mem_gen ?inE ?Hx ?Hy. apply/injmP=> a b Ka Kb /=; rewrite -!pprodmEr //. by apply: (injmP _ injf); rewrite ?mem_gen //; apply/setUP; right. move/eqP=> fHK; rewrite ker_pprodm; apply/subsetP=> y. case/imset2P=> x a Hx /setIdP[Ka /eqP fxa] ->. have: fH x \in fH @* K by rewrite -fHK inE {2}fxa !mem_morphim. case/morphimP=> z Hz Kz /(injmP _ injfH) def_x. rewrite def_x // eqfHK ?inE ?Hz // in fxa. by rewrite def_x // (injmP _ injfK _ _ Kz Ka fxa) mulgV set11. Qed. End Props. Section Sdprodm. Variables H K G : {group gT}. Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}). Hypothesis eqHK_G : H ><| K = G. Hypothesis actf : {in H & K, morph_act 'J 'J fH fK}. Lemma sdprodm_norm : K \subset 'N(H). Proof. by case/sdprodP: eqHK_G. Qed. Lemma sdprodm_sub : G \subset H <*> K. Proof. by case/sdprodP: eqHK_G => _ <- nHK _; rewrite norm_joinEr. Qed. Lemma sdprodm_eqf : {in H :&: K, fH =1 fK}. Proof. by case/sdprodP: eqHK_G => _ _ _ -> _ /set1P->; rewrite !morph1. Qed. Definition sdprodm := restrm sdprodm_sub (pprodm sdprodm_norm actf sdprodm_eqf). Canonical sdprodm_morphism := Eval hnf in [morphism of sdprodm]. Lemma sdprodmE a b : a \in H -> b \in K -> sdprodm (a * b) = fH a * fK b. Proof. exact: pprodmE. Qed. Lemma sdprodmEl a : a \in H -> sdprodm a = fH a. Proof. exact: pprodmEl. Qed. Lemma sdprodmEr b : b \in K -> sdprodm b = fK b. Proof. exact: pprodmEr. Qed. Lemma morphim_sdprodm A B : A \subset H -> B \subset K -> sdprodm @* (A * B) = fH @* A * fK @* B. Proof. move=> sAH sBK; rewrite morphim_restrm /= (setIidPr _) ?morphim_pprodm //. case/sdprodP: eqHK_G => _ <- _ _; exact: mulgSS. Qed. Lemma im_sdprodm : sdprodm @* G = fH @* H * fK @* K. Proof. by rewrite -morphim_sdprodm //; case/sdprodP: eqHK_G => _ ->. Qed. Lemma morphim_sdprodml A : A \subset H -> sdprodm @* A = fH @* A. Proof. by move=> sHA; rewrite -{1}(mulg1 A) morphim_sdprodm ?sub1G // morphim1 mulg1. Qed. Lemma morphim_sdprodmr B : B \subset K -> sdprodm @* B = fK @* B. Proof. by move=> sBK; rewrite -{1}(mul1g B) morphim_sdprodm ?sub1G // morphim1 mul1g. Qed. Lemma ker_sdprodm : 'ker sdprodm = [set a * b^-1 | a in H, b in K & fH a == fK b]. Proof. rewrite ker_restrm (setIidPr _) ?subIset ?ker_pprodm //; apply/orP; left. by case/sdprodP: eqHK_G => _ <- nHK _; rewrite norm_joinEr. Qed. Lemma injm_sdprodm : 'injm sdprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1]. Proof. rewrite ker_sdprodm -(ker_pprodm sdprodm_norm actf sdprodm_eqf) injm_pprodm. congr [&& _, _ & _ == _]; have [_ _ _ tiHK] := sdprodP eqHK_G. by rewrite -morphimIdom tiHK morphim1. Qed. End Sdprodm. Section Cprodm. Variables H K G : {group gT}. Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}). Hypothesis eqHK_G : H \* K = G. Hypothesis cfHK : fK @* K \subset 'C(fH @* H). Hypothesis eqfHK : {in H :&: K, fH =1 fK}. Lemma cprodm_norm : K \subset 'N(H). Proof. by rewrite cents_norm //; case/cprodP: eqHK_G. Qed. Lemma cprodm_sub : G \subset H <*> K. Proof. by case/cprodP: eqHK_G => _ <- cHK; rewrite cent_joinEr. Qed. Lemma cprodm_actf : {in H & K, morph_act 'J 'J fH fK}. Proof. case/cprodP: eqHK_G => _ _ cHK a b Ha Kb /=. by rewrite /conjg -(centsP cHK b) // -(centsP cfHK (fK b)) ?mulKg ?mem_morphim. Qed. Definition cprodm := restrm cprodm_sub (pprodm cprodm_norm cprodm_actf eqfHK). Canonical cprodm_morphism := Eval hnf in [morphism of cprodm]. Lemma cprodmE a b : a \in H -> b \in K -> cprodm (a * b) = fH a * fK b. Proof. exact: pprodmE. Qed. Lemma cprodmEl a : a \in H -> cprodm a = fH a. Proof. exact: pprodmEl. Qed. Lemma cprodmEr b : b \in K -> cprodm b = fK b. Proof. exact: pprodmEr. Qed. Lemma morphim_cprodm A B : A \subset H -> B \subset K -> cprodm @* (A * B) = fH @* A * fK @* B. Proof. move=> sAH sBK; rewrite morphim_restrm /= (setIidPr _) ?morphim_pprodm //. case/cprodP: eqHK_G => _ <- _; exact: mulgSS. Qed. Lemma im_cprodm : cprodm @* G = fH @* H * fK @* K. Proof. by have [_ defHK _] := cprodP eqHK_G; rewrite -{2}defHK morphim_cprodm. Qed. Lemma morphim_cprodml A : A \subset H -> cprodm @* A = fH @* A. Proof. by move=> sHA; rewrite -{1}(mulg1 A) morphim_cprodm ?sub1G // morphim1 mulg1. Qed. Lemma morphim_cprodmr B : B \subset K -> cprodm @* B = fK @* B. Proof. by move=> sBK; rewrite -{1}(mul1g B) morphim_cprodm ?sub1G // morphim1 mul1g. Qed. Lemma ker_cprodm : 'ker cprodm = [set a * b^-1 | a in H, b in K & fH a == fK b]. Proof. rewrite ker_restrm (setIidPr _) ?subIset ?ker_pprodm //; apply/orP; left. by case/cprodP: eqHK_G => _ <- cHK; rewrite cent_joinEr. Qed. Lemma injm_cprodm : 'injm cprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == fH @* K]. Proof. by rewrite ker_cprodm -(ker_pprodm cprodm_norm cprodm_actf eqfHK) injm_pprodm. Qed. End Cprodm. Section Dprodm. Variables G H K : {group gT}. Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}). Hypothesis eqHK_G : H \x K = G. Hypothesis cfHK : fK @* K \subset 'C(fH @* H). Lemma dprodm_cprod : H \* K = G. Proof. by rewrite -eqHK_G /dprod; case/dprodP: eqHK_G => _ _ _ ->; rewrite subxx. Qed. Lemma dprodm_eqf : {in H :&: K, fH =1 fK}. Proof. by case/dprodP: eqHK_G => _ _ _ -> _ /set1P->; rewrite !morph1. Qed. Definition dprodm := cprodm dprodm_cprod cfHK dprodm_eqf. Canonical dprodm_morphism := Eval hnf in [morphism of dprodm]. Lemma dprodmE a b : a \in H -> b \in K -> dprodm (a * b) = fH a * fK b. Proof. exact: pprodmE. Qed. Lemma dprodmEl a : a \in H -> dprodm a = fH a. Proof. exact: pprodmEl. Qed. Lemma dprodmEr b : b \in K -> dprodm b = fK b. Proof. exact: pprodmEr. Qed. Lemma morphim_dprodm A B : A \subset H -> B \subset K -> dprodm @* (A * B) = fH @* A * fK @* B. Proof. exact: morphim_cprodm. Qed. Lemma im_dprodm : dprodm @* G = fH @* H * fK @* K. Proof. exact: im_cprodm. Qed. Lemma morphim_dprodml A : A \subset H -> dprodm @* A = fH @* A. Proof. exact: morphim_cprodml. Qed. Lemma morphim_dprodmr B : B \subset K -> dprodm @* B = fK @* B. Proof. exact: morphim_cprodmr. Qed. Lemma ker_dprodm : 'ker dprodm = [set a * b^-1 | a in H, b in K & fH a == fK b]. Proof. exact: ker_cprodm. Qed. Lemma injm_dprodm : 'injm dprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1]. Proof. rewrite injm_cprodm -(morphimIdom fH K). by case/dprodP: eqHK_G => _ _ _ ->; rewrite morphim1. Qed. End Dprodm. Lemma isog_dprod A B G C D L : A \x B = G -> C \x D = L -> isog A C -> isog B D -> isog G L. Proof. move=> defG {C D} /dprodP[[C D -> ->] defL cCD trCD]. case/dprodP: defG (defG) => {A B} [[A B -> ->] defG _ _] dG defC defD. case/isogP: defC defL cCD trCD => fA injfA <-{C}. case/isogP: defD => fB injfB <-{D} defL cCD trCD. apply/isogP; exists (dprodm_morphism dG cCD). by rewrite injm_dprodm injfA injfB trCD eqxx. by rewrite /= -{2}defG morphim_dprodm. Qed. End ProdMorph. Section ExtSdprodm. Variables gT aT rT : finGroupType. Variables (H : {group gT}) (K : {group aT}) (to : groupAction K H). Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}). Hypothesis actf : {in H & K, morph_act to 'J fH fK}. Local Notation fsH := (fH \o invm (injm_sdpair1 to)). Local Notation fsK := (fK \o invm (injm_sdpair2 to)). Let DgH := sdpair1 to @* H. Let DgK := sdpair2 to @* K. Lemma xsdprodm_dom1 : DgH \subset 'dom fsH. Proof. by rewrite ['dom _]morphpre_invm. Qed. Local Notation gH := (restrm xsdprodm_dom1 fsH). Lemma xsdprodm_dom2 : DgK \subset 'dom fsK. Proof. by rewrite ['dom _]morphpre_invm. Qed. Local Notation gK := (restrm xsdprodm_dom2 fsK). Lemma im_sdprodm1 : gH @* DgH = fH @* H. Proof. by rewrite morphim_restrm setIid morphim_comp im_invm. Qed. Lemma im_sdprodm2 : gK @* DgK = fK @* K. Proof. by rewrite morphim_restrm setIid morphim_comp im_invm. Qed. Lemma xsdprodm_act : {in DgH & DgK, morph_act 'J 'J gH gK}. Proof. move=> fh fk; case/morphimP=> h _ Hh ->{fh}; case/morphimP=> k _ Kk ->{fk}. by rewrite /= -sdpair_act // /restrm /= !invmE ?actf ?gact_stable. Qed. Definition xsdprodm := sdprodm (sdprod_sdpair to) xsdprodm_act. Canonical xsdprod_morphism := [morphism of xsdprodm]. Lemma im_xsdprodm : xsdprodm @* setT = fH @* H * fK @* K. Proof. by rewrite -im_sdpair morphim_sdprodm // im_sdprodm1 im_sdprodm2. Qed. Lemma injm_xsdprodm : 'injm xsdprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1]. Proof. rewrite injm_sdprodm im_sdprodm1 im_sdprodm2 !subG1 /= !ker_restrm !ker_comp. rewrite !morphpre_invm !morphimIim. by rewrite !morphim_injm_eq1 ?subsetIl ?injm_sdpair1 ?injm_sdpair2. Qed. End ExtSdprodm. Section DirprodIsom. Variable gT : finGroupType. Implicit Types G H : {group gT}. Definition mulgm : gT * gT -> _ := prod_curry mulg. Lemma imset_mulgm (A B : {set gT}) : mulgm @: setX A B = A * B. Proof. by rewrite -curry_imset2X. Qed. Lemma mulgmP H1 H2 G : reflect (H1 \x H2 = G) (misom (setX H1 H2) G mulgm). Proof. apply: (iffP misomP) => [[pM /isomP[injf /= <-]] | ]. have /dprodP[_ /= defX cH12] := setX_dprod H1 H2. rewrite -{4}defX {}defX => /(congr1 (fun A => morphm pM @* A)). move/(morphimS (morphm_morphism pM)): cH12 => /=. have sH1H: setX H1 1 \subset setX H1 H2 by rewrite setXS ?sub1G. have sH2H: setX 1 H2 \subset setX H1 H2 by rewrite setXS ?sub1G. rewrite morphim1 injm_cent ?injmI //= subsetI => /andP[_]. by rewrite !morphimEsub //= !imset_mulgm mulg1 mul1g; exact: dprodE. case/dprodP=> _ defG cH12 trH12. have fM: morphic (setX H1 H2) mulgm. apply/morphicP=> [[x1 x2] [y1 y2] /setXP[_ Hx2] /setXP[Hy1 _]]. by rewrite /= mulgA -(mulgA x1) -(centsP cH12 x2) ?mulgA. exists fM; apply/isomP; split; last by rewrite morphimEsub //= imset_mulgm. apply/subsetP=> [[x1 x2]]; rewrite !inE /= andbC -eq_invg_mul. case: eqP => //= <-; rewrite groupV -in_setI trH12 => /set1P->. by rewrite invg1 eqxx. Qed. End DirprodIsom. Implicit Arguments mulgmP [gT H1 H2 G]. Prenex Implicits mulgm mulgmP.
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Bhavik Mehta -/ import category_theory.monad.adjunction import category_theory.adjunction.limits import category_theory.limits.preserves.shapes.terminal namespace category_theory open category open category_theory.limits universes v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes]. namespace monad variables {C : Type u₁} [category.{v₁} C] variables {T : monad C} variables {J : Type v₁} [small_category J] namespace forget_creates_limits variables (D : J ⥤ algebra T) (c : cone (D ⋙ forget T)) (t : is_limit c) /-- (Impl) The natural transformation used to define the new cone -/ @[simps] def γ : (D ⋙ forget T ⋙ ↑T) ⟶ (D ⋙ forget T) := { app := λ j, (D.obj j).a } /-- (Impl) This new cone is used to construct the algebra structure -/ @[simps] def new_cone : cone (D ⋙ forget T) := { X := T.obj c.X, π := (functor.const_comp _ _ ↑T).inv ≫ whisker_right c.π T ≫ (γ D) } /-- The algebra structure which will be the apex of the new limit cone for `D`. -/ @[simps] def cone_point : algebra T := { A := c.X, a := t.lift (new_cone D c), unit' := begin apply t.hom_ext, intro j, erw [category.assoc, t.fac (new_cone D c), id_comp], dsimp, erw [id_comp, ← category.assoc, ← T.η.naturality, functor.id_map, category.assoc, (D.obj j).unit, comp_id], end, assoc' := begin apply t.hom_ext, intro j, rw [category.assoc, category.assoc, t.fac (new_cone D c)], dsimp, erw id_comp, slice_lhs 1 2 {rw ← T.μ.naturality}, slice_lhs 2 3 {rw (D.obj j).assoc}, slice_rhs 1 2 {rw ← (T : C ⥤ C).map_comp}, rw t.fac (new_cone D c), dsimp, erw [id_comp, functor.map_comp, category.assoc] end } /-- (Impl) Construct the lifted cone in `algebra T` which will be limiting. -/ @[simps] def lifted_cone : cone D := { X := cone_point D c t, π := { app := λ j, { f := c.π.app j }, naturality' := λ X Y f, by { ext1, dsimp, erw c.w f, simp } } } /-- (Impl) Prove that the lifted cone is limiting. -/ @[simps] def lifted_cone_is_limit : is_limit (lifted_cone D c t) := { lift := λ s, { f := t.lift ((forget T).map_cone s), h' := begin apply t.hom_ext, intro j, slice_rhs 2 3 {rw t.fac ((forget T).map_cone s) j}, dsimp, slice_lhs 2 3 {rw t.fac (new_cone D c) j}, dsimp, rw category.id_comp, slice_lhs 1 2 {rw ← (T : C ⥤ C).map_comp}, rw t.fac ((forget T).map_cone s) j, exact (s.π.app j).h end }, uniq' := λ s m J, begin ext1, apply t.hom_ext, intro j, simpa [t.fac (functor.map_cone (forget T) s) j] using congr_arg algebra.hom.f (J j), end } end forget_creates_limits -- Theorem 5.6.5 from [Riehl][riehl2017] /-- The forgetful functor from the Eilenberg-Moore category creates limits. -/ noncomputable instance forget_creates_limits : creates_limits (forget T) := { creates_limits_of_shape := λ J 𝒥, by exactI { creates_limit := λ D, creates_limit_of_reflects_iso (λ c t, { lifted_cone := forget_creates_limits.lifted_cone D c t, valid_lift := cones.ext (iso.refl _) (λ j, (id_comp _).symm), makes_limit := forget_creates_limits.lifted_cone_is_limit _ _ _ } ) } } /-- `D ⋙ forget T` has a limit, then `D` has a limit. -/ lemma has_limit_of_comp_forget_has_limit (D : J ⥤ algebra T) [has_limit (D ⋙ forget T)] : has_limit D := has_limit_of_created D (forget T) namespace forget_creates_colimits -- Let's hide the implementation details in a namespace variables {D : J ⥤ algebra T} (c : cocone (D ⋙ forget T)) (t : is_colimit c) -- We have a diagram D of shape J in the category of algebras, and we assume that we are given a -- colimit for its image D ⋙ forget T under the forgetful functor, say its apex is L. -- We'll construct a colimiting coalgebra for D, whose carrier will also be L. -- To do this, we must find a map TL ⟶ L. Since T preserves colimits, TL is also a colimit. -- In particular, it is a colimit for the diagram `(D ⋙ forget T) ⋙ T` -- so to construct a map TL ⟶ L it suffices to show that L is the apex of a cocone for this diagram. -- In other words, we need a natural transformation from const L to `(D ⋙ forget T) ⋙ T`. -- But we already know that L is the apex of a cocone for the diagram `D ⋙ forget T`, so it -- suffices to give a natural transformation `((D ⋙ forget T) ⋙ T) ⟶ (D ⋙ forget T)`: /-- (Impl) The natural transformation given by the algebra structure maps, used to construct a cocone `c` with apex `colimit (D ⋙ forget T)`. -/ @[simps] def γ : ((D ⋙ forget T) ⋙ ↑T) ⟶ (D ⋙ forget T) := { app := λ j, (D.obj j).a } /-- (Impl) A cocone for the diagram `(D ⋙ forget T) ⋙ T` found by composing the natural transformation `γ` with the colimiting cocone for `D ⋙ forget T`. -/ @[simps] def new_cocone : cocone ((D ⋙ forget T) ⋙ ↑T) := { X := c.X, ι := γ ≫ c.ι } variables [preserves_colimit (D ⋙ forget T) (T : C ⥤ C)] /-- (Impl) Define the map `λ : TL ⟶ L`, which will serve as the structure of the coalgebra on `L`, and we will show is the colimiting object. We use the cocone constructed by `c` and the fact that `T` preserves colimits to produce this morphism. -/ @[reducible] def lambda : ((T : C ⥤ C).map_cocone c).X ⟶ c.X := (preserves_colimit.preserves t).desc (new_cocone c) /-- (Impl) The key property defining the map `λ : TL ⟶ L`. -/ lemma commuting (j : J) : T.map (c.ι.app j) ≫ lambda c t = (D.obj j).a ≫ c.ι.app j := is_colimit.fac (preserves_colimit.preserves t) (new_cocone c) j variables [preserves_colimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] /-- (Impl) Construct the colimiting algebra from the map `λ : TL ⟶ L` given by `lambda`. We are required to show it satisfies the two algebra laws, which follow from the algebra laws for the image of `D` and our `commuting` lemma. -/ @[simps] def cocone_point : algebra T := { A := c.X, a := lambda c t, unit' := begin apply t.hom_ext, intro j, erw [comp_id, ← category.assoc, T.η.naturality, category.assoc, commuting, ← category.assoc], erw algebra.unit, apply id_comp end, assoc' := begin apply is_colimit.hom_ext (preserves_colimit.preserves (preserves_colimit.preserves t)), intro j, erw [← category.assoc, T.μ.naturality, ← functor.map_cocone_ι_app, category.assoc, is_colimit.fac _ (new_cocone c) j], rw ← category.assoc, erw [← functor.map_comp, commuting], dsimp, erw [← category.assoc, algebra.assoc, category.assoc, functor.map_comp, category.assoc, commuting], apply_instance, apply_instance end } /-- (Impl) Construct the lifted cocone in `algebra T` which will be colimiting. -/ @[simps] def lifted_cocone : cocone D := { X := cocone_point c t, ι := { app := λ j, { f := c.ι.app j, h' := commuting _ _ _ }, naturality' := λ A B f, by { ext1, dsimp, erw [comp_id, c.w] } } } /-- (Impl) Prove that the lifted cocone is colimiting. -/ @[simps] def lifted_cocone_is_colimit : is_colimit (lifted_cocone c t) := { desc := λ s, { f := t.desc ((forget T).map_cocone s), h' := begin dsimp, apply is_colimit.hom_ext (preserves_colimit.preserves t), intro j, rw ← category.assoc, erw ← functor.map_comp, erw t.fac', rw ← category.assoc, erw forget_creates_colimits.commuting, rw category.assoc, rw t.fac', apply algebra.hom.h, apply_instance end }, uniq' := λ s m J, by { ext1, apply t.hom_ext, intro j, simpa using congr_arg algebra.hom.f (J j) } } end forget_creates_colimits open forget_creates_colimits -- TODO: the converse of this is true as well /-- The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit which the monad itself preserves. -/ noncomputable instance forget_creates_colimit (D : J ⥤ algebra T) [preserves_colimit (D ⋙ forget T) (T : C ⥤ C)] [preserves_colimit ((D ⋙ forget T) ⋙ ↑T) (T : C ⥤ C)] : creates_colimit D (forget T) := creates_colimit_of_reflects_iso $ λ c t, { lifted_cocone := { X := cocone_point c t, ι := { app := λ j, { f := c.ι.app j, h' := commuting _ _ _ }, naturality' := λ A B f, by { ext1, dsimp, erw [comp_id, c.w] } } }, valid_lift := cocones.ext (iso.refl _) (by tidy), makes_colimit := lifted_cocone_is_colimit _ _ } noncomputable instance forget_creates_colimits_of_shape [preserves_colimits_of_shape J (T : C ⥤ C)] : creates_colimits_of_shape J (forget T) := { creates_colimit := λ K, by apply_instance } noncomputable instance forget_creates_colimits [preserves_colimits (T : C ⥤ C)] : creates_colimits (forget T) := { creates_colimits_of_shape := λ J 𝒥₁, by apply_instance } /-- For `D : J ⥤ algebra T`, `D ⋙ forget T` has a colimit, then `D` has a colimit provided colimits of shape `J` are preserved by `T`. -/ lemma forget_creates_colimits_of_monad_preserves [preserves_colimits_of_shape J (T : C ⥤ C)] (D : J ⥤ algebra T) [has_colimit (D ⋙ forget T)] : has_colimit D := has_colimit_of_created D (forget T) end monad variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₁} D] variables {J : Type v₁} [small_category J] instance comp_comparison_forget_has_limit (F : J ⥤ D) (R : D ⥤ C) [monadic_right_adjoint R] [has_limit (F ⋙ R)] : has_limit ((F ⋙ monad.comparison (adjunction.of_right_adjoint R)) ⋙ monad.forget _) := @has_limit_of_iso _ _ _ _ (F ⋙ R) _ _ (iso_whisker_left F (monad.comparison_forget (adjunction.of_right_adjoint R)).symm) instance comp_comparison_has_limit (F : J ⥤ D) (R : D ⥤ C) [monadic_right_adjoint R] [has_limit (F ⋙ R)] : has_limit (F ⋙ monad.comparison (adjunction.of_right_adjoint R)) := monad.has_limit_of_comp_forget_has_limit (F ⋙ monad.comparison (adjunction.of_right_adjoint R)) /-- Any monadic functor creates limits. -/ noncomputable def monadic_creates_limits (R : D ⥤ C) [monadic_right_adjoint R] : creates_limits R := creates_limits_of_nat_iso (monad.comparison_forget (adjunction.of_right_adjoint R)) /-- The forgetful functor from the Eilenberg-Moore category for a monad creates any colimit which the monad itself preserves. -/ noncomputable def monadic_creates_colimit_of_preserves_colimit (R : D ⥤ C) (K : J ⥤ D) [monadic_right_adjoint R] [preserves_colimit (K ⋙ R) (left_adjoint R ⋙ R)] [preserves_colimit ((K ⋙ R) ⋙ left_adjoint R ⋙ R) (left_adjoint R ⋙ R)] : creates_colimit K R := begin apply creates_colimit_of_nat_iso (monad.comparison_forget (adjunction.of_right_adjoint R)), apply category_theory.comp_creates_colimit _ _, apply_instance, let i : ((K ⋙ monad.comparison (adjunction.of_right_adjoint R)) ⋙ monad.forget _) ≅ K ⋙ R := functor.associator _ _ _ ≪≫ iso_whisker_left K (monad.comparison_forget (adjunction.of_right_adjoint R)), apply category_theory.monad.forget_creates_colimit _, { dsimp, refine preserves_colimit_of_iso_diagram _ i.symm }, { dsimp, refine preserves_colimit_of_iso_diagram _ (iso_whisker_right i (left_adjoint R ⋙ R)).symm }, end /-- A monadic functor creates any colimits of shapes it preserves. -/ noncomputable def monadic_creates_colimits_of_shape_of_preserves_colimits_of_shape (R : D ⥤ C) [monadic_right_adjoint R] [preserves_colimits_of_shape J R] : creates_colimits_of_shape J R := begin have : preserves_colimits_of_shape J (left_adjoint R ⋙ R), { apply category_theory.limits.comp_preserves_colimits_of_shape _ _, { haveI := adjunction.left_adjoint_preserves_colimits (adjunction.of_right_adjoint R), apply_instance }, apply_instance }, exactI ⟨λ K, monadic_creates_colimit_of_preserves_colimit _ _⟩, end /-- A monadic functor creates colimits if it preserves colimits. -/ noncomputable def monadic_creates_colimits_of_preserves_colimits (R : D ⥤ C) [monadic_right_adjoint R] [preserves_colimits R] : creates_colimits R := { creates_colimits_of_shape := λ J 𝒥₁, by exactI monadic_creates_colimits_of_shape_of_preserves_colimits_of_shape _ } section lemma has_limit_of_reflective (F : J ⥤ D) (R : D ⥤ C) [has_limit (F ⋙ R)] [reflective R] : has_limit F := by { haveI := monadic_creates_limits R, exact has_limit_of_created F R } /-- If `C` has limits of shape `J` then any reflective subcategory has limits of shape `J`. -/ lemma has_limits_of_shape_of_reflective [has_limits_of_shape J C] (R : D ⥤ C) [reflective R] : has_limits_of_shape J D := { has_limit := λ F, has_limit_of_reflective F R } /-- If `C` has limits then any reflective subcategory has limits. -/ lemma has_limits_of_reflective (R : D ⥤ C) [has_limits C] [reflective R] : has_limits D := { has_limits_of_shape := λ J 𝒥₁, by exactI has_limits_of_shape_of_reflective R } /-- If `C` has colimits of shape `J` then any reflective subcategory has colimits of shape `J`. -/ lemma has_colimits_of_shape_of_reflective (R : D ⥤ C) [reflective R] [has_colimits_of_shape J C] : has_colimits_of_shape J D := { has_colimit := λ F, begin let c := (left_adjoint R).map_cocone (colimit.cocone (F ⋙ R)), letI := (adjunction.of_right_adjoint R).left_adjoint_preserves_colimits, let t : is_colimit c := is_colimit_of_preserves (left_adjoint R) (colimit.is_colimit _), apply has_colimit.mk ⟨_, (is_colimit.precompose_inv_equiv _ _).symm t⟩, apply (iso_whisker_left F (as_iso (adjunction.of_right_adjoint R).counit) : _) ≪≫ F.right_unitor, end } /-- If `C` has colimits then any reflective subcategory has colimits. -/ lemma has_colimits_of_reflective (R : D ⥤ C) [reflective R] [has_colimits C] : has_colimits D := { has_colimits_of_shape := λ J 𝒥, by exactI has_colimits_of_shape_of_reflective R } /-- The reflector always preserves terminal objects. Note this in general doesn't apply to any other limit. -/ noncomputable def left_adjoint_preserves_terminal_of_reflective (R : D ⥤ C) [reflective R] [has_terminal C] : preserves_limits_of_shape (discrete pempty) (left_adjoint R) := { preserves_limit := λ K, begin letI : has_terminal D := has_limits_of_shape_of_reflective R, letI := monadic_creates_limits R, letI := category_theory.preserves_limit_of_creates_limit_and_has_limit (functor.empty _) R, letI : preserves_limit (functor.empty _) (left_adjoint R), { apply preserves_terminal_of_iso, apply _ ≪≫ as_iso ((adjunction.of_right_adjoint R).counit.app (⊤_ D)), apply (left_adjoint R).map_iso (preserves_terminal.iso R).symm }, apply preserves_limit_of_iso_diagram (left_adjoint R) (functor.unique_from_empty _).symm, end } end end category_theory
Require Export Reals Omega. Require Export Classical_Prop. Definition Complex : Set := R*R. Delimit Scope C_scope with C. Definition Cplus ( x y : Complex ) : Complex := match x, y with | (a,b) , (c,d) => (a+c,b+d)%R end. Definition Cmult ( x y : Complex ) : Complex := match x, y with | (a,b) , (c,d) => (a*c-b*d,a*d+b*c)%R end. Definition C0 : Complex := (0,0)%R. Definition C1 : Complex := (1,0)%R. Definition Ci : Complex := (0,1)%R. Definition Copp ( x: Complex ) : Complex := match x with | (a,b) => (-a,-b)%R end. Definition Cinv ( x: Complex ) : Complex := match x with | (a,b) => (a/(a*a+b*b),-b/(a*a+b*b))%R end. Theorem Real_eq_dec : forall r1 r2 : R , ({ r1 = r2 } + { r1 <> r2 })%R. Proof. intros. assert ({r1 < r2} + {r1 = r2} + {r1 > r2})%R. apply total_order_T. destruct H in H. destruct s. right. Admitted. Definition Clt ( x y : Complex ) : Prop := match x, y with | (a,b) , (c,d) => if (Real_eq_dec a c)%R then (b<d)%R else (a<c)%R end. Infix "+" := Cplus : C_scope. Infix "*" := Cmult : C_scope. Notation "- x" := (Copp x) : C_scope. Notation "/ x" := (Cinv x) : C_scope. Infix "<" := Clt : C_scope. Definition Cgt (r1 r2:Complex) : Prop := (r2 < r1)%C. Definition Cle (r1 r2:Complex) : Prop := (r1 < r2 \/ r1 = r2)%C. Definition Cge (r1 r2:Complex) : Prop := (Cgt r1 r2 \/ r1 = r2)%C. Definition Cminus (r1 r2:Complex) : Complex := (r1 + - r2)%C. Definition Cdiv (r1 r2:Complex) : Complex := (r1 * / r2)%C. Infix "-" := Cminus : C_scope. Infix "/" := Cdiv : C_scope. Infix "<=" := Cle : C_scope. Infix ">=" := Cge : C_scope. Infix ">" := Cgt : C_scope. Notation "x <= y <= z" := (x <= y /\ y <= z) : C_scope. Notation "x <= y < z" := (x <= y /\ y < z) : C_scope. Notation "x < y < z" := (x < y /\ y < z) : C_scope. Notation "x < y <= z" := (x < y /\ y <= z) : C_scope. (* end Cdefinition *) Definition real_p ( z: Complex ) := fst z. Definition imag_p ( z: Complex ) := snd z. Lemma Cdecompose : forall z : Complex , z = ( real_p z , imag_p z ). Proof. intros. apply surjective_pairing. Qed. Lemma Cplus_decompose : forall z1 z2 : Complex , ( z1 + z2 )%C = ( real_p z1 + real_p z2 , imag_p z1 + imag_p z2 )%R. Proof. intros. replace (z1 + z2)%C with (( real_p z1 , imag_p z1 )+( real_p z2 , imag_p z2 ))%C. unfold Cplus. auto. rewrite <- ! Cdecompose. auto. Qed. Lemma Cplus_comm : forall z1 z2:Complex, (z1 + z2 = z2 + z1)%C. Proof. intros. rewrite ! Cplus_decompose. apply injective_projections. simpl. ring. simpl. ring. Qed. Hint Resolve Cplus_comm : complex. Lemma Cplus_assoc : forall r1 r2 r3:Complex , (r1 + (r2 + r3) = r1 + r2 + r3)%C. Proof. intros. rewrite ! Cplus_decompose. apply injective_projections. simpl. ring. simpl. ring. Qed. Hint Resolve Cplus_assoc: complex. Lemma Cplus_opp_r : forall r:Complex, (r + -r = C0 )%C. Proof. intros. replace (r) with ( real_p r , imag_p r ). unfold Copp. apply injective_projections. simpl. ring. simpl. ring. apply eq_sym. apply Cdecompose. Qed. Hint Resolve Cplus_opp_r: complex. Lemma Cplus_0_l : forall r:Complex , (C0 + r = r)%C. Proof. intros. rewrite ! Cplus_decompose. unfold real_p. unfold imag_p. apply injective_projections. simpl. ring. simpl. ring. Qed. Hint Resolve Cplus_0_l: complex. Lemma Cmult_decompose : forall z1 z2 : Complex , ( z1 * z2 )%C = ( real_p z1 * real_p z2 - imag_p z1 * imag_p z2 , real_p z1 * imag_p z2 + imag_p z1 * real_p z2 )%R. Proof. intros. replace (z1 * z2)%C with (( real_p z1 , imag_p z1 )*( real_p z2 , imag_p z2 ))%C. unfold Cplus. auto. rewrite <- ! Cdecompose. auto. Qed. Lemma Cmult_comm : forall r1 r2:Complex, (r1 * r2 = r2 * r1)%C. Proof. intros. rewrite ! Cmult_decompose. apply injective_projections. simpl. ring. simpl. ring. Qed. Hint Resolve Cmult_comm: complex. Lemma Cmult_assoc : forall r1 r2 r3:Complex, (r1 * (r2 * r3) = r1 * r2 * r3)%C. Proof. intros. rewrite ! Cmult_decompose. apply injective_projections. simpl. ring. simpl. ring. Qed. Hint Resolve Cmult_assoc: complex. Local Open Scope R_scope. Lemma Ra2b2n0 : forall a b : R , a<>0 \/ b<>0 -> 0<a*a+b*b. Proof. intros. assert ( 0 <= a * a ). replace ( a * a ) with (a^2) ; [idtac | ring ]. apply pow2_ge_0 with ( x := a ). assert ( 0 <= b * b ). replace ( b * b ) with (b^2) ; [idtac | ring ]. apply pow2_ge_0 with ( x := b ). unfold Rle in H0. case H0. intros. replace 0 with (0+0); [ idtac | ring ]. apply Rplus_gt_ge_compat. auto. apply Rle_ge. auto. intros. assert (b<>0). assert ( a=0). apply eq_sym in H2. apply Rmult_integral in H2. case H2. auto. auto. case H. contradiction. auto. assert ( b * b <> 0). auto. assert ( 0 < b * b ). case H1. auto. intros. apply eq_sym in H5. contradiction. replace 0 with (0+0); [ idtac | ring ]. apply Rplus_ge_gt_compat. rewrite <- H2. auto with real. auto with real. Qed. Local Close Scope R_scope. Lemma Cinv_l : forall r:Complex, (r <> C0 -> / r * r = C1)%C. Proof. intros. replace (r) with ( real_p r , imag_p r ). assert ( real_p r <> 0 \/ imag_p r <> 0)%R as orenq. apply Peirce. intros. apply not_or_and in H0. destruct H0 as [rp0 ip0]. apply NNPP in rp0. apply NNPP in ip0. elim H. replace (r) with ( real_p r , imag_p r ). unfold C0. apply injective_projections. auto. auto. apply eq_sym. apply Cdecompose. assert((real_p r * real_p r + imag_p r * imag_p r)%R <> 0%R). unfold not. intros. assert ( 0<(real_p r * real_p r + imag_p r * imag_p r)%R )%R. apply Ra2b2n0. auto. rewrite H0 in H1. apply Rlt_irrefl in H1. auto. unfold Cinv. unfold C1. apply injective_projections. simpl. field. auto. simpl. field. auto. rewrite Cdecompose. auto. Qed. Hint Resolve Cinv_l: complex. Lemma Cmult_1_l : forall r:Complex, (C1 * r = r)%C. Proof. intros. replace (r) with ( real_p r , imag_p r ). rewrite ! Cmult_decompose. apply injective_projections. simpl. ring. simpl. ring. rewrite Cdecompose. auto. Qed. Hint Resolve Cmult_1_l: complex. Lemma Cmult_0_l : forall r:Complex, (C0 * r = C0)%C. Proof. intros. unfold C0. replace (r) with ( real_p r , imag_p r ). rewrite ! Cmult_decompose. apply injective_projections. simpl. ring. simpl. ring. rewrite Cdecompose. auto. Qed. Hint Resolve Cmult_0_l: complex. Lemma C1_neq_C0 : C1 <> C0. Proof. unfold not. intros. assert ( real_p C1 = 1 )%R. auto. assert ( real_p C1 = 0 )%R. rewrite H. auto. auto with real. Qed. Hint Resolve C1_neq_C0: complex. Lemma Cmult_plus_distr_r : forall r2 r3 r1:Complex, ((r2 + r3)*r1 = r2*r1 + r3 * r1)%C. Proof. intros. rewrite ! Cplus_decompose. rewrite ! Cmult_decompose. apply injective_projections. simpl. ring. simpl. ring. Qed. Hint Resolve Cmult_plus_distr_r: complex. Lemma complexSRth : ring_theory C0 C1 Cplus Cmult Cminus Copp (@eq Complex). Proof. constructor. exact Cplus_0_l. exact Cplus_comm. exact Cplus_assoc. exact Cmult_1_l. exact Cmult_comm. exact Cmult_assoc. exact Cmult_plus_distr_r. auto. exact Cplus_opp_r. Qed. Add Ring complexr : complexSRth.
-- @@stderr -- dtrace: failed to compile script test/unittest/lexer/err.D_SYNTAX.brace1.d: [D_SYNTAX] line 18: syntax error near "}"
theory Assign imports Main begin subsection \<open> preparation \<close> consts order :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixr "\<sqsubseteq>" 60) type_synonym 'a proc = "('a \<times> 'a) list" consts uskip :: "'a proc" ("II") consts uzero :: "'a proc" ("\<bottom>") lemma "[x,y,z]@[u] = [x,y,z,u]" by simp lemma "set [a,b,c,a] = {a,b,c,a}" by simp lemma "zip [a,b,c] [x,y,z] = [(a,x),(b,y),(c,z)]" by simp lemma "map f [a,b] = [f a,f b]" by simp lemma "fst (a,b) = a" by simp subsection \<open>assignment operater \<close> class assi = fixes assi :: "'a list\<Rightarrow> 'a list\<Rightarrow> 'a proc" (infixl ":=" 65) assumes assi_equal: "set (zip X A) = set(zip Y B) \<Longrightarrow> X := A = Y:=B" and assi_orde1: "set (zip X A) \<subseteq> set(zip Y B) \<Longrightarrow> X := A \<sqsubseteq> Y:=B" and assi_orde2: "X := A \<sqsubseteq> Y:=B \<Longrightarrow> set (zip X A) \<subseteq> set(zip Y B)" and assi_uskip: "set (zip u u) = {}" assumes assi_setadd: "Z = X @ Y \<Longrightarrow> c= A @ B \<Longrightarrow>set (zip Z C) = set (zip X A) \<union> set(zip Y B) " lemma l1:" [x,y,z] := [a,b,c] = [x,y,z,u] := [a,b,c,u]" by (metis append.right_neutral assi_equal assi_setadd assi_uskip) lemma l2: "[x,y,z,w] := [a,b,c,d] = [x,y,w,z] := [a,b,d,c]" proof - have f1: "set (zip [x,y,w,z] [a,b,d,c]) = set (zip [x,y,z,w] [a,b,c,d])" by (simp add: insert_commute) show ?thesis using assi_equal f1 by blast qed lemma l4: "[x,y,z] := [a,b,c] \<sqsubseteq> [x,y,z,w] := [a,b,c,d]" by (simp add: assi_orde1) class serial = assi + fixes nep :: "'a proc \<Rightarrow>'a proc \<Rightarrow>'a proc" (infixl ";;" 60) assumes serial_assoc : "(x ;; y) ;; z = x ;; (y ;; z)" and serial_skip_left : "II ;; x = x" and serial_skip_right : "x ;; II = x" assumes assi_serial_map : "X:=A ;; X:=map f X = X:=map f A" lemma l3: "[x,y]:=[a,b] ;; [x,y]:= [f x,f y] = [x,y]:=[f a,f b]" by (metis (mono_tags, hide_lams) assi_serial_map insert_Nil list.simps(8) list.simps(9)) end
{-# OPTIONS --cubical-compatible #-} open import Agda.Builtin.Nat open import Agda.Builtin.Equality data Fin : Nat → Set where zero : {n : Nat} → Fin (suc n) suc : {n : Nat} (i : Fin n) → Fin (suc n) -- From Data.Fin.Properties in the standard library (2016-12-30). suc-injective : ∀ {o} {m n : Fin o} → Fin.suc m ≡ suc n → m ≡ n suc-injective refl = refl
Bosch Security Systems was chosen as the central supplier for the security systems at Marmara Park Shopping Center in Istanbul, one of the largest of its kind in Turkey. The shopping center is completely designed in a galaxy-theme. Space-related lighting, planet models and a theme park for visitors form the individual identity of the shopping center. The networked and integrated security solution from Bosch comprises fire and voice evacuation systems, video surveillance, access control, and intrusion detection. All of these systems are centrally managed and operated via Bosch's Building Integration System. With a total floor space of 100,000 square meters, 250 individual shops and restaurants, a hypermarket, a cinema complex and parking for 4,000 cars, Marmara Park serves approximately 40,000 customers per day. More than 2,400 jobs were created within the shopping center developed by ECE Türkiye. In 2013 it was awarded the MIPIM award in the shopping center category, one of the world's most prestigious awards in real estate development. To enable the highest security level for customers, employees and suppliers of Marmara Park, local Bosch partner Entegre designed a highly modular and scalable security system that meets all the standards as set in norm EN54. The Bosch fire alarm system consists of four networked Modular Fire Panel 5000 Series with 59 loops supporting more than 5,000 fire detectors. It is tightly integrated with the Bosch PRAESIDEO voice evacuation system which can also be used for announcements and background music in normal operations. This system with 64 amplifiers supports 140 independent zones, allowing targeted messaging in case of an evacuation. Video surveillance of the entire premises has been realized using almost 300 cameras and 18 digital video recorders. In addition, Entegre installed a comprehensive access control system for non-public areas within the centre as well as the addressable intrusion detection system Modular Alarm Platform MAP 5000 from Bosch with more than 1,000 detectors. This allows the operator to exactly locate every alarm in real time, enabling fast response to any incident. The same holds true for the panic buttons which have been installed in all of the shops. Being a tightly integrated solution, the entire security system can be configured and operated very efficiently from one central location or distributed consoles. The open architecture makes it highly scalable and adaptable to future additions or changing requirements.
-- ---------------------------------------------------------------- [ TODO.idr ] -- Module : TODO.idr -- Copyright : (c) Jan de Muijnck-Hughes -- License : see LICENSE -- --------------------------------------------------------------------- [ EOH ] module GRL.Test.DSML.TODO import Data.DList import GRL.Lang.GLang -- ------------------------------------------------------------------- [ Types ] data Ty = TyITEM | TyTASK -- ------------------------------------------------------------- [ Interpreter ] data IRes : Ty -> Type where IResItem : GLang ELEM -> IRes TyITEM IResTask : GLang ELEM -> GLang INTENT -> IRes TyTASK interpItem : String -> Maybe SValue -> IRes TyITEM interpItem title Nothing = IResItem $ mkGoal title interpItem title (Just sval) = IResItem $ mkSatGoal title sval interpTask : String -> SValue -> IRes TyITEM -> IRes TyTASK interpTask t s (IResItem to) = IResTask elem link where elem : GLang ELEM elem = mkSatTask t s link : GLang INTENT link = (elem ==> to | MAKES) buildModel : String -> List (IRes TyITEM) -> List (IRes TyTASK) -> GModel buildModel n is ts = insertMany tis $ insertMany tes m where root : GLang ELEM root = mkGoal n es : List (GLang ELEM) es = map (\(IResItem x) => x) is toRoot : GLang STRUCT toRoot = (root &= es) m : GModel m = insert toRoot $ insertMany (root::es) emptyModel ties : List (GLang ELEM, GLang INTENT) ties = map (\(IResTask e i) => (e,i)) ts tis : List (GLang ELEM) tis = map fst ties tes : List (GLang INTENT) tes = map snd ties -- --------------------------------------------------------- [ Data Structures ] data TODOItem : (ty : Ty) -> IRes ty -> Type where Done : (title : String) -> (desc : Maybe String) -> TODOItem TyITEM (interpItem title (Just SATISFIED)) TODO : (title : String) -> (desc : Maybe String) -> TODOItem TyITEM (interpItem title Nothing) Action : (title : String) -> (desc : Maybe String) -> (value : SValue) -> (todo : TODOItem TyITEM e) -> TODOItem TyTASK (interpTask title value e) data TODOList : GModel -> Type where MyList : (name : String) -> DList (IRes TyITEM) (\res => TODOItem TyITEM res) is -> DList (IRes TyTASK) (\res => TODOItem TyTASK res) ts -> TODOList (buildModel name is ts) -- --------------------------------------------------------------------- [ EOF ]
module GGT.Bundles where open import Level open import Relation.Unary open import Relation.Binary -- using (Rel) open import Algebra.Core open import Algebra.Bundles open import GGT.Structures open import Data.Product -- do we need a left action definition? -- parametrize over Op r/l? record Action a b ℓ₁ ℓ₂ : Set (suc (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂)) where infixl 6 _·_ infix 3 _≋_ open Group hiding (setoid) field G : Group a ℓ₁ Ω : Set b _≋_ : Rel Ω ℓ₂ _·_ : Opᵣ (Carrier G) Ω isAction : IsAction (_≈_ G) _≋_ _·_ (_∙_ G) (ε G) (_⁻¹ G) open IsAction isAction public -- the (raw) pointwise stabilizer stab : Ω → Pred (Carrier G) ℓ₂ stab o = λ (g : Carrier G) → o · g ≋ o -- Orbital relation _ω_ : Rel Ω (a ⊔ ℓ₂) o ω o' = ∃[ g ] (o · g ≋ o') _·G : Ω → Pred Ω (a ⊔ ℓ₂) o ·G = o ω_ -- Orbits open import GGT.Setoid setoid (a ⊔ ℓ₂) Orbit : Ω → Setoid (b ⊔ (a ⊔ ℓ₂)) ℓ₂ Orbit o = subSetoid (o ·G)
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import algebra.group.pi import algebra.group.prod import algebra.hom.iterate import logic.equiv.set /-! # The group of permutations (self-equivalences) of a type `α` > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines the `group` structure on `equiv.perm α`. -/ universes u v namespace equiv variables {α : Type u} {β : Type v} namespace perm instance perm_group : group (perm α) := { mul := λ f g, equiv.trans g f, one := equiv.refl α, inv := equiv.symm, mul_assoc := λ f g h, (trans_assoc _ _ _).symm, one_mul := trans_refl, mul_one := refl_trans, mul_left_inv := self_trans_symm } @[simp] lemma default_eq : (default : perm α) = 1 := rfl /-- The permutation of a type is equivalent to the units group of the endomorphisms monoid of this type. -/ @[simps] def equiv_units_End : perm α ≃* units (function.End α) := { to_fun := λ e, ⟨e, e.symm, e.self_comp_symm, e.symm_comp_self⟩, inv_fun := λ u, ⟨(u : function.End α), (↑u⁻¹ : function.End α), congr_fun u.inv_val, congr_fun u.val_inv⟩, left_inv := λ e, ext $ λ x, rfl, right_inv := λ u, units.ext rfl, map_mul' := λ e₁ e₂, rfl } /-- Lift a monoid homomorphism `f : G →* function.End α` to a monoid homomorphism `f : G →* equiv.perm α`. -/ @[simps] def _root_.monoid_hom.to_hom_perm {G : Type*} [group G] (f : G →* function.End α) : G →* perm α := equiv_units_End.symm.to_monoid_hom.comp f.to_hom_units theorem mul_apply (f g : perm α) (x) : (f * g) x = f (g x) := equiv.trans_apply _ _ _ theorem one_apply (x) : (1 : perm α) x = x := rfl @[simp] lemma inv_apply_self (f : perm α) (x) : f⁻¹ (f x) = x := f.symm_apply_apply x @[simp] lemma apply_inv_self (f : perm α) (x) : f (f⁻¹ x) = x := f.apply_symm_apply x lemma one_def : (1 : perm α) = equiv.refl α := rfl lemma mul_def (f g : perm α) : f * g = g.trans f := rfl lemma inv_def (f : perm α) : f⁻¹ = f.symm := rfl @[simp, norm_cast] lemma coe_one : ⇑(1 : perm α) = id := rfl @[simp, norm_cast] lemma coe_mul (f g : perm α) : ⇑(f * g) = f ∘ g := rfl @[norm_cast] lemma coe_pow (f : perm α) (n : ℕ) : ⇑(f ^ n) = (f^[n]) := hom_coe_pow _ rfl (λ _ _, rfl) _ _ @[simp] lemma iterate_eq_pow (f : perm α) (n : ℕ) : (f^[n]) = ⇑(f ^ n) := (coe_pow _ _).symm lemma eq_inv_iff_eq {f : perm α} {x y : α} : x = f⁻¹ y ↔ f x = y := f.eq_symm_apply lemma inv_eq_iff_eq {f : perm α} {x y : α} : f⁻¹ x = y ↔ x = f y := f.symm_apply_eq lemma zpow_apply_comm {α : Type*} (σ : perm α) (m n : ℤ) {x : α} : (σ ^ m) ((σ ^ n) x) = (σ ^ n) ((σ ^ m) x) := by rw [←equiv.perm.mul_apply, ←equiv.perm.mul_apply, zpow_mul_comm] @[simp] lemma image_inv (f : perm α) (s : set α) : ⇑f⁻¹ '' s = f ⁻¹' s := f⁻¹.image_eq_preimage _ @[simp] lemma preimage_inv (f : perm α) (s : set α) : ⇑f⁻¹ ⁻¹' s = f '' s := (f.image_eq_preimage _).symm /-! Lemmas about mixing `perm` with `equiv`. Because we have multiple ways to express `equiv.refl`, `equiv.symm`, and `equiv.trans`, we want simp lemmas for every combination. The assumption made here is that if you're using the group structure, you want to preserve it after simp. -/ @[simp] lemma trans_one {α : Sort*} {β : Type*} (e : α ≃ β) : e.trans (1 : perm β) = e := equiv.trans_refl e @[simp] lemma mul_refl (e : perm α) : e * equiv.refl α = e := equiv.trans_refl e @[simp] lemma one_symm : (1 : perm α).symm = 1 := equiv.refl_symm @[simp] lemma refl_inv : (equiv.refl α : perm α)⁻¹ = 1 := equiv.refl_symm @[simp] lemma one_trans {α : Type*} {β : Sort*} (e : α ≃ β) : (1 : perm α).trans e = e := equiv.refl_trans e @[simp] lemma refl_mul (e : perm α) : equiv.refl α * e = e := equiv.refl_trans e @[simp] lemma inv_trans_self (e : perm α) : e⁻¹.trans e = 1 := equiv.symm_trans_self e @[simp] lemma mul_symm (e : perm α) : e * e.symm = 1 := equiv.symm_trans_self e @[simp] lemma self_trans_inv (e : perm α) : e.trans e⁻¹ = 1 := equiv.self_trans_symm e @[simp] lemma symm_mul (e : perm α) : e.symm * e = 1 := equiv.self_trans_symm e /-! Lemmas about `equiv.perm.sum_congr` re-expressed via the group structure. -/ @[simp] lemma sum_congr_mul {α β : Type*} (e : perm α) (f : perm β) (g : perm α) (h : perm β) : sum_congr e f * sum_congr g h = sum_congr (e * g) (f * h) := sum_congr_trans g h e f @[simp] lemma sum_congr_inv {α β : Type*} (e : perm α) (f : perm β) : (sum_congr e f)⁻¹ = sum_congr e⁻¹ f⁻¹ := sum_congr_symm e f @[simp] lemma sum_congr_one {α β : Type*} : sum_congr (1 : perm α) (1 : perm β) = 1 := sum_congr_refl /-- `equiv.perm.sum_congr` as a `monoid_hom`, with its two arguments bundled into a single `prod`. This is particularly useful for its `monoid_hom.range` projection, which is the subgroup of permutations which do not exchange elements between `α` and `β`. -/ @[simps] def sum_congr_hom (α β : Type*) : perm α × perm β →* perm (α ⊕ β) := { to_fun := λ a, sum_congr a.1 a.2, map_one' := sum_congr_one, map_mul' := λ a b, (sum_congr_mul _ _ _ _).symm} lemma sum_congr_hom_injective {α β : Type*} : function.injective (sum_congr_hom α β) := begin rintros ⟨⟩ ⟨⟩ h, rw prod.mk.inj_iff, split; ext i, { simpa using equiv.congr_fun h (sum.inl i), }, { simpa using equiv.congr_fun h (sum.inr i), }, end @[simp] lemma sum_congr_swap_one {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : α) : sum_congr (equiv.swap i j) (1 : perm β) = equiv.swap (sum.inl i) (sum.inl j) := sum_congr_swap_refl i j @[simp] lemma sum_congr_one_swap {α β : Type*} [decidable_eq α] [decidable_eq β] (i j : β) : sum_congr (1 : perm α) (equiv.swap i j) = equiv.swap (sum.inr i) (sum.inr j) := sum_congr_refl_swap i j /-! Lemmas about `equiv.perm.sigma_congr_right` re-expressed via the group structure. -/ @[simp] lemma sigma_congr_right_mul {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) (G : Π a, perm (β a)) : sigma_congr_right F * sigma_congr_right G = sigma_congr_right (F * G) := sigma_congr_right_trans G F @[simp] lemma sigma_congr_right_inv {α : Type*} {β : α → Type*} (F : Π a, perm (β a)) : (sigma_congr_right F)⁻¹ = sigma_congr_right (λ a, (F a)⁻¹) := sigma_congr_right_symm F @[simp] lemma sigma_congr_right_one {α : Type*} {β : α → Type*} : (sigma_congr_right (1 : Π a, equiv.perm $ β a)) = 1 := sigma_congr_right_refl /-- `equiv.perm.sigma_congr_right` as a `monoid_hom`. This is particularly useful for its `monoid_hom.range` projection, which is the subgroup of permutations which do not exchange elements between fibers. -/ @[simps] def sigma_congr_right_hom {α : Type*} (β : α → Type*) : (Π a, perm (β a)) →* perm (Σ a, β a) := { to_fun := sigma_congr_right, map_one' := sigma_congr_right_one, map_mul' := λ a b, (sigma_congr_right_mul _ _).symm } lemma sigma_congr_right_hom_injective {α : Type*} {β : α → Type*} : function.injective (sigma_congr_right_hom β) := begin intros x y h, ext a b, simpa using equiv.congr_fun h ⟨a, b⟩, end /-- `equiv.perm.subtype_congr` as a `monoid_hom`. -/ @[simps] def subtype_congr_hom (p : α → Prop) [decidable_pred p] : (perm {a // p a}) × (perm {a // ¬ p a}) →* perm α := { to_fun := λ pair, perm.subtype_congr pair.fst pair.snd, map_one' := perm.subtype_congr.refl, map_mul' := λ _ _, (perm.subtype_congr.trans _ _ _ _).symm } lemma subtype_congr_hom_injective (p : α → Prop) [decidable_pred p] : function.injective (subtype_congr_hom p) := begin rintros ⟨⟩ ⟨⟩ h, rw prod.mk.inj_iff, split; ext i; simpa using equiv.congr_fun h i end /-- If `e` is also a permutation, we can write `perm_congr` completely in terms of the group structure. -/ @[simp] lemma perm_congr_eq_mul (e p : perm α) : e.perm_congr p = e * p * e⁻¹ := rfl section extend_domain /-! Lemmas about `equiv.perm.extend_domain` re-expressed via the group structure. -/ variables (e : perm α) {p : β → Prop} [decidable_pred p] (f : α ≃ subtype p) @[simp] lemma extend_domain_one : extend_domain 1 f = 1 := extend_domain_refl f @[simp] lemma extend_domain_inv : (e.extend_domain f)⁻¹ = e⁻¹.extend_domain f := rfl @[simp] lemma extend_domain_mul (e e' : perm α) : (e.extend_domain f) * (e'.extend_domain f) = (e * e').extend_domain f := extend_domain_trans _ _ _ /-- `extend_domain` as a group homomorphism -/ @[simps] def extend_domain_hom : perm α →* perm β := { to_fun := λ e, extend_domain e f, map_one' := extend_domain_one f, map_mul' := λ e e', (extend_domain_mul f e e').symm } lemma extend_domain_hom_injective : function.injective (extend_domain_hom f) := (injective_iff_map_eq_one (extend_domain_hom f)).mpr (λ e he, ext (λ x, f.injective (subtype.ext ((extend_domain_apply_image e f x).symm.trans (ext_iff.mp he (f x)))))) @[simp] @[simp] lemma extend_domain_pow (n : ℕ) : (e ^ n).extend_domain f = e.extend_domain f ^ n := map_pow (extend_domain_hom f) _ _ @[simp] lemma extend_domain_zpow (n : ℤ) : (e ^ n).extend_domain f = e.extend_domain f ^ n := map_zpow (extend_domain_hom f) _ _ end extend_domain section subtype variables {p : α → Prop} {f : perm α} /-- If the permutation `f` fixes the subtype `{x // p x}`, then this returns the permutation on `{x // p x}` induced by `f`. -/ def subtype_perm (f : perm α) (h : ∀ x, p x ↔ p (f x)) : perm {x // p x} := ⟨λ x, ⟨f x, (h _).1 x.2⟩, λ x, ⟨f⁻¹ x, (h (f⁻¹ x)).2 $ by simpa using x.2⟩, λ _, by simp only [perm.inv_apply_self, subtype.coe_eta, subtype.coe_mk], λ _, by simp only [perm.apply_inv_self, subtype.coe_eta, subtype.coe_mk]⟩ @[simp] lemma subtype_perm_apply (f : perm α) (h : ∀ x, p x ↔ p (f x)) (x : {x // p x}) : subtype_perm f h x = ⟨f x, (h _).1 x.2⟩ := rfl @[simp] lemma subtype_perm_one (p : α → Prop) (h := λ _, iff.rfl) : @subtype_perm α p 1 h = 1 := equiv.ext $ λ ⟨_, _⟩, rfl @[simp] lemma subtype_perm_mul (f g : perm α) (hf hg) : (f.subtype_perm hf * g.subtype_perm hg : perm {x // p x}) = (f * g).subtype_perm (λ x, (hg _).trans $ hf _) := rfl private lemma inv_aux : (∀ x, p x ↔ p (f x)) ↔ ∀ x, p x ↔ p (f⁻¹ x) := f⁻¹.surjective.forall.trans $ by simp_rw [f.apply_inv_self, iff.comm] /-- See `equiv.perm.inv_subtype_perm`-/ lemma subtype_perm_inv (f : perm α) (hf) : f⁻¹.subtype_perm hf = (f.subtype_perm $ inv_aux.2 hf : perm {x // p x})⁻¹ := rfl /-- See `equiv.perm.subtype_perm_inv`-/ @[simp] lemma inv_subtype_perm (f : perm α) (hf) : (f.subtype_perm hf : perm {x // p x})⁻¹ = f⁻¹.subtype_perm (inv_aux.1 hf) := rfl private lemma pow_aux (hf : ∀ x, p x ↔ p (f x)) : ∀ {n : ℕ} x, p x ↔ p ((f ^ n) x) | 0 x := iff.rfl | (n + 1) x := (pow_aux _).trans (hf _) @[simp] lemma subtype_perm_pow (f : perm α) (n : ℕ) (hf) : (f.subtype_perm hf : perm {x // p x}) ^ n = (f ^ n).subtype_perm (pow_aux hf) := begin induction n with n ih, { simp }, { simp_rw [pow_succ', ih, subtype_perm_mul] } end private lemma zpow_aux (hf : ∀ x, p x ↔ p (f x)) : ∀ {n : ℤ} x, p x ↔ p ((f ^ n) x) | (int.of_nat n) := pow_aux hf | (int.neg_succ_of_nat n) := by { rw zpow_neg_succ_of_nat, exact inv_aux.1 (pow_aux hf) } @[simp] lemma subtype_perm_zpow (f : perm α) (n : ℤ) (hf) : (f.subtype_perm hf ^ n : perm {x // p x}) = (f ^ n).subtype_perm (zpow_aux hf) := begin induction n with n ih, { exact subtype_perm_pow _ _ _ }, { simp only [zpow_neg_succ_of_nat, subtype_perm_pow, subtype_perm_inv] } end variables [decidable_pred p] {a : α} /-- The inclusion map of permutations on a subtype of `α` into permutations of `α`, fixing the other points. -/ def of_subtype : perm (subtype p) →* perm α := { to_fun := λ f, extend_domain f (equiv.refl (subtype p)), map_one' := equiv.perm.extend_domain_one _, map_mul' := λ f g, (equiv.perm.extend_domain_mul _ f g).symm, } lemma of_subtype_subtype_perm {f : perm α} (h₁ : ∀ x, p x ↔ p (f x)) (h₂ : ∀ x, f x ≠ x → p x) : of_subtype (subtype_perm f h₁) = f := equiv.ext $ λ x, begin by_cases hx : p x, { exact (subtype_perm f h₁).extend_domain_apply_subtype _ hx, }, { rw [of_subtype, monoid_hom.coe_mk, equiv.perm.extend_domain_apply_not_subtype], { exact not_not.mp (λ h, hx (h₂ x (ne.symm h))), }, { exact hx, }, } end lemma of_subtype_apply_of_mem (f : perm (subtype p)) (ha : p a) : of_subtype f a = f ⟨a, ha⟩ := extend_domain_apply_subtype _ _ _ @[simp] lemma of_subtype_apply_coe (f : perm (subtype p)) (x : subtype p) : of_subtype f x = f x := subtype.cases_on x $ λ _, of_subtype_apply_of_mem f lemma of_subtype_apply_of_not_mem (f : perm (subtype p)) (ha : ¬ p a) : of_subtype f a = a := extend_domain_apply_not_subtype _ _ ha lemma mem_iff_of_subtype_apply_mem (f : perm (subtype p)) (x : α) : p x ↔ p ((of_subtype f : α → α) x) := if h : p x then by simpa only [h, true_iff, monoid_hom.coe_mk, of_subtype_apply_of_mem f h] using (f ⟨x, h⟩).2 else by simp [h, of_subtype_apply_of_not_mem f h] @[simp] lemma subtype_perm_of_subtype (f : perm (subtype p)) : subtype_perm (of_subtype f) (mem_iff_of_subtype_apply_mem f) = f := equiv.ext $ λ x, subtype.coe_injective (of_subtype_apply_coe f x) /-- Permutations on a subtype are equivalent to permutations on the original type that fix pointwise the rest. -/ @[simps] protected def subtype_equiv_subtype_perm (p : α → Prop) [decidable_pred p] : perm (subtype p) ≃ {f : perm α // ∀ a, ¬p a → f a = a} := { to_fun := λ f, ⟨f.of_subtype, λ a, f.of_subtype_apply_of_not_mem⟩, inv_fun := λ f, (f : perm α).subtype_perm (λ a, ⟨decidable.not_imp_not.1 $ λ hfa, (f.val.injective (f.prop _ hfa) ▸ hfa), decidable.not_imp_not.1 $ λ ha hfa, ha $ f.prop a ha ▸ hfa⟩), left_inv := equiv.perm.subtype_perm_of_subtype, right_inv := λ f, subtype.ext (equiv.perm.of_subtype_subtype_perm _ $ λ a, not.decidable_imp_symm $ f.prop a) } lemma subtype_equiv_subtype_perm_apply_of_mem (f : perm (subtype p)) (h : p a) : perm.subtype_equiv_subtype_perm p f a = f ⟨a, h⟩ := f.of_subtype_apply_of_mem h lemma subtype_equiv_subtype_perm_apply_of_not_mem (f : perm (subtype p)) (h : ¬ p a) : perm.subtype_equiv_subtype_perm p f a = a := f.of_subtype_apply_of_not_mem h end subtype end perm section swap variables [decidable_eq α] @[simp] lemma swap_inv (x y : α) : (swap x y)⁻¹ = swap x y := rfl @[simp] lemma swap_mul_self (i j : α) : swap i j * swap i j = 1 := swap_swap i j lemma swap_mul_eq_mul_swap (f : perm α) (x y : α) : swap x y * f = f * swap (f⁻¹ x) (f⁻¹ y) := equiv.ext $ λ z, begin simp only [perm.mul_apply, swap_apply_def], split_ifs; simp only [perm.apply_inv_self, *, perm.eq_inv_iff_eq, eq_self_iff_true, not_true] at * end lemma mul_swap_eq_swap_mul (f : perm α) (x y : α) : f * swap x y = swap (f x) (f y) * f := by rw [swap_mul_eq_mul_swap, perm.inv_apply_self, perm.inv_apply_self] lemma swap_apply_apply (f : perm α) (x y : α) : swap (f x) (f y) = f * swap x y * f⁻¹ := by rw [mul_swap_eq_swap_mul, mul_inv_cancel_right] /-- Left-multiplying a permutation with `swap i j` twice gives the original permutation. This specialization of `swap_mul_self` is useful when using cosets of permutations. -/ @[simp] lemma swap_mul_self_mul (i j : α) (σ : perm α) : equiv.swap i j * (equiv.swap i j * σ) = σ := by rw [←mul_assoc, swap_mul_self, one_mul] /-- Right-multiplying a permutation with `swap i j` twice gives the original permutation. This specialization of `swap_mul_self` is useful when using cosets of permutations. -/ @[simp] lemma mul_swap_mul_self (i j : α) (σ : perm α) : (σ * equiv.swap i j) * equiv.swap i j = σ := by rw [mul_assoc, swap_mul_self, mul_one] /-- A stronger version of `mul_right_injective` -/ @[simp] lemma swap_mul_involutive (i j : α) : function.involutive ((*) (equiv.swap i j)) := swap_mul_self_mul i j /-- A stronger version of `mul_left_injective` -/ @[simp] lemma mul_swap_involutive (i j : α) : function.involutive (* (equiv.swap i j)) := mul_swap_mul_self i j @[simp] lemma swap_eq_one_iff {i j : α} : swap i j = (1 : perm α) ↔ i = j := swap_eq_refl_iff lemma swap_mul_eq_iff {i j : α} {σ : perm α} : swap i j * σ = σ ↔ i = j := ⟨(assume h, have swap_id : swap i j = 1 := mul_right_cancel (trans h (one_mul σ).symm), by {rw [←swap_apply_right i j, swap_id], refl}), (assume h, by erw [h, swap_self, one_mul])⟩ lemma mul_swap_eq_iff {i j : α} {σ : perm α} : σ * swap i j = σ ↔ i = j := ⟨(assume h, have swap_id : swap i j = 1 := mul_left_cancel (trans h (one_mul σ).symm), by {rw [←swap_apply_right i j, swap_id], refl}), (assume h, by erw [h, swap_self, mul_one])⟩ lemma swap_mul_swap_mul_swap {x y z : α} (hwz: x ≠ y) (hxz : x ≠ z) : swap y z * swap x y * swap y z = swap z x := equiv.ext $ λ n, by { simp only [swap_apply_def, perm.mul_apply], split_ifs; cc } end swap section add_group variables [add_group α] (a b : α) @[simp] lemma add_left_zero : equiv.add_left (0 : α) = 1 := ext zero_add @[simp] lemma add_right_zero : equiv.add_right (0 : α) = 1 := ext add_zero @[simp] lemma add_left_add : equiv.add_left (a + b) = equiv.add_left a * equiv.add_left b := ext $ add_assoc _ _ @[simp] lemma add_right_add : equiv.add_right (a + b) = equiv.add_right b * equiv.add_right a := ext $ λ _, (add_assoc _ _ _).symm @[simp] lemma inv_add_left : (equiv.add_left a)⁻¹ = equiv.add_left (-a) := equiv.coe_inj.1 rfl @[simp] lemma inv_add_right : (equiv.add_right a)⁻¹ = equiv.add_right (-a) := equiv.coe_inj.1 rfl @[simp] lemma pow_add_left (n : ℕ) : equiv.add_left a ^ n = equiv.add_left (n • a) := by { ext, simp [perm.coe_pow] } @[simp] lemma pow_add_right (n : ℕ) : equiv.add_right a ^ n = equiv.add_right (n • a) := by { ext, simp [perm.coe_pow] } @[simp] lemma zpow_add_left (n : ℤ) : equiv.add_left a ^ n = equiv.add_left (n • a) := (map_zsmul (⟨equiv.add_left, add_left_zero, add_left_add⟩ : α →+ additive (perm α)) _ _).symm @[simp] lemma zpow_add_right (n : ℤ) : equiv.add_right a ^ n = equiv.add_right (n • a) := @zpow_add_left αᵃᵒᵖ _ _ _ end add_group section group variables [group α] (a b : α) @[simp, to_additive] lemma mul_left_one : equiv.mul_left (1 : α) = 1 := ext one_mul @[simp, to_additive] lemma mul_right_one : equiv.mul_right (1 : α) = 1 := ext mul_one @[simp, to_additive] lemma mul_left_mul : equiv.mul_left (a * b) = equiv.mul_left a * equiv.mul_left b := ext $ mul_assoc _ _ @[simp, to_additive] lemma mul_right_mul : equiv.mul_right (a * b) = equiv.mul_right b * equiv.mul_right a := ext $ λ _, (mul_assoc _ _ _).symm @[simp, to_additive inv_add_left] lemma inv_mul_left : (equiv.mul_left a)⁻¹ = equiv.mul_left a⁻¹ := equiv.coe_inj.1 rfl @[simp, to_additive inv_add_right] lemma inv_mul_right : (equiv.mul_right a)⁻¹ = equiv.mul_right a⁻¹ := equiv.coe_inj.1 rfl @[simp, to_additive pow_add_left] lemma pow_mul_left (n : ℕ) : equiv.mul_left a ^ n = equiv.mul_left (a ^ n) := by { ext, simp [perm.coe_pow] } @[simp, to_additive pow_add_right] lemma pow_mul_right (n : ℕ) : equiv.mul_right a ^ n = equiv.mul_right (a ^ n) := by { ext, simp [perm.coe_pow] } @[simp, to_additive zpow_add_left] lemma zpow_mul_left (n : ℤ) : equiv.mul_left a ^ n = equiv.mul_left (a ^ n) := (map_zpow (⟨equiv.mul_left, mul_left_one, mul_left_mul⟩ : α →* perm α) _ _).symm @[simp, to_additive zpow_add_right] lemma zpow_mul_right : ∀ n : ℤ, equiv.mul_right a ^ n = equiv.mul_right (a ^ n) | (int.of_nat n) := by simp | (int.neg_succ_of_nat n) := by simp end group end equiv open equiv function namespace set variables {α : Type*} {f : perm α} {s t : set α} @[simp] lemma bij_on_perm_inv : bij_on ⇑f⁻¹ t s ↔ bij_on f s t := equiv.bij_on_symm alias bij_on_perm_inv ↔ bij_on.of_perm_inv bij_on.perm_inv lemma maps_to.perm_pow : maps_to f s s → ∀ n : ℕ, maps_to ⇑(f ^ n) s s := by { simp_rw equiv.perm.coe_pow, exact maps_to.iterate } lemma surj_on.perm_pow : surj_on f s s → ∀ n : ℕ, surj_on ⇑(f ^ n) s s := by { simp_rw equiv.perm.coe_pow, exact surj_on.iterate } lemma bij_on.perm_pow : bij_on f s s → ∀ n : ℕ, bij_on ⇑(f ^ n) s s := by { simp_rw equiv.perm.coe_pow, exact bij_on.iterate } lemma bij_on.perm_zpow (hf : bij_on f s s) : ∀ n : ℤ, bij_on ⇑(f ^ n) s s | (int.of_nat n) := hf.perm_pow _ | (int.neg_succ_of_nat n) := by { rw zpow_neg_succ_of_nat, exact (hf.perm_pow _).perm_inv } end set
module integration_data use bl_types, only: dp_t implicit none type :: integration_status_t logical :: integration_complete real(dp_t) :: atol_spec, atol_enuc real(dp_t) :: rtol_spec, rtol_enuc end type integration_status_t end module integration_data
(** ********************************************************** Ralph Matthes 2022, after the model of EndofunctorsMonoidal *) (** ********************************************************** Contents : - build monoidal category for the endofunctors ************************************************************) Require Import UniMath.Foundations.PartD. Require Import UniMath.MoreFoundations.Tactics. Require Import UniMath.CategoryTheory.Core.Categories. Require Import UniMath.CategoryTheory.Monoidal.Categories. Require Import UniMath.Bicategories.MonoidalCategories.WhiskeredMonoidalFromBicategory. Require Import UniMath.Bicategories.Core.Examples.BicatOfCats. Local Open Scope cat. Section Endofunctors_as_monoidal_category. Context (C : category). Definition cat_of_endofunctors: category := category_from_bicat_and_ob(C:=bicat_of_cats) C. Definition monoidal_of_endofunctors: monoidal cat_of_endofunctors:= monoidal_from_bicat_and_ob(C:=bicat_of_cats) C. (** we need this high-level view in order to be able to instantiate [montrafotargetbicat_disp_monoidal] in [ActionBasedStrongFunctorsWhiskeredMonoidal] *) End Endofunctors_as_monoidal_category.
section {*FUNCTION\_\_EPDA\_RE\_\_EPDA\_RESTRICT\_EDGES*} theory FUNCTION__EPDA_RE__EPDA_RESTRICT_EDGES imports PRJ_12_04_01_02__ENTRY begin definition F_ALT_EPDA_RE :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda_step_label set \<Rightarrow> ('state, 'event, 'stack) epda" where "F_ALT_EPDA_RE G E \<equiv> let Q = {epda_initial G} \<union> {q \<in> epda_states G. \<exists>e \<in> epda_delta G \<inter> E. edge_src e = q \<or> edge_trg e = q} in \<lparr>epda_states = Q, epda_events = epda_events G, epda_gamma = epda_gamma G, epda_delta = epda_delta G \<inter> E, epda_initial = epda_initial G, epda_box = epda_box G, epda_marking = Q \<inter> epda_marking G\<rparr>" lemma PDA_to_epda: " valid_pda G \<Longrightarrow> valid_epda G" apply(simp add: valid_pda_def) done lemma F_EPDA_R__vs_F_ALT_EPDA_RE: " valid_epda G \<Longrightarrow> F_EPDA_R G ({epda_initial G} \<union> {q \<in> epda_states G. \<exists>e \<in> epda_delta G \<inter> E. edge_src e = q \<or> edge_trg e = q}) E = F_ALT_EPDA_RE G E" apply(simp add: F_EPDA_R_def F_ALT_EPDA_RE_def Let_def) apply(rule conjI) apply(rule antisym) apply(force) apply(clarsimp) apply(simp add: valid_epda_def) apply(force) apply(rule conjI) apply(rule antisym) apply(force) apply(clarsimp) apply(simp add: valid_epda_def) apply(clarsimp) apply(erule_tac x="x" in ballE) prefer 2 apply(force) apply(simp add: valid_epda_step_label_def) apply(force) apply(force) done lemma F_EPDA_RE__vs_F_ALT_EPDA_RE: " valid_epda G \<Longrightarrow> F_EPDA_RE G E = F_ALT_EPDA_RE G E" apply(simp add: F_EPDA_RE_def) apply(rule_tac t="F_EPDA_R G (insert (epda_initial G) {q \<in> epda_states G. \<exists>e\<in>epda_delta G \<inter> E. edge_src e = q \<or> edge_trg e = q}) E" and s="F_EPDA_R G ({epda_initial G} \<union> {q \<in> epda_states G. \<exists>e \<in> epda_delta G \<inter> E. edge_src e = q \<or> edge_trg e = q}) E" in ssubst) apply(force) apply (rule F_EPDA_R__vs_F_ALT_EPDA_RE) apply(force) done lemma F_ALT_EPDA_RE_preserves_epda: " valid_epda G \<Longrightarrow> valid_epda (F_ALT_EPDA_RE G E)" apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(simp add: valid_epda_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(simp add: valid_epda_step_label_def) apply(erule_tac x = "x" in ballE) apply(rename_tac x)(*strict*) prefer 2 apply(force) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rule conjI) apply(rename_tac x)(*strict*) apply(force) apply(rename_tac x)(*strict*) apply(force) done lemma F_ALT_EPDA_RE_preserves_PDA: " valid_pda G \<Longrightarrow> valid_pda (F_ALT_EPDA_RE G E)" apply(subgoal_tac "valid_epda (F_ALT_EPDA_RE G E)") prefer 2 apply(rule F_ALT_EPDA_RE_preserves_epda) apply(simp add: valid_pda_def) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(simp add: valid_pda_def) done definition F_ALT_EPDA_REE :: " ('state, 'event, 'stack) epda_step_label \<Rightarrow> ('state, 'event, 'stack) epda_step_label" where "F_ALT_EPDA_REE e \<equiv> e" definition F_ALT_EPDA_REERev :: " ('state, 'event, 'stack) epda_step_label \<Rightarrow> ('state, 'event, 'stack) epda_step_label" where "F_ALT_EPDA_REERev e \<equiv> e" lemma F_ALT_EPDA_REERev_preserves_edges: " valid_epda G \<Longrightarrow> e \<in> epda_delta (F_ALT_EPDA_RE G E) \<Longrightarrow> F_ALT_EPDA_REERev e \<in> epda_delta G" apply(simp add: F_ALT_EPDA_REERev_def) apply(simp add: F_ALT_EPDA_RE_def Let_def) done definition F_ALT_EPDA_REC :: " ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf" where "F_ALT_EPDA_REC c \<equiv> c" definition F_ALT_EPDA_RECRev :: " ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf" where "F_ALT_EPDA_RECRev c \<equiv> c" lemma epdaToSymbolE_preserves_valid_epda_step_label: " valid_epda G \<Longrightarrow> e \<in> epda_delta G \<Longrightarrow> valid_epda_step_label G e \<Longrightarrow> e \<in> E \<Longrightarrow> G' = F_ALT_EPDA_RE G E \<Longrightarrow> e' = F_ALT_EPDA_REE e \<Longrightarrow> valid_epda_step_label G' e'" apply(simp add: F_ALT_EPDA_RE_def Let_def F_ALT_EPDA_REE_def valid_epda_def valid_epda_step_label_def) apply(clarsimp) apply(erule_tac x = "e" in ballE) prefer 2 apply(force) apply(clarsimp) apply(rule conjI) apply(case_tac "edge_src e = epda_initial G") apply(clarsimp) apply(clarsimp) apply(rule_tac x = "e" in bexI) apply(force) apply(force) apply(case_tac "edge_trg e = epda_initial G") apply(clarsimp) apply(clarsimp) apply(rule_tac x = "e" in bexI) apply(force) apply(force) done lemma F_ALT_EPDA_RE_preserves_configuration: " valid_pda G \<Longrightarrow> q \<in> epda_states G \<Longrightarrow> set i \<subseteq> epda_events G \<Longrightarrow> set s \<subseteq> epda_gamma G \<Longrightarrow> epdaS.derivation_initial G d \<Longrightarrow> d ia = Some (pair e \<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = i, epdaS_conf_stack = s\<rparr>) \<Longrightarrow> q \<in> epda_states (F_ALT_EPDA_RE G (epdaS_accessible_edges G)) \<and> set i \<subseteq> epda_events (F_ALT_EPDA_RE G (epdaS_accessible_edges G)) \<and> set s \<subseteq> epda_gamma (F_ALT_EPDA_RE G (epdaS_accessible_edges G))" apply(induct ia arbitrary: q i s e) apply(rename_tac q i s e)(*strict*) apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def) apply(clarsimp) apply(rename_tac i)(*strict*) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac ia q i s e)(*strict*) apply(clarsimp) apply(subgoal_tac "\<exists>e1 e2 c1 c2. d ia = Some (pair e1 c1) \<and> d (Suc ia) = Some (pair (Some e2) c2) \<and> epdaS_step_relation G c1 e2 c2") apply(rename_tac ia q i s e)(*strict*) prefer 2 apply(rule_tac m = "Suc ia" in epdaS.step_detail_before_some_position) apply(rename_tac ia q i s e)(*strict*) apply(rule epdaS.derivation_initial_is_derivation) apply(force) apply(rename_tac ia q i s e)(*strict*) apply(force) apply(rename_tac ia q i s e)(*strict*) apply(force) apply(rename_tac ia q i s e)(*strict*) apply(clarsimp) apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(subgoal_tac "c1 \<in> epdaS_configurations G") apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(case_tac c1) apply(rename_tac ia q i s e1 e2 c1 epdaS_conf_state epdaS_conf_scheduler epdaS_conf_stack)(*strict*) apply(rename_tac q' i' s') apply(rename_tac ia q i s e1 e2 c1 q' i' s')(*strict*) apply(clarsimp) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(erule_tac x = "q'" in meta_allE) apply(erule_tac x = "i'" in meta_allE) apply(erule_tac x = "s'" in meta_allE) apply(erule_tac x = "e1" in meta_allE) apply(clarsimp) apply(erule_tac meta_impE) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(simp add: epdaS_configurations_def) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(erule_tac meta_impE) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(simp add: epdaS_configurations_def) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(erule_tac meta_impE) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(simp add: epdaS_configurations_def) apply(rename_tac ia q i s e1 e2 q' i' s')(*strict*) apply(clarsimp) apply(simp add: epdaS_step_relation_def) apply(clarsimp) apply(rename_tac ia i e1 e2 w)(*strict*) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(clarsimp) apply(erule disjE) apply(rename_tac ia i e1 e2 w)(*strict*) apply(clarsimp) apply(erule_tac x = "e2" in ballE) apply(rename_tac ia i e1 e2 w)(*strict*) prefer 2 apply(simp add: epdaS_accessible_edges_def) apply(rename_tac ia i e1 e2 w)(*strict*) apply(clarsimp) apply(rename_tac ia i e1 e2 w)(*strict*) apply(clarsimp) apply(rename_tac ia i e1 e2 w e)(*strict*) apply(erule disjE) apply(rename_tac ia i e1 e2 w e)(*strict*) apply(erule_tac x = "e2" in ballE) apply(rename_tac ia i e1 e2 w e)(*strict*) prefer 2 apply(simp add: epdaS_accessible_edges_def) apply(rename_tac ia i e1 e2 w e)(*strict*) apply(clarsimp) apply(rename_tac ia i e1 e2 w e)(*strict*) apply(erule_tac x = "e2" in ballE) apply(rename_tac ia i e1 e2 w e)(*strict*) apply(force) apply(rename_tac ia i e1 e2 w e)(*strict*) apply(simp add: epdaS_accessible_edges_def) apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(rule epdaS.belongs_configurations) apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(rule epdaS.derivation_initial_belongs) apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(simp add: valid_pda_def) apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(force) apply(rename_tac ia q i s e1 e2 c1)(*strict*) apply(force) done lemma F_ALT_EPDA_REC_preserves_configurations: " valid_pda G \<Longrightarrow> c \<in> epdaS.get_accessible_configurations G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> F_ALT_EPDA_REC c \<in> epdaS_configurations (F_ALT_EPDA_RE G E)" apply(subgoal_tac "c \<in> epdaS_configurations G") prefer 2 apply (metis (full_types) valid_pda_to_valid_epda contra_subsetD epdaS.get_accessible_configurations_are_configurations) apply(simp add: epdaS_configurations_def) apply(simp add: F_ALT_EPDA_REC_def) apply(clarsimp) apply(rename_tac q i s)(*strict*) apply(simp add: epdaS.get_accessible_configurations_def) apply(clarsimp) apply(rename_tac q i s d ia)(*strict*) apply(case_tac "d ia") apply(rename_tac q i s d ia)(*strict*) apply(simp add: get_configuration_def) apply(rename_tac q i s d ia a)(*strict*) apply(clarsimp) apply(simp add: get_configuration_def) apply(case_tac a) apply(rename_tac q i s d ia a option b)(*strict*) apply(clarsimp) apply(rename_tac q i s d ia option)(*strict*) apply(rule F_ALT_EPDA_RE_preserves_configuration) apply(rename_tac q i s d ia option)(*strict*) apply(force) apply(rename_tac q i s d ia option)(*strict*) apply(force) apply(rename_tac q i s d ia option)(*strict*) apply(force) apply(rename_tac q i s d ia option)(*strict*) apply(force) apply(rename_tac q i s d ia option)(*strict*) apply(force) apply(rename_tac q i s d ia option)(*strict*) apply(force) done lemma F_ALT_EPDA_REC_preserves_initial_configurations: " valid_pda G \<Longrightarrow> c \<in> epdaS_initial_configurations G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> F_ALT_EPDA_REC c \<in> epdaS_initial_configurations (F_ALT_EPDA_RE G E)" apply(simp (no_asm) add: epdaS_initial_configurations_def) apply(clarsimp) apply(rule conjI) apply(simp add: epdaS_initial_configurations_def) apply(simp add: F_ALT_EPDA_REC_def) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rule conjI) apply(simp add: epdaS_initial_configurations_def) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(simp add: F_ALT_EPDA_REC_def) apply(rule F_ALT_EPDA_REC_preserves_configurations) apply(force) apply (metis PDA_to_epda epdaS.initial_configurations_are_get_accessible_configurations) apply(force) done lemma F_ALT_EPDA_REC_preserves_marking_configurations: " valid_pda G \<Longrightarrow> c \<in> epdaS_marking_configurations G \<Longrightarrow> c \<in> epdaS.get_accessible_configurations G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> F_ALT_EPDA_REC c \<in> epdaS_marking_configurations (F_ALT_EPDA_RE G E)" apply(subgoal_tac "F_ALT_EPDA_REC c \<in> epdaS_configurations (F_ALT_EPDA_RE G E)") apply(simp add: epdaS_marking_configurations_def) apply(clarsimp) apply(rule conjI) apply(simp add: F_ALT_EPDA_REC_def) apply(simp add: F_ALT_EPDA_RE_def Let_def F_ALT_EPDA_REC_def epdaS_configurations_def) apply(clarsimp) apply(rule F_ALT_EPDA_REC_preserves_configurations) apply(force) apply(force) apply(force) done definition F_ALT_EPDA_RE_relation_TSstructureLR :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<equiv> valid_pda G1 \<and> G2 = F_ALT_EPDA_RE G1 (epdaS_accessible_edges G1)" definition F_ALT_EPDA_RE_relation_configurationLR :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<equiv> F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<and> c1 \<in> epdaS.get_accessible_configurations G1 \<and> c2 = F_ALT_EPDA_REC c1" definition F_ALT_EPDA_RE_relation_initial_configurationLR :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 c1 c2 \<equiv> F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<and> c1 \<in> epdaS_initial_configurations G1 \<and> c2 = F_ALT_EPDA_REC c1" definition F_ALT_EPDA_RE_relation_effectLR :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> 'event list \<Rightarrow> 'event list \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_effectLR G1 G2 w1 w2 \<equiv> F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<and> w1 = w2" lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs: " (\<forall>G1. Ex (F_ALT_EPDA_RE_relation_TSstructureLR G1) \<longrightarrow> valid_epda G1)" apply(clarsimp) apply(rename_tac G1 x)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply(rename_tac G1)(*strict*) apply(simp add: valid_dpda_def valid_pda_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> valid_epda G2)" apply(clarsimp) apply(rename_tac G1 G2)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply(rename_tac G1)(*strict*) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) done definition F_ALT_EPDA_RE_relation_step_simulation :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epda_step_label \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e c1' c2 d \<equiv> d = der2 (F_ALT_EPDA_REC c1) (F_ALT_EPDA_REE e) (F_ALT_EPDA_REC c1')" definition F_ALT_EPDA_RE_relation_initial_simulation :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_initial_simulation G1 G2 c1 d \<equiv> d = der1 (F_ALT_EPDA_REC c1)" lemma F_ALT_EPDA_RE_C_preserves_configurations: " F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<Longrightarrow> c1 \<in> epdaS.get_accessible_configurations G1 \<Longrightarrow> F_ALT_EPDA_REC c1 \<in> epdaS_configurations G2" apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply(rule F_ALT_EPDA_REC_preserves_configurations) apply(force) apply(force) apply(force) done lemma F_ALT_EPDA_RE_C_preserves_initial_configurations: " F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<Longrightarrow> c1 \<in> epdaS_initial_configurations G1 \<Longrightarrow> F_ALT_EPDA_REC c1 \<in> epdaS_initial_configurations G2" apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply(rule F_ALT_EPDA_REC_preserves_initial_configurations) apply(force) apply(force) apply(force) done lemma F_ALT_EPDA_RE_C_preserves_marking_configurations: " F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<Longrightarrow> c1 \<in> epdaS_marking_configurations G1 \<Longrightarrow> c1 \<in> epdaS.get_accessible_configurations G1 \<Longrightarrow> F_ALT_EPDA_REC c1 \<in> epdaS_marking_configurations G2" apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply(rule F_ALT_EPDA_REC_preserves_marking_configurations) apply(force) apply(force) apply(force) apply(force) done lemma F_ALT_EPDA_RE_initial_simulation_preserves_derivation: " F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<Longrightarrow> c1 \<in> epdaS_initial_configurations G1 \<Longrightarrow> epdaS.derivation_initial G2 (der1 (F_ALT_EPDA_REC c1))" apply(rule epdaS.derivation_initialI) apply(rule epdaS.der1_is_derivation) apply(clarsimp) apply(rename_tac c)(*strict*) apply(simp add: get_configuration_def der1_def) apply(clarsimp) apply(rule F_ALT_EPDA_RE_C_preserves_initial_configurations) apply(force) apply(force) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<exists>d2. epdaS.derivation_initial G2 d2 \<and> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 c1 (the (get_configuration (d2 0))) \<and> F_ALT_EPDA_RE_relation_initial_simulation G1 G2 c1 d2 \<and> (\<exists>n. maximum_of_domain d2 n \<and> F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 (the (get_configuration (d2 n))))))" apply(clarsimp) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_simulation_def) apply(rule conjI) apply(rename_tac G1 G2 c1)(*strict*) apply(rule F_ALT_EPDA_RE_initial_simulation_preserves_derivation) apply(rename_tac G1 G2 c1)(*strict*) apply(force) apply(rename_tac G1 G2 c1)(*strict*) apply(force) apply(rename_tac G1 G2 c1)(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationLR_def) apply(simp add: get_configuration_def der1_def) apply(rename_tac G1 G2 c1)(*strict*) apply(rule_tac x = "0" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1)(*strict*) apply(rule der1_maximum_of_domain) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: get_configuration_def der1_def) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def valid_pda_def valid_dpda_def) apply(clarsimp) apply(rename_tac G1 c1)(*strict*) apply (metis epdaS.initial_configurations_are_get_accessible_configurations) done lemma F_ALT_EPDA_RE_preserves_step_relation: " valid_epda G1 \<Longrightarrow> epdaS_step_relation G1 c1 e1 c1' \<Longrightarrow> E = epdaS_accessible_edges G1 \<Longrightarrow> c1 \<in> epdaS.get_accessible_configurations G1 \<Longrightarrow> epdaS_step_relation (F_ALT_EPDA_RE G1 E) (F_ALT_EPDA_REC c1) (F_ALT_EPDA_REE e1) (F_ALT_EPDA_REC c1')" apply(subgoal_tac "c1' \<in> epdaS.get_accessible_configurations G1") prefer 2 apply(rule epdaS.der2_preserves_get_accessible_configurations) apply(force) apply(rule epdaS.der2_is_derivation) apply(force) apply(force) apply(simp (no_asm) add: epdaS_step_relation_def) apply(clarsimp) apply(rule conjI) apply(simp add: F_ALT_EPDA_RE_def F_ALT_EPDA_REE_def Let_def) apply(simp add: epdaS_accessible_edges_def) apply(simp add: epdaS.get_accessible_configurations_def) apply(clarsimp) apply(rename_tac d da i ia)(*strict*) apply(rule conjI) apply(rename_tac d da i ia)(*strict*) apply(simp add: epdaS_step_relation_def) apply(rename_tac d da i ia)(*strict*) apply(rule_tac x = "derivation_append (derivation_take d i) (der2 c1 e1 c1') i" in exI) apply(rule conjI) apply(rename_tac d da i ia)(*strict*) apply(rule epdaS.derivation_append_preserves_derivation_initial) apply(rename_tac d da i ia)(*strict*) apply(force) apply(rename_tac d da i ia)(*strict*) apply(rule epdaS.derivation_take_preserves_derivation_initial) apply(force) apply(rename_tac d da i ia)(*strict*) apply(rule epdaS.derivation_append_preserves_derivation) apply(rename_tac d da i ia)(*strict*) apply(rule epdaS.derivation_take_preserves_derivation) apply(simp add: epdaS.derivation_initial_def) apply(rename_tac d da i ia)(*strict*) apply(rule epdaS.der2_is_derivation) apply(force) apply(rename_tac d da i ia)(*strict*) apply(simp add: derivation_take_def) apply(case_tac "d i") apply(rename_tac d da i ia)(*strict*) apply(simp add: get_configuration_def) apply(rename_tac d da i ia a)(*strict*) apply(simp add: get_configuration_def) apply(case_tac a) apply(rename_tac d da i ia a option b)(*strict*) apply(clarsimp) apply(rename_tac d da i ia option)(*strict*) apply(simp add: der2_def) apply(rename_tac d da i ia)(*strict*) apply(rule_tac x = "Suc i" in exI) apply(simp add: der2_def derivation_append_def) apply(rule conjI) apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_REE_def epdaS_step_relation_def) apply(rule conjI) apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_REE_def epdaS_step_relation_def) apply(rule conjI) apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_REE_def epdaS_step_relation_def) apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_REE_def epdaS_step_relation_def) done lemma F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation: " F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \<Longrightarrow> F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<Longrightarrow> epdaS_step_relation G1 c1 e1 c1' \<Longrightarrow> epdaS.derivation G2 d2" apply(simp add: F_ALT_EPDA_RE_relation_step_simulation_def) apply(subgoal_tac "c1 \<in> epdaS.get_accessible_configurations G1") prefer 2 apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(rule epdaS.der2_is_derivation) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply(rule F_ALT_EPDA_RE_preserves_step_relation) apply(simp add: valid_pda_def) apply(force) apply(force) apply(force) done lemma F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation_belongs: " F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \<Longrightarrow> F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<Longrightarrow> epdaS_step_relation G1 c1 e1 c1' \<Longrightarrow> epdaS.belongs G2 d2" apply(simp add: F_ALT_EPDA_RE_relation_step_simulation_def) apply(rule epdaS.der2_belongs_prime) prefer 3 apply(rule F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation) apply(simp add: F_ALT_EPDA_RE_relation_step_simulation_def) apply(force) apply(force) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(clarsimp) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(rule F_ALT_EPDA_RE_C_preserves_configurations) apply(force) apply (metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS.get_accessible_configurations_are_configurations subsetD) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<exists>d2. epdaS.derivation G2 d2 \<and> epdaS.belongs G2 d2 \<and> the (get_configuration (d2 0)) = c2 \<and> F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \<and> (\<exists>n. maximum_of_domain d2 n \<and> F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1' (the (get_configuration (d2 n)))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_step_simulation_def) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_step_simulation_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation_belongs) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_step_simulation_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: der2_def get_configuration_def F_ALT_EPDA_RE_relation_configurationLR_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule_tac x = "Suc 0" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule der2_maximum_of_domain) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: der2_def get_configuration_def F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1')(*strict*) apply(rule epdaS.der2_preserves_get_accessible_configurations) apply(rename_tac G1 G2 c1 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def valid_pda_def) apply(rename_tac G1 G2 c1 e1 c1')(*strict*) apply(rule epdaS.der2_is_derivation) apply(force) apply(rename_tac G1 G2 c1 e1 c1')(*strict*) apply(force) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms: " ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_configurationLR F_ALT_EPDA_RE_relation_TSstructureLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation" apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs) done interpretation "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR" : ATS_Simulation_Configuration_Weak (* TSstructure1 *) "valid_epda" (* configurations1 *) "epdaS_configurations" (* initial_configurations1 *) "epdaS_initial_configurations" (* step_labels1 *) "epda_step_labels" (* step_relation1 *) "epdaS_step_relation" (* effects1 *) "epda_effects" (* marking_condition1 *) "epdaS_marking_condition" (* marked_effect1 *) "epdaS_marked_effect" (* unmarked_effect1 *) "epdaS_unmarked_effect" (* TSstructure2 *) "valid_epda" (* configurations2 *) "epdaS_configurations" (* initial_configurations2 *) "epdaS_initial_configurations" (* step_labels2 *) "epda_step_labels" (* step_relation2 *) "epdaS_step_relation" (* effects2 *) "epda_effects" (* marking_condition2 *) "epdaS_marking_condition" (* marked_effect2 *) "epdaS_marked_effect" (* unmarked_effect2 *) "epdaS_unmarked_effect" (* relation_configuration *) "F_ALT_EPDA_RE_relation_configurationLR" (* relation_initial_configuration *) "F_ALT_EPDA_RE_relation_initial_configurationLR" (* relation_effect *) "F_ALT_EPDA_RE_relation_effectLR" (* relation_TSstructure *) "F_ALT_EPDA_RE_relation_TSstructureLR" (* relation_initial_simulation *) "F_ALT_EPDA_RE_relation_initial_simulation" (* relation_step_simulation *) "F_ALT_EPDA_RE_relation_step_simulation" apply(simp add: LOCALE_DEFS epda_interpretations) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_marking_condition: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: epdaS_marking_condition_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(thin_tac "derivation_append deri1 (der2 c1 e1 c1') deri1n i = Some (pair e c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(rule_tac x = "e" in exI) apply(rule_tac x = "c" in exI) apply(clarsimp) apply(simp add: derivation_append_def get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e)(*strict*) apply(rule F_ALT_EPDA_RE_C_preserves_marking_configurations) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e)(*strict*) apply(force) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e)(*strict*) apply(force) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "i = Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*) apply(subgoal_tac "c = c1'") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_def) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "Suc deri1n" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y)(*strict*) apply(rule_tac x = "deri2n+n" in exI) apply(case_tac y) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(rule_tac t = "c" and s = "F_ALT_EPDA_REC c1'" in ssubst) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def derivation_append_def get_configuration_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(rule F_ALT_EPDA_RE_C_preserves_marking_configurations) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def get_configuration_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*) apply(simp add: derivation_append_def der2_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i>Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(simp add: derivation_append_def der2_def) apply(case_tac "i-deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*) apply(clarsimp) apply(case_tac nat) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat nata)(*strict*) apply(clarsimp) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_marking_condition: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_initial_simulation G1 G2 c1 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: epdaS_marking_condition_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(case_tac y) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(rule_tac x = "e" in exI) apply(rule_tac x = "c" in exI) apply(clarsimp) apply(rule_tac t = "c" and s = "F_ALT_EPDA_REC ca" in ssubst) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(simp add: derivation_append_def get_configuration_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule F_ALT_EPDA_RE_C_preserves_marking_configurations) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(simp add: get_configuration_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "i = deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i>deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(force) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(simp add: derivation_append_def der1_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms: " ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_configurationLR F_ALT_EPDA_RE_relation_TSstructureLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation" apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def) apply(rule conjI) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_step_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_marking_condition) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_initial_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_marking_condition) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_marked_effect: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectLR G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(rule_tac x = "a" in bexI) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectLR_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_marked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*) apply(simp add: derivation_append_def F_ALT_EPDA_RE_relation_initial_configurationLR_def) apply(clarsimp) apply(simp add: get_configuration_def F_ALT_EPDA_REC_def F_ALT_EPDA_REC_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(simp add: get_configuration_def) apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_marked_effect: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_initial_simulation G1 G2 c1 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectLR G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n)))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(rule_tac x = "a" in bexI) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectLR_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_marked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*) apply(simp add: derivation_append_def F_ALT_EPDA_RE_relation_initial_configurationLR_def) apply(clarsimp) apply(simp add: F_ALT_EPDA_REC_def get_configuration_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms: " ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_configurationLR F_ALT_EPDA_RE_relation_effectLR F_ALT_EPDA_RE_relation_TSstructureLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation" apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def) apply(rule conjI) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_step_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_marked_effect) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_initial_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_marked_effect) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_preserves_unmarked_effect: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationLR G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectLR G1 G2) (epdaS_unmarked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_unmarked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_unmarked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectLR_def) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) prefer 2 apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(rule_tac x = "ca" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c')") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_DEF_def) apply(clarsimp) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e c)(*strict*) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationLR_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(subgoal_tac "\<exists>c. deri1 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) prefer 2 apply(rule_tac M = "G1" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "F_ALT_EPDA_REC c'" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(simp add: derivation_append_def) apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_REC_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(subgoal_tac "i = Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(case_tac "i>Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(clarsimp) apply(simp add: derivation_append_def der2_def) apply(case_tac "i-deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca nat)(*strict*) apply(clarsimp) apply(case_tac nat) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca nat)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i ca)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca nat nata)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' e ca)(*strict*) apply(subgoal_tac "c' = c1'") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def der2_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' e ca)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e ca)(*strict*) apply(rule_tac x = "F_ALT_EPDA_REC c1'" in exI) apply(subgoal_tac "F_ALT_EPDA_REC c = ca") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationLR_def) apply(clarsimp) apply(simp add: get_configuration_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e ca)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "Suc deri1n" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e c)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e c)(*strict*) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e)(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e)(*strict*) apply(rule_tac x = "deri2n+n" in exI) apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e)(*strict*) apply(simp add: F_ALT_EPDA_REC_def get_configuration_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_preserves_unmarked_effect: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureLR G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_initial_simulation G1 G2 c1 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationLR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectLR G1 G2) (epdaS_unmarked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_unmarked_effect G2 (derivation_append deri2 d2 deri2n)))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_unmarked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectLR_def) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) prefer 2 apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(rule_tac x = "ca" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c')") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.simulating_derivation_DEF_def) apply(clarsimp) apply(simp add: F_ALT_EPDA_RE_relation_configurationLR_def) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e c)(*strict*) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationLR_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(subgoal_tac "\<exists>c. deri1 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) prefer 2 apply(rule_tac M = "G1" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "F_ALT_EPDA_REC c'" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(simp add: derivation_append_def F_ALT_EPDA_REC_def F_ALT_EPDA_REC_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: derivation_append_def der1_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms: " ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_unmarked_effect epdaS_initial_configurations epdaS_step_relation epdaS_unmarked_effect F_ALT_EPDA_RE_relation_configurationLR F_ALT_EPDA_RE_relation_initial_configurationLR F_ALT_EPDA_RE_relation_effectLR F_ALT_EPDA_RE_relation_TSstructureLR F_ALT_EPDA_RE_relation_initial_simulation F_ALT_EPDA_RE_relation_step_simulation" apply(simp add: ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms_def) apply(rule conjI) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_step_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_preserves_unmarked_effect) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_initial_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_preserves_unmarked_effect) done interpretation "epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR" : ATS_Simulation_Configuration_WeakLR_FULL (* TSstructure1 *) "valid_epda" (* configurations1 *) "epdaS_configurations" (* initial_configurations1 *) "epdaS_initial_configurations" (* step_labels1 *) "epda_step_labels" (* step_relation1 *) "epdaS_step_relation" (* effects1 *) "epda_effects" (* marking_condition1 *) "epdaS_marking_condition" (* marked_effect1 *) "epdaS_marked_effect" (* unmarked_effect1 *) "epdaS_unmarked_effect" (* TSstructure2 *) "valid_epda" (* configurations2 *) "epdaS_configurations" (* initial_configurations2 *) "epdaS_initial_configurations" (* step_labels2 *) "epda_step_labels" (* step_relation2 *) "epdaS_step_relation" (* effects2 *) "epda_effects" (* marking_condition2 *) "epdaS_marking_condition" (* marked_effect2 *) "epdaS_marked_effect" (* unmarked_effect2 *) "epdaS_unmarked_effect" (* relation_configuration *) "F_ALT_EPDA_RE_relation_configurationLR" (* relation_initial_configuration *) "F_ALT_EPDA_RE_relation_initial_configurationLR" (* relation_effect *) "F_ALT_EPDA_RE_relation_effectLR" (* relation_TSstructure *) "F_ALT_EPDA_RE_relation_TSstructureLR" (* relation_initial_simulation *) "F_ALT_EPDA_RE_relation_initial_simulation" (* relation_step_simulation *) "F_ALT_EPDA_RE_relation_step_simulation" apply(simp add: LOCALE_DEFS epda_interpretations) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms ) done lemma F_ALT_EPDA_RE_preserves_lang1: " valid_pda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.marked_language G \<subseteq> epdaS.marked_language (F_ALT_EPDA_RE G E)" apply(rule_tac t = "epdaS.marked_language G" and s = "epdaS.finite_marked_language G" in ssubst) apply (metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_ALT_EPDA_RE_relation_TSstructureLR_def Suc_n_not_n epdaS.AX_marked_language_finite) apply(rule_tac t = "epdaS.marked_language (F_ALT_EPDA_RE G E)" and s = "epdaS.finite_marked_language (F_ALT_EPDA_RE G E)" in ssubst) apply(rule sym) apply(rule epdaS.AX_marked_language_finite) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) apply(subgoal_tac "left_total_on (F_ALT_EPDA_RE_relation_effectLR SSG1 SSG2) (epdaS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)" for SSG1 SSG2) prefer 2 apply(rule_tac ?G1.0 = "G" in epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.ATS_Simulation_Configuration_Weak_Marked_Effect_sound) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(erule_tac x = "x" in ballE) apply(rename_tac x)(*strict*) prefer 2 apply(force) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac x b)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectLR_def) done lemma F_ALT_EPDA_RE_preserves_unmarked_language1: " valid_pda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.unmarked_language G \<subseteq> epdaS.unmarked_language (F_ALT_EPDA_RE G E)" apply(rule_tac t = "epdaS.unmarked_language G" and s = "epdaS.finite_unmarked_language G" in ssubst) apply (metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_ALT_EPDA_RE_relation_TSstructureLR_def Suc_n_not_n epdaS.AX_unmarked_language_finite) apply(rule_tac t = "epdaS.unmarked_language (F_ALT_EPDA_RE G E)" and s = "epdaS.finite_unmarked_language (F_ALT_EPDA_RE G E)" in ssubst) apply(rule sym) apply(rule epdaS.AX_unmarked_language_finite) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda epdaS_inst_AX_unmarked_language_finite) apply(subgoal_tac "left_total_on (F_ALT_EPDA_RE_relation_effectLR SSG1 SSG2) (epdaS.finite_unmarked_language SSG1) (epdaS.finite_unmarked_language SSG2)" for SSG1 SSG2) prefer 2 apply(rule_tac ?G1.0 = "G" in epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR.ATS_Simulation_Configuration_Weak_Unmarked_Effect_sound) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureLR_def) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(erule_tac x = "x" in ballE) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac x b)(*strict*) prefer 2 apply(rename_tac x)(*strict*) apply(force) apply(rename_tac x b)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectLR_def) done definition F_ALT_EPDA_RE_relation_TSstructureRL :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_TSstructureRL G2 G1 \<equiv> valid_pda G1 \<and> G2 = F_ALT_EPDA_RE G1 (epdaS_accessible_edges G1)" definition F_ALT_EPDA_RE_relation_configurationRL :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1 c2 \<equiv> F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<and> c1 \<in> epdaS_configurations G1 \<and> c2 = F_ALT_EPDA_RECRev c1" definition F_ALT_EPDA_RE_relation_initial_configurationRL :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 c1 c2 \<equiv> F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<and> c1 \<in> epdaS_initial_configurations G1 \<and> c2 = F_ALT_EPDA_RECRev c1" definition F_ALT_EPDA_RE_relation_effectRL :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> 'event list \<Rightarrow> 'event list \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_effectRL G1 G2 w1 w2 \<equiv> F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<and> w1 = w2" lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs: " (\<forall>G1. Ex (F_ALT_EPDA_RE_relation_TSstructureRL G1) \<longrightarrow> valid_epda G1)" apply(clarsimp) apply(rename_tac G1 G2)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(clarsimp) apply(rename_tac G2)(*strict*) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> valid_epda G2)" apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(clarsimp) apply(rename_tac G2)(*strict*) apply (metis valid_dpda_def valid_pda_def) done definition F_ALT_EPDA_RE_relation_step_simulationRL :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epda_step_label \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_step_simulationRL G2 G1 c1 e c1' c2 d \<equiv> d = der2 (F_ALT_EPDA_RECRev c1) (F_ALT_EPDA_REERev e) (F_ALT_EPDA_RECRev c1')" definition F_ALT_EPDA_RE_relation_initial_simulationRL :: " ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> ('state, 'event, 'stack) epdaS_conf \<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation \<Rightarrow> bool" where "F_ALT_EPDA_RE_relation_initial_simulationRL G1 G2 c1 d \<equiv> d = der1 (F_ALT_EPDA_RECRev c1)" lemma F_ALT_EPDA_RE_C_rev_preserves_configurations: " F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<Longrightarrow> c1 \<in> epdaS_configurations G1 \<Longrightarrow> F_ALT_EPDA_RECRev c1 \<in> epdaS_configurations G2" apply(simp add: epdaS_configurations_def) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(clarsimp) apply(rename_tac q i s)(*strict*) apply(simp add: F_ALT_EPDA_RE_def F_ALT_EPDA_RECRev_def F_ALT_EPDA_RE_def Let_def) apply(erule disjE) apply(rename_tac q i s)(*strict*) apply(simp add: valid_pda_def valid_epda_def) apply(rename_tac q i s)(*strict*) apply(clarsimp) done lemma F_ALT_EPDA_RE_C_rev_preserves_initial_configurations: " F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<Longrightarrow> c1 \<in> epdaS_initial_configurations G1 \<Longrightarrow> F_ALT_EPDA_RECRev c1 \<in> epdaS_initial_configurations G2" apply(simp add: F_ALT_EPDA_RECRev_def F_ALT_EPDA_RE_relation_TSstructureRL_def F_ALT_EPDA_RE_def epdaS_initial_configurations_def Let_def epdaS_configurations_def valid_pda_def valid_epda_def) apply(force) done lemma F_ALT_EPDA_REC_reverse: " c1 = F_ALT_EPDA_REC (F_ALT_EPDA_RECRev c1)" apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_RECRev_def F_ALT_EPDA_RE_def epdaS_initial_configurations_def epdaS_configurations_def) done lemma F_ALT_EPDA_REC_reverse2: " c1 = F_ALT_EPDA_RECRev (F_ALT_EPDA_REC c1)" apply(simp add: F_ALT_EPDA_REC_def F_ALT_EPDA_RECRev_def F_ALT_EPDA_RE_def epdaS_initial_configurations_def epdaS_configurations_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<exists>d2. epdaS.derivation_initial G2 d2 \<and> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 c1 (the (get_configuration (d2 0))) \<and> F_ALT_EPDA_RE_relation_initial_simulationRL G1 G2 c1 d2 \<and> (\<exists>n. maximum_of_domain d2 n \<and> F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1 (the (get_configuration (d2 n)))))))" apply(clarsimp) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_simulationRL_def) apply(rule conjI) apply(rename_tac G1 G2 c1)(*strict*) apply(rule epdaS.derivation_initialI) apply(rename_tac G1 G2 c1)(*strict*) apply(rule epdaS.der1_is_derivation) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: get_configuration_def der1_def) apply(rule F_ALT_EPDA_RE_C_rev_preserves_initial_configurations) apply(rename_tac G1 G2 c1)(*strict*) apply(force) apply(rename_tac G1 G2 c1)(*strict*) apply(force) apply(rename_tac G1 G2 c1)(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: get_configuration_def der1_def) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationRL_def) apply(rename_tac G1 G2 c1)(*strict*) apply(rule_tac x = "0" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1)(*strict*) apply(rule der1_maximum_of_domain) apply(rename_tac G1 G2 c1)(*strict*) apply(simp add: get_configuration_def der1_def) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(clarsimp) apply(rename_tac G2 c1)(*strict*) apply(simp add: epdaS_initial_configurations_def) done lemma F_ALT_EPDA_RERev_preserves_step_relation: " F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<Longrightarrow> epdaS_step_relation G1 c1 e1 c1' \<Longrightarrow> epdaS_step_relation G2 (F_ALT_EPDA_RECRev c1) (F_ALT_EPDA_REERev e1) (F_ALT_EPDA_RECRev c1')" apply(simp add: epdaS_step_relation_def F_ALT_EPDA_RECRev_def F_ALT_EPDA_RE_relation_TSstructureRL_def F_ALT_EPDA_RECRev_def F_ALT_EPDA_REERev_def F_ALT_EPDA_RE_def Let_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_step_relation_step_simulation: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<exists>d2. epdaS.derivation G2 d2 \<and> epdaS.belongs G2 d2 \<and> the (get_configuration (d2 0)) = c2 \<and> F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \<and> (\<exists>n. maximum_of_domain d2 n \<and> F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1' (the (get_configuration (d2 n))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_step_simulationRL_def) apply(rule context_conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule epdaS.der2_is_derivation) apply(rule F_ALT_EPDA_RERev_preserves_step_relation) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule epdaS.derivation_belongs) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(simp add: valid_pda_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: der2_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule F_ALT_EPDA_RE_C_rev_preserves_configurations) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(simp add: get_configuration_def der2_def F_ALT_EPDA_RE_relation_configurationRL_def F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*) apply(rule_tac x = "Suc 0" in exI) apply(simp add: maximum_of_domain_def der2_def) apply(simp add: get_configuration_def F_ALT_EPDA_RE_relation_configurationRL_def F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(clarsimp) apply(rename_tac G2 c1 e1 c1')(*strict*) apply(rule epdaS.AX_step_relation_preserves_belongsC) apply(rename_tac G2 c1 e1 c1')(*strict*) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) apply(rename_tac G2 c1 e1 c1')(*strict*) apply(force) apply(rename_tac G2 c1 e1 c1')(*strict*) apply(force) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms: " ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_configurationRL F_ALT_EPDA_RE_relation_TSstructureRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL" apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_step_relation_step_simulation epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs) done interpretation "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL" : ATS_Simulation_Configuration_Weak (* TSstructure1 *) "valid_epda" (* configurations1 *) "epdaS_configurations" (* initial_configurations1 *) "epdaS_initial_configurations" (* step_labels1 *) "epda_step_labels" (* step_relation1 *) "epdaS_step_relation" (* effects1 *) "epda_effects" (* marking_condition1 *) "epdaS_marking_condition" (* marked_effect1 *) "epdaS_marked_effect" (* unmarked_effect1 *) "epdaS_unmarked_effect" (* TSstructure2 *) "valid_epda" (* configurations2 *) "epdaS_configurations" (* initial_configurations2 *) "epdaS_initial_configurations" (* step_labels2 *) "epda_step_labels" (* step_relation2 *) "epdaS_step_relation" (* effects2 *) "epda_effects" (* marking_condition2 *) "epdaS_marking_condition" (* marked_effect2 *) "epdaS_marked_effect" (* unmarked_effect2 *) "epdaS_unmarked_effect" (* relation_configuration *) "F_ALT_EPDA_RE_relation_configurationRL" (* relation_initial_configuration *) "F_ALT_EPDA_RE_relation_initial_configurationRL" (* relation_effect *) "F_ALT_EPDA_RE_relation_effectRL" (* relation_TSstructure *) "F_ALT_EPDA_RE_relation_TSstructureRL" (* relation_initial_simulation *) "F_ALT_EPDA_RE_relation_initial_simulationRL" (* relation_step_simulation *) "F_ALT_EPDA_RE_relation_step_simulationRL" apply(simp add: LOCALE_DEFS epda_interpretations) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms) done lemma F_ALT_EPDA_RE_C_rev_preserves_marking_configurations: " F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<Longrightarrow> c1 \<in> epdaS_marking_configurations G1 \<Longrightarrow> F_ALT_EPDA_RECRev c1 \<in> epdaS_marking_configurations G2" apply(simp add: epdaS_marking_configurations_def F_ALT_EPDA_RECRev_def F_ALT_EPDA_RE_relation_TSstructureRL_def F_ALT_EPDA_RE_def F_ALT_EPDA_RECRev_def Let_def epdaS_configurations_def valid_pda_def valid_epda_def) apply(force) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_marking_condition: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: epdaS_marking_condition_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(thin_tac "derivation_append deri1 (der2 c1 e1 c1') deri1n i = Some (pair e c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(rule_tac x = "e" in exI) apply(rule_tac x = "c" in exI) apply(clarsimp) apply(rule_tac t = "c" and s = "F_ALT_EPDA_RECRev ca" in ssubst) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(simp add: derivation_append_def get_configuration_def) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule F_ALT_EPDA_RE_C_rev_preserves_marking_configurations) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "i = Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*) apply(subgoal_tac "c = c1'") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_def) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "Suc deri1n" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y)(*strict*) apply(rule_tac x = "deri2n+n" in exI) apply(case_tac y) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(rule_tac t = "c" and s = "F_ALT_EPDA_RECRev c1'" in ssubst) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def derivation_append_def get_configuration_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(rule F_ALT_EPDA_RE_C_rev_preserves_marking_configurations) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def derivation_append_def get_configuration_def F_ALT_EPDA_RE_relation_initial_configurationRL_def der2_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i>Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(simp add: derivation_append_def der2_def) apply(case_tac "i-deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*) apply(clarsimp) apply(case_tac nat) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat nata)(*strict*) apply(clarsimp) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_marking_condition: " \<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_initial_simulationRL G1 G2 c1 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: epdaS_marking_condition_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(clarsimp) apply(case_tac y) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(rule_tac x = "e" in exI) apply(rule_tac x = "c" in exI) apply(clarsimp) apply(rule_tac t = "c" and s = "F_ALT_EPDA_RECRev ca" in ssubst) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(simp add: derivation_append_def get_configuration_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(rule F_ALT_EPDA_RE_C_rev_preserves_marking_configurations) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*) apply(force) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(subgoal_tac "i = deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(case_tac "i>deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) prefer 2 apply(force) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*) apply(clarsimp) apply(simp add: derivation_append_def der1_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms: " ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_configurationRL F_ALT_EPDA_RE_relation_TSstructureRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL" apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def) apply(rule conjI) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_step_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_marking_condition) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_initial_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_marking_condition) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_marked_effect: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectRL G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(rule_tac x = "a" in bexI) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectRL_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_marked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*) apply(simp add: derivation_append_def F_ALT_EPDA_RE_relation_initial_configurationRL_def) apply(clarsimp) apply(simp add: get_configuration_def F_ALT_EPDA_RECRev_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_marked_effect: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_initial_simulationRL G1 G2 c1 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectRL G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(rule_tac x = "a" in bexI) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectRL_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_marked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*) apply(simp add: derivation_append_def F_ALT_EPDA_RE_relation_initial_configurationRL_def) apply(clarsimp) apply(simp add: get_configuration_def F_ALT_EPDA_RECRev_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*) apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms: " ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_configurationRL F_ALT_EPDA_RE_relation_effectRL F_ALT_EPDA_RE_relation_TSstructureRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL" apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def) apply(rule conjI) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_step_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_marked_effect) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_initial_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_marked_effect) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_unmarked_effect: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1 c2. F_ALT_EPDA_RE_relation_configurationRL G1 G2 c1 c2 \<longrightarrow> (\<forall>e1. e1 \<in> epda_step_labels G1 \<longrightarrow> (\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectRL G1 G2) (epdaS_unmarked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_unmarked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_unmarked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectRL_def) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) prefer 2 apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(rule_tac x = "ca" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c')") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_DEF_def) apply(clarsimp) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e c)(*strict*) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationRL_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(subgoal_tac "\<exists>c. deri1 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) prefer 2 apply(rule_tac M = "G1" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(simp add: F_ALT_EPDA_RECRev_def) apply(rule_tac x = "c'" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(subgoal_tac "i = Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(case_tac "i>Suc deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(clarsimp) apply(simp add: derivation_append_def der2_def) apply(case_tac "i-deri1n") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca nat)(*strict*) apply(clarsimp) apply(case_tac nat) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca nat)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i ca)(*strict*) apply(force) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca nat nata)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' e ca)(*strict*) apply(subgoal_tac "c' = c1'") apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def der2_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c c' e ca)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e ca)(*strict*) apply(rule_tac x = "F_ALT_EPDA_RECRev c1'" in exI) apply(simp add: derivation_append_def) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationRL_def) apply(clarsimp) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e)(*strict*) apply(rule conjI) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e)(*strict*) apply(rule_tac x = "deri2n+n" in exI) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_DEF_def) apply(clarsimp) apply(erule_tac x = "Suc deri1n" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e c)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e c)(*strict*) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e)(*strict*) apply(case_tac n) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f a ca ea e nat)(*strict*) apply(simp add: F_ALT_EPDA_RECRev_def) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a c e)(*strict*) apply(simp add: F_ALT_EPDA_RECRev_def F_ALT_EPDA_REC_def F_ALT_EPDA_REC_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_unmarked_effect: " (\<forall>G1 G2. F_ALT_EPDA_RE_relation_TSstructureRL G1 G2 \<longrightarrow> (\<forall>c1. c1 \<in> epdaS_initial_configurations G1 \<longrightarrow> (\<forall>d2. F_ALT_EPDA_RE_relation_initial_simulationRL G1 G2 c1 d2 \<longrightarrow> (\<forall>n. maximum_of_domain d2 n \<longrightarrow> (\<forall>deri1. epdaS.derivation_initial G1 deri1 \<longrightarrow> (\<forall>deri1n. maximum_of_domain deri1 deri1n \<longrightarrow> (\<forall>deri2. epdaS.derivation_initial G2 deri2 \<longrightarrow> (\<forall>deri2n. maximum_of_domain deri2 deri2n \<longrightarrow> F_ALT_EPDA_RE_relation_initial_configurationRL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \<longrightarrow> derivation_append_fit deri2 d2 deri2n \<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \<longrightarrow> left_total_on (F_ALT_EPDA_RE_relation_effectRL G1 G2) (epdaS_unmarked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_unmarked_effect G2 (derivation_append deri2 d2 deri2n))))))))))" apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*) apply(rename_tac f) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*) apply(simp add: epdaS_unmarked_effect_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectRL_def) apply(subgoal_tac "\<exists>c. deri2 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) prefer 2 apply(rule_tac M = "G2" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(rule_tac x = "ca" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(case_tac "i\<le>deri1n") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(subgoal_tac "deri1 i = Some (pair e c')") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) prefer 2 apply(simp add: derivation_append_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_def) apply(clarsimp) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.simulating_derivation_DEF_def) apply(clarsimp) apply(simp add: F_ALT_EPDA_RE_relation_configurationRL_def) apply(erule_tac x = "i" in allE) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y)(*strict*) apply(case_tac y) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca y option b)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca option b)(*strict*) apply(rename_tac e c) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e c)(*strict*) apply(simp add: get_configuration_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea caa e)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_initial_configurationRL_def) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(subgoal_tac "\<exists>c. deri1 0 = Some (pair None c)") apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) prefer 2 apply(rule_tac M = "G1" in epdaS.some_position_has_details_at_0) apply (metis epdaS.derivation_initial_is_derivation) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e)(*strict*) apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "c'" in exI) apply(rule conjI) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(rule_tac x = "f i" in exI) apply(clarsimp) apply(simp add: derivation_append_def F_ALT_EPDA_RECRev_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a ca c' i ea e c)(*strict*) apply(simp add: derivation_append_def F_ALT_EPDA_RECRev_def) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a c c' i e ca)(*strict*) apply(simp add: derivation_append_def der1_def) done lemma epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ANY_axioms: " ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_unmarked_effect epdaS_initial_configurations epdaS_step_relation epdaS_unmarked_effect F_ALT_EPDA_RE_relation_configurationRL F_ALT_EPDA_RE_relation_initial_configurationRL F_ALT_EPDA_RE_relation_effectRL F_ALT_EPDA_RE_relation_TSstructureRL F_ALT_EPDA_RE_relation_initial_simulationRL F_ALT_EPDA_RE_relation_step_simulationRL" apply(simp add: ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms_def) apply(rule conjI) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_step_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_unmarked_effect) apply(clarsimp) apply(rename_tac G1 G2 d1' d2')(*strict*) apply(rule epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_initial_simulation_preservation_PROVE2) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) prefer 2 apply(rename_tac G1 G2 d1' d2')(*strict*) apply(force) apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(thin_tac "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'") apply(clarsimp) apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*) apply(metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_unmarked_effect) done interpretation "epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL" : ATS_Simulation_Configuration_WeakLR_FULL (* TSstructure1 *) "valid_epda" (* configurations1 *) "epdaS_configurations" (* initial_configurations1 *) "epdaS_initial_configurations" (* step_labels1 *) "epda_step_labels" (* step_relation1 *) "epdaS_step_relation" (* effects1 *) "epda_effects" (* marking_condition1 *) "epdaS_marking_condition" (* marked_effect1 *) "epdaS_marked_effect" (* unmarked_effect1 *) "epdaS_unmarked_effect" (* TSstructure2 *) "valid_epda" (* configurations2 *) "epdaS_configurations" (* initial_configurations2 *) "epdaS_initial_configurations" (* step_labels2 *) "epda_step_labels" (* step_relation2 *) "epdaS_step_relation" (* effects2 *) "epda_effects" (* marking_condition2 *) "epdaS_marking_condition" (* marked_effect2 *) "epdaS_marked_effect" (* unmarked_effect2 *) "epdaS_unmarked_effect" (* relation_configuration *) "F_ALT_EPDA_RE_relation_configurationRL" (* relation_initial_configuration *) "F_ALT_EPDA_RE_relation_initial_configurationRL" (* relation_effect *) "F_ALT_EPDA_RE_relation_effectRL" (* relation_TSstructure *) "F_ALT_EPDA_RE_relation_TSstructureRL" (* relation_initial_simulation *) "F_ALT_EPDA_RE_relation_initial_simulationRL" (* relation_step_simulation *) "F_ALT_EPDA_RE_relation_step_simulationRL" apply(simp add: LOCALE_DEFS epda_interpretations) apply(simp add: epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ANY_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms) done lemma F_ALT_EPDA_RE_preserves_lang2: " valid_pda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.marked_language G \<supseteq> epdaS.marked_language (F_ALT_EPDA_RE G E)" apply(rule_tac t = "epdaS.marked_language G" and s = "epdaS.finite_marked_language G" in ssubst) apply (metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_ALT_EPDA_RE_relation_TSstructureLR_def epdaS_inst_lang_finite) apply(rule_tac t = "epdaS.marked_language (F_ALT_EPDA_RE G E)" and s = "epdaS.finite_marked_language (F_ALT_EPDA_RE G E)" in ssubst) apply(rule sym) apply(rule epdaS.AX_marked_language_finite) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) apply(subgoal_tac "left_total_on (F_ALT_EPDA_RE_relation_effectRL SSG1 SSG2) (epdaS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)" for SSG1 SSG2) prefer 2 apply(rule_tac ?G2.0 = "G" in epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.ATS_Simulation_Configuration_Weak_Marked_Effect_sound) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(erule_tac x = "x" in ballE) apply(rename_tac x)(*strict*) prefer 2 apply(force) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac x b)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectRL_def) done lemma F_ALT_EPDA_RE_preserves_unmarked_language2: " valid_pda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.unmarked_language G \<supseteq> epdaS.unmarked_language (F_ALT_EPDA_RE G E)" apply(rule_tac t = "epdaS.unmarked_language G" and s = "epdaS.finite_unmarked_language G" in ssubst) apply (metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_ALT_EPDA_RE_relation_TSstructureLR_def epdaS_inst_AX_unmarked_language_finite n_not_Suc_n) apply(rule_tac t = "epdaS.unmarked_language (F_ALT_EPDA_RE G E)" and s = "epdaS.finite_unmarked_language (F_ALT_EPDA_RE G E)" in ssubst) apply(rule sym) apply(rule epdaS.AX_unmarked_language_finite) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) apply(subgoal_tac "left_total_on (F_ALT_EPDA_RE_relation_effectRL SSG1 SSG2) (epdaS.finite_unmarked_language SSG1) (epdaS.finite_unmarked_language SSG2)" for SSG1 SSG2) prefer 2 apply(rule_tac ?G2.0 = "G" in epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL.ATS_Simulation_Configuration_Weak_Unmarked_Effect_sound) apply(simp add: F_ALT_EPDA_RE_relation_TSstructureRL_def) apply(simp add: left_total_on_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(erule_tac x = "x" in ballE) apply(rename_tac x)(*strict*) prefer 2 apply(force) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac x b)(*strict*) apply(simp add: F_ALT_EPDA_RE_relation_effectRL_def) done lemma F_ALT_EPDA_RE_preserves_lang: " valid_pda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.marked_language G = epdaS.marked_language (F_ALT_EPDA_RE G E)" apply(rule order_antisym) apply (metis F_ALT_EPDA_RE_preserves_lang1) apply (metis F_ALT_EPDA_RE_preserves_lang2) done lemma F_ALT_EPDA_RE_preserves_unmarked_language: " valid_pda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.unmarked_language G = epdaS.unmarked_language (F_ALT_EPDA_RE G E)" apply(rule order_antisym) apply (metis F_ALT_EPDA_RE_preserves_unmarked_language1) apply (metis F_ALT_EPDA_RE_preserves_unmarked_language2) done lemma F_ALT_EPDA_RE_preserves_DPDA: " valid_dpda G \<Longrightarrow> E \<subseteq> epda_delta G \<Longrightarrow> valid_dpda (F_ALT_EPDA_RE G E)" apply(simp add: valid_dpda_def) apply(clarsimp) apply(rule conjI) apply (metis F_ALT_EPDA_RE_preserves_PDA) apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(erule_tac x="c" in ballE) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(erule_tac x="c1" in allE) apply(erule_tac x="c2" in allE) apply(erule_tac x="e1" in allE) apply(erule_tac x="e2" in allE) apply(erule impE) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(simp add: F_ALT_EPDA_RE_def epdaS_step_relation_def Let_def) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(force) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(subgoal_tac "c \<in> epdaS.get_accessible_configurations G") apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(force) apply(rename_tac c c1 c2 e1 e2)(*strict*) apply(thin_tac "c \<notin> A" for A) apply(simp add: epdaS.get_accessible_configurations_def) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) apply(rule_tac x="d" in exI) apply(rule conjI) apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) prefer 2 apply(rule_tac x="i" in exI) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) apply(rule epdaS.derivation_initialI) apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) apply(simp (no_asm) add: epdaS.derivation_def) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i ia)(*strict*) apply(case_tac ia) apply(rename_tac c c1 c2 e1 e2 d i ia)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) apply(simp add: epdaS.derivation_initial_def epdaS.derivation_def) apply(case_tac "d 0") apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) apply(force) apply(rename_tac c c1 c2 e1 e2 d i a)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac c c1 c2 e1 e2 d i a option conf)(*strict*) apply(force) apply(rename_tac c c1 c2 e1 e2 d i ia nat)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i nat)(*strict*) apply(simp add: epdaS.derivation_initial_def epdaS.derivation_def) apply(clarsimp) apply(erule_tac x="Suc nat" in allE) apply(clarsimp) apply(case_tac "d (Suc nat)") apply(rename_tac c c1 c2 e1 e2 d i nat)(*strict*) apply(force) apply(rename_tac c c1 c2 e1 e2 d i nat a)(*strict*) apply(case_tac "d nat") apply(rename_tac c c1 c2 e1 e2 d i nat a)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac c c1 c2 e1 e2 d i nat a option conf)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i nat a aa)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac c c1 c2 e1 e2 d i nat a aa option conf)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i nat aa option conf)(*strict*) apply(case_tac aa) apply(rename_tac c c1 c2 e1 e2 d i nat aa option conf optiona confa)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i nat option conf optiona confa)(*strict*) apply(case_tac option) apply(rename_tac c c1 c2 e1 e2 d i nat option conf optiona confa)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i nat option conf optiona confa a)(*strict*) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i nat conf optiona confa a)(*strict*) apply(simp add: F_ALT_EPDA_RE_def epdaS_step_relation_def Let_def) apply(rename_tac c c1 c2 e1 e2 d i)(*strict*) apply(simp add: epdaS.derivation_initial_def epdaS.derivation_def get_configuration_def) apply(clarsimp) apply(rename_tac c c1 c2 e1 e2 d i ca)(*strict*) apply(simp add: epdaS_configurations_def epdaS_initial_configurations_def F_ALT_EPDA_RE_def epdaS_step_relation_def Let_def valid_pda_def valid_epda_def) apply(clarsimp) done lemma F_ALT_EPDA_RE_preserves_derivation: " valid_dpda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.derivation_initial G d \<Longrightarrow> epdaS.derivation_initial (F_ALT_EPDA_RE G E) d" apply(simp add: epdaS.derivation_initial_def) apply(rule conjI) prefer 2 apply(case_tac "d 0") apply(clarsimp) apply(rename_tac a)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac a option b)(*strict*) apply(clarsimp) apply(rename_tac b)(*strict*) apply(simp add: F_ALT_EPDA_RE_def Let_def epdaS_initial_configurations_def F_ALT_EPDA_RE_relation_TSstructureLR_def valid_dpda_def valid_pda_def valid_epda_def epdaS_configurations_def) apply(clarsimp) apply(clarsimp) apply(simp (no_asm) add: epdaS.derivation_def) apply(clarsimp) apply(rename_tac i)(*strict*) apply(case_tac i) apply(rename_tac i)(*strict*) apply(clarsimp) apply(case_tac "d 0") apply(clarsimp) apply(rename_tac a)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac a option b)(*strict*) apply(clarsimp) apply(rename_tac i nat)(*strict*) apply(clarsimp) apply(rename_tac nat)(*strict*) apply(case_tac "d (Suc nat)") apply(rename_tac nat)(*strict*) apply(clarsimp) apply(rename_tac nat a)(*strict*) apply(clarsimp) apply(subgoal_tac "\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \<and> d (Suc nat) = Some (pair (Some e2) c2) \<and> epdaS_step_relation G c1 e2 c2") apply(rename_tac nat a)(*strict*) prefer 2 apply(rule_tac m = "Suc nat" in epdaS.step_detail_before_some_position) apply(rename_tac nat a)(*strict*) apply(force) apply(rename_tac nat a)(*strict*) apply(force) apply(rename_tac nat a)(*strict*) apply(force) apply(rename_tac nat a)(*strict*) apply(clarsimp) apply(rename_tac nat e1 e2 c1 c2)(*strict*) apply(simp add: F_ALT_EPDA_RE_def Let_def epdaS_initial_configurations_def F_ALT_EPDA_RE_relation_TSstructureLR_def valid_dpda_def valid_pda_def valid_epda_def epdaS_configurations_def epdaS_step_relation_def epdaS_accessible_edges_def) apply(clarsimp) apply(rename_tac nat e1 e2 c1 c2 w)(*strict*) apply(rule_tac x = "d" in exI) apply(simp add: epdaS.derivation_initial_def) apply(force) done lemma F_ALT_EPDA_RE_establishes_coblockbreeness: " valid_dpda G \<Longrightarrow> E = epdaS_accessible_edges G \<Longrightarrow> epdaS.accessible (F_ALT_EPDA_RE G E)" apply(simp add: epdaS.accessible_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(simp add: epdaS.get_accessible_destinations_def epda_destinations_def) apply(erule disjE) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac xa)(*strict*) apply(simp add: epdaS_get_destinations_def) apply(case_tac "xa = epda_initial G") apply(rename_tac xa)(*strict*) apply(rule_tac x = "der1 \<lparr>epdaS_conf_state = epda_initial G, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box G]\<rparr>" in exI) apply(rule conjI) apply(rename_tac xa)(*strict*) apply(simp add: epdaS.derivation_initial_def) apply(rule conjI) apply(rename_tac xa)(*strict*) apply(rule epdaS.der1_is_derivation) apply(rename_tac xa)(*strict*) apply(simp add: der1_def) apply(simp add: epdaS_initial_configurations_def epdaS_configurations_def) apply(simp add: valid_dpda_def valid_pda_def valid_epda_def) apply(simp add: der1_def) apply(clarsimp) apply(simp add: epdaS_accessible_edges_def) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac xa)(*strict*) apply(clarsimp) apply(rule_tac x = "0" in exI) apply(simp add: der1_def) apply(rename_tac xa)(*strict*) apply(subgoal_tac "xa \<in> epda_states G \<and> (\<exists>e\<in> epda_delta G \<inter> epdaS_accessible_edges G. edge_src e = xa \<or> edge_trg e = xa)") apply(rename_tac xa)(*strict*) prefer 2 apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac xa)(*strict*) apply(clarsimp) apply(rename_tac xa e)(*strict*) apply(subgoal_tac "\<exists>d. epdaS.derivation_initial G d \<and> (\<exists>n c. d n = Some (pair (Some e) c))") apply(rename_tac xa e)(*strict*) prefer 2 apply(simp add: epdaS_accessible_edges_def) apply(rename_tac xa e)(*strict*) apply(clarsimp) apply(rename_tac xa e d n c)(*strict*) apply(rule_tac x = "d" in exI) apply(rule conjI) apply(rename_tac xa e d n c)(*strict*) apply(rule F_ALT_EPDA_RE_preserves_derivation) apply(rename_tac xa e d n c)(*strict*) apply(force) apply(rename_tac xa e d n c)(*strict*) apply(force) apply(rename_tac xa e d n c)(*strict*) apply(force) apply(rename_tac xa e d n c)(*strict*) apply(case_tac n) apply(rename_tac xa e d n c)(*strict*) apply(clarsimp) apply(rename_tac xa e d c)(*strict*) apply(simp add: valid_dpda_def valid_pda_def) apply(clarsimp) apply (metis epdaS.derivation_initial_is_derivation epdaS.initialNotEdgeSome) apply(rename_tac xa e d n c nat)(*strict*) apply(subgoal_tac "\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \<and> d (Suc nat) = Some (pair (Some e2) c2) \<and> epdaS_step_relation G c1 e2 c2") apply(rename_tac xa e d n c nat)(*strict*) prefer 2 apply(rule_tac m = "Suc nat" in epdaS.step_detail_before_some_position) apply(rename_tac xa e d n c nat)(*strict*) apply(rule epdaS.derivation_initial_is_derivation) apply(force) apply(rename_tac xa e d n c nat)(*strict*) apply(force) apply(rename_tac xa e d n c nat)(*strict*) apply(force) apply(rename_tac xa e d n c nat)(*strict*) apply(clarsimp) apply(rename_tac xa e d c nat e1 c1)(*strict*) apply(simp add: epdaS_step_relation_def) apply(erule disjE) apply(rename_tac xa e d c nat e1 c1)(*strict*) apply(rule_tac x = "nat" in exI) apply(rule_tac x = "e1" in exI) apply(rule_tac x = "c1" in exI) apply(clarsimp) apply(rename_tac xa e d c nat e1 c1)(*strict*) apply(rule_tac x = "Suc nat" in exI) apply(rule_tac x = "Some e" in exI) apply(rule_tac x = "c" in exI) apply(clarsimp) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac xa)(*strict*) apply(simp add: epdaS_get_destinations_def) apply(subgoal_tac "xa \<in> epdaS_accessible_edges G") apply(rename_tac xa)(*strict*) prefer 2 apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac xa)(*strict*) apply(subgoal_tac "(\<exists>d. epdaS.derivation_initial G d \<and> (\<exists>n c. d n = Some (pair (Some xa) c)))") apply(rename_tac xa)(*strict*) prefer 2 apply(simp add: epdaS_accessible_edges_def) apply(rename_tac xa)(*strict*) apply(clarsimp) apply(rename_tac xa d n c)(*strict*) apply(rule_tac x = "d" in exI) apply(rule conjI) apply(rename_tac xa d n c)(*strict*) apply(rule F_ALT_EPDA_RE_preserves_derivation) apply(rename_tac xa d n c)(*strict*) apply(force) apply(rename_tac xa d n c)(*strict*) apply(force) apply(rename_tac xa d n c)(*strict*) apply(force) apply(rename_tac xa d n c)(*strict*) apply(rule_tac x = "n" in exI) apply(rule_tac x = "Some xa" in exI) apply(clarsimp) done definition F_EPDA_RE__SpecInput :: " (('state, 'event, 'stack) epda \<times> ('state, 'event, 'stack) epda_step_label set) \<Rightarrow> bool" where "F_EPDA_RE__SpecInput X \<equiv> case X of (G, E) \<Rightarrow> valid_dpda G \<and> E = epdaS_accessible_edges G" definition F_EPDA_RE__SpecOutput :: " (('state, 'event, 'stack) epda \<times> ('state, 'event, 'stack) epda_step_label set) \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> bool" where "F_EPDA_RE__SpecOutput X Go \<equiv> case X of (Gi, E) \<Rightarrow> valid_dpda Go \<and> epdaS.accessible Go \<and> epdaS.marked_language Gi = epdaS.marked_language Go \<and> epdaS.unmarked_language Gi = epdaS.unmarked_language Go" lemma F_ALT_EPDA_RE__SOUND: " F_EPDA_RE__SpecInput (G, E) \<Longrightarrow> F_EPDA_RE__SpecOutput (G, E) (F_ALT_EPDA_RE G E)" apply(simp add: F_EPDA_RE__SpecInput_def F_EPDA_RE__SpecOutput_def) apply(rule context_conjI) apply(rule F_ALT_EPDA_RE_preserves_DPDA) apply(force) apply(simp add: epdaS_accessible_edges_def) apply(force) apply(rule conjI) apply(rule F_ALT_EPDA_RE_establishes_coblockbreeness) apply(force) apply(force) apply(rule conjI) apply(rule F_ALT_EPDA_RE_preserves_lang) apply(simp add: valid_dpda_def) apply(force) apply(rule F_ALT_EPDA_RE_preserves_unmarked_language) apply(simp add: valid_dpda_def) apply(force) done theorem F_EPDA_RE__SOUND: " F_EPDA_RE__SpecInput (G, E) \<Longrightarrow> F_EPDA_RE__SpecOutput (G, E) (F_EPDA_RE G E)" apply(rule_tac t="F_EPDA_RE G E" and s="F_ALT_EPDA_RE G E" in ssubst) apply(rule F_EPDA_RE__vs_F_ALT_EPDA_RE) apply(simp add: F_EPDA_RE__SpecInput_def F_EPDA_RE__SpecOutput_def) apply(simp add: valid_dpda_def valid_pda_def) apply(rule F_ALT_EPDA_RE__SOUND) apply(force) done definition F_EPDA_RE__SpecInput2 :: " (('state, 'event, 'stack) epda \<times> ('state, 'event, 'stack) epda_step_label set) \<Rightarrow> bool" where "F_EPDA_RE__SpecInput2 X \<equiv> case X of (G, E) \<Rightarrow> valid_dpda G \<and> E = epdaS_required_edges G" definition F_EPDA_RE__SpecOutput2 :: " (('state, 'event, 'stack) epda \<times> ('state, 'event, 'stack) epda_step_label set) \<Rightarrow> ('state, 'event, 'stack) epda \<Rightarrow> bool" where "F_EPDA_RE__SpecOutput2 X Go \<equiv> case X of (Gi, E) \<Rightarrow> valid_dpda Go \<and> epdaS.accessible Go \<and> epdaS.marked_language Gi = epdaS.marked_language Go \<and> epdaS.unmarked_language Go \<subseteq> epdaS.unmarked_language Gi \<and> (epdaH.Nonblockingness_branching Gi \<longrightarrow> (epdaS.unmarked_language Gi \<subseteq> epdaS.unmarked_language Go \<and> epdaH.Nonblockingness_branching Go))" lemma F_ALT_EPDA_RE_preserves_derivation__epdaS_required_edges: " valid_dpda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> epdaS.derivation_initial G d \<Longrightarrow> d k = Some (pair ea ca) \<Longrightarrow> ca \<in> epdaS_marking_configurations G \<Longrightarrow> epdaS.derivation_initial (F_ALT_EPDA_RE G E) (derivation_take d k)" apply(simp add: epdaS.derivation_initial_def) apply(rule conjI) prefer 2 apply(case_tac "d 0") apply(clarsimp) apply(rename_tac a)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac a option b)(*strict*) apply(clarsimp) apply(rename_tac b)(*strict*) apply(simp add: F_ALT_EPDA_RE_def Let_def epdaS_initial_configurations_def F_ALT_EPDA_RE_relation_TSstructureLR_def valid_dpda_def valid_pda_def valid_epda_def epdaS_configurations_def derivation_take_def) apply(clarsimp) apply(clarsimp) apply(simp (no_asm) add: epdaS.derivation_def) apply(clarsimp) apply(rename_tac i)(*strict*) apply(case_tac i) apply(rename_tac i)(*strict*) apply(clarsimp) apply(case_tac "d 0") apply(clarsimp) apply(rename_tac a)(*strict*) apply(clarsimp) apply(case_tac a) apply(rename_tac a option b)(*strict*) apply(clarsimp) apply(simp add: derivation_take_def) apply(rename_tac i nat)(*strict*) apply(clarsimp) apply(rename_tac nat)(*strict*) apply(case_tac "d (Suc nat)") apply(rename_tac nat)(*strict*) apply(simp add: derivation_take_def) apply(rename_tac nat a)(*strict*) apply(simp add: derivation_take_def) apply(subgoal_tac "\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \<and> d (Suc nat) = Some (pair (Some e2) c2) \<and> epdaS_step_relation G c1 e2 c2") apply(rename_tac nat a)(*strict*) prefer 2 apply(rule_tac m = "Suc nat" in epdaS.step_detail_before_some_position) apply(rename_tac nat a)(*strict*) apply(force) apply(rename_tac nat a)(*strict*) apply(force) apply(rename_tac nat a)(*strict*) apply(force) apply(rename_tac nat a)(*strict*) apply(clarsimp) apply(rename_tac nat e1 e2 c1 c2)(*strict*) apply(simp add: F_ALT_EPDA_RE_def Let_def epdaS_initial_configurations_def F_ALT_EPDA_RE_relation_TSstructureLR_def valid_dpda_def valid_pda_def valid_epda_def epdaS_configurations_def epdaS_step_relation_def epdaS_accessible_edges_def) apply(clarsimp) apply(simp add: derivation_take_def) apply(simp add: epdaS_step_relation_def F_ALT_EPDA_RE_def Let_def epdaS_required_edges_def) apply(rename_tac nat e1 e2 c1 c2 w)(*strict*) apply(rule_tac x = "d" in exI) apply(simp add: epdaS.derivation_initial_def) apply(force) done lemma F_ALT_EPDA_RE_establishes_coblockbreeness__epdaS_required_edges: " valid_dpda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> epdaS.accessible (F_ALT_EPDA_RE G E)" apply(simp add: epdaS.accessible_def) apply(clarsimp) apply(rename_tac x)(*strict*) apply(simp add: epdaS.get_accessible_destinations_def epda_destinations_def) apply(erule disjE) apply(rename_tac x)(*strict*) apply(clarsimp) apply(rename_tac xa)(*strict*) apply(simp add: epdaS_get_destinations_def) apply(case_tac "xa = epda_initial G") apply(rename_tac xa)(*strict*) apply(rule_tac x = "der1 \<lparr>epdaS_conf_state = epda_initial G, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box G]\<rparr>" in exI) apply(rule conjI) apply(rename_tac xa)(*strict*) apply(simp add: epdaS.derivation_initial_def) apply(rule conjI) apply(rename_tac xa)(*strict*) apply(rule epdaS.der1_is_derivation) apply(rename_tac xa)(*strict*) apply(simp add: der1_def) apply(simp add: epdaS_initial_configurations_def epdaS_configurations_def) apply(simp add: valid_dpda_def valid_pda_def valid_epda_def) apply(simp add: der1_def) apply(clarsimp) apply(simp add: epdaS_required_edges_def) apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac xa)(*strict*) apply(clarsimp) apply(rule_tac x = "0" in exI) apply(simp add: der1_def) apply(rename_tac xa)(*strict*) apply(subgoal_tac "xa \<in> epda_states G \<and> (\<exists>e\<in> epda_delta G \<inter> epdaS_required_edges G. edge_src e = xa \<or> edge_trg e = xa)") apply(rename_tac xa)(*strict*) prefer 2 apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac xa)(*strict*) apply(clarsimp) apply(rename_tac xa e)(*strict*) apply(subgoal_tac "\<exists>d. epdaS.derivation_initial G d \<and> (\<exists>n. (\<exists>c. d n = Some (pair (Some e) c)) \<and> (\<exists>k\<ge>n. \<exists>e c. d k = Some (pair e c) \<and> c \<in> epdaS_marking_configurations G))") apply(rename_tac xa e)(*strict*) prefer 2 apply(simp add: epdaS_required_edges_def) apply(rename_tac xa e)(*strict*) apply(clarsimp) apply(rule_tac x = "derivation_take d k" in exI) apply(rule conjI) apply(rule F_ALT_EPDA_RE_preserves_derivation__epdaS_required_edges) apply(force) apply(force) apply(force) apply(force) apply(force) apply(case_tac n) apply(clarsimp) apply(simp add: valid_dpda_def valid_pda_def) apply(clarsimp) apply (metis epdaS.derivation_initial_is_derivation epdaS.initialNotEdgeSome) apply(subgoal_tac "\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \<and> d (Suc nat) = Some (pair (Some e2) c2) \<and> epdaS_step_relation G c1 e2 c2") prefer 2 apply(rule_tac m = "Suc nat" in epdaS.step_detail_before_some_position) apply(rule epdaS.derivation_initial_is_derivation) apply(force) apply(force) apply(force) apply(clarsimp) apply(simp add: epdaS_step_relation_def) apply(erule disjE) apply(rule_tac x = "nat" in exI) apply(rule_tac x = "e1" in exI) apply(rule_tac x = "c1" in exI) apply(clarsimp) apply(simp add: derivation_take_def) apply(rule_tac x = "Suc nat" in exI) apply(rule_tac x = "Some e" in exI) apply(rule_tac x = "c" in exI) apply(clarsimp) apply(simp add: derivation_take_def) apply(clarsimp) apply(simp add: epdaS_get_destinations_def) apply(subgoal_tac "xa \<in> epdaS_required_edges G") prefer 2 apply(simp add: F_ALT_EPDA_RE_def Let_def) apply(rename_tac xa)(*strict*) apply(subgoal_tac "xa \<in> epda_delta G \<and> (\<exists>d. epdaS.derivation_initial G d \<and> (\<exists>n. (\<exists>c. d n = Some (pair (Some xa) c)) \<and> (\<exists>k\<ge>n. \<exists>e c. d k = Some (pair e c) \<and> c \<in> epdaS_marking_configurations G)))") prefer 2 apply(simp add: epdaS_required_edges_def) apply(clarsimp) apply(rule_tac x = "derivation_take d k" in exI) apply(rule conjI) apply(rule F_ALT_EPDA_RE_preserves_derivation__epdaS_required_edges) apply(force) apply(force) apply(force) apply(force) apply(force) apply(rule_tac x = "n" in exI) apply(rule_tac x = "Some xa" in exI) apply(clarsimp) apply(simp add: derivation_take_def) done lemma F_ALT_EPDA_RE_preserves_lang2__epdaS_required_edges: " valid_epda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> epdaH.marked_language (F_ALT_EPDA_RE G E) \<subseteq> epdaH.marked_language G" apply(rule epda_sub_preserves_epdaH_marked_language) apply(force) apply(rule F_ALT_EPDA_RE_preserves_epda) apply(force) apply(simp add: epda_sub_def F_ALT_EPDA_RE_def Let_def valid_epda_def) apply(force) done lemma F_ALT_EPDA_RE_preserves_unmarked_lang2__epdaS_required_edges: " valid_epda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> epdaH.unmarked_language (F_ALT_EPDA_RE G E) \<subseteq> epdaH.unmarked_language G" apply(rule epda_sub_preserves_epdaH_unmarked_language) apply(force) apply(rule F_ALT_EPDA_RE_preserves_epda) apply(force) apply(simp add: epda_sub_def F_ALT_EPDA_RE_def Let_def valid_epda_def) apply(force) done lemma F_ALT_EPDA_RE_preserves_lang1__epdaS_required_edges: " valid_dpda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> epdaS.marked_language G \<subseteq> epdaS.marked_language (F_ALT_EPDA_RE G E)" apply(rule_tac t = "epdaS.marked_language G" and s = "epdaS.finite_marked_language G" in ssubst) apply(simp add: valid_dpda_def) apply (metis epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_ALT_EPDA_RE_relation_TSstructureLR_def epdaS.AX_marked_language_finite) apply(rule_tac t = "epdaS.marked_language (F_ALT_EPDA_RE G E)" and s = "epdaS.finite_marked_language (F_ALT_EPDA_RE G E)" in ssubst) apply(rule sym) apply(simp add: valid_dpda_def) apply(rule epdaS.AX_marked_language_finite) apply (metis F_ALT_EPDA_RE_preserves_epda PDA_to_epda) apply(clarsimp) apply(simp add: epdaS.finite_marked_language_def) apply(clarsimp) apply(simp add: epdaS_marking_condition_def) apply(clarsimp) apply(thin_tac "maximum_of_domain d xa") apply(rule_tac x="derivation_take d i" in exI) apply(rule conjI) apply(rule F_ALT_EPDA_RE_preserves_derivation__epdaS_required_edges) apply(force) apply(force) apply(force) apply(force) apply(force) apply(clarsimp) apply(rule conjI) apply(simp add: derivation_take_def epdaS_marked_effect_def) apply(rule conjI) apply(rule_tac x="i" in exI) apply(simp add: derivation_take_def epdaS_marked_effect_def) apply(clarsimp) apply(simp add: derivation_take_def epdaS_marked_effect_def epdaS_marking_configurations_def F_ALT_EPDA_RE_def Let_def epdaS_configurations_def) apply(erule conjE)+ apply(erule exE)+ apply(erule conjE)+ apply(rule conjI) apply(case_tac i) apply(rule disjI1) apply(clarsimp) apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def) apply(rule disjI2) apply(clarsimp) apply(subgoal_tac "X" for X) prefer 2 apply(rule_tac n="nat" and m = "Suc nat" in epdaS.step_detail_before_some_position) apply(rule epdaS.derivation_initial_is_derivation) apply(force) apply(force) apply(force) apply(clarsimp) apply(rule_tac x="e2" in bexI) apply(simp add: epdaS_step_relation_def) apply(simp add: epdaS_step_relation_def) apply(simp add: epdaS_required_edges_def) apply(rule_tac x="d" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(simp add: epdaS_marking_configurations_def epdaS_configurations_def) apply(rule_tac x="epdaS_conf_state c" in exI) apply(rule_tac x="epdaS_conf_scheduler c" in exI) apply(rule_tac x="epdaS_conf_stack c" in exI) apply(rule conjI) apply(clarsimp) apply(rule conjI) apply(case_tac i) apply(rule disjI1) apply(clarsimp) apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def) apply(rule disjI2) apply(clarsimp) apply(subgoal_tac "X" for X) prefer 2 apply(rule_tac n="nat" and m = "Suc nat" in epdaS.step_detail_before_some_position) apply(rule epdaS.derivation_initial_is_derivation) apply(force) apply(force) apply(force) apply(clarsimp) apply(rule_tac x="e2" in bexI) apply(simp add: epdaS_step_relation_def) apply(simp add: epdaS_step_relation_def) apply(simp add: epdaS_required_edges_def) apply(rule_tac x="d" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(simp add: epdaS_marking_configurations_def epdaS_configurations_def) apply(force) apply(rule_tac x="i" in exI) apply (metis maximum_of_domain_derivation_take not_None_eq) done lemma F_ALT_EPDA_RE_preserves_lang__epdaS_required_edges: " valid_dpda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> epdaS.marked_language G = epdaS.marked_language (F_ALT_EPDA_RE G E)" apply(rule order_antisym) apply (metis F_ALT_EPDA_RE_preserves_lang1__epdaS_required_edges) apply(simp add: valid_dpda_def valid_pda_def) apply(erule conjE) apply(subgoal_tac "X" for X) prefer 2 apply (rule F_ALT_EPDA_RE_preserves_lang2__epdaS_required_edges) apply(force) apply(force) apply (metis F_ALT_EPDA_RE_preserves_epda epdaS_to_epdaH_mlang) done lemma F_ALT_EPDA_RE_preserves_epdaH_initial_marking_derivations_at_end: " valid_epda G \<Longrightarrow> epdaH_initial_marking_derivations_at_end G \<subseteq> epdaH_initial_marking_derivations_at_end (F_ALT_EPDA_RE G (epdaH_required_edges G))" apply(simp add: epdaH_initial_marking_derivations_at_end_def) apply(clarsimp) apply(rename_tac d n e c) apply(rule context_conjI) apply(simp (no_asm) add: epdaH.derivation_initial_def) apply(rule context_conjI) apply(simp (no_asm) add: epdaH.derivation_def) apply(clarsimp) apply(case_tac i) apply(clarsimp) apply(case_tac "d 0") apply(simp add: epdaH.derivation_initial_def) apply(clarsimp) apply(case_tac a) apply(clarsimp) apply(simp add: epdaH.derivation_initial_def) apply(clarsimp) apply(rename_tac n) apply(case_tac "d (Suc n)") apply(clarsimp) apply(clarsimp) apply(subgoal_tac "X" for X) prefer 2 apply(rule_tac n="n" and m="Suc n" in epdaH.step_detail_before_some_position) apply(rule epdaH.derivation_initial_is_derivation) apply(force) apply(force) apply(force) apply(clarsimp) apply(simp add: epdaH_step_relation_def F_ALT_EPDA_RE_def Let_def epdaH_required_edges_def) apply(clarsimp) apply(rule_tac x="d" in exI) apply(clarsimp) apply(rule_tac x="Suc n" in exI) apply(clarsimp) apply(rule_tac x="na" in exI) apply(clarsimp) apply(rule epdaH.allPreMaxDomSome_prime) apply(simp add: epdaH.derivation_initial_def) apply(force) apply(force) apply(force) apply(case_tac "d 0") apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def) apply(case_tac a) apply(clarsimp) apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def) apply(clarsimp) apply(simp add: epdaH_initial_configurations_def F_ALT_EPDA_RE_def Let_def epdaH_configurations_def) apply(clarsimp) apply(rule_tac x="n" in exI) apply(clarsimp) apply(simp add: epdaH_marking_configurations_def epdaH_initial_configurations_def F_ALT_EPDA_RE_def Let_def epdaH_configurations_def) apply(erule conjE)+ apply(erule exE)+ apply(erule conjE)+ apply(rule conjI) apply(case_tac n) apply(rule disjI1) apply(clarsimp) apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def epdaH_initial_configurations_def) apply(rule disjI2) apply(clarsimp) apply(subgoal_tac "X" for X) prefer 2 apply(rule_tac n="nat" and m = "Suc nat" in epdaH.step_detail_before_some_position) apply(rule epdaH.derivation_initial_is_derivation) apply(force) apply(force) apply(force) apply(clarsimp) apply(rule_tac x="e2" in bexI) apply(simp add: epdaH_step_relation_def) apply(simp add: epdaH_step_relation_def) apply(simp add: epdaH_required_edges_def) apply(rule_tac x="d" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(simp add: epdaH_marking_configurations_def epdaH_configurations_def) apply(rule_tac x="epdaH_conf_state c" in exI) apply(rule_tac x="epdaH_conf_stack c" in exI) apply(rule_tac x="epdaH_conf_history c" in exI) apply(rule conjI) apply(clarsimp) apply(rule conjI) apply(case_tac n) apply(rule disjI1) apply(clarsimp) apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def) apply(rule disjI2) apply(clarsimp) apply(subgoal_tac "X" for X) prefer 2 apply(rule_tac n="nat" and m = "Suc nat" in epdaH.step_detail_before_some_position) apply(rule epdaH.derivation_initial_is_derivation) apply(force) apply(force) apply(force) apply(clarsimp) apply(rule_tac x="e2" in bexI) apply(simp add: epdaH_step_relation_def) apply(simp add: epdaH_step_relation_def) apply(simp add: epdaH_required_edges_def) apply(rule_tac x="d" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(rule_tac x="Suc nat" in exI) apply(clarsimp) apply(simp add: epdaH_marking_configurations_def epdaH_configurations_def) apply(force) done lemma epda_sub__equal_unmarked_language__Nonblockingness_branching_and_preservation_of_initial_marking_derivation: " valid_epda G1 \<Longrightarrow> valid_epda G2 \<Longrightarrow> epda_sub G1 G2 \<Longrightarrow> epdaH_initial_marking_derivations_at_end G2 \<subseteq> epdaH_initial_marking_derivations_at_end G1 \<Longrightarrow> epdaH.Nonblockingness_branching G2 \<Longrightarrow> epdaH.unmarked_language G2 \<subseteq> epdaH.unmarked_language G1" apply(simp add: epdaH.unmarked_language_def epdaH.Nonblockingness_branching_def) apply(clarsimp) apply(simp add: epdaH_unmarked_effect_def) apply(clarsimp) apply(erule_tac x="derivation_take d i" in allE) apply(erule impE) apply(rule epdaH.derivation_take_preserves_derivation_initial) apply(force) apply(erule_tac x="i" in allE) apply(erule impE) apply(simp add: maximum_of_domain_def derivation_take_def) apply(clarsimp) apply(simp add: epdaH_marking_condition_def) apply(clarsimp) apply(rule_tac x="derivation_take (derivation_append (derivation_take d i) dc i) ia " in exI) apply(rule context_conjI) apply(subgoal_tac "(derivation_take (derivation_append (derivation_take d i) dc i) ia) \<in> epdaH_initial_marking_derivations_at_end G1") apply(simp add: epdaH_initial_marking_derivations_at_end_def) apply(subgoal_tac "(derivation_take (derivation_append (derivation_take d i) dc i) ia) \<in> epdaH_initial_marking_derivations_at_end G2") apply(force) apply(thin_tac "epdaH_initial_marking_derivations_at_end G2 \<subseteq> epdaH_initial_marking_derivations_at_end G1") apply(simp add: epdaH_initial_marking_derivations_at_end_def) apply(rule conjI) apply(rule epdaH.derivation_take_preserves_derivation_initial) apply(rule epdaH.derivation_append_preserves_derivation_initial) apply(force) apply(rule epdaH.derivation_take_preserves_derivation_initial) apply(force) apply(rule epdaH.derivation_append_preserves_derivation) apply(rule epdaH.derivation_take_preserves_derivation) apply(force) apply(force) apply(simp add: derivation_take_def derivation_append_fit_def) apply(case_tac "dc 0") apply(clarsimp) apply(clarsimp) apply(case_tac a) apply(clarsimp) apply(case_tac x1) apply(clarsimp) apply(clarsimp) apply(rule_tac x="ia" in exI) apply(rule conjI) apply(simp add: derivation_take_def maximum_of_domain_def) apply(simp add: derivation_take_def) apply(rule conjI) prefer 2 apply(simp add: epdaH.derivation_initial_def) apply(case_tac "i\<le>ia") apply(rule_tac x="i" in exI) apply(simp add: derivation_take_def derivation_append_def) apply(case_tac "ia<i") prefer 2 apply(clarsimp) apply(clarsimp) apply(erule_tac x="i" in allE) apply(clarsimp) apply(rule_tac x="ia" in exI) apply(simp add: derivation_take_def epdaH_string_state_def derivation_append_def) done lemma F_ALT_EPDA_RE__preserves__unmarked_language_if_Nonblockingness_branching__epdaS_required_edges: " valid_epda G \<Longrightarrow> E = epdaS_required_edges G \<Longrightarrow> valid_epda (F_ALT_EPDA_RE G (epdaS_required_edges G)) \<Longrightarrow> ATS_Language0.Nonblockingness_branching epdaH_configurations epdaH_initial_configurations epda_step_labels epdaH_step_relation epdaH_marking_condition G \<Longrightarrow> ATS_Language0.unmarked_language epdaH_initial_configurations epdaH_step_relation epdaH_unmarked_effect G \<subseteq> ATS_Language0.unmarked_language epdaH_initial_configurations epdaH_step_relation epdaH_unmarked_effect (F_ALT_EPDA_RE G (epdaS_required_edges G))" apply(rule epda_sub__equal_unmarked_language__Nonblockingness_branching_and_preservation_of_initial_marking_derivation) apply(force) apply(force) apply(simp add: epda_sub_def F_ALT_EPDA_RE_def Let_def valid_epda_def) apply(force) apply(subgoal_tac "X" for X) prefer 2 apply(rule F_ALT_EPDA_RE_preserves_epdaH_initial_marking_derivations_at_end) apply(force) apply (metis epdaS_required_edges__vs__epdaH_required_edges) apply(force) done lemma F_ALT_EPDA_RE__SOUND2: " F_EPDA_RE__SpecInput2 (G, E) \<Longrightarrow> F_EPDA_RE__SpecOutput2 (G, E) (F_ALT_EPDA_RE G E)" apply(simp add: F_EPDA_RE__SpecInput2_def F_EPDA_RE__SpecOutput2_def) apply(rule context_conjI) apply(rule F_ALT_EPDA_RE_preserves_DPDA) apply(force) apply(simp add: epdaS_required_edges_def) apply(force) apply(rule context_conjI) apply(rule F_ALT_EPDA_RE_establishes_coblockbreeness__epdaS_required_edges) apply(force) apply(force) apply(rule context_conjI) apply(rule F_ALT_EPDA_RE_preserves_lang__epdaS_required_edges) apply(simp add: valid_dpda_def) apply(force) apply(rule context_conjI) apply(subgoal_tac "X" for X) prefer 2 apply(rule F_ALT_EPDA_RE_preserves_unmarked_lang2__epdaS_required_edges) apply(simp add: valid_dpda_def valid_pda_def) apply(force) apply(force) apply (metis PDA_to_epda epdaS_to_epdaH_unmarked_language valid_dpda_to_valid_pda) apply(rule impI) apply(rule context_conjI) apply(subgoal_tac "epdaH.unmarked_language G \<subseteq> epdaH.unmarked_language (F_ALT_EPDA_RE G (epdaS_required_edges G))") apply (metis PDA_to_epda epdaS_to_epdaH_unmarked_language valid_dpda_to_valid_pda) apply(rule F_ALT_EPDA_RE__preserves__unmarked_language_if_Nonblockingness_branching__epdaS_required_edges) apply(simp add: valid_dpda_def valid_pda_def) apply(force) apply (metis PDA_to_epda valid_dpda_to_valid_pda) apply(force) apply (metis DPDA_to_epdaH_determinism PDA_to_epda antisym epdaH.AX_is_forward_edge_deterministic_correspond_DB_SB epdaH.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long epdaH_language_Nonblockingness_from_operational_Nonblockingness epdaH_operational_Nonblockingness_from_language_Nonblockingness epda_inter_semantics_language_relationship valid_dpda_to_valid_pda) done theorem F_EPDA_RE__SOUND2: " F_EPDA_RE__SpecInput2 (G, E) \<Longrightarrow> F_EPDA_RE__SpecOutput2 (G, E) (F_EPDA_RE G E)" apply(rule_tac t="F_EPDA_RE G E" and s="F_ALT_EPDA_RE G E" in ssubst) apply(rule F_EPDA_RE__vs_F_ALT_EPDA_RE) apply(simp add: F_EPDA_RE__SpecInput2_def F_EPDA_RE__SpecOutput2_def) apply(simp add: valid_dpda_def valid_pda_def) apply(rule F_ALT_EPDA_RE__SOUND2) apply(force) done hide_fact F_EPDA_R__vs_F_ALT_EPDA_RE F_EPDA_RE__vs_F_ALT_EPDA_RE F_ALT_EPDA_RE_preserves_PDA F_ALT_EPDA_REERev_preserves_edges epdaToSymbolE_preserves_valid_epda_step_label F_ALT_EPDA_RE_preserves_configuration F_ALT_EPDA_REC_preserves_configurations F_ALT_EPDA_REC_preserves_initial_configurations F_ALT_EPDA_REC_preserves_marking_configurations epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs F_ALT_EPDA_RE_C_preserves_configurations F_ALT_EPDA_RE_C_preserves_initial_configurations F_ALT_EPDA_RE_C_preserves_marking_configurations F_ALT_EPDA_RE_initial_simulation_preserves_derivation epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation F_ALT_EPDA_RE_preserves_step_relation F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation F_ALT_EPDA_RE_relation_step_simulation_maps_to_derivation_belongs epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_marking_condition epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_marking_condition epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_marked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_marked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_step_simulation_preserves_unmarked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_relation_initial_simulation_preserves_unmarked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms F_ALT_EPDA_RE_preserves_lang1 F_ALT_EPDA_RE_preserves_unmarked_language1 epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs F_ALT_EPDA_RE_C_rev_preserves_configurations F_ALT_EPDA_RE_C_rev_preserves_initial_configurations F_ALT_EPDA_REC_reverse F_ALT_EPDA_REC_reverse2 epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation F_ALT_EPDA_RERev_preserves_step_relation epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_step_relation_step_simulation epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms F_ALT_EPDA_RE_C_rev_preserves_marking_configurations epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_marking_condition epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_marking_condition epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_marked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_marked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_step_simulation_preserves_unmarked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimRL_inst_relation_initial_simulation_preserves_unmarked_effect epdaS_epdaS_F_ALT_EPDA_RE_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ANY_axioms F_ALT_EPDA_RE_preserves_lang2 F_ALT_EPDA_RE_preserves_unmarked_language2 F_ALT_EPDA_RE_preserves_derivation F_ALT_EPDA_RE__SOUND end