Datasets:
AI4M
/

text
stringlengths
0
3.34M
% Complete documentation on the extended LaTeX markup used for Python % documentation is available in ``Documenting Python'', which is part % of the standard documentation for Python. It may be found online % at: % % http://www.python.org/doc/current/doc/doc.html \documentclass{manual} \title{lib537} \author{Chad W. L. Whitacre} % Please at least include a long-lived email address; % the rest is at your discretion. \authoraddress{ Zeta Design \&\ Development \\ \url{http://www.zetadev.com/software/lib537/} \\ Email: \email{\ulink{[email protected]}{mailto:[email protected]}} } \date{~~DATE~~} % update before release! %\date\today % Use an explicit date so that reformatting % doesn't cause a new date to be used. Setting % the date to \today can be used during draft % stages to make it easier to handle versions. \release{~~VERSION~~} % release version; this is used to define the % \version macro \begin{document} \maketitle \begin{abstract} \noindent lib537 is a Python library. \end{abstract} \input{installation} \chapter{Library Reference Manual} \label{manual} \input{httpy} \input{mode} \input{restarter} \input{legal} \end{document}
The infimum distance from a point $x$ to a singleton set $\{y\}$ is the distance from $x$ to $y$.
(* infotheo (c) AIST. R. Affeldt, M. Hagiwara, J. Senizergues. GNU GPLv3. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime. From mathcomp Require Import binomial ssralg finset fingroup finalg matrix. Require Import Reals Fourier. Require Import ssrR Reals_ext Ranalysis_ext logb ln_facts Rbigop proba entropy. Require Import channel_code channel divergence conditional_divergence. Require Import variation_dist pinsker. Set Implicit Arguments. Unset Strict Implicit. Import Prenex Implicits. Local Open Scope divergence_scope. Local Open Scope proba_scope. Local Open Scope entropy_scope. Local Open Scope channel_scope. Local Open Scope reals_ext_scope. Section mutinfo_distance_bound. Variable A B : finType. Variables V W : `Ch_1(A, B). Variable P : dist A. Hypothesis V_dom_by_W : P|- V << W. Hypothesis cdiv_ub : D(V || W | P) <= (exp(-2)) ^ 2 * / 2. Let cdiv_bounds : 0 <= sqrt (2 * D(V || W | P)) <= exp (-2). Proof. split; first by apply sqrt_pos. apply pow2_Rle_inv; [ by apply sqrt_pos | exact/ltRW/exp_pos | ]. rewrite [in X in X <= _]/= mulR1 sqrt_sqrt; last first. apply mulR_ge0; by [fourier | apply leq0cdiv]. apply/leRP; rewrite -(leR_pmul2r' (/ 2)); last exact/ltRP/invR_gt0. rewrite -mulRA mulRCA mulRV ?mulR1; [exact/leRP | exact/eqP/gtR_eqF]. Qed. Local Open Scope variation_distance_scope. (** Distance from the output entropy of one channel to another: *) Lemma out_entropy_dist_ub : `| `H(P `o V) - `H(P `o W) | <= / ln 2 * INR #|B| * - xlnx (sqrt (2 * D(V || W | P))). Proof. rewrite 2!xlnx_entropy. rewrite /Rminus -mulRN -mulRDr normRM gtR0_norm; last exact/invR_gt0/ln2_gt0. rewrite -mulRA; apply leR_pmul2l; first exact/invR_gt0/ln2_gt0. rewrite oppRK (big_morph _ morph_Ropp oppR0) -big_split /=. apply: leR_trans; first exact: ler_rsum_Rabs. rewrite -iter_addR -big_const. apply ler_rsum => b _; rewrite addRC. apply Rabs_xlnx => //. - split; [exact/dist_ge0 | exact/dist_max]. - split; [exact/dist_ge0 | exact/dist_max]. - rewrite 2!OutDist.dE /Rminus (big_morph _ morph_Ropp oppR0) -big_split /=. apply: leR_trans; first exact: ler_rsum_Rabs. apply (@leR_trans (d(`J(P , V), `J(P , W)))). + rewrite /var_dist /=. apply (@leR_trans (\rsum_(a : A) \rsum_(b : B) `| (`J(P, V)) (a, b) - (`J(P, W)) (a, b) |)); last first. apply Req_le; rewrite pair_bigA /=; apply eq_bigr; by case. apply: ler_rsum => a _. rewrite (bigD1 b) //= distRC -[X in X <= _]addR0. rewrite 2!JointDist.dE /=; apply/leR_add2l/rsumr_ge0 => ? _; exact/normR_ge0. + rewrite cdiv_is_div_joint_dist => //. exact/Pinsker_inequality_weak/joint_dom. Qed. (** Distance from the joint entropy of one channel to another: *) Lemma joint_entropy_dist_ub : `| `H(P , V) - `H(P , W) | <= / ln 2 * INR #|A| * INR #|B| * - xlnx (sqrt (2 * D(V || W | P))). Proof. rewrite 2!xlnx_entropy. rewrite /Rminus -mulRN -mulRDr normRM gtR0_norm; last exact/invR_gt0/ln2_gt0. rewrite -2!mulRA; apply leR_pmul2l; first exact/invR_gt0/ln2_gt0. rewrite oppRK (big_morph _ morph_Ropp oppR0) -big_split /=. apply: leR_trans; first exact: ler_rsum_Rabs. rewrite -2!iter_addR -2!big_const pair_bigA /=. apply: ler_rsum; case => a b _; rewrite addRC /=. apply Rabs_xlnx => //. - split; [exact: dist_ge0 | exact: dist_max]. - split; [exact: dist_ge0 | exact: dist_max]. - apply (@leR_trans (d(`J(P , V) , `J(P , W)))). rewrite /var_dist /R_dist (bigD1 (a, b)) //= distRC. rewrite -[X in X <= _]addR0. apply/leR_add2l/rsumr_ge0 => ? _; exact/normR_ge0. rewrite cdiv_is_div_joint_dist => //. exact/Pinsker_inequality_weak/joint_dom. Qed. (** * Distance from the mutual information of one channel to another *) Lemma mut_info_dist_ub : `| `I(P ; V) - `I(P ; W) | <= / ln 2 * (INR #|B| + INR #|A| * INR #|B|) * - xlnx (sqrt (2 * D(V || W | P))). Proof. rewrite /mut_info. rewrite (_ : _ - _ = `H(P `o V) - `H(P `o W) + (`H(P , W) - `H(P , V))); last by field. apply: leR_trans; first exact: Rabs_triang. rewrite -mulRA mulRDl mulRDr. apply leR_add. - by rewrite mulRA; apply out_entropy_dist_ub. - by rewrite distRC 2!mulRA; apply joint_entropy_dist_ub. Qed. End mutinfo_distance_bound. Section error_exponent_lower_bound. Variables A B : finType. Hypothesis Bnot0 : (0 < #|B|)%nat. Variable W : `Ch_1(A, B). Variable cap : R. Hypothesis W_cap : capacity W cap. Variable minRate : R. Hypothesis minRate_cap : minRate > cap. (** * Error exponent bound *) Lemma error_exponent_bound : exists Delta, 0 < Delta /\ forall P : dist A, forall V : `Ch_1(A, B), P |- V << W -> Delta <= D(V || W | P) + +| minRate - `I(P ; V) |. Proof. set gamma := / (INR #|B| + INR #|A| * INR #|B|) * (ln 2 * ((minRate - cap) / 2)). move: (continue_xlnx 0). rewrite /continuity_pt /continue_in /limit1_in /limit_in. move=> /(_ (min(exp (-2), gamma))). have Htmp : min(exp (-2), gamma) > 0. apply Rmin_Rgt_r ; split ; apply Rlt_gt. - by apply exp_pos. - subst gamma ; apply mulR_gt0. apply/invR_gt0/addR_gt0wl. - exact/ltR0n. - apply mulR_ge0; exact/leR0n. apply mulR_gt0 => //; apply mulR_gt0; last exact: invR_gt0. by rewrite subR_gt0. move=> /(_ Htmp) {Htmp} [] /= mu [mu_pos mu_cond]. set x := min(mu / 2, exp (-2)). move: {mu_cond}(mu_cond x). have x_pos : 0 < x. subst x. apply Rmin_pos; last by apply exp_pos. apply mulR_gt0 => //; exact: invR_gt0. have Htmp : D_x no_cond 0 x /\ R_dist x 0 < mu. split. - split => //; exact/ltR_eqF. - rewrite /R_dist subR0 gtR0_norm //. subst x. apply (@leR_ltR_trans (mu * / 2)); first exact/geR_minl. apply/ltRP; rewrite ltR_pdivr_mulr //; apply/ltRP; fourier. move=> /(_ Htmp) {Htmp}. rewrite /R_dist {2}/xlnx ltRR' subR0 ltR0_norm; last first. apply xlnx_neg. split => //; subst x. exact: leR_ltR_trans (geR_minr _ _) ltRinve21. move=> Hx. set Delta := min((minRate - cap) / 2, x ^ 2 / 2). exists Delta; split. apply Rmin_case. apply mulR_gt0; [exact/subR_gt0 | exact/invR_gt0]. apply mulR_gt0; [exact: pow_gt0 | exact: invR_gt0]. move=> P V v_dom_by_w. case/boolP : (Delta <b= D(V || W | P)). move/leRP => Hcase. apply (@leR_trans (D(V || W | P))) => //. rewrite -{1}(addR0 (D(V || W | P))); exact/leR_add2l/leR_maxl. move/leRP/ltRNge => Hcase. suff Htmp : (minRate - cap) / 2 <= minRate - (`I(P; V)). clear -Hcase v_dom_by_w Htmp. apply (@leR_trans +| minRate - `I(P ; V) |); last first. rewrite -[X in X <= _]add0R. apply/leR_add2r/leq0cdiv => b Hb ? ?; exact: v_dom_by_w. apply: leR_trans; last exact: leR_maxr. apply: (leR_trans _ Htmp); exact: geR_minl. have Htmp : `I(P ; V) <= cap + / ln 2 * (INR #|B| + INR #|A| * INR #|B|) * (- xlnx (sqrt (2 * D(V || W | P)))). apply (@leR_trans (`I(P ; W) + / ln 2 * (INR #|B| + INR #|A| * INR #|B|) * - xlnx (sqrt (2 * D(V || W | P))))); last first. apply/leR_add2r. move: W_cap; rewrite /capacity /lub; case; by move/(_ P). rewrite addRC -leR_subl_addr. apply (@leR_trans `| `I(P ; V) + - `I(P ; W) |); first exact: Rle_abs. have Htmp : D(V || W | P) <= exp (-2) ^ 2 * / 2. clear -Hcase x_pos. apply/ltRW/(ltR_leR_trans Hcase). apply (@leR_trans (x ^ 2 * / 2)); first exact: geR_minr. apply leR_wpmul2r; first exact/ltRW/invR_gt0. apply pow_incr. split; [exact: ltRW | exact: geR_minr]. by apply mut_info_dist_ub. rewrite -[X in _ <= X]oppRK in Htmp. apply leR_oppr in Htmp. apply (@leR_add2l minRate) in Htmp. apply: (leR_trans _ Htmp) => {Htmp}. suff Htmp : - xlnx (sqrt (2 * (D(V || W | P)))) <= gamma. rewrite oppRD addRA addRC -leR_subl_addr. rewrite [X in X <= _](_ : _ = - ((minRate + - cap) / 2)); last by field. rewrite leR_oppr oppRK -mulRA mulRC. apply/leRP; rewrite leR_pdivr_mulr //. rewrite mulRC -leR_pdivl_mulr; last first. by apply/ltRP; rewrite -mult_INR -plus_INR plusE multE ltR0n' addn_gt0 Bnot0. apply/leRP; by rewrite [in X in _ <= X]mulRC /Rdiv (mulRC _ (/ (_ + _))). suff Htmp : xlnx x <= xlnx (sqrt (2 * (D(V || W | P)))). clear -Hx Htmp. rewrite leR_oppl. apply (@leR_trans (xlnx x)) => //. rewrite leR_oppl. apply/ltRW/(ltR_leR_trans Hx). subst gamma; exact: geR_minr. apply/ltRW/Rgt_lt. have Htmp : sqrt (2 * D(V || W | P)) < x. apply pow2_Rlt_inv; [exact: sqrt_pos | exact: ltRW | ]. rewrite [in X in X < _]/= mulR1 sqrt_sqrt; last first. apply mulR_ge0; first exact/ltRW. apply leq0cdiv=> a Ha ? ?; by apply v_dom_by_w. apply/ltRP; rewrite mulRC -ltR_pdivl_mulr //. exact/ltRP/(ltR_leR_trans Hcase)/geR_minr. apply xlnx_sdecreasing_0_Rinv_e => //. - split; first exact/sqrt_pos. apply: (@leR_trans x _ _ (ltRW _)) => //. subst x. apply (@leR_trans (exp (-2))); first exact: geR_minr. apply/ltRW/exp_increasing; fourier. - split; first exact: ltRW. apply (@leR_trans (exp (-2))); first exact: geR_minr. apply/ltRW/exp_increasing; fourier. Qed. End error_exponent_lower_bound.
# Necessary libraries: library(plyr) library(dplyr) library(tibble) library(tidyr) library(ggplot2) library(lme4) library(e1071) library(anytime) theme_set(theme_bw()) # This file contains several examples of typical statistical analysis functions, # can be used as a template for other R scripts. # # Assumes that the dataset contains the following: # # depvar => dependent variable (assume ratio scaled here) # bin-indvar => binary independent variable: categorial, bin-indvar-1 = True, bin-indvar-0 = False # cont-indvar-A => continuous independent variable A: ratio scale # cont-indvar-B => continuous independent variable B: ratio scale # # Also assume that there are zero values/NAs for the dependent variable setwd("") # Insert path to working directory d = read.csv(file="") # Insert csv filename for data summary(d) head(d) # Create dataframe with depvar NAs as zero d$depvar[is.na(d$depvar)] <- 0 # Return number of rows nrow(d) # Make table of all rows excluding zero depvar d_no_zero <- d %>% filter(depvar != 0) nrow(d_no_zero) # Make table of all rows only zero depvar d_only_zero <- d %>% filter(depvar == 0) nrow(d_only_zero) # Make table consisting only of bin-indvar-1 rows bin-indvar-1-table <- d %>% filter(bin-indvar-1 == 1) bin-indvar-1-table$depvar[is.na(bin-indvar-1-table$depvar)] <- 0 # Change NAs in depvar column to 0 nrow(bin-indvar-1-table) # Make table of bin-indvar-1 excluding zeros bin-indvar-1-no-zero <- bin-indvar-1-table %>% filter(depvar != 0) nrow(bin-indvar-1-no-zero) # Make table of bin-indvar-1 only zeros bin-indvar-1-only-zero <- bin-indvar-1-table %>% filter(depvar == 0) nrow(bin-indvar-1-only-zero) # Make table consisting only of bin-indvar-0 rows bin-indvar-0-table <- d %>% filter(bin-indvar-1 == 0) bin-indvar-0-table$depvar[is.na(bin-indvar-0-table$depvar)] <- 0 # Change NAs in depvar column to 0 nrow(bin-indvar-0-table) # Make table of bin-indvar-0 excluding zeros bin-indvar-0-no-zero <- bin-indvar-0-table %>% filter(depvar != 0) nrow(bin-indvar-0-no-zero) # Make table of bin-indvar-0 only zeros bin-indvar-0-only-zero <- bin-indvar-0-table %>% filter(depvar == 0) nrow(bin-indvar-0-only-zero) # Get max, min, mean and median depvar from each subset: summary(d_no_zero) summary(bin-indvar-1-no-zero) summary(bin-indvar-0-no-zero) # Get st. dev. and IQR for depvar of each subset: sd(d_no_zero$depvar) sd(bin-indvar-1-no-zero$depvar) sd(bin-indvar-0-no-zero$depvar) IQR(d_no_zero$depvar) IQR(bin-indvar-1-no-zero$depvar) IQR(bin-indvar-0-no-zero$depvar) # Make density plot of depvar for each subset: limit <- 1 # change this for data d_depvar_dens_plot <- ggplot(d_no_zero, aes(x=depvar)) + geom_density() + scale_x_continuous(limits = c(0, limit)) + geom_vline(aes(xintercept=mean(depvar)), color="red", linetype="dashed", size=1) + geom_vline(aes(xintercept=median(depvar)), color="blue", linetype="dashed", size=1) + labs(x="depvar", y = "Density") + theme(plot.title = element_text(hjust = 0.5, size=24), axis.text=element_text(size=22), axis.title=element_text(size=22,face="bold")) d_depvar_dens_plot bin-indvar-1-depvar-dens-plot <- ggplot(bin-indvar-1-no-zero, aes(x=depvar)) + geom_density() + scale_x_continuous(limits = c(0, limit)) + geom_vline(aes(xintercept=mean(depvar)), color="red", linetype="dashed", size=1) + geom_vline(aes(xintercept=median(depvar)), color="blue", linetype="dashed", size=1) + labs(x="depvar", y = "Density") + theme(plot.title = element_text(hjust = 0.5, size=24), axis.text=element_text(size=22), axis.title=element_text(size=22,face="bold")) bin-indvar-1-depvar-dens-plot bin-indvar-0-depvar-dens-plot <- ggplot(bin-indvar-0-no-zero, aes(x=depvar)) + geom_density() + scale_x_continuous(limits = c(0, limit)) + geom_vline(aes(xintercept=mean(depvar)), color="red", linetype="dashed", size=1) + geom_vline(aes(xintercept=median(depvar)), color="blue", linetype="dashed", size=1) + labs(x="depvar", y = "Density") + theme(plot.title = element_text(hjust = 0.5, size=24), axis.text=element_text(size=22), axis.title=element_text(size=22,face="bold")) bin-indvar-0-depvar-dens-plot # Compute skewness of each subset skewness(d_no_zero$depvar) skewness(bin-indvar-1-no-zero$depvar) skewness(bin-indvar-0-no-zero$depvar) # t-test for difference in depvar between bin-indvar-1 and bin-indvar-0 d_no_zero$log_depvar <- log(d_no_zero$depvar) # create log transform column of depvar bin-indvar-1-no-zero$log_depvar <- log(bin-indvar-1-no-zero$depvar) bin-indvar-0-no-zero$log_depvar <- log(bin-indvar-0-no-zero$depvar) t.test(bin-indvar-1-no-zero$log_depvar, bin-indvar-0-no-zero$log_depvar, alternative = "greater") # Create scatterplots of cont-indvar-A vs. log_depvar cont-indvar-A_scatter_bin-indvar-1 <- ggplot(bin-indvar-1-no-zero, aes(x=cont-indvar-A, y=log_depvar)) + geom_point(shape = 20, size = 1) + stat_smooth(method = lm) + labs(x="cont-indvar-A", y = "Log of depvar") + theme(axis.text=element_text(size=22), axis.title=element_text(size=22,face="bold")) cont-indvar-A_scatter_bin-indvar-1 cont-indvar-A_scatter_bin-indvar-0 <- ggplot(bin-indvar-0-no-zero, aes(x=cont-indvar-A, y=log_depvar)) + geom_point(shape = 20, size = 1) + stat_smooth(method = lm) + labs(x="cont-indvar-A", y = "Log of depvar") + theme(axis.text=element_text(size=22), axis.title=element_text(size=22,face="bold")) cont-indvar-A_scatter_bin-indvar-0 # If distribution is long-tailed and there are several outliers: # Create bin-indvar-1 set excluding outliers outlier_threshold_upper <- 20 # change according to data outlier_threshold_lower <- 12 # change according to data bin-indvar-1-exclude-outliers <- bin-indvar-1-no-zero[bin-indvar-1-no-zero$log_depvar<outlier_threshold_upper & bin-indvar-1-no-zero$log_depvar>outlier_threshold_lower,] # Test correlation of cont-indvar-A and depvar in bin-indvar-1 set cor(bin-indvar-1-no-zero$cont-indvar-A, bin-indvar-1-no-zero$log_depvar) cor(bin-indvar-1-exclude-outliers$cont-indvar-A, bin-indvar-1-exclude-outliers$log_depvar) # Simple density plots for cont-indvar-B variable in each subset: plot(density(d_no_zero$cont-indvar-B), main=NA, xlab="cont-indvar-B", cex.lab=2, cex.axis=2) plot(density(bin-indvar-1-no-zero$cont-indvar-B), main=NA, xlab="cont-indvar-B", cex.lab=2, cex.axis=2) plot(density(bin-indvar-0-no-zero$cont-indvar-B), main=NA, xlab="cont-indvar-B", cex.lab=2, cex.axis=2) # Get modes for cont-indvar-B and depvar in split of bin-indvar-0 set: cont-indvar-B_threshold <- 75 # change according to data bin-indvar-0-longer <- bin-indvar-0-no-zero[bin-indvar-0-no-zero$cont-indvar-B>=cont-indvar-B_threshold,] get.mode(bin-indvar-0-longer$cont-indvar-B) get.mode(bin-indvar-0-longer$depvar) # Get modes for cont-indvar-B and depvar, longer-time bin-indvar-1 set: bin-indvar-1-longer <- bin-indvar-1-no-zero[bin-indvar-1-no-zero$cont-indvar-B>=cont-indvar-B_threshold,] get.mode(bin-indvar-1-longer$cont-indvar-B) get.mode(bin-indvar-1-longer$depvar) # Get modal depvar increase: modal_increase <- (get.mode(bin-indvar-1-longer$depvar) / get.mode(bin-indvar-1-longer$cont-indvar-B)) - (get.mode(bin-indvar-0-longer$depvar) / get.mode(bin-indvar-0-longer$cont-indvar-B)) modal_increase # Get medians: median(bin-indvar-0-longer$cont-indvar-B) median(bin-indvar-0-longer$depvar) median(bin-indvar-1-longer$cont-indvar-B) median(bin-indvar-1-longer$depvar) # Get median depvar increase: median_increase <- (median(bin-indvar-1-longer$depvar) / median(bin-indvar-1-longer$cont-indvar-B)) - (median(bin-indvar-0-longer$depvar) / median(bin-indvar-0-longer$cont-indvar-B)) median_increase # If a linear regression is appropriate: # Build linear regression model: depvar as a function of fixed effects model <- lm(log_depvar ~ cont-indvar-A * bin-indvar-1 * cont-indvar-B, data=d_no_zero) summary(model) # Q-Q plot of residuals: plot(model,which=2,cex.lab=2, cex.axis=2) # If residuals are not normally distributed, and polynomial model is appropriate: # Polynomial model: poly_model <- lm(log_depvar ~ bin-indvar-1 + polym(cont-indvar-A, degree=3) + polym(cont-indvar-B, degree=3), data = d_no_zero) summary(poly_model) plot(poly_model,which=2,cex.lab=2, cex.axis=2) # Histogram of log of depvar hist(log(d_no_zero$depvar), main=NA, xlab="Log of depvar", freq=F,cex.lab=2, cex.axis=2) legend("topright", c("Normal curve", "Empirical curve"), col=c("black", "red"), lwd=1) lines(seq(10, 40, by=.5), dnorm(seq(10, 40, by=.5), mean(log(d_no_zero$depvar)), sd(log(d_no_zero$depvar)))) lines(density(log(d_no_zero$depvar)),col="red") # If histogram of log of depvar itself is still not normally distributed with heavy tails: # Histogram excluding tails: log_depvar_threshold_upper <- 19 # change according to data log_depvar_threshold_lower <- 14 # change according to data no_tails <- d_no_zero[d_no_zero$log_depvar >= log_depvar_threshold_lower & d_no_zero$log_depvar <= log_depvar_threshold_upper,] hist(log(no_tails$depvar), main=NA, xlab="Log of depvar", freq=F,cex.lab=2, cex.axis=2) lines(seq(10, 40, by=.5), dnorm(seq(10, 40, by=.5), mean(log(no_tails$depvar)), sd(log(no_tails$depvar)))) legend("topright", c("Normal curve", "Empirical curve"), col=c("black", "red"), lwd=1) lines(density(log(no_tails$depvar)),col="red") # Linear model excluding tails: no_tails_model <- lm(log_depvar ~ cont-indvar-A * bin-indvar-1 * cont-indvar-B, data=no_tails) summary(no_tails_model) no_tails_model_raw <- lm(depvar ~ cont-indvar-A * bin-indvar-1 * cont-indvar-B, data=no_tails) summary(no_tails_model_raw) plot(no_tails_model,which=2,cex.lab=2, cex.axis=2) # Generate correlation matrices: cor(bin-indvar-1-no-zero$cont-indvar-A, bin-indvar-1-no-zero$cont-indvar-B) plot(bin-indvar-1-no-zero$cont-indvar-A, bin-indvar-1-no-zero$cont-indvar-B) # Investigating subset of data with only NAs for depvar: # Histogram for only zeros hist(bin-indvar-1-only-zero$cont-indvar-A, freq=F, main=NA, xlab="cont-indvar-A", cex.lab=2, cex.axis=2, xlim=c(-1.5,20), ylim=c(0,15)) # change lims according to data lines(density(bin-indvar-1-only-zero$cont-indvar-A), col="red") hist(bin-indvar-1-no-zero$cont-indvar-A, freq=F, main=NA, xlab="cont-indvar-A", cex.lab=2, cex.axis=2, xlim=c(-1.5,20), ylim=c(0,15)) # change lims according to data lines(density(bin-indvar-1-no-zero$cont-indvar-A), col="red") # Polynomial regression incl zeros model_incl_zeros <-lm(depvar ~ bin-indvar-1 + polym(cont-indvar-A, degree=3) + polym(cont-indvar-B, degree=3), data = d) summary(model_incl_zeros)
[STATEMENT] lemma set_insort_insert: "set (insort_insert x xs) = insert x (set xs)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. set (insort_insert x xs) = insert x (set xs) [PROOF STEP] by (auto simp add: insort_insert_key_def set_insort_key)
If $s$ is a compact set and $c$ is a component of $s$, then $c$ is compact.
### Initialization #### Notebook stuff ```python from IPython.display import display, Latex, HTML display(HTML(open('01.css').read())) ``` #### Numpy and Scipy ```python import numpy as np from numpy import array, cos, diag, eye, linspace, pi from numpy import poly1d, sign, sin, sqrt, where, zeros from scipy.linalg import eigh, inv, det ``` #### Matplotlib ```python %matplotlib inline import matplotlib.pyplot as plt plt.style.use('seaborn-paper') plt.rcParams['figure.dpi'] = 115 plt.rcParams['figure.figsize'] = (7.5, 2.5) plt.rcParams['axes.grid'] = True ``` #### Miscellaneous definitions In the following `ld` and `pmat` are used to display mathematical formulas generated by the program, `rounder` ensures that a floating point number _close_ to an integer will be rounded correctly when formatted as an integer, `p` is a shorthand to calling `poly1d` that is long and requires a single argument, `vw` computes the virtual work done by moments `m` for the curvatures `c`, when the lengths of the beams are `l` and eventually `p0_p1` given an array of values `p` returns first `p[0], p[1]` then `p[1], p[2]` then... ```python def ld(*items): display(Latex('$$' + ' '.join(items) + '$$')) def pmat(mat, env='bmatrix', fmt='%+f'): opener = '\\begin{'+env+'}\n ' closer = '\n\\end{'+env+'}' formatted = '\\\\\n '.join('&'.join(fmt%elt for elt in row) for row in mat) return opener+formatted+closer def rounder(mat): return mat+0.01*sign(mat) def p(*l): return poly1d(l) def vw(emme, chi, L): return sum(((m*c).integ()(l)-(m*c).integ()(0)) for (m, c, l) in zip(emme, chi, L)) def p0_p1(p): from itertools import tee a, b = tee(p) next(b, None) return zip(a, b) ``` # 3 DOF System ## Input motion We need the imposed displacement, the imposed velocity (an intermediate result) and the imposed acceleration. It is convenient to express these quantities in terms of an adimensional time coordinate $a = \omega_0 t$, \begin{align} u &= \frac{4/3\omega_0 t - \sin(4/3\omega_0 t)}{2\pi} = \frac{\lambda_0 a- \sin(\lambda_0 a)}{2\pi},\\ \dot{u} &= \frac{4}{3}\omega_0 \frac{1-\cos(4/3\omega_0t)}{2\pi} = \lambda_0 \omega_0 \frac{1-\cos(\lambda_0 a)}{2\pi},\\ \ddot{u} &= \frac{16}{9}\omega_0^2 \frac{\sin(4/3\omega_0t)}{2\pi} = \lambda_0^2\omega_0^2 \frac{\sin(\lambda_0 a)}{2\pi}, \end{align} with $\lambda_0=4/3$. The equations above are valid in the interval $$ 0 \le t \le \frac{2\pi}{4/3 \omega_0} \rightarrow 0 \le a \le \frac{3\pi}2 $$ (we have multiplied all terms by $\omega_0$ and simplified the last term). Following a similar reasoning, the plotting interval is equal to $0\le a\le2\pi$. ```python l0 = 4/3 # define a function to get back the time array and the 3 dependent vars def a_uA_vA_aA(t0, t1, npoints): a = linspace(t0, t1, npoints) uA = where(a<3*pi/2, (l0*a-sin(l0*a))/2/pi, 1) vA = where(a<3*pi/2, (1-cos(l0*a))/2/pi, 0) aA = where(a<3*pi/2, 16*sin(l0*a)/18/pi, 0) return a, uA, vA, aA # and use it a, uA, vA, aA = a_uA_vA_aA(0, 2*pi, 501) ``` #### The plots ```python plt.plot(a/pi, uA) plt.xlabel(r'$\omega_0 t/\pi$') plt.ylabel(r'$u_A/\delta$') plt.title('Imposed support motion'); ``` ```python plt.plot(a/pi, vA) plt.xlabel(r'$\omega_0 t/\pi$') plt.ylabel(r'$\dot u_A/\delta\omega_0$') plt.title('Imposed support velocity'); ``` ```python plt.plot(a/pi, aA) plt.xlabel(r'$\omega_0 t/\pi$') plt.ylabel(r'$\ddot u_A/\delta\omega_0^2$') plt.title('Imposed support acceleration'); ``` ## Equation of Motion The EoM expressed in adimensional coordinates and using adimensional structural matrices is $$ m\omega_0^2\hat{\boldsymbol M} \frac{\partial^2\boldsymbol x}{\partial a^2} + \frac{EJ}{L^3}\hat{\boldsymbol K}\boldsymbol x = m \hat{\boldsymbol M} \boldsymbol e \omega_0^2 \frac{\partial^2 u_A}{\partial a^2} $$ using the dot notation to denote derivatives with respect to $a$, if we divide both members by $m\omega_0^2$ we have $$ \hat{\boldsymbol M} \ddot{\boldsymbol x} + \hat{\boldsymbol K}\boldsymbol x = \hat{\boldsymbol M} \boldsymbol e \ddot{u}_A. $$ We must determine the influence vector $\boldsymbol e$ and the adimensional structural matrices ### Influence vector To impose a horizontal displacement in $A$ we must remove one constraint, so that the structure has 1 DOF as a rigid system and the influence vector must be determined by a kinematic analysis. ```python display(HTML(open('figures/trab1kin_conv.svg').read())) ``` <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="757.158pt" height="381.639pt" viewBox="0 0 757.158 381.639" version="1.1"> <defs> <g> <symbol overflow="visible" id="glyph0-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph0-1"> <path style="stroke:none;" d="M 9.796875 -8.421875 C 9.125 -8.296875 8.875 -7.8125 8.875 -7.421875 C 8.875 -6.921875 9.28125 -6.75 9.5625 -6.75 C 10.1875 -6.75 10.625 -7.296875 10.625 -7.84375 C 10.625 -8.71875 9.625 -9.109375 8.765625 -9.109375 C 7.5 -9.109375 6.796875 -7.875 6.609375 -7.484375 C 6.140625 -9.03125 4.859375 -9.109375 4.484375 -9.109375 C 2.375 -9.109375 1.265625 -6.40625 1.265625 -5.953125 C 1.265625 -5.859375 1.34375 -5.765625 1.484375 -5.765625 C 1.65625 -5.765625 1.6875 -5.890625 1.734375 -5.96875 C 2.4375 -8.265625 3.828125 -8.703125 4.421875 -8.703125 C 5.34375 -8.703125 5.53125 -7.828125 5.53125 -7.328125 C 5.53125 -6.875 5.40625 -6.40625 5.171875 -5.40625 L 4.46875 -2.578125 C 4.15625 -1.34375 3.546875 -0.203125 2.453125 -0.203125 C 2.359375 -0.203125 1.84375 -0.203125 1.40625 -0.46875 C 2.140625 -0.625 2.3125 -1.234375 2.3125 -1.484375 C 2.3125 -1.90625 2 -2.140625 1.609375 -2.140625 C 1.109375 -2.140625 0.578125 -1.71875 0.578125 -1.046875 C 0.578125 -0.1875 1.546875 0.203125 2.4375 0.203125 C 3.421875 0.203125 4.125 -0.578125 4.5625 -1.421875 C 4.890625 -0.203125 5.921875 0.203125 6.6875 0.203125 C 8.796875 0.203125 9.921875 -2.5 9.921875 -2.953125 C 9.921875 -3.0625 9.828125 -3.140625 9.703125 -3.140625 C 9.515625 -3.140625 9.5 -3.03125 9.4375 -2.875 C 8.875 -1.046875 7.6875 -0.203125 6.75 -0.203125 C 6.03125 -0.203125 5.640625 -0.75 5.640625 -1.59375 C 5.640625 -2.046875 5.71875 -2.375 6.046875 -3.734375 L 6.78125 -6.546875 C 7.078125 -7.78125 7.78125 -8.703125 8.734375 -8.703125 C 8.78125 -8.703125 9.359375 -8.703125 9.796875 -8.421875 Z M 9.796875 -8.421875 "/> </symbol> <symbol overflow="visible" id="glyph1-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph1-1"> <path style="stroke:none;" d="M 2.640625 -5.15625 C 2.390625 -5.140625 2.34375 -5.125 2.34375 -4.984375 C 2.34375 -4.84375 2.40625 -4.84375 2.671875 -4.84375 L 3.328125 -4.84375 C 4.546875 -4.84375 5.09375 -3.84375 5.09375 -2.46875 C 5.09375 -0.59375 4.109375 -0.09375 3.40625 -0.09375 C 2.71875 -0.09375 1.546875 -0.421875 1.140625 -1.359375 C 1.59375 -1.296875 2.015625 -1.546875 2.015625 -2.0625 C 2.015625 -2.484375 1.703125 -2.765625 1.3125 -2.765625 C 0.96875 -2.765625 0.59375 -2.5625 0.59375 -2.015625 C 0.59375 -0.75 1.859375 0.296875 3.453125 0.296875 C 5.15625 0.296875 6.421875 -1 6.421875 -2.453125 C 6.421875 -3.765625 5.359375 -4.8125 3.984375 -5.046875 C 5.234375 -5.40625 6.03125 -6.453125 6.03125 -7.578125 C 6.03125 -8.703125 4.859375 -9.53125 3.46875 -9.53125 C 2.03125 -9.53125 0.96875 -8.65625 0.96875 -7.609375 C 0.96875 -7.046875 1.421875 -6.921875 1.640625 -6.921875 C 1.9375 -6.921875 2.28125 -7.140625 2.28125 -7.578125 C 2.28125 -8.03125 1.9375 -8.234375 1.625 -8.234375 C 1.53125 -8.234375 1.5 -8.234375 1.46875 -8.21875 C 2.015625 -9.1875 3.359375 -9.1875 3.421875 -9.1875 C 3.90625 -9.1875 4.828125 -8.984375 4.828125 -7.578125 C 4.828125 -7.296875 4.796875 -6.5 4.375 -5.875 C 3.9375 -5.25 3.453125 -5.203125 3.0625 -5.1875 Z M 2.640625 -5.15625 "/> </symbol> <symbol overflow="visible" id="glyph1-2"> <path style="stroke:none;" d="M 6.3125 -2.40625 L 6 -2.40625 C 5.953125 -2.171875 5.84375 -1.375 5.6875 -1.140625 C 5.59375 -1.015625 4.78125 -1.015625 4.34375 -1.015625 L 1.6875 -1.015625 C 2.078125 -1.34375 2.953125 -2.265625 3.328125 -2.609375 C 5.515625 -4.625 6.3125 -5.359375 6.3125 -6.78125 C 6.3125 -8.4375 5 -9.53125 3.34375 -9.53125 C 1.671875 -9.53125 0.703125 -8.125 0.703125 -6.890625 C 0.703125 -6.15625 1.328125 -6.15625 1.375 -6.15625 C 1.671875 -6.15625 2.046875 -6.375 2.046875 -6.828125 C 2.046875 -7.234375 1.78125 -7.5 1.375 -7.5 C 1.25 -7.5 1.21875 -7.5 1.171875 -7.484375 C 1.453125 -8.46875 2.21875 -9.125 3.15625 -9.125 C 4.375 -9.125 5.125 -8.109375 5.125 -6.78125 C 5.125 -5.5625 4.421875 -4.5 3.59375 -3.578125 L 0.703125 -0.34375 L 0.703125 0 L 5.9375 0 Z M 6.3125 -2.40625 "/> </symbol> <symbol overflow="visible" id="glyph1-3"> <path style="stroke:none;" d="M 4.125 -9.1875 C 4.125 -9.53125 4.125 -9.53125 3.84375 -9.53125 C 3.5 -9.15625 2.78125 -8.625 1.3125 -8.625 L 1.3125 -8.203125 C 1.640625 -8.203125 2.359375 -8.203125 3.140625 -8.578125 L 3.140625 -1.109375 C 3.140625 -0.59375 3.09375 -0.421875 1.84375 -0.421875 L 1.390625 -0.421875 L 1.390625 0 C 1.78125 -0.03125 3.171875 -0.03125 3.640625 -0.03125 C 4.109375 -0.03125 5.5 -0.03125 5.875 0 L 5.875 -0.421875 L 5.4375 -0.421875 C 4.171875 -0.421875 4.125 -0.59375 4.125 -1.109375 Z M 4.125 -9.1875 "/> </symbol> <symbol overflow="visible" id="glyph2-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph2-1"> <path style="stroke:none;" d="M 7.1875 -2.671875 L 6.875 -2.671875 C 6.703125 -1.453125 6.5625 -1.234375 6.484375 -1.140625 C 6.40625 -1 5.171875 -1 4.921875 -1 L 1.625 -1 C 2.234375 -1.671875 3.4375 -2.890625 4.90625 -4.3125 C 5.953125 -5.296875 7.1875 -6.46875 7.1875 -8.171875 C 7.1875 -10.203125 5.5625 -11.375 3.75 -11.375 C 1.859375 -11.375 0.703125 -9.71875 0.703125 -8.15625 C 0.703125 -7.484375 1.203125 -7.40625 1.40625 -7.40625 C 1.578125 -7.40625 2.09375 -7.5 2.09375 -8.109375 C 2.09375 -8.640625 1.65625 -8.796875 1.40625 -8.796875 C 1.3125 -8.796875 1.203125 -8.78125 1.140625 -8.75 C 1.46875 -10.203125 2.46875 -10.9375 3.515625 -10.9375 C 5.015625 -10.9375 5.984375 -9.75 5.984375 -8.171875 C 5.984375 -6.6875 5.109375 -5.390625 4.125 -4.265625 L 0.703125 -0.390625 L 0.703125 0 L 6.765625 0 Z M 7.1875 -2.671875 "/> </symbol> <symbol overflow="visible" id="glyph3-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph3-1"> <path style="stroke:none;" d="M 5.875 -1 C 6.09375 -0.03125 6.921875 0.171875 7.328125 0.171875 C 7.890625 0.171875 8.296875 -0.1875 8.578125 -0.78125 C 8.875 -1.390625 9.09375 -2.40625 9.09375 -2.46875 C 9.09375 -2.546875 9.015625 -2.625 8.921875 -2.625 C 8.765625 -2.625 8.75 -2.53125 8.671875 -2.265625 C 8.375 -1.078125 8.0625 -0.171875 7.375 -0.171875 C 6.859375 -0.171875 6.859375 -0.734375 6.859375 -0.96875 C 6.859375 -1.359375 6.90625 -1.53125 7.078125 -2.25 C 7.203125 -2.71875 7.3125 -3.1875 7.421875 -3.671875 L 8.125 -6.46875 C 8.25 -6.90625 8.25 -6.9375 8.25 -6.984375 C 8.25 -7.25 8.046875 -7.421875 7.78125 -7.421875 C 7.28125 -7.421875 7.15625 -6.984375 7.0625 -6.5625 C 6.890625 -5.890625 5.953125 -2.1875 5.84375 -1.578125 C 5.8125 -1.578125 5.140625 -0.171875 3.890625 -0.171875 C 3 -0.171875 2.828125 -0.953125 2.828125 -1.578125 C 2.828125 -2.5625 3.3125 -3.9375 3.75 -5.09375 C 3.953125 -5.640625 4.046875 -5.875 4.046875 -6.21875 C 4.046875 -6.953125 3.515625 -7.59375 2.6875 -7.59375 C 1.109375 -7.59375 0.46875 -5.09375 0.46875 -4.953125 C 0.46875 -4.890625 0.53125 -4.796875 0.65625 -4.796875 C 0.8125 -4.796875 0.828125 -4.875 0.890625 -5.109375 C 1.3125 -6.59375 1.984375 -7.25 2.640625 -7.25 C 2.8125 -7.25 3.078125 -7.234375 3.078125 -6.6875 C 3.078125 -6.234375 2.890625 -5.734375 2.640625 -5.078125 C 1.875 -3.03125 1.796875 -2.375 1.796875 -1.859375 C 1.796875 -0.109375 3.109375 0.171875 3.828125 0.171875 C 4.921875 0.171875 5.53125 -0.578125 5.875 -1 Z M 5.875 -1 "/> </symbol> <symbol overflow="visible" id="glyph4-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph4-1"> <path style="stroke:none;" d="M 2.03125 -1.328125 C 1.609375 -0.625 1.203125 -0.375 0.640625 -0.34375 C 0.5 -0.328125 0.40625 -0.328125 0.40625 -0.125 C 0.40625 -0.046875 0.46875 0 0.546875 0 C 0.765625 0 1.296875 -0.03125 1.515625 -0.03125 C 1.859375 -0.03125 2.25 0 2.578125 0 C 2.65625 0 2.796875 0 2.796875 -0.234375 C 2.796875 -0.328125 2.703125 -0.34375 2.625 -0.34375 C 2.359375 -0.375 2.125 -0.46875 2.125 -0.75 C 2.125 -0.921875 2.203125 -1.046875 2.359375 -1.3125 L 3.265625 -2.828125 L 6.3125 -2.828125 C 6.328125 -2.71875 6.328125 -2.625 6.328125 -2.515625 C 6.375 -2.203125 6.515625 -0.953125 6.515625 -0.734375 C 6.515625 -0.375 5.90625 -0.34375 5.71875 -0.34375 C 5.578125 -0.34375 5.453125 -0.34375 5.453125 -0.125 C 5.453125 0 5.5625 0 5.625 0 C 5.828125 0 6.078125 -0.03125 6.28125 -0.03125 L 6.953125 -0.03125 C 7.6875 -0.03125 8.21875 0 8.21875 0 C 8.3125 0 8.4375 0 8.4375 -0.234375 C 8.4375 -0.34375 8.328125 -0.34375 8.15625 -0.34375 C 7.5 -0.34375 7.484375 -0.453125 7.453125 -0.8125 L 6.71875 -8.265625 C 6.6875 -8.515625 6.640625 -8.53125 6.515625 -8.53125 C 6.390625 -8.53125 6.328125 -8.515625 6.21875 -8.328125 Z M 3.46875 -3.171875 L 5.875 -7.1875 L 6.28125 -3.171875 Z M 3.46875 -3.171875 "/> </symbol> </g> <clipPath id="clip1"> <path d="M 4 4 L 753 4 L 753 381.640625 L 4 381.640625 Z M 4 4 "/> </clipPath> <clipPath id="clip2"> <path d="M 284 190 L 286 190 L 286 248 L 284 248 Z M 284 190 "/> </clipPath> <clipPath id="clip3"> <path d="M 0 381.640625 L 758 381.640625 L 758 -0.359375 L 0 -0.359375 Z M 283.785156 189.828125 L 285.730469 189.828125 L 288.929688 209.71875 L 280.585938 209.71875 Z M 283.785156 189.828125 "/> </clipPath> <clipPath id="clip4"> <path d="M 565 190 L 567 190 L 567 248 L 565 248 Z M 565 190 "/> </clipPath> <clipPath id="clip5"> <path d="M 0 381.640625 L 758 381.640625 L 758 -0.359375 L 0 -0.359375 Z M 565.441406 189.828125 L 567.386719 189.828125 L 570.585938 209.71875 L 562.242188 209.71875 Z M 565.441406 189.828125 "/> </clipPath> <clipPath id="clip6"> <path d="M 666 252 L 724 252 L 724 254 L 666 254 Z M 666 252 "/> </clipPath> <clipPath id="clip7"> <path d="M 0 381.640625 L 758 381.640625 L 758 -0.359375 L 0 -0.359375 Z M 723.863281 252.417969 L 723.863281 254.363281 L 703.976562 257.5625 L 703.976562 249.21875 Z M 723.863281 252.417969 "/> </clipPath> </defs> <g id="surface1"> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 3.101562 165.765625 L 754.1875 165.765625 L 754.1875 153.246094 L 3.101562 153.246094 Z M 3.101562 165.765625 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 3.101562 71.878906 L 754.1875 71.878906 L 754.1875 59.359375 L 3.101562 59.359375 Z M 3.101562 71.878906 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 3.101562 259.652344 L 754.1875 259.652344 L 754.1875 247.132812 L 3.101562 247.132812 Z M 3.101562 259.652344 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 3.101562 353.535156 L 754.1875 353.535156 L 754.1875 341.019531 L 3.101562 341.019531 Z M 3.101562 353.535156 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 90.726562 378.574219 L 103.246094 378.574219 L 103.246094 3.03125 L 90.726562 3.03125 Z M 90.726562 378.574219 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 184.613281 378.574219 L 197.132812 378.574219 L 197.132812 3.03125 L 184.613281 3.03125 Z M 184.613281 378.574219 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 278.496094 378.574219 L 291.015625 378.574219 L 291.015625 3.03125 L 278.496094 3.03125 Z M 278.496094 378.574219 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 372.382812 378.574219 L 384.902344 378.574219 L 384.902344 3.03125 L 372.382812 3.03125 Z M 372.382812 378.574219 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 466.269531 378.574219 L 478.789062 378.574219 L 478.789062 3.03125 L 466.269531 3.03125 Z M 466.269531 378.574219 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 560.15625 378.574219 L 572.671875 378.574219 L 572.671875 3.03125 L 560.15625 3.03125 Z M 560.15625 378.574219 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(90.039062%,90.039062%,90.039062%);fill-opacity:1;" d="M 654.039062 378.574219 L 666.558594 378.574219 L 666.558594 3.03125 L 654.039062 3.03125 Z M 654.039062 378.574219 "/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 31.015625 2221.311875 L 7541.875 2221.311875 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 31.015625 3160.179063 L 7541.875 3160.179063 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 31.015625 1282.48375 L 7541.875 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 31.015625 343.616563 L 7541.875 343.616563 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 3786.0775 L 969.84375 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1908.710938 3786.0775 L 1908.710938 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2847.578125 3786.0775 L 2847.578125 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3786.445312 3786.0775 L 3786.445312 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 4725.273438 3786.0775 L 4725.273438 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5664.140625 3786.0775 L 5664.140625 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(100%,100%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6603.007812 3786.0775 L 6603.007812 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <g clip-path="url(#clip1)" clip-rule="nonzero"> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.792419%,38.792419%,38.792419%);stroke-opacity:1;stroke-dasharray:125.181;stroke-miterlimit:10;" d="M 7228.90625 30.647813 L 343.945312 3473.147813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> </g> <path style="fill:none;stroke-width:20.8635;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(38.792419%,38.792419%,38.792419%);stroke-opacity:1;stroke-dasharray:125.181;stroke-miterlimit:10;" d="M 969.84375 3473.147813 L 969.84375 30.647813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 65.691406 153.246094 L 128.28125 153.246094 L 128.28125 121.953125 L 65.691406 121.953125 Z M 65.691406 153.246094 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 2221.311875 L 1078.359375 2409.124375 L 861.367188 2409.124375 Z M 969.84375 2221.311875 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 844.6875 2471.7025 L 1095.039062 2471.7025 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6603.007812 343.616563 L 6102.265625 343.616563 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6603.007812 343.616563 L 6477.8125 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6477.8125 343.616563 L 6352.65625 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6352.65625 343.616563 L 6227.460938 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6227.460938 343.616563 L 6102.265625 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 7103.710938 343.616563 L 6603.007812 343.616563 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 7103.710938 343.616563 L 6978.554688 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6978.554688 343.616563 L 6853.359375 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6853.359375 343.616563 L 6728.164062 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6728.164062 343.616563 L 6603.007812 218.42125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1470.585938 2471.7025 L 969.84375 2471.7025 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1470.585938 2471.7025 L 1345.390625 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1345.390625 2471.7025 L 1220.234375 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1220.234375 2471.7025 L 1095.039062 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1095.039062 2471.7025 L 969.84375 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 2471.7025 L 469.140625 2471.7025 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 2471.7025 L 844.6875 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 844.6875 2471.7025 L 719.492188 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 719.492188 2471.7025 L 594.296875 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 594.296875 2471.7025 L 469.140625 2596.897813 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(0%,68.943787%,68.943787%);fill-opacity:1;" d="M 578.933594 253.390625 C 578.933594 260.304688 573.328125 265.910156 566.414062 265.910156 C 559.5 265.910156 553.894531 260.304688 553.894531 253.390625 C 553.894531 246.476562 559.5 240.871094 566.414062 240.871094 C 573.328125 240.871094 578.933594 246.476562 578.933594 253.390625 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5789.335938 1282.48375 C 5789.335938 1213.343125 5733.28125 1157.288438 5664.140625 1157.288438 C 5595 1157.288438 5538.945312 1213.343125 5538.945312 1282.48375 C 5538.945312 1351.624375 5595 1407.679063 5664.140625 1407.679063 C 5733.28125 1407.679063 5789.335938 1351.624375 5789.335938 1282.48375 Z M 5789.335938 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(0%,68.943787%,68.943787%);fill-opacity:1;" d="M 297.273438 253.390625 C 297.273438 260.304688 291.671875 265.910156 284.757812 265.910156 C 277.84375 265.910156 272.238281 260.304688 272.238281 253.390625 C 272.238281 246.476562 277.84375 240.871094 284.757812 240.871094 C 291.671875 240.871094 297.273438 246.476562 297.273438 253.390625 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2972.734375 1282.48375 C 2972.734375 1213.343125 2916.71875 1157.288438 2847.578125 1157.288438 C 2778.4375 1157.288438 2722.382812 1213.343125 2722.382812 1282.48375 C 2722.382812 1351.624375 2778.4375 1407.679063 2847.578125 1407.679063 C 2916.71875 1407.679063 2972.734375 1351.624375 2972.734375 1282.48375 Z M 2972.734375 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5977.109375 1532.835313 C 5977.109375 1498.265 5949.0625 1470.257188 5914.492188 1470.257188 C 5879.921875 1470.257188 5851.914062 1498.265 5851.914062 1532.835313 C 5851.914062 1567.405625 5879.921875 1595.413438 5914.492188 1595.413438 C 5949.0625 1595.413438 5977.109375 1567.405625 5977.109375 1532.835313 Z M 5977.109375 1532.835313 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3160.507812 1532.835313 C 3160.507812 1498.265 3132.5 1470.257188 3097.929688 1470.257188 C 3063.359375 1470.257188 3035.351562 1498.265 3035.351562 1532.835313 C 3035.351562 1567.405625 3063.359375 1595.413438 3097.929688 1595.413438 C 3132.5 1595.413438 3160.507812 1567.405625 3160.507812 1532.835313 Z M 3160.507812 1532.835313 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:41.727;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 2221.311875 L 969.84375 1282.48375 L 6603.007812 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:41.727;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6603.007812 343.616563 L 6603.007812 2221.311875 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <g clip-path="url(#clip2)" clip-rule="nonzero"> <g clip-path="url(#clip3)" clip-rule="evenodd"> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2847.578125 1345.061875 L 2847.578125 1908.382188 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2889.296875 1719.2025 L 2847.578125 1886.116563 L 2805.859375 1719.2025 Z M 2889.296875 1719.2025 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <g clip-path="url(#clip4)" clip-rule="nonzero"> <g clip-path="url(#clip5)" clip-rule="evenodd"> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5664.140625 1345.061875 L 5664.140625 1908.382188 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5705.859375 1719.2025 L 5664.140625 1886.116563 L 5622.421875 1719.2025 Z M 5705.859375 1719.2025 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <g clip-path="url(#clip6)" clip-rule="nonzero"> <g clip-path="url(#clip7)" clip-rule="evenodd"> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6665.585938 1282.48375 L 7228.90625 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 7039.765625 1240.765 L 7206.640625 1282.48375 L 7039.765625 1324.2025 Z M 7039.765625 1240.765 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1095.039062 2221.311875 L 1220.234375 1282.48375 L 4975.664062 1783.186875 L 6853.359375 1282.48375 L 6603.007812 343.616563 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,100%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6853.359375 1282.48375 L 7103.710938 2221.311875 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 1094.710313 L 1220.234375 1094.710313 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 969.84375 1157.288438 L 969.84375 1032.093125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1220.234375 1157.288438 L 1220.234375 1032.093125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2847.578125 1032.093125 L 2847.578125 1157.288438 L 2847.578125 1094.710313 L 3097.929688 1094.710313 L 3097.929688 1157.288438 L 3097.929688 1032.093125 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3223.125 1532.835313 L 3348.28125 1532.835313 L 3285.703125 1532.835313 L 3285.703125 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5476.367188 1282.48375 L 5476.367188 1532.835313 L 5413.789062 1532.835313 L 5538.945312 1532.835313 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 5664.140625 1094.710313 L 5664.140625 969.515 L 5664.140625 1032.093125 L 5914.492188 1032.093125 L 5914.492188 1094.710313 L 5914.492188 969.515 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 478.789062 253.390625 C 478.789062 256.847656 475.984375 259.652344 472.527344 259.652344 C 469.070312 259.652344 466.269531 256.847656 466.269531 253.390625 C 466.269531 249.933594 469.070312 247.132812 472.527344 247.132812 C 475.984375 247.132812 478.789062 249.933594 478.789062 253.390625 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 4787.890625 1282.48375 C 4787.890625 1247.913438 4759.84375 1219.866563 4725.273438 1219.866563 C 4690.703125 1219.866563 4662.695312 1247.913438 4662.695312 1282.48375 C 4662.695312 1317.054063 4690.703125 1345.061875 4725.273438 1345.061875 C 4759.84375 1345.061875 4787.890625 1317.054063 4787.890625 1282.48375 Z M 4787.890625 1282.48375 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 666.558594 347.277344 C 666.558594 350.734375 663.757812 353.535156 660.300781 353.535156 C 656.84375 353.535156 654.039062 350.734375 654.039062 347.277344 C 654.039062 343.820312 656.84375 341.019531 660.300781 341.019531 C 663.757812 341.019531 666.558594 343.820312 666.558594 347.277344 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6665.585938 343.616563 C 6665.585938 309.04625 6637.578125 281.038438 6603.007812 281.038438 C 6568.4375 281.038438 6540.390625 309.04625 6540.390625 343.616563 C 6540.390625 378.186875 6568.4375 406.194688 6603.007812 406.194688 C 6637.578125 406.194688 6665.585938 378.186875 6665.585938 343.616563 Z M 6665.585938 343.616563 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 103.246094 159.507812 C 103.246094 162.960938 100.441406 165.765625 96.984375 165.765625 C 93.53125 165.765625 90.726562 162.960938 90.726562 159.507812 C 90.726562 156.050781 93.53125 153.246094 96.984375 153.246094 C 100.441406 153.246094 103.246094 156.050781 103.246094 159.507812 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1032.460938 2221.311875 C 1032.460938 2186.780625 1004.414062 2158.73375 969.84375 2158.73375 C 935.3125 2158.73375 907.265625 2186.780625 907.265625 2221.311875 C 907.265625 2255.882188 935.3125 2283.929063 969.84375 2283.929063 C 1004.414062 2283.929063 1032.460938 2255.882188 1032.460938 2221.311875 Z M 1032.460938 2221.311875 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 93.925781 137.53125 C 93.925781 139.296875 92.492188 140.726562 90.726562 140.726562 C 88.960938 140.726562 87.527344 139.296875 87.527344 137.53125 C 87.527344 135.761719 88.960938 134.328125 90.726562 134.328125 C 92.492188 134.328125 93.925781 135.761719 93.925781 137.53125 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 939.257812 2441.0775 C 939.257812 2423.42125 924.921875 2409.124375 907.265625 2409.124375 C 889.609375 2409.124375 875.273438 2423.42125 875.273438 2441.0775 C 875.273438 2458.772813 889.609375 2473.10875 907.265625 2473.10875 C 924.921875 2473.10875 939.257812 2458.772813 939.257812 2441.0775 Z M 939.257812 2441.0775 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 106.445312 137.53125 C 106.445312 139.296875 105.011719 140.726562 103.246094 140.726562 C 101.476562 140.726562 100.046875 139.296875 100.046875 137.53125 C 100.046875 135.761719 101.476562 134.328125 103.246094 134.328125 C 105.011719 134.328125 106.445312 135.761719 106.445312 137.53125 "/> <path style="fill:none;stroke-width:10.4318;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1064.453125 2441.0775 C 1064.453125 2423.42125 1050.117188 2409.124375 1032.460938 2409.124375 C 1014.765625 2409.124375 1000.46875 2423.42125 1000.46875 2441.0775 C 1000.46875 2458.772813 1014.765625 2473.10875 1032.460938 2473.10875 C 1050.117188 2473.10875 1064.453125 2458.772813 1064.453125 2441.0775 Z M 1064.453125 2441.0775 " transform="matrix(0.1,0,0,-0.1,0,381.639)"/> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-1" x="578.856" y="203.337"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph1-1" x="590.353" y="206.436"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-1" x="297.216" y="203.337"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph1-2" x="308.713" y="206.436"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-1" x="710.287" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph1-3" x="721.784" y="287.799"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="508.282" y="240.889"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="516.178" y="240.889"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="525.772" y="243.471"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="597.632" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="605.527" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="615.121" y="287.282"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="128.233" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="136.128" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="145.722" y="287.282"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="315.992" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="323.888" y="284.699"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="333.481" y="287.282"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="334.768" y="247.148"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="342.664" y="247.148"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="352.257" y="249.73"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="115.715" y="165.785"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="125.309" y="168.367"/> </g> </g> </svg> The left beam is constrained by a roller and by the right beam, the first requires that the Centre of Instantaneous Rotation (CIR) belongs to the vertical line in $A$, while the second requires that the CIR belongs to the line that connects the hinges of the right beam. The angles of rotation are $\theta_\text{left} = u_A/L$ and $\theta_\text{right} = -2 u_A/L$ and eventually we have $x_1=x_2=x_3=2u_A$ and $$ \boldsymbol e = \begin{Bmatrix}2\\2\\2\end{Bmatrix}.$$ ```python e = array((2.0, 2.0, 2.0)) ``` ### Structural Matrices ```python display(HTML(open('figures/trab1_conv.svg').read())) ``` <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="334.147pt" height="147.344pt" viewBox="0 0 334.147 147.344" version="1.1"> <defs> <g> <symbol overflow="visible" id="glyph0-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph0-1"> <path style="stroke:none;" d="M 5.46875 -1.484375 C 5.515625 -1.015625 5.609375 -0.609375 5.671875 -0.375 C 5.78125 0.046875 5.828125 0.265625 6.21875 0.265625 C 6.640625 0.265625 7.34375 -0.140625 7.34375 -0.328125 C 7.34375 -0.34375 7.34375 -0.390625 7.265625 -0.390625 C 7.25 -0.390625 7.140625 -0.375 6.96875 -0.28125 C 6.875 -0.234375 6.859375 -0.234375 6.828125 -0.234375 C 6.5625 -0.234375 6.5 -0.515625 6.390625 -1.046875 C 6.3125 -1.4375 6.25 -1.71875 6.15625 -3.046875 C 6.09375 -3.84375 6.046875 -4.625 6.046875 -5.421875 L 6.046875 -6.265625 C 6.046875 -6.4375 6.046875 -6.484375 5.953125 -6.484375 C 5.84375 -6.484375 5.484375 -6.359375 5.28125 -6.09375 L 5.21875 -5.984375 C 5.203125 -5.96875 4.5625 -4.5625 3.421875 -2.765625 C 2.953125 -2.046875 1.890625 -0.390625 1.375 -0.390625 C 1.125 -0.390625 0.734375 -0.578125 0.640625 -0.890625 C 0.625 -0.953125 0.625 -1 0.578125 -1 C 0.4375 -1 0.234375 -0.53125 0.234375 -0.296875 C 0.234375 0.015625 0.625 0.453125 1.078125 0.453125 C 1.625 0.453125 2.3125 -0.53125 2.96875 -1.484375 Z M 5.265625 -5.390625 L 5.265625 -5 C 5.265625 -3.984375 5.375 -2.484375 5.421875 -1.984375 L 3.734375 -1.984375 C 3.578125 -1.984375 3.453125 -1.984375 3.203125 -1.828125 C 3.765625 -2.6875 4.046875 -3.15625 4.375 -3.71875 C 4.9375 -4.734375 5.125 -5.140625 5.25 -5.390625 Z M 5.265625 -5.390625 "/> </symbol> <symbol overflow="visible" id="glyph0-2"> <path style="stroke:none;" d="M 2.5625 -6.25 C 2.5625 -6.3125 2.53125 -6.328125 2.453125 -6.328125 C 2.359375 -6.328125 2.09375 -6.1875 1.90625 -6.09375 C 1.453125 -5.859375 1.125 -5.703125 1.125 -5.546875 C 1.125 -5.5 1.171875 -5.484375 1.21875 -5.484375 C 1.3125 -5.484375 1.578125 -5.625 1.765625 -5.703125 C 1.609375 -4.59375 1.4375 -3.671875 1.28125 -2.921875 C 1.015625 -1.71875 0.828125 -0.953125 0.390625 -0.109375 C 0.28125 0.109375 0.28125 0.125 0.28125 0.140625 C 0.28125 0.203125 0.359375 0.203125 0.375 0.203125 C 0.46875 0.203125 0.90625 0.046875 1.078125 -0.265625 C 1.25 -0.625 1.53125 -1.140625 1.75 -2 C 1.890625 -2.53125 2.265625 -4.015625 2.96875 -4.953125 C 3.328125 -5.421875 3.6875 -5.828125 4.375 -5.828125 C 4.859375 -5.828125 5.3125 -5.546875 5.3125 -5.03125 C 5.3125 -4.3125 4.59375 -4.03125 3.40625 -3.625 C 2.875 -3.453125 2.75 -3.25 2.75 -3.1875 C 2.75 -3.125 2.796875 -3.125 2.84375 -3.125 C 2.90625 -3.125 3.09375 -3.15625 3.296875 -3.15625 C 4.21875 -3.15625 4.984375 -2.625 4.984375 -1.765625 C 4.984375 -0.515625 3.796875 -0.3125 3.171875 -0.3125 C 2.71875 -0.3125 2.328125 -0.453125 2 -0.796875 C 1.953125 -0.859375 1.9375 -0.859375 1.875 -0.859375 C 1.75 -0.859375 1.5625 -0.765625 1.453125 -0.703125 C 1.25 -0.5625 1.25 -0.53125 1.1875 -0.40625 C 1.34375 -0.234375 1.6875 0.203125 2.5625 0.203125 C 3.875 0.203125 5.765625 -0.703125 5.765625 -2.15625 C 5.765625 -3.015625 5.0625 -3.53125 4.296875 -3.625 C 4.828125 -3.890625 6.09375 -4.5 6.09375 -5.421875 C 6.09375 -5.96875 5.625 -6.328125 4.984375 -6.328125 C 4.359375 -6.328125 3.25 -5.984375 2.359375 -4.859375 L 2.34375 -4.859375 Z M 2.5625 -6.25 "/> </symbol> <symbol overflow="visible" id="glyph0-3"> <path style="stroke:none;" d="M 4.59375 -1.40625 C 4.59375 -1.453125 4.5625 -1.484375 4.515625 -1.484375 C 4.421875 -1.484375 4.03125 -1.359375 3.828125 -1.0625 C 3.609375 -0.75 3.234375 -0.28125 2.5 -0.28125 C 1.65625 -0.28125 0.90625 -0.890625 0.90625 -2.25 C 0.90625 -2.859375 1.109375 -4.046875 1.890625 -5.03125 C 2.296875 -5.53125 2.8125 -5.828125 3.546875 -5.828125 C 3.96875 -5.828125 4.125 -5.65625 4.125 -5.34375 C 4.125 -5.015625 3.75 -4.34375 3.703125 -4.265625 C 3.625 -4.140625 3.625 -4.109375 3.625 -4.09375 C 3.625 -4.046875 3.6875 -4.03125 3.71875 -4.03125 C 3.875 -4.03125 4.25 -4.21875 4.375 -4.421875 C 4.40625 -4.46875 4.90625 -5.3125 4.90625 -5.734375 C 4.90625 -6.15625 4.65625 -6.328125 4.15625 -6.328125 C 3.078125 -6.328125 2 -5.734375 1.3125 -4.953125 C 0.453125 -3.984375 0.125 -2.6875 0.125 -1.859375 C 0.125 -0.5 0.875 0.21875 1.890625 0.21875 C 3.359375 0.21875 4.59375 -1.203125 4.59375 -1.40625 Z M 4.59375 -1.40625 "/> </symbol> <symbol overflow="visible" id="glyph0-4"> <path style="stroke:none;" d="M 1.921875 0 C 4.078125 0 7.0625 -1.59375 7.0625 -4.03125 C 7.0625 -4.828125 6.6875 -5.375 6.078125 -5.71875 C 5.3125 -6.125 4.546875 -6.125 3.6875 -6.125 C 2.921875 -6.125 2.3125 -6.125 1.53125 -5.78125 C 0.3125 -5.21875 0.1875 -4.484375 0.1875 -4.453125 C 0.1875 -4.40625 0.203125 -4.375 0.28125 -4.375 C 0.34375 -4.375 0.515625 -4.421875 0.6875 -4.53125 C 0.921875 -4.6875 0.9375 -4.734375 0.984375 -4.890625 C 1.109375 -5.25 1.3125 -5.5625 2.53125 -5.625 C 2.421875 -3.84375 1.984375 -2.109375 1.3125 -0.46875 C 0.890625 -0.328125 0.765625 -0.109375 0.765625 -0.0625 C 0.765625 -0.015625 0.765625 0 0.984375 0 Z M 1.953125 -0.5 C 2.796875 -2.53125 3.109375 -3.984375 3.296875 -5.625 C 3.953125 -5.625 6.28125 -5.625 6.28125 -3.640625 C 6.28125 -1.859375 4.65625 -0.5 2.46875 -0.5 Z M 1.953125 -0.5 "/> </symbol> <symbol overflow="visible" id="glyph1-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph1-1"> <path style="stroke:none;" d="M 1.6875 -1.40625 C 1.796875 -1.828125 1.96875 -2.484375 1.96875 -2.5625 C 1.984375 -2.609375 2.21875 -3.046875 2.53125 -3.359375 C 2.796875 -3.59375 3.140625 -3.734375 3.484375 -3.734375 C 3.96875 -3.734375 3.96875 -3.265625 3.96875 -3.109375 C 3.96875 -3 3.96875 -2.875 3.859375 -2.4375 L 3.65625 -1.640625 C 3.375 -0.484375 3.296875 -0.203125 3.296875 -0.15625 C 3.296875 -0.046875 3.375 0.09375 3.578125 0.09375 C 3.703125 0.09375 3.84375 0.015625 3.90625 -0.09375 C 3.921875 -0.140625 4 -0.4375 4.046875 -0.609375 L 4.25 -1.40625 C 4.34375 -1.828125 4.515625 -2.484375 4.53125 -2.5625 C 4.546875 -2.609375 4.765625 -3.046875 5.09375 -3.359375 C 5.359375 -3.59375 5.6875 -3.734375 6.046875 -3.734375 C 6.53125 -3.734375 6.53125 -3.265625 6.53125 -3.109375 C 6.53125 -2.5625 6.109375 -1.46875 6.015625 -1.1875 C 5.90625 -0.921875 5.859375 -0.828125 5.859375 -0.65625 C 5.859375 -0.171875 6.234375 0.09375 6.640625 0.09375 C 7.5 0.09375 7.84375 -1.1875 7.84375 -1.28125 C 7.84375 -1.328125 7.828125 -1.390625 7.734375 -1.390625 C 7.625 -1.390625 7.625 -1.34375 7.59375 -1.234375 C 7.359375 -0.46875 6.984375 -0.125 6.65625 -0.125 C 6.59375 -0.125 6.4375 -0.125 6.4375 -0.40625 C 6.4375 -0.640625 6.53125 -0.875 6.59375 -1.0625 C 6.78125 -1.53125 7.140625 -2.46875 7.140625 -2.984375 C 7.140625 -3.78125 6.546875 -3.96875 6.078125 -3.96875 C 5.21875 -3.96875 4.75 -3.328125 4.59375 -3.109375 C 4.5 -3.84375 3.890625 -3.96875 3.515625 -3.96875 C 2.6875 -3.96875 2.25 -3.375 2.09375 -3.1875 C 2.046875 -3.671875 1.671875 -3.96875 1.234375 -3.96875 C 0.859375 -3.96875 0.65625 -3.6875 0.53125 -3.4375 C 0.390625 -3.125 0.265625 -2.625 0.265625 -2.578125 C 0.265625 -2.5 0.328125 -2.46875 0.390625 -2.46875 C 0.484375 -2.46875 0.5 -2.515625 0.546875 -2.703125 C 0.71875 -3.40625 0.90625 -3.734375 1.203125 -3.734375 C 1.484375 -3.734375 1.484375 -3.453125 1.484375 -3.3125 C 1.484375 -3.125 1.40625 -2.859375 1.359375 -2.625 C 1.296875 -2.390625 1.203125 -2 1.171875 -1.890625 L 0.8125 -0.421875 C 0.75 -0.203125 0.75 -0.1875 0.75 -0.15625 C 0.75 -0.046875 0.828125 0.09375 1.015625 0.09375 C 1.140625 0.09375 1.28125 0.015625 1.34375 -0.09375 C 1.375 -0.140625 1.4375 -0.4375 1.484375 -0.609375 Z M 1.6875 -1.40625 "/> </symbol> <symbol overflow="visible" id="glyph2-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph2-1"> <path style="stroke:none;" d="M -6.03125 -3.734375 C -6.390625 -3.8125 -6.5 -3.84375 -6.5 -4.78125 C -6.5 -5.078125 -6.5 -5.15625 -6.6875 -5.15625 C -6.8125 -5.15625 -6.8125 -5.046875 -6.8125 -5 C -6.8125 -4.671875 -6.78125 -3.859375 -6.78125 -3.53125 C -6.78125 -3.234375 -6.8125 -2.5 -6.8125 -2.203125 C -6.8125 -2.140625 -6.8125 -2.015625 -6.609375 -2.015625 C -6.5 -2.015625 -6.5 -2.109375 -6.5 -2.296875 C -6.5 -2.3125 -6.5 -2.5 -6.484375 -2.671875 C -6.453125 -2.84375 -6.453125 -2.9375 -6.3125 -2.9375 C -6.28125 -2.9375 -6.25 -2.9375 -6.125 -2.90625 L -0.78125 -1.5625 C -0.390625 -1.46875 -0.3125 -1.453125 -0.3125 -0.65625 C -0.3125 -0.484375 -0.3125 -0.390625 -0.109375 -0.390625 C 0 -0.390625 0 -0.484375 0 -0.65625 L 0 -5.28125 C 0 -5.515625 0 -5.515625 -0.171875 -5.578125 L -2.328125 -6.375 C -2.4375 -6.40625 -2.453125 -6.40625 -2.46875 -6.40625 C -2.5 -6.40625 -2.578125 -6.375 -2.578125 -6.296875 C -2.578125 -6.203125 -2.515625 -6.1875 -2.359375 -6.125 C -1.453125 -5.78125 -0.3125 -5.34375 -0.3125 -3.625 L -0.3125 -2.6875 C -0.3125 -2.546875 -0.3125 -2.515625 -0.3125 -2.46875 C -0.328125 -2.359375 -0.34375 -2.328125 -0.421875 -2.328125 C -0.453125 -2.328125 -0.46875 -2.328125 -0.640625 -2.375 Z M -6.03125 -3.734375 "/> </symbol> <symbol overflow="visible" id="glyph3-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph3-1"> <path style="stroke:none;" d="M 1.265625 -0.765625 L 2.328125 -1.796875 C 3.875 -3.171875 4.46875 -3.703125 4.46875 -4.703125 C 4.46875 -5.84375 3.578125 -6.640625 2.359375 -6.640625 C 1.234375 -6.640625 0.5 -5.71875 0.5 -4.828125 C 0.5 -4.28125 1 -4.28125 1.03125 -4.28125 C 1.203125 -4.28125 1.546875 -4.390625 1.546875 -4.8125 C 1.546875 -5.0625 1.359375 -5.328125 1.015625 -5.328125 C 0.9375 -5.328125 0.921875 -5.328125 0.890625 -5.3125 C 1.109375 -5.96875 1.65625 -6.328125 2.234375 -6.328125 C 3.140625 -6.328125 3.5625 -5.515625 3.5625 -4.703125 C 3.5625 -3.90625 3.078125 -3.125 2.515625 -2.5 L 0.609375 -0.375 C 0.5 -0.265625 0.5 -0.234375 0.5 0 L 4.203125 0 L 4.46875 -1.734375 L 4.234375 -1.734375 C 4.171875 -1.4375 4.109375 -1 4 -0.84375 C 3.9375 -0.765625 3.28125 -0.765625 3.0625 -0.765625 Z M 1.265625 -0.765625 "/> </symbol> <symbol overflow="visible" id="glyph4-0"> <path style="stroke:none;" d=""/> </symbol> <symbol overflow="visible" id="glyph4-1"> <path style="stroke:none;" d="M 3.734375 -6.03125 C 3.8125 -6.390625 3.84375 -6.5 4.78125 -6.5 C 5.078125 -6.5 5.15625 -6.5 5.15625 -6.6875 C 5.15625 -6.8125 5.046875 -6.8125 5 -6.8125 C 4.671875 -6.8125 3.859375 -6.78125 3.53125 -6.78125 C 3.234375 -6.78125 2.5 -6.8125 2.203125 -6.8125 C 2.140625 -6.8125 2.015625 -6.8125 2.015625 -6.609375 C 2.015625 -6.5 2.109375 -6.5 2.296875 -6.5 C 2.3125 -6.5 2.5 -6.5 2.671875 -6.484375 C 2.84375 -6.453125 2.9375 -6.453125 2.9375 -6.3125 C 2.9375 -6.28125 2.9375 -6.25 2.90625 -6.125 L 1.5625 -0.78125 C 1.46875 -0.390625 1.453125 -0.3125 0.65625 -0.3125 C 0.484375 -0.3125 0.390625 -0.3125 0.390625 -0.109375 C 0.390625 0 0.484375 0 0.65625 0 L 5.28125 0 C 5.515625 0 5.515625 0 5.578125 -0.171875 L 6.375 -2.328125 C 6.40625 -2.4375 6.40625 -2.453125 6.40625 -2.46875 C 6.40625 -2.5 6.375 -2.578125 6.296875 -2.578125 C 6.203125 -2.578125 6.1875 -2.515625 6.125 -2.359375 C 5.78125 -1.453125 5.34375 -0.3125 3.625 -0.3125 L 2.6875 -0.3125 C 2.546875 -0.3125 2.515625 -0.3125 2.46875 -0.3125 C 2.359375 -0.328125 2.328125 -0.34375 2.328125 -0.421875 C 2.328125 -0.453125 2.328125 -0.46875 2.375 -0.640625 Z M 3.734375 -6.03125 "/> </symbol> </g> <clipPath id="clip1"> <path d="M 322 104 L 334.148438 104 L 334.148438 121 L 322 121 Z M 322 104 "/> </clipPath> <clipPath id="clip2"> <path d="M 322 109 L 334.148438 109 L 334.148438 126 L 322 126 Z M 322 109 "/> </clipPath> <clipPath id="clip3"> <path d="M 322 114 L 334.148438 114 L 334.148438 131 L 322 131 Z M 322 114 "/> </clipPath> <clipPath id="clip4"> <path d="M 322 118 L 334.148438 118 L 334.148438 136 L 322 136 Z M 322 118 "/> </clipPath> <clipPath id="clip5"> <path d="M 318 3 L 334.148438 3 L 334.148438 20 L 318 20 Z M 318 3 "/> </clipPath> <clipPath id="clip6"> <path d="M 8 71 L 9 71 L 9 121 L 8 121 Z M 8 71 "/> </clipPath> <clipPath id="clip7"> <path d="M 0 147.34375 L 335 147.34375 L 335 -0.65625 L 0 -0.65625 Z M 8.582031 120.183594 L 7.835938 120.183594 L 6.601562 112.527344 L 9.816406 112.527344 Z M 7.835938 71.25 L 8.582031 71.25 L 9.816406 78.90625 L 6.601562 78.90625 Z M 7.835938 71.25 "/> </clipPath> <clipPath id="clip8"> <path d="M 126 138 L 223 138 L 223 140 L 126 140 Z M 126 138 "/> </clipPath> <clipPath id="clip9"> <path d="M 0 147.34375 L 335 147.34375 L 335 -0.65625 L 0 -0.65625 Z M 223.011719 138.707031 L 223.011719 139.457031 L 215.355469 140.691406 L 215.355469 137.476562 Z M 125.890625 139.457031 L 125.890625 138.707031 L 133.546875 137.476562 L 133.546875 140.691406 Z M 125.890625 139.457031 "/> </clipPath> <clipPath id="clip10"> <path d="M 222 138 L 272 138 L 272 140 L 222 140 Z M 222 138 "/> </clipPath> <clipPath id="clip11"> <path d="M 0 147.34375 L 335 147.34375 L 335 -0.65625 L 0 -0.65625 Z M 222.261719 139.457031 L 222.261719 138.707031 L 229.917969 137.476562 L 229.917969 140.691406 Z M 271.199219 138.707031 L 271.199219 139.457031 L 263.539062 140.691406 L 263.539062 137.476562 Z M 271.199219 138.707031 "/> </clipPath> <clipPath id="clip12"> <path d="M 270 138 L 320 138 L 320 140 L 270 140 Z M 270 138 "/> </clipPath> <clipPath id="clip13"> <path d="M 0 147.34375 L 335 147.34375 L 335 -0.65625 L 0 -0.65625 Z M 270.449219 139.457031 L 270.449219 138.707031 L 278.105469 137.476562 L 278.105469 140.691406 Z M 319.382812 138.707031 L 319.382812 139.457031 L 311.726562 140.691406 L 311.726562 137.476562 Z M 319.382812 138.707031 "/> </clipPath> <clipPath id="clip14"> <path d="M 8 23 L 9 23 L 9 72 L 8 72 Z M 8 23 "/> </clipPath> <clipPath id="clip15"> <path d="M 0 147.34375 L 335 147.34375 L 335 -0.65625 L 0 -0.65625 Z M 8.582031 71.996094 L 7.835938 71.996094 L 6.601562 64.339844 L 9.816406 64.339844 Z M 7.835938 23.0625 L 8.582031 23.0625 L 9.816406 30.71875 L 6.601562 30.71875 Z M 7.835938 23.0625 "/> </clipPath> <clipPath id="clip16"> <path d="M 29 138 L 127 138 L 127 140 L 29 140 Z M 29 138 "/> </clipPath> <clipPath id="clip17"> <path d="M 0 147.34375 L 335 147.34375 L 335 -0.65625 L 0 -0.65625 Z M 126.640625 138.707031 L 126.640625 139.457031 L 118.984375 140.691406 L 118.984375 137.476562 Z M 29.519531 139.457031 L 29.519531 138.707031 L 37.175781 137.476562 L 37.175781 140.691406 Z M 29.519531 139.457031 "/> </clipPath> <clipPath id="clip18"> <path d="M 320 110 L 334.148438 110 L 334.148438 125 L 320 125 Z M 320 110 "/> </clipPath> <clipPath id="clip19"> <path d="M 320 115 L 334.148438 115 L 334.148438 130 L 320 130 Z M 320 115 "/> </clipPath> </defs> <g id="surface1"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 395.3125 1239.065 L 202.578125 1239.065 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 395.3125 1239.065 L 347.109375 1287.268125 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 347.109375 1239.065 L 298.945312 1287.268125 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 298.945312 1239.065 L 250.742188 1287.268125 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 250.742188 1239.065 L 202.578125 1287.268125 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3190.078125 1239.065 L 3231.835938 1311.330625 L 3148.320312 1311.330625 Z M 3190.078125 1239.065 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3141.914062 1335.432188 L 3238.28125 1335.432188 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3190.078125 275.354063 L 3262.382812 233.59625 L 3262.382812 317.111875 Z M 3190.078125 275.354063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 323.518125 L 3286.445312 227.150938 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 371.72125 L 3286.445312 178.986875 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip1)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 371.72125 L 3334.648438 323.518125 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <g clip-path="url(#clip2)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 323.518125 L 3334.648438 275.354063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <g clip-path="url(#clip3)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 275.354063 L 3334.648438 227.150938 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <g clip-path="url(#clip4)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 227.150938 L 3334.648438 178.986875 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 1335.432188 L 3093.710938 1335.432188 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip5)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3286.445312 1335.432188 L 3238.28125 1383.635313 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3238.28125 1335.432188 L 3190.078125 1383.635313 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3190.078125 1335.432188 L 3141.914062 1383.635313 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3141.914062 1335.432188 L 3093.710938 1383.635313 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(0%,56.054688%,56.054688%);fill-opacity:1;" d="M 275.640625 71.621094 C 275.640625 74.285156 273.484375 76.441406 270.824219 76.441406 C 268.160156 76.441406 266.003906 74.285156 266.003906 71.621094 C 266.003906 68.960938 268.160156 66.804688 270.824219 66.804688 C 273.484375 66.804688 275.640625 68.960938 275.640625 71.621094 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2756.40625 757.229063 C 2756.40625 730.588438 2734.84375 709.025938 2708.242188 709.025938 C 2681.601562 709.025938 2660.039062 730.588438 2660.039062 757.229063 C 2660.039062 783.830625 2681.601562 805.393125 2708.242188 805.393125 C 2734.84375 805.393125 2756.40625 783.830625 2756.40625 757.229063 Z M 2756.40625 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(0%,56.054688%,56.054688%);fill-opacity:1;" d="M 131.085938 71.621094 C 131.085938 74.285156 128.925781 76.441406 126.265625 76.441406 C 123.605469 76.441406 121.445312 74.285156 121.445312 71.621094 C 121.445312 68.960938 123.605469 66.804688 126.265625 66.804688 C 128.925781 66.804688 131.085938 68.960938 131.085938 71.621094 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1310.859375 757.229063 C 1310.859375 730.588438 1289.257812 709.025938 1262.65625 709.025938 C 1236.054688 709.025938 1214.453125 730.588438 1214.453125 757.229063 C 1214.453125 783.830625 1236.054688 805.393125 1262.65625 805.393125 C 1289.257812 805.393125 1310.859375 783.830625 1310.859375 757.229063 Z M 1310.859375 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6.054688 757.229063 L 158.125 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6.054688 1239.065 L 158.125 1239.065 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip6)" clip-rule="nonzero"> <g clip-path="url(#clip7)" clip-rule="evenodd"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 82.109375 757.229063 L 82.109375 275.354063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 98.164062 684.3775 L 82.109375 748.635313 L 66.015625 684.3775 Z M 98.164062 684.3775 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 66.015625 348.166563 L 82.109375 283.90875 L 98.164062 348.166563 Z M 66.015625 348.166563 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6.054688 275.354063 L 158.125 275.354063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 6.054688 757.229063 L 158.125 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 298.945312 158.635313 L 298.945312 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1262.65625 158.635313 L 1262.65625 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip8)" clip-rule="nonzero"> <g clip-path="url(#clip9)" clip-rule="evenodd"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1262.65625 82.619688 L 2226.367188 82.619688 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1335.46875 98.674375 L 1271.210938 82.619688 L 1335.46875 66.525938 Z M 1335.46875 98.674375 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2153.554688 66.525938 L 2217.8125 82.619688 L 2153.554688 98.674375 Z M 2153.554688 66.525938 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1262.65625 158.635313 L 1262.65625 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2226.367188 158.635313 L 2226.367188 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip10)" clip-rule="nonzero"> <g clip-path="url(#clip11)" clip-rule="evenodd"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2708.242188 82.619688 L 2226.367188 82.619688 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2635.390625 66.525938 L 2699.648438 82.619688 L 2635.390625 98.674375 Z M 2635.390625 66.525938 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2299.179688 98.674375 L 2234.921875 82.619688 L 2299.179688 66.525938 Z M 2299.179688 98.674375 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2226.367188 158.635313 L 2226.367188 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2708.242188 158.635313 L 2708.242188 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip12)" clip-rule="nonzero"> <g clip-path="url(#clip13)" clip-rule="evenodd"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3190.078125 82.619688 L 2708.242188 82.619688 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3117.265625 66.525938 L 3181.523438 82.619688 L 3117.265625 98.674375 Z M 3117.265625 66.525938 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2781.054688 98.674375 L 2716.796875 82.619688 L 2781.054688 66.525938 Z M 2781.054688 98.674375 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2708.242188 158.635313 L 2708.242188 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3190.078125 158.635313 L 3190.078125 6.565 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip14)" clip-rule="nonzero"> <g clip-path="url(#clip15)" clip-rule="evenodd"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 82.109375 1239.065 L 82.109375 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 98.164062 1166.2525 L 82.109375 1230.510313 L 66.015625 1166.2525 Z M 98.164062 1166.2525 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 66.015625 830.041563 L 82.109375 765.78375 L 98.164062 830.041563 Z M 66.015625 830.041563 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <g clip-path="url(#clip16)" clip-rule="nonzero"> <g clip-path="url(#clip17)" clip-rule="evenodd"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 298.945312 82.619688 L 1262.65625 82.619688 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> </g> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 371.757812 98.674375 L 307.5 82.619688 L 371.757812 66.525938 Z M 371.757812 98.674375 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill-rule:evenodd;fill:rgb(0%,0%,0%);fill-opacity:1;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 1189.84375 66.525938 L 1254.0625 82.619688 L 1189.84375 98.674375 Z M 1189.84375 66.525938 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:16.062;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 298.945312 1239.065 L 298.945312 757.229063 L 3190.078125 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style="fill:none;stroke-width:16.062;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3190.078125 1239.065 L 3190.078125 275.354063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 0.605469 107.761719 L 15.8125 107.761719 L 15.8125 83.667969 L 0.605469 83.667969 Z M 0.605469 107.761719 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 66.03125 146.6875 L 90.125 146.6875 L 90.125 131.480469 L 66.03125 131.480469 Z M 66.03125 146.6875 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 162.40625 146.6875 L 186.496094 146.6875 L 186.496094 131.480469 L 162.40625 131.480469 Z M 162.40625 146.6875 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 234.683594 146.6875 L 258.777344 146.6875 L 258.777344 131.480469 L 234.683594 131.480469 Z M 234.683594 146.6875 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 282.871094 146.6875 L 306.964844 146.6875 L 306.964844 131.480469 L 282.871094 131.480469 Z M 282.871094 146.6875 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 0.605469 59.578125 L 15.8125 59.578125 L 15.8125 35.484375 L 0.605469 35.484375 Z M 0.605469 59.578125 "/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 225.046875 71.621094 C 225.046875 72.953125 223.96875 74.03125 222.636719 74.03125 C 221.308594 74.03125 220.226562 72.953125 220.226562 71.621094 C 220.226562 70.292969 221.308594 69.214844 222.636719 69.214844 C 223.96875 69.214844 225.046875 70.292969 225.046875 71.621094 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 2250.46875 757.229063 C 2250.46875 743.90875 2239.6875 733.1275 2226.367188 733.1275 C 2213.085938 733.1275 2202.265625 743.90875 2202.265625 757.229063 C 2202.265625 770.510313 2213.085938 781.291563 2226.367188 781.291563 C 2239.6875 781.291563 2250.46875 770.510313 2250.46875 757.229063 Z M 2250.46875 757.229063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 32.300781 23.4375 C 32.300781 24.765625 31.222656 25.847656 29.894531 25.847656 C 28.5625 25.847656 27.484375 24.765625 27.484375 23.4375 C 27.484375 22.105469 28.5625 21.027344 29.894531 21.027344 C 31.222656 21.027344 32.300781 22.105469 32.300781 23.4375 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 323.007812 1239.065 C 323.007812 1225.78375 312.226562 1214.963438 298.945312 1214.963438 C 285.625 1214.963438 274.84375 1225.78375 274.84375 1239.065 C 274.84375 1252.385313 285.625 1263.166563 298.945312 1263.166563 C 312.226562 1263.166563 323.007812 1252.385313 323.007812 1239.065 Z M 323.007812 1239.065 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 321.417969 23.4375 C 321.417969 24.765625 320.339844 25.847656 319.007812 25.847656 C 317.679688 25.847656 316.601562 24.765625 316.601562 23.4375 C 316.601562 22.105469 317.679688 21.027344 319.007812 21.027344 C 320.339844 21.027344 321.417969 22.105469 321.417969 23.4375 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3214.179688 1239.065 C 3214.179688 1225.78375 3203.398438 1214.963438 3190.078125 1214.963438 C 3176.796875 1214.963438 3166.015625 1225.78375 3166.015625 1239.065 C 3166.015625 1252.385313 3176.796875 1263.166563 3190.078125 1263.166563 C 3203.398438 1263.166563 3214.179688 1252.385313 3214.179688 1239.065 Z M 3214.179688 1239.065 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 321.417969 119.808594 C 321.417969 121.140625 320.339844 122.21875 319.007812 122.21875 C 317.679688 122.21875 316.601562 121.140625 316.601562 119.808594 C 316.601562 118.476562 317.679688 117.398438 319.007812 117.398438 C 320.339844 117.398438 321.417969 118.476562 321.417969 119.808594 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3214.179688 275.354063 C 3214.179688 262.03375 3203.398438 251.2525 3190.078125 251.2525 C 3176.796875 251.2525 3166.015625 262.03375 3166.015625 275.354063 C 3166.015625 288.674375 3176.796875 299.455625 3190.078125 299.455625 C 3203.398438 299.455625 3214.179688 288.674375 3214.179688 275.354063 Z M 3214.179688 275.354063 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 317.832031 14.976562 C 317.832031 15.65625 317.28125 16.210938 316.601562 16.210938 C 315.921875 16.210938 315.367188 15.65625 315.367188 14.976562 C 315.367188 14.296875 315.921875 13.746094 316.601562 13.746094 C 317.28125 13.746094 317.832031 14.296875 317.832031 14.976562 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3178.320312 1323.674375 C 3178.320312 1316.8775 3172.8125 1311.330625 3166.015625 1311.330625 C 3159.21875 1311.330625 3153.671875 1316.8775 3153.671875 1323.674375 C 3153.671875 1330.47125 3159.21875 1335.979063 3166.015625 1335.979063 C 3172.8125 1335.979063 3178.320312 1330.47125 3178.320312 1323.674375 Z M 3178.320312 1323.674375 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 322.648438 14.976562 C 322.648438 15.65625 322.097656 16.210938 321.417969 16.210938 C 320.738281 16.210938 320.1875 15.65625 320.1875 14.976562 C 320.1875 14.296875 320.738281 13.746094 321.417969 13.746094 C 322.097656 13.746094 322.648438 14.296875 322.648438 14.976562 "/> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3226.484375 1323.674375 C 3226.484375 1316.8775 3220.976562 1311.330625 3214.179688 1311.330625 C 3207.382812 1311.330625 3201.875 1316.8775 3201.875 1323.674375 C 3201.875 1330.47125 3207.382812 1335.979063 3214.179688 1335.979063 C 3220.976562 1335.979063 3226.484375 1330.47125 3226.484375 1323.674375 Z M 3226.484375 1323.674375 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 328.59375 117.398438 C 328.59375 118.050781 328.066406 118.578125 327.414062 118.578125 C 326.765625 118.578125 326.238281 118.050781 326.238281 117.398438 C 326.238281 116.75 326.765625 116.222656 327.414062 116.222656 C 328.066406 116.222656 328.59375 116.75 328.59375 117.398438 "/> <g clip-path="url(#clip18)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3285.9375 299.455625 C 3285.9375 292.932188 3280.664062 287.65875 3274.140625 287.65875 C 3267.65625 287.65875 3262.382812 292.932188 3262.382812 299.455625 C 3262.382812 305.94 3267.65625 311.213438 3274.140625 311.213438 C 3280.664062 311.213438 3285.9375 305.94 3285.9375 299.455625 Z M 3285.9375 299.455625 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <path style=" stroke:none;fill-rule:evenodd;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 328.59375 122.21875 C 328.59375 122.867188 328.066406 123.394531 327.414062 123.394531 C 326.765625 123.394531 326.238281 122.867188 326.238281 122.21875 C 326.238281 121.566406 326.765625 121.039062 327.414062 121.039062 C 328.066406 121.039062 328.59375 121.566406 328.59375 122.21875 "/> <g clip-path="url(#clip19)" clip-rule="nonzero"> <path style="fill:none;stroke-width:4.0155;stroke-linecap:butt;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;" d="M 3285.9375 251.2525 C 3285.9375 244.768125 3280.664062 239.494688 3274.140625 239.494688 C 3267.65625 239.494688 3262.382812 244.768125 3262.382812 251.2525 C 3262.382812 257.775938 3267.65625 263.049375 3274.140625 263.049375 C 3280.664062 263.049375 3285.9375 257.775938 3285.9375 251.2525 Z M 3285.9375 251.2525 " transform="matrix(0.1,0,0,-0.1,0,147.344)"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-1" x="26.248" y="16.223"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-2" x="315.899" y="6.586"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-3" x="313.955" y="131.871"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph0-4" x="218.989" y="83.684"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph1-1" x="122.243" y="62"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph1-1" x="266.803784" y="62"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="11.886" y="50.934"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph2-1" x="11.886" y="99.121"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="72.235" y="142.739"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="77.216" y="142.739"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph3-1" x="168.608" y="142.739"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="173.59" y="142.739"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="243.374028" y="142.739"/> </g> <g style="fill:rgb(0%,0%,0%);fill-opacity:1;"> <use xlink:href="#glyph4-1" x="291.569102" y="142.739"/> </g> </g> </svg> Compute the 3x3 flexibility using the Principle of Virtual Displacements and the 3x3 stiffness using inversion, while the mass matrix is directly assembled with the understanding that the lumped mass on $x_1$ is $2m$. The code uses a structure `m` where each of the three rows contains the computational represention (as polynomial coefficients) of the bending moments due to a unit load applied in the position of each of the three degrees of freedom, in each row six groups of polynomial coefficients, one group for each of the six intervals of definition in which the structure has been subdivided (a possible seventh interval is omitted because the bending moment is always zero for every possible unit load). ```python l = [1, 2, 2, 1, 1, 1] h = 0.5 ; t = 3*h m = [[p(2,0),p(h,0),p(h,1),p(h,0),p(h,h),p(1,0)], [p(2,0),p(1,0),p(0,2),p(1,0),p(1,1),p(2,0)], [p(2,0),p(h,0),p(h,1),p(h,0),p(t,h),p(2,0)]] F = array([[vw(emme, chi, l) for emme in m] for chi in m]) K = inv(F) M = array(((2.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0))) iM = inv(M) ld('\\boldsymbol F = \\frac{L^3}{12EJ}\\,', pmat(rounder(F*12), fmt='%+d')) ld('\\boldsymbol K = \\frac{3 EJ}{1588L^3}\\,', pmat(rounder(K*1588/3), fmt='%+d'), '= \\frac{EJ}{L^3}\\;\\hat{\\boldsymbol K}.') ld('\\boldsymbol M = m\\,', pmat(M, fmt='%d'), '= m\\;\\hat{\\boldsymbol M}.') ``` $$\boldsymbol F = \frac{L^3}{12EJ}\, \begin{bmatrix} +92&+128&+101\\ +128&+192&+146\\ +101&+146&+118 \end{bmatrix}$$ $$\boldsymbol K = \frac{3 EJ}{1588L^3}\, \begin{bmatrix} +1340&-358&-704\\ -358&+655&-504\\ -704&-504&+1280 \end{bmatrix} = \frac{EJ}{L^3}\;\hat{\boldsymbol K}.$$ $$\boldsymbol M = m\, \begin{bmatrix} 2&0&0\\ 0&1&0\\ 0&0&1 \end{bmatrix} = m\;\hat{\boldsymbol M}.$$ ### The eigenvalues problem We solve immediately the eigenvalue problem because when we know the shortest modal period of vibration it is possible to choose the integration time step $h$ to avoid numerical unstability issues with the linear acceleration algorithm. ```python wn2, Psi = eigh(K, M) wn = sqrt(wn2) li = wn Lambda2 = diag(wn2) Lambda = diag(wn) # eigenvectors are normalized → M* is a unit matrix, as well as its inverse Mstar, iMstar = eye(3), eye(3) ld(r'\boldsymbol\Omega^2 = \omega_0^2\,', pmat(Lambda2), r'=\omega_0^2\,\boldsymbol\Lambda^2.') ld(r'\boldsymbol\Omega=\omega_0\,', pmat(Lambda), r'=\omega_0\,\boldsymbol\Lambda.') ld(r'\boldsymbol T_\text{n}=\frac{2\pi}{\omega_0}\,', pmat(inv(Lambda)), r'= t_0\,\boldsymbol\Theta.') ld(r'\Psi=', pmat(Psi), '.') ``` $$\boldsymbol\Omega^2 = \omega_0^2\, \begin{bmatrix} +0.024831&+0.000000&+0.000000\\ +0.000000&+1.729964&+0.000000\\ +0.000000&+0.000000&+3.166490 \end{bmatrix} =\omega_0^2\,\boldsymbol\Lambda^2.$$ $$\boldsymbol\Omega=\omega_0\, \begin{bmatrix} +0.157577&+0.000000&+0.000000\\ +0.000000&+1.315281&+0.000000\\ +0.000000&+0.000000&+1.779463 \end{bmatrix} =\omega_0\,\boldsymbol\Lambda.$$ $$\boldsymbol T_\text{n}=\frac{2\pi}{\omega_0}\, \begin{bmatrix} +6.346086&+0.000000&-0.000000\\ +0.000000&+0.760294&-0.000000\\ +0.000000&+0.000000&+0.561967 \end{bmatrix} = t_0\,\boldsymbol\Theta.$$ $$\Psi= \begin{bmatrix} -0.431570&+0.504229&-0.243928\\ -0.623940&-0.701061&-0.345271\\ -0.488051&+0.004508&+0.872803 \end{bmatrix} .$$ ## Numerical Integration The shortest period is $T_3 = 2\pi\,0.562/\omega_0 \rightarrow A_3 = 1.124 \pi$ hence to avoid unstability of the linear acceleration algorithm we shall use a non dimensional time step $h<0.55A_3\approx0.6\pi$. We can anticipate that the modal response associated with mode 2 is important ($\lambda_2\approx\lambda_0$) so we choose an adimensional time step $h=A_2/20=2\pi\,0.760/20\approx0.08\pi$ that is much smaller than the maximum time step for which we have a stable behaviour. ### Initialization First a new, longer adimensional time vector and the corresponding support acceleration, then the efficace load vector (`peff` is an array with 2001 rows and 3 columns, each row corresponding to the force vector in a particular instant of time) ```python nsppi = 200 a, _, _, aA = a_uA_vA_aA(0, 16*pi, nsppi*16+1) peff = (- M @ e) * aA[:,None] ``` The constants that we need in the linear acceleration algorithm — note that we have an undamped system or, in other words, $\boldsymbol C = \boldsymbol 0$ ```python h = pi/nsppi K_ = K + 6*M/h**2 F_ = inv(K_) dp_v = 6*M/h dp_a = 3*M ``` ### The integration loop First we initialize the containers where to save the new results with the initial values at $a=0$, next the loop on the values of the load at times $t_i$ and $t_{i+1}$ with $i=0,\ldots,1999$. ```python Xl, Vl = [zeros(3)], [zeros(3)] for p0, p1 in p0_p1(peff): x0, v0 = Xl[-1], Vl[-1] a0 = iM @ (p0 -K@x0) dp = (p1-p0) + dp_a@a0 + dp_v@v0 dx = F_@dp dv = 3*dx/h - 3*v0 - a0*h/2 Xl.append(x0+dx), Vl.append(v0+dv) Xl = array(Xl) ; Vl = array(Vl) ``` #### Plotting ```python for i, line in enumerate(plt.plot(a/pi, Xl), 1): line.set_label(r'$x_{%d}$'%i) plt.xlabel(r'$\omega_0 t/\pi$') plt.ylabel(r'$x_i/\delta$') plt.title('Response — numerical integration — lin.acc.') plt.legend(); ``` ## Equation of Motion Denoting with $\boldsymbol x$ the dynamic component of the displacements, with $\boldsymbol x_\text{tot} = \boldsymbol x + \boldsymbol x_\text{stat} = \boldsymbol x + \boldsymbol e \;u_\mathcal{A}$ the equation of motion is (the independent variable being $a=\omega_0t$) $$ \hat{\boldsymbol M} \ddot{\boldsymbol x} + \hat{\boldsymbol K} \boldsymbol x = - \hat{\boldsymbol M} \boldsymbol e \ddot u_\mathcal{A}. $$ Using mass-normalized eigenvectors, with $\boldsymbol x = \delta\boldsymbol\Psi\boldsymbol q$ we have $$ \boldsymbol I \ddot{\boldsymbol q} + \boldsymbol\Lambda^2\boldsymbol q = \boldsymbol\Psi^T\hat{\boldsymbol M} \boldsymbol e \frac{\ddot u_A}{\delta}.$$ It is $$\frac{\ddot u_A}{\delta} = \frac{1}{2\pi}\,\lambda_0^2\,\sin(\lambda_0a)$$ and $$ \ddot q_i + \lambda_i^2 q_i = \frac{\Gamma_i}{2\pi}\,\lambda_0^2\,\sin(\lambda_0 a),\qquad\text{with } \Gamma_i = -\boldsymbol\psi_i^T \hat{\boldsymbol M} \boldsymbol e\text{ and } \lambda_0 = \frac43.$$ ```python G = - Psi.T @ M @ e ``` Substituting a particular integral $\xi_i=C_i\sin(\lambda_0 a)$ in the modal equation of motion we have $$(\lambda^2_i-\lambda^2_0)\,C_i\sin(\lambda_0 a) = \frac{\Gamma_i}{2\pi}\,\lambda_0^2\,\sin(\lambda_0 a)$$ and solving w/r to $C_i$ we have $$ C_i = \frac{\Gamma_i}{2\pi}\,\frac{\lambda_0^2}{\lambda_i^2-\lambda_0^2}$$ ```python C = G*l0**2/(li**2-l0**2)/2/pi ``` The modal response, taking into account that we start from rest conditions, is $$ q_i = C_i\left(\sin(\lambda_0 a) - \frac{\lambda_0}{\lambda_i}\,\sin(\lambda_i a)\right)$$ $$ \dot q_i = \lambda_0 C_i \left( \cos(\lambda_0 a) - \cos(\lambda_i a) \right).$$ ```python for n in range(3): i = n+1 ld(r'q_%d=%+10f\left(\sin\frac43a-%10f\sin%1fa\right)' % (i,C[n],l0/li[n],li[n]), r'\qquad\text{for }0 \le a \le \frac32\pi') ``` $$q_1= -0.637609\left(\sin\frac43a- 8.461449\sin0.157577a\right) \qquad\text{for }0 \le a \le \frac32\pi$$ $$q_2= +3.691468\left(\sin\frac43a- 1.013725\sin1.315281a\right) \qquad\text{for }0 \le a \le \frac32\pi$$ $$q_3= -0.016167\left(\sin\frac43a- 0.749290\sin1.779463a\right) \qquad\text{for }0 \le a \le \frac32\pi$$ ### Free vibration phase, $a\ge 3\pi/2 = a_1$ When the forced phase end, the system is in free vibrations and we can determine the constants of integration requiring that the displacements and velocities of the free vibration equal the displacements and velocities of the forced response at $t=t_0$. \begin{align} + (\cos\lambda_i a_1)\, A_i + (\sin\lambda_i a_1)\, B_i &= q_i(a_1) \\ - (\sin\lambda_i a_1)\, A_i + (\cos\lambda_i a_1)\, B_i &= \frac{\dot q_i(a_1)}{\lambda_i} \end{align} Because the coefficients form an othogonal matrix, \begin{align} A_i &= + (\cos\lambda_i a_1)\, q_i(a_1) - (\sin\lambda_i a_1)\, \frac{\dot q_i(a_1)}{\lambda_i}\\ B_i &= + (\sin\lambda_i a_1)\, q_i(a_1) + (\cos\lambda_i a_1)\, \frac{\dot q_i(a_1)}{\lambda_i}. \end{align} ```python a1 = 3*pi/2 q_a1 = C*(sin(l0*a1)-l0*sin(li*a1)/li) v_a1 = C*l0*(cos(l0*a1)-cos(li*a1)) ABs = [] for i in range(3): b = array((q_a1[i], v_a1[i]/li[i])) A = array(((+cos(li[i]*a1), -sin(li[i]*a1)), (+sin(li[i]*a1), +cos(li[i]*a1)))) ABs.append(A@b) ABs = array(ABs) ``` #### Analytical expressions ```python display(Latex(r'Modal responses for $a_1 \le a$.')) for n in range(3): i, l, A_, B_ = n+1, li[n], *ABs[n] display(Latex((r'$$q_{%d} = '+ r'%+6.3f\cos%6.3fa '+ r'%+6.3f\sin%6.3fa$$')%(i, A_, l, B_, l))) ``` Modal responses for $a_1 \le a$. $$q_{1} = +3.648\cos 0.158a +1.420\sin 0.158a$$ $$q_{2} = +0.318\cos 1.315a -0.014\sin 1.315a$$ $$q_{3} = +0.010\cos 1.779a +0.018\sin 1.779a$$ #### Stitching the two responses We must evaluate numerically the analytical responses ```python ac = a[:,None] q = where(ac<=a1, C*(sin(l0*ac)-l0*sin(li*ac)/li), ABs[:,0]*cos(li*ac) + ABs[:,1]*sin(li*ac)) ``` #### Plotting the Analytical Response First, we zoom around $a_1$ to verify the continuity of displacements and velocities ```python # #### Plot zooming around a1 low, hi = int(0.8*a1*nsppi/pi), int(1.2*a1*nsppi/pi) for i, line in enumerate(plt.plot(a[low:hi]/pi, q[low:hi]), 1): line.set_label('$q_{%d}$'%i) plt.title('Modal Responses, zoom on transition zone') plt.xlabel(r'$\omega_0 t/\pi$') plt.legend(loc='best') plt.show() ``` next, the modal responses over the interval $0 \le a \le 16\pi$ ```python # #### Plot in 0 ≤ a ≤ 16 pi for i, line in enumerate(plt.plot(a/pi, q), 1): line.set_label('$q_{%d}$'%i) plt.title('Modal Responses') plt.xlabel(r'$\omega_0 t/\pi$') plt.legend(loc='best'); plt.xticks() plt.show(); ``` ### Nodal responses ```python x = [email protected] ``` Why `x = [email protected]` rather than `x = Psi@q`? Because for different reasons (mostly, ease of use with the plotting libraries) we have all the response arrays organized in the shape of `(Nsteps × 3)`. That's equivalent to say that `q` and `x`, the Pyton objects, are isomorph to $\boldsymbol q^T$ and $\boldsymbol x^T$ and because it is $$\boldsymbol x^T = (\boldsymbol\Psi \boldsymbol q)^T = \boldsymbol q^T \boldsymbol \Psi^T,$$ in Python to write `x = [email protected]` we have. That said. here are the plot of the nodal responses. Compare with the numerical solutions. ```python for i, line in enumerate(plt.plot(a/pi, x), 1): line.set_label('$x_{%d}/\delta$'%i) plt.title('Normalized Nodal Displacements — analytical solution') plt.xlabel(r'$\omega_0 t / \pi$') plt.legend(loc='best') plt.show(); ```
# frame builder # create series of pngs from plots that can be turned into animations # helpful precursor tools to animation-engine.R # by Jack Hester # generatePNGs <- function(list.of.plots, saveDir=getwd()){ i = 0 sysinf <- Sys.info() for(p in list.of.plots){ # if(sysinf['sysname']=='Windows'){ # name <- paste0(saveDir,'\\frame',i,'.png') # #print(name) # png(name) # print(p) # dev.off() # } # else{ # name <- paste0(saveDir,'/frame',i,'.png') # png(name) # print(p) # dev.off() # } name <- paste0(saveDir,'/frame',i,'.png') png(name) print(p) dev.off() i <- i+1 } rm(name) rm(sysinf) rm(i) }
/* * test_kmeans.cpp * * Created on: 15 juin 2016 * Author: boubad */ #include <boost/test/unit_test.hpp> ///////////////////////// #include <clusterize.h> ///////////////////////////// #include "datafixture.h" #include "global_defs.h" //////////////////// using namespace info; using namespace std; /////////////////////////////////// using MyFixture =InfoDataFixture<IDTYPE, STRINGTYPE, DATATYPE>; using SourceType = typename MyFixture::SourceType; using MatriceDataType = typename MyFixture::MatriceDataType; using strings_vector = typename MyFixture::strings_vector; using pcancelflag = typename MyFixture::pcancelflag; using PBackgrounder =typename MyFixture::PBackgrounder; //////////////////////////////// using ints_sizet_map = std::map<IDTYPE, size_t>; using IndivClusterType = IndivCluster<IDTYPE,STRINGTYPE>; using SourceType = IIndivSource<IDTYPE,STRINGTYPE>; using clusters_vector = std::vector<IndivClusterType>; using ints_vector = std::vector<IDTYPE>; using sizet_intsvector_map = std::map<size_t, ints_vector>; using ClustersCollectionType = ClustersCollection<IDTYPE,STRINGTYPE>; using cancelflag = std::atomic<bool>; using pcancelflag = cancelflag *; using PBackgrounder = Backgrounder *; using ClusterizeResultType = ClusterizeResult<IDTYPE>; using ClusterizeResultPtr = std::shared_ptr< ClusterizeResultType>; using ClusterizeKMeansType = ClusterizeKMeans<IDTYPE,STRINGTYPE,DISTANCETYPE>; ////////////////////////// BOOST_FIXTURE_TEST_SUITE(KMeansTestSuite,MyFixture) BOOST_AUTO_TEST_CASE(testMortalKmeans) { auto infologger = [&](ClusterizeResultPtr oRes) { ClusterizeResultType *p = oRes.get(); if (p != nullptr) { STRINGTYPE sr; p->to_string(sr); BOOST_TEST_MESSAGE(sr); } // p }; SourceType *pProvider = this->mortal_indiv_provider(); BOOST_CHECK(pProvider != nullptr); // pcancelflag pCancel = this->get_cancelflag(); BOOST_CHECK(pCancel != nullptr); PBackgrounder pBack = this->get_backgrounder(); BOOST_CHECK(pBack != nullptr); // ClusterizeKMeansType oMat(pCancel, pBack, infologger); oMat.process(pProvider, 5, 10); } //testMortalKmeans BOOST_AUTO_TEST_SUITE_END();
[STATEMENT] lemma of_int_closed [simp, intro]: "of_int n \<in> A" [PROOF STATE] proof (prove) goal (1 subgoal): 1. of_int n \<in> A [PROOF STEP] by (induction n) auto
[STATEMENT] lemma last_drop_rev: "xs \<noteq> [] \<Longrightarrow> last xs # drop 1 (rev xs) = rev xs" [PROOF STATE] proof (prove) goal (1 subgoal): 1. xs \<noteq> [] \<Longrightarrow> last xs # drop 1 (rev xs) = rev xs [PROOF STEP] by (metis One_nat_def hd_drop_1 hd_rev rev.simps(1) rev_rev_ident)
State Before: R : Type u S : Type v T : Type w a b : R n : ℕ inst✝¹ : CommRing R inst✝ : IsDomain R p q : R[X] L : List R[X] hd : R[X] tl : List R[X] ih : ¬0 ∈ tl → roots (List.prod tl) = Multiset.bind (↑tl) roots H : ¬0 ∈ hd :: tl ⊢ roots (List.prod (hd :: tl)) = Multiset.bind (↑(hd :: tl)) roots State After: R : Type u S : Type v T : Type w a b : R n : ℕ inst✝¹ : CommRing R inst✝ : IsDomain R p q : R[X] L : List R[X] hd : R[X] tl : List R[X] ih : ¬0 ∈ tl → roots (List.prod tl) = Multiset.bind (↑tl) roots H : ¬0 = hd ∧ ¬0 ∈ tl ⊢ roots (List.prod (hd :: tl)) = Multiset.bind (↑(hd :: tl)) roots Tactic: rw [List.mem_cons, not_or] at H State Before: R : Type u S : Type v T : Type w a b : R n : ℕ inst✝¹ : CommRing R inst✝ : IsDomain R p q : R[X] L : List R[X] hd : R[X] tl : List R[X] ih : ¬0 ∈ tl → roots (List.prod tl) = Multiset.bind (↑tl) roots H : ¬0 = hd ∧ ¬0 ∈ tl ⊢ roots (List.prod (hd :: tl)) = Multiset.bind (↑(hd :: tl)) roots State After: no goals Tactic: rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2]
function options = gpnddisimOptions % GPNDDISIMOPTIONS Creates a set of default options for a GPNDDISIM model. % FORMAT % DESC returns a default options stucture for a GPNDDISIM model. % RETURN options : the options structure. % % SEEALSO : gpnddisimCreate % % COPYRIGHT : Neil D. Lawrence, 2006, 2008 % % COPYRIGHT : Pei Gao, 2008 % % COPYRIGHT : Jaakko Peltonen, 2011 % GPNDDISIM options=struct(); options.includeNoise=1; options.addPriors=0; options.optimiser='quasinew'; options.use_disimstartmean=1; options.use_fixedrnavariance=0; options.fix=[];
Formal statement is: lemma tendsto_diff [tendsto_intros]: fixes a b :: "'a::topological_group_add" shows "(f \<longlongrightarrow> a) F \<Longrightarrow> (g \<longlongrightarrow> b) F \<Longrightarrow> ((\<lambda>x. f x - g x) \<longlongrightarrow> a - b) F" Informal statement is: If $f$ and $g$ converge to $a$ and $b$, respectively, then $f - g$ converges to $a - b$.
function [ mO ] = ImageConvFrequencyDomain( mI, mH, convShape ) % ----------------------------------------------------------------------------------------------- % % [ mO ] = ImageConvFrequencyDomain( mI, mH, convShape ) % Applies Image Convolution in the Frequency Domain. % Input: % - mI - Input Image. % Structure: Matrix (numRows x numCols). % Type: 'Single' / 'Double'. % Range: (-inf, inf). % - mH - Filtering Kernel. % Structure: Matrix. % Type: 'Single' / 'Double'. % Range: (-inf, inf). % - convShape - Convolution Shape. % Sets the convolution shape. % Structure: Scalar. % Type: 'Single' / 'Double'. % Range: {1, 2, 3}. % Output: % - mI - Output Image. % Structure: Matrix. % Type: 'Single' / 'Double'. % Range: (-inf, inf). % References: % 1. MATLAB's 'conv2()' - https://www.mathworks.com/help/matlab/ref/conv2.html. % Remarks: % 1. For the transformation the (0, 0) of the image and the kernel is % the top left corner of teh matrix (i = 1, j = 1). Hence it can be % thought that a shifting is needed (To center the kernel). % 1. The function supports single channel image only. % TODO: % 1. % Release Notes: % - 1.0.000 29/04/2021 Royi Avital [email protected] % * First release version. % ----------------------------------------------------------------------------------------------- % CONV_SHAPE_FULL = 1; CONV_SHAPE_SAME = 2; CONV_SHAPE_VALID = 3; numRows = size(mI, 1); numCols = size(mI, 2); numRowsKernel = size(mH, 1); numColsKernel = size(mH, 2); switch(convShape) case(CONV_SHAPE_FULL) numRowsFft = numRows + numRowsKernel - 1; numColsFft = numCols + numColsKernel - 1; firstRowIdx = 1; firstColIdx = 1; lastRowIdx = numRowsFft; lastColdIdx = numColsFft; case(CONV_SHAPE_SAME) numRowsFft = numRows + numRowsKernel; numColsFft = numCols + numColsKernel; firstRowIdx = ceil((numRowsKernel + 1) / 2); firstColIdx = ceil((numColsKernel + 1) / 2); lastRowIdx = firstRowIdx + numRows - 1; lastColdIdx = firstColIdx + numCols - 1; case(CONV_SHAPE_VALID) numRowsFft = numRows; numColsFft = numCols; firstRowIdx = numRowsKernel; firstColIdx = numColsKernel; lastRowIdx = numRowsFft; lastColdIdx = numColsFft; end mO = ifft2(fft2(mI, numRowsFft, numColsFft) .* fft2(mH, numRowsFft, numColsFft), 'symmetric'); mO = mO(firstRowIdx:lastRowIdx, firstColIdx:lastColdIdx); end
Formal statement is: lemma (in ring_of_sets) empty_continuous_imp_countably_additive: fixes f :: "'a set \<Rightarrow> ennreal" assumes f: "positive M f" "additive M f" and fin: "\<forall>A\<in>M. f A \<noteq> \<infinity>" assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> 0" shows "countably_additive M f" Informal statement is: If $f$ is a positive additive function on a ring of sets $M$ such that $f(A) \neq \infty$ for all $A \in M$, and if $f$ is continuous from below, then $f$ is countably additive.
(* File: boolexp.thy *) theory boolexp imports Main begin section{* Basic Type and Evaluation Function for Boolean Expressions *} text{* The following type mirrors the BNF grammar we gave in for boolean expressions. We will use only prefixed connectives here *} datatype 'a boolexp = TRUE | FALSE |Var 'a | Not "'a boolexp" | And "'a boolexp" "'a boolexp" | Or "'a boolexp" "'a boolexp" | Implies "'a boolexp" "'a boolexp" value "TRUE" text{* The following is a recursive definition of the function for evaluating boolean expressions. It is the same as the definition of \textit{models} given in class. *} fun boolexp_eval where "boolexp_eval env TRUE = True" | "boolexp_eval env FALSE = False" | "boolexp_eval env (Var x) = env x" | "boolexp_eval env (Not b) = (\<not> (boolexp_eval env b))" | "boolexp_eval env (And a b) = ((boolexp_eval env a) \<and> (boolexp_eval env b))" | "boolexp_eval env (Or a b) = ((boolexp_eval env a) \<or> (boolexp_eval env b))" | "boolexp_eval env (Implies a b) = ((\<not> (boolexp_eval env a))\<or> (boolexp_eval env b))" text{* Because all our definition have been purely computational, we may use \tettt{value} to evaluate expressions using the type \texttt{boolexp} and the term boolexp_eval. *} (* value "boolexp_eval (\<lambda> x. case x of ''a'' \<Rightarrow> True | _ \<Rightarrow> False) (Implies (Var ''b'') (Var ''a''))" *) value "boolexp_eval (\<lambda> x. case x of (0::nat) \<Rightarrow> True | _ \<Rightarrow> False) (Implies (Var (1::nat)) (Var (0::nat)))" text{* Our objective is to build a function that will tell us all the ways a boolean expression can be satisfied. Our approach is to put the boolean expression in disjunctive normal form. We start by eliminating implies. *} fun remove_implies where "remove_implies TRUE = TRUE" | "remove_implies FALSE = FALSE" | "remove_implies (Var x) = Var x" | "remove_implies (Not a) = Not (remove_implies a)" | "remove_implies (And a b) = And (remove_implies a) (remove_implies b)" | "remove_implies (Or a b) = Or (remove_implies a) (remove_implies b)" | "remove_implies (Implies a b) = (Or (Not (remove_implies a)) (remove_implies b))" thm boolexp.induct lemma remove_implies_same_eval [simp]: "boolexp_eval env (remove_implies a) = boolexp_eval env a" apply (induct "a") by simp_all (* by (induct "a", auto) *) fun number_of_implies where "number_of_implies TRUE = (0::nat)" | "number_of_implies FALSE = 0" | "number_of_implies (Var x) = 0" | "number_of_implies (Not a) = number_of_implies a" | "number_of_implies (And a b) = (number_of_implies a) + (number_of_implies b)" | "number_of_implies (Or a b) = (number_of_implies a) + (number_of_implies b)" | "number_of_implies (Implies a b) = (number_of_implies a) + (number_of_implies b) + 1" lemma number_of_implies_remove_implies_0 [simp]: "number_of_implies (remove_implies a) = 0" by (induct "a", auto) fun push_not where "push_not TRUE = TRUE" | "push_not FALSE = FALSE" | "push_not (Var x) = Var x" | "push_not (Not TRUE) = FALSE" | "push_not (Not FALSE) = TRUE" | "push_not (Not (Var x)) = Not (Var x)" | "push_not (Not (Not a)) = push_not a" | "push_not (Not (And a b)) = (Or (push_not (Not a)) (push_not (Not b)))" | "push_not (Not (Or a b)) = (And (push_not (Not a)) (push_not (Not b)))" | "push_not (Not (Implies a b)) = (And (push_not a) (push_not (Not b)))" | "push_not (And a b) = (And (push_not a) (push_not b))" | "push_not (Or a b) = (Or (push_not a) (push_not b))" | "push_not (Implies a b) = (Implies (push_not a) (push_not b))" lemma push_not_same_eval [simp]: "(boolexp_eval env (push_not (Not a)) = (\<not> (boolexp_eval env (push_not a)))) \<and> (boolexp_eval env (push_not a) = boolexp_eval env a)" by (induct "a", auto) lemma push_not_preserves_no_implies_helper: "number_of_implies a = 0 \<Longrightarrow> (number_of_implies (push_not a) = 0) \<and> (number_of_implies (push_not (Not a)) = 0)" by (induct "a", auto) lemma push_not_preserves_no_implies: "number_of_implies a = 0 \<Longrightarrow> (number_of_implies (push_not a) = 0)" by (auto simp add: push_not_preserves_no_implies_helper) lemma push_not_remove_implies_no_implies [simp]: "number_of_implies (push_not (remove_implies a)) = 0" apply (rule push_not_preserves_no_implies) apply (rule number_of_implies_remove_implies_0) done export_code boolexp_eval push_not remove_implies in OCaml module_name Boolexp file "boolexp.ml" datatype 'a boolexp_no_imp = TRUE_ni | FALSE_ni |Var_ni 'a | Not_ni "'a boolexp_no_imp" | And_ni "'a boolexp_no_imp" "'a boolexp_no_imp" | Or_ni "'a boolexp_no_imp" "'a boolexp_no_imp" fun boolexp_no_imp_eval where "boolexp_no_imp_eval env TRUE_ni = True" | "boolexp_no_imp_eval env FALSE_ni = False" | "boolexp_no_imp_eval env (Var_ni x) = env x" | "boolexp_no_imp_eval env (Not_ni a) = (\<not> (boolexp_no_imp_eval env a))" | "boolexp_no_imp_eval env (And_ni a b) = ((boolexp_no_imp_eval env a) \<and> (boolexp_no_imp_eval env b))" | "boolexp_no_imp_eval env (Or_ni a b) = ((boolexp_no_imp_eval env a) \<or> (boolexp_no_imp_eval env b))" fun remove_implies_ni where "remove_implies_ni TRUE = TRUE_ni" | "remove_implies_ni FALSE = FALSE_ni" | "remove_implies_ni (Var x) = Var_ni x" | "remove_implies_ni (Not a) = Not_ni (remove_implies_ni a)" | "remove_implies_ni (And a b) = And_ni (remove_implies_ni a) (remove_implies_ni b)" | "remove_implies_ni (Or a b) = Or_ni (remove_implies_ni a) (remove_implies_ni b)" | "remove_implies_ni (Implies a b) = (Or_ni (Not_ni (remove_implies_ni a)) (remove_implies_ni b))" lemma remove_implies_ni_same_eval: "boolexp_no_imp_eval env (remove_implies_ni a) = boolexp_eval env (remove_implies a)" by (induct_tac a, auto) datatype 'a boolexp_nipn = TRUE_nipn | FALSE_nipn |Var_nipn 'a | Not_Var_nipn 'a | And_nipn "'a boolexp_nipn" "'a boolexp_nipn" | Or_nipn "'a boolexp_nipn" "'a boolexp_nipn" fun push_not_pn where "push_not_pn TRUE_ni = TRUE_nipn" | "push_not_pn FALSE_ni = FALSE_nipn" | "push_not_pn (Var_ni x) = Var_nipn x" | "push_not_pn (Not_ni TRUE_ni) = FALSE_nipn" | "push_not_pn (Not_ni FALSE_ni) = TRUE_nipn" | "push_not_pn (Not_ni (Var_ni x)) = Not_Var_nipn x" | "push_not_pn (Not_ni (Not_ni a)) = push_not_pn a" | "push_not_pn (Not_ni (And_ni a b)) = (Or_nipn (push_not_pn (Not_ni a)) (push_not_pn (Not_ni b)))" | "push_not_pn (Not_ni (Or_ni a b)) = (And_nipn (push_not_pn (Not_ni a)) (push_not_pn (Not_ni b)))" | "push_not_pn (And_ni a b) = (And_nipn (push_not_pn a) (push_not_pn b))" | "push_not_pn (Or_ni a b) = (Or_nipn (push_not_pn a) (push_not_pn b))" fun boolexp_nipn_eval where "boolexp_nipn_eval env TRUE_nipn = True" | "boolexp_nipn_eval env FALSE_nipn = False" | "boolexp_nipn_eval env (Var_nipn x) = env x" | "boolexp_nipn_eval env (Not_Var_nipn a) = (\<not> (env a))" | "boolexp_nipn_eval env (And_nipn a b) = ((boolexp_nipn_eval env a) \<and> (boolexp_nipn_eval env b))" | "boolexp_nipn_eval env (Or_nipn a b) = ((boolexp_nipn_eval env a) \<or> (boolexp_nipn_eval env b))" lemma push_not_pn_same_eval [simp]: "(boolexp_nipn_eval env (push_not_pn (Not_ni b)) = (\<not> (boolexp_no_imp_eval env b))) \<and> (boolexp_nipn_eval env (push_not_pn b) = boolexp_no_imp_eval env b)" by (induct_tac b, auto) fun node_count where "node_count TRUE = (1::nat)" | "node_count FALSE = 1" | "node_count (Var x) = 1" | "node_count (Not x) = 1 + node_count x" | "node_count (And a b) = 1 + (node_count a) + (node_count b)" | "node_count (Or a b) = 1 + (node_count a) + (node_count b)" | "node_count (Implies a b) = 1 + (node_count a) + (node_count b)" lemma node_count_non_zero [simp]: "0 < node_count b" by (induct_tac b, auto) function push_not_elim_imp where "push_not_elim_imp TRUE = TRUE_nipn" | "push_not_elim_imp FALSE = FALSE_nipn" | "push_not_elim_imp (Var x) = Var_nipn x" | "push_not_elim_imp (Not TRUE) = FALSE_nipn" | "push_not_elim_imp (Not FALSE) = TRUE_nipn" | "push_not_elim_imp (Not (Var x)) = Not_Var_nipn x" | "push_not_elim_imp (Not (Not b)) = push_not_elim_imp b" | "push_not_elim_imp (Not (And a b)) = (Or_nipn (push_not_elim_imp (Not a)) (push_not_elim_imp (Not b)))" | "push_not_elim_imp (Not (Or a b)) = (And_nipn (push_not_elim_imp (Not a)) (push_not_elim_imp (Not b)))" | "push_not_elim_imp (Not (Implies a b)) = (And_nipn (push_not_elim_imp a) (push_not_elim_imp (Not b)))" | "push_not_elim_imp (And a b) = (And_nipn (push_not_elim_imp a) (push_not_elim_imp b))" | "push_not_elim_imp (Or a b) = (Or_nipn (push_not_elim_imp a) (push_not_elim_imp b))" | "push_not_elim_imp (Implies a b) = (Or_nipn (push_not_elim_imp (Not a)) (push_not_elim_imp b))" by (pat_completeness, auto) term "op <*mlex*>" termination by (relation "measures [node_count]", auto) lemma push_not_elim_imp_push_not_pn_remove_implies_ni [simp]: "(push_not_elim_imp (boolexp.Not a) = push_not_pn (Not_ni (remove_implies_ni a))) \<and> (push_not_elim_imp a = push_not_pn (remove_implies_ni a))" by (induct_tac a, auto) lemma push_not_elim_imp_same_eval [simp]: "(boolexp_nipn_eval env (push_not_elim_imp (Not a)) = (\<not>(boolexp_eval env a))) \<and> (boolexp_nipn_eval env (push_not_elim_imp a) = boolexp_eval env a)" by (induct_tac a, auto) datatype 'a bool_atom = TRUE_at | FALSE_at |Var_at 'a | Not_Var_at 'a fun bool_atom_eval where "bool_atom_eval env TRUE_at = True" | "bool_atom_eval env FALSE_at = False" | "bool_atom_eval env (Var_at x) = env x" | "bool_atom_eval env (Not_Var_at x) = (\<not>(env x))" datatype 'a bool_conj = Atom "'a bool_atom" | And_conj "'a bool_atom" "'a bool_conj" fun bool_conj_eval where "bool_conj_eval env (Atom a) = bool_atom_eval env a" | "bool_conj_eval env (And_conj a b) = ((bool_atom_eval env a) \<and> (bool_conj_eval env b))" fun conj_and where "conj_and (Atom a) b = And_conj a b" | "conj_and (And_conj a b) c = And_conj a (conj_and b c)" lemma conj_and_eval [simp]: "bool_conj_eval env (conj_and a b) = ((bool_conj_eval env a) \<and> (bool_conj_eval env b))" by (induct_tac a, auto) datatype 'a bool_dnf = Conj "'a bool_conj" | Or_dnf "'a bool_conj" "'a bool_dnf" fun bool_dnf_eval where "bool_dnf_eval env (Conj c) = bool_conj_eval env c" | "bool_dnf_eval env (Or_dnf a b) = ((bool_conj_eval env a) \<or> (bool_dnf_eval env b))" fun dnf_or where "dnf_or (Conj a) b = Or_dnf a b" | "dnf_or (Or_dnf a b) c = Or_dnf a (dnf_or b c)" lemma dnf_or_eval [simp]: "bool_dnf_eval env (dnf_or a b) = ((bool_dnf_eval env a) \<or> (bool_dnf_eval env b))" by (induct_tac "a", auto) fun conj_or where "conj_or a (Conj b) = Conj (conj_and a b)" | "conj_or a (Or_dnf b c) = Or_dnf(conj_and a b) (conj_or a c)" lemma conj_or_eval [simp]: "bool_dnf_eval env (conj_or a b) = ((bool_conj_eval env a) \<and> (bool_dnf_eval env b))" by (induct_tac "b", auto) fun dist_and_or where "dist_and_or (Conj a) b = conj_or a b" | "dist_and_or (Or_dnf a b) c = dnf_or (conj_or a c) (dist_and_or b c)" lemma dist_and_or_and_eval [simp]: "bool_dnf_eval env (dist_and_or a b) = ((bool_dnf_eval env a) \<and> (bool_dnf_eval env b))" by (induct_tac a, auto) fun basic_dnf where "basic_dnf TRUE_nipn = Conj(Atom TRUE_at)" | "basic_dnf FALSE_nipn = Conj(Atom FALSE_at)" | "basic_dnf (Var_nipn x) = Conj(Atom (Var_at x))" | "basic_dnf (Not_Var_nipn x) = Conj(Atom (Not_Var_at x))" | "basic_dnf (And_nipn a b) = dist_and_or (basic_dnf a) (basic_dnf b)" | "basic_dnf (Or_nipn a b) = dnf_or (basic_dnf a) (basic_dnf b)" lemma basic_dnv_eval [simp]: "bool_dnf_eval env (basic_dnf a) = boolexp_nipn_eval env a" by (induct_tac a, auto) definition dnf where "dnf a = basic_dnf (push_not_elim_imp a)" lemma dnf_eval [simp]: "boolexp_eval env a = bool_dnf_eval env (dnf a)" by (auto simp only: dnf_def push_not_elim_imp_same_eval basic_dnv_eval) fun sat_bool_atom where "sat_bool_atom TRUE_at = Some (None)" | "sat_bool_atom FALSE_at = None" | "sat_bool_atom (Var_at x) = Some(Some(x,True))" | "sat_bool_atom (Not_Var_at x) = Some(Some(x,False))" lemma sat_bool_atom_no_sat [simp]: "sat_bool_atom a = None \<Longrightarrow> \<not>(bool_atom_eval env a)" by (case_tac "a", simp_all) lemma sat_bool_atom_sound [simp]: "\<lbrakk> sat_bool_atom a = Some l; (l = None) \<or> l = Some (y, env y) \<rbrakk> \<Longrightarrow> bool_atom_eval env a" by (induct a, auto) lemma sat_bool_atom_complete [simp]: "bool_atom_eval env a \<Longrightarrow> \<exists> l y. ((sat_bool_atom a = Some l) \<and> ((l = None) \<or> l = Some(y, env y)))" apply (case_tac "sat_bool_atom a", auto) by (induct a, auto) fun member where "member x [] = False" | "member x (y#ys) = ((x = y) \<or> (member x ys))" fun sat_conj where "sat_conj (Atom a) = (case sat_bool_atom a of None \<Rightarrow> None | Some None \<Rightarrow> Some [] | Some (Some (y,t)) \<Rightarrow> Some[(y,t)])" | "sat_conj (And_conj a b) = (case sat_bool_atom a of None \<Rightarrow> None | Some None \<Rightarrow> sat_conj b | Some (Some (y,t)) \<Rightarrow> (case sat_conj b of None \<Rightarrow> None | Some l \<Rightarrow> (if member (y,\<not>t) l then None else if member (y,t) l then Some l else Some ((y,t)#l))))" fun sat_to_env where "sat_to_env [] = {env. True}" | "sat_to_env ((y,b)#l) = {env. env y = b} \<inter> (sat_to_env l)" (* lemma sat_conj_sound: "\<lbrakk> sat_conj a = Some l; env \<in> sat_to_env l \<rbrakk> \<Longrightarrow> bool_conj_eval env a" apply (induct "a", simp_all) apply (case_tac "bool_atom", simp_all) apply auto *) fun sat_dnf where "sat_dnf (Conj a) = (case sat_conj a of None \<Rightarrow> [] | Some l \<Rightarrow> [l])" | "sat_dnf (Or_dnf a b) = (case sat_conj a of None \<Rightarrow> sat_dnf b | Some l => l# (sat_dnf b))" definition sat where "sat a \<equiv> sat_dnf (dnf a)" export_code sat in OCaml module_name Sat file "sat.ml" end
# import copy import pickle from functools import partial import numpy as np import pandas as pd from sklearn.linear_model import LogisticRegression from sklearn.model_selection import KFold, StratifiedKFold from sklearn.neural_network import MLPClassifier from sklearn.tree import DecisionTreeClassifier from hypernets.core import set_random_state, get_random_state from hypernets.core.callbacks import SummaryCallback from hypernets.core.ops import ModuleChoice, HyperInput, ModuleSpace from hypernets.core.search_space import HyperSpace, Choice, Int, Real, Cascade, Constant, HyperNode from hypernets.model import Estimator, HyperModel from hypernets.searchers import make_searcher from hypernets.tabular import get_tool_box from hypernets.utils import fs, logging, const logger = logging.get_logger(__name__) class PlainSearchSpace(object): def __init__(self, enable_dt=True, enable_lr=True, enable_nn=True): assert enable_dt or enable_lr or enable_nn super(PlainSearchSpace, self).__init__() self.enable_dt = enable_dt self.enable_lr = enable_lr self.enable_nn = enable_nn # DecisionTreeClassifier @property def dt(self): return dict( cls=DecisionTreeClassifier, criterion=Choice(["gini", "entropy"]), splitter=Choice(["best", "random"]), max_depth=Choice([None, 3, 5, 10, 20, 50]), random_state=get_random_state(), ) # NN @property def nn(self): solver = Choice(['lbfgs', 'sgd', 'adam']) return dict( cls=MLPClassifier, max_iter=Int(500, 5000, step=500), activation=Choice(['identity', 'logistic', 'tanh', 'relu']), solver=solver, learning_rate=Choice(['constant', 'invscaling', 'adaptive']), learning_rate_init_stub=Cascade(partial(self._cascade, self._nn_learning_rate_init, 'slvr'), slvr=solver), random_state=get_random_state(), ) @staticmethod def _nn_learning_rate_init(slvr): if slvr in ['sgd' or 'adam']: return 'learning_rate_init', Choice([0.001, 0.01]) else: return 'learning_rate_init', Constant(0.001) # LogisticRegression @property def lr(self): iters = [1000] while iters[-1] < 9000: iters.append(int(round(iters[-1] * 1.25, -2))) solver = Choice(['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga']) penalty = Cascade(partial(self._cascade, self._lr_penalty_fn, 'slvr'), slvr=solver) l1_ratio = Cascade(partial(self._cascade, self._lr_l1_ratio, 'penalty'), penalty=penalty) return dict( cls=LogisticRegression, max_iter=Choice(iters), solver=solver, penalty_stub=penalty, l1_ratio_stub=l1_ratio, random_state=get_random_state(), ) @staticmethod def _lr_penalty_fn(slvr): if slvr == 'saga': return 'penalty', Choice(['l2', 'elasticnet', 'l1', 'none']) else: return 'penalty', Constant('l2') @staticmethod def _lr_l1_ratio(penalty): if penalty in ['elasticnet', ]: return 'l1_ratio', Real(0.0, 1.0, step=0.1) else: return 'l1_ratio', Constant(None) # commons @staticmethod def _cascade(fn, key, args, space): with space.as_default(): kvalue = args[key] if isinstance(kvalue, HyperNode): kvalue = kvalue.value return fn(kvalue) # HyperSpace def __call__(self, *args, **kwargs): space = HyperSpace() with space.as_default(): hyper_input = HyperInput(name='input1') estimators = [] if self.enable_dt: estimators.append(self.dt) if self.enable_lr: estimators.append(self.lr) if self.enable_nn: estimators.append(self.nn) modules = [ModuleSpace(name=f'{e["cls"].__name__}', **e) for e in estimators] outputs = ModuleChoice(modules)(hyper_input) space.set_inputs(hyper_input) return space class PlainEstimator(Estimator): def __init__(self, space_sample, task=const.TASK_BINARY, transformer=None): assert task in {const.TASK_BINARY, const.TASK_MULTICLASS, const.TASK_REGRESSION} super(PlainEstimator, self).__init__(space_sample, task) # space, _ = space_sample.compile_and_forward() out = space_sample.get_outputs()[0] kwargs = out.param_values kwargs = {k: v for k, v in kwargs.items() if not isinstance(v, HyperNode)} cls = kwargs.pop('cls') logger.info(f'create estimator {cls.__name__}: {kwargs}') self.model = cls(**kwargs) self.cls = cls self.model_args = kwargs self.transformer = transformer # fitted self.classes_ = None self.cv_models_ = [] def summary(self): pass def fit(self, X, y, **kwargs): eval_set = kwargs.pop('eval_set', None) # ignore if self.transformer is not None: X = self.transformer.fit_transform(X, y) self.model.fit(X, y, **kwargs) self.classes_ = getattr(self.model, 'classes_', None) self.cv_models_ = [] return self def fit_cross_validation(self, X, y, stratified=True, num_folds=3, shuffle=False, random_state=9527, metrics=None, **kwargs): assert num_folds > 0 assert isinstance(metrics, (list, tuple)) eval_set = kwargs.pop('eval_set', None) # ignore if self.transformer is not None: X = self.transformer.fit_transform(X, y) if stratified and self.task == const.TASK_BINARY: iterators = StratifiedKFold(n_splits=num_folds, shuffle=True, random_state=random_state) else: iterators = KFold(n_splits=num_folds, shuffle=True, random_state=random_state) if isinstance(y, (pd.Series, pd.DataFrame)): y = y.values tb = get_tool_box(X, y) oof_ = None oof_scores = [] cv_models = [] for n_fold, (train_idx, valid_idx) in enumerate(iterators.split(X, y)): x_train_fold, y_train_fold = X.iloc[train_idx], y[train_idx] x_val_fold, y_val_fold = X.iloc[valid_idx], y[valid_idx] fold_model = copy.deepcopy(self.model) fold_model.fit(x_train_fold, y_train_fold, **kwargs) # calc fold oof and score if self.task == const.TASK_REGRESSION: proba = fold_model.predict(x_val_fold) preds = proba else: proba = fold_model.predict_proba(x_val_fold) if self.task == const.TASK_BINARY: proba = tb.fix_binary_predict_proba_result(proba) proba_threshold = 0.5 if proba.shape[-1] > 2: # multiclass preds = proba.argmax(axis=-1) else: # binary: preds = (proba[:, 1] > proba_threshold).astype('int32') preds = np.array(fold_model.classes_).take(preds, axis=0) if oof_ is None: if len(proba.shape) == 1: oof_ = np.full(y.shape, np.nan, proba.dtype) else: oof_ = np.full((y.shape[0], proba.shape[-1]), np.nan, proba.dtype) fold_scores = tb.metrics.calc_score(y_val_fold, preds, proba, metrics, task=self.task) # save fold result oof_[valid_idx] = proba oof_scores.append(fold_scores) cv_models.append(fold_model) self.classes_ = getattr(cv_models[0], 'classes_', None) self.cv_models_ = cv_models # calc final score with mean scores = pd.concat([pd.Series(s) for s in oof_scores], axis=1).mean(axis=1).to_dict() logger.info(f'fit_cross_validation score:{scores}, folds score:{oof_scores}') # return return scores, oof_, oof_scores def predict(self, X, **kwargs): eval_set = kwargs.pop('eval_set', None) # ignore if self.transformer is not None: X = self.transformer.transform(X) if self.cv_models_: if self.task == const.TASK_REGRESSION: pred_sum = None for est in self.cv_models_: pred = est.predict(X, **kwargs) if pred_sum is None: pred_sum = pred else: pred_sum += pred preds = pred_sum / len(self.cv_models_) else: proba = self.predict_proba(X, **kwargs) preds = self.proba2predict(proba) preds = np.array(self.classes_).take(preds, axis=0) else: preds = self.model.predict(X, **kwargs) return preds def predict_proba(self, X, **kwargs): eval_set = kwargs.pop('eval_set', None) # ignore if self.transformer is not None: X = self.transformer.transform(X) tb = get_tool_box(X) if self.cv_models_: proba_sum = None for est in self.cv_models_: proba = est.predict_proba(X, **kwargs) if self.task == const.TASK_BINARY: proba = tb.fix_binary_predict_proba_result(proba) if proba_sum is None: proba_sum = proba else: proba_sum += proba proba = proba_sum / len(self.cv_models_) else: proba = self.model.predict_proba(X, **kwargs) if self.task == const.TASK_BINARY: proba = tb.fix_binary_predict_proba_result(proba) return proba def evaluate(self, X, y, metrics=None, **kwargs): if metrics is None: metrics = ['rmse'] if self.task == const.TASK_REGRESSION else ['accuracy'] if self.task == const.TASK_REGRESSION: proba = None preds = self.predict(X, **kwargs) else: proba = self.predict_proba(X, **kwargs) preds = self.proba2predict(proba, proba_threshold=kwargs.get('proba_threshold', 0.5)) scores = get_tool_box(y).metrics.calc_score(y, preds, proba, metrics, self.task) return scores def proba2predict(self, proba, proba_threshold=0.5): if self.task == const.TASK_REGRESSION: return proba if proba.shape[-1] > 2: predict = proba.argmax(axis=-1) elif proba.shape[-1] == 2: predict = (proba[:, 1] > proba_threshold).astype('int32') else: predict = (proba > proba_threshold).astype('int32') return predict def save(self, model_file): with fs.open(model_file, 'wb') as f: pickle.dump(self, f, protocol=4) @staticmethod def load(model_file): with fs.open(model_file, 'rb') as f: return pickle.load(f) def get_iteration_scores(self): return [] class PlainModel(HyperModel): def __init__(self, searcher, dispatcher=None, callbacks=None, reward_metric=None, task=None, discriminator=None, transformer=None): super(PlainModel, self).__init__(searcher, dispatcher=dispatcher, callbacks=callbacks, reward_metric=reward_metric, task=task) self.transformer = transformer def _get_estimator(self, space_sample): if callable(self.transformer): transformer = self.transformer() else: transformer = self.transformer return PlainEstimator(space_sample, task=self.task, transformer=transformer) def load_estimator(self, model_file): return PlainEstimator.load(model_file) def train(X_train, y_train, X_eval, y_eval, task=None, reward_metric=None, optimize_direction='max', **kwargs): if task is None: task, _ = get_tool_box(y_train).infer_task_type(y_train) if reward_metric is None: reward_metric = 'rmse' if task == const.TASK_REGRESSION else 'accuracy' search_space = PlainSearchSpace() searcher = make_searcher('mcts', search_space, optimize_direction=optimize_direction) callbacks = [SummaryCallback()] hm = PlainModel(searcher=searcher, task=task, reward_metric=reward_metric, callbacks=callbacks) hm.search(X_train, y_train, X_eval, y_eval, **kwargs) best = hm.get_best_trial() model = hm.final_train(best.space_sample, X_train, y_train) return hm, model def train_heart_disease(**kwargs): from hypernets.tabular.datasets import dsutils from sklearn.model_selection import train_test_split X = dsutils.load_heart_disease_uci() y = X.pop('target') X_train, X_test, y_train, y_test = \ train_test_split(X, y, test_size=0.3, random_state=get_random_state()) X_train, X_eval, y_train, y_eval = \ train_test_split(X_train, y_train, test_size=0.3, random_state=get_random_state()) kwargs = {'reward_metric': 'auc', 'max_trials': 10, **kwargs} hm, model = train(X_train, y_train, X_eval, y_eval, const.TASK_BINARY, **kwargs) print('-' * 50) scores = model.evaluate(X_test, y_test, metrics=['auc', 'accuracy', 'f1', 'recall', 'precision']) print('scores:', scores) trials = hm.get_top_trials(10) models = [hm.load_estimator(t.model_file) for t in trials] msgs = [f'{t.trial_no},{t.reward},{m.cls.__name__} {m.model_args}' for t, m in zip(trials, models)] print('top trials:') print('\n'.join(msgs)) if __name__ == '__main__': set_random_state(335) train_heart_disease()
Require Import Fiat.Common Fiat.Computation.Core Fiat.ADT.Core Coq.Sets.Ensembles. Section HideADT. Context {extSig : ADTSig}. (* The extended signature *) Context {resConstructorIndex : Type}. (* The restricted set of constructor indices *) Context {resMethodIndex : Type}. (* The restricted set of method indices *) Variable constructorMap : resConstructorIndex -> ConstructorIndex extSig. (* Map from restricted to extended constructor indices *) Variable methodMap : resMethodIndex -> MethodIndex extSig. (* Map from restricted to extended method indices *) Definition resSig := {| ConstructorIndex := resConstructorIndex; MethodIndex := resMethodIndex; ConstructorDom idx := ConstructorDom extSig (constructorMap idx); MethodDomCod idx := MethodDomCod extSig (methodMap idx) |}. (* The signature of the ADT with restricted constructor and method indices *) Definition HideADT (extADT : ADT extSig) : ADT resSig := match extADT with {| Rep := rep; Constructors := extConstructors; Methods := extMethods |} => Build_ADT resSig (fun idx => extConstructors (constructorMap idx)) (fun idx => extMethods (methodMap idx)) end. End HideADT.
/- Copyright (c) 2021 Ashwin Iyengar. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Johan Commelin, Ashwin Iyengar, Patrick Massot -/ import group_theory.subgroup.basic import topology.algebra.open_subgroup import topology.algebra.ring.basic /-! # Nonarchimedean Topology > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we set up the theory of nonarchimedean topological groups and rings. A nonarchimedean group is a topological group whose topology admits a basis of open neighborhoods of the identity element in the group consisting of open subgroups. A nonarchimedean ring is a topological ring whose underlying topological (additive) group is nonarchimedean. ## Definitions - `nonarchimedean_add_group`: nonarchimedean additive group. - `nonarchimedean_group`: nonarchimedean multiplicative group. - `nonarchimedean_ring`: nonarchimedean ring. -/ open_locale pointwise /-- An topological additive group is nonarchimedean if every neighborhood of 0 contains an open subgroup. -/ class nonarchimedean_add_group (G : Type*) [add_group G] [topological_space G] extends topological_add_group G : Prop := (is_nonarchimedean : ∀ U ∈ nhds (0 : G), ∃ V : open_add_subgroup G, (V : set G) ⊆ U) /-- A topological group is nonarchimedean if every neighborhood of 1 contains an open subgroup. -/ @[to_additive] class nonarchimedean_group (G : Type*) [group G] [topological_space G] extends topological_group G : Prop := (is_nonarchimedean : ∀ U ∈ nhds (1 : G), ∃ V : open_subgroup G, (V : set G) ⊆ U) /-- An topological ring is nonarchimedean if its underlying topological additive group is nonarchimedean. -/ class nonarchimedean_ring (R : Type*) [ring R] [topological_space R] extends topological_ring R : Prop := (is_nonarchimedean : ∀ U ∈ nhds (0 : R), ∃ V : open_add_subgroup R, (V : set R) ⊆ U) /-- Every nonarchimedean ring is naturally a nonarchimedean additive group. -/ @[priority 100] -- see Note [lower instance priority] instance nonarchimedean_ring.to_nonarchimedean_add_group (R : Type*) [ring R] [topological_space R] [t: nonarchimedean_ring R] : nonarchimedean_add_group R := {..t} namespace nonarchimedean_group variables {G : Type*} [group G] [topological_space G] [nonarchimedean_group G] variables {H : Type*} [group H] [topological_space H] [topological_group H] variables {K : Type*} [group K] [topological_space K] [nonarchimedean_group K] /-- If a topological group embeds into a nonarchimedean group, then it is nonarchimedean. -/ @[to_additive nonarchimedean_add_group.nonarchimedean_of_emb "If a topological group embeds into a nonarchimedean group, then it is nonarchimedean."] lemma nonarchimedean_of_emb (f : G →* H) (emb : open_embedding f) : nonarchimedean_group H := { is_nonarchimedean := λ U hU, have h₁ : (f ⁻¹' U) ∈ nhds (1 : G), from by {apply emb.continuous.tendsto, rwa f.map_one}, let ⟨V, hV⟩ := is_nonarchimedean (f ⁻¹' U) h₁ in ⟨{is_open' := emb.is_open_map _ V.is_open, ..subgroup.map f V}, set.image_subset_iff.2 hV⟩ } /-- An open neighborhood of the identity in the cartesian product of two nonarchimedean groups contains the cartesian product of an open neighborhood in each group. -/ @[to_additive nonarchimedean_add_group.prod_subset "An open neighborhood of the identity in the cartesian product of two nonarchimedean groups contains the cartesian product of an open neighborhood in each group."] lemma prod_subset {U} (hU : U ∈ nhds (1 : G × K)) : ∃ (V : open_subgroup G) (W : open_subgroup K), (V : set G) ×ˢ (W : set K) ⊆ U := begin erw [nhds_prod_eq, filter.mem_prod_iff] at hU, rcases hU with ⟨U₁, hU₁, U₂, hU₂, h⟩, cases is_nonarchimedean _ hU₁ with V hV, cases is_nonarchimedean _ hU₂ with W hW, use V, use W, rw set.prod_subset_iff, intros x hX y hY, exact set.subset.trans (set.prod_mono hV hW) h (set.mem_sep hX hY), end /-- An open neighborhood of the identity in the cartesian square of a nonarchimedean group contains the cartesian square of an open neighborhood in the group. -/ @[to_additive nonarchimedean_add_group.prod_self_subset "An open neighborhood of the identity in the cartesian square of a nonarchimedean group contains the cartesian square of an open neighborhood in the group."] lemma prod_self_subset {U} (hU : U ∈ nhds (1 : G × G)) : ∃ (V : open_subgroup G), (V : set G) ×ˢ (V : set G) ⊆ U := let ⟨V, W, h⟩ := prod_subset hU in ⟨V ⊓ W, by {refine set.subset.trans (set.prod_mono _ _) ‹_›; simp}⟩ /-- The cartesian product of two nonarchimedean groups is nonarchimedean. -/ @[to_additive "The cartesian product of two nonarchimedean groups is nonarchimedean."] instance : nonarchimedean_group (G × K) := { is_nonarchimedean := λ U hU, let ⟨V, W, h⟩ := prod_subset hU in ⟨V.prod W, ‹_›⟩ } end nonarchimedean_group namespace nonarchimedean_ring open nonarchimedean_ring open nonarchimedean_add_group variables {R S : Type*} variables [ring R] [topological_space R] [nonarchimedean_ring R] variables [ring S] [topological_space S] [nonarchimedean_ring S] /-- The cartesian product of two nonarchimedean rings is nonarchimedean. -/ instance : nonarchimedean_ring (R × S) := { is_nonarchimedean := nonarchimedean_add_group.is_nonarchimedean } /-- Given an open subgroup `U` and an element `r` of a nonarchimedean ring, there is an open subgroup `V` such that `r • V` is contained in `U`. -/ lemma left_mul_subset (U : open_add_subgroup R) (r : R) : ∃ V : open_add_subgroup R, r • (V : set R) ⊆ U := ⟨U.comap (add_monoid_hom.mul_left r) (continuous_mul_left r), (U : set R).image_preimage_subset _⟩ /-- An open subgroup of a nonarchimedean ring contains the square of another one. -/ lemma mul_subset (U : open_add_subgroup R) : ∃ V : open_add_subgroup R, (V : set R) * V ⊆ U := let ⟨V, H⟩ := prod_self_subset (is_open.mem_nhds (is_open.preimage continuous_mul U.is_open) begin simpa only [set.mem_preimage, set_like.mem_coe, prod.snd_zero, mul_zero] using U.zero_mem, end) in begin use V, rintros v ⟨a, b, ha, hb, hv⟩, have hy := H (set.mk_mem_prod ha hb), simp only [set.mem_preimage, set_like.mem_coe] at hy, rwa hv at hy end end nonarchimedean_ring
[STATEMENT] lemma add_block_sub_sys: "sub_incidence_system \<V> \<B> (\<V> \<union> b) (add_block b)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. sub_incidence_system \<V> \<B> (\<V> \<union> b) (add_block b) [PROOF STEP] using add_block_wf wf_invalid_point add_block_def [PROOF STATE] proof (prove) using this: incidence_system (\<V> \<union> ?b) (add_block ?b) \<lbrakk>?x \<notin> \<V>; ?b \<in># \<B>\<rbrakk> \<Longrightarrow> ?x \<notin> ?b add_block ?b \<equiv> \<B> + {#?b#} goal (1 subgoal): 1. sub_incidence_system \<V> \<B> (\<V> \<union> b) (add_block b) [PROOF STEP] by (unfold_locales) (auto)
lemma uncountable_closed_segment: fixes a :: "'a::real_normed_vector" assumes "a \<noteq> b" shows "uncountable (closed_segment a b)"
C Copyright(C) 1999-2020 National Technology & Engineering Solutions C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with C NTESS, the U.S. Government retains certain rights in this software. C C See packages/seacas/LICENSE for details C======================================================================= SUBROUTINE SPMAIN (A, NEUTRL, NAMES, NPTIMS, IPTIMS, * TIMES, NENUM, & XN, YN, ZN, XE, YE, ZE, & IE2ELB, ISEVOK, LIDSP, BLKCOL, IDELB, * MAPEL, MAPND) C======================================================================= C --*** SPMAIN *** (SPLOT) SPLOT main plot routine C -- Modified by John Glick - 11/9/88 C -- Written by Amy Gilkey - revised 03/07/88 C -- C --SPMAIN calculates the distances, reads the variables, and displays C --the distance-versus-variable plots. C -- C --Parameters: C -- A - IN - the dynamic memory base array C -- NEUTRL - IN - the type of neutral file to write. C -- NAMES - IN - the variable names C -- NPTIMS - IN - the number of selected time steps C -- IPTIMS - IN - the selected time steps C -- TIMES - IN - the database times C -- NENUM - IN - the selected node/element numbers C -- XN,YN,ZN - IN - the nodal mesh coordinates C -- XE,YE,ZE - IN - the element centroid mesh coordinates C -- IE2ELB - IN - the element block for each element C -- ISEVOK - IN - the element block variable truth table; C -- variable i of block j exists iff ISEVOK(j,i) C -- LIDSP(0:*) - IN - the indices of the selected variables C -- whose values will be displayed on the plot legend. C -- LIDSP(0) = the number of variables in the list. C -- LIDSP(i) identifies the ith variable in the list. C -- LIDSP(i) > 0, LIDSP(i) is the id of a history var. C -- LIDSP(i) < 0, -LIDSP(i) is the id of a global var. C -- LIDSP(i) = 0, TIME is displayed on the plot legend. C -- BLKCOL - I/O - the user selected colors of the element blocks. C -- BLKCOL(0) = 1 if the user defined material C -- colors should be used in mesh plots. C -- = -1 if program selected colors should C -- be used. C -- BLKCOL(i) = the user selected color of element C -- block i: C -- -2 - no color selected by user. C -- -1 - black C -- 0 - white C -- 1 - red C -- 2 - green C -- 3 - yellow C -- 4 - blue C -- 5 - cyan C -- 6 - magenta C -- C --Common Variables: C -- Uses NNENUM of /SELNE/ C -- Uses NSPVAR of /SPVARS/ include 'params.blk' PARAMETER (KLFT=1, KRGT=2, KBOT=3, KTOP=4) include 'dbnums.blk' include 'selne.blk' include 'spvars.blk' DIMENSION A(*) CHARACTER*(*) NAMES(*) INTEGER IPTIMS(NPTIMS) REAL TIMES(*) INTEGER NENUM(NNENUM) REAL XN(*), YN(*), ZN(*) REAL XE(*), YE(*), ZE(*) INTEGER IE2ELB(*) LOGICAL ISEVOK(*) INTEGER LIDSP(0:*) INTEGER BLKCOL(0:NELBLK) INTEGER IDELB(*) INTEGER MAPEL(*), MAPND(*) C --Use the selected color table CALL GRCOLU ('ALTERNATE') C --Reserve storage for plot variables LPLVAL = NNENUM * NSPVAR * NPTIMS CALL MDRSRV ('PLTVAL', KPLVAL, LPLVAL) CALL MDSTAT (NERR, MEM) IF (NERR .GT. 0) GOTO 100 C --Read plot variables CALL SPREAD (A, NPTIMS, IPTIMS, NENUM, A(KPLVAL)) CALL MDSTAT (NERR, MEM) IF (NERR .GT. 0) GOTO 100 C --Identify and index element variables with undefined values CALL MDRSRV ('IXSEGV', KXSEGV, NSPVAR) CALL MDSTAT (NERR, MEM) IF (NERR .GT. 0) GOTO 100 CALL SPDSEG (A, NENUM, IE2ELB, ISEVOK, & NSEGV, A(KXSEGV), KSEGEL) CALL MDSTAT (NERR, MEM) IF (NERR .GT. 0) GOTO 100 C --Calculate distances CALL MDRSRV ('DIST', KDIST, NNENUM) CALL MDSTAT (NERR, MEM) IF (NERR .GT. 0) GOTO 100 IF (NODVAR) THEN CALL CALDIS (NNENUM, NENUM, XN, YN, ZN, A(KDIST)) ELSE CALL CALDIS (NNENUM, NENUM, XE, YE, ZE, A(KDIST)) END IF C --Plot requested curves IF (NSEGV .GT. 0) THEN CALL MDRSRV ('XDIST', KXDIST, NNENUM) CALL MDSTAT (NERR, MEM) IF (NERR .GT. 0) GOTO 100 END IF CALL SPPLOT (A, NEUTRL, NPTIMS, IPTIMS, TIMES, NENUM, & A(KDIST), A(KPLVAL), NAMES, & A(KXSEGV), A(KSEGEL), A(KXDIST), LIDSP, BLKCOL, * MAPEL, MAPND) CALL MDDEL ('PLTVAL') CALL MDDEL ('DIST') IF (NSEGV .GT. 0) THEN CALL MDDEL ('XDIST') END IF CALL MDDEL ('IXSEGV') IF (NSEGV .GT. 0) THEN CALL MDDEL ('ISEGEL') END IF 100 CONTINUE RETURN END
(** 挿入ソートの証明駆動開発 *) (** * はじめに *) (** 挿入ソート (Insertion Sort) を Coq の 「Programコマンド」を使って証明駆動開発してみます。 プログラムの定義や検証の方法は以下のサイトに基づいていますから、併読してください。 ただし、証明そのものは少し違うところがあります。 #<a href="http://www.iij-ii.co.jp/lab/techdoc/coqt/coqt8.html"> プログラミング Coq 証明駆動開発入門(1) </a># *) (** ソースコードは、 #<a href="https://github.com/suharahiromichi/coq/blob/master/prog/coq_isort_prog2.v"> ここ </a> にあります。 *) Require Import List. Require Import Arith. Require Import Sorting.Permutation. Require Import Sorting.Sorted. Require Import Program. (** * 準備 *) (** 証明に perm と sort のコンストラクタを使いますから、 これらをHintデータベースに追加します。 *) Hint Resolve perm_nil perm_skip perm_swap perm_trans Permutation_cons : perm. Hint Resolve LSorted_nil LSorted_cons1 LSorted_consn : sort. (** さらに不等号についての補題 [n < m -> n <= m] をHintデータベースに追加します。*) Hint Resolve lt_le_weak : lt_le. (** * insert の定義と証明 *) (** 最初に挿入関数 [insert] を証明付きで定義します。 定義自体は最初の参考文献とおなじです。 この関数では、リスト [l] に [a] を挿入した結果が関数の値 [l'] になるので、 これらをソートのために使う場合は次の関係を満たす必要があります。 (1) [a] と [l] を結合(cons)したものと、[l'] が Permutation の関係にあること。 (2) [l] がソートされているなら、[l'] もソートされていること。 のふたつです。これに加えて (3) [a] と リスト [l] と [l'] との関係として、 (3.1) [a] は [l'] の先頭である([a]が[l]の先頭に置かれる場合)、または、 (3.2) [l] と [l'] の先頭が同じ([a]が[l]の途中以降に挿入される場合) を追加しておきます。以上を連言でつないでいます。 それを関数の値に記載して、証明することになります。 関数の定義では、サブタイプコアーションが働くので、insert の再帰呼び出しでは、 証明の部分を無視して、リストだけを返す関数として使うことができます。 *) Program Fixpoint insert (a : nat) (l : list nat) {struct l} : {l' : list nat | Permutation (a :: l) l' /\ (LocallySorted le l -> LocallySorted le l') /\ (hd a l' = a \/ hd a l' = hd a l)} := match l with | nil => a :: nil | x :: l' => if le_gt_dec a x then a :: x :: l' else x :: (insert a l') end. Obligation 1. Proof. now auto with sort. Defined. Obligation 2. now auto with sort. Defined. Obligation 3. Proof. split. - rewrite perm_swap. now auto with perm. - split. + intros Hxl'. assert (LocallySorted le l') as H1 by (inversion Hxl'; auto with sort). assert (LocallySorted le x0) as H2 by auto. destruct x0. * now auto with sort. * inversion Hxl'; simpl in o; destruct o; subst; now auto with sort lt_le. + now auto. Defined. (** rewrite では、通常の [=] ではなく、 Permutation に対する rewrite が行われていることに注意してください。 ゴール [Permutation (a :: x :: l') (x :: x0)] に対して、 [[ perm_swap : forall (A : Type) (x y : A) (l : list A), Permutation (y :: x :: l) (x :: y :: l) ]] でrewriteすることで、ゴールのPermutationの左側が書き換えられ、 [Permutation (x :: a :: l') (x :: x0)] が得られます。 それができるのは、Import している [Sorting/Permutation.v] のなかで、 [Instance Permutation_Equivalence] が定義されているからですが、 このあたりについては、 #<a href="http://www.labri.fr/perso/casteran/CoqArt/TypeClassesTut/typeclassestut.pdf"> A Gentle Introduction to Type Classes and Relations in Coq </a># を参照してください。 *) (** また、[auto with sort lt_le] では、 [apply LSorted_consn] と [apply lt_le] が実行されています。 *) (** 実行してみます。証明の部分を取り除いて値だけを取り出すために、 [proj1_sig] の演算子 [`] を使います。 *) Compute ` (insert 1 [2; 3]). (** ==> [[1; 2; 3]] *) Compute ` (insert 2 [1; 3]). (** ==> [[1; 2; 3]] *) (** OCaml のコードを生成してみます。証明の部分のコードは含まれていません。 *) Extraction insert. (** [[ val insert : nat -> nat list -> nat list let rec insert a = function | Nil -> Cons (a, Nil) | Cons (x, l') -> (match le_gt_dec a x with | Left -> Cons (a, (Cons (x, l'))) | Right -> Cons (x, (insert a l'))) ]] *) (** * Insertion Sort の定義と証明 *) (** 最後にソート関数 isort を証明付きで定義します。 定義自体は最初の参考文献とおなじです。 また、その正しさの証明も同じで、ソート前の引数 [l] と、ソート結果の関数値 [l'] に対して、 (1) [l] と [l'] が Permutation の関係であること。 (2) [l'] がソートされていること。 のふたつで、それらを連言でつないでいます。 それを関数の値に記載して、証明することになります。 関数の定義では、サブタイプコアーションが働くので、isort の再帰呼び出しのみならず、 下位処理として呼び出す insert もリストだけを返す関数として使うことができます。 *) Program Fixpoint isort l {struct l} : {l' : list nat | Permutation l l' /\ LocallySorted le l'} := match l with | nil => nil | a :: l' => insert a (isort l') end. Obligations. Obligation 1. Proof. now auto with sort perm. Defined. Obligation 2. Proof. remember (insert a x). destruct s; subst. destruct a0; subst. simpl. split. - eauto with perm. - destruct a0; now auto. Defined. (** 実行してみます。証明の部分を取り除いて値だけを取り出すために、 [proj1_sig] の演算子 [`] を使います。 *) Compute ` (isort [0; 2; 1; 3]). (** ==> [[0; 1; 2; 3]] *) (** OCaml のコードを生成してみます。証明の部分のコードは含まれていません。 *) Extraction isort. (** [[ val isort : nat list -> nat list let rec isort = function | Nil -> Nil | Cons (a, l') -> insert a (isort l') ]] *) (* END *)
C @(#)get_otrpt9.f 20.5 1/7/99 C**************************************************************** C C File: get_otrpt9.f C Purpose: Routine to generate area interchange output C reports using IPF command C C / REPORTS, SELECT AI_SUMMARY C WHERE BUS = "<busname>" C (END) C C Author: Walt Powell Date: 14 July 1994 C Modified: 14 July 1994 C Called by: C C**************************************************************** C subroutine get_otrpt9 (scrfil) integer scrfil include 'ipfinc/parametr.inc' include 'ipfinc/lfiles.inc' include 'ipfinc/blank.inc' include 'ipfinc/bus.inc' include 'ipfinc/sortuvov.inc' character in_buffer*(MAXBUFFER), out_buffer*(MAXBUFFER), & null*1, linefeed*1, header(4)*132, capital*1, & text*2, temp*10 integer apdoutbuf, o1, o2, findstr, status, areaintrtp logical change_v, change_f, load_fltr, finished, no_more null = char(0) linefeed = char(10) linespage = 22 call getenvir ('NO_MORE', temp) no_more = (temp(1:7) .eq. 'NO_MORE') change_f = .true. ! Change filters do while (change_f) in_buffer(1:1) = null i1 = index (in_buffer, null) length = apdoutbuf(i1, '/REPORTS, SELECT AI_SUMMARY ', & in_buffer(i1:)) i1 = i1 + length change_f = load_fltr(in_buffer, out_buffer, i1) if (change_f) then out_buffer(1:1) = null ix = findstr (in_buffer, 'AI_SUMMARY') & + lastch ('AI_SUMMARY') status = areaintrpt(in_buffer(ix:), out_buffer, scrfil) o1 = 1 do i = 1, 3 o2 = nxt_term(out_buffer(o1+1:)) + o1 header(i) = out_buffer(o1:o2-1) o1 = o2 if (out_buffer(o1:o1) .eq. linefeed) o1 = o1 + 1 enddo o1 = 1 numlin = 1 finished = .false. do while (.not. finished) do while (o1 .lt. MAXBUFFER .and. & out_buffer(o1:o1) .ne. null) o2 = nxt_term(out_buffer(o1+1:)) + o1 if (out_buffer(o1:o1) .eq. '/') then o2 = MAXBUFFER + 1 else if (out_buffer(o1:o1+6) .eq. '*[MORE]' .and. & .not. no_more) then in_buffer(1:1) = null i1 = index (in_buffer, null) length = apdoutbuf(i1, & '/REPORTS, SELECT AI_SUMMARY CONTNIUE ', & in_buffer(i1:)) i1 = i1 + length out_buffer(1:1) = null status = areaintrpt(in_buffer(ix:), & out_buffer, scrfil) o1 = 1 do i = 1, 43 o2 = nxt_term(out_buffer(o1+1:)) + o1 o1 = o2 if (out_buffer(o1:o1) .eq. linefeed) & o1 = o1 + 1 enddo o2 = nxt_term(out_buffer(o1+1:)) + o1 endif if (no_more) then finished = .true. go to 130 else if (numlin .ge. linespage+1) then numlin = 0 write(*, 100) 100 format (' --More-- ') read (*, 120) text(1:1) 120 format (a) text(1:1) = capital (text(1:1)) if (text(1:1) .eq. 'Q') then finished = .true. go to 130 endif do i = 1, 3 write (*, 110) header(i) numlin = numlin + 1 enddo endif numlin = numlin + 1 write (*, 110) out_buffer(o1:o2-1) 110 format (1x, a) endif o1 = o2 if (out_buffer(o1:o1) .eq. linefeed) o1 = o1 + 1 enddo 130 finished = .true. enddo endif enddo return end
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro ! This file was ported from Lean 3 source module algebra.module.submodule.basic ! leanprover-community/mathlib commit fac369018417f980cec5fcdafc766a69f88d8cfe ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.Algebra.Module.LinearMap import Mathbin.Algebra.Module.Equiv import Mathbin.GroupTheory.GroupAction.SubMulAction import Mathbin.GroupTheory.Submonoid.Membership /-! # Submodules of a module > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define * `submodule R M` : a subset of a `module` `M` that contains zero and is closed with respect to addition and scalar multiplication. * `subspace k M` : an abbreviation for `submodule` assuming that `k` is a `field`. ## Tags submodule, subspace, linear map -/ open Function open BigOperators universe u'' u' u v w variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w} #print SubmoduleClass /- /-- `submodule_class S R M` says `S` is a type of submodules `s ≤ M`. Note that only `R` is marked as `out_param` since `M` is already supplied by the `set_like` class. -/ class SubmoduleClass (S : Type _) (R : outParam <| Type _) (M : Type _) [AddZeroClass M] [SMul R M] [SetLike S M] [AddSubmonoidClass S M] extends SMulMemClass S R M #align submodule_class SubmoduleClass -/ #print Submodule /- /-- A submodule of a module is one which is closed under vector operations. This is a sufficient condition for the subset of vectors in the submodule to themselves form a module. -/ structure Submodule (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] [Module R M] extends AddSubmonoid M, SubMulAction R M : Type v #align submodule Submodule -/ /-- Reinterpret a `submodule` as an `add_submonoid`. -/ add_decl_doc Submodule.toAddSubmonoid /-- Reinterpret a `submodule` as an `sub_mul_action`. -/ add_decl_doc Submodule.toSubMulAction namespace Submodule variable [Semiring R] [AddCommMonoid M] [Module R M] instance : SetLike (Submodule R M) M where coe := Submodule.carrier coe_injective' p q h := by cases p <;> cases q <;> congr instance : AddSubmonoidClass (Submodule R M) M where zero_mem := zero_mem' add_mem := add_mem' instance : SubmoduleClass (Submodule R M) R M where smul_mem := smul_mem' /- warning: submodule.mem_to_add_submonoid -> Submodule.mem_toAddSubmonoid is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] (p : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (x : M), Iff (Membership.Mem.{u2, u2} M (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SetLike.hasMem.{u2, u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) M (AddSubmonoid.setLike.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) x (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 p)) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)) x p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] (p : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (x : M), Iff (Membership.mem.{u2, u2} M (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SetLike.instMembership.{u2, u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) M (AddSubmonoid.instSetLikeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) x (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 p)) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)) x p) Case conversion may be inaccurate. Consider using '#align submodule.mem_to_add_submonoid Submodule.mem_toAddSubmonoidₓ'. -/ @[simp] theorem mem_toAddSubmonoid (p : Submodule R M) (x : M) : x ∈ p.toAddSubmonoid ↔ x ∈ p := Iff.rfl #align submodule.mem_to_add_submonoid Submodule.mem_toAddSubmonoid variable {p q : Submodule R M} /- warning: submodule.mem_mk -> Submodule.mem_mk is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {S : Set.{u2} M} {x : M} (h₁ : forall {a : M} {b : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) a S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) b S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) a b) S)) (h₂ : Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) S) (h₃ : forall (c : R) {x : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (SMul.smul.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) c x) S)), Iff (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)) x (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S h₁ h₂ h₃)) (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x S) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {S : AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))} {x : M} (h₁ : forall (a : R) {b : M}, (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) b (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S))) -> (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) (HSMul.hSMul.{u1, u2, u2} R M M (instHSMul.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) a b) (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S)))), Iff (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)) x (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S h₁)) (Membership.mem.{u2, u2} M (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SetLike.instMembership.{u2, u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) M (AddSubmonoid.instSetLikeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) x S) Case conversion may be inaccurate. Consider using '#align submodule.mem_mk Submodule.mem_mkₓ'. -/ @[simp] theorem mem_mk {S : Set M} {x : M} (h₁ h₂ h₃) : x ∈ (⟨S, h₁, h₂, h₃⟩ : Submodule R M) ↔ x ∈ S := Iff.rfl #align submodule.mem_mk Submodule.mem_mk /- warning: submodule.coe_set_mk -> Submodule.coe_set_mk is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] (S : Set.{u2} M) (h₁ : forall {a : M} {b : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) a S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) b S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) a b) S)) (h₂ : Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) S) (h₃ : forall (c : R) {x : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (SMul.smul.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) c x) S)), Eq.{succ u2} (Set.{u2} M) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Set.{u2} M) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Set.{u2} M) (CoeTCₓ.coe.{succ u2, succ u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Set.{u2} M) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S h₁ h₂ h₃)) S but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] (S : AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (h₁ : forall (a : R) {b : M}, (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) b (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S))) -> (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) (HSMul.hSMul.{u1, u2, u2} R M M (instHSMul.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) a b) (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S)))), Eq.{succ u2} (Set.{u2} M) (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S h₁)) (SetLike.coe.{u2, u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) M (AddSubmonoid.instSetLikeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) S) Case conversion may be inaccurate. Consider using '#align submodule.coe_set_mk Submodule.coe_set_mkₓ'. -/ @[simp] theorem coe_set_mk (S : Set M) (h₁ h₂ h₃) : ((⟨S, h₁, h₂, h₃⟩ : Submodule R M) : Set M) = S := rfl #align submodule.coe_set_mk Submodule.coe_set_mk /- warning: submodule.mk_le_mk -> Submodule.mk_le_mk is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {S : Set.{u2} M} {S' : Set.{u2} M} (h₁ : forall {a : M} {b : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) a S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) b S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) a b) S)) (h₂ : Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) S) (h₃ : forall (c : R) {x : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x S) -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (SMul.smul.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) c x) S)) (h₁' : forall {a : M} {b : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) a S') -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) b S') -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) a b) S')) (h₂' : Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) S') (h₃' : forall (c : R) {x : M}, (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x S') -> (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) (SMul.smul.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) c x) S')), Iff (LE.le.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S h₁ h₂ h₃) (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S' h₁' h₂' h₃')) (HasSubset.Subset.{u2} (Set.{u2} M) (Set.hasSubset.{u2} M) S S') but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {S : AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))} {S' : AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))} (h₁ : forall (a : R) {b : M}, (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) b (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S))) -> (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) (HSMul.hSMul.{u1, u2, u2} R M M (instHSMul.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) a b) (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S)))) (h₂ : forall (c : R) {x : M}, (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S'))) -> (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) (HSMul.hSMul.{u1, u2, u2} R M M (instHSMul.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) c x) (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) S')))), Iff (LE.le.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S h₁) (Submodule.mk.{u1, u2} R M _inst_1 _inst_2 _inst_3 S' h₂)) (LE.le.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Preorder.toLE.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.instCompleteLatticeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))) S S') Case conversion may be inaccurate. Consider using '#align submodule.mk_le_mk Submodule.mk_le_mkₓ'. -/ @[simp] theorem mk_le_mk {S S' : Set M} (h₁ h₂ h₃ h₁' h₂' h₃') : (⟨S, h₁, h₂, h₃⟩ : Submodule R M) ≤ (⟨S', h₁', h₂', h₃'⟩ : Submodule R M) ↔ S ⊆ S' := Iff.rfl #align submodule.mk_le_mk Submodule.mk_le_mk #print Submodule.ext /- @[ext] theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h #align submodule.ext Submodule.ext -/ #print Submodule.copy /- /-- Copy of a submodule with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : Submodule R M) (s : Set M) (hs : s = ↑p) : Submodule R M where carrier := s zero_mem' := hs.symm ▸ p.zero_mem' add_mem' _ _ := hs.symm ▸ p.add_mem' smul_mem' := hs.symm ▸ p.smul_mem' #align submodule.copy Submodule.copy -/ #print Submodule.coe_copy /- @[simp] theorem coe_copy (S : Submodule R M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s := rfl #align submodule.coe_copy Submodule.coe_copy -/ #print Submodule.copy_eq /- theorem copy_eq (S : Submodule R M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align submodule.copy_eq Submodule.copy_eq -/ #print Submodule.toAddSubmonoid_injective /- theorem toAddSubmonoid_injective : Injective (toAddSubmonoid : Submodule R M → AddSubmonoid M) := fun p q h => SetLike.ext'_iff.2 (show _ from SetLike.ext'_iff.1 h) #align submodule.to_add_submonoid_injective Submodule.toAddSubmonoid_injective -/ #print Submodule.toAddSubmonoid_eq /- @[simp] theorem toAddSubmonoid_eq : p.toAddSubmonoid = q.toAddSubmonoid ↔ p = q := toAddSubmonoid_injective.eq_iff #align submodule.to_add_submonoid_eq Submodule.toAddSubmonoid_eq -/ /- warning: submodule.to_add_submonoid_strict_mono -> Submodule.toAddSubmonoid_strictMono is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], StrictMono.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.completeLattice.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], StrictMono.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.instCompleteLatticeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3) Case conversion may be inaccurate. Consider using '#align submodule.to_add_submonoid_strict_mono Submodule.toAddSubmonoid_strictMonoₓ'. -/ @[mono] theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : Submodule R M → AddSubmonoid M) := fun _ _ => id #align submodule.to_add_submonoid_strict_mono Submodule.toAddSubmonoid_strictMono /- warning: submodule.to_add_submonoid_le -> Submodule.toAddSubmonoid_le is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {p : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3} {q : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3}, Iff (LE.le.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Preorder.toLE.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.completeLattice.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 p) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 q)) (LE.le.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) p q) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {p : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3} {q : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3}, Iff (LE.le.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Preorder.toLE.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.instCompleteLatticeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 p) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 q)) (LE.le.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Preorder.toLE.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) p q) Case conversion may be inaccurate. Consider using '#align submodule.to_add_submonoid_le Submodule.toAddSubmonoid_leₓ'. -/ theorem toAddSubmonoid_le : p.toAddSubmonoid ≤ q.toAddSubmonoid ↔ p ≤ q := Iff.rfl #align submodule.to_add_submonoid_le Submodule.toAddSubmonoid_le /- warning: submodule.to_add_submonoid_mono -> Submodule.toAddSubmonoid_mono is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], Monotone.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.completeLattice.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], Monotone.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.instCompleteLatticeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3) Case conversion may be inaccurate. Consider using '#align submodule.to_add_submonoid_mono Submodule.toAddSubmonoid_monoₓ'. -/ @[mono] theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : Submodule R M → AddSubmonoid M) := toAddSubmonoid_strictMono.Monotone #align submodule.to_add_submonoid_mono Submodule.toAddSubmonoid_mono /- warning: submodule.coe_to_add_submonoid -> Submodule.coe_toAddSubmonoid is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] (p : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3), Eq.{succ u2} (Set.{u2} M) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Set.{u2} M) (HasLiftT.mk.{succ u2, succ u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Set.{u2} M) (CoeTCₓ.coe.{succ u2, succ u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Set.{u2} M) (SetLike.Set.hasCoeT.{u2, u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) M (AddSubmonoid.setLike.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 p)) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Set.{u2} M) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Set.{u2} M) (CoeTCₓ.coe.{succ u2, succ u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (Set.{u2} M) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] (p : Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3), Eq.{succ u2} (Set.{u2} M) (SetLike.coe.{u2, u2} (AddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) M (AddSubmonoid.instSetLikeAddSubmonoid.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 _inst_3 p)) (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3) p) Case conversion may be inaccurate. Consider using '#align submodule.coe_to_add_submonoid Submodule.coe_toAddSubmonoidₓ'. -/ @[simp] theorem coe_toAddSubmonoid (p : Submodule R M) : (p.toAddSubmonoid : Set M) = p := rfl #align submodule.coe_to_add_submonoid Submodule.coe_toAddSubmonoid #print Submodule.toSubMulAction_injective /- theorem toSubMulAction_injective : Injective (toSubMulAction : Submodule R M → SubMulAction R M) := fun p q h => SetLike.ext'_iff.2 (show _ from SetLike.ext'_iff.1 h) #align submodule.to_sub_mul_action_injective Submodule.toSubMulAction_injective -/ #print Submodule.toSubMulAction_eq /- @[simp] theorem toSubMulAction_eq : p.toSubMulAction = q.toSubMulAction ↔ p = q := toSubMulAction_injective.eq_iff #align submodule.to_sub_mul_action_eq Submodule.toSubMulAction_eq -/ /- warning: submodule.to_sub_mul_action_strict_mono -> Submodule.toSubMulAction_strictMono is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], StrictMono.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SubMulAction.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (SetLike.partialOrder.{u2, u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) M (SubMulAction.setLike.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))))) (Submodule.toSubMulAction.{u1, u2} R M _inst_1 _inst_2 _inst_3) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], StrictMono.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (SetLike.instPartialOrder.{u2, u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) M (SubMulAction.instSetLikeSubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))))) (Submodule.toSubMulAction.{u1, u2} R M _inst_1 _inst_2 _inst_3) Case conversion may be inaccurate. Consider using '#align submodule.to_sub_mul_action_strict_mono Submodule.toSubMulAction_strictMonoₓ'. -/ @[mono] theorem toSubMulAction_strictMono : StrictMono (toSubMulAction : Submodule R M → SubMulAction R M) := fun _ _ => id #align submodule.to_sub_mul_action_strict_mono Submodule.toSubMulAction_strictMono /- warning: submodule.to_sub_mul_action_mono -> Submodule.toSubMulAction_mono is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], Monotone.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SubMulAction.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (SetLike.partialOrder.{u2, u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) M (SubMulAction.setLike.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))))) (Submodule.toSubMulAction.{u1, u2} R M _inst_1 _inst_2 _inst_3) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2], Monotone.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 _inst_3) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 _inst_3))) (PartialOrder.toPreorder.{u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) (SetLike.instPartialOrder.{u2, u2} (SubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))) M (SubMulAction.instSetLikeSubMulAction.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3))))))) (Submodule.toSubMulAction.{u1, u2} R M _inst_1 _inst_2 _inst_3) Case conversion may be inaccurate. Consider using '#align submodule.to_sub_mul_action_mono Submodule.toSubMulAction_monoₓ'. -/ @[mono] theorem toSubMulAction_mono : Monotone (toSubMulAction : Submodule R M → SubMulAction R M) := toSubMulAction_strictMono.Monotone #align submodule.to_sub_mul_action_mono Submodule.toSubMulAction_mono #print Submodule.coe_toSubMulAction /- @[simp] theorem coe_toSubMulAction (p : Submodule R M) : (p.toSubMulAction : Set M) = p := rfl #align submodule.coe_to_sub_mul_action Submodule.coe_toSubMulAction -/ end Submodule namespace SubmoduleClass variable [Semiring R] [AddCommMonoid M] [Module R M] {A : Type _} [SetLike A M] [AddSubmonoidClass A M] [hA : SubmoduleClass A R M] (S' : A) include hA #print SubmoduleClass.toModule /- -- Prefer subclasses of `module` over `submodule_class`. /-- A submodule of a `module` is a `module`. -/ instance (priority := 75) toModule : Module R S' := Subtype.coe_injective.Module R (AddSubmonoidClass.Subtype S') (SetLike.val_smul S') #align submodule_class.to_module SubmoduleClass.toModule -/ #print SubmoduleClass.subtype /- /-- The natural `R`-linear map from a submodule of an `R`-module `M` to `M`. -/ protected def subtype : S' →ₗ[R] M := ⟨coe, fun _ _ => rfl, fun _ _ => rfl⟩ #align submodule_class.subtype SubmoduleClass.subtype -/ /- warning: submodule_class.coe_subtype -> SubmoduleClass.coeSubtype is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] [_inst_3 : Module.{u1, u2} R M _inst_1 _inst_2] {A : Type.{u3}} [_inst_4 : SetLike.{u3, u2} A M] [_inst_5 : AddSubmonoidClass.{u3, u2} A M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) _inst_4] [hA : SubmoduleClass.{u3, u1, u2} A R M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 _inst_3)))) _inst_4 _inst_5] (S' : A), Eq.{succ u2} ((fun (_x : LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (AddSubmonoidClass.toAddCommMonoid.{u2, u3} M _inst_2 A _inst_4 _inst_5 S') _inst_2 (SubmoduleClass.toModule.{u1, u2, u3} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S') _inst_3) => (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') -> M) (SubmoduleClass.subtype.{u1, u2, u3} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S')) (coeFn.{succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (AddSubmonoidClass.toAddCommMonoid.{u2, u3} M _inst_2 A _inst_4 _inst_5 S') _inst_2 (SubmoduleClass.toModule.{u1, u2, u3} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S') _inst_3) (fun (_x : LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (AddSubmonoidClass.toAddCommMonoid.{u2, u3} M _inst_2 A _inst_4 _inst_5 S') _inst_2 (SubmoduleClass.toModule.{u1, u2, u3} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S') _inst_3) => (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') -> M) (LinearMap.hasCoeToFun.{u1, u1, u2, u2} R R (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M _inst_1 _inst_1 (AddSubmonoidClass.toAddCommMonoid.{u2, u3} M _inst_2 A _inst_4 _inst_5 S') _inst_2 (SubmoduleClass.toModule.{u1, u2, u3} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S') _inst_3 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (SubmoduleClass.subtype.{u1, u2, u3} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S')) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (coeBase.{succ u2, succ u2} (coeSort.{succ u3, succ (succ u2)} A Type.{u2} (SetLike.hasCoeToSort.{u3, u2} A M _inst_4) S') M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u3} M A (SetLike.hasMem.{u3, u2} A M _inst_4) x S')))))) but is expected to have type forall {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : Semiring.{u2} R] [_inst_2 : AddCommMonoid.{u3} M] [_inst_3 : Module.{u2, u3} R M _inst_1 _inst_2] {A : Type.{u1}} [_inst_4 : SetLike.{u1, u3} A M] [_inst_5 : AddSubmonoidClass.{u1, u3} A M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) _inst_4] [hA : SubmoduleClass.{u1, u2, u3} A R M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (SMulZeroClass.toSMul.{u2, u3} R M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u2, u3} R M (MonoidWithZero.toZero.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_1)) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R _inst_1) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (Module.toMulActionWithZero.{u2, u3} R M _inst_1 _inst_2 _inst_3)))) _inst_4 _inst_5] (S' : A), Eq.{succ u3} (forall (a : Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')), (fun ([email protected]._hyg.6190 : Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) => M) a) (FunLike.coe.{succ u3, succ u3, succ u3} (LinearMap.{u2, u2, u3, u3} R R _inst_1 _inst_1 (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_1)) (Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) M (AddSubmonoidClass.toAddCommMonoid.{u3, u1} M _inst_2 A _inst_4 _inst_5 S') _inst_2 (SubmoduleClass.toModule.{u2, u3, u1} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S') _inst_3) (Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) (fun (_x : Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) => (fun ([email protected]._hyg.6190 : Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) => M) _x) (LinearMap.instFunLikeLinearMap.{u2, u2, u3, u3} R R (Subtype.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) M _inst_1 _inst_1 (AddSubmonoidClass.toAddCommMonoid.{u3, u1} M _inst_2 A _inst_4 _inst_5 S') _inst_2 (SubmoduleClass.toModule.{u2, u3, u1} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S') _inst_3 (RingHom.id.{u2} R (Semiring.toNonAssocSemiring.{u2} R _inst_1))) (SubmoduleClass.subtype.{u2, u3, u1} R M _inst_1 _inst_2 _inst_3 A _inst_4 _inst_5 hA S')) (Subtype.val.{succ u3} M (fun (x : M) => Membership.mem.{u3, u1} M A (SetLike.instMembership.{u1, u3} A M _inst_4) x S')) Case conversion may be inaccurate. Consider using '#align submodule_class.coe_subtype SubmoduleClass.coeSubtypeₓ'. -/ @[simp] protected theorem coeSubtype : (SubmoduleClass.subtype S' : S' → M) = coe := rfl #align submodule_class.coe_subtype SubmoduleClass.coeSubtype end SubmoduleClass namespace Submodule section AddCommMonoid variable [Semiring R] [AddCommMonoid M] -- We can infer the module structure implicitly from the bundled submodule, -- rather than via typeclass resolution. variable {module_M : Module R M} variable {p q : Submodule R M} variable {r : R} {x y : M} variable (p) /- warning: submodule.mem_carrier -> Submodule.mem_carrier is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) {x : M}, Iff (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x (Submodule.carrier.{u1, u2} R M _inst_1 _inst_2 module_M p)) (Membership.Mem.{u2, u2} M (Set.{u2} M) (Set.hasMem.{u2} M) x ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (Set.{u2} M) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (Set.{u2} M) (CoeTCₓ.coe.{succ u2, succ u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (Set.{u2} M) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)))) p)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) {x : M}, Iff (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (AddSubsemigroup.carrier.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (AddSubmonoid.toAddSubsemigroup.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Submodule.toAddSubmonoid.{u1, u2} R M _inst_1 _inst_2 module_M p)))) (Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) Case conversion may be inaccurate. Consider using '#align submodule.mem_carrier Submodule.mem_carrierₓ'. -/ @[simp] theorem mem_carrier : x ∈ p.carrier ↔ x ∈ (p : Set M) := Iff.rfl #align submodule.mem_carrier Submodule.mem_carrier /- warning: submodule.zero_mem -> Submodule.zero_mem is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M), Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) p but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M), Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) p Case conversion may be inaccurate. Consider using '#align submodule.zero_mem Submodule.zero_memₓ'. -/ @[simp] protected theorem zero_mem : (0 : M) ∈ p := zero_mem _ #align submodule.zero_mem Submodule.zero_mem /- warning: submodule.add_mem -> Submodule.add_mem is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) {x : M} {y : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p) -> (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) y p) -> (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) x y) p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) {x : M} {y : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p) -> (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) y p) -> (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) x y) p) Case conversion may be inaccurate. Consider using '#align submodule.add_mem Submodule.add_memₓ'. -/ protected theorem add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := add_mem h₁ h₂ #align submodule.add_mem Submodule.add_mem #print Submodule.smul_mem /- theorem smul_mem (r : R) (h : x ∈ p) : r • x ∈ p := p.smul_mem' r h #align submodule.smul_mem Submodule.smul_mem -/ #print Submodule.smul_of_tower_mem /- theorem smul_of_tower_mem [SMul S R] [SMul S M] [IsScalarTower S R M] (r : S) (h : x ∈ p) : r • x ∈ p := p.toSubMulAction.smul_of_tower_mem r h #align submodule.smul_of_tower_mem Submodule.smul_of_tower_mem -/ #print Submodule.sum_mem /- protected theorem sum_mem {t : Finset ι} {f : ι → M} : (∀ c ∈ t, f c ∈ p) → (∑ i in t, f i) ∈ p := sum_mem #align submodule.sum_mem Submodule.sum_mem -/ #print Submodule.sum_smul_mem /- theorem sum_smul_mem {t : Finset ι} {f : ι → M} (r : ι → R) (hyp : ∀ c ∈ t, f c ∈ p) : (∑ i in t, r i • f i) ∈ p := sum_mem fun i hi => smul_mem _ _ (hyp i hi) #align submodule.sum_smul_mem Submodule.sum_smul_mem -/ #print Submodule.smul_mem_iff' /- @[simp] theorem smul_mem_iff' [Group G] [MulAction G M] [SMul G R] [IsScalarTower G R M] (g : G) : g • x ∈ p ↔ x ∈ p := p.toSubMulAction.smul_mem_iff' g #align submodule.smul_mem_iff' Submodule.smul_mem_iff' -/ instance : Add p := ⟨fun x y => ⟨x.1 + y.1, add_mem x.2 y.2⟩⟩ instance : Zero p := ⟨⟨0, zero_mem _⟩⟩ instance : Inhabited p := ⟨0⟩ instance [SMul S R] [SMul S M] [IsScalarTower S R M] : SMul S p := ⟨fun c x => ⟨c • x.1, smul_of_tower_mem _ c x.2⟩⟩ instance [SMul S R] [SMul S M] [IsScalarTower S R M] : IsScalarTower S R p := p.toSubMulAction.IsScalarTower #print Submodule.isScalarTower' /- instance isScalarTower' {S' : Type _} [SMul S R] [SMul S M] [SMul S' R] [SMul S' M] [SMul S S'] [IsScalarTower S' R M] [IsScalarTower S S' M] [IsScalarTower S R M] : IsScalarTower S S' p := p.toSubMulAction.isScalarTower' #align submodule.is_scalar_tower' Submodule.isScalarTower' -/ instance [SMul S R] [SMul S M] [IsScalarTower S R M] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S p := p.toSubMulAction.IsCentralScalar #print Submodule.nonempty /- protected theorem nonempty : (p : Set M).Nonempty := ⟨0, p.zero_mem⟩ #align submodule.nonempty Submodule.nonempty -/ /- warning: submodule.mk_eq_zero -> Submodule.mk_eq_zero is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) {x : M} (h : Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p), Iff (Eq.{succ u2} (Subtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Subtype.mk.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p) x h) (OfNat.ofNat.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) 0 (OfNat.mk.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) 0 (Zero.zero.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p))))) (Eq.{succ u2} M x (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) {x : M} (h : Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p), Iff (Eq.{succ u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Subtype.mk.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p) x h) (OfNat.ofNat.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) 0 (Zero.toOfNat0.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p)))) (Eq.{succ u2} M x (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))) Case conversion may be inaccurate. Consider using '#align submodule.mk_eq_zero Submodule.mk_eq_zeroₓ'. -/ @[simp] theorem mk_eq_zero {x} (h : x ∈ p) : (⟨x, h⟩ : p) = 0 ↔ x = 0 := Subtype.ext_iff_val #align submodule.mk_eq_zero Submodule.mk_eq_zero variable {p} /- warning: submodule.coe_eq_zero -> Submodule.coe_eq_zero is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} {p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M} {x : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p}, Iff (Eq.{succ u2} M ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p))))) x) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))))) (Eq.{succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) x (OfNat.ofNat.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) 0 (OfNat.mk.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) 0 (Zero.zero.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p))))) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} {p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M} {x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)}, Iff (Eq.{succ u2} M (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) x) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))))) (Eq.{succ u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) x (OfNat.ofNat.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) 0 (Zero.toOfNat0.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p)))) Case conversion may be inaccurate. Consider using '#align submodule.coe_eq_zero Submodule.coe_eq_zeroₓ'. -/ @[simp, norm_cast] theorem coe_eq_zero {x : p} : (x : M) = 0 ↔ x = 0 := (SetLike.coe_eq_coe : (x : M) = (0 : p) ↔ x = 0) #align submodule.coe_eq_zero Submodule.coe_eq_zero /- warning: submodule.coe_add -> Submodule.coe_add is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} {p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M} (x : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (y : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p), Eq.{succ u2} M ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p))))) (HAdd.hAdd.{u2, u2, u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (instHAdd.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (Submodule.add.{u1, u2} R M _inst_1 _inst_2 module_M p)) x y)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p))))) x) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p))))) y)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} {p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M} (x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (y : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)), Eq.{succ u2} M (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) (HAdd.hAdd.{u2, u2, u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (instHAdd.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Submodule.add.{u1, u2} R M _inst_1 _inst_2 module_M p)) x y)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) x) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) y)) Case conversion may be inaccurate. Consider using '#align submodule.coe_add Submodule.coe_addₓ'. -/ @[simp, norm_cast] theorem coe_add (x y : p) : (↑(x + y) : M) = ↑x + ↑y := rfl #align submodule.coe_add Submodule.coe_add /- warning: submodule.coe_zero -> Submodule.coe_zero is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} {p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M}, Eq.{succ u2} M ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p))))) (OfNat.ofNat.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) 0 (OfNat.mk.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) 0 (Zero.zero.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p))))) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))))) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} {p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M}, Eq.{succ u2} M (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) (OfNat.ofNat.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) 0 (Zero.toOfNat0.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p)))) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)))) Case conversion may be inaccurate. Consider using '#align submodule.coe_zero Submodule.coe_zeroₓ'. -/ @[simp, norm_cast] theorem coe_zero : ((0 : p) : M) = 0 := rfl #align submodule.coe_zero Submodule.coe_zero #print Submodule.coe_smul /- @[norm_cast] theorem coe_smul (r : R) (x : p) : ((r • x : p) : M) = r • ↑x := rfl #align submodule.coe_smul Submodule.coe_smul -/ #print Submodule.coe_smul_of_tower /- @[simp, norm_cast] theorem coe_smul_of_tower [SMul S R] [SMul S M] [IsScalarTower S R M] (r : S) (x : p) : ((r • x : p) : M) = r • ↑x := rfl #align submodule.coe_smul_of_tower Submodule.coe_smul_of_tower -/ #print Submodule.coe_mk /- @[simp, norm_cast] theorem coe_mk (x : M) (hx : x ∈ p) : ((⟨x, hx⟩ : p) : M) = x := rfl #align submodule.coe_mk Submodule.coe_mk -/ #print Submodule.coe_mem /- @[simp] theorem coe_mem (x : p) : (x : M) ∈ p := x.2 #align submodule.coe_mem Submodule.coe_mem -/ variable (p) instance : AddCommMonoid p := { p.toAddSubmonoid.toAddCommMonoid with add := (· + ·) zero := 0 } #print Submodule.module' /- instance module' [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : Module S p := by refine' { p.to_sub_mul_action.mul_action' with smul := (· • ·).. } <;> · intros apply SetCoe.ext simp [smul_add, add_smul, mul_smul] #align submodule.module' Submodule.module' -/ instance : Module R p := p.module' /- warning: submodule.no_zero_smul_divisors -> Submodule.noZeroSMulDivisors is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) [_inst_3 : NoZeroSMulDivisors.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 module_M))))], NoZeroSMulDivisors.{u1, u2} R (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p) (Submodule.smul.{u1, u1, u2} R R M _inst_1 _inst_2 module_M p (Mul.toSMul.{u1} R (MulOneClass.toHasMul.{u1} R (Monoid.toMulOneClass.{u1} R (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1))))) (MulAction.toHasSmul.{u1, u2} R M (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (MulActionWithZero.toMulAction.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 module_M))) (IsScalarTower.left.{u1, u2} R M (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (MulActionWithZero.toMulAction.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2))) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 module_M)))) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) [_inst_3 : NoZeroSMulDivisors.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 module_M))))], NoZeroSMulDivisors.{u1, u2} R (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (Submodule.zero.{u1, u2} R M _inst_1 _inst_2 module_M p) (Submodule.smul.{u1, u1, u2} R R M _inst_1 _inst_2 module_M p (SMulZeroClass.toSMul.{u1, u1} R R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (SMulWithZero.toSMulZeroClass.{u1, u1} R R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (MulZeroClass.toSMulWithZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonAssocSemiring.toNonUnitalNonAssocSemiring.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)))))) (SMulZeroClass.toSMul.{u1, u2} R M (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 module_M)))) (IsScalarTower.left.{u1, u2} R M (MonoidWithZero.toMonoid.{u1} R (Semiring.toMonoidWithZero.{u1} R _inst_1)) (MulActionWithZero.toMulAction.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R _inst_1) (AddMonoid.toZero.{u2} M (AddCommMonoid.toAddMonoid.{u2} M _inst_2)) (Module.toMulActionWithZero.{u1, u2} R M _inst_1 _inst_2 module_M)))) Case conversion may be inaccurate. Consider using '#align submodule.no_zero_smul_divisors Submodule.noZeroSMulDivisorsₓ'. -/ instance noZeroSMulDivisors [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R p := ⟨fun c x h => have : c = 0 ∨ (x : M) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg coe h) this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩ #align submodule.no_zero_smul_divisors Submodule.noZeroSMulDivisors #print Submodule.subtype /- /-- Embedding of a submodule `p` to the ambient space `M`. -/ protected def subtype : p →ₗ[R] M := by refine' { toFun := coe.. } <;> simp [coe_smul] #align submodule.subtype Submodule.subtype -/ /- warning: submodule.subtype_apply -> Submodule.subtype_apply is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (x : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p), Eq.{succ u2} M (coeFn.{succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) (fun (_x : LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) => (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) -> M) (LinearMap.hasCoeToFun.{u1, u1, u2, u2} R R (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M _inst_1 _inst_1 (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p) x) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p))))) x) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)), Eq.{succ u2} ((fun ([email protected]._hyg.6190 : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => M) x) (FunLike.coe.{succ u2, succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (fun (_x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => (fun ([email protected]._hyg.6190 : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => M) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u2, u2} R R (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M _inst_1 _inst_1 (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p) x) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M) p)) x) Case conversion may be inaccurate. Consider using '#align submodule.subtype_apply Submodule.subtype_applyₓ'. -/ theorem subtype_apply (x : p) : p.Subtype x = x := rfl #align submodule.subtype_apply Submodule.subtype_apply /- warning: submodule.coe_subtype -> Submodule.coeSubtype is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M), Eq.{succ u2} ((fun (_x : LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) => (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) -> M) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p)) (coeFn.{succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) (fun (_x : LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) => (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) -> M) (LinearMap.hasCoeToFun.{u1, u1, u2, u2} R R (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M _inst_1 _inst_1 (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p)) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)))))) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M), Eq.{succ u2} (forall (a : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)), (fun ([email protected]._hyg.6190 : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => M) a) (FunLike.coe.{succ u2, succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (fun (_x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => (fun ([email protected]._hyg.6190 : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => M) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u2, u2} R R (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M _inst_1 _inst_1 (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p)) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) Case conversion may be inaccurate. Consider using '#align submodule.coe_subtype Submodule.coeSubtypeₓ'. -/ @[simp] theorem coeSubtype : (Submodule.subtype p : p → M) = coe := rfl #align submodule.coe_subtype Submodule.coeSubtype /- warning: submodule.injective_subtype -> Submodule.injective_subtype is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M), Function.Injective.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (coeFn.{succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) (fun (_x : LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) => (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) -> M) (LinearMap.hasCoeToFun.{u1, u1, u2, u2} R R (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) p) M _inst_1 _inst_1 (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Semiring.{u1} R] [_inst_2 : AddCommMonoid.{u2} M] {module_M : Module.{u1, u2} R M _inst_1 _inst_2} (p : Submodule.{u1, u2} R M _inst_1 _inst_2 module_M), Function.Injective.{succ u2, succ u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M (FunLike.coe.{succ u2, succ u2, succ u2} (LinearMap.{u1, u1, u2, u2} R R _inst_1 _inst_1 (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) (fun (_x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => (fun ([email protected]._hyg.6190 : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) => M) _x) (LinearMap.instFunLikeLinearMap.{u1, u1, u2, u2} R R (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M _inst_1 _inst_2 module_M) M (Submodule.setLike.{u1, u2} R M _inst_1 _inst_2 module_M)) x p)) M _inst_1 _inst_1 (Submodule.addCommMonoid.{u1, u2} R M _inst_1 _inst_2 module_M p) _inst_2 (Submodule.module.{u1, u2} R M _inst_1 _inst_2 module_M p) module_M (RingHom.id.{u1} R (Semiring.toNonAssocSemiring.{u1} R _inst_1))) (Submodule.subtype.{u1, u2} R M _inst_1 _inst_2 module_M p)) Case conversion may be inaccurate. Consider using '#align submodule.injective_subtype Submodule.injective_subtypeₓ'. -/ theorem injective_subtype : Injective p.Subtype := Subtype.coe_injective #align submodule.injective_subtype Submodule.injective_subtype #print Submodule.coe_sum /- /-- Note the `add_submonoid` version of this lemma is called `add_submonoid.coe_finset_sum`. -/ @[simp] theorem coe_sum (x : ι → p) (s : Finset ι) : ↑(∑ i in s, x i) = ∑ i in s, (x i : M) := map_sum p.Subtype _ _ #align submodule.coe_sum Submodule.coe_sum -/ section RestrictScalars variable (S) [Semiring S] [Module S M] [Module R M] [SMul S R] [IsScalarTower S R M] #print Submodule.restrictScalars /- /-- `V.restrict_scalars S` is the `S`-submodule of the `S`-module given by restriction of scalars, corresponding to `V`, an `R`-submodule of the original `R`-module. -/ def restrictScalars (V : Submodule R M) : Submodule S M where carrier := V zero_mem' := V.zero_mem smul_mem' c m h := V.smul_of_tower_mem c h add_mem' x y hx hy := V.add_mem hx hy #align submodule.restrict_scalars Submodule.restrictScalars -/ #print Submodule.coe_restrictScalars /- @[simp] theorem coe_restrictScalars (V : Submodule R M) : (V.restrictScalars S : Set M) = V := rfl #align submodule.coe_restrict_scalars Submodule.coe_restrictScalars -/ #print Submodule.restrictScalars_mem /- @[simp] theorem restrictScalars_mem (V : Submodule R M) (m : M) : m ∈ V.restrictScalars S ↔ m ∈ V := Iff.refl _ #align submodule.restrict_scalars_mem Submodule.restrictScalars_mem -/ #print Submodule.restrictScalars_self /- @[simp] theorem restrictScalars_self (V : Submodule R M) : V.restrictScalars R = V := SetLike.coe_injective rfl #align submodule.restrict_scalars_self Submodule.restrictScalars_self -/ variable (R S M) #print Submodule.restrictScalars_injective /- theorem restrictScalars_injective : Function.Injective (restrictScalars S : Submodule R M → Submodule S M) := fun V₁ V₂ h => ext <| Set.ext_iff.1 (SetLike.ext'_iff.1 h : _) #align submodule.restrict_scalars_injective Submodule.restrictScalars_injective -/ #print Submodule.restrictScalars_inj /- @[simp] theorem restrictScalars_inj {V₁ V₂ : Submodule R M} : restrictScalars S V₁ = restrictScalars S V₂ ↔ V₁ = V₂ := (restrictScalars_injective S _ _).eq_iff #align submodule.restrict_scalars_inj Submodule.restrictScalars_inj -/ #print Submodule.restrictScalars.origModule /- /-- Even though `p.restrict_scalars S` has type `submodule S M`, it is still an `R`-module. -/ instance restrictScalars.origModule (p : Submodule R M) : Module R (p.restrictScalars S) := (by infer_instance : Module R p) #align submodule.restrict_scalars.orig_module Submodule.restrictScalars.origModule -/ instance (p : Submodule R M) : IsScalarTower S R (p.restrictScalars S) where smul_assoc r s x := Subtype.ext <| smul_assoc r s (x : M) /- warning: submodule.restrict_scalars_embedding -> Submodule.restrictScalarsEmbedding is a dubious translation: lean 3 declaration is forall (S : Type.{u1}) (R : Type.{u2}) (M : Type.{u3}) [_inst_1 : Semiring.{u2} R] [_inst_2 : AddCommMonoid.{u3} M] [_inst_3 : Semiring.{u1} S] [_inst_4 : Module.{u1, u3} S M _inst_3 _inst_2] [_inst_5 : Module.{u2, u3} R M _inst_1 _inst_2] [_inst_6 : SMul.{u1, u2} S R] [_inst_7 : IsScalarTower.{u1, u2, u3} S R M _inst_6 (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_1)))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R _inst_1) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2))) (Module.toMulActionWithZero.{u2, u3} R M _inst_1 _inst_2 _inst_5)))) (SMulZeroClass.toHasSmul.{u1, u3} S M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2))) (SMulWithZero.toSmulZeroClass.{u1, u3} S M (MulZeroClass.toHasZero.{u1} S (MulZeroOneClass.toMulZeroClass.{u1} S (MonoidWithZero.toMulZeroOneClass.{u1} S (Semiring.toMonoidWithZero.{u1} S _inst_3)))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2))) (MulActionWithZero.toSMulWithZero.{u1, u3} S M (Semiring.toMonoidWithZero.{u1} S _inst_3) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2))) (Module.toMulActionWithZero.{u1, u3} S M _inst_3 _inst_2 _inst_4))))], OrderEmbedding.{u3, u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) (Preorder.toLE.{u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) (PartialOrder.toPreorder.{u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) (SetLike.partialOrder.{u3, u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) M (Submodule.setLike.{u2, u3} R M _inst_1 _inst_2 _inst_5)))) (Preorder.toLE.{u3} (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) (PartialOrder.toPreorder.{u3} (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) (SetLike.partialOrder.{u3, u3} (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) M (Submodule.setLike.{u1, u3} S M _inst_3 _inst_2 _inst_4)))) but is expected to have type forall (S : Type.{u1}) (R : Type.{u2}) (M : Type.{u3}) [_inst_1 : Semiring.{u2} R] [_inst_2 : AddCommMonoid.{u3} M] [_inst_3 : Semiring.{u1} S] [_inst_4 : Module.{u1, u3} S M _inst_3 _inst_2] [_inst_5 : Module.{u2, u3} R M _inst_1 _inst_2] [_inst_6 : SMul.{u1, u2} S R] [_inst_7 : IsScalarTower.{u1, u2, u3} S R M _inst_6 (SMulZeroClass.toSMul.{u2, u3} R M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u2, u3} R M (MonoidWithZero.toZero.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_1)) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R _inst_1) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (Module.toMulActionWithZero.{u2, u3} R M _inst_1 _inst_2 _inst_5)))) (SMulZeroClass.toSMul.{u1, u3} S M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (SMulWithZero.toSMulZeroClass.{u1, u3} S M (MonoidWithZero.toZero.{u1} S (Semiring.toMonoidWithZero.{u1} S _inst_3)) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (MulActionWithZero.toSMulWithZero.{u1, u3} S M (Semiring.toMonoidWithZero.{u1} S _inst_3) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_2)) (Module.toMulActionWithZero.{u1, u3} S M _inst_3 _inst_2 _inst_4))))], OrderEmbedding.{u3, u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) (Preorder.toLE.{u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) (PartialOrder.toPreorder.{u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) (SetLike.instPartialOrder.{u3, u3} (Submodule.{u2, u3} R M _inst_1 _inst_2 _inst_5) M (Submodule.setLike.{u2, u3} R M _inst_1 _inst_2 _inst_5)))) (Preorder.toLE.{u3} (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) (PartialOrder.toPreorder.{u3} (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) (SetLike.instPartialOrder.{u3, u3} (Submodule.{u1, u3} S M _inst_3 _inst_2 _inst_4) M (Submodule.setLike.{u1, u3} S M _inst_3 _inst_2 _inst_4)))) Case conversion may be inaccurate. Consider using '#align submodule.restrict_scalars_embedding Submodule.restrictScalarsEmbeddingₓ'. -/ /-- `restrict_scalars S` is an embedding of the lattice of `R`-submodules into the lattice of `S`-submodules. -/ @[simps] def restrictScalarsEmbedding : Submodule R M ↪o Submodule S M where toFun := restrictScalars S inj' := restrictScalars_injective S R M map_rel_iff' p q := by simp [SetLike.le_def] #align submodule.restrict_scalars_embedding Submodule.restrictScalarsEmbedding #print Submodule.restrictScalarsEquiv /- /-- Turning `p : submodule R M` into an `S`-submodule gives the same module structure as turning it into a type and adding a module structure. -/ @[simps (config := { simpRhs := true })] def restrictScalarsEquiv (p : Submodule R M) : p.restrictScalars S ≃ₗ[R] p := { AddEquiv.refl p with toFun := id invFun := id map_smul' := fun c x => rfl } #align submodule.restrict_scalars_equiv Submodule.restrictScalarsEquiv -/ end RestrictScalars end AddCommMonoid section AddCommGroup variable [Ring R] [AddCommGroup M] variable {module_M : Module R M} variable (p p' : Submodule R M) variable {r : R} {x y : M} instance [Module R M] : AddSubgroupClass (Submodule R M) M := { Submodule.addSubmonoidClass with neg_mem := fun p x => p.toSubMulAction.neg_mem } /- warning: submodule.neg_mem -> Submodule.neg_mem is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (Neg.neg.{u2} M (SubNegMonoid.toHasNeg.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))) x) p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (Neg.neg.{u2} M (NegZeroClass.toNeg.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_2))))) x) p) Case conversion may be inaccurate. Consider using '#align submodule.neg_mem Submodule.neg_memₓ'. -/ protected theorem neg_mem (hx : x ∈ p) : -x ∈ p := neg_mem hx #align submodule.neg_mem Submodule.neg_mem #print Submodule.toAddSubgroup /- /-- Reinterpret a submodule as an additive subgroup. -/ def toAddSubgroup : AddSubgroup M := { p.toAddSubmonoid with neg_mem' := fun _ => p.neg_mem } #align submodule.to_add_subgroup Submodule.toAddSubgroup -/ /- warning: submodule.coe_to_add_subgroup -> Submodule.coe_toAddSubgroup is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M), Eq.{succ u2} (Set.{u2} M) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Set.{u2} M) (HasLiftT.mk.{succ u2, succ u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Set.{u2} M) (CoeTCₓ.coe.{succ u2, succ u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Set.{u2} M) (SetLike.Set.hasCoeT.{u2, u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) M (AddSubgroup.setLike.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p)) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Set.{u2} M) (HasLiftT.mk.{succ u2, succ u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Set.{u2} M) (CoeTCₓ.coe.{succ u2, succ u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Set.{u2} M) (SetLike.Set.hasCoeT.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)))) p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M), Eq.{succ u2} (Set.{u2} M) (SetLike.coe.{u2, u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) M (AddSubgroup.instSetLikeAddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p)) (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) p) Case conversion may be inaccurate. Consider using '#align submodule.coe_to_add_subgroup Submodule.coe_toAddSubgroupₓ'. -/ @[simp] theorem coe_toAddSubgroup : (p.toAddSubgroup : Set M) = p := rfl #align submodule.coe_to_add_subgroup Submodule.coe_toAddSubgroup /- warning: submodule.mem_to_add_subgroup -> Submodule.mem_toAddSubgroup is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M}, Iff (Membership.Mem.{u2, u2} M (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (SetLike.hasMem.{u2, u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) M (AddSubgroup.setLike.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))) x (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p)) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M}, Iff (Membership.mem.{u2, u2} M (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (SetLike.instMembership.{u2, u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) M (AddSubgroup.instSetLikeAddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))) x (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p)) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) Case conversion may be inaccurate. Consider using '#align submodule.mem_to_add_subgroup Submodule.mem_toAddSubgroupₓ'. -/ @[simp] theorem mem_toAddSubgroup : x ∈ p.toAddSubgroup ↔ x ∈ p := Iff.rfl #align submodule.mem_to_add_subgroup Submodule.mem_toAddSubgroup include module_M #print Submodule.toAddSubgroup_injective /- theorem toAddSubgroup_injective : Injective (toAddSubgroup : Submodule R M → AddSubgroup M) | p, q, h => SetLike.ext (SetLike.ext_iff.1 h : _) #align submodule.to_add_subgroup_injective Submodule.toAddSubgroup_injective -/ #print Submodule.toAddSubgroup_eq /- @[simp] theorem toAddSubgroup_eq : p.toAddSubgroup = p'.toAddSubgroup ↔ p = p' := toAddSubgroup_injective.eq_iff #align submodule.to_add_subgroup_eq Submodule.toAddSubgroup_eq -/ /- warning: submodule.to_add_subgroup_strict_mono -> Submodule.toAddSubgroup_strictMono is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)}, StrictMono.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M))) (PartialOrder.toPreorder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (AddSubgroup.completeLattice.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)}, StrictMono.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M))) (PartialOrder.toPreorder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (AddSubgroup.instCompleteLatticeAddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M) Case conversion may be inaccurate. Consider using '#align submodule.to_add_subgroup_strict_mono Submodule.toAddSubgroup_strictMonoₓ'. -/ @[mono] theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : Submodule R M → AddSubgroup M) := fun _ _ => id #align submodule.to_add_subgroup_strict_mono Submodule.toAddSubgroup_strictMono /- warning: submodule.to_add_subgroup_le -> Submodule.toAddSubgroup_le is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (p' : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M), Iff (LE.le.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Preorder.toLE.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (PartialOrder.toPreorder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (AddSubgroup.completeLattice.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p')) (LE.le.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Preorder.toLE.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)))) p p') but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (p' : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M), Iff (LE.le.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Preorder.toLE.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (PartialOrder.toPreorder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (AddSubgroup.instCompleteLatticeAddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M p')) (LE.le.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Preorder.toLE.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)))) p p') Case conversion may be inaccurate. Consider using '#align submodule.to_add_subgroup_le Submodule.toAddSubgroup_leₓ'. -/ theorem toAddSubgroup_le : p.toAddSubgroup ≤ p'.toAddSubgroup ↔ p ≤ p' := Iff.rfl #align submodule.to_add_subgroup_le Submodule.toAddSubgroup_le /- warning: submodule.to_add_subgroup_mono -> Submodule.toAddSubgroup_mono is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)}, Monotone.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.partialOrder.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M))) (PartialOrder.toPreorder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (AddSubgroup.completeLattice.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)}, Monotone.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (PartialOrder.toPreorder.{u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instPartialOrder.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M))) (PartialOrder.toPreorder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteSemilatticeInf.toPartialOrder.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (CompleteLattice.toCompleteSemilatticeInf.{u2} (AddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (AddSubgroup.instCompleteLatticeAddSubgroup.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))))) (Submodule.toAddSubgroup.{u1, u2} R M _inst_1 _inst_2 module_M) Case conversion may be inaccurate. Consider using '#align submodule.to_add_subgroup_mono Submodule.toAddSubgroup_monoₓ'. -/ @[mono] theorem toAddSubgroup_mono : Monotone (toAddSubgroup : Submodule R M → AddSubgroup M) := toAddSubgroup_strictMono.Monotone #align submodule.to_add_subgroup_mono Submodule.toAddSubgroup_mono omit module_M /- warning: submodule.sub_mem -> Submodule.sub_mem is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p) -> (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toHasSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) x y) p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p) -> (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) x y) p) Case conversion may be inaccurate. Consider using '#align submodule.sub_mem Submodule.sub_memₓ'. -/ protected theorem sub_mem : x ∈ p → y ∈ p → x - y ∈ p := sub_mem #align submodule.sub_mem Submodule.sub_mem /- warning: submodule.neg_mem_iff -> Submodule.neg_mem_iff is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M}, Iff (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (Neg.neg.{u2} M (SubNegMonoid.toHasNeg.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))) x) p) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M}, Iff (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (Neg.neg.{u2} M (NegZeroClass.toNeg.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_2))))) x) p) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) Case conversion may be inaccurate. Consider using '#align submodule.neg_mem_iff Submodule.neg_mem_iffₓ'. -/ protected theorem neg_mem_iff : -x ∈ p ↔ x ∈ p := neg_mem_iff #align submodule.neg_mem_iff Submodule.neg_mem_iff /- warning: submodule.add_mem_iff_left -> Submodule.add_mem_iff_left is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p) -> (Iff (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))))) x y) p) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p) -> (Iff (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))))) x y) p) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) Case conversion may be inaccurate. Consider using '#align submodule.add_mem_iff_left Submodule.add_mem_iff_leftₓ'. -/ protected theorem add_mem_iff_left : y ∈ p → (x + y ∈ p ↔ x ∈ p) := add_mem_cancel_right #align submodule.add_mem_iff_left Submodule.add_mem_iff_left /- warning: submodule.add_mem_iff_right -> Submodule.add_mem_iff_right is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Iff (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))))) x y) p) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Iff (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))))) x y) p) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p)) Case conversion may be inaccurate. Consider using '#align submodule.add_mem_iff_right Submodule.add_mem_iff_rightₓ'. -/ protected theorem add_mem_iff_right : x ∈ p → (x + y ∈ p ↔ y ∈ p) := add_mem_cancel_left #align submodule.add_mem_iff_right Submodule.add_mem_iff_right /- warning: submodule.coe_neg -> Submodule.coe_neg is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (x : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p), Eq.{succ u2} M ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p))))) (Neg.neg.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) (AddSubgroupClass.neg.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Submodule.addSubgroupClass.{u1, u2} R M _inst_1 _inst_2 module_M) p) x)) (Neg.neg.{u2} M (SubNegMonoid.toHasNeg.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2))) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p))))) x)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)), Eq.{succ u2} M (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) p)) (Neg.neg.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) (AddSubgroupClass.neg.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Submodule.addSubgroupClass.{u1, u2} R M _inst_1 _inst_2 module_M) p) x)) (Neg.neg.{u2} M (NegZeroClass.toNeg.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_2))))) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) p)) x)) Case conversion may be inaccurate. Consider using '#align submodule.coe_neg Submodule.coe_negₓ'. -/ protected theorem coe_neg (x : p) : ((-x : p) : M) = -x := AddSubgroupClass.coe_neg _ #align submodule.coe_neg Submodule.coe_neg /- warning: submodule.coe_sub -> Submodule.coe_sub is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (x : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) (y : coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p), Eq.{succ u2} M ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p))))) (HSub.hSub.{u2, u2, u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) (instHSub.{u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) (AddSubgroupClass.sub.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Submodule.addSubgroupClass.{u1, u2} R M _inst_1 _inst_2 module_M) p)) x y)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toHasSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p))))) x) ((fun (a : Type.{u2}) (b : Type.{u2}) [self : HasLiftT.{succ u2, succ u2} a b] => self.0) (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (HasLiftT.mk.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (CoeTCₓ.coe.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeBase.{succ u2, succ u2} (coeSort.{succ u2, succ (succ u2)} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) Type.{u2} (SetLike.hasCoeToSort.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) p) M (coeSubtype.{succ u2} M (fun (x : M) => Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p))))) y)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (x : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) (y : Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)), Eq.{succ u2} M (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) p)) (HSub.hSub.{u2, u2, u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) (instHSub.{u2} (Subtype.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) (AddSubgroupClass.sub.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)) (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (Submodule.addSubgroupClass.{u1, u2} R M _inst_1 _inst_2 module_M) p)) x y)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) p)) x) (Subtype.val.{succ u2} M (fun (x : M) => Membership.mem.{u2, u2} M (Set.{u2} M) (Set.instMembershipSet.{u2} M) x (SetLike.coe.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) p)) y)) Case conversion may be inaccurate. Consider using '#align submodule.coe_sub Submodule.coe_subₓ'. -/ protected theorem coe_sub (x y : p) : (↑(x - y) : M) = ↑x - ↑y := AddSubgroupClass.coe_sub _ _ #align submodule.coe_sub Submodule.coe_sub /- warning: submodule.sub_mem_iff_left -> Submodule.sub_mem_iff_left is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p) -> (Iff (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toHasSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) x y) p) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p) -> (Iff (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) x y) p) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p)) Case conversion may be inaccurate. Consider using '#align submodule.sub_mem_iff_left Submodule.sub_mem_iff_leftₓ'. -/ theorem sub_mem_iff_left (hy : y ∈ p) : x - y ∈ p ↔ x ∈ p := by rw [sub_eq_add_neg, p.add_mem_iff_left (p.neg_mem hy)] #align submodule.sub_mem_iff_left Submodule.sub_mem_iff_left /- warning: submodule.sub_mem_iff_right -> Submodule.sub_mem_iff_right is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Iff (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toHasSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) x y) p) (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : AddCommGroup.{u2} M] {module_M : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2)} (p : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) {x : M} {y : M}, (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) x p) -> (Iff (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) (HSub.hSub.{u2, u2, u2} M M M (instHSub.{u2} M (SubNegMonoid.toSub.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_2)))) x y) p) (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_2) module_M)) y p)) Case conversion may be inaccurate. Consider using '#align submodule.sub_mem_iff_right Submodule.sub_mem_iff_rightₓ'. -/ theorem sub_mem_iff_right (hx : x ∈ p) : x - y ∈ p ↔ y ∈ p := by rw [sub_eq_add_neg, p.add_mem_iff_right hx, p.neg_mem_iff] #align submodule.sub_mem_iff_right Submodule.sub_mem_iff_right instance : AddCommGroup p := { p.toAddSubgroup.toAddCommGroup with add := (· + ·) zero := 0 neg := Neg.neg } end AddCommGroup section IsDomain variable [Ring R] [IsDomain R] variable [AddCommGroup M] [Module R M] {b : ι → M} /- warning: submodule.not_mem_of_ortho -> Submodule.not_mem_of_ortho is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R _inst_1)] [_inst_3 : AddCommGroup.{u2} M] [_inst_4 : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)] {x : M} {N : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4}, (forall (c : R) (y : M), (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)) y N) -> (Eq.{succ u2} M (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3)))))) (SMul.smul.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1))))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)))) (Module.toMulActionWithZero.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)))) c x) y) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3))))))))) -> (Eq.{succ u1} R c (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R _inst_1)))))))))) -> (Not (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)) x N)) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R _inst_1)] [_inst_3 : AddCommGroup.{u2} M] [_inst_4 : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)] {x : M} {N : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4}, (forall (c : R) (y : M), (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)) y N) -> (Eq.{succ u2} M (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3)))))) (HSMul.hSMul.{u1, u2, u2} R M M (instHSMul.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3))))) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3))))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3))))) (Module.toMulActionWithZero.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4))))) c x) y) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3)))))))) -> (Eq.{succ u1} R c (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1))))))) -> (Not (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)) x N)) Case conversion may be inaccurate. Consider using '#align submodule.not_mem_of_ortho Submodule.not_mem_of_orthoₓ'. -/ theorem not_mem_of_ortho {x : M} {N : Submodule R M} (ortho : ∀ (c : R), ∀ y ∈ N, c • x + y = (0 : M) → c = 0) : x ∉ N := by intro hx simpa using ortho (-1) x hx #align submodule.not_mem_of_ortho Submodule.not_mem_of_ortho /- warning: submodule.ne_zero_of_ortho -> Submodule.ne_zero_of_ortho is a dubious translation: lean 3 declaration is forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R _inst_1)] [_inst_3 : AddCommGroup.{u2} M] [_inst_4 : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)] {x : M} {N : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4}, (forall (c : R) (y : M), (Membership.Mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) (SetLike.hasMem.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)) y N) -> (Eq.{succ u2} M (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toHasAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3)))))) (SMul.smul.{u1, u2} R M (SMulZeroClass.toHasSmul.{u1, u2} R M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)))) (SMulWithZero.toSmulZeroClass.{u1, u2} R M (MulZeroClass.toHasZero.{u1} R (MulZeroOneClass.toMulZeroClass.{u1} R (MonoidWithZero.toMulZeroOneClass.{u1} R (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1))))) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (AddCommMonoid.toAddMonoid.{u2} M (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)))) (Module.toMulActionWithZero.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)))) c x) y) (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3))))))))) -> (Eq.{succ u1} R c (OfNat.ofNat.{u1} R 0 (OfNat.mk.{u1} R 0 (Zero.zero.{u1} R (MulZeroClass.toHasZero.{u1} R (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} R (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} R (NonAssocRing.toNonUnitalNonAssocRing.{u1} R (Ring.toNonAssocRing.{u1} R _inst_1)))))))))) -> (Ne.{succ u2} M x (OfNat.ofNat.{u2} M 0 (OfNat.mk.{u2} M 0 (Zero.zero.{u2} M (AddZeroClass.toHasZero.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3))))))))) but is expected to have type forall {R : Type.{u1}} {M : Type.{u2}} [_inst_1 : Ring.{u1} R] [_inst_2 : IsDomain.{u1} R (Ring.toSemiring.{u1} R _inst_1)] [_inst_3 : AddCommGroup.{u2} M] [_inst_4 : Module.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3)] {x : M} {N : Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4}, (forall (c : R) (y : M), (Membership.mem.{u2, u2} M (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) (SetLike.instMembership.{u2, u2} (Submodule.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4) M (Submodule.setLike.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4)) y N) -> (Eq.{succ u2} M (HAdd.hAdd.{u2, u2, u2} M M M (instHAdd.{u2} M (AddZeroClass.toAdd.{u2} M (AddMonoid.toAddZeroClass.{u2} M (SubNegMonoid.toAddMonoid.{u2} M (AddGroup.toSubNegMonoid.{u2} M (AddCommGroup.toAddGroup.{u2} M _inst_3)))))) (HSMul.hSMul.{u1, u2, u2} R M M (instHSMul.{u1, u2} R M (SMulZeroClass.toSMul.{u1, u2} R M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3))))) (SMulWithZero.toSMulZeroClass.{u1, u2} R M (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1))) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3))))) (MulActionWithZero.toSMulWithZero.{u1, u2} R M (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1)) (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3))))) (Module.toMulActionWithZero.{u1, u2} R M (Ring.toSemiring.{u1} R _inst_1) (AddCommGroup.toAddCommMonoid.{u2} M _inst_3) _inst_4))))) c x) y) (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3)))))))) -> (Eq.{succ u1} R c (OfNat.ofNat.{u1} R 0 (Zero.toOfNat0.{u1} R (MonoidWithZero.toZero.{u1} R (Semiring.toMonoidWithZero.{u1} R (Ring.toSemiring.{u1} R _inst_1))))))) -> (Ne.{succ u2} M x (OfNat.ofNat.{u2} M 0 (Zero.toOfNat0.{u2} M (NegZeroClass.toZero.{u2} M (SubNegZeroMonoid.toNegZeroClass.{u2} M (SubtractionMonoid.toSubNegZeroMonoid.{u2} M (SubtractionCommMonoid.toSubtractionMonoid.{u2} M (AddCommGroup.toDivisionAddCommMonoid.{u2} M _inst_3)))))))) Case conversion may be inaccurate. Consider using '#align submodule.ne_zero_of_ortho Submodule.ne_zero_of_orthoₓ'. -/ theorem ne_zero_of_ortho {x : M} {N : Submodule R M} (ortho : ∀ (c : R), ∀ y ∈ N, c • x + y = (0 : M) → c = 0) : x ≠ 0 := mt (fun h => show x ∈ N from h.symm ▸ N.zero_mem) (not_mem_of_ortho ortho) #align submodule.ne_zero_of_ortho Submodule.ne_zero_of_ortho end IsDomain section OrderedMonoid variable [Semiring R] #print Submodule.toOrderedAddCommMonoid /- /-- A submodule of an `ordered_add_comm_monoid` is an `ordered_add_comm_monoid`. -/ instance toOrderedAddCommMonoid {M} [OrderedAddCommMonoid M] [Module R M] (S : Submodule R M) : OrderedAddCommMonoid S := Subtype.coe_injective.OrderedAddCommMonoid coe rfl (fun _ _ => rfl) fun _ _ => rfl #align submodule.to_ordered_add_comm_monoid Submodule.toOrderedAddCommMonoid -/ #print Submodule.toLinearOrderedAddCommMonoid /- /-- A submodule of a `linear_ordered_add_comm_monoid` is a `linear_ordered_add_comm_monoid`. -/ instance toLinearOrderedAddCommMonoid {M} [LinearOrderedAddCommMonoid M] [Module R M] (S : Submodule R M) : LinearOrderedAddCommMonoid S := Subtype.coe_injective.LinearOrderedAddCommMonoid coe rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align submodule.to_linear_ordered_add_comm_monoid Submodule.toLinearOrderedAddCommMonoid -/ #print Submodule.toOrderedCancelAddCommMonoid /- /-- A submodule of an `ordered_cancel_add_comm_monoid` is an `ordered_cancel_add_comm_monoid`. -/ instance toOrderedCancelAddCommMonoid {M} [OrderedCancelAddCommMonoid M] [Module R M] (S : Submodule R M) : OrderedCancelAddCommMonoid S := Subtype.coe_injective.OrderedCancelAddCommMonoid coe rfl (fun _ _ => rfl) fun _ _ => rfl #align submodule.to_ordered_cancel_add_comm_monoid Submodule.toOrderedCancelAddCommMonoid -/ #print Submodule.toLinearOrderedCancelAddCommMonoid /- /-- A submodule of a `linear_ordered_cancel_add_comm_monoid` is a `linear_ordered_cancel_add_comm_monoid`. -/ instance toLinearOrderedCancelAddCommMonoid {M} [LinearOrderedCancelAddCommMonoid M] [Module R M] (S : Submodule R M) : LinearOrderedCancelAddCommMonoid S := Subtype.coe_injective.LinearOrderedCancelAddCommMonoid coe rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align submodule.to_linear_ordered_cancel_add_comm_monoid Submodule.toLinearOrderedCancelAddCommMonoid -/ end OrderedMonoid section OrderedGroup variable [Ring R] #print Submodule.toOrderedAddCommGroup /- /-- A submodule of an `ordered_add_comm_group` is an `ordered_add_comm_group`. -/ instance toOrderedAddCommGroup {M} [OrderedAddCommGroup M] [Module R M] (S : Submodule R M) : OrderedAddCommGroup S := Subtype.coe_injective.OrderedAddCommGroup coe rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align submodule.to_ordered_add_comm_group Submodule.toOrderedAddCommGroup -/ #print Submodule.toLinearOrderedAddCommGroup /- /-- A submodule of a `linear_ordered_add_comm_group` is a `linear_ordered_add_comm_group`. -/ instance toLinearOrderedAddCommGroup {M} [LinearOrderedAddCommGroup M] [Module R M] (S : Submodule R M) : LinearOrderedAddCommGroup S := Subtype.coe_injective.LinearOrderedAddCommGroup coe rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl #align submodule.to_linear_ordered_add_comm_group Submodule.toLinearOrderedAddCommGroup -/ end OrderedGroup end Submodule namespace Submodule variable [DivisionRing S] [Semiring R] [AddCommMonoid M] [Module R M] variable [SMul S R] [Module S M] [IsScalarTower S R M] variable (p : Submodule R M) {s : S} {x y : M} /- warning: submodule.smul_mem_iff -> Submodule.smul_mem_iff is a dubious translation: lean 3 declaration is forall {S : Type.{u1}} {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : DivisionRing.{u1} S] [_inst_2 : Semiring.{u2} R] [_inst_3 : AddCommMonoid.{u3} M] [_inst_4 : Module.{u2, u3} R M _inst_2 _inst_3] [_inst_5 : SMul.{u1, u2} S R] [_inst_6 : Module.{u1, u3} S M (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1)) _inst_3] [_inst_7 : IsScalarTower.{u1, u2, u3} S R M _inst_5 (SMulZeroClass.toHasSmul.{u2, u3} R M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (SMulWithZero.toSmulZeroClass.{u2, u3} R M (MulZeroClass.toHasZero.{u2} R (MulZeroOneClass.toMulZeroClass.{u2} R (MonoidWithZero.toMulZeroOneClass.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_2)))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R _inst_2) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (Module.toMulActionWithZero.{u2, u3} R M _inst_2 _inst_3 _inst_4)))) (SMulZeroClass.toHasSmul.{u1, u3} S M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (SMulWithZero.toSmulZeroClass.{u1, u3} S M (MulZeroClass.toHasZero.{u1} S (MulZeroOneClass.toMulZeroClass.{u1} S (MonoidWithZero.toMulZeroOneClass.{u1} S (Semiring.toMonoidWithZero.{u1} S (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1)))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (MulActionWithZero.toSMulWithZero.{u1, u3} S M (Semiring.toMonoidWithZero.{u1} S (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (Module.toMulActionWithZero.{u1, u3} S M (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1)) _inst_3 _inst_6))))] (p : Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) {s : S} {x : M}, (Ne.{succ u1} S s (OfNat.ofNat.{u1} S 0 (OfNat.mk.{u1} S 0 (Zero.zero.{u1} S (MulZeroClass.toHasZero.{u1} S (NonUnitalNonAssocSemiring.toMulZeroClass.{u1} S (NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring.{u1} S (NonAssocRing.toNonUnitalNonAssocRing.{u1} S (Ring.toNonAssocRing.{u1} S (DivisionRing.toRing.{u1} S _inst_1)))))))))) -> (Iff (Membership.Mem.{u3, u3} M (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) M (Submodule.setLike.{u2, u3} R M _inst_2 _inst_3 _inst_4)) (SMul.smul.{u1, u3} S M (SMulZeroClass.toHasSmul.{u1, u3} S M (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (SMulWithZero.toSmulZeroClass.{u1, u3} S M (MulZeroClass.toHasZero.{u1} S (MulZeroOneClass.toMulZeroClass.{u1} S (MonoidWithZero.toMulZeroOneClass.{u1} S (Semiring.toMonoidWithZero.{u1} S (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1)))))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (MulActionWithZero.toSMulWithZero.{u1, u3} S M (Semiring.toMonoidWithZero.{u1} S (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1))) (AddZeroClass.toHasZero.{u3} M (AddMonoid.toAddZeroClass.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3))) (Module.toMulActionWithZero.{u1, u3} S M (Ring.toSemiring.{u1} S (DivisionRing.toRing.{u1} S _inst_1)) _inst_3 _inst_6)))) s x) p) (Membership.Mem.{u3, u3} M (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) (SetLike.hasMem.{u3, u3} (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) M (Submodule.setLike.{u2, u3} R M _inst_2 _inst_3 _inst_4)) x p)) but is expected to have type forall {S : Type.{u1}} {R : Type.{u2}} {M : Type.{u3}} [_inst_1 : DivisionRing.{u1} S] [_inst_2 : Semiring.{u2} R] [_inst_3 : AddCommMonoid.{u3} M] [_inst_4 : Module.{u2, u3} R M _inst_2 _inst_3] [_inst_5 : SMul.{u1, u2} S R] [_inst_6 : Module.{u1, u3} S M (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1)) _inst_3] [_inst_7 : IsScalarTower.{u1, u2, u3} S R M _inst_5 (SMulZeroClass.toSMul.{u2, u3} R M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (SMulWithZero.toSMulZeroClass.{u2, u3} R M (MonoidWithZero.toZero.{u2} R (Semiring.toMonoidWithZero.{u2} R _inst_2)) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (MulActionWithZero.toSMulWithZero.{u2, u3} R M (Semiring.toMonoidWithZero.{u2} R _inst_2) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (Module.toMulActionWithZero.{u2, u3} R M _inst_2 _inst_3 _inst_4)))) (SMulZeroClass.toSMul.{u1, u3} S M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (SMulWithZero.toSMulZeroClass.{u1, u3} S M (MonoidWithZero.toZero.{u1} S (Semiring.toMonoidWithZero.{u1} S (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1)))) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (MulActionWithZero.toSMulWithZero.{u1, u3} S M (Semiring.toMonoidWithZero.{u1} S (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1))) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (Module.toMulActionWithZero.{u1, u3} S M (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1)) _inst_3 _inst_6))))] (p : Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) {s : S} {x : M}, (Ne.{succ u1} S s (OfNat.ofNat.{u1} S 0 (Zero.toOfNat0.{u1} S (MonoidWithZero.toZero.{u1} S (Semiring.toMonoidWithZero.{u1} S (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1))))))) -> (Iff (Membership.mem.{u3, u3} M (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) M (Submodule.setLike.{u2, u3} R M _inst_2 _inst_3 _inst_4)) (HSMul.hSMul.{u1, u3, u3} S M M (instHSMul.{u1, u3} S M (SMulZeroClass.toSMul.{u1, u3} S M (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (SMulWithZero.toSMulZeroClass.{u1, u3} S M (MonoidWithZero.toZero.{u1} S (Semiring.toMonoidWithZero.{u1} S (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1)))) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (MulActionWithZero.toSMulWithZero.{u1, u3} S M (Semiring.toMonoidWithZero.{u1} S (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1))) (AddMonoid.toZero.{u3} M (AddCommMonoid.toAddMonoid.{u3} M _inst_3)) (Module.toMulActionWithZero.{u1, u3} S M (DivisionSemiring.toSemiring.{u1} S (DivisionRing.toDivisionSemiring.{u1} S _inst_1)) _inst_3 _inst_6))))) s x) p) (Membership.mem.{u3, u3} M (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) (SetLike.instMembership.{u3, u3} (Submodule.{u2, u3} R M _inst_2 _inst_3 _inst_4) M (Submodule.setLike.{u2, u3} R M _inst_2 _inst_3 _inst_4)) x p)) Case conversion may be inaccurate. Consider using '#align submodule.smul_mem_iff Submodule.smul_mem_iffₓ'. -/ theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p := p.toSubMulAction.smul_mem_iff s0 #align submodule.smul_mem_iff Submodule.smul_mem_iff end Submodule #print Subspace /- /-- Subspace of a vector space. Defined to equal `submodule`. -/ abbrev Subspace (R : Type u) (M : Type v) [DivisionRing R] [AddCommGroup M] [Module R M] := Submodule R M #align subspace Subspace -/
Formal statement is: lemma convex_on_subset: "convex_on t f \<Longrightarrow> S \<subseteq> t \<Longrightarrow> convex_on S f" Informal statement is: If $f$ is convex on $t$, and $S \subseteq t$, then $f$ is convex on $S$.
/* Cholesky Decomposition * * Copyright (C) 2000 Thomas Walter * * 3 May 2000: Modified for GSL by Brian Gough * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This source 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. */ /* * Cholesky decomposition of a symmetrix positive definite matrix. * This is useful to solve the matrix arising in * periodic cubic splines * approximating splines * * This algorthm does: * A = L * L' * with * L := lower left triangle matrix * L' := the transposed form of L. * */ #include <config.h> #include <gsl/gsl_math.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_blas.h> #include <gsl/gsl_linalg.h> int gsl_linalg_cholesky_decomp (gsl_matrix * A) { const size_t M = A->size1; const size_t N = A->size2; if (M != N) { GSL_ERROR("cholesky decomposition requires square matrix", GSL_ENOTSQR); } else { size_t i,j,k; int status = 0; /* Do the first 2 rows explicitly. It is simple, and faster. And * one can return if the matrix has only 1 or 2 rows. */ double A_00 = gsl_matrix_get (A, 0, 0); double L_00 = sqrt(A_00); if (A_00 <= 0) { status = GSL_EDOM ; } gsl_matrix_set (A, 0, 0, L_00); if (M > 1) { double A_10 = gsl_matrix_get (A, 1, 0); double A_11 = gsl_matrix_get (A, 1, 1); double L_10 = A_10 / L_00; double diag = A_11 - L_10 * L_10; double L_11 = sqrt(diag); if (diag <= 0) { status = GSL_EDOM; } gsl_matrix_set (A, 1, 0, L_10); gsl_matrix_set (A, 1, 1, L_11); } for (k = 2; k < M; k++) { double A_kk = gsl_matrix_get (A, k, k); for (i = 0; i < k; i++) { double sum = 0; double A_ki = gsl_matrix_get (A, k, i); double A_ii = gsl_matrix_get (A, i, i); gsl_vector_view ci = gsl_matrix_row (A, i); gsl_vector_view ck = gsl_matrix_row (A, k); if (i > 0) { gsl_vector_view di = gsl_vector_subvector(&ci.vector, 0, i); gsl_vector_view dk = gsl_vector_subvector(&ck.vector, 0, i); gsl_blas_ddot (&di.vector, &dk.vector, &sum); } A_ki = (A_ki - sum) / A_ii; gsl_matrix_set (A, k, i, A_ki); } { gsl_vector_view ck = gsl_matrix_row (A, k); gsl_vector_view dk = gsl_vector_subvector (&ck.vector, 0, k); double sum = gsl_blas_dnrm2 (&dk.vector); double diag = A_kk - sum * sum; double L_kk = sqrt(diag); if (diag <= 0) { status = GSL_EDOM; } gsl_matrix_set (A, k, k, L_kk); } } /* Now copy the transposed lower triangle to the upper triangle, * the diagonal is common. */ for (i = 1; i < M; i++) { for (j = 0; j < i; j++) { double A_ij = gsl_matrix_get (A, i, j); gsl_matrix_set (A, j, i, A_ij); } } if (status == GSL_EDOM) { GSL_ERROR ("matrix must be positive definite", GSL_EDOM); } return GSL_SUCCESS; } } int gsl_linalg_cholesky_solve (const gsl_matrix * LLT, const gsl_vector * b, gsl_vector * x) { if (LLT->size1 != LLT->size2) { GSL_ERROR ("cholesky matrix must be square", GSL_ENOTSQR); } else if (LLT->size1 != b->size) { GSL_ERROR ("matrix size must match b size", GSL_EBADLEN); } else if (LLT->size2 != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else { /* Copy x <- b */ gsl_vector_memcpy (x, b); /* Solve for c using forward-substitution, L c = b */ gsl_blas_dtrsv (CblasLower, CblasNoTrans, CblasNonUnit, LLT, x); /* Perform back-substitution, U x = c */ gsl_blas_dtrsv (CblasUpper, CblasNoTrans, CblasNonUnit, LLT, x); return GSL_SUCCESS; } } int gsl_linalg_cholesky_svx (const gsl_matrix * LLT, gsl_vector * x) { if (LLT->size1 != LLT->size2) { GSL_ERROR ("cholesky matrix must be square", GSL_ENOTSQR); } else if (LLT->size2 != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else { /* Solve for c using forward-substitution, L c = b */ gsl_blas_dtrsv (CblasLower, CblasNoTrans, CblasNonUnit, LLT, x); /* Perform back-substitution, U x = c */ gsl_blas_dtrsv (CblasUpper, CblasNoTrans, CblasNonUnit, LLT, x); return GSL_SUCCESS; } }
module main where open import Not-named-according-to-the-Haskell-lexical-syntax main = return Not-named-according-to-the-Haskell-lexical-syntax.unit -- The following code once triggered an MAlonzo bug resulting in the -- error message "Panic: ... no such name main.M.d". module M where data D : Set where d : D
! { dg-do compile } ! ! PR 44211: [OOP] ICE with TBP of pointer component of derived type array ! ! Original test case by Hans-Werner Boschmann <[email protected]> ! Modified by Janus Weil <[email protected]> module ice_module type::ice_type class(ice_type),pointer::next contains procedure::ice_sub procedure::ice_fun end type ice_type contains subroutine ice_sub(this) class(ice_type)::this end subroutine integer function ice_fun(this) class(ice_type)::this end function subroutine ice() type(ice_type),dimension(2)::ice_array call ice_array(1)%next%ice_sub() print *,ice_array(2)%next%ice_fun() end subroutine end module ice_module ! { dg-final { cleanup-modules "ice_module" } }
(* Property from Case-Analysis for Rippling and Inductive Proof, Moa Johansson, Lucas Dixon and Alan Bundy, ITP 2010. 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_74 imports "../../Test_Base" begin datatype 'a list = nil2 | cons2 "'a" "'a list" datatype Nat = Z | S "Nat" fun x :: "'a list => 'a list => 'a list" where "x (nil2) z = z" | "x (cons2 z2 xs) z = cons2 z2 (x xs z)" fun take :: "Nat => 'a list => 'a list" where "take (Z) z = nil2" | "take (S z2) (nil2) = nil2" | "take (S z2) (cons2 x2 x3) = cons2 x2 (take z2 x3)" fun rev :: "'a list => 'a list" where "rev (nil2) = nil2" | "rev (cons2 z xs) = x (rev xs) (cons2 z (nil2))" fun len :: "'a list => Nat" where "len (nil2) = Z" | "len (cons2 z xs) = S (len xs)" fun drop :: "Nat => 'a list => 'a list" where "drop (Z) z = z" | "drop (S z2) (nil2) = nil2" | "drop (S z2) (cons2 x2 x3) = drop z2 x3" fun t2 :: "Nat => Nat => Nat" where "t2 (Z) z = Z" | "t2 (S z2) (Z) = S z2" | "t2 (S z2) (S x2) = t2 z2 x2" theorem property0 : "((rev (take i xs)) = (drop (t2 (len xs) i) (rev xs)))" oops end
{-# LANGUAGE RecordWildCards #-} import Data.Complex import Control.Monad.Trans.Except import Foreign.C.Types import Data.Word import System.IO import Data.Monoid import Control.Error.Util import Data.Vector.Storable as VS hiding ((++)) import Data.Vector.Generic as VG hiding ((++)) import Pipes import qualified Pipes.Prelude as P import Foreign.Storable.Complex import Options.Applicative import SDR.Filter import SDR.RTLSDRStream import SDR.Util import SDR.Demod import SDR.Pulse import SDR.Serialize import SDR.ArgUtils import SDR.CPUID --The filter coefficients are stored in another module import Coeffs data Options = Options { frequency :: Word32, input :: Maybe FilePath, output :: Maybe FilePath } optParser :: Parser Options optParser = Options <$> option (fmap fromIntegral parseSize) ( long "frequency" <> short 'f' <> metavar "FREQUENCY" <> help "Frequency to tune to" ) <*> optional (strOption ( long "input" <> short 'i' <> metavar "FILENAME" <> help "Input filename" )) <*> optional (strOption ( long "output" <> short 'o' <> metavar "FILENAME" <> help "Output filename" )) opt :: ParserInfo Options opt = info (helper <*> optParser) (fullDesc <> progDesc "Receive and demodulate broadcast FM radio" <> header "RTLSDR FM") bufNum = 1 bufLen = 16384 samples = fromIntegral (bufNum * bufLen) `quot` 2 decimation = 8 sqd = samples `quot` decimation {- Sampling frequency of the input is 1280 khz This is decimated by a factor of 8 and then demodulated Sampling frequency of demodulated signal is 160 khz Need audio output at 48 khz Resampling factor is 48/160 == 3/10 FM pilot tone at 19khz (0.3958 * 48) Start audio filter cutoff at 15khz (0.3125 * 48) -} doIt Options{..} = do info <- lift getCPUInfo let rtlstream = do str <- sdrStream (defaultRTLSDRParams frequency 1280000) bufNum bufLen return $ str >-> P.map (interleavedIQUnsignedByteToFloatFast info) let fileStream fname = lift $ do h <- openFile fname ReadMode return $ fromHandle samples h --TODO: how do I ensure these handles get closed? inputSpectrum <- maybe rtlstream fileStream input let fileSink fname = do h <- openFile fname ReadMode return $ toHandle h sink <- lift $ maybe pulseAudioSink fileSink output deci <- lift $ fastDecimatorC info decimation coeffsRFDecim resp <- lift $ fastResamplerR info 3 10 coeffsAudioResampler filt <- lift $ fastFilterSymR info coeffsAudioFilter --Build the pipeline let pipeline :: Effect IO () pipeline = inputSpectrum >-> firDecimator deci sqd >-> fmDemod >-> firResampler resp sqd >-> firFilter filt sqd >-> P.map (VG.map (* 0.2)) >-> sink --Run the pipeline lift $ runEffect pipeline main = execParser opt >>= exceptT putStrLn return . doIt
function strs = slstrsplit(srcstr, delimiters) %SLSTRSPLIT splits a string into cell array of strings by delimiters % % $ Syntax $ % - strs = slstrsplit(srcstr, delimiters) % % $ Arguments $ % - srcstr: the source string % - delimiters: the array of delimiting chars % % $ Description $ % - strs = slstrsplit(srcstr, delimiters) splits the source string into % a cell array of parts, which are delimited by the chars in % delimiters. % % $ Remarks $ % - If for adjacent delimiters, the between will not will extracted. % - No further processing is applied, you can use functions like % slcompresstext to achieve these goals. % % $ History $ % - Created by Dahua Lin, on Aug 13, 2006 % %% determine delimiter positions n0 = length(srcstr); is_delimiter = false(n0, 1); nd = length(delimiters); for i = 1 : nd ch = delimiters(i); is_delimiter(srcstr == ch) = true; end dps = find(is_delimiter); dps = dps(:)'; %% extract parts if isempty(dps) strs = {srcstr}; else sps = [1, dps+1]; eps = [dps-1, n0]; fv = find(sps <= eps); if ~isempty(fv) sps = sps(fv); eps = eps(fv); np = length(fv); strs = cell(np, 1); for i = 1 : np strs{i} = srcstr(sps(i):eps(i)); end else strs = {}; end end
MODULE m_vxcwb91 !.....----------------------------------------------------------------- !.....pw91 exchange-correlation potential in hartree. !.....------------------------------------------------------------------ CONTAINS SUBROUTINE vxcwb91( & jspins,mirm,irmx,rh,agr,agru,agrd, & g2r,g2ru,g2rd,gggr,gggru,gggrd,gzgr, & vx,vxc, & idsprs,isprsv,sprsv) USE m_corl91 USE m_corg91 USE m_xch91 USE m_constants, ONLY: pi_const IMPLICIT NONE ! .. Arguments .. INTEGER, INTENT (IN) :: jspins,irmx,mirm,isprsv,idsprs REAL, INTENT (IN) :: sprsv REAL, INTENT (IN) :: rh(mirm,jspins) REAL, INTENT (IN) :: agr(mirm),agru(mirm),agrd(mirm) REAL, INTENT (IN) :: g2r(mirm),g2ru(mirm),g2rd(mirm) REAL, INTENT (IN) :: gggr(mirm),gggru(mirm) REAL, INTENT (IN) :: gggrd(mirm),gzgr(mirm) REAL, INTENT (OUT) ::vx(mirm,jspins),vxc(mirm,jspins) ! .. local variables REAL :: pi,ro,zta,alf,alfc,c13,c23,c43,c53, & cedg,cedl,dbrod,dbrou,dsprs,ec,ecrs,eczta,fk,gz, & ro13,ro2,rod,rod3,rod43,rod53,rou,rou3,rou43,rou53, & rs,sd,sk,su,tc,td,tksg,tu,uc,ud,uu,vc, & vcgd,vcgu,vcld,vclu,vxgd,vxgu,vxld, & vxlu,wc,xced,xedg,xedgd,xedgu,xedl,xedld,xedlu, & rou13,rod13,xcptu,xcptd INTEGER :: i REAL, PARAMETER :: sml = 1.e-14 REAL, PARAMETER :: huges = 1.e+6 !.....----------------------------------------------------------------- !.....huges: if su(sdw).gt.huges, grad.expansion calc.non-excuted. !.....----------------------------------------------------------------- do 300 i = 1,irmx if(jspins == 1) then rou=rh(i,1)/2 rou=max(rou,sml) rod=rou else rou=rh(i,1) rod=rh(i,jspins) rou=max(rou,sml) rod=max(rod,sml) endif zta=(rou-rod)/(rou+rod) if(zta > 1.e0-sml) zta = 1.e0 - sml if(zta < -1.e0-sml) zta = -1.e0 + sml !..... ! vxlu,vxld,vxgu,vxgd: exchange potential in ry.(local,grad), !c (up,dw). ! vclu,vcld,vcgu,vcgd: correl. potential in ry.(local,grad), !c (up,dw). ! all later in hartree. !..... vxlu = 0.0e0 vclu = 0.0e0 vxld = 0.0e0 vcld = 0.0e0 vxgu = 0.0e0 vcgu = 0.0e0 vxgd = 0.0e0 vcgd = 0.0e0 !..... ro = rh(i,1) IF (ro < sml) THEN ro = sml zta = 0.e0 GO TO 200 ENDIF !..... c13 = 1.e0/3.e0 c23 = 2.e0/3.e0 c43 = 4.e0/3.e0 c53 = 5.e0/3.e0 !..... alf=-3*(3/4*pai)**(1/3). alf = -1.861051473e0 !..... ro2 = ro*ro ro13 = ro**c13 !..... rou = ro* (1.e0+zta)/2.e0 rou3 = rou**3 rou13 = rou**c13 rou43 = rou**c43 !..... rod = ro - rou rod3 = rod**3 rod13 = rod**c13 rod43 = rod**c43 !..... ! gr2=drr*drr ! gr2u=drru**2 ! drrd=drr-drru ! gr2d=drrd**2 ! ddrrd=ddrr-ddrru !..... !..... gz,gz2,gz3: for wang-perdew ssf. gz = ((1.e0+zta)**c23+ (1.e0-zta)**c23)/2.e0 !..... !..... rs = 0.620350491e0/ro13 !..... !..... exchange-potential, vxp,vxlu,vxld: v-exchange-(para,up,dw). vxlu = c43*alf*rou13 vxld = c43*alf*rod13 !..... !.... .gradient correction. !..... if(abs(agr(i)) < sml) go to 200 !..... !..... dsprs = 1.e0 if(idsprs == 1) dsprs = 1.e-19 if(isprsv == 1) dsprs = dsprs*sprsv !..... ! agr,agru,agrd: abs(grad(rho)), for all, up, and down. !c gr2,gr2u,gr2d: grad(rho_all)**2, grad(rho_up)**2, grad(rho_d)**2. ! g2r,g2ru,g2rd: laplacian rho_all, _up and _down. ! gggru,-d: grad(rho)*grad(abs(grad(rho))) for all,up and down. ! grgru,-d: grad(rho_all)*grad(rhor_up) and for down. ! g2r=ddrr+2*drr/rv !..... rou53 = rou**c53 !..... !..... edrru: d(abs(d(rou)/dr))/dr, edrrd for down. ! edrru=ddrru ! if(drru.lt.0.) edrru=-ddrru !..... ! agr,agbru,-d: abs(grad(rho)),for rou, rod. ! gggru,-d: grad(rho)*grad(abs(grad(rho))) for up and down. !..... su:at ro=2*rou. 1/(2(3*pai**2)**(1/3))*|grad(rou)|/rou**(4/3). su = 0.128278244e0*agru(i)/rou43 if(su > huges) go to 200 ! g2ru=ddrru+2*drru/rv tu = .016455307e0*g2ru(i)/rou53 uu = 0.002110857e0*gggru(i)/rou3 dbrou = rou*2 call xch91(dbrou,su,uu,tu,xedlu,xedgu,vxlu,vxgu) vxgu = dsprs*vxgu !..... rod53 = rod**c53 ! edrrd=ddrrd ! if(drrd.lt.0.) edrrd=-ddrrd sd = 0.128278244e0*agrd(i)/rod43 if(sd > huges) go to 200 ! g2rd=ddrrd+2*drrd/rv td = .016455307e0*g2rd(i)/rod53 ud = 0.002110857e0*gggrd(i)/rod3 dbrod = rod*2 call xch91(dbrod,sd,ud,td,xedld,xedgd,vxld,vxgd) vxgd = dsprs*vxgd !.... cro: c(n) of (6),phys.rev..b33,8822('86). in ry. !.... dcdr: d(cro)/d(ro). !..... 0.001625816=1.745*f(=0.11)*cro(rs=0). ! pw91 call corl91(rs,zta,ec,vclu,vcld,ecrs,eczta,alfc) vclu = vclu*2.e0 vcld = vcld*2.e0 fk = 1.91915829e0/rs sk = sqrt(4.e0*fk/pi_const) tksg = 2.e0*sk*gz tc = agr(i)/ (ro*tksg) uc = gggr(i)/ (ro2*tksg**3) vc = g2r(i)/ (ro*tksg**2) wc = gzgr(i)/ (ro*tksg**2) call corg91(fk,sk,gz,ec,ecrs,eczta,rs,zta,tc,uc,vc,wc,cedg, & vcgu,vcgd) vcgu = dsprs*vcgu*2.e0 vcgd = dsprs*vcgd*2.e0 200 continue xcptu = vxlu + vclu + vxgu + vcgu xcptd = vxld + vcld + vxgd + vcgd ! change to hartree. vx(i,1) = vxlu + vxgu vx(i,jspins) = vxld + vxgd vxc(i,1) = xcptu vxc(i,jspins) = xcptd 300 END DO END SUBROUTINE vxcwb91 END MODULE m_vxcwb91
{-# OPTIONS --without-K --termination-depth=2 #-} open import HoTT open import cw.CW module cw.Sphere where CWSphere-skel : ∀ n → Skeleton {lzero} n CWSphere : ℕ → Type₀ CWSphere n = ⟦ CWSphere-skel n ⟧ Sphere-to-CWSphere : (n : ℕ) → Sphere n → CWSphere n CWSphere-skel O = Bool CWSphere-skel (S n) = (CWSphere-skel n , Bool , cst (Sphere-to-CWSphere n)) {- mapping: hub true <-> north hub false <-> south incl _ -> north spoke true x -> idp spoke fales x -> merid x ! spoke true x ∙ spoke false x <- merid x -} private module PosToCW n = SuspensionRec {C = CWSphere (S n)} (hub true) (hub false) (λ x → (! (spoke true x)) ∙' spoke false x) Sphere-to-CWSphere O = idf _ Sphere-to-CWSphere (S n) = PosToCW.f n {- Now proving the equivalence -} private CWSphere-to-Sphere-incl : ∀ n → CWSphere n → Sphere (S n) CWSphere-to-Sphere-incl _ _ = north CWSphere-to-Sphere-hub : ∀ n → Bool → Sphere (S n) CWSphere-to-Sphere-hub _ true = north CWSphere-to-Sphere-hub _ false = south CWSphere-to-Sphere-spoke : ∀ n (b : Bool) (x : Sphere n) → CWSphere-to-Sphere-incl n (Sphere-to-CWSphere n x) == CWSphere-to-Sphere-hub n b CWSphere-to-Sphere-spoke _ true _ = idp CWSphere-to-Sphere-spoke _ false x = merid x module PosFromCW n = AttachedRec {attaching = cst (Sphere-to-CWSphere n)} (CWSphere-to-Sphere-incl n) (CWSphere-to-Sphere-hub n) (CWSphere-to-Sphere-spoke n) CWSphere-to-Sphere : ∀ n → CWSphere n → Sphere n CWSphere-to-Sphere O = idf _ CWSphere-to-Sphere (S n) = PosFromCW.f n private from-to : ∀ n x → CWSphere-to-Sphere n (Sphere-to-CWSphere n x) == x from-to O _ = idp from-to (S n) = SuspensionElim.f idp idp path where to = Sphere-to-CWSphere (S n) from = CWSphere-to-Sphere (S n) module To = PosToCW n module From = PosFromCW n path : ∀ x → idp == idp [ (λ x → from (to x) == x) ↓ merid x ] path x = ↓-app=idf-in $ ! $ ap (from ∘ to) (merid x) ∙ idp =⟨ ∙-unit-r $ ap (from ∘ to) (merid x) ⟩ ap (from ∘ to) (merid x) =⟨ ap-∘ from to (merid x) ⟩ ap from (ap to (merid x)) =⟨ To.merid-β x |in-ctx ap from ⟩ ap from (! (spoke true x) ∙' spoke false x) =⟨ ap-∙' from (! (spoke true x)) (spoke false x) ⟩ ap from (! (spoke true x)) ∙' ap from (spoke false x) =⟨ ap-! from (spoke true x) |in-ctx (λ p → p ∙' ap from (spoke false x)) ⟩ ! (ap from (spoke true x)) ∙' ap from (spoke false x) =⟨ From.spoke-β true x |in-ctx (λ p → ! p ∙' ap from (spoke false x)) ⟩ idp ∙' ap from (spoke false x) =⟨ From.spoke-β false x |in-ctx (idp ∙'_) ⟩ idp ∙' merid x ∎ Sphere-to-CWSphere-is-equiv : ∀ n → is-equiv (Sphere-to-CWSphere n) private to-from : ∀ n x → Sphere-to-CWSphere n (CWSphere-to-Sphere n x) == x Sphere-to-CWSphere-is-equiv n = is-eq _ (CWSphere-to-Sphere n) (to-from n) (from-to n) to-from O _ = idp to-from (S n) = AttachedElim.f to-from-incl to-from-hub to-from-spoke where to = Sphere-to-CWSphere (S n) from = CWSphere-to-Sphere (S n) module To = PosToCW n module From = PosFromCW n to-from-incl : ∀ (c : CWSphere n) → to (from (incl c)) == incl c to-from-incl c = ! (spoke true (CWSphere-to-Sphere n c)) ∙ ap incl (is-equiv.f-g (Sphere-to-CWSphere-is-equiv n) c) to-from-hub : ∀ b → to (from (hub b)) == hub b to-from-hub true = idp to-from-hub false = idp to-from-incl-to : ∀ (x : Sphere n) → to-from-incl (Sphere-to-CWSphere n x) == ! (spoke true x) to-from-incl-to x = ! (spoke true (CWSphere-to-Sphere n (Sphere-to-CWSphere n x))) ∙ ap incl (is-equiv.f-g (Sphere-to-CWSphere-is-equiv n) (Sphere-to-CWSphere n x)) =⟨ ! $ is-equiv.adj (Sphere-to-CWSphere-is-equiv n) x |in-ctx (λ p → ! (spoke true (CWSphere-to-Sphere n (Sphere-to-CWSphere n x))) ∙ ap incl p) ⟩ ! (spoke true (CWSphere-to-Sphere n (Sphere-to-CWSphere n x))) ∙ ap incl (ap (Sphere-to-CWSphere n) (is-equiv.g-f (Sphere-to-CWSphere-is-equiv n) x)) =⟨ ! $ ap-∘ incl (Sphere-to-CWSphere n) (is-equiv.g-f (Sphere-to-CWSphere-is-equiv n) x) |in-ctx (λ p → ! (spoke true (CWSphere-to-Sphere n (Sphere-to-CWSphere n x))) ∙ p) ⟩ ! (spoke true (CWSphere-to-Sphere n (Sphere-to-CWSphere n x))) ∙ ap (incl ∘ Sphere-to-CWSphere n) (is-equiv.g-f (Sphere-to-CWSphere-is-equiv n) x) =⟨ htpy-natural-cst=app (λ x → ! (spoke true x)) (is-equiv.g-f (Sphere-to-CWSphere-is-equiv n) x) ⟩ ! (spoke true x) ∎ to-from-spoke : ∀ (b : Bool) (x : Sphere n) → to-from-incl (Sphere-to-CWSphere n x) == to-from-hub b [ (λ x → to (from x) == x) ↓ spoke b x ] to-from-spoke true x = ↓-app=idf-in $ to-from-incl (Sphere-to-CWSphere n x) ∙' spoke true x =⟨ to-from-incl-to x |in-ctx (λ p → p ∙' spoke true x) ⟩ ! (spoke true x) ∙' spoke true x =⟨ !-inv'-l (spoke true x) ⟩ idp =⟨ ! $ From.spoke-β true x |in-ctx (λ p → ap to p ∙ idp) ⟩ ap to (ap from (spoke true x)) ∙ idp =⟨ ∘-ap to from (spoke true x) |in-ctx (λ p → p ∙ idp) ⟩ ap (to ∘ from) (spoke true x) ∙ idp ∎ to-from-spoke false x = ↓-app=idf-in $ to-from-incl (Sphere-to-CWSphere n x) ∙' spoke false x =⟨ to-from-incl-to x |in-ctx (λ p → p ∙' spoke false x) ⟩ ! (spoke true x) ∙' spoke false x =⟨ ! $ To.merid-β x ⟩ ap to (merid x) =⟨ ! $ From.spoke-β false x |in-ctx (ap to) ⟩ ap to (ap from (spoke false x)) =⟨ ∘-ap to from (spoke false x) ⟩ ap (to ∘ from) (spoke false x) =⟨ ! $ ∙-unit-r _ ⟩ ap (to ∘ from) (spoke false x) ∙ idp ∎ Sphere-equiv-CWSphere : ∀ n → Sphere n ≃ CWSphere n Sphere-equiv-CWSphere n = _ , Sphere-to-CWSphere-is-equiv n CWSphere-has-dec-cells : ∀ n → has-dec-cells (CWSphere-skel n) CWSphere-has-dec-cells 0 = Bool-has-dec-eq CWSphere-has-dec-cells (S n) = CWSphere-has-dec-cells n , Bool-has-dec-eq CWSphere-is-aligned : ∀ n → is-aligned (CWSphere-skel n) CWSphere-is-aligned 0 = lift tt CWSphere-is-aligned 1 = lift tt CWSphere-is-aligned 2 = lift tt , (λ _ → true , spoke true true) CWSphere-is-aligned (S (S (S n))) = CWSphere-is-aligned (S (S n)) , (λ _ → hub true , spoke true north)
// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // 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/. #include <chrono> #include <functional> #include <iomanip> #include <forward_list> #include <boost/system/error_code.hpp> #include <vsomeip/constants.hpp> #include <vsomeip/primitive_types.hpp> #include <vsomeip/runtime.hpp> #include <vsomeip/error.hpp> #include <vsomeip/internal/logger.hpp> #include "../include/routing_manager_stub.hpp" #include "../include/routing_manager_stub_host.hpp" #include "../include/remote_subscription.hpp" #include "../../configuration/include/configuration.hpp" #include "../../security/include/security.hpp" #include "../../endpoints/include/local_server_endpoint_impl.hpp" #include "../../endpoints/include/endpoint_manager_impl.hpp" #include "../../utility/include/byteorder.hpp" #include "../../utility/include/utility.hpp" #include "../implementation/message/include/payload_impl.hpp" namespace vsomeip_v3 { const std::vector<byte_t> routing_manager_stub::its_ping_( { VSOMEIP_PING, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); routing_manager_stub::routing_manager_stub( routing_manager_stub_host *_host, const std::shared_ptr<configuration>& _configuration) : host_(_host), io_(_host->get_io()), watchdog_timer_(_host->get_io()), client_id_timer_(_host->get_io()), endpoint_(nullptr), local_receiver_(nullptr), configuration_(_configuration), is_socket_activated_(false), client_registration_running_(false), max_local_message_size_(configuration_->get_max_message_size_local()), configured_watchdog_timeout_(configuration_->get_watchdog_timeout()), pinged_clients_timer_(io_), pending_security_update_id_(0) { } routing_manager_stub::~routing_manager_stub() { } void routing_manager_stub::init() { init_routing_endpoint(); } void routing_manager_stub::start() { { std::lock_guard<std::mutex> its_lock(used_client_ids_mutex_); used_client_ids_ = utility::get_used_client_ids(); // Wait VSOMEIP_MAX_CONNECT_TIMEOUT * 2 and expect after that time // that all client_ids are used have to be connected to the routing. // Otherwise they can be marked as "erroneous client". client_id_timer_.expires_from_now(std::chrono::milliseconds(VSOMEIP_MAX_CONNECT_TIMEOUT * 2)); client_id_timer_.async_wait( std::bind( &routing_manager_stub::on_client_id_timer_expired, std::dynamic_pointer_cast<routing_manager_stub>(shared_from_this()), std::placeholders::_1)); } if (!endpoint_) { // application has been stopped and started again init_routing_endpoint(); } if (endpoint_) { endpoint_->start(); } client_registration_running_ = true; client_registration_thread_ = std::make_shared<std::thread>( std::bind(&routing_manager_stub::client_registration_func, this)); if (configuration_->is_watchdog_enabled()) { VSOMEIP_INFO << "Watchdog is enabled : Timeout in ms = " << configuration_->get_watchdog_timeout() << " : Allowed missing pongs = " << configuration_->get_allowed_missing_pongs() << "."; start_watchdog(); } else { VSOMEIP_INFO << "Watchdog is disabled!"; } { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); routing_info_[host_->get_client()].first = 0; } } void routing_manager_stub::stop() { { std::lock_guard<std::mutex> its_lock(client_registration_mutex_); client_registration_running_ = false; client_registration_condition_.notify_one(); } if (client_registration_thread_->joinable()) { client_registration_thread_->join(); } { std::lock_guard<std::mutex> its_lock(watchdog_timer_mutex_); watchdog_timer_.cancel(); } { std::lock_guard<std::mutex> its_lock(used_client_ids_mutex_); client_id_timer_.cancel(); } if( !is_socket_activated_) { endpoint_->stop(); endpoint_ = nullptr; std::stringstream its_endpoint_path; its_endpoint_path << utility::get_base_path(configuration_) << std::hex << VSOMEIP_ROUTING_CLIENT; #ifdef _WIN32 ::_unlink(its_endpoint_path.str().c_str()); #else if (-1 == ::unlink(its_endpoint_path.str().c_str())) { VSOMEIP_ERROR << "routing_manager_stub::stop() unlink failed (" << its_endpoint_path.str() << "): "<< std::strerror(errno); } #endif } if(local_receiver_) { local_receiver_->stop(); local_receiver_ = nullptr; std::stringstream its_local_receiver_path; its_local_receiver_path << utility::get_base_path(configuration_) << std::hex << host_->get_client(); #ifdef _WIN32 ::_unlink(its_local_receiver_path.str().c_str()); #else if (-1 == ::unlink(its_local_receiver_path.str().c_str())) { VSOMEIP_ERROR << "routing_manager_stub::stop() unlink (local receiver) failed (" << its_local_receiver_path.str() << "): "<< std::strerror(errno); } #endif } } void routing_manager_stub::on_message(const byte_t *_data, length_t _size, endpoint *_receiver, const boost::asio::ip::address &_destination, client_t _bound_client, credentials_t _credentials, const boost::asio::ip::address &_remote_address, std::uint16_t _remote_port) { (void)_receiver; (void)_destination; (void)_remote_address; (void) _remote_port; #if 0 std::stringstream msg; msg << "rms::on_message: "; for (length_t i = 0; i < _size; ++i) msg << std::hex << std::setw(2) << std::setfill('0') << (int)_data[i] << " "; VSOMEIP_INFO << msg.str(); #endif std::uint32_t its_sender_uid = std::get<0>(_credentials); std::uint32_t its_sender_gid = std::get<1>(_credentials); if (VSOMEIP_COMMAND_SIZE_POS_MAX < _size) { byte_t its_command; client_t its_client; std::string its_client_endpoint; service_t its_service; instance_t its_instance; method_t its_method; eventgroup_t its_eventgroup; event_t its_notifier; event_type_e its_event_type; bool is_provided(false); major_version_t its_major; minor_version_t its_minor; std::shared_ptr<payload> its_payload; const byte_t *its_data; uint32_t its_size; bool its_reliable(false); client_t its_client_from_header; client_t its_target_client; client_t its_subscriber; uint8_t its_check_status(0); std::uint16_t its_subscription_id(PENDING_SUBSCRIPTION_ID); offer_type_e its_offer_type; its_command = _data[VSOMEIP_COMMAND_TYPE_POS]; std::memcpy(&its_client, &_data[VSOMEIP_COMMAND_CLIENT_POS], sizeof(its_client)); if (security::get()->is_enabled() && _bound_client != its_client) { VSOMEIP_WARNING << "vSomeIP Security: routing_manager_stub::on_message: " << "Routing Manager received a message from client " << std::hex << std::setw(4) << std::setfill('0') << its_client << " with command " << (uint32_t)its_command << " which doesn't match the bound client " << std::setw(4) << std::setfill('0') << _bound_client << " ~> skip message!"; return; } std::memcpy(&its_size, &_data[VSOMEIP_COMMAND_SIZE_POS_MIN], sizeof(its_size)); if (its_size <= _size - VSOMEIP_COMMAND_HEADER_SIZE) { switch (its_command) { case VSOMEIP_REGISTER_APPLICATION: if (_size != VSOMEIP_REGISTER_APPLICATION_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a REGISTER_APPLICATION command with wrong size ~> skip!"; break; } update_registration(its_client, registration_type_e::REGISTER); break; case VSOMEIP_DEREGISTER_APPLICATION: if (_size != VSOMEIP_DEREGISTER_APPLICATION_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a DEREGISTER_APPLICATION command with wrong size ~> skip!"; break; } update_registration(its_client, registration_type_e::DEREGISTER); break; case VSOMEIP_PONG: if (_size != VSOMEIP_PONG_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a PONG command with wrong size ~> skip!"; break; } on_pong(its_client); VSOMEIP_TRACE << "PONG(" << std::hex << std::setw(4) << std::setfill('0') << its_client << ")"; break; case VSOMEIP_OFFER_SERVICE: if (_size != VSOMEIP_OFFER_SERVICE_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a OFFER_SERVICE command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_major, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_major)); std::memcpy(&its_minor, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 5], sizeof(its_minor)); if (security::get()->is_offer_allowed(its_sender_uid, its_sender_gid, its_client, its_service, its_instance)) { host_->offer_service(its_client, its_service, its_instance, its_major, its_minor); } else { VSOMEIP_WARNING << "vSomeIP Security: Client 0x" << std::hex << its_client << " : routing_manager_stub::on_message: isn't allowed to offer " << "the following service/instance " << its_service << "/" << its_instance << " ~> Skip offer!"; } break; case VSOMEIP_STOP_OFFER_SERVICE: if (_size != VSOMEIP_STOP_OFFER_SERVICE_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a STOP_OFFER_SERVICE command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_major, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_major)); std::memcpy(&its_minor, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 5], sizeof(its_minor)); host_->stop_offer_service(its_client, its_service, its_instance, its_major, its_minor); break; case VSOMEIP_SUBSCRIBE: if (_size != VSOMEIP_SUBSCRIBE_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a SUBSCRIBE command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_eventgroup, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_eventgroup)); std::memcpy(&its_major, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(its_major)); std::memcpy(&its_notifier, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 7], sizeof(its_notifier)); if (its_notifier == ANY_EVENT) { if (host_->is_subscribe_to_any_event_allowed(_credentials, its_client, its_service, its_instance, its_eventgroup)) { host_->subscribe(its_client, its_sender_uid, its_sender_gid, its_service, its_instance, its_eventgroup, its_major, its_notifier); } else { VSOMEIP_WARNING << "vSomeIP Security: Client 0x" << std::hex << its_client << " : routing_manager_stub::on_message: " << " subscribes to service/instance/event " << its_service << "/" << its_instance << "/ANY_EVENT" << " which violates the security policy ~> Skip subscribe!"; } } else { if (security::get()->is_client_allowed(its_sender_uid, its_sender_gid, its_client, its_service, its_instance, its_notifier)) { host_->subscribe(its_client, its_sender_uid, its_sender_gid, its_service, its_instance, its_eventgroup, its_major, its_notifier); } else { VSOMEIP_WARNING << "vSomeIP Security: Client 0x" << std::hex << its_client << " : routing_manager_stub::on_message: " << " subscribes to service/instance/event " << its_service << "/" << its_instance << "/" << its_notifier << " which violates the security policy ~> Skip subscribe!"; } } break; case VSOMEIP_UNSUBSCRIBE: if (_size != VSOMEIP_UNSUBSCRIBE_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a UNSUBSCRIBE command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_eventgroup, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_eventgroup)); std::memcpy(&its_notifier, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(its_notifier)); host_->unsubscribe(its_client, its_sender_uid, its_sender_gid, its_service, its_instance, its_eventgroup, its_notifier); break; case VSOMEIP_SUBSCRIBE_ACK: if (_size != VSOMEIP_SUBSCRIBE_ACK_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a SUBSCRIBE_ACK command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_eventgroup, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_eventgroup)); std::memcpy(&its_subscriber, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(its_subscriber)); std::memcpy(&its_notifier, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 8], sizeof(its_notifier)); std::memcpy(&its_subscription_id, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 10], sizeof(its_subscription_id)); host_->on_subscribe_ack(its_subscriber, its_service, its_instance, its_eventgroup, its_notifier, its_subscription_id); VSOMEIP_INFO << "SUBSCRIBE ACK(" << std::hex << std::setw(4) << std::setfill('0') << its_client << "): [" << std::hex << std::setw(4) << std::setfill('0') << its_service << "." << std::hex << std::setw(4) << std::setfill('0') << its_instance << "." << std::hex << std::setw(4) << std::setfill('0') << its_eventgroup << "." << std::hex << std::setw(4) << std::setfill('0') << its_notifier << "]"; break; case VSOMEIP_SUBSCRIBE_NACK: if (_size != VSOMEIP_SUBSCRIBE_NACK_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a SUBSCRIBE_NACK command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_eventgroup, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_eventgroup)); std::memcpy(&its_subscriber, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(its_subscriber)); std::memcpy(&its_notifier, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 8], sizeof(its_notifier)); std::memcpy(&its_subscription_id, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 10], sizeof(its_subscription_id)); host_->on_subscribe_nack(its_subscriber, its_service, its_instance, its_eventgroup, its_notifier, its_subscription_id); VSOMEIP_INFO << "SUBSCRIBE NACK(" << std::hex << std::setw(4) << std::setfill('0') << its_client << "): [" << std::hex << std::setw(4) << std::setfill('0') << its_service << "." << std::hex << std::setw(4) << std::setfill('0') << its_instance << "." << std::hex << std::setw(4) << std::setfill('0') << its_eventgroup << "." << std::hex << std::setw(4) << std::setfill('0') << its_notifier << "]"; break; case VSOMEIP_UNSUBSCRIBE_ACK: if (_size != VSOMEIP_UNSUBSCRIBE_ACK_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a VSOMEIP_UNSUBSCRIBE_ACK command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_eventgroup, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_eventgroup)); std::memcpy(&its_subscription_id, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(its_subscription_id)); host_->on_unsubscribe_ack(its_client, its_service, its_instance, its_eventgroup, its_subscription_id); VSOMEIP_INFO << "UNSUBSCRIBE ACK(" << std::hex << std::setw(4) << std::setfill('0') << its_client << "): [" << std::hex << std::setw(4) << std::setfill('0') << its_service << "." << std::hex << std::setw(4) << std::setfill('0') << its_instance << "." << std::hex << std::setw(4) << std::setfill('0') << its_eventgroup << "]"; break; case VSOMEIP_SEND: { if (_size < VSOMEIP_SEND_COMMAND_SIZE + VSOMEIP_FULL_HEADER_SIZE) { VSOMEIP_WARNING << "Received a SEND command with too small size ~> skip!"; break; } its_data = &_data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS]; its_service = VSOMEIP_BYTES_TO_WORD( its_data[VSOMEIP_SERVICE_POS_MIN], its_data[VSOMEIP_SERVICE_POS_MAX]); its_client_from_header = VSOMEIP_BYTES_TO_WORD( its_data[VSOMEIP_CLIENT_POS_MIN], its_data[VSOMEIP_CLIENT_POS_MAX]); its_method = VSOMEIP_BYTES_TO_WORD( its_data[VSOMEIP_METHOD_POS_MIN], its_data[VSOMEIP_METHOD_POS_MAX]); std::memcpy(&its_instance, &_data[VSOMEIP_SEND_COMMAND_INSTANCE_POS_MIN], sizeof(its_instance)); std::memcpy(&its_reliable, &_data[VSOMEIP_SEND_COMMAND_RELIABLE_POS], sizeof(its_reliable)); std::memcpy(&its_check_status, &_data[VSOMEIP_SEND_COMMAND_CHECK_STATUS_POS], sizeof(its_check_status)); // Allow response messages from local proxies as answer to remote requests // but check requests sent by local proxies to remote against policy. if (utility::is_request(its_data[VSOMEIP_MESSAGE_TYPE_POS])) { if (!security::get()->is_client_allowed(its_sender_uid, its_sender_gid, its_client_from_header, its_service, its_instance, its_method)) { VSOMEIP_WARNING << "vSomeIP Security: Client 0x" << std::hex << its_client_from_header << " : routing_manager_stub::on_message: " << " isn't allowed to send a request to service/instance/method " << its_service << "/" << its_instance << "/" << its_method << " ~> Skip message!"; return; } } // reduce by size of instance, flush, reliable, client and is_valid_crc flag const std::uint32_t its_message_size = its_size - (VSOMEIP_SEND_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE); if (its_message_size != VSOMEIP_BYTES_TO_LONG(_data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 1], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 2], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 3]) + VSOMEIP_SOMEIP_HEADER_SIZE) { VSOMEIP_WARNING << "Received a SEND command containing message with invalid size -> skip!"; break; } host_->on_message(its_service, its_instance, its_data, its_message_size, its_reliable, _bound_client, _credentials, its_check_status, false); break; } case VSOMEIP_NOTIFY: { if (_size < VSOMEIP_SEND_COMMAND_SIZE + VSOMEIP_FULL_HEADER_SIZE) { VSOMEIP_WARNING << "Received a NOTIFY command with too small size ~> skip!"; break; } its_data = &_data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS]; its_service = VSOMEIP_BYTES_TO_WORD( its_data[VSOMEIP_SERVICE_POS_MIN], its_data[VSOMEIP_SERVICE_POS_MAX]); std::memcpy(&its_instance, &_data[VSOMEIP_SEND_COMMAND_INSTANCE_POS_MIN], sizeof(its_instance)); // reduce by size of instance, flush, reliable, is_valid_crc flag and target client const std::uint32_t its_message_size = its_size - (VSOMEIP_SEND_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE); if (its_message_size != VSOMEIP_BYTES_TO_LONG(_data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 1], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 2], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 3]) + VSOMEIP_SOMEIP_HEADER_SIZE) { VSOMEIP_WARNING << "Received a NOTIFY command containing message with invalid size -> skip!"; break; } host_->on_notification(VSOMEIP_ROUTING_CLIENT, its_service, its_instance, its_data, its_message_size); break; } case VSOMEIP_NOTIFY_ONE: { if (_size < VSOMEIP_SEND_COMMAND_SIZE + VSOMEIP_FULL_HEADER_SIZE) { VSOMEIP_WARNING << "Received a NOTIFY_ONE command with too small size ~> skip!"; break; } its_data = &_data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS]; its_service = VSOMEIP_BYTES_TO_WORD( its_data[VSOMEIP_SERVICE_POS_MIN], its_data[VSOMEIP_SERVICE_POS_MAX]); std::memcpy(&its_instance, &_data[VSOMEIP_SEND_COMMAND_INSTANCE_POS_MIN], sizeof(its_instance)); std::memcpy(&its_target_client, &_data[VSOMEIP_SEND_COMMAND_DST_CLIENT_POS_MIN], sizeof(client_t)); // reduce by size of instance, flush, reliable flag, is_valid_crc and target client const std::uint32_t its_message_size = its_size - (VSOMEIP_SEND_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE); if (its_message_size != VSOMEIP_BYTES_TO_LONG(_data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 1], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 2], _data[VSOMEIP_SEND_COMMAND_PAYLOAD_POS + VSOMEIP_LENGTH_POS_MIN + 3]) + VSOMEIP_SOMEIP_HEADER_SIZE) { VSOMEIP_WARNING << "Received a NOTIFY_ONE command containing message with invalid size -> skip!"; break; } host_->on_notification(its_target_client, its_service, its_instance, its_data, its_message_size, true); break; } case VSOMEIP_REQUEST_SERVICE: { uint32_t entry_size = (sizeof(service_t) + sizeof(instance_t) + sizeof(major_version_t) + sizeof(minor_version_t)); if (its_size % entry_size > 0) { VSOMEIP_WARNING << "Received a REQUEST_SERVICE command with invalid size -> skip!"; break; } uint32_t request_count(its_size / entry_size); std::set<service_data_t> requests; for (uint32_t i = 0; i < request_count; ++i) { service_t its_service; instance_t its_instance; major_version_t its_major; minor_version_t its_minor; std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + (i * entry_size)], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2 + (i * entry_size)], sizeof(its_instance)); std::memcpy(&its_major, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4 + (i * entry_size)], sizeof(its_major)); std::memcpy(&its_minor, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 5 + (i * entry_size)], sizeof(its_minor)); if (security::get()->is_client_allowed(its_sender_uid, its_sender_gid, its_client, its_service, its_instance, 0x00, true)) { host_->request_service(its_client, its_service, its_instance, its_major, its_minor ); service_data_t request = { its_service, its_instance, its_major, its_minor }; requests.insert(request); } else { VSOMEIP_WARNING << "vSomeIP Security: Client 0x" << std::hex << its_client << " : routing_manager_stub::on_message: " << "requests service/instance " << its_service << "/" << its_instance << " which violates the security policy ~> Skip request!"; } } if (security::get()->is_enabled()) { handle_credentials(its_client, requests); } handle_requests(its_client, requests); break; } case VSOMEIP_RELEASE_SERVICE: if (_size != VSOMEIP_RELEASE_SERVICE_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a RELEASE_SERVICE command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); host_->release_service(its_client, its_service, its_instance); break; case VSOMEIP_REGISTER_EVENT: { if (_size < VSOMEIP_REGISTER_EVENT_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a REGISTER_EVENT command with wrong size ~> skip!"; break; } std::set<eventgroup_t> its_eventgroups; reliability_type_e its_reliability = reliability_type_e::RT_UNKNOWN; std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_notifier, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_notifier)); std::memcpy(&its_event_type, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(its_event_type)); std::memcpy(&is_provided, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 7], sizeof(is_provided)); std::memcpy(&its_reliability, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 8], sizeof(its_reliability)); if (is_provided && !configuration_->is_offered_remote(its_service, its_instance)) { break; } for (std::size_t i = 9; i+1 < its_size; i++) { std::memcpy(&its_eventgroup, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + i], sizeof(its_eventgroup)); its_eventgroups.insert(its_eventgroup); } host_->register_shadow_event(its_client, its_service, its_instance, its_notifier, its_eventgroups, its_event_type, its_reliability, is_provided); VSOMEIP_INFO << "REGISTER EVENT(" << std::hex << std::setw(4) << std::setfill('0') << its_client << "): [" << std::hex << std::setw(4) << std::setfill('0') << its_service << "." << std::hex << std::setw(4) << std::setfill('0') << its_instance << "." << std::hex << std::setw(4) << std::setfill('0') << its_notifier << ":is_provider=" << is_provided << ":reliability=" << (std::uint32_t)(its_reliability) << "]"; break; } case VSOMEIP_UNREGISTER_EVENT: if (_size != VSOMEIP_UNREGISTER_EVENT_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a UNREGISTER_EVENT command with wrong size ~> skip!"; break; } std::memcpy(&its_service, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_service)); std::memcpy(&its_instance, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 2], sizeof(its_instance)); std::memcpy(&its_notifier, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 4], sizeof(its_notifier)); std::memcpy(&is_provided, &_data[VSOMEIP_COMMAND_PAYLOAD_POS + 6], sizeof(is_provided)); if (is_provided && !configuration_->is_offered_remote(its_service, its_instance)) { break; } host_->unregister_shadow_event(its_client, its_service, its_instance, its_notifier, is_provided); VSOMEIP_INFO << "UNREGISTER EVENT(" << std::hex << std::setw(4) << std::setfill('0') << its_client << "): [" << std::hex << std::setw(4) << std::setfill('0') << its_service << "." << std::hex << std::setw(4) << std::setfill('0') << its_instance << "." << std::hex << std::setw(4) << std::setfill('0') << its_notifier << ":is_provider=" << is_provided << "]"; break; case VSOMEIP_REGISTERED_ACK: if (_size != VSOMEIP_REGISTERED_ACK_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a REGISTERED_ACK command with wrong size ~> skip!"; break; } VSOMEIP_INFO << "REGISTERED_ACK(" << std::hex << std::setw(4) << std::setfill('0') << its_client << ")"; break; case VSOMEIP_OFFERED_SERVICES_REQUEST: { if (_size != VSOMEIP_OFFERED_SERVICES_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a VSOMEIP_OFFERED_SERVICES_REQUEST command with wrong size ~> skip!"; break; } std::memcpy(&its_offer_type, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(its_offer_type)); std::lock_guard<std::mutex> its_guard(routing_info_mutex_); create_offered_services_info(its_client); for (const auto& found_client : routing_info_) { // skip services which are offered on remote hosts if (found_client.first != VSOMEIP_ROUTING_CLIENT) { for (const auto &its_service : found_client.second.second) { for (const auto &its_instance : its_service.second) { uint16_t its_reliable_port = configuration_->get_reliable_port(its_service.first, its_instance.first); uint16_t its_unreliable_port = configuration_->get_unreliable_port( its_service.first, its_instance.first); if (its_offer_type == offer_type_e::OT_LOCAL) { if (its_reliable_port == ILLEGAL_PORT && its_unreliable_port == ILLEGAL_PORT) { insert_offered_services_info(its_client, routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE, its_service.first, its_instance.first, its_instance.second.first, its_instance.second.second); } } else if (its_offer_type == offer_type_e::OT_REMOTE) { if (its_reliable_port != ILLEGAL_PORT || its_unreliable_port != ILLEGAL_PORT) { insert_offered_services_info(its_client, routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE, its_service.first, its_instance.first, its_instance.second.first, its_instance.second.second); } } else if (its_offer_type == offer_type_e::OT_ALL) { insert_offered_services_info(its_client, routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE, its_service.first, its_instance.first, its_instance.second.first, its_instance.second.second); } } } } } send_offered_services_info(its_client); break; } case VSOMEIP_RESEND_PROVIDED_EVENTS: { if (_size != VSOMEIP_RESEND_PROVIDED_EVENTS_COMMAND_SIZE) { VSOMEIP_WARNING << "Received a RESEND_PROVIDED_EVENTS command with wrong size ~> skip!"; break; } pending_remote_offer_id_t its_pending_remote_offer_id(0); std::memcpy(&its_pending_remote_offer_id, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(pending_remote_offer_id_t)); host_->on_resend_provided_events_response(its_pending_remote_offer_id); VSOMEIP_INFO << "RESEND_PROVIDED_EVENTS(" << std::hex << std::setw(4) << std::setfill('0') << its_client << ")"; break; } case VSOMEIP_UPDATE_SECURITY_POLICY_RESPONSE: { if (_size != VSOMEIP_UPDATE_SECURITY_POLICY_RESPONSE_COMMAND_SIZE) { VSOMEIP_WARNING << "vSomeIP Security: Received a VSOMEIP_UPDATE_SECURITY_POLICY_RESPONSE " << "command with wrong size ~> skip!"; break; } pending_security_update_id_t its_pending_security_update_id(0); std::memcpy(&its_pending_security_update_id, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(pending_security_update_id_t)); on_security_update_response(its_pending_security_update_id ,its_client); break; } case VSOMEIP_REMOVE_SECURITY_POLICY_RESPONSE: { if (_size != VSOMEIP_REMOVE_SECURITY_POLICY_RESPONSE_COMMAND_SIZE) { VSOMEIP_WARNING << "vSomeIP Security: Received a VSOMEIP_REMOVE_SECURITY_POLICY_RESPONSE " << "command with wrong size ~> skip!"; break; } pending_security_update_id_t its_pending_security_update_id(0); std::memcpy(&its_pending_security_update_id, &_data[VSOMEIP_COMMAND_PAYLOAD_POS], sizeof(pending_security_update_id_t)); on_security_update_response(its_pending_security_update_id ,its_client); break; } } } } } void routing_manager_stub::on_register_application(client_t _client) { auto endpoint = host_->find_local(_client); if (endpoint) { VSOMEIP_WARNING << "Reregistering application: " << std::hex << _client << ". Last registration might have been taken too long."; } else { endpoint = host_->find_or_create_local(_client); { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); routing_info_[_client].first = 0; } std::pair<uid_t, gid_t> its_uid_gid; std::set<std::shared_ptr<policy> > its_policies; security::get()->get_client_to_uid_gid_mapping(_client, its_uid_gid); get_requester_policies(its_uid_gid.first, its_uid_gid.second, its_policies); if (!its_policies.empty()) send_requester_policies({ _client }, its_policies); } } void routing_manager_stub::on_deregister_application(client_t _client) { std::vector< std::tuple<service_t, instance_t, major_version_t, minor_version_t>> services_to_report; { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); auto its_info = routing_info_.find(_client); if (its_info != routing_info_.end()) { for (const auto &its_service : its_info->second.second) { for (const auto &its_instance : its_service.second) { const auto its_version = its_instance.second; services_to_report.push_back( std::make_tuple(its_service.first, its_instance.first, its_version.first, its_version.second)); } } } routing_info_.erase(_client); } for (const auto &s : services_to_report) { host_->on_availability(std::get<0>(s), std::get<1>(s), false, std::get<2>(s), std::get<3>(s)); host_->on_stop_offer_service(_client, std::get<0>(s), std::get<1>(s), std::get<2>(s), std::get<3>(s)); } } void routing_manager_stub::client_registration_func(void) { #ifndef _WIN32 { std::stringstream s; s << std::hex << std::setw(4) << std::setfill('0') << host_->get_client() << "_client_reg"; pthread_setname_np(pthread_self(),s.str().c_str()); } #endif std::unique_lock<std::mutex> its_lock(client_registration_mutex_); while (client_registration_running_) { while (!pending_client_registrations_.size() && client_registration_running_) { client_registration_condition_.wait(its_lock); } std::map<client_t, std::vector<registration_type_e>> its_registrations( pending_client_registrations_); pending_client_registrations_.clear(); its_lock.unlock(); for (const auto& r : its_registrations) { for (auto b : r.second) { if (b == registration_type_e::REGISTER) { on_register_application(r.first); } else { on_deregister_application(r.first); } // Inform (de)registered client. All others will be informed after // the client acknowledged its registered state! // Don't inform client if we deregister because of an client // endpoint error to avoid writing in an already closed socket if (b != registration_type_e::DEREGISTER_ON_ERROR) { std::lock_guard<std::mutex> its_guard(routing_info_mutex_); create_client_routing_info(r.first); insert_client_routing_info(r.first, b == registration_type_e::REGISTER ? routing_info_entry_e::RIE_ADD_CLIENT : routing_info_entry_e::RIE_DEL_CLIENT, r.first); // distribute updated security config to new clients if (b == registration_type_e::REGISTER) { send_cached_security_policies(r.first); } send_client_routing_info(r.first); } if (b != registration_type_e::REGISTER) { { std::lock_guard<std::mutex> its_guard(routing_info_mutex_); auto its_connection = connection_matrix_.find(r.first); if (its_connection != connection_matrix_.end()) { for (auto its_client : its_connection->second) { if (its_client != r.first && its_client != VSOMEIP_ROUTING_CLIENT && its_client != get_client()) { create_client_routing_info(its_client); insert_client_routing_info(its_client, routing_info_entry_e::RIE_DEL_CLIENT, r.first); send_client_routing_info(its_client); } } connection_matrix_.erase(r.first); } for (const auto& its_client : connection_matrix_) { connection_matrix_[its_client.first].erase(r.first); } service_requests_.erase(r.first); } // Don't remove client ID to UID maping as same client // could have passed its credentials again host_->remove_local(r.first, false); utility::release_client_id(r.first); } } } its_lock.lock(); } } void routing_manager_stub::init_routing_endpoint() { endpoint_ = host_->get_endpoint_manager()->create_local_server( &is_socket_activated_, shared_from_this()); } void routing_manager_stub::on_offer_service(client_t _client, service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor) { if (_client == host_->get_client()) { create_local_receiver(); } std::lock_guard<std::mutex> its_guard(routing_info_mutex_); routing_info_[_client].second[_service][_instance] = std::make_pair(_major, _minor); if (security::get()->is_enabled()) { distribute_credentials(_client, _service, _instance); } inform_requesters(_client, _service, _instance, _major, _minor, routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE, true); } void routing_manager_stub::on_stop_offer_service(client_t _client, service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor) { std::lock_guard<std::mutex> its_guard(routing_info_mutex_); auto found_client = routing_info_.find(_client); if (found_client != routing_info_.end()) { auto found_service = found_client->second.second.find(_service); if (found_service != found_client->second.second.end()) { auto found_instance = found_service->second.find(_instance); if (found_instance != found_service->second.end()) { auto found_version = found_instance->second; if( _major == found_version.first && _minor == found_version.second) { found_service->second.erase(_instance); if (0 == found_service->second.size()) { found_client->second.second.erase(_service); } inform_requesters(_client, _service, _instance, _major, _minor, routing_info_entry_e::RIE_DEL_SERVICE_INSTANCE, false); } else if( _major == DEFAULT_MAJOR && _minor == DEFAULT_MINOR) { found_service->second.erase(_instance); if (0 == found_service->second.size()) { found_client->second.second.erase(_service); } inform_requesters(_client, _service, _instance, _major, _minor, routing_info_entry_e::RIE_DEL_SERVICE_INSTANCE, false); } } } } } void routing_manager_stub::create_client_routing_info(const client_t _target) { std::vector<byte_t> its_command; its_command.push_back(VSOMEIP_ROUTING_INFO); // Sender client client_t client = get_client(); for (uint32_t i = 0; i < sizeof(client_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&client)[i]); } // Overall size placeholder byte_t size_placeholder = 0x0; for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back(size_placeholder); } client_routing_info_[_target] = its_command; } void routing_manager_stub::create_client_credentials_info(const client_t _target) { std::vector<byte_t> its_command; its_command.push_back(VSOMEIP_UPDATE_SECURITY_CREDENTIALS); // Sender client client_t client = get_client(); for (uint32_t i = 0; i < sizeof(client_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&client)[i]); } // Overall size placeholder byte_t size_placeholder = 0x0; for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back(size_placeholder); } client_credentials_info_[_target] = its_command; } void routing_manager_stub::insert_client_credentials_info(client_t _target, std::set<std::pair<uint32_t, uint32_t>> _credentials) { if (client_credentials_info_.find(_target) == client_credentials_info_.end()) { return; } auto its_command = client_credentials_info_[_target]; // insert uid / gid credential pairs for (auto its_credentials : _credentials) { //uid for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&std::get<0>(its_credentials))[i]); } //gid for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&std::get<1>(its_credentials))[i]); } } client_credentials_info_[_target] = its_command; } void routing_manager_stub::send_client_credentials_info(const client_t _target) { if (client_credentials_info_.find(_target) == client_credentials_info_.end()) { return; } std::shared_ptr<endpoint> its_endpoint = host_->find_local(_target); if (its_endpoint) { auto its_command = client_credentials_info_[_target]; // File overall size std::size_t its_size = its_command.size() - VSOMEIP_COMMAND_PAYLOAD_POS; std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(uint32_t)); its_size += VSOMEIP_COMMAND_PAYLOAD_POS; #if 0 std::stringstream msg; msg << "rms::send_credentials_info to (" << std::hex << _target << "): "; for (uint32_t i = 0; i < its_size; ++i) msg << std::hex << std::setw(2) << std::setfill('0') << (int)its_command[i] << " "; VSOMEIP_INFO << msg.str(); #endif // Send routing info or error! if(its_command.size() <= max_local_message_size_ || VSOMEIP_MAX_LOCAL_MESSAGE_SIZE == 0) { its_endpoint->send(&its_command[0], uint32_t(its_size)); } else { VSOMEIP_ERROR << "Credentials info exceeds maximum message size: Can't send!"; } client_credentials_info_.erase(_target); } else { VSOMEIP_ERROR << "Send credentials info to client 0x" << std::hex << _target << " failed: No valid endpoint!"; } } void routing_manager_stub::create_offered_services_info(const client_t _target) { std::vector<byte_t> its_command; its_command.push_back(VSOMEIP_OFFERED_SERVICES_RESPONSE); // Sender client client_t client = get_client(); for (uint32_t i = 0; i < sizeof(client_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&client)[i]); } // Overall size placeholder byte_t size_placeholder = 0x0; for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back(size_placeholder); } offered_services_info_[_target] = its_command; } void routing_manager_stub::send_client_routing_info(const client_t _target) { if (client_routing_info_.find(_target) == client_routing_info_.end()) { return; } std::shared_ptr<endpoint> its_endpoint = host_->find_local(_target); if (its_endpoint) { auto its_command = client_routing_info_[_target]; // File overall size std::size_t its_size = its_command.size() - VSOMEIP_COMMAND_PAYLOAD_POS; std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(uint32_t)); its_size += VSOMEIP_COMMAND_PAYLOAD_POS; #if 0 std::stringstream msg; msg << "rms::send_routing_info to (" << std::hex << _target << "): "; for (uint32_t i = 0; i < its_size; ++i) msg << std::hex << std::setw(2) << std::setfill('0') << (int)its_command[i] << " "; VSOMEIP_INFO << msg.str(); #endif // Send routing info or error! if(its_command.size() <= max_local_message_size_ || VSOMEIP_MAX_LOCAL_MESSAGE_SIZE == 0) { its_endpoint->send(&its_command[0], uint32_t(its_size)); } else { VSOMEIP_ERROR << "Routing info exceeds maximum message size: Can't send!"; } client_routing_info_.erase(_target); } else { VSOMEIP_ERROR << "Send routing info to client 0x" << std::hex << _target << " failed: No valid endpoint!"; } } void routing_manager_stub::send_offered_services_info(const client_t _target) { if (offered_services_info_.find(_target) == offered_services_info_.end()) { return; } std::shared_ptr<endpoint> its_endpoint = host_->find_local(_target); if (its_endpoint) { auto its_command = offered_services_info_[_target]; // File overall size std::size_t its_size = its_command.size() - VSOMEIP_COMMAND_PAYLOAD_POS; std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(uint32_t)); its_size += VSOMEIP_COMMAND_PAYLOAD_POS; #if 0 std::stringstream msg; msg << "rms::send_offered_services_info to (" << std::hex << _target << "): "; for (uint32_t i = 0; i < its_size; ++i) msg << std::hex << std::setw(2) << std::setfill('0') << (int)its_command[i] << " "; VSOMEIP_INFO << msg.str(); #endif // Send routing info or error! if(its_command.size() <= max_local_message_size_ || VSOMEIP_MAX_LOCAL_MESSAGE_SIZE == 0) { its_endpoint->send(&its_command[0], uint32_t(its_size)); } else { VSOMEIP_ERROR << "Offered services info exceeds maximum message size: Can't send!"; } offered_services_info_.erase(_target); } else { VSOMEIP_ERROR << "Send offered services info to client 0x" << std::hex << _target << " failed: No valid endpoint!"; } } void routing_manager_stub::insert_client_routing_info(client_t _target, routing_info_entry_e _entry, client_t _client, service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor) { if (client_routing_info_.find(_target) == client_routing_info_.end()) { return; } connection_matrix_[_target].insert(_client); auto its_command = client_routing_info_[_target]; // Routing Info State Change for (uint32_t i = 0; i < sizeof(routing_info_entry_e); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_entry)[i]); } std::size_t its_size_pos = its_command.size(); std::size_t its_entry_size = its_command.size(); // Client size placeholder byte_t placeholder = 0x0; for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back(placeholder); } // Client for (uint32_t i = 0; i < sizeof(client_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_client)[i]); } if (_entry == routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE || _entry == routing_info_entry_e::RIE_DEL_SERVICE_INSTANCE) { //Service uint32_t its_service_entry_size = uint32_t(sizeof(service_t) + sizeof(instance_t) + sizeof(major_version_t) + sizeof(minor_version_t)); for (uint32_t i = 0; i < sizeof(its_service_entry_size); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&its_service_entry_size)[i]); } for (uint32_t i = 0; i < sizeof(service_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_service)[i]); } // Instance for (uint32_t i = 0; i < sizeof(instance_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_instance)[i]); } // Major version for (uint32_t i = 0; i < sizeof(major_version_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_major)[i]); } // Minor version for (uint32_t i = 0; i < sizeof(minor_version_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_minor)[i]); } } // File client size its_entry_size = its_command.size() - its_entry_size - uint32_t(sizeof(uint32_t)); std::memcpy(&its_command[its_size_pos], &its_entry_size, sizeof(uint32_t)); client_routing_info_[_target] = its_command; } void routing_manager_stub::insert_offered_services_info(client_t _target, routing_info_entry_e _entry, service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor) { if (offered_services_info_.find(_target) == offered_services_info_.end()) { return; } auto its_command = offered_services_info_[_target]; // Routing Info State Change for (uint32_t i = 0; i < sizeof(routing_info_entry_e); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_entry)[i]); } // entry size uint32_t its_service_entry_size = uint32_t(sizeof(service_t) + sizeof(instance_t) + sizeof(major_version_t) + sizeof(minor_version_t)); for (uint32_t i = 0; i < sizeof(its_service_entry_size); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&its_service_entry_size)[i]); } //Service for (uint32_t i = 0; i < sizeof(service_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_service)[i]); } // Instance for (uint32_t i = 0; i < sizeof(instance_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_instance)[i]); } // Major version for (uint32_t i = 0; i < sizeof(major_version_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_major)[i]); } // Minor version for (uint32_t i = 0; i < sizeof(minor_version_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_minor)[i]); } offered_services_info_[_target] = its_command; } void routing_manager_stub::distribute_credentials(client_t _hoster, service_t _service, instance_t _instance) { std::set<std::pair<uint32_t, uint32_t>> its_credentials; std::set<client_t> its_requesting_clients; // search for clients which shall receive the credentials for (auto its_requesting_client : service_requests_) { auto its_service = its_requesting_client.second.find(_service); if (its_service != its_requesting_client.second.end()) { for (auto its_instance : its_service->second) { if (its_instance.first == ANY_INSTANCE || its_instance.first == _instance) { its_requesting_clients.insert(its_requesting_client.first); } else { auto found_instance = its_service->second.find(_instance); if (found_instance != its_service->second.end()) { its_requesting_clients.insert(its_requesting_client.first); } } } } } // search for UID / GID linked with the client ID that offers the requested services std::pair<uint32_t, uint32_t> its_uid_gid; if (security::get()->get_client_to_uid_gid_mapping(_hoster, its_uid_gid)) { for (auto its_requesting_client : its_requesting_clients) { std::pair<uint32_t, uint32_t> its_requester_uid_gid; if (security::get()->get_client_to_uid_gid_mapping(its_requesting_client, its_requester_uid_gid)) { if (its_uid_gid != its_requester_uid_gid) { its_credentials.insert(std::make_pair(std::get<0>(its_uid_gid), std::get<1>(its_uid_gid))); create_client_credentials_info(its_requesting_client); insert_client_credentials_info(its_requesting_client, its_credentials); send_client_credentials_info(its_requesting_client); } } } } } void routing_manager_stub::inform_requesters(client_t _hoster, service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor, routing_info_entry_e _entry, bool _inform_service) { for (auto its_client : service_requests_) { auto its_service = its_client.second.find(_service); if (its_service != its_client.second.end()) { bool send(false); for (auto its_instance : its_service->second) { if (its_instance.first == ANY_INSTANCE || its_instance.first == _instance) { send = true; } } if (send) { if (_inform_service) { if (_hoster != VSOMEIP_ROUTING_CLIENT && _hoster != host_->get_client()) { if (!is_already_connected(_hoster, its_client.first)) { create_client_routing_info(_hoster); insert_client_routing_info(_hoster, routing_info_entry_e::RIE_ADD_CLIENT, its_client.first); send_client_routing_info(_hoster); } } } if (its_client.first != VSOMEIP_ROUTING_CLIENT && its_client.first != get_client()) { create_client_routing_info(its_client.first); insert_client_routing_info(its_client.first, _entry, _hoster, _service, _instance, _major, _minor); send_client_routing_info(its_client.first); } } } } } bool routing_manager_stub::is_already_connected(client_t _source, client_t _sink) { return connection_matrix_[_source].find(_sink) != connection_matrix_[_source].end(); } void routing_manager_stub::broadcast(const std::vector<byte_t> &_command) const { std::lock_guard<std::mutex> its_guard(routing_info_mutex_); for (const auto& a : routing_info_) { if (a.first != VSOMEIP_ROUTING_CLIENT && a.first != host_->get_client()) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(a.first); if (its_endpoint) { its_endpoint->send(&_command[0], uint32_t(_command.size())); } } } } bool routing_manager_stub::send_subscribe(const std::shared_ptr<endpoint>& _target, client_t _client, service_t _service, instance_t _instance, eventgroup_t _eventgroup, major_version_t _major, event_t _event, remote_subscription_id_t _id) { if (_target) { byte_t its_command[VSOMEIP_SUBSCRIBE_COMMAND_SIZE]; uint32_t its_size = VSOMEIP_SUBSCRIBE_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE; its_command[VSOMEIP_COMMAND_TYPE_POS] = VSOMEIP_SUBSCRIBE; std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &_client, sizeof(_client)); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS], &_service, sizeof(_service)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 2], &_instance, sizeof(_instance)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 4], &_eventgroup, sizeof(_eventgroup)); its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 6] = _major; std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 7], &_event, sizeof(_event)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 9], &_id, sizeof(_id)); return _target->send(its_command, sizeof(its_command)); } else { VSOMEIP_WARNING << __func__ << " Couldn't send subscription to local client [" << std::hex << std::setw(4) << std::setfill('0') << _service << "." << std::hex << std::setw(4) << std::setfill('0') << _instance << "." << std::hex << std::setw(4) << std::setfill('0') << _eventgroup << "." << std::hex << std::setw(4) << std::setfill('0') << _event << "]" << " subscriber: "<< std::hex << std::setw(4) << std::setfill('0') << _client; return false; } } bool routing_manager_stub::send_unsubscribe( const std::shared_ptr<endpoint>& _target, client_t _client, service_t _service, instance_t _instance, eventgroup_t _eventgroup, event_t _event, remote_subscription_id_t _id) { if (_target) { byte_t its_command[VSOMEIP_UNSUBSCRIBE_COMMAND_SIZE]; uint32_t its_size = VSOMEIP_UNSUBSCRIBE_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE; its_command[VSOMEIP_COMMAND_TYPE_POS] = VSOMEIP_UNSUBSCRIBE; std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &_client, sizeof(_client)); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS], &_service, sizeof(_service)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 2], &_instance, sizeof(_instance)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 4], &_eventgroup, sizeof(_eventgroup)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 6], &_event, sizeof(_event)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 8], &_id, sizeof(_id)); return _target->send(its_command, sizeof(its_command)); } else { VSOMEIP_WARNING << __func__ << " Couldn't send unsubscription to local client [" << std::hex << std::setw(4) << std::setfill('0') << _service << "." << std::hex << std::setw(4) << std::setfill('0') << _instance << "." << std::hex << std::setw(4) << std::setfill('0') << _eventgroup << "." << std::hex << std::setw(4) << std::setfill('0') << _event << "]" << " subscriber: "<< std::hex << std::setw(4) << std::setfill('0') << _client; return false; } } void routing_manager_stub::send_subscribe_ack(client_t _client, service_t _service, instance_t _instance, eventgroup_t _eventgroup, event_t _event) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (its_endpoint) { byte_t its_command[VSOMEIP_SUBSCRIBE_ACK_COMMAND_SIZE]; uint32_t its_size = VSOMEIP_SUBSCRIBE_ACK_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE; client_t this_client = get_client(); its_command[VSOMEIP_COMMAND_TYPE_POS] = VSOMEIP_SUBSCRIBE_ACK; std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &this_client, sizeof(this_client)); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS], &_service, sizeof(_service)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 2], &_instance, sizeof(_instance)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 4], &_eventgroup, sizeof(_eventgroup)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 6], &_client, sizeof(_client)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 8], &_event, sizeof(_event)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 10], &PENDING_SUBSCRIPTION_ID, sizeof(PENDING_SUBSCRIPTION_ID)); its_endpoint->send(&its_command[0], sizeof(its_command)); } } void routing_manager_stub::send_subscribe_nack(client_t _client, service_t _service, instance_t _instance, eventgroup_t _eventgroup, event_t _event) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (its_endpoint) { byte_t its_command[VSOMEIP_SUBSCRIBE_NACK_COMMAND_SIZE]; uint32_t its_size = VSOMEIP_SUBSCRIBE_NACK_COMMAND_SIZE - VSOMEIP_COMMAND_HEADER_SIZE; client_t this_client = get_client(); its_command[VSOMEIP_COMMAND_TYPE_POS] = VSOMEIP_SUBSCRIBE_NACK; std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &this_client, sizeof(this_client)); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS], &_service, sizeof(_service)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 2], &_instance, sizeof(_instance)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 4], &_eventgroup, sizeof(_eventgroup)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 6], &_client, sizeof(_client)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 8], &_event, sizeof(_event)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 10], &PENDING_SUBSCRIPTION_ID, sizeof(PENDING_SUBSCRIPTION_ID)); its_endpoint->send(&its_command[0], sizeof(its_command)); } } bool routing_manager_stub::contained_in_routing_info( client_t _client, service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor) const { std::lock_guard<std::mutex> its_guard(routing_info_mutex_); auto found_client = routing_info_.find(_client); if (found_client != routing_info_.end()) { auto found_service = found_client->second.second.find(_service); if (found_service != found_client->second.second.end()) { auto found_instance = found_service->second.find(_instance); if (found_instance != found_service->second.end()) { if (found_instance->second.first == _major && found_instance->second.second == _minor) { return true; } } } } return false; } // Watchdog void routing_manager_stub::broadcast_ping() const { broadcast(its_ping_); } void routing_manager_stub::on_pong(client_t _client) { { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); auto found_info = routing_info_.find(_client); if (found_info != routing_info_.end()) { found_info->second.first = 0; } else { VSOMEIP_ERROR << "Received PONG from unregistered application: " << std::hex << std::setw(4) << std::setfill('0') << _client; } } remove_from_pinged_clients(_client); host_->on_pong(_client); } void routing_manager_stub::start_watchdog() { auto its_callback = [this](boost::system::error_code const &_error) { if (!_error) check_watchdog(); }; { std::lock_guard<std::mutex> its_lock(watchdog_timer_mutex_); // Divide / 2 as start and check sleep each watchdog_timer_.expires_from_now( std::chrono::milliseconds( configuration_->get_watchdog_timeout() / 2)); watchdog_timer_.async_wait(its_callback); } } void routing_manager_stub::check_watchdog() { { std::lock_guard<std::mutex> its_guard(routing_info_mutex_); for (auto i = routing_info_.begin(); i != routing_info_.end(); ++i) { i->second.first++; } } broadcast_ping(); auto its_callback = [this](boost::system::error_code const &_error) { (void)_error; std::list< client_t > lost; { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); for (const auto& i : routing_info_) { if (i.first > 0 && i.first != host_->get_client()) { if (i.second.first > configuration_->get_allowed_missing_pongs()) { VSOMEIP_WARNING << "Lost contact to application " << std::hex << (int)i.first; lost.push_back(i.first); } } } } for (auto i : lost) { host_->handle_client_error(i); } start_watchdog(); }; { std::lock_guard<std::mutex> its_lock(watchdog_timer_mutex_); watchdog_timer_.expires_from_now( std::chrono::milliseconds( configuration_->get_watchdog_timeout() / 2)); watchdog_timer_.async_wait(its_callback); } } void routing_manager_stub::create_local_receiver() { std::lock_guard<std::mutex> its_lock(local_receiver_mutex_); if (local_receiver_) { return; } #ifndef _WIN32 else if (!security::get()->check_credentials(get_client(), getuid(), getgid())) { VSOMEIP_ERROR << "vSomeIP Security: Client 0x" << std::hex << get_client() << " : routing_manager_stub::create_local_receiver: isn't allowed" << " to create a server endpoint due to credential check failed!"; return; } #endif local_receiver_ = std::static_pointer_cast<endpoint_manager_base>( host_->get_endpoint_manager())->create_local_server(shared_from_this()); local_receiver_->start(); } bool routing_manager_stub::send_ping(client_t _client) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (!its_endpoint) { return false; } { std::lock_guard<std::mutex> its_lock(pinged_clients_mutex_); if (pinged_clients_.find(_client) != pinged_clients_.end()) { // client was already pinged: don't ping again and wait for answer // or timeout of previous ping. return true; } boost::system::error_code ec; pinged_clients_timer_.cancel(ec); if (ec) { VSOMEIP_ERROR << "routing_manager_stub::send_ping cancellation of " "timer failed: " << ec.message(); } const std::chrono::steady_clock::time_point now( std::chrono::steady_clock::now()); std::chrono::milliseconds next_timeout(configured_watchdog_timeout_); for (const auto &tp : pinged_clients_) { const std::chrono::milliseconds its_clients_timeout = std::chrono::duration_cast<std::chrono::milliseconds>( now - tp.second); if (next_timeout > its_clients_timeout) { next_timeout = its_clients_timeout; } } pinged_clients_[_client] = now; ec.clear(); pinged_clients_timer_.expires_from_now(next_timeout, ec); if (ec) { VSOMEIP_ERROR<< "routing_manager_stub::send_ping setting " "expiry time of timer failed: " << ec.message(); } pinged_clients_timer_.async_wait( std::bind(&routing_manager_stub::on_ping_timer_expired, this, std::placeholders::_1)); return its_endpoint->send(&its_ping_[0], uint32_t(its_ping_.size())); } } void routing_manager_stub::on_ping_timer_expired( boost::system::error_code const &_error) { if(_error) { return; } std::forward_list<client_t> timed_out_clients; std::chrono::milliseconds next_timeout(configured_watchdog_timeout_); bool pinged_clients_remaining(false); { // remove timed out clients std::lock_guard<std::mutex> its_lock(pinged_clients_mutex_); const std::chrono::steady_clock::time_point now( std::chrono::steady_clock::now()); for (auto client_iter = pinged_clients_.begin(); client_iter != pinged_clients_.end(); ) { if ((now - client_iter->second) >= configured_watchdog_timeout_) { timed_out_clients.push_front(client_iter->first); client_iter = pinged_clients_.erase(client_iter); } else { ++client_iter; } } pinged_clients_remaining = (pinged_clients_.size() > 0); if(pinged_clients_remaining) { // find out next timeout for (const auto &tp : pinged_clients_) { const std::chrono::milliseconds its_clients_timeout = std::chrono::duration_cast<std::chrono::milliseconds>( now - tp.second); if (next_timeout > its_clients_timeout) { next_timeout = its_clients_timeout; } } } } for (const client_t client : timed_out_clients) { // Client did not respond to ping. Report client_error in order to // accept pending offers trying to replace the offers of the client // that seems to be gone. host_->handle_client_error(client); } if (pinged_clients_remaining) { boost::system::error_code ec; pinged_clients_timer_.expires_from_now(next_timeout, ec); if (ec) { VSOMEIP_ERROR<< "routing_manager_stub::on_ping_timer_expired " "setting expiry time of timer failed: " << ec.message(); } pinged_clients_timer_.async_wait( std::bind(&routing_manager_stub::on_ping_timer_expired, this, std::placeholders::_1)); } } void routing_manager_stub::remove_from_pinged_clients(client_t _client) { std::lock_guard<std::mutex> its_lock(pinged_clients_mutex_); if (!pinged_clients_.size()) { return; } boost::system::error_code ec; pinged_clients_timer_.cancel(ec); if (ec) { VSOMEIP_ERROR << "routing_manager_stub::remove_from_pinged_clients " "cancellation of timer failed: " << ec.message(); } pinged_clients_.erase(_client); if (!pinged_clients_.size()) { return; } const std::chrono::steady_clock::time_point now( std::chrono::steady_clock::now()); std::chrono::milliseconds next_timeout(configured_watchdog_timeout_); // find out next timeout for (const auto &tp : pinged_clients_) { const std::chrono::milliseconds its_clients_timeout = std::chrono::duration_cast<std::chrono::milliseconds>( now - tp.second); if (next_timeout > its_clients_timeout) { next_timeout = its_clients_timeout; } } ec.clear(); pinged_clients_timer_.expires_from_now(next_timeout, ec); if (ec) { VSOMEIP_ERROR<< "routing_manager_stub::remove_from_pinged_clients " "setting expiry time of timer failed: " << ec.message(); } pinged_clients_timer_.async_wait( std::bind(&routing_manager_stub::on_ping_timer_expired, this, std::placeholders::_1)); } bool routing_manager_stub::is_registered(client_t _client) const { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); return (routing_info_.find(_client) != routing_info_.end()); } void routing_manager_stub::update_registration(client_t _client, registration_type_e _type) { VSOMEIP_INFO << "Application/Client " << std::hex << std::setw(4) << std::setfill('0') << _client << " is " << (_type == registration_type_e::REGISTER ? "registering." : "deregistering."); if (_type != registration_type_e::REGISTER) { security::get()->remove_client_to_uid_gid_mapping(_client); } if (_type == registration_type_e::DEREGISTER) { // If we receive a DEREGISTER client command // the endpoint error handler is not longer needed // as the client is going down anyways. // Normally the handler is removed in "remove_local" // anyways, but as some time takes place until // the client DEREGISTER command is consumed // and therefore "remove_local" is finally called // it was possible the same client registers itself // again in very short time and then could "overtake" // the occurring error in the endpoint and was then // erroneously unregistered even that error has // nothing to do with the newly registered client. auto its_endpoint = host_->find_local(_client); if (its_endpoint) { its_endpoint->register_error_handler(nullptr); } } std::lock_guard<std::mutex> its_lock(client_registration_mutex_); pending_client_registrations_[_client].push_back(_type); client_registration_condition_.notify_one(); if (_type != registration_type_e::REGISTER) { std::lock_guard<std::mutex> its_lock(used_client_ids_mutex_); used_client_ids_.erase(_client); } } client_t routing_manager_stub::get_client() const { return host_->get_client(); } void routing_manager_stub::handle_credentials(const client_t _client, std::set<service_data_t>& _requests) { if (!_requests.size()) { return; } std::lock_guard<std::mutex> its_guard(routing_info_mutex_); std::set<std::pair<uint32_t, uint32_t>> its_credentials; std::pair<uint32_t, uint32_t> its_requester_uid_gid; if (security::get()->get_client_to_uid_gid_mapping(_client, its_requester_uid_gid)) { // determine credentials of offering clients using current routing info std::set<client_t> its_offering_clients; // search in local clients for the offering client for (auto request : _requests) { std::set<client_t> its_clients; its_clients = host_->find_local_clients(request.service_, request.instance_); for (auto its_client : its_clients) { its_offering_clients.insert(its_client); } } // search for UID / GID linked with the client ID that offers the requested services for (auto its_offering_client : its_offering_clients) { std::pair<uint32_t, uint32_t> its_uid_gid; if (security::get()->get_client_to_uid_gid_mapping(its_offering_client, its_uid_gid)) { if (its_uid_gid != its_requester_uid_gid) { its_credentials.insert(std::make_pair(std::get<0>(its_uid_gid), std::get<1>(its_uid_gid))); } } } // send credentials to clients if (!its_credentials.empty()) { create_client_credentials_info(_client); insert_client_credentials_info(_client, its_credentials); send_client_credentials_info(_client); } } } void routing_manager_stub::handle_requests(const client_t _client, std::set<service_data_t>& _requests) { if (!_requests.size()) { return; } bool service_available(false); std::lock_guard<std::mutex> its_guard(routing_info_mutex_); create_client_routing_info(_client); for (auto request : _requests) { service_requests_[_client][request.service_][request.instance_] = std::make_pair(request.major_, request.minor_); if (request.instance_ == ANY_INSTANCE) { std::set<client_t> its_clients = host_->find_local_clients(request.service_, request.instance_); // insert VSOMEIP_ROUTING_CLIENT to check wether service is remotely offered its_clients.insert(VSOMEIP_ROUTING_CLIENT); for (const client_t c : its_clients) { if (c != VSOMEIP_ROUTING_CLIENT && c != host_->get_client()) { if (!is_already_connected(c, _client)) { if (_client == c) { service_available = true; insert_client_routing_info(c, routing_info_entry_e::RIE_ADD_CLIENT, _client); } else { create_client_routing_info(c); insert_client_routing_info(c, routing_info_entry_e::RIE_ADD_CLIENT, _client); send_client_routing_info(c); } } } if (_client != VSOMEIP_ROUTING_CLIENT && _client != host_->get_client()) { const auto found_client = routing_info_.find(c); if (found_client != routing_info_.end()) { const auto found_service = found_client->second.second.find(request.service_); if (found_service != found_client->second.second.end()) { for (auto instance : found_service->second) { service_available = true; insert_client_routing_info(_client, routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE, c, request.service_, instance.first, instance.second.first, instance.second.second); } } } } } } else { const client_t c = host_->find_local_client(request.service_, request.instance_); const auto found_client = routing_info_.find(c); if (found_client != routing_info_.end()) { const auto found_service = found_client->second.second.find(request.service_); if (found_service != found_client->second.second.end()) { const auto found_instance = found_service->second.find(request.instance_); if (found_instance != found_service->second.end()) { if (c != VSOMEIP_ROUTING_CLIENT && c != host_->get_client()) { if (!is_already_connected(c, _client)) { if (_client == c) { service_available = true; insert_client_routing_info(c, routing_info_entry_e::RIE_ADD_CLIENT, _client); } else { create_client_routing_info(c); insert_client_routing_info(c, routing_info_entry_e::RIE_ADD_CLIENT, _client); send_client_routing_info(c); } } } if (_client != VSOMEIP_ROUTING_CLIENT && _client != host_->get_client()) { service_available = true; insert_client_routing_info(_client, routing_info_entry_e::RIE_ADD_SERVICE_INSTANCE, c, request.service_, request.instance_, found_instance->second.first, found_instance->second.second); } } } } } } if (service_available) { send_client_routing_info(_client); } } void routing_manager_stub::on_client_id_timer_expired(boost::system::error_code const &_error) { std::set<client_t> used_client_ids; { std::lock_guard<std::mutex> its_lock(used_client_ids_mutex_); used_client_ids = used_client_ids_; used_client_ids_.clear(); } std::set<client_t> erroneous_clients; if (!_error) { std::lock_guard<std::mutex> its_lock(routing_info_mutex_); for (auto client : used_client_ids) { if (client != VSOMEIP_ROUTING_CLIENT && client != get_client()) { if (routing_info_.find(client) == routing_info_.end()) { erroneous_clients.insert(client); } } } } for (auto client : erroneous_clients) { VSOMEIP_WARNING << "Releasing client identifier " << std::hex << std::setw(4) << std::setfill('0') << client << ". " << "Its corresponding application went offline while no " << "routing manager was running."; host_->handle_client_error(client); } } void routing_manager_stub::print_endpoint_status() const { if (local_receiver_) { local_receiver_->print_status(); } if (endpoint_) { endpoint_->print_status(); } } bool routing_manager_stub::send_provided_event_resend_request(client_t _client, pending_remote_offer_id_t _id) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (its_endpoint) { byte_t its_command[VSOMEIP_RESEND_PROVIDED_EVENTS_COMMAND_SIZE]; its_command[VSOMEIP_COMMAND_TYPE_POS] = VSOMEIP_RESEND_PROVIDED_EVENTS; const client_t routing_client(VSOMEIP_ROUTING_CLIENT); std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &routing_client, sizeof(routing_client)); std::uint32_t its_size = sizeof(pending_remote_offer_id_t); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS], &_id, sizeof(pending_remote_offer_id_t)); return its_endpoint->send(its_command, sizeof(its_command)); } else { VSOMEIP_WARNING << __func__ << " Couldn't send provided event resend " "request to local client: 0x" << std::hex << std::setw(4) << std::setfill('0') << _client; return false; } } bool routing_manager_stub::is_policy_cached(uint32_t _uid) { { std::lock_guard<std::mutex> its_lock(updated_security_policies_mutex_); if (updated_security_policies_.find(_uid) != updated_security_policies_.end()) { VSOMEIP_INFO << __func__ << " Policy for UID: " << std::dec << _uid << " was already updated before!"; return true; } else { return false; } } } void routing_manager_stub::policy_cache_add(uint32_t _uid, const std::shared_ptr<payload>& _payload) { // cache security policy payload for later distribution to new registering clients { std::lock_guard<std::mutex> its_lock(updated_security_policies_mutex_); updated_security_policies_[_uid] = _payload; } } void routing_manager_stub::policy_cache_remove(uint32_t _uid) { { std::lock_guard<std::mutex> its_lock(updated_security_policies_mutex_); updated_security_policies_.erase(_uid); } } bool routing_manager_stub::send_update_security_policy_request(client_t _client, pending_security_update_id_t _update_id, uint32_t _uid, const std::shared_ptr<payload>& _payload) { (void)_uid; std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (its_endpoint) { std::vector<byte_t> its_command; // command its_command.push_back(VSOMEIP_UPDATE_SECURITY_POLICY); // client ID for (uint32_t i = 0; i < sizeof(client_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_client)[i]); } // security update id length + payload length including gid and uid std::uint32_t its_size = uint32_t(sizeof(pending_security_update_id_t) + _payload->get_length()); for (uint32_t i = 0; i < sizeof(its_size); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&its_size)[i]); } // ID of update request for (uint32_t i = 0; i < sizeof(pending_security_update_id_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&_update_id)[i]); } // payload for (uint32_t i = 0; i < _payload->get_length(); ++i) { its_command.push_back(_payload->get_data()[i]); } return its_endpoint->send(its_command.data(), uint32_t(its_command.size())); } else { return false; } } bool routing_manager_stub::send_cached_security_policies(client_t _client) { std::vector<byte_t> its_command; std::size_t its_size(0); std::lock_guard<std::mutex> its_lock(updated_security_policies_mutex_); uint32_t its_policy_count = uint32_t(updated_security_policies_.size()); if (!its_policy_count) { return true; } VSOMEIP_INFO << __func__ << " Distributing [" << std::dec << its_policy_count << "] security policy updates to registering client: " << std::hex << _client; // command its_command.push_back(VSOMEIP_DISTRIBUTE_SECURITY_POLICIES); // client ID client_t its_client = get_client(); for (uint32_t i = 0; i < sizeof(client_t); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&its_client)[i]); } //overall size (placeholder for (uint32_t i = 0; i < sizeof(uint32_t); ++i) { its_command.push_back(0x00); } // number of policies contained in message for (uint32_t i = 0; i < sizeof(its_policy_count); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&its_policy_count)[i]); } for (const auto& its_uid_gid : updated_security_policies_) { // policy payload length including gid and uid std::uint32_t its_length = uint32_t(its_uid_gid.second->get_length()); for (uint32_t i = 0; i < sizeof(its_length); ++i) { its_command.push_back( reinterpret_cast<const byte_t*>(&its_length)[i]); } // payload its_command.insert(its_command.end(), its_uid_gid.second->get_data(), its_uid_gid.second->get_data() + its_uid_gid.second->get_length()); } // File overall size its_size = its_command.size() - VSOMEIP_COMMAND_PAYLOAD_POS; std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(uint32_t)); std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (its_endpoint) { return its_endpoint->send(its_command.data(), uint32_t(its_command.size())); } else { VSOMEIP_WARNING << __func__ << " Couldn't send cached security policies " " to registering client: 0x" << std::hex << std::setw(4) << std::setfill('0') << _client; return false; } } bool routing_manager_stub::send_remove_security_policy_request( client_t _client, pending_security_update_id_t _update_id, uint32_t _uid, uint32_t _gid) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(_client); if (its_endpoint) { byte_t its_command[VSOMEIP_REMOVE_SECURITY_POLICY_COMMAND_SIZE]; its_command[VSOMEIP_COMMAND_TYPE_POS] = VSOMEIP_REMOVE_SECURITY_POLICY; std::memcpy(&its_command[VSOMEIP_COMMAND_CLIENT_POS], &_client, sizeof(client_t)); std::uint32_t its_size = sizeof(_update_id) + sizeof(_uid) + sizeof(_gid); std::memcpy(&its_command[VSOMEIP_COMMAND_SIZE_POS_MIN], &its_size, sizeof(its_size)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS], &_update_id, sizeof(uint32_t)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 4], &_uid, sizeof(uint32_t)); std::memcpy(&its_command[VSOMEIP_COMMAND_PAYLOAD_POS + 8], &_gid, sizeof(uint32_t)); return its_endpoint->send(its_command, sizeof(its_command)); } else { return false; } } bool routing_manager_stub::add_requester_policies(uid_t _uid, gid_t _gid, const std::set<std::shared_ptr<policy> > &_policies) { std::lock_guard<std::mutex> its_lock(requester_policies_mutex_); auto found_uid = requester_policies_.find(_uid); if (found_uid != requester_policies_.end()) { auto found_gid = found_uid->second.find(_gid); if (found_gid != found_uid->second.end()) { found_gid->second.insert(_policies.begin(), _policies.end()); } else { found_uid->second.insert(std::make_pair(_gid, _policies)); } } else { requester_policies_[_uid][_gid] = _policies; } // Check whether clients with uid/gid are already registered. // If yes, update their policy std::unordered_set<client_t> its_clients; security::get()->get_clients(_uid, _gid, its_clients); if (!its_clients.empty()) return send_requester_policies(its_clients, _policies); return (true); } void routing_manager_stub::remove_requester_policies(uid_t _uid, gid_t _gid) { std::lock_guard<std::mutex> its_lock(requester_policies_mutex_); auto found_uid = requester_policies_.find(_uid); if (found_uid != requester_policies_.end()) { found_uid->second.erase(_gid); if (found_uid->second.empty()) requester_policies_.erase(_uid); } } void routing_manager_stub::get_requester_policies(uid_t _uid, gid_t _gid, std::set<std::shared_ptr<policy> > &_policies) const { std::lock_guard<std::mutex> its_lock(requester_policies_mutex_); auto found_uid = requester_policies_.find(_uid); if (found_uid != requester_policies_.end()) { auto found_gid = found_uid->second.find(_gid); if (found_gid != found_uid->second.end()) _policies = found_gid->second; } } void routing_manager_stub::add_pending_security_update_handler( pending_security_update_id_t _id, security_update_handler_t _handler) { std::lock_guard<std::recursive_mutex> its_lock(security_update_handlers_mutex_); security_update_handlers_[_id] = _handler; } void routing_manager_stub::add_pending_security_update_timer( pending_security_update_id_t _id) { std::shared_ptr<boost::asio::steady_timer> its_timer = std::make_shared<boost::asio::steady_timer>(io_); boost::system::error_code ec; its_timer->expires_from_now(std::chrono::milliseconds(3000), ec); if (!ec) { its_timer->async_wait( std::bind( &routing_manager_stub::on_security_update_timeout, shared_from_this(), std::placeholders::_1, _id, its_timer)); } else { VSOMEIP_ERROR << __func__ << "[" << std::dec << _id << "]: timer creation: " << ec.message(); } std::lock_guard<std::mutex> its_lock(security_update_timers_mutex_); security_update_timers_[_id] = its_timer; } bool routing_manager_stub::send_requester_policies(const std::unordered_set<client_t> &_clients, const std::set<std::shared_ptr<policy> > &_policies) { pending_security_update_id_t its_policy_id; // serialize the policies and send them... for (const auto p : _policies) { std::vector<byte_t> its_policy_data; if (p->serialize(its_policy_data)) { std::vector<byte_t> its_message; its_message.push_back(VSOMEIP_UPDATE_SECURITY_POLICY_INT); its_message.push_back(0); its_message.push_back(0); uint32_t its_policy_size = static_cast<uint32_t>(its_policy_data.size() + sizeof(uint32_t)); its_message.push_back(VSOMEIP_LONG_BYTE0(its_policy_size)); its_message.push_back(VSOMEIP_LONG_BYTE1(its_policy_size)); its_message.push_back(VSOMEIP_LONG_BYTE2(its_policy_size)); its_message.push_back(VSOMEIP_LONG_BYTE3(its_policy_size)); its_policy_id = pending_security_update_add(_clients); its_message.push_back(VSOMEIP_LONG_BYTE0(its_policy_id)); its_message.push_back(VSOMEIP_LONG_BYTE1(its_policy_id)); its_message.push_back(VSOMEIP_LONG_BYTE2(its_policy_id)); its_message.push_back(VSOMEIP_LONG_BYTE3(its_policy_id)); its_message.insert(its_message.end(), its_policy_data.begin(), its_policy_data.end()); for (const auto c : _clients) { std::shared_ptr<endpoint> its_endpoint = host_->find_local(c); if (its_endpoint) its_endpoint->send(&its_message[0], static_cast<uint32_t>(its_message.size())); } } } return (true); } void routing_manager_stub::on_security_update_timeout( const boost::system::error_code& _error, pending_security_update_id_t _id, std::shared_ptr<boost::asio::steady_timer> _timer) { (void)_timer; if (_error) { // timer was cancelled return; } security_update_state_e its_state = security_update_state_e::SU_UNKNOWN_USER_ID; std::unordered_set<client_t> its_missing_clients = pending_security_update_get(_id); { // erase timer std::lock_guard<std::mutex> its_lock(security_update_timers_mutex_); security_update_timers_.erase(_id); } { // print missing responses and check if some clients did not respond because they already disconnected if (!its_missing_clients.empty()) { for (auto its_client : its_missing_clients) { VSOMEIP_INFO << __func__ << ": Client 0x" << std::hex << its_client << " did not respond to the policy update / removal with ID: 0x" << std::hex << _id; if (!host_->find_local(its_client)) { VSOMEIP_INFO << __func__ << ": Client 0x" << std::hex << its_client << " is not connected anymore, do not expect answer for policy update / removal with ID: 0x" << std::hex << _id; pending_security_update_remove(_id, its_client); } } } its_missing_clients = pending_security_update_get(_id); if (its_missing_clients.empty()) { VSOMEIP_INFO << __func__ << ": Received all responses for " "security update/removal ID: 0x" << std::hex << _id; its_state = security_update_state_e::SU_SUCCESS; } { // erase pending security update std::lock_guard<std::mutex> its_lock(pending_security_updates_mutex_); pending_security_updates_.erase(_id); } // call handler with error on timeout or with SUCCESS if missing clients are not connected std::lock_guard<std::recursive_mutex> its_lock(security_update_handlers_mutex_); const auto found_handler = security_update_handlers_.find(_id); if (found_handler != security_update_handlers_.end()) { found_handler->second(its_state); security_update_handlers_.erase(found_handler); } else { VSOMEIP_WARNING << __func__ << ": Callback not found for security update / removal with ID: 0x" << std::hex << _id; } } } bool routing_manager_stub::update_security_policy_configuration( uint32_t _uid, uint32_t _gid, const std::shared_ptr<policy> &_policy, const std::shared_ptr<payload> &_payload, const security_update_handler_t &_handler) { bool ret(true); // cache security policy payload for later distribution to new registering clients policy_cache_add(_uid, _payload); // update security policy from configuration security::get()->update_security_policy(_uid, _gid, _policy); // Build requester policies for the services offered by the new policy std::set<std::shared_ptr<policy> > its_requesters; security::get()->get_requester_policies(_policy, its_requesters); // and add them to the requester policy cache add_requester_policies(_uid, _gid, its_requesters); // determine currently connected clients std::unordered_set<client_t> its_clients_to_inform; auto its_epm = host_->get_endpoint_manager(); if (its_epm) its_clients_to_inform = its_epm->get_connected_clients(); // add handler pending_security_update_id_t its_id; if (!its_clients_to_inform.empty()) { its_id = pending_security_update_add(its_clients_to_inform); add_pending_security_update_handler(its_id, _handler); add_pending_security_update_timer(its_id); // trigger all currently connected clients to update the security policy uint32_t sent_counter(0); uint32_t its_tranche = uint32_t(its_clients_to_inform.size() >= 10 ? (its_clients_to_inform.size() / 10) : 1); VSOMEIP_INFO << __func__ << ": Informing [" << std::dec << its_clients_to_inform.size() << "] currently connected clients about policy update for UID: " << std::dec << _uid << " with update ID: 0x" << std::hex << its_id; for (auto its_client : its_clients_to_inform) { if (!send_update_security_policy_request(its_client, its_id, _uid, _payload)) { VSOMEIP_INFO << __func__ << ": Couldn't send update security policy " << "request to client 0x" << std::hex << std::setw(4) << std::setfill('0') << its_client << " policy UID: " << std::hex << std::setw(4) << std::setfill('0') << _uid << " GID: " << std::hex << std::setw(4) << std::setfill('0') << _gid << " with update ID: 0x" << std::hex << its_id << " as client already disconnected"; // remove client from expected answer list pending_security_update_remove(its_id, its_client); } sent_counter++; // Prevent burst if (sent_counter % its_tranche == 0) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } } else { // if routing manager has no client call the handler directly _handler(security_update_state_e::SU_SUCCESS); } return ret; } bool routing_manager_stub::remove_security_policy_configuration( uint32_t _uid, uint32_t _gid, const security_update_handler_t &_handler) { bool ret(true); // remove security policy from configuration (only if there was a updateACL call before) if (is_policy_cached(_uid)) { if (!security::get()->remove_security_policy(_uid, _gid)) { _handler(security_update_state_e::SU_UNKNOWN_USER_ID); ret = false; } else { // remove policy from cache to prevent sending it to registering clients policy_cache_remove(_uid); // add handler pending_security_update_id_t its_id; // determine currently connected clients std::unordered_set<client_t> its_clients_to_inform; auto its_epm = host_->get_endpoint_manager(); if (its_epm) its_clients_to_inform = its_epm->get_connected_clients(); if (!its_clients_to_inform.empty()) { its_id = pending_security_update_add(its_clients_to_inform); add_pending_security_update_handler(its_id, _handler); add_pending_security_update_timer(its_id); // trigger all clients to remove the security policy uint32_t sent_counter(0); uint32_t its_tranche = uint32_t(its_clients_to_inform.size() >= 10 ? (its_clients_to_inform.size() / 10) : 1); VSOMEIP_INFO << __func__ << ": Informing [" << std::dec << its_clients_to_inform.size() << "] currently connected clients about policy removal for UID: " << std::dec << _uid << " with update ID: " << its_id; for (auto its_client : its_clients_to_inform) { if (!send_remove_security_policy_request(its_client, its_id, _uid, _gid)) { VSOMEIP_INFO << __func__ << ": Couldn't send remove security policy " << "request to client 0x" << std::hex << std::setw(4) << std::setfill('0') << its_client << " policy UID: " << std::hex << std::setw(4) << std::setfill('0') << _uid << " GID: " << std::hex << std::setw(4) << std::setfill('0') << _gid << " with update ID: 0x" << std::hex << its_id << " as client already disconnected"; // remove client from expected answer list pending_security_update_remove(its_id, its_client); } sent_counter++; // Prevent burst if (sent_counter % its_tranche == 0) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } } else { // if routing manager has no client call the handler directly _handler(security_update_state_e::SU_SUCCESS); } } } else { _handler(security_update_state_e::SU_UNKNOWN_USER_ID); ret = false; } return ret; } pending_security_update_id_t routing_manager_stub::pending_security_update_add( const std::unordered_set<client_t>& _clients) { std::lock_guard<std::mutex> its_lock(pending_security_updates_mutex_); if (++pending_security_update_id_ == 0) { pending_security_update_id_++; } pending_security_updates_[pending_security_update_id_] = _clients; return pending_security_update_id_; } std::unordered_set<client_t> routing_manager_stub::pending_security_update_get( pending_security_update_id_t _id) { std::lock_guard<std::mutex> its_lock(pending_security_updates_mutex_); std::unordered_set<client_t> its_missing_clients; auto found_si = pending_security_updates_.find(_id); if (found_si != pending_security_updates_.end()) { its_missing_clients = pending_security_updates_[_id]; } return its_missing_clients; } bool routing_manager_stub::pending_security_update_remove( pending_security_update_id_t _id, client_t _client) { std::lock_guard<std::mutex> its_lock(pending_security_updates_mutex_); auto found_si = pending_security_updates_.find(_id); if (found_si != pending_security_updates_.end()) { if (found_si->second.erase(_client)) { return true; } } return false; } bool routing_manager_stub::is_pending_security_update_finished( pending_security_update_id_t _id) { std::lock_guard<std::mutex> its_lock(pending_security_updates_mutex_); bool ret(false); auto found_si = pending_security_updates_.find(_id); if (found_si != pending_security_updates_.end()) { if (!found_si->second.size()) { ret = true; } } if (ret) { pending_security_updates_.erase(_id); } return ret; } void routing_manager_stub::on_security_update_response( pending_security_update_id_t _id, client_t _client) { if (pending_security_update_remove(_id, _client)) { if (is_pending_security_update_finished(_id)) { // cancel timeout timer { std::lock_guard<std::mutex> its_lock(security_update_timers_mutex_); auto found_timer = security_update_timers_.find(_id); if (found_timer != security_update_timers_.end()) { boost::system::error_code ec; found_timer->second->cancel(ec); security_update_timers_.erase(found_timer); } else { VSOMEIP_WARNING << __func__ << ": Received all responses " "for security update/removal ID: 0x" << std::hex << _id << " but timeout already happened"; } } // call handler { std::lock_guard<std::recursive_mutex> its_lock(security_update_handlers_mutex_); auto found_handler = security_update_handlers_.find(_id); if (found_handler != security_update_handlers_.end()) { found_handler->second(security_update_state_e::SU_SUCCESS); security_update_handlers_.erase(found_handler); VSOMEIP_INFO << __func__ << ": Received all responses for " "security update/removal ID: 0x" << std::hex << _id; } else { VSOMEIP_WARNING << __func__ << ": Received all responses " "for security update/removal ID: 0x" << std::hex << _id << " but didn't find handler"; } } } } } } // namespace vsomeip_v3
Require Import Crypto.Specific.Framework.RawCurveParameters. Require Import Crypto.Util.LetIn. (*** Modulus : 2^226 - 5 Base: 45.2 ***) Definition curve : CurveParameters := {| sz := 5%nat; base := 45 + 1/5; bitwidth := 64; s := 2^226; c := [(1, 5)]; carry_chains := Some [seq 0 (pred 5); [0; 1]]%nat; a24 := None; coef_div_modulus := Some 2%nat; goldilocks := None; karatsuba := None; montgomery := false; freeze := Some true; ladderstep := false; mul_code := None; square_code := None; upper_bound_of_exponent_loose := None; upper_bound_of_exponent_tight := None; allowable_bit_widths := None; freeze_extra_allowable_bit_widths := None; modinv_fuel := None |}. Ltac extra_prove_mul_eq _ := idtac. Ltac extra_prove_square_eq _ := idtac.
theory flash101Rev imports flashPub begin section{*Main defintions*} lemma NI_FAckVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_FAck ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_InvVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Inv iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_InvAck_1VsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_InvAck_1 iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have "?P2 s" by(cut_tac a1 a2 a3 a4, auto) then show "?P1 s\<or>?P2 s\<or>?P3 s" by auto qed lemma NI_InvAck_1_HomeVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_InvAck_1_Home iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_InvAck_2VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_InvAck_2 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_Local_GetX_GetXVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_GetX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P3 s" apply( cut_tac a1 a2 b1 , simp) apply(rule_tac x=" (neg ( andForm ( eqn ( IVar ( Para ''procCmd'' iInv1) ) ( Const NODE_None )) ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) ) ( Const UNI_GetX )) ) ) " in exI,auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_Nak1VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_Nak1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_Nak2VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_Nak2 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_Nak3VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_Nak3 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX1VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX1 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX2VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX2 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX3VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX3 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX4VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX4 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX5VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX5 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX6VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX6 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX7VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX7 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX8VsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX8 N iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) " by( cut_tac a1 a2 a3 a4 , auto) moreover {assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))" have "?P1 s" apply(cut_tac a1 a2 a3 a4 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX8_homeVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX8_home N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX9VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX9 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX10VsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX10 N iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) " by( cut_tac a1 a2 a3 a4 , auto) moreover {assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))" have "?P1 s" apply(cut_tac a1 a2 a3 a4 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX10_homeVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX10_home N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_GetX_PutX11VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_GetX_PutX11 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_Get_GetVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Get iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_Local_Get_Nak1VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Nak1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_Get_Nak2VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Nak2 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_Get_Nak3VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Nak3 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_Get_Put1VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Put1 N iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_Get_Put2VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Put2 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_Get_Put3VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Get_Put3 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Local_PutVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_Put ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_Local_PutXAcksDoneVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Local_PutXAcksDone ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_NakVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Nak iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Nak_ClearVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Nak_Clear ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_Nak_HomeVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Nak_Home ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_Remote_GetX_NakVsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_GetX_Nak iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) " by( cut_tac a1 a2 a3 a4 , auto) moreover {assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))" have "?P1 s" apply(cut_tac a1 a2 a3 a4 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Remote_GetX_Nak_HomeVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_GetX_Nak_Home iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_Remote_GetX_PutXVsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_GetX_PutX iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) " by( cut_tac a1 a2 a3 a4 , auto) moreover {assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))" have "?P1 s" apply(cut_tac a1 a2 a3 a4 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Remote_GetX_PutX_HomeVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_GetX_PutX_Home iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_Remote_Get_Nak1VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_Get_Nak1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_Remote_Get_Nak2VsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_Get_Nak2 iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) " by( cut_tac a1 a2 a3 a4 , auto) moreover {assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))" have "?P1 s" apply(cut_tac a1 a2 a3 a4 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Remote_Get_Put1VsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_Get_Put1 iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_Remote_Get_Put2VsInv101: (*Rule2VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iRule2 \<le> N" and a3:"iInv1 \<le> N" and a4:"iRule1~=iRule2 " shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_Get_Put2 iRule1 iRule2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1\<and>(iRule2~=iInv1 )) \<or>((iRule1~=iInv1 )\<and>iRule2=iInv1) \<or>((iRule1~=iInv1 )\<and>(iRule2~=iInv1 )) " by( cut_tac a1 a2 a3 a4 , auto) moreover {assume b1:"(iRule1=iInv1\<and>(iRule2~=iInv1 ))" have "?P1 s" apply(cut_tac a1 a2 a3 a4 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>iRule2=iInv1)" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 )\<and>(iRule2~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 a3 a4 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Remote_PutVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_Put iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_Remote_PutXVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Remote_PutX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma NI_ReplaceVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Replace iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_ReplaceHomeVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_ReplaceHome ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_ReplaceHomeShrVldVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_ReplaceHomeShrVld ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_ReplaceShrVldVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_ReplaceShrVld iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma NI_ShWbVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_ShWb N ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma NI_WbVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (NI_Wb ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_GetX_GetX1VsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_GetX_GetX1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_GetX_GetX2VsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_GetX_GetX2 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_GetX_PutX1VsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_GetX_PutX2VsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_GetX_PutX3VsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_GetX_PutX3 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_GetX_PutX4VsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_GetX_PutX4 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_Get_GetVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_Get_Get ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_Get_PutVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_Get_Put ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_PutXVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_PutX ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Local_ReplaceVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Local_Replace ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) lemma PI_Remote_GetVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Remote_Get iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma PI_Remote_GetXVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Remote_GetX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") proof - have allCases:"(iRule1=iInv1) \<or>((iRule1~=iInv1 )) " by( cut_tac a1 a2 , auto) moreover {assume b1:"(iRule1=iInv1)" have "?P1 s" apply(cut_tac a1 a2 b1 , auto) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } moreover {assume b1:"((iRule1~=iInv1 ))" have "?P2 s" apply(cut_tac a1 a2 b1 , auto intro!:forallVars1 simp add :invHoldForRule2'_def varsOfVar_def) done then have "?P1 s\<or> ?P2 s \<or> ?P3 s" by blast } ultimately show "?P1 s\<or> ?P2 s\<or> ?P3 s" by metis qed lemma PI_Remote_PutXVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Remote_PutX iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma PI_Remote_ReplaceVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (PI_Remote_Replace iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma StoreVsInv101: (*Rule1VsPInv1*) assumes a1:"iRule1 \<le> N" and a2:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (Store iRule1 ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 a2 , auto) lemma StoreHomeVsInv101: (*Rule0VsPInv1*) assumes a1:"iInv1 \<le> N" shows "invHoldForRule' s (inv101 iInv1 ) (StoreHome ) (invariants N)" (is " ?P1 s\<or>?P2 s\<or>?P3 s") by (cut_tac a1 , auto) end
using JLD2 using GLMakie include("one_degree_artifacts.jl") include("one_degree_interface_heights.jl") z_interfaces = one_degree_interface_heights() z_centers = (z_interfaces[1:end-1] .+ z_interfaces[2:end]) ./ 2 filename = "bathymetry-360x150-latitude-75.0.jld2" file = jldopen(filename) h = file["bathymetry"] close(file) land = h .> 0 initial_condition_path = download_initial_condition() file = jldopen(initial_condition_path) Tᵢ = file["T"] Nz = size(Tᵢ, 3) for k in 1:Nz z = z_centers[k] earth = h .> z view(Tᵢ, :, :, k)[earth] .= NaN end fig = Figure(resolution=(1800, 800)) ax = Axis(fig[2, 1]) slider = Slider(fig[3, 1:2], range=1:Nz, startvalue=Nz) k = slider.value depth = @lift z_centers[$k] title = @lift string("Temperature (ᵒC) at z = ", $depth, " m") Label(fig[1, 1:2], title) Tᵏ = @lift view(Tᵢ, :, :, $k) hm = heatmap!(ax, Tᵏ, colorrange=(-2, 32), colormap=:thermal) Colorbar(fig[2, 2], hm, label="Temperature (ᵒC)") display(fig) record(fig, "one_degree_initial_condition.mp4", 1:Nz, framerate=12) do kk k[] = kk end
%% patchEdges % Below is a demonstration of the features of the |patchEdges| function %% clear; close all; clc; %% Syntax % |varargout=patchEdges(varargin);| %% Description % UNDOCUMENTED %% Examples % %% % % <<gibbVerySmall.gif>> % % _*GIBBON*_ % <www.gibboncode.org> % % _Kevin Mattheus Moerman_, <[email protected]> %% % _*GIBBON footer text*_ % % License: <https://github.com/gibbonCode/GIBBON/blob/master/LICENSE> % % GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for % image segmentation, image-based modeling, meshing, and finite element % analysis. % % Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors % % 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, see <http://www.gnu.org/licenses/>.
(* This program is free software; you can redistribute it and/or *) (* modify it under the terms of the GNU Lesser General Public License *) (* as published by the Free Software Foundation; either version 2.1 *) (* of the License, or (at your option) any later version. *) (* *) (* This 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 Lesser General Public *) (* License along with this program; if not, write to the Free *) (* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *) (* 02110-1301 USA *) (* Contribution to the Coq Library V6.3 (July 1999) *) (* monofun.v *) (* *) (* Author: Pierre Casteran. *) (* LABRI, URA CNRS 1304, *) (* Departement d'Informatique, Universite Bordeaux I, *) (* 33405 Talence CEDEX, *) (* e-mail: [email protected] *) (* the monoid of functions from A to A *) (***************************************) Require Import monoid. Section fun_. Variable A : Set. Hypothesis eta_A : forall f g : A -> A, (forall x : A, f x = g x) -> f = g. Let comp (f g : A -> A) (x : A) := g (f x). Let Id (a : A) := a. Lemma funmono : monoid (A -> A). Proof. refine (mkmonoid (A -> A) Id comp _ _ _); auto. Defined. End fun_.
''' Source codes for Python Machine Learning By Example 3rd Edition (Packt Publishing) Chapter 5 Predicting Online Ads Click-through with Logistic Regression Author: Yuxi (Hayden) Liu ([email protected]) ''' import numpy as np import pandas as pd n_rows = 100000 df = pd.read_csv("train", nrows=n_rows) X = df.drop(['click', 'id', 'hour', 'device_id', 'device_ip'], axis=1).values Y = df['click'].values X_train = X Y_train = Y from sklearn.preprocessing import OneHotEncoder enc = OneHotEncoder(handle_unknown='ignore') X_train_enc = enc.fit_transform(X_train) # Feature selection with random forest from sklearn.ensemble import RandomForestClassifier random_forest = RandomForestClassifier(n_estimators=100, criterion='gini', min_samples_split=30, n_jobs=-1) random_forest.fit(X_train_enc.toarray(), Y_train) feature_imp = random_forest.feature_importances_ print(feature_imp) # bottom 10 weights and the corresponding 10 least important features feature_names = enc.get_feature_names() print(np.sort(feature_imp)[:10]) bottom_10 = np.argsort(feature_imp)[:10] print('10 least important features are:\n', feature_names[bottom_10]) # top 10 weights and the corresponding 10 most important features print(np.sort(feature_imp)[-10:]) top_10 = np.argsort(feature_imp)[-10:] print('10 most important features are:\n', feature_names[top_10])
#Emera Tagging project.library( 'aegis', 'bio.snowcrab') dn = file.path(project.datadirectory("bio.snowcrab"),'data','tagging','Emera') a = dir(dn) b = a[grep('tags',a)] a = a[grep('meta',a)] a = read.csv(file.path(dn,a),header=T) out = NULL for(i in b) { h = read.csv(file.path(dn,i),header=T) out = rbind(h,out) } names(out) = tolower(names(out)) out$dt = strptime(out$datetime, format= "%d/%m/%Y %H:%M") #N Animals detects b= unique(out$transmitter) #58 #N Detects per anmimal a = aggregate(detectedid~transmitter,data=out,FUN=length) #each animal with(out[which(out$transmitter==b[1]),]) for(i in 1:length(b)) { oo = out[which(out$transmitter==b[i]),] oo = oo[order(oo$dt),] ll = nrow(oo) oo$ms = c(0,oo$dt[2:(ll)]-oo$dt[1:(ll-1)]) makeMap(xlim=c(-60.3,-60.1),ylim=c(46.5,46.6)) with(oo,plot(lon,lat,type='l',lwd=0.4)) title(paste(b[i],'N days =', round(as.numeric(max(oo$dt)-min(oo$dt)[1]),1) )) savePlot(file.path(dn,paste('tag',b[i],".pdf",sep=".")),type='pdf') }
theory FSM2 imports "../../Transition_Systems_and_Automata/Basic/Sequence_Zip" "../../Transition_Systems_and_Automata/Transition_Systems/Transition_System" "../../Transition_Systems_and_Automata/Transition_Systems/Transition_System_Extra" "../../Transition_Systems_and_Automata/Transition_Systems/Transition_System_Construction" begin section {* Finite state machines *} text \<open> We formalise finite state machines as a 4-tuples, omitting the explicit formulation of the state set,as it can easily be calculated from the successor function. This definition does not require the successor function to be restricted to the input or output alphabet, which is later expressed by the property @{verbatim well_formed}, together with the finiteness of the state set. \<close> record FSM = initial :: nat inputs :: "nat list" outputs :: "nat list" transitions :: "(nat \<times> nat \<times> nat \<times> nat) list" abbreviation "h M \<equiv> transitions M" abbreviation "t_source (a ::nat \<times> nat \<times> nat \<times> nat) \<equiv> fst a" abbreviation "t_input (a ::nat \<times> nat \<times> nat \<times> nat) \<equiv> fst (snd a)" abbreviation "t_output (a ::nat \<times> nat \<times> nat \<times> nat) \<equiv> fst (snd (snd a))" abbreviation "t_target (a ::nat \<times> nat \<times> nat \<times> nat) \<equiv> snd (snd (snd a))" value "t_source (1,2,3,4)" value "t_input (1,2,3,4)" value "t_output (1,2,3,4)" value "t_target (1,2,3,4)" subsection {* FSMs as transition systems *} text \<open> We interpret FSMs as transition systems with a singleton initial state set, based on @{cite "Transition_Systems_and_Automata-AFP"}. \<close> global_interpretation FSM : transition_system_initial (* "\<lambda> ((x,y),q') p. q'" \<comment> \<open>execute\<close> "\<lambda> ((x,y),q') q. (q,x,y,q') \<in> set (h A) \<and> x \<in> set (inputs A) \<and> y \<in> set (outputs A)" \<comment> \<open>enabled\<close> *) "\<lambda> a p. snd a" \<comment> \<open>execute\<close> "\<lambda> a p. (p,fst (fst a), snd (fst a),snd a) \<in> set (h A) \<and> fst (fst a) \<in> set (inputs A) \<and> snd (fst a) \<in> set (outputs A)" \<comment> \<open>enabled\<close> "\<lambda> p. p = initial A" \<comment> \<open>initial\<close> for A defines path = FSM.path and run = FSM.run and reachable = FSM.reachable and nodes = FSM.nodes by this abbreviation "size_FSM M \<equiv> card (nodes M)" notation size_FSM ("(|_|)") fun is_wf_transition :: "'a FSM_scheme \<Rightarrow> (nat \<times> nat \<times> nat \<times> nat) \<Rightarrow> bool" where "is_wf_transition M t = ((t_input t) \<in> set (inputs M) \<and> (t_output t) \<in> set (outputs M))" fun wf_transrel :: "'a FSM_scheme \<Rightarrow> (nat \<times> nat) set" where "wf_transrel M = image (\<lambda> t. (t_source t, t_target t)) (set (filter (is_wf_transition M) (h M)))" lemma wf_transrel_transition_ob : assumes "tr \<in> wf_transrel M" obtains t where "t \<in> set (h M)" and "fst tr = t_source t" and "snd tr = t_target t" and "is_wf_transition M t" using assms by auto fun wf_trancl :: "'a FSM_scheme \<Rightarrow> (nat \<times> nat) set" where "wf_trancl M = trancl (wf_transrel M)" fun isReachable :: "'a FSM_scheme \<Rightarrow> nat \<Rightarrow> bool" where "isReachable M q = ((initial M, q) \<in> wf_trancl M)" fun nodes' :: "'a FSM_scheme \<Rightarrow> nat set" where "nodes' M = insert (initial M) (set (filter (isReachable M) (map t_target (h M))))" lemma reachable_next : assumes "isReachable M (t_source t)" and "is_wf_transition M t" and "t \<in> set (h M)" shows "isReachable M (t_target t)" proof - have "(initial M, t_source t) \<in> wf_trancl M" using assms(1) by auto moreover have "(t_source t, t_target t) \<in> wf_transrel M" using assms(2,3) by auto ultimately show ?thesis by auto qed lemma nodes'_next : assumes "t_source t \<in> nodes' M" and "is_wf_transition M t" and "t \<in> set (h M)" shows "t_target t \<in> nodes' M" proof (cases "t_source t = initial M") case True moreover have "(t_source t, t_target t) \<in> wf_transrel M" using assms(2,3) by auto ultimately have "(initial M, t_target t) \<in> wf_transrel M" by auto then show ?thesis by auto next case False then have "(initial M, t_source t) \<in> wf_trancl M" using assms(1) by auto moreover have "(t_source t, t_target t) \<in> wf_transrel M" using assms(2,3) by auto ultimately have "(initial M, t_target t) \<in> wf_trancl M" by auto then show ?thesis using assms(3) by auto qed value "wf_transrel (\<lparr> initial = 2, inputs = [0,1,2], outputs = [10,20,30], transitions = [(2,1,20,3),(2,1,20,4),(3,1,20,5)] \<rparr>)" value "wf_trancl (\<lparr> initial = 2, inputs = [0,1,2], outputs = [10,20,30], transitions = [(2,1,20,3),(2,1,20,4),(3,1,20,5)] \<rparr>)" value "map (isReachable (\<lparr> initial = 2, inputs = [0,1,2], outputs = [10,20,30], transitions = [(2,1,20,3),(2,1,20,4),(3,1,20,5)] \<rparr>)) [1,2,3,4,5,6]" value "nodes' (\<lparr> initial = 2, inputs = [0,1,2], outputs = [10,20,30], transitions = [(2,1,20,3),(2,1,20,4),(3,1,20,5)] \<rparr>)" subsection {* Language *} text \<open> The following definitions establish basic notions for FSMs similarly to those of nondeterministic finite automata as defined in @{cite "Transition_Systems_and_Automata-AFP"}. In particular, the language of an FSM state are the IO-parts of the paths in the FSM enabled from that state. \<close> abbreviation "target \<equiv> FSM.target" abbreviation "states \<equiv> FSM.states" abbreviation "trace \<equiv> FSM.trace" abbreviation successors :: "('more) FSM_scheme \<Rightarrow> nat \<Rightarrow> nat set" where "successors \<equiv> FSM.successors TYPE('more)" lemma states_alt_def: "states r p = map snd r" by (induct r arbitrary: p) (auto) lemma trace_alt_def: "trace r p = smap snd r" by (coinduction arbitrary: r p) (auto) lemma wf_trancl_path : assumes "(q,q') \<in> wf_trancl M" obtains p where "path M p q" and "target p q = q'" proof - have "\<exists> p .path M p q \<and> target p q = q'" using assms unfolding wf_trancl.simps proof (induction rule: trancl.induct) case (r_into_trancl a b) then obtain t where "t \<in> set (h M)" and "a = t_source t" and "b = t_target t" and "is_wf_transition M t" by auto then have "path M [((t_input t, t_output t), b)] a" and "target [((t_input t, t_output t), b)] a = b" by auto then show "\<exists>p. path M p a \<and> target p a = b" using r_into_trancl.prems by auto next case (trancl_into_trancl a b c) then obtain p where "path M p a" and "target p a = b" by blast obtain t where "t \<in> set (h M)" and "b = t_source t" and "c = t_target t" and "is_wf_transition M t" using trancl_into_trancl.hyps(2) by auto then have "path M [((t_input t, t_output t), c)] b" and "target [((t_input t, t_output t), c)] b = c" by auto have "path M (p@[((t_input t, t_output t), c)]) a" by (simp add: FSM.path_append \<open>path M [((t_input t, t_output t), c)] b\<close> \<open>path M p a\<close> \<open>target p a = b\<close>) moreover have "target (p@[((t_input t, t_output t), c)]) a = c" proof - have "target (p@[((t_input t, t_output t), c)]) a = target [((t_input t, t_output t), c)] a" by auto then show ?thesis by simp qed ultimately show ?case by blast qed then show ?thesis using that by auto qed let ?t = "(target p (initial M),fst (fst a), snd (fst a),q)" have "is_wf_transition M ?t" by (simp add: \<open>fst (fst a) \<in> set (inputs M)\<close> \<open>snd (fst a) \<in> set (outputs M)\<close>) have "target p (initial M) \<in> nodes' M" using snoc by auto then have "t_source ?t \<in> nodes' M" by auto show ?case using nodes'_next[OF \<open>t_source ?t \<in> nodes' M\<close> \<open>is_wf_transition M ?t\<close> \<open>?t \<in> set (h M)\<close>] by auto qed qed show "nodes' M \<subseteq> nodes M" proof fix q assume "q \<in> nodes' M" then show "q \<in> nodes M" proof (cases "q = initial M") case True then show ?thesis by auto next case False then have "(initial M, q) \<in> wf_trancl M" using \<open>q \<in> nodes' M\<close> by auto obtain p where "path M p (initial M) \<and> target p (initial M) = q" using wf_trancl_path[OF \<open>(initial M, q) \<in> wf_trancl M\<close>] by auto then show ?thesis by auto qed qed qed definition language_state :: "FSM \<Rightarrow> nat \<Rightarrow> (nat \<times> nat) list set" ("LS") where "language_state M q \<equiv> {map fst r |r . path M r q}" text \<open> The language of an FSM is the language of its initial state. \<close> abbreviation "L M \<equiv> LS M (initial M)" lemma language_state_alt_def : "LS M q = {io | io tr . path M (io || tr) q \<and> length io = length tr}" proof - have "LS M q \<subseteq> { io | io tr . path M (io || tr) q \<and> length io = length tr }" proof fix xr assume xr_assm : "xr \<in> LS M q" then obtain r where r_def : "map fst r = xr" "path M r q" unfolding language_state_def by auto then obtain xs ys where xr_split : "xr = xs || ys" "length xs = length ys" "length xs = length xr" by (metis length_map zip_map_fst_snd) then have "(xs || ys) \<in> { io | io tr . path M (io || tr) q \<and> length io = length tr }" proof - have f1: "xs || ys = map fst r" by (simp add: r_def(1) xr_split(1)) then have f2: "path M ((xs || ys) || take (min (length (xs || ys)) (length (map snd r))) (map snd r)) q" by (simp add: r_def(2)) have "length (xs || ys) = length (take (min (length (xs || ys)) (length (map snd r))) (map snd r))" using f1 by force then show ?thesis using f2 by blast qed then show "xr \<in> { io | io tr . path M (io || tr) q \<and> length io = length tr }" using xr_split by metis qed moreover have "{ io | io tr . path M (io || tr) q \<and> length io = length tr } \<subseteq> LS M q" proof fix xs assume xs_assm : "xs \<in> { io | io tr . path M (io || tr) q \<and> length io = length tr }" then obtain ys where ys_def : "path M (xs || ys) q" "length xs = length ys" by auto then have "xs = map fst (xs || ys)" by auto then show "xs \<in> LS M q" using ys_def unfolding language_state_def by blast qed ultimately show ?thesis by auto qed lemma language_state[intro]: assumes "path M (w || r) q" "length w = length r" shows "w \<in> LS M q" using assms unfolding language_state_def by force lemma language_state_elim[elim]: assumes "w \<in> LS M q" obtains r where "path M (w || r) q" "length w = length r" using assms unfolding language_state_def by (force iff: split_zip_ex) lemma language_state_split: assumes "w1 @ w2 \<in> LS M q" obtains tr1 tr2 where "path M (w1 || tr1) q" "length w1 = length tr1" "path M (w2 || tr2) (target (w1 || tr1) q)" "length w2 = length tr2" proof - obtain tr where tr_def : "path M ((w1 @ w2) || tr) q" "length (w1 @ w2) = length tr" using assms by blast let ?tr1 = "take (length w1) tr" let ?tr2 = "drop (length w1) tr" have tr_split : "?tr1 @ ?tr2 = tr" by auto then show ?thesis proof - have f1: "length w1 + length w2 = length tr" using tr_def(2) by auto then have f2: "length w2 = length tr - length w1" by presburger then have "length w1 = length (take (length w1) tr)" using f1 by (metis (no_types) tr_split diff_add_inverse2 length_append length_drop) then show ?thesis using f2 by (metis (no_types) FSM.path_append_elim length_drop that tr_def(1) zip_append1) qed qed lemma language_state_prefix : assumes "w1 @ w2 \<in> LS M q" shows "w1 \<in> LS M q" using assms by (meson language_state language_state_split) lemma succ_nodes : fixes A :: "('a,'b,'c) FSM" and w :: "('a \<times> 'b)" assumes "q2 \<in> succ A w q1" and "q1 \<in> nodes A" shows "q2 \<in> nodes A" proof - obtain x y where "w = (x,y)" by (meson surj_pair) then have "q2 \<in> successors A q1" using assms by auto then have "q2 \<in> reachable A q1" by blast then have "q2 \<in> reachable A (initial A)" using assms by blast then show "q2 \<in> nodes A" by blast qed lemma states_target_index : assumes "i < length p" shows "(states p q1) ! i = target (take (Suc i) p) q1" using assms by auto subsection {* Product machine for language intersection *} text \<open> The following describes the construction of a product machine from two FSMs @{verbatim M1} and @{verbatim M2} such that the language of the product machine is the intersection of the language of @{verbatim M1} and the language of @{verbatim M2}. \<close> definition product :: "('in, 'out, 'state1) FSM \<Rightarrow> ('in, 'out, 'state2) FSM \<Rightarrow> ('in, 'out, 'state1 \<times>'state2) FSM" where "product A B \<equiv> \<lparr> succ = \<lambda> a (p\<^sub>1, p\<^sub>2). succ A a p\<^sub>1 \<times> succ B a p\<^sub>2, inputs = inputs A \<union> inputs B, outputs = outputs A \<union> outputs B, initial = (initial A, initial B) \<rparr>" lemma product_simps[simp]: "succ (product A B) a (p\<^sub>1, p\<^sub>2) = succ A a p\<^sub>1 \<times> succ B a p\<^sub>2" "inputs (product A B) = inputs A \<union> inputs B" "outputs (product A B) = outputs A \<union> outputs B" "initial (product A B) = (initial A, initial B)" unfolding product_def by simp+ lemma product_target[simp]: assumes "length w = length r\<^sub>1" "length r\<^sub>1 = length r\<^sub>2" shows "target (w || r\<^sub>1 || r\<^sub>2) (p\<^sub>1, p\<^sub>2) = (target (w || r\<^sub>1) p\<^sub>1, target (w || r\<^sub>2) p\<^sub>2)" using assms by (induct arbitrary: p\<^sub>1 p\<^sub>2 rule: list_induct3) (auto) lemma product_path[iff]: assumes "length w = length r\<^sub>1" "length r\<^sub>1 = length r\<^sub>2" shows "path (product A B) (w || r\<^sub>1 || r\<^sub>2) (p\<^sub>1, p\<^sub>2) \<longleftrightarrow> path A (w || r\<^sub>1) p\<^sub>1 \<and> path B (w || r\<^sub>2) p\<^sub>2" using assms by (induct arbitrary: p\<^sub>1 p\<^sub>2 rule: list_induct3) (auto) lemma product_language_state[simp]: "LS (product A B) (q1,q2) = LS A q1 \<inter> LS B q2" by (fastforce iff: split_zip) lemma product_nodes : "nodes (product A B) \<subseteq> nodes A \<times> nodes B" proof fix q assume "q \<in> nodes (product A B)" then show "q \<in> nodes A \<times> nodes B" proof (induction rule: FSM.nodes.induct) case (initial p) then show ?case by auto next case (execute p a) then have "fst p \<in> nodes A" "snd p \<in> nodes B" by auto have "snd a \<in> (succ A (fst a) (fst p)) \<times> (succ B (fst a) (snd p))" using execute by auto then have "fst (snd a) \<in> succ A (fst a) (fst p)" "snd (snd a) \<in> succ B (fst a) (snd p)" by auto have "fst (snd a) \<in> nodes A" using \<open>fst p \<in> nodes A\<close> \<open>fst (snd a) \<in> succ A (fst a) (fst p)\<close> by (metis FSM.nodes.simps fst_conv snd_conv) moreover have "snd (snd a) \<in> nodes B" using \<open>snd p \<in> nodes B\<close> \<open>snd (snd a) \<in> succ B (fst a) (snd p)\<close> by (metis FSM.nodes.simps fst_conv snd_conv) ultimately show ?case by (simp add: mem_Times_iff) qed qed subsection {* Required properties *} text \<open> FSMs used by the adaptive state counting algorithm are required to satisfy certain properties which are introduced in here. Most notably, the observability property (see observable) implies the uniqueness of certain paths and hence allows for several stronger reformulations of previous results. \<close> fun finite_FSM :: "('in, 'out, 'state) FSM \<Rightarrow> bool" where "finite_FSM M = (finite (nodes M) \<and> finite (inputs M) \<and> finite (outputs M))" fun observable :: "('in, 'out, 'state) FSM \<Rightarrow> bool" where "observable M = (\<forall> t . \<forall> s1 . ((succ M) t s1 = {}) \<or> (\<exists> s2 . (succ M) t s1 = {s2}))" fun completely_specified :: "('in, 'out, 'state) FSM \<Rightarrow> bool" where "completely_specified M = (\<forall> s1 \<in> nodes M . \<forall> x \<in> inputs M . \<exists> y \<in> outputs M . \<exists> s2 . s2 \<in> (succ M) (x,y) s1)" fun well_formed :: "('in, 'out, 'state) FSM \<Rightarrow> bool" where "well_formed M = (finite_FSM M \<and> (\<forall> s1 x y . (x \<notin> inputs M \<or> y \<notin> outputs M) \<longrightarrow> succ M (x,y) s1 = {}) \<and> inputs M \<noteq> {} \<and> outputs M \<noteq> {})" abbreviation "OFSM M \<equiv> well_formed M \<and> observable M \<and> completely_specified M" lemma OFSM_props[elim!] : assumes "OFSM M" shows "well_formed M" "observable M" "completely_specified M" using assms by auto lemma set_of_succs_finite : assumes "well_formed M" and "q \<in> nodes M" shows "finite (succ M io q)" proof (rule ccontr) assume "infinite (succ M io q)" moreover have "succ M io q \<subseteq> nodes M" using assms by (simp add: subsetI succ_nodes) ultimately have "infinite (nodes M)" using infinite_super by blast then show "False" using assms by auto qed lemma well_formed_path_io_containment : assumes "well_formed M" and "path M p q" shows "set (map fst p) \<subseteq> (inputs M \<times> outputs M)" using assms proof (induction p arbitrary: q) case Nil then show ?case by auto next case (Cons a p) have "fst a \<in> (inputs M \<times> outputs M)" proof (rule ccontr) assume "fst a \<notin> inputs M \<times> outputs M" then have "fst (fst a) \<notin> inputs M \<or> snd (fst a) \<notin> outputs M" by (metis SigmaI prod.collapse) then have "succ M (fst a) q = {}" using Cons by (metis prod.collapse well_formed.elims(2)) moreover have "(snd a) \<in> succ M (fst a) q" using Cons by auto ultimately show "False" by auto qed moreover have "set (map fst p) \<subseteq> (inputs M \<times> outputs M)" using Cons by blast ultimately show ?case by auto qed lemma path_input_containment : assumes "well_formed M" and "path M p q" shows "set (map fst (map fst p)) \<subseteq> inputs M" using assms proof (induction p arbitrary: q rule: rev_induct) case Nil then show ?case by auto next case (snoc a p) have "set (map fst (p @ [a])) \<subseteq> (inputs M \<times> outputs M)" using well_formed_path_io_containment[OF snoc.prems] by assumption then have "(fst a) \<in> (inputs M \<times> outputs M)" by auto then have "fst (fst a) \<in> inputs M" by auto moreover have "set (map fst (map fst p)) \<subseteq> inputs M" using snoc.IH[OF snoc.prems(1)] using snoc.prems(2) by blast ultimately show ?case by simp qed lemma path_state_containment : assumes "path M p q" and "q \<in> nodes M" shows "set (map snd p) \<subseteq> nodes M" using assms by (metis FSM.nodes_states states_alt_def) lemma language_state_inputs : assumes "well_formed M" and "io \<in> language_state M q" shows "set (map fst io) \<subseteq> inputs M" proof - obtain tr where "path M (io || tr) q" "length tr = length io" using assms(2) by auto show ?thesis by (metis (no_types) \<open>\<And>thesis. (\<And>tr. \<lbrakk>path M (io || tr) q; length tr = length io\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close> assms(1) map_fst_zip path_input_containment) qed lemma set_of_paths_finite : assumes "well_formed M" and "q1 \<in> nodes M" shows "finite { p . path M p q1 \<and> target p q1 = q2 \<and> length p \<le> k }" proof - let ?trs = "{ tr . set tr \<subseteq> nodes M \<and> length tr \<le> k }" let ?ios = "{ io . set io \<subseteq> inputs M \<times> outputs M \<and> length io \<le> k }" let ?iotrs = "image (\<lambda> (io,tr) . io || tr) (?ios \<times> ?trs)" let ?paths = "{ p . path M p q1 \<and> target p q1 = q2 \<and> length p \<le> k }" have "finite (inputs M \<times> outputs M)" using assms by auto then have "finite ?ios" using assms by (simp add: finite_lists_length_le) moreover have "finite ?trs" using assms by (simp add: finite_lists_length_le) ultimately have "finite ?iotrs" by auto moreover have "?paths \<subseteq> ?iotrs" proof fix p assume p_assm : "p \<in> { p . path M p q1 \<and> target p q1 = q2 \<and> length p \<le> k }" then obtain io tr where p_split : "p = io || tr \<and> length io = length tr" using that by (metis (no_types) length_map zip_map_fst_snd) then have "io \<in> ?ios" using well_formed_path_io_containment proof - have f1: "path M p q1 \<and> target p q1 = q2 \<and> length p \<le> k" using p_assm by force then have "set io \<subseteq> inputs M \<times> outputs M" by (metis (no_types) assms(1) map_fst_zip p_split well_formed_path_io_containment) then show ?thesis using f1 by (simp add: p_split) qed moreover have "tr \<in> ?trs" using p_split proof - have f1: "path M (io || tr) q1 \<and> target (io || tr) q1 = q2 \<and> length (io || tr) \<le> k" using \<open>p \<in> {p. path M p q1 \<and> target p q1 = q2 \<and> length p \<le> k}\<close> p_split by force then have f2: "length tr \<le> k" by (simp add: p_split) have "set tr \<subseteq> nodes M" using f1 by (metis (no_types) assms(2) length_map p_split path_state_containment zip_eq zip_map_fst_snd) then show ?thesis using f2 by blast qed ultimately show "p \<in> ?iotrs" using p_split by auto qed ultimately show ?thesis using Finite_Set.finite_subset by blast qed lemma non_distinct_duplicate_indices : assumes "\<not> distinct xs" shows "\<exists> i1 i2 . i1 \<noteq> i2 \<and> xs ! i1 = xs ! i2 \<and> i1 \<le> length xs \<and> i2 \<le> length xs" using assms by (meson distinct_conv_nth less_imp_le) lemma reaching_path_without_repetition : assumes "well_formed M" and "q2 \<in> reachable M q1" and "q1 \<in> nodes M" shows "\<exists> p . path M p q1 \<and> target p q1 = q2 \<and> distinct (q1 # states p q1)" proof - have shorten_nondistinct : "\<forall> p. (path M p q1 \<and> target p q1 = q2 \<and> \<not> distinct (q1 # states p q1)) \<longrightarrow> (\<exists> p' . path M p' q1 \<and> target p' q1 = q2 \<and> length p' < length p)" proof fix p show "(path M p q1 \<and> target p q1 = q2 \<and> \<not> distinct (q1 # states p q1)) \<longrightarrow> (\<exists> p' . path M p' q1 \<and> target p' q1 = q2 \<and> length p' < length p)" proof assume assm : "path M p q1 \<and> target p q1 = q2 \<and> \<not> distinct (q1 # states p q1)" then show "(\<exists>p'. path M p' q1 \<and> target p' q1 = q2 \<and> length p' < length p)" proof (cases "q1 \<in> set (states p q1)") case True have "\<exists> i1 . target (take i1 p) q1 = q1 \<and> i1 \<le> length p \<and> i1 > 0" proof (rule ccontr) assume "\<not> (\<exists> i1. target (take i1 p) q1 = q1 \<and> i1 \<le> length p \<and> i1 > 0)" then have "\<not> (\<exists> i1 . (states p q1) ! i1 = q1 \<and> i1 \<le> length (states p q1))" by (metis True in_set_conv_nth less_eq_Suc_le scan_length scan_nth zero_less_Suc) then have "q1 \<notin> set (states p q1)" by (meson in_set_conv_nth less_imp_le) then show "False" using True by auto qed then obtain i1 where i1_def : "target (take i1 p) q1 = q1 \<and> i1 \<le> length p \<and> i1 > 0" by auto then have "path M (take i1 p) q1" using assm by (metis FSM.path_append_elim append_take_drop_id) moreover have "path M (drop i1 p) q1" using i1_def by (metis FSM.path_append_elim append_take_drop_id assm) ultimately have "path M (drop i1 p) q1 \<and> (target (drop i1 p) q1 = q2)" using i1_def by (metis (no_types) append_take_drop_id assm fold_append o_apply) moreover have "length (drop i1 p) < length p" using i1_def by auto ultimately show ?thesis using assms by blast next case False then have assm' : "path M p q1 \<and> target p q1 = q2 \<and> \<not> distinct (states p q1)" using assm by auto have "\<exists> i1 i2 . i1 \<noteq> i2 \<and> target (take i1 p) q1 = target (take i2 p) q1 \<and> i1 \<le> length p \<and> i2 \<le> length p" proof (rule ccontr) assume "\<not> (\<exists> i1 i2 . i1 \<noteq> i2 \<and> target (take i1 p) q1 = target (take i2 p) q1 \<and> i1 \<le> length p \<and> i2 \<le> length p)" then have "\<not> (\<exists> i1 i2 . i1 \<noteq> i2 \<and> (states p q1) ! i1 = (states p q1) ! i2 \<and> i1 \<le> length (states p q1) \<and> i2 \<le> length (states p q1))" by (metis (no_types, lifting) Suc_leI assm' distinct_conv_nth nat.inject scan_length scan_nth) then have "distinct (states p q1)" using non_distinct_duplicate_indices by blast then show "False" using assm' by auto qed then obtain i1 i2 where i_def : "i1 < i2 \<and> target (take i1 p) q1 = target (take i2 p) q1 \<and> i1 \<le> length p \<and> i2 \<le> length p" by (metis nat_neq_iff) then have "path M (take i1 p) q1" using assm by (metis FSM.path_append_elim append_take_drop_id) moreover have "path M (drop i2 p) (target (take i2 p) q1)" by (metis FSM.path_append_elim append_take_drop_id assm) ultimately have "path M ((take i1 p) @ (drop i2 p)) q1 \<and> (target ((take i1 p) @ (drop i2 p)) q1 = q2)" using i_def assm by (metis FSM.path_append append_take_drop_id fold_append o_apply) moreover have "length ((take i1 p) @ (drop i2 p)) < length p" using i_def by auto ultimately have "path M ((take i1 p) @ (drop i2 p)) q1 \<and> target ((take i1 p) @ (drop i2 p)) q1 = q2 \<and> length ((take i1 p) @ (drop i2 p)) < length p" by simp then show ?thesis using assms by blast qed qed qed obtain p where p_def : "path M p q1 \<and> target p q1 = q2" using assms by auto let ?paths = "{p' . (path M p' q1 \<and> target p' q1 = q2 \<and> length p' \<le> length p)}" let ?minPath = "arg_min length (\<lambda> io . io \<in> ?paths)" have "?paths \<noteq> empty" using p_def by auto moreover have "finite ?paths" using assms by (simp add: set_of_paths_finite) ultimately have minPath_def : "?minPath \<in> ?paths \<and> (\<forall> p' \<in> ?paths . length ?minPath \<le> length p')" by (meson arg_min_nat_lemma equals0I) moreover have "distinct (q1 # states ?minPath q1)" proof (rule ccontr) assume "\<not> distinct (q1 # states ?minPath q1)" then have "\<exists> p' . path M p' q1 \<and> target p' q1 = q2 \<and> length p' < length ?minPath" using shorten_nondistinct minPath_def by blast then show "False" using minPath_def using arg_min_nat_le dual_order.strict_trans1 by auto qed ultimately show ?thesis by auto qed lemma observable_path_unique[simp] : assumes "io \<in> LS M q" and "observable M" and "path M (io || tr1) q" "length io = length tr1" and "path M (io || tr2) q" "length io = length tr2" shows "tr1 = tr2" proof (rule ccontr) assume tr_assm : "tr1 \<noteq> tr2" then have state_diff : "(states (io || tr1) q ) \<noteq> (states (io || tr2) q)" by (metis assms(4) assms(6) map_snd_zip states_alt_def) show "False" using assms tr_assm proof (induction io arbitrary: q tr1 tr2) case Nil then show ?case using Nil by simp next case (Cons io_hd io_tl) then obtain tr1_hd tr1_tl tr2_hd tr2_tl where tr_split : "tr1 = tr1_hd # tr1_tl \<and> tr2 = tr2_hd # tr2_tl" by (metis length_0_conv neq_Nil_conv) have p1: "path M ([io_hd] || [tr1_hd]) q" using Cons.prems tr_split by auto have p2: "path M ([io_hd] || [tr2_hd]) q" using Cons.prems tr_split by auto have tr_hd_eq : "tr1_hd = tr2_hd" using Cons.prems unfolding observable.simps proof - assume "\<forall>t s1. succ M t s1 = {} \<or> (\<exists>s2. succ M t s1 = {s2})" then show ?thesis by (metis (no_types) p1 p2 FSM.path_cons_elim empty_iff prod.sel(1) prod.sel(2) singletonD zip_Cons_Cons) qed then show ?thesis using Cons.IH Cons.prems(3) Cons.prems(4) Cons.prems(5) Cons.prems(6) Cons.prems(7) assms(2) tr_split by auto qed qed lemma observable_path_unique_ex[elim] : assumes "observable M" and "io \<in> LS M q" obtains tr where "{ t . path M (io || t) q \<and> length io = length t } = { tr }" proof - obtain tr where tr_def : "path M (io || tr) q" "length io = length tr" using assms by auto then have "{ t . path M (io || t) q \<and> length io = length t } \<noteq> {}" by blast moreover have "\<forall> t \<in> { t . path M (io || t) q \<and> length io = length t } . t = tr" using assms tr_def by auto ultimately show ?thesis using that by moura qed lemma well_formed_product[simp] : assumes "well_formed M1" and "well_formed M2" shows "well_formed (product M2 M1)" (is "well_formed ?PM") unfolding well_formed.simps proof have "finite (nodes M1)" "finite (nodes M2)" using assms by auto then have "finite (nodes M2 \<times> nodes M1)" by simp moreover have "nodes ?PM \<subseteq> nodes M2 \<times> nodes M1" using product_nodes assms by blast ultimately show "finite_FSM ?PM" using infinite_subset assms by auto next have "inputs ?PM = inputs M2 \<union> inputs M1" "outputs ?PM = outputs M2 \<union> outputs M1" by auto then show "(\<forall>s1 x y. x \<notin> inputs ?PM \<or> y \<notin> outputs ?PM \<longrightarrow> succ ?PM (x, y) s1 = {}) \<and> inputs ?PM \<noteq> {} \<and> outputs ?PM \<noteq> {}" using assms by auto qed subsection {* States reached by a given IO-sequence *} text \<open> The function @{verbatim io_targets} collects all states of an FSM reached from a given state by a given IO-sequence. Notably, for any observable FSM, this set contains at most one state. \<close> fun io_targets :: "('in, 'out, 'state) FSM \<Rightarrow> 'state \<Rightarrow> ('in \<times> 'out) list \<Rightarrow> 'state set" where "io_targets M q io = { target (io || tr) q | tr . path M (io || tr) q \<and> length io = length tr }" lemma io_target_implies_L : assumes "q \<in> io_targets M (initial M) io" shows "io \<in> L M" proof - obtain tr where "path M (io || tr) (initial M)" "length tr = length io" "target (io || tr) (initial M) = q" using assms by auto then show ?thesis by auto qed lemma io_target_from_path : assumes "path M (w || tr) q" and "length w = length tr" shows "target (w || tr) q \<in> io_targets M q w" using assms by auto lemma io_targets_observable_singleton_ex : assumes "observable M" and "io \<in> LS M q1" shows "\<exists> q2 . io_targets M q1 io = { q2 }" proof - obtain tr where tr_def : "{ t . path M (io || t) q1 \<and> length io = length t } = { tr }" using assms observable_path_unique_ex by (metis (mono_tags, lifting)) then have "io_targets M q1 io = { target (io || tr) q1 }" by fastforce then show ?thesis by blast qed lemma io_targets_observable_singleton_ob : assumes "observable M" and "io \<in> LS M q1" obtains q2 where "io_targets M q1 io = { q2 }" proof - obtain tr where tr_def : "{ t . path M (io || t) q1 \<and> length io = length t } = { tr }" using assms observable_path_unique_ex by (metis (mono_tags, lifting)) then have "io_targets M q1 io = { target (io || tr) q1 }" by fastforce then show ?thesis using that by blast qed lemma io_targets_elim[elim] : assumes "p \<in> io_targets M q io" obtains tr where "target (io || tr) q = p \<and> path M (io || tr) q \<and> length io = length tr" using assms unfolding io_targets.simps by force lemma io_targets_reachable : assumes "q2 \<in> io_targets M q1 io" shows "q2 \<in> reachable M q1" using assms unfolding io_targets.simps by blast lemma io_targets_nodes : assumes "q2 \<in> io_targets M q1 io" and "q1 \<in> nodes M" shows "q2 \<in> nodes M" using assms by auto lemma observable_io_targets_split : assumes "observable M" and "io_targets M q1 (vs @ xs) = {q3}" and "io_targets M q1 vs = {q2}" shows "io_targets M q2 xs = {q3}" proof - have "vs @ xs \<in> LS M q1" using assms(2) by force then obtain trV trX where tr_def : "path M (vs || trV) q1" "length vs = length trV" "path M (xs || trX) (target (vs || trV) q1)" "length xs = length trX" using language_state_split[of vs xs M q1] by auto then have tgt_V : "target (vs || trV) q1 = q2" using assms(3) by auto then have path_X : "path M (xs || trX) q2 \<and> length xs = length trX" using tr_def by auto have tgt_all : "target (vs @ xs || trV @ trX) q1 = q3" proof - have f1: "\<exists>cs. q3 = target (vs @ xs || cs) q1 \<and> path M (vs @ xs || cs) q1 \<and> length (vs @ xs) = length cs" using assms(2) by auto have "length (vs @ xs) = length trV + length trX" by (simp add: tr_def(2) tr_def(4)) then have "length (vs @ xs) = length (trV @ trX)" by simp then show ?thesis using f1 by (metis FSM.path_append \<open>vs @ xs \<in> LS M q1\<close> assms(1) observable_path_unique tr_def(1) tr_def(2) tr_def(3) zip_append) qed then have "target ((vs || trV) @ (xs || trX)) q1 = q3" using tr_def by simp then have "target (xs || trX) q2 = q3" using tgt_V by auto then have "q3 \<in> io_targets M q2 xs" using path_X by auto then show ?thesis by (metis (no_types) \<open>observable M\<close> path_X insert_absorb io_targets_observable_singleton_ex language_state singleton_insert_inj_eq') qed lemma observable_io_target_unique_target : assumes "observable M" and "io_targets M q1 io = {q2}" and "path M (io || tr) q1" and "length io = length tr" shows "target (io || tr) q1 = q2" using assms by auto lemma target_alt_def : assumes "length io = length tr" shows "length io = 0 \<Longrightarrow> target (io || tr) q = q" "length io > 0 \<Longrightarrow> target (io || tr) q = last tr" proof - show "length io = 0 \<Longrightarrow> target (io || tr) q = q" by simp show "length io > 0 \<Longrightarrow> target (io || tr) q = last tr" by (metis assms last_ConsR length_greater_0_conv map_snd_zip scan_last states_alt_def) qed lemma obs_target_is_io_targets : assumes "observable M" and "path M (io || tr) q" and "length io = length tr" shows "io_targets M q io = {target (io || tr) q}" by (metis assms(1) assms(2) assms(3) io_targets_observable_singleton_ex language_state observable_io_target_unique_target) lemma io_target_target : assumes "io_targets M q1 io = {q2}" and "path M (io || tr) q1" and "length io = length tr" shows "target (io || tr) q1 = q2" proof - have "target (io || tr) q1 \<in> io_targets M q1 io" using assms(2) assms(3) by auto then show ?thesis using assms(1) by blast qed lemma index_last_take : assumes "i < length xs" shows "xs ! i = last (take (Suc i) xs)" by (simp add: assms take_Suc_conv_app_nth) lemma path_last_io_target : assumes "path M (xs || tr) q" and "length xs = length tr" and "length xs > 0" shows "last tr \<in> io_targets M q xs" proof - have "last tr = target (xs || tr) q" by (metis assms(2) assms(3) map_snd_zip states_alt_def target_in_states) then show ?thesis using assms(1) assms(2) by auto qed lemma path_prefix_io_targets : assumes "path M (xs || tr) q" and "length xs = length tr" and "length xs > 0" shows "last (take (Suc i) tr) \<in> io_targets M q (take (Suc i) xs)" proof - have "path M (take (Suc i) xs || take (Suc i) tr) q" by (metis (no_types) FSM.path_append_elim append_take_drop_id assms(1) take_zip) then show ?thesis using assms(2) assms(3) path_last_io_target by fastforce qed lemma states_index_io_target : assumes "i < length xs" and "path M (xs || tr) q" and "length xs = length tr" and "length xs > 0" shows "(states (xs || tr) q) ! i \<in> io_targets M q (take (Suc i) xs)" proof - have "(states (xs || tr) q) ! i = last (take (Suc i) (states (xs || tr) q))" by (metis assms(1) assms(3) map_snd_zip states_alt_def index_last_take) then have "(states (xs || tr) q) ! i = last (states (take (Suc i) xs || take (Suc i) tr) q)" by (simp add: take_zip) then have "(states (xs || tr) q) ! i = last (take (Suc i) tr)" by (simp add: assms(3) states_alt_def) moreover have "last (take (Suc i) tr) \<in> io_targets M q (take (Suc i) xs)" by (meson assms(2) assms(3) assms(4) path_prefix_io_targets) ultimately show ?thesis by simp qed lemma observable_io_targets_append : assumes "observable M" and "io_targets M q1 vs = {q2}" and "io_targets M q2 xs = {q3}" shows "io_targets M q1 (vs@xs) = {q3}" proof - obtain trV where "path M (vs || trV) q1 \<and> length trV = length vs \<and> target (vs || trV) q1 = q2" by (metis assms(2) io_targets_elim singletonI) moreover obtain trX where "path M (xs || trX) q2 \<and> length trX = length xs \<and> target (xs || trX) q2 = q3" by (metis assms(3) io_targets_elim singletonI) ultimately have "path M (vs @ xs || trV @ trX) q1 \<and> length (trV @ trX) = length (vs @ xs) \<and> target (vs @ xs || trV @ trX) q1 = q3" by auto then show ?thesis by (metis assms(1) obs_target_is_io_targets) qed lemma io_path_states_prefix : assumes "observable M" and "path M (io1 || tr1) q" and "length tr1 = length io1" and "path M (io2 || tr2) q" and "length tr2 = length io2" and "prefix io1 io2" shows "tr1 = take (length tr1) tr2" proof - let ?tr1' = "take (length tr1) tr2" let ?io1' = "take (length tr1) io2" have "path M (?io1' || ?tr1') q" by (metis FSM.path_append_elim append_take_drop_id assms(4) take_zip) have "length ?tr1' = length ?io1'" using assms (5) by auto have "?io1' = io1" proof - have "\<forall>ps psa. \<not> prefix (ps::('a \<times> 'b) list) psa \<or> length ps \<le> length psa" using prefix_length_le by blast then have "length (take (length tr1) io2) = length io1" using assms(3) assms(6) min.absorb2 by auto then show ?thesis by (metis assms(6) min.cobounded2 min_def_raw prefix_length_prefix prefix_order.dual_order.antisym take_is_prefix) qed show "tr1 = ?tr1'" by (metis \<open>length (take (length tr1) tr2) = length (take (length tr1) io2)\<close> \<open>path M (take (length tr1) io2 || take (length tr1) tr2) q\<close> \<open>take (length tr1) io2 = io1\<close> assms(1) assms(2) assms(3) language_state observable_path_unique) qed lemma observable_io_targets_suffix : assumes "observable M" and "io_targets M q1 vs = {q2}" and "io_targets M q1 (vs@xs) = {q3}" shows "io_targets M q2 xs = {q3}" proof - have "prefix vs (vs@xs)" by auto obtain trV where "path M (vs || trV) q1 \<and> length trV = length vs \<and> target (vs || trV) q1 = q2" by (metis assms(2) io_targets_elim singletonI) moreover obtain trVX where "path M (vs@xs || trVX) q1 \<and> length trVX = length (vs@xs) \<and> target (vs@xs || trVX) q1 = q3" by (metis assms(3) io_targets_elim singletonI) ultimately have "trV = take (length trV) trVX" using io_path_states_prefix[OF assms(1) _ _ _ _ \<open>prefix vs (vs@xs)\<close>, of trV q1 trVX] by auto show ?thesis by (meson assms(1) assms(2) assms(3) observable_io_targets_split) qed lemma observable_io_target_is_singleton[simp] : assumes "observable M" and "p \<in> io_targets M q io" shows "io_targets M q io = {p}" proof - have "io \<in> LS M q" using assms(2) by auto then obtain p' where "io_targets M q io = {p'}" using assms(1) by (meson io_targets_observable_singleton_ex) then show ?thesis using assms(2) by simp qed lemma observable_path_prefix : assumes "observable M" and "path M (io || tr) q" and "length io = length tr" and "path M (ioP || trP) q" and "length ioP = length trP" and "prefix ioP io" shows "trP = take (length ioP) tr" proof - have ioP_def : "ioP = take (length ioP) io" using assms(6) by (metis append_eq_conv_conj prefixE) then have "take (length ioP) (io || tr) = take (length ioP) io || take (length ioP) tr" using take_zip by blast moreover have "path M (take (length ioP) (io || tr)) q" using assms by (metis FSM.path_append_elim append_take_drop_id) ultimately have "path M (take (length ioP) io || take (length ioP) tr) q \<and> length (take (length ioP) io) = length (take (length ioP) tr)" using assms(3) by auto then have "path M (ioP || take (length ioP) tr) q \<and> length ioP = length (take (length ioP) tr)" using assms(3) using ioP_def by auto then show ?thesis by (meson assms(1) assms(4) assms(5) language_state observable_path_unique) qed lemma io_targets_succ : assumes "q2 \<in> io_targets M q1 [xy]" shows "q2 \<in> succ M xy q1" proof - obtain tr where tr_def : "target ([xy] || tr) q1 = q2" "path M ([xy] || tr) q1" "length [xy] = length tr" using assms by auto have "length tr = Suc 0" using \<open>length [xy] = length tr\<close> by auto then obtain q2' where "tr = [q2']" by (metis Suc_length_conv length_0_conv) then have "target ([xy] || tr) q1 = q2'" by auto then have "q2' = q2" using \<open>target ([xy] || tr) q1 = q2\<close> by simp then have "path M ([xy] || [q2]) q1" using tr_def(2) \<open>tr = [q2']\<close> by auto then have "path M [(xy,q2)] q1" by auto show ?thesis proof (cases rule: FSM.path.cases[of M "[(xy,q2)]" q1]) case nil show ?case using \<open>path M [(xy,q2)] q1\<close> by simp next case cons show "snd (xy, q2) \<in> succ M (fst (xy, q2)) q1 \<Longrightarrow> path M [] (snd (xy, q2)) \<Longrightarrow> q2 \<in> succ M xy q1" by auto qed qed subsection {* D-reachability *} text \<open> A state of some FSM is d-reached by some input sequence if any sequence in the language of the FSM with this input sequence reaches that state. That state is then called d-reachable. \<close> abbreviation "d_reached_by M p xs q tr ys \<equiv> ((length xs = length ys \<and> length xs = length tr \<and> (path M ((xs || ys) || tr) p) \<and> target ((xs || ys) || tr) p = q) \<and> (\<forall> ys2 tr2 . (length xs = length ys2 \<and> length xs = length tr2 \<and> path M ((xs || ys2) || tr2) p) \<longrightarrow> target ((xs || ys2) || tr2) p = q))" fun d_reaches :: "('in, 'out, 'state) FSM \<Rightarrow> 'state \<Rightarrow> 'in list \<Rightarrow> 'state \<Rightarrow> bool" where "d_reaches M p xs q = (\<exists> tr ys . d_reached_by M p xs q tr ys)" fun d_reachable :: "('in, 'out, 'state) FSM \<Rightarrow> 'state \<Rightarrow> 'state set" where "d_reachable M p = { q . (\<exists> xs . d_reaches M p xs q) }" lemma d_reaches_unique[elim] : assumes "d_reaches M p xs q1" and "d_reaches M p xs q2" shows "q1 = q2" using assms unfolding d_reaches.simps by blast lemma d_reaches_unique_cases[simp] : "{ q . d_reaches M (initial M) xs q } = {} \<or> (\<exists> q2 . { q . d_reaches M (initial M) xs q } = { q2 })" unfolding d_reaches.simps by blast lemma d_reaches_unique_obtain[simp] : assumes "d_reaches M (initial M) xs q" shows "{ p . d_reaches M (initial M) xs p } = { q }" using assms unfolding d_reaches.simps by blast lemma d_reaches_io_target : assumes "d_reaches M p xs q" and "length ys = length xs" shows "io_targets M p (xs || ys) \<subseteq> {q}" proof fix q' assume "q' \<in> io_targets M p (xs || ys)" then obtain trQ where "path M ((xs || ys) || trQ) p \<and> length (xs || ys) = length trQ" by auto moreover obtain trD ysD where "d_reached_by M p xs q trD ysD" using assms(1) by auto ultimately have "target ((xs || ys) || trQ) p = q" by (simp add: assms(2)) then show "q' \<in> {q}" using \<open>d_reached_by M p xs q trD ysD\<close> \<open>q' \<in> io_targets M p (xs || ys)\<close> assms(2) by auto qed lemma d_reachable_reachable : "d_reachable M p \<subseteq> reachable M p" unfolding d_reaches.simps d_reachable.simps by blast subsection {* Deterministic state cover *} text \<open> The deterministic state cover of some FSM is a minimal set of input sequences such that every d-reachable state of the FSM is d-reached by a sequence in the set and the set contains the empty sequence (which d-reaches the initial state). \<close> fun is_det_state_cover_ass :: "('in, 'out, 'state) FSM \<Rightarrow> ('state \<Rightarrow> 'in list) \<Rightarrow> bool" where "is_det_state_cover_ass M f = (f (initial M) = [] \<and> (\<forall> s \<in> d_reachable M (initial M) . d_reaches M (initial M) (f s) s))" lemma det_state_cover_ass_dist : assumes "is_det_state_cover_ass M f" and "s1 \<in> d_reachable M (initial M)" and "s2 \<in> d_reachable M (initial M)" and "s1 \<noteq> s2" shows "\<not>(d_reaches M (initial M) (f s2) s1)" by (meson assms(1) assms(3) assms(4) d_reaches_unique is_det_state_cover_ass.simps) lemma det_state_cover_ass_diff : assumes "is_det_state_cover_ass M f" and "s1 \<in> d_reachable M (initial M)" and "s2 \<in> d_reachable M (initial M)" and "s1 \<noteq> s2" shows "f s1 \<noteq> f s2" by (metis assms det_state_cover_ass_dist is_det_state_cover_ass.simps) fun is_det_state_cover :: "('in, 'out, 'state) FSM \<Rightarrow> 'in list set \<Rightarrow> bool" where "is_det_state_cover M V = (\<exists> f . is_det_state_cover_ass M f \<and> V = image f (d_reachable M (initial M)))" lemma det_state_cover_d_reachable[elim] : assumes "is_det_state_cover M V" and "v \<in> V" obtains q where "d_reaches M (initial M) v q" by (metis (no_types, hide_lams) assms(1) assms(2) image_iff is_det_state_cover.simps is_det_state_cover_ass.elims(2)) lemma det_state_cover_card[simp] : assumes "is_det_state_cover M V" and "finite (nodes M)" shows "card (d_reachable M (initial M)) = card V" proof - obtain f where f_def : "is_det_state_cover_ass M f \<and> V = image f (d_reachable M (initial M))" using assms unfolding is_det_state_cover.simps by blast then have card_f : "card V = card (image f (d_reachable M (initial M)))" by simp have "d_reachable M (initial M) \<subseteq> nodes M" unfolding d_reachable.simps d_reaches.simps using d_reachable_reachable by blast then have dr_finite : "finite (d_reachable M (initial M))" using assms infinite_super by blast then have card_le : "card (image f (d_reachable M (initial M))) \<le> card (d_reachable M (initial M))" using card_image_le by blast have "card (image f (d_reachable M (initial M))) = card (d_reachable M (initial M))" by (meson card_image det_state_cover_ass_diff f_def inj_onI) then show ?thesis using card_f by auto qed lemma det_state_cover_finite : assumes "is_det_state_cover M V" and "finite (nodes M)" shows "finite V" proof - have "d_reachable M (initial M) \<subseteq> nodes M" by auto show "finite V" using det_state_cover_card[OF assms] by (metis \<open>d_reachable M (initial M) \<subseteq> nodes M\<close> assms(1) assms(2) finite_imageI infinite_super is_det_state_cover.simps) qed lemma det_state_cover_empty : assumes "is_det_state_cover M V" shows "[] \<in> V" proof - obtain f where f_def : "is_det_state_cover_ass M f \<and> V = f ` d_reachable M (initial M)" using assms by auto then have "f (initial M) = []" by auto moreover have "initial M \<in> d_reachable M (initial M)" proof - have "d_reaches M (initial M) [] (initial M)" by auto then show ?thesis by (metis d_reachable.simps mem_Collect_eq) qed moreover have "f (initial M) \<in> V" using f_def calculation by blast ultimately show ?thesis by auto qed subsection {* IO reduction *} text \<open> An FSM is a reduction of another, if its language is a subset of the language of the latter FSM. \<close> fun io_reduction :: "('in, 'out, 'state) FSM \<Rightarrow> ('in, 'out, 'state) FSM \<Rightarrow> bool" (infix "\<preceq>" 200) where "M1 \<preceq> M2 = (LS M1 (initial M1) \<subseteq> LS M2 (initial M2))" lemma language_state_inclusion_of_state_reached_by_same_sequence : assumes "LS M1 q1 \<subseteq> LS M2 q2" and "observable M1" and "observable M2" and "io_targets M1 q1 io = { q1t }" and "io_targets M2 q2 io = { q2t }" shows "LS M1 q1t \<subseteq> LS M2 q2t" proof fix x assume "x \<in> LS M1 q1t" obtain q1x where "io_targets M1 q1t x = {q1x}" by (meson \<open>x \<in> LS M1 q1t\<close> assms(2) io_targets_observable_singleton_ex) have "io \<in> LS M1 q1" using assms(4) by auto have "io@x \<in> LS M1 q1" using observable_io_targets_append[OF assms(2) \<open>io_targets M1 q1 io = { q1t }\<close> \<open>io_targets M1 q1t x = {q1x}\<close>] by (metis io_targets_elim language_state singletonI) then have "io@x \<in> LS M2 q2" using assms(1) by blast then obtain q2x where "io_targets M2 q2 (io@x) = {q2x}" by (meson assms(3) io_targets_observable_singleton_ex) show "x \<in> LS M2 q2t" using observable_io_targets_split[OF assms(3) \<open>io_targets M2 q2 (io @ x) = {q2x}\<close> assms(5)] by auto qed subsection {* Language subsets for input sequences *} text \<open> The following definitions describe restrictions of languages to only those IO-sequences that exhibit a certain input sequence or whose input sequence is contained in a given set of input sequences. This allows to define the notion that some FSM is a reduction of another over a given set of input sequences, but not necessarily over the entire language of the latter FSM. \<close> fun language_state_for_input :: "('in, 'out, 'state) FSM \<Rightarrow> 'state \<Rightarrow> 'in list \<Rightarrow> ('in \<times> 'out) list set" where "language_state_for_input M q xs = {(xs || ys) | ys . (length xs = length ys \<and> (xs || ys) \<in> LS M q)}" fun language_state_for_inputs :: "('in, 'out, 'state) FSM \<Rightarrow> 'state \<Rightarrow> 'in list set \<Rightarrow> ('in \<times> 'out) list set" ("(LS\<^sub>i\<^sub>n _ _ _)" [1000,1000,1000]) where "language_state_for_inputs M q ISeqs = {(xs || ys) | xs ys . (xs \<in> ISeqs \<and> length xs = length ys \<and> (xs || ys) \<in> LS M q)}" abbreviation "L\<^sub>i\<^sub>n M TS \<equiv> LS\<^sub>i\<^sub>n M (initial M) TS" abbreviation "io_reduction_on M1 TS M2 \<equiv> (L\<^sub>i\<^sub>n M1 TS \<subseteq> L\<^sub>i\<^sub>n M2 TS)" notation io_reduction_on ("(_ \<preceq>\<lbrakk>_\<rbrakk> _)" [1000,0,0] 61) notation (latex output) io_reduction_on ("(_ \<preceq>\<^bsub>_\<^esub> _)" [1000,0,0] 61) lemma language_state_for_input_alt_def : "language_state_for_input M q xs = LS\<^sub>i\<^sub>n M q {xs}" unfolding language_state_for_input.simps language_state_for_inputs.simps by blast lemma language_state_for_inputs_alt_def : "LS\<^sub>i\<^sub>n M q ISeqs = \<Union> (image (language_state_for_input M q) ISeqs)" by auto lemma language_state_for_inputs_in_language_state : "LS\<^sub>i\<^sub>n M q T \<subseteq> language_state M q" unfolding language_state_for_inputs.simps language_state_def by blast lemma language_state_for_inputs_map_fst : assumes "io \<in> language_state M q" and "map fst io \<in> T" shows "io \<in> LS\<^sub>i\<^sub>n M q T" proof - let ?xs = "map fst io" let ?ys = "map snd io" have "?xs \<in> T \<and> length ?xs = length ?ys \<and> ?xs || ?ys \<in> language_state M q" using assms(2,1) by auto then have "?xs || ?ys \<in> LS\<^sub>i\<^sub>n M q T" unfolding language_state_for_inputs.simps by blast then show ?thesis by simp qed lemma language_state_for_inputs_nonempty : assumes "set xs \<subseteq> inputs M" and "completely_specified M" and "q \<in> nodes M" shows "LS\<^sub>i\<^sub>n M q {xs} \<noteq> {}" using assms proof (induction xs arbitrary: q) case Nil then show ?case by auto next case (Cons x xs) then have "x \<in> inputs M" by simp then obtain y q' where x_step : "q' \<in> succ M (x,y) q" using Cons(3,4) unfolding completely_specified.simps by blast then have "path M ([(x,y)] || [q']) q \<and> length [q] = length [(x,y)]" "target ([(x,y)] || [q']) q = q'" by auto then have "q' \<in> nodes M" using Cons(4) by (metis FSM.nodes_target) then have "LS\<^sub>i\<^sub>n M q' {xs} \<noteq> {}" using Cons.prems Cons.IH by auto then obtain ys where "length xs = length ys \<and> (xs || ys) \<in> LS M q'" by auto then obtain tr where "path M ((xs || ys) || tr) q' \<and> length tr = length (xs || ys)" by auto then have "path M ([(x,y)] @ (xs || ys) || [q'] @ tr) q \<and> length ([q'] @ tr) = length ([(x,y)] @ (xs || ys))" by (simp add: FSM.path.intros(2) x_step) then have "path M ((x#xs || y#ys) || [q'] @ tr) q \<and> length ([q'] @ tr) = length (x#xs || y#ys)" by auto then have "(x#xs || y#ys) \<in> LS M q" by (metis language_state) moreover have "length (x#xs) = length (y#ys)" by (simp add: \<open>length xs = length ys \<and> xs || ys \<in> LS M q'\<close>) ultimately have "(x#xs || y#ys) \<in> LS\<^sub>i\<^sub>n M q {x # xs}" unfolding language_state_for_inputs.simps by blast then show ?case by blast qed lemma language_state_for_inputs_map_fst_contained : assumes "vs \<in> LS\<^sub>i\<^sub>n M q V" shows "map fst vs \<in> V" proof - have "(map fst vs) || (map snd vs) = vs" by auto then have "(map fst vs) || (map snd vs) \<in> LS\<^sub>i\<^sub>n M q V" using assms by auto then show ?thesis by auto qed lemma language_state_for_inputs_empty : assumes "[] \<in> V" shows "[] \<in> LS\<^sub>i\<^sub>n M q V" proof - have "[] \<in> language_state_for_input M q []" by auto then show ?thesis using language_state_for_inputs_alt_def by (metis UN_I assms) qed lemma language_state_for_input_empty[simp] : "language_state_for_input M q [] = {[]}" by auto lemma language_state_for_input_take : assumes "io \<in> language_state_for_input M q xs" shows "take n io \<in> language_state_for_input M q (take n xs)" proof - obtain ys where "io = xs || ys" "length xs = length ys" "xs || ys \<in> language_state M q" using assms by auto then obtain p where "length p = length xs" "path M ((xs || ys) || p) q " by auto then have "path M (take n ((xs || ys) || p)) q" by (metis FSM.path_append_elim append_take_drop_id) then have "take n (xs || ys) \<in> language_state M q" by (simp add: \<open>length p = length xs\<close> \<open>length xs = length ys\<close> language_state take_zip) then have "(take n xs) || (take n ys) \<in> language_state M q" by (simp add: take_zip) have "take n io = (take n xs) || (take n ys)" using \<open>io = xs || ys\<close> take_zip by blast moreover have "length (take n xs) = length (take n ys)" by (simp add: \<open>length xs = length ys\<close>) ultimately show ?thesis using \<open>(take n xs) || (take n ys) \<in> language_state M q\<close> unfolding language_state_for_input.simps by blast qed lemma language_state_for_inputs_prefix : assumes "vs@xs \<in> L\<^sub>i\<^sub>n M1 {vs'@xs'}" and "length vs = length vs'" shows "vs \<in> L\<^sub>i\<^sub>n M1 {vs'}" proof - have "vs@xs \<in> L M1" using assms(1) by auto then have "vs \<in> L M1" by (meson language_state_prefix) then have "vs \<in> L\<^sub>i\<^sub>n M1 {map fst vs}" by (meson insertI1 language_state_for_inputs_map_fst) moreover have "vs' = map fst vs" by (metis append_eq_append_conv assms(1) assms(2) language_state_for_inputs_map_fst_contained length_map map_append singletonD) ultimately show ?thesis by blast qed lemma language_state_for_inputs_union : shows "LS\<^sub>i\<^sub>n M q T1 \<union> LS\<^sub>i\<^sub>n M q T2 = LS\<^sub>i\<^sub>n M q (T1 \<union> T2)" unfolding language_state_for_inputs.simps by blast lemma io_reduction_on_subset : assumes "io_reduction_on M1 T M2" and "T' \<subseteq> T" shows "io_reduction_on M1 T' M2" proof (rule ccontr) assume "\<not> io_reduction_on M1 T' M2" then obtain xs' where "xs' \<in> T'" "\<not> L\<^sub>i\<^sub>n M1 {xs'} \<subseteq> L\<^sub>i\<^sub>n M2 {xs'}" proof - have f1: "\<forall>ps P Pa. (ps::('a \<times> 'b) list) \<notin> P \<or> \<not> P \<subseteq> Pa \<or> ps \<in> Pa" by blast obtain pps :: "('a \<times> 'b) list set \<Rightarrow> ('a \<times> 'b) list set \<Rightarrow> ('a \<times> 'b) list" where "\<forall>x0 x1. (\<exists>v2. v2 \<in> x1 \<and> v2 \<notin> x0) = (pps x0 x1 \<in> x1 \<and> pps x0 x1 \<notin> x0)" by moura then have f2: "\<forall>P Pa. pps Pa P \<in> P \<and> pps Pa P \<notin> Pa \<or> P \<subseteq> Pa" by (meson subsetI) have f3: "\<forall>ps f c A. (ps::('a \<times> 'b) list) \<notin> LS\<^sub>i\<^sub>n f (c::'c) A \<or> map fst ps \<in> A" by (meson language_state_for_inputs_map_fst_contained) then have "L\<^sub>i\<^sub>n M1 T' \<subseteq> L\<^sub>i\<^sub>n M1 T" using f2 by (meson assms(2) language_state_for_inputs_in_language_state language_state_for_inputs_map_fst set_rev_mp) then show ?thesis using f3 f2 f1 by (meson \<open>\<not> io_reduction_on M1 T' M2\<close> assms(1) language_state_for_inputs_in_language_state language_state_for_inputs_map_fst) qed then have "xs' \<in> T" using assms(2) by blast have "\<not> io_reduction_on M1 T M2" proof - have f1: "\<forall>as. as \<notin> T' \<or> as \<in> T" using assms(2) by auto obtain pps :: "('a \<times> 'b) list set \<Rightarrow> ('a \<times> 'b) list set \<Rightarrow> ('a \<times> 'b) list" where "\<forall>x0 x1. (\<exists>v2. v2 \<in> x1 \<and> v2 \<notin> x0) = (pps x0 x1 \<in> x1 \<and> pps x0 x1 \<notin> x0)" by moura then have "\<forall>P Pa. (\<not> P \<subseteq> Pa \<or> (\<forall>ps. ps \<notin> P \<or> ps \<in> Pa)) \<and> (P \<subseteq> Pa \<or> pps Pa P \<in> P \<and> pps Pa P \<notin> Pa)" by blast then show ?thesis using f1 by (meson \<open>\<not> io_reduction_on M1 T' M2\<close> language_state_for_inputs_in_language_state language_state_for_inputs_map_fst language_state_for_inputs_map_fst_contained) qed then show "False" using assms(1) by auto qed subsection {* Sequences to failures *} text \<open> A sequence to a failure for FSMs @{verbatim M1} and @{verbatim M2} is a sequence such that any proper prefix of it is contained in the languages of both @{verbatim M1} and @{verbatim M2}, while the sequence itself is contained only in the language of A. That is, if a sequence to a failure for @{verbatim M1} and @{verbatim M2} exists, then @{verbatim M1} is not a reduction of @{verbatim M2}. \<close> fun sequence_to_failure :: "('in,'out,'state) FSM \<Rightarrow> ('in,'out,'state) FSM \<Rightarrow> ('in \<times> 'out) list \<Rightarrow> bool" where "sequence_to_failure M1 M2 xs = ( (butlast xs) \<in> (language_state M2 (initial M2) \<inter> language_state M1 (initial M1)) \<and> xs \<in> (language_state M1 (initial M1) - language_state M2 (initial M2)))" lemma sequence_to_failure_ob : assumes "\<not> M1 \<preceq> M2" and "well_formed M1" and "well_formed M2" obtains io where "sequence_to_failure M1 M2 io" proof - let ?diff = "{ io . io \<in> language_state M1 (initial M1) \<and> io \<notin> language_state M2 (initial M2)}" have "?diff \<noteq> empty" using assms by auto moreover obtain io where io_def[simp] : "io = arg_min length (\<lambda> io . io \<in> ?diff)" using assms by auto ultimately have io_diff : "io \<in> ?diff" using assms by (meson all_not_in_conv arg_min_natI) then have "io \<noteq> []" using assms io_def language_state by auto then obtain io_init io_last where io_split[simp] : "io = io_init @ [io_last]" by (metis append_butlast_last_id) have io_init_inclusion : "io_init \<in> language_state M1 (initial M1) \<and> io_init \<in> language_state M2 (initial M2)" proof (rule ccontr) assume assm : "\<not> (io_init \<in> language_state M1 (initial M1) \<and> io_init \<in> language_state M2 (initial M2))" have "io_init @ [io_last] \<in> language_state M1 (initial M1)" using io_diff io_split by auto then have "io_init \<in> language_state M1 (initial M1)" by (meson language_state language_state_split) moreover have "io_init \<notin> language_state M2 (initial M2)" using assm calculation by auto ultimately have "io_init \<in> ?diff" by auto moreover have "length io_init < length io" using io_split by auto ultimately have "io \<noteq> arg_min length (\<lambda> io . io \<in> ?diff)" proof - have "\<exists>ps. ps \<in> {ps \<in> language_state M1 (initial M1). ps \<notin> language_state M2 (initial M2)} \<and> \<not> length io \<le> length ps" using \<open>io_init \<in> {io\<in> language_state M1 (initial M1). io \<notin> language_state M2 (initial M2)}\<close> \<open>length io_init < length io\<close> linorder_not_less by blast then show ?thesis by (meson arg_min_nat_le) qed then show "False" using io_def by simp qed then have "sequence_to_failure M1 M2 io" using io_split io_diff by auto then show ?thesis using that by auto qed lemma sequence_to_failure_succ : assumes "sequence_to_failure M1 M2 io" shows "\<forall> q \<in> io_targets M2 (initial M2) (butlast io) . succ M2 (last io) q = {}" proof have "io \<noteq> []" using assms by auto fix q assume "q \<in> io_targets M2 (initial M2) (butlast io)" then obtain tr where "q = target (butlast io || tr) (initial M2)" and "path M2 (butlast io || tr) (initial M2)" and "length (butlast io) = length tr" unfolding io_targets.simps by auto show "succ M2 (last io) q = {}" proof (rule ccontr) assume "succ M2 (last io) q \<noteq> {}" then obtain q' where "q' \<in> succ M2 (last io) q" by blast then have "path M2 [(last io, q')] (target (butlast io || tr) (initial M2))" using \<open>q = target (butlast io || tr) (initial M2)\<close> by auto have "path M2 ((butlast io || tr) @ [(last io, q')]) (initial M2)" using \<open>path M2 (butlast io || tr) (initial M2)\<close> \<open>path M2 [(last io, q')] (target (butlast io || tr) (initial M2))\<close> by auto have "butlast io @ [last io] = io" by (meson \<open>io \<noteq> []\<close> append_butlast_last_id) have "path M2 (io || (tr@[q'])) (initial M2)" proof - have "path M2 ((butlast io || tr) @ ([last io] || [q'])) (initial M2)" by (simp add: FSM.path_append \<open>path M2 (butlast io || tr) (initial M2)\<close> \<open>path M2 [(last io, q')] (target (butlast io || tr) (initial M2))\<close>) then show ?thesis by (metis (no_types) \<open>butlast io @ [last io] = io\<close> \<open>length (butlast io) = length tr\<close> zip_append) qed have "io \<in> L M2" proof - have "length tr + (0 + Suc 0) = length io" by (metis \<open>butlast io @ [last io] = io\<close> \<open>length (butlast io) = length tr\<close> length_append list.size(3) list.size(4)) then show ?thesis using \<open>path M2 (io || tr @ [q']) (initial M2)\<close> by fastforce qed then show "False" using assms by auto qed qed lemma sequence_to_failure_non_nil : assumes "sequence_to_failure M1 M2 xs" shows "xs \<noteq> []" proof assume "xs = []" then have "xs \<in> L M1 \<inter> L M2" by auto then show "False" using assms by auto qed lemma sequence_to_failure_from_arbitrary_failure : assumes "vs@xs \<in> L M1 - L M2" and "vs \<in> L M2 \<inter> L M1" shows "\<exists> xs' . prefix xs' xs \<and> sequence_to_failure M1 M2 (vs@xs')" using assms proof (induction xs rule: rev_induct) case Nil then show ?case by auto next case (snoc x xs) have "vs @ xs \<in> L M1" using snoc.prems(1) by (metis Diff_iff append.assoc language_state_prefix) show ?case proof (cases "vs@xs \<in> L M2") case True have "butlast (vs@xs@[x]) \<in> L M2 \<inter> L M1" using True \<open>vs @ xs \<in> L M1\<close> by (simp add: butlast_append) then show ?thesis using sequence_to_failure.simps snoc.prems by blast next case False then have "vs@xs \<in> L M1 - L M2" using \<open>vs @ xs \<in> L M1\<close> by blast then obtain xs' where "prefix xs' xs" "sequence_to_failure M1 M2 (vs@xs')" using snoc.prems(2) snoc.IH by blast then show ?thesis using prefix_snoc by auto qed qed text \<open> The following lemma shows that if @{verbatim M1} is not a reduction of @{verbatim M2}, then a minimal sequence to a failure exists that is of length at most the number of states in @{verbatim M1} times the number of states in @{verbatim M2}. \<close> lemma sequence_to_failure_length : assumes "well_formed M1" and "well_formed M2" and "observable M1" and "observable M2" and "\<not> M1 \<preceq> M2" shows "\<exists> xs . sequence_to_failure M1 M2 xs \<and> length xs \<le> |M2| * |M1|" proof - obtain seq where "sequence_to_failure M1 M2 seq" using assms sequence_to_failure_ob by blast then have "seq \<noteq> []" by auto let ?bls = "butlast seq" have "?bls \<in> L M1" "?bls \<in> L M2" using \<open>sequence_to_failure M1 M2 seq\<close> by auto then obtain tr1b tr2b where "path M1 (?bls || tr1b) (initial M1)" "length tr1b = length ?bls" "path M2 (?bls || tr2b) (initial M2)" "length ?bls = length tr2b" by fastforce then have "length tr2b = length tr1b" by auto let ?PM = "product M2 M1" have "well_formed ?PM" using well_formed_product[OF assms(1,2)] by assumption have "path ?PM (?bls || tr2b || tr1b) (initial M2, initial M1)" using product_path[OF \<open>length ?bls = length tr2b\<close> \<open>length tr2b = length tr1b\<close>, of M2 M1 "initial M2" "initial M1"] using \<open>path M1 (butlast seq || tr1b) (initial M1)\<close> \<open>path M2 (butlast seq || tr2b) (initial M2)\<close> by blast let ?q1b = "target (?bls || tr1b) (initial M1)" let ?q2b = "target (?bls || tr2b) (initial M2)" have "io_targets M2 (initial M2) ?bls = {?q2b}" by (metis \<open>length (butlast seq) = length tr2b\<close> \<open>path M2 (butlast seq || tr2b) (initial M2)\<close> assms(4) obs_target_is_io_targets) have "io_targets M1 (initial M1) ?bls = {?q1b}" by (metis \<open>length tr1b = length (butlast seq)\<close> \<open>path M1 (butlast seq || tr1b) (initial M1)\<close> assms(3) obs_target_is_io_targets) have "(?q2b, ?q1b) \<in> reachable (product M2 M1) (initial M2, initial M1)" proof - have "target (butlast seq || tr2b || tr1b) (initial M2, initial M1) \<in> reachable (product M2 M1) (initial M2, initial M1)" using \<open>path (product M2 M1) (butlast seq || tr2b || tr1b) (initial M2, initial M1)\<close> by blast then show ?thesis using \<open>length (butlast seq) = length tr2b\<close> \<open>length tr2b = length tr1b\<close> by auto qed have "(initial M2, initial M1) \<in> nodes (product M2 M1)" by (simp add: FSM.nodes.initial) obtain p where repFreePath : "path (product M2 M1) p (initial M2, initial M1) \<and> target p (initial M2, initial M1) = (?q2b,?q1b)" "distinct ((initial M2, initial M1) # states p (initial M2, initial M1))" using reaching_path_without_repetition[OF \<open>well_formed ?PM\<close> \<open>(?q2b, ?q1b) \<in> reachable (product M2 M1) (initial M2, initial M1)\<close> \<open>(initial M2, initial M1) \<in> nodes (product M2 M1)\<close>] by blast then have "set (states p (initial M2, initial M1)) \<subseteq> nodes ?PM" by (simp add: FSM.nodes_states \<open>(initial M2, initial M1) \<in> nodes (product M2 M1)\<close>) moreover have "(initial M2, initial M1) \<notin> set (states p (initial M2, initial M1))" using \<open>distinct ((initial M2, initial M1) # states p (initial M2, initial M1))\<close> by auto ultimately have "set (states p (initial M2, initial M1)) \<subseteq> nodes ?PM - {(initial M2,initial M1)}" by blast moreover have "finite (nodes ?PM)" using \<open>well_formed ?PM\<close> by auto ultimately have "card (set (states p (initial M2, initial M1))) < card (nodes ?PM)" by (metis \<open>(initial M2, initial M1) \<in> nodes (product M2 M1)\<close> \<open>(initial M2, initial M1) \<notin> set (states p (initial M2, initial M1))\<close> \<open>set (states p (initial M2, initial M1)) \<subseteq> nodes (product M2 M1)\<close> psubsetI psubset_card_mono) moreover have "card (set (states p (initial M2, initial M1))) = length (states p (initial M2, initial M1))" using distinct_card repFreePath(2) by fastforce ultimately have "length (states p (initial M2, initial M1)) < |?PM|" by linarith then have "length p < |?PM|" by auto let ?p1 = "map (snd \<circ> snd) p" let ?p2 = "map (fst \<circ> snd) p" let ?pIO = "map fst p" have "p = ?pIO || ?p2 || ?p1" by (metis map_map zip_map_fst_snd) have "path M2 (?pIO || ?p2) (initial M2)" "path M1 (?pIO || ?p1) (initial M1)" using product_path[of ?pIO ?p2 ?p1 M2 M1] using \<open>p = ?pIO || ?p2 || ?p1\<close> repFreePath(1) by auto have "(?q2b, ?q1b) = (target (?pIO || ?p2 || ?p1) (initial M2, initial M1))" using \<open>p = ?pIO || ?p2 || ?p1\<close> repFreePath(1) by auto then have "?q2b = target (?pIO || ?p2) (initial M2)" "?q1b = target (?pIO || ?p1) (initial M1)" by auto have "io_targets M2 (initial M2) ?pIO = {?q2b}" by (metis \<open>path M2 (map fst p || map (fst \<circ> snd) p) (initial M2)\<close> \<open>target (?bls || tr2b) (initial M2) = target (map fst p || map (fst \<circ> snd) p) (initial M2)\<close> assms(4) length_map obs_target_is_io_targets) have "io_targets M1 (initial M1) ?pIO = {?q1b}" by (metis \<open>path M1 (map fst p || map (snd \<circ> snd) p) (initial M1)\<close> \<open>target (?bls || tr1b) (initial M1) = target (map fst p || map (snd \<circ> snd) p) (initial M1)\<close> assms(3) length_map obs_target_is_io_targets) have "seq \<in> L M1" "seq \<notin> L M2" using \<open>sequence_to_failure M1 M2 seq\<close> by auto have "io_targets M1 (initial M1) ?bls = {?q1b}" by (metis \<open>length tr1b = length (butlast seq)\<close> \<open>path M1 (butlast seq || tr1b) (initial M1)\<close> assms(3) obs_target_is_io_targets) obtain q1s where "io_targets M1 (initial M1) seq = {q1s}" by (meson \<open>seq \<in> L M1\<close> assms(3) io_targets_observable_singleton_ob) moreover have "seq = (butlast seq)@[last seq]" using \<open>seq \<noteq> []\<close> by auto ultimately have "io_targets M1 (initial M1) ((butlast seq)@[last seq]) = {q1s}" by auto have "io_targets M1 ?q1b [last seq] = {q1s}" using observable_io_targets_suffix[OF assms(3) \<open>io_targets M1 (initial M1) ?bls = {?q1b}\<close> \<open>io_targets M1 (initial M1) ((butlast seq)@[last seq]) = {q1s}\<close>] by assumption then obtain tr1s where "q1s = target ([last seq] || tr1s) ?q1b" "path M1 ([last seq] || tr1s) ?q1b" "length [last seq] = length tr1s" by auto have "path M1 ([last seq] || [q1s]) ?q1b" by (metis (no_types) \<open>length [last seq] = length tr1s\<close> \<open>path M1 ([last seq] || tr1s) (target (butlast seq || tr1b) (initial M1))\<close> \<open>q1s = target ([last seq] || tr1s) (target (butlast seq || tr1b) (initial M1))\<close> append_Nil append_butlast_last_id butlast.simps(2) length_butlast length_greater_0_conv not_Cons_self2 target_alt_def(2)) then have "q1s \<in> succ M1 (last seq) ?q1b" by auto have "succ M2 (last seq) ?q2b = {}" proof (rule ccontr) assume "succ M2 (last seq) (target (butlast seq || tr2b) (initial M2)) \<noteq> {}" then obtain q2f where "q2f \<in> succ M2 (last seq) ?q2b" by blast then have "target ([last seq] || [q2f]) ?q2b = q2f" "path M2 ([last seq] || [q2f]) ?q2b" "length [q2f] = length [last seq]" by auto then have "q2f \<in> io_targets M2 ?q2b [last seq]" by (metis io_target_from_path) then have "io_targets M2 ?q2b [last seq] = {q2f}" using assms(4) by (meson observable_io_target_is_singleton) have "io_targets M2 (initial M2) (butlast seq @ [last seq]) = {q2f}" using observable_io_targets_append[OF assms(4) \<open>io_targets M2 (initial M2) ?bls = {?q2b}\<close> \<open>io_targets M2 ?q2b [last seq] = {q2f}\<close>] by assumption then have "seq \<in> L M2" using \<open>seq = butlast seq @ [last seq]\<close> by auto then show "False" using \<open>seq \<notin> L M2\<close> by blast qed have "?pIO \<in> L M1" "?pIO \<in> L M2" using \<open>path M1 (?pIO || ?p1) (initial M1)\<close> \<open>path M2 (?pIO || ?p2) (initial M2)\<close> by auto then have "butlast (?pIO@[last seq]) \<in> L M1 \<inter> L M2" by auto have "?pIO@[last seq] \<in> L M1" using observable_io_targets_append[OF assms(3) \<open>io_targets M1 (initial M1) ?pIO = {?q1b}\<close> \<open>io_targets M1 ?q1b [last seq] = {q1s}\<close>] by (metis all_not_in_conv insert_not_empty io_targets_elim language_state) moreover have "?pIO@[last seq] \<notin> L M2" proof assume "?pIO@[last seq] \<in> L M2" then obtain q2f where "io_targets M2 (initial M2) (?pIO@[last seq]) = {q2f}" by (meson assms(4) io_targets_observable_singleton_ob) have "io_targets M2 ?q2b [last seq] = {q2f}" using observable_io_targets_split[OF assms(4) \<open>io_targets M2 (initial M2) (?pIO@[last seq]) = {q2f}\<close> \<open>io_targets M2 (initial M2) (map fst p) = {?q2b}\<close>] by assumption then have "q2f \<in> succ M2 (last seq) ?q2b" by (simp add: io_targets_succ) then show "False" using \<open>succ M2 (last seq) ?q2b = {}\<close> by auto qed ultimately have "?pIO@[last seq] \<in> L M1 - L M2" by auto have "sequence_to_failure M1 M2 (?pIO@[last seq])" using \<open>butlast (?pIO@[last seq]) \<in> L M1 \<inter> L M2\<close> \<open>?pIO@[last seq] \<in> L M1 - L M2\<close> by auto have "length (?pIO@[last seq]) = Suc (length ?pIO)" by auto then have "length (?pIO@[last seq]) \<le> |?PM|" using \<open>length p < |?PM|\<close> by auto have "card (nodes M2 \<times> nodes M1) \<le> |M2| * |M1|" by (simp add: card_cartesian_product) have "finite (nodes M2 \<times> nodes M1)" proof show "finite (nodes M2)" using assms by auto show "finite (nodes M1)" using assms by auto qed have "|?PM| \<le> |M2| * |M1|" by (meson \<open>card (nodes M2 \<times> nodes M1) \<le> |M2| * |M1|\<close> \<open>finite (nodes M2 \<times> nodes M1)\<close> card_mono dual_order.trans product_nodes) then have "length (?pIO@[last seq]) \<le> |M2| * |M1|" using \<open>length (?pIO@[last seq]) \<le> |?PM|\<close> by auto then have "sequence_to_failure M1 M2 (?pIO@[last seq]) \<and> length (?pIO@[last seq]) \<le> |M2| * |M1|" using \<open>sequence_to_failure M1 M2 (?pIO@[last seq])\<close> by auto then show ?thesis by blast qed subsection {* Minimal sequence to failure extending *} text \<open> A minimal sequence to a failure extending some some set of IO-sequences is a sequence to a failure of minimal length such that a prefix of that sequence is contained in the set. \<close> fun minimal_sequence_to_failure_extending :: "'in list set \<Rightarrow> ('in,'out,'state) FSM \<Rightarrow> ('in,'out,'state) FSM \<Rightarrow> ('in \<times> 'out) list \<Rightarrow> ('in \<times> 'out) list \<Rightarrow> bool" where "minimal_sequence_to_failure_extending V M1 M2 v' io = ( v' \<in> L\<^sub>i\<^sub>n M1 V \<and> sequence_to_failure M1 M2 (v' @ io) \<and> \<not> (\<exists> io' . \<exists> w' \<in> L\<^sub>i\<^sub>n M1 V . sequence_to_failure M1 M2 (w' @ io') \<and> length io' < length io))" lemma minimal_sequence_to_failure_extending_det_state_cover_ob : assumes "well_formed M1" and "well_formed M2" and "is_det_state_cover M2 V" and "\<not> M1 \<preceq> M2" obtains vs xs where "minimal_sequence_to_failure_extending V M1 M2 vs xs" proof - \<comment> \<open>set of all IO-sequences that extend some reaction of M1 to V to a failure\<close> let ?exts = "{xs. \<exists>vs' \<in> L\<^sub>i\<^sub>n M1 V. sequence_to_failure M1 M2 (vs'@xs)}" \<comment> \<open>arbitrary sequence to failure\<close> \<comment> \<open>must be contained in ?exts as V contains the empty sequence\<close> obtain stf where "sequence_to_failure M1 M2 stf" using assms sequence_to_failure_ob by blast then have "sequence_to_failure M1 M2 ([] @ stf)" by simp moreover have "[] \<in> L\<^sub>i\<^sub>n M1 V" by (meson assms(3) det_state_cover_initial language_state_for_inputs_empty) ultimately have "stf \<in> ?exts" by blast \<comment> \<open>the minimal length sequence of ?exts\<close> \<comment> \<open>is a minimal sequence to a failure extending V by construction\<close> let ?xsMin = "arg_min length (\<lambda>xs. xs \<in> ?exts)" have xsMin_def : "?xsMin \<in> ?exts \<and> (\<forall>xs \<in> ?exts. length ?xsMin \<le> length xs)" by (metis (no_types, lifting) \<open>stf \<in> ?exts\<close> arg_min_nat_lemma) then obtain vs where "vs \<in> L\<^sub>i\<^sub>n M1 V \<and> sequence_to_failure M1 M2 (vs @ ?xsMin)" by blast moreover have "\<not>(\<exists>xs . \<exists>ws \<in> L\<^sub>i\<^sub>n M1 V. sequence_to_failure M1 M2 (ws@xs) \<and> length xs < length ?xsMin)" using leD xsMin_def by blast ultimately have "minimal_sequence_to_failure_extending V M1 M2 vs ?xsMin" by auto then show ?thesis using that by auto qed lemma mstfe_prefix_input_in_V : assumes "minimal_sequence_to_failure_extending V M1 M2 vs xs" shows "(map fst vs) \<in> V" proof - have "vs \<in> L\<^sub>i\<^sub>n M1 V" using assms by auto then show ?thesis using language_state_for_inputs_map_fst_contained by auto qed subsection {* Complete test suite derived from the product machine *} text \<open> The classical result of testing FSMs for language inclusion : Any failure can be observed by a sequence of length at most n*m where n is the number of states of the reference model (here FSM @{verbatim M2}) and m is an upper bound on the number of states of the SUT (here FSM @{verbatim M1}). \<close> lemma product_suite_soundness : assumes "well_formed M1" and "well_formed M2" and "observable M1" and "observable M2" and "inputs M2 = inputs M1" and "|M1| \<le> m " shows "\<not> M1 \<preceq> M2 \<longrightarrow> \<not> M1 \<preceq>\<lbrakk>{xs . set xs \<subseteq> inputs M2 \<and> length xs \<le> |M2| * m}\<rbrakk> M2" (is "\<not> M1 \<preceq> M2 \<longrightarrow> \<not> M1 \<preceq>\<lbrakk>?TS\<rbrakk> M2") proof assume "\<not> M1 \<preceq> M2" obtain stf where "sequence_to_failure M1 M2 stf \<and> length stf \<le> |M2| * |M1|" using sequence_to_failure_length[OF assms(1-4) \<open>\<not> M1 \<preceq> M2\<close>] by blast then have "sequence_to_failure M1 M2 stf" "length stf \<le> |M2| * |M1|" by auto then have "stf \<in> L M1" by auto let ?xs = "map fst stf" have "set ?xs \<subseteq> inputs M1" by (meson \<open>stf \<in> L M1\<close> assms(1) language_state_inputs) then have "set ?xs \<subseteq> inputs M2" using assms(5) by auto have "length ?xs \<le> |M2| * |M1|" using \<open>length stf \<le> |M2| * |M1|\<close> by auto have "length ?xs \<le> |M2| * m" proof - show ?thesis by (metis (no_types) \<open>length (map fst stf) \<le> |M2| * |M1|\<close> \<open>|M1| \<le> m\<close> dual_order.trans mult.commute mult_le_mono1) qed have "stf \<in> L\<^sub>i\<^sub>n M1 {?xs}" by (meson \<open>stf \<in> L M1\<close> insertI1 language_state_for_inputs_map_fst) have "?xs \<in> ?TS" using \<open>set ?xs \<subseteq> inputs M2\<close> \<open>length ?xs \<le> |M2| * m\<close> by blast have "stf \<in> L\<^sub>i\<^sub>n M1 ?TS" by (metis (no_types, lifting) \<open>map fst stf \<in> {xs. set xs \<subseteq> inputs M2 \<and> length xs \<le> |M2| * m}\<close> \<open>stf \<in> L M1\<close> language_state_for_inputs_map_fst) have "stf \<notin> L M2" using \<open>sequence_to_failure M1 M2 stf\<close> by auto then have "stf \<notin> L\<^sub>i\<^sub>n M2 ?TS" by auto show "\<not> M1 \<preceq>\<lbrakk>?TS\<rbrakk> M2" using \<open>stf \<in> L\<^sub>i\<^sub>n M1 ?TS\<close> \<open>stf \<notin> L\<^sub>i\<^sub>n M2 ?TS\<close> by blast qed lemma product_suite_completeness : assumes "well_formed M1" and "well_formed M2" and "observable M1" and "observable M2" and "inputs M2 = inputs M1" and "|M1| \<le> m " shows "M1 \<preceq> M2 \<longleftrightarrow> M1 \<preceq>\<lbrakk>{xs . set xs \<subseteq> inputs M2 \<and> length xs \<le> |M2| * m}\<rbrakk> M2" (is "M1 \<preceq> M2 \<longleftrightarrow> M1 \<preceq>\<lbrakk>?TS\<rbrakk> M2") proof show "M1 \<preceq> M2 \<Longrightarrow> M1 \<preceq>\<lbrakk>?TS\<rbrakk> M2" \<comment> \<open>soundness holds trivially\<close> unfolding language_state_for_inputs.simps io_reduction.simps by blast show "M1 \<preceq>\<lbrakk>?TS\<rbrakk> M2 \<Longrightarrow> M1 \<preceq> M2" using product_suite_soundness[OF assms] by auto qed end
(* -------------------------------------------------------------------- * Copyright (c) - 2006--2012 - IMDEA Software Institute * Copyright (c) - 2006--2012 - Inria * Copyright (c) - 2006--2012 - Microsoft Coprporation * * Distributed under the terms of the CeCILL-B-V1 license * -------------------------------------------------------------------- *) (** * SemHElGamal.v : Language extension with cyclic group and bitstring types *) Set Implicit Arguments. Require Import PPT. Require Export BuildTac. Require Export Group. Require Export Bitstrings. Unset Strict Implicit. Inductive Ut : Type := | Bitstring | Group. (** * User-defined type module *) Module UT <: UTYPE. Definition t := Ut. Definition eqb (x y:t) := match x, y with | Bitstring, Bitstring => true | Group, Group => true | _, _ => false end. Lemma eqb_spec : forall x y, if eqb x y then x = y else x <> y. Proof. intros x y; case x; case y; simpl; trivial; discriminate. Qed. Definition eq_dec (x y:t) : {x = y} + {True} := match x as x0 return {x0 = y} + {True} with | Bitstring => match y as y0 return {Bitstring= y0} + {True} with | Bitstring => left _ (refl_equal _) | _ => right _ I end | Group => match y as y0 return {Group= y0} + {True} with | Group => left _ (refl_equal _) | _ => right _ I end end. Lemma eq_dec_r : forall x y i, eq_dec x y = right _ i -> x <> y. Proof. intros x y; case x; case y; simpl; intros; discriminate. Qed. Definition interp k (t0:t) : Type := match t0 with | Bitstring => Bvector k | Group => CGK.t (2^k) end. Definition size k (t0:t) (_:interp k t0) := S k. Definition default k (t0:t) : interp k t0 := match t0 with | Bitstring => Bvect_false k | Group => CGK.g0 (2^k) end. Definition default_poly (t0:t) := pplus (pcst 1) pvar. Lemma size_positive : forall k t0 (x:interp k t0), (0 < size x)%nat. Proof. intros k t0 x. unfold size; auto with arith. Qed. Lemma default_poly_spec : forall k (t0:t), (size (default k t0) <= peval (default_poly t0) k)%nat. Proof. intros k t0. unfold size, default, default_poly. rewrite pplus_spec, pcst_spec, pvar_spec; trivial. Qed. Definition i_eqb k t : interp k t -> interp k t -> bool := match t with | Bitstring => @Veqb k | Group => @CGK.eqb (2^k) end. Lemma i_eqb_spec : forall k t (x y:interp k t), if i_eqb x y then x = y else x <> y. Proof. intros; unfold i_eqb. destruct t0. apply Veqb_spec. apply CGK.eqb_spec. Qed. End UT. Module T := MakeType UT. Inductive usupport_ (Ttype : Type) (Tuser : Ut -> Ttype) : Ttype -> Type := | Usupport : usupport_ Tuser (Tuser Bitstring). (** * User-defined random sampling for bitstrings *) Module US <: USUPPORT UT T. Definition usupport := usupport_ T.User. Definition eval k t (s:usupport t) : list (T.interp k t) := match s in usupport_ _ t0 return list (T.interp k t0) with | Usupport => bs_support k end. Definition ceval k t (s:usupport t) : list (T.interp k t) * nat := match s in usupport_ _ t0 return list (T.interp k t0) * nat with | Usupport => (bs_support k, S O) end. Lemma eval_usupport_nil : forall k t (s:usupport t), eval k s <> nil. Proof. intros; case s; exact (@bs_support_not_nil k). Qed. Lemma ceval_spec : forall k t (s:usupport t), eval k s = fst (ceval k s). Proof. intros k t s; case s; trivial. Qed. Definition eqb (t1 t2:T.type) (s1:usupport t1) (s2:usupport t2) : bool := match s1, s2 with | Usupport, Usupport => true end. Lemma eqb_spec_dep : forall t1 (e1 : usupport t1) t2 (e2:usupport t2), if eqb e1 e2 then eq_dep T.type usupport t1 e1 t2 e2 else ~eq_dep T.type usupport t1 e1 t2 e2. Proof. intros. case e1; case e2; simpl. constructor. Qed. Lemma eqb_spec : forall t (e1 e2:usupport t), if eqb e1 e2 then e1 = e2 else e1 <> e2. Proof. intros t e1 e2. generalize (eqb_spec_dep e1 e2). case (eqb e1 e2); intro H. apply T.eq_dep_eq; trivial. intro Heq; apply H; rewrite Heq; constructor. Qed. End US. Inductive uop : Type := | OGorder | OGen | OGmul | OGpow | OGinv | Oxor. (** * Module for user-defined operators *) Module Uop <: UOP UT T. Definition t := uop. Definition eqb (o1 o2 : t) : bool := match o1, o2 with | OGorder, OGorder | OGen, OGen | OGmul, OGmul | OGpow, OGpow | OGinv, OGinv => true | Oxor, Oxor => true | _, _ => false end. Lemma eqb_spec : forall x y, if eqb x y then x = y else x <> y. Proof. destruct x; destruct y; simpl; trivial; intro; discriminate. Qed. Definition targs (op : t) : list T.type := match op with | OGorder | OGen => nil | OGmul => T.User Group :: T.User Group :: nil | OGpow => T.User Group :: T.Nat :: nil | OGinv => T.User Group :: nil | Oxor => T.User Bitstring :: T.User Bitstring :: nil end. Definition tres (op: t) : T.type := match op with | OGorder => T.Nat | Oxor => T.User Bitstring | _ => T.User Group end. Open Scope nat_scope. Definition interp_op (k:nat) (op:t) : T.type_op k (targs op) (tres op) := match op as op0 return T.type_op k (targs op0) (tres op0) with | OGorder => 2^k | OGen => @CGK.g (2^k) | OGmul => @CGK.mul (2^k) | OGpow => @CGK.pow (2^k) | OGinv => @CGK.inv (2^k) | Oxor => BVxor k end. Implicit Arguments interp_op [k]. Definition cinterp_op (k:nat) (op:t) : T.ctype_op k (targs op) (tres op) := match op as op0 return T.ctype_op k (targs op0) (tres op0) with | OGorder => (2^k, size_nat (2^k)) | OGen => (@CGK.g (2^k), S O) | OGmul => fun x y => (@CGK.mul (2^k) x y, CGK.cost_mul x y) | OGpow => fun x n => (@CGK.pow (2^k) x n, CGK.cost_pow x n) | OGinv => fun x => (@CGK.inv (2^k) x, CGK.cost_inv x) | Oxor => fun x y => (BVxor k x y, k) end. Implicit Arguments cinterp_op [k]. Definition eval_op k (op:t) (args: dlist (T.interp k) (targs op)) : T.interp k (tres op) := @T.app_op k (targs op) (tres op) (interp_op op) args. Definition ceval_op k (op:t) (args: dlist (T.interp k) (targs op)) : T.interp k (tres op) * nat := @T.capp_op k (targs op) (tres op) (cinterp_op op) args. Lemma ceval_op_spec : forall k op args, @eval_op k op args = fst (@ceval_op k op args). Proof. intros k o args; destruct o; simpl in args; T.dlist_inversion args; subst; trivial. Qed. End Uop. (** Semantics with optimizations *) Module Entries. Module SemO <: SEM_OPT. Module Sem := MakeSem.Make UT T Uop US. Export Sem. Notation "x '^' y" := (E.Eop (O.Ouser OGpow) {x, y}). Notation "x '**' y" := (E.Eop (O.Ouser OGmul) {x , y}) (at level 40, left associativity). Notation "x '|x|' y" := (E.Eop (O.Ouser Oxor) {x, y}) (at level 50, left associativity). Notation "'g'" := (E.Eop (O.Ouser OGen) (@dnil T.type E.expr)). Notation "'q'" := (E.Eop (O.Ouser OGorder) (@dnil T.type E.expr)). Notation "'{0,1}^k'" := (E.Duser (Usupport T.User)). (* Simplifies [(e1^e2)^e3] to [e1^(e2*e3)] *) Definition simpl_op (op : Uop.t) : E.args (Uop.targs op) -> E.expr (Uop.tres op) := match op as op0 return E.args (Uop.targs op0) -> E.expr (Uop.tres op0) with | OGpow => fun args => E.app_expr (T.User Group) args (fun (e:E.expr (T.User Group)) (e3:E.expr T.Nat) => match E.get_uop e with | Some (existT uop args) => match uop as uop0 return E.args (Uop.targs uop0) -> E.expr (T.User Group) with | OGpow => fun args => E.app_expr (T.User Group) args (fun (e1:E.expr (T.User Group)) (e2:E.expr T.Nat) => e1 ^ (e2 *! e3)) | _ => fun _ => e ^ e3 end args | None => e ^ e3 end) | op => fun args => E.Eop (O.Ouser op) args end. Implicit Arguments simpl_op []. Lemma simpl_op_spec : forall k op args (m:Mem.t k), E.eval_expr (simpl_op op args) m = E.eval_expr (E.Eop (O.Ouser op) args) m. Proof. destruct op; simpl; trivial. intros args;T.dlist_inversion args; rewrite Heq; intros; simpl. generalize (E.get_uop_spec x); destruct (E.get_uop x); trivial. destruct s as (uop0, args0). intros H; generalize (H uop0 args0 (refl_equal _)); clear H; simpl; intros. destruct uop0; trivial. rewrite (T.eq_dep_eq H); clear H. clear Heq;T.dlist_inversion args0; rewrite Heq. simpl; unfold O.eval_op; simpl. rewrite CGKP.pow_pow; trivial. Qed. End SemO. Module BP := BaseProp.Make SemO.Sem. Module Uppt. Import BP. Implicit Arguments T.size [k t]. Open Scope nat_scope. (** PPT expression *) Definition PPT_expr (t:T.type) (e:E.expr t) (F:polynomial -> polynomial) (G:polynomial -> polynomial) : Prop := forall k (m:Mem.t k) p, (forall t (x:Var.var t), BP.Vset.mem x (BP.fv_expr e) -> T.size (m x) <= peval p k) -> let (v,n) := E.ceval_expr e m in T.size v <= peval (F p) k /\ n <= peval (G p) k. (** PPT support *) Definition PPT_support t (s:E.support t) (F:polynomial -> polynomial) (G:polynomial -> polynomial) : Prop := forall k (m:Mem.t k) p, (forall t (x:Var.var t), BP.Vset.mem x (BP.fv_distr s) -> T.size (m x) <= peval p k) -> let (l,n) := E.ceval_support s m in (forall v, In v l -> T.size v <= peval (F p) k) /\ n <= peval (G p) k. Definition utsize : UT.t -> nat := fun _ => 1. Definition utsize_default_poly : nat -> polynomial := fun _ => pplus (pcst 1) pvar. Lemma utsize_default_poly_spec : forall r ut, utsize ut <= r -> forall k, UT.size (t:=ut) (UT.default k ut) <= peval (utsize_default_poly r) k. Proof. intros r ut _ k. case ut; simpl; unfold UT.size, utsize_default_poly; rewrite pplus_spec, pcst_spec, pvar_spec; trivial. Qed. Definition uop_poly (o:Uop.t) : bool := match o with | OGorder | OGen | OGmul | OGpow | Oxor => true | _ => false end. Lemma uop_poly_spec : forall o (la:dlist E.expr (O.targs (O.Ouser o))), uop_poly o -> (forall t (e:E.expr t), @DIn _ E.expr _ e _ la -> exists F, exists G, PPT_expr e F G) -> exists F, exists G, PPT_expr (E.Eop (O.Ouser o) la) F G. Proof. intros o la H Hla. destruct o. (* OGorder *) T.dlist_inversion la. rewrite Heq in Hla |- *. exists (fun _ => pplus (pcst 1) pvar). exists (fun _ => pplus (pcst 1) pvar). simpl; split. rewrite pplus_spec, pcst_spec, pvar_spec; rewrite size_nat_pow_2; trivial. simpl; rewrite plus_0_r. rewrite pplus_spec, pcst_spec, pvar_spec; rewrite size_nat_pow_2; trivial. (* OGen *) T.dlist_inversion la. rewrite Heq in Hla |- *. exists (fun _ => pplus (pcst 1) pvar). exists (fun _ => 1). simpl; split. rewrite pplus_spec, pcst_spec, pvar_spec; trivial. rewrite pcst_spec; trivial. (* OGmul *) T.dlist_inversion la. rewrite Heq in Hla |- *. destruct (Hla _ x) as [F1 [G1 H1] ]. left; trivial. destruct (Hla _ x0) as [F2 [G2 H2] ]. right; left; trivial. exists (fun _ => pplus (pcst 1) pvar). exists (fun p => pplus CGK.cost_mul_poly (pplus (G1 p) (G2 p))). intros k m p Hm; simpl; split. rewrite pplus_spec, pcst_spec, pvar_spec; trivial. rewrite pplus_spec, pplus_spec. apply plus_le_compat. apply le_trans with (peval CGK.cost_mul_poly (pred (size_nat (2^k)))). apply CGK.cost_mul_poly_spec. rewrite size_nat_pow_2; trivial. generalize (H1 k m p) (H2 k m p); clear H1 H2. case_eq (E.ceval_expr x m); simpl. case_eq (E.ceval_expr x0 m); simpl. intros i n Heqi i0 n0 Heqi0 Hi Hi0. destruct Hi. intros; apply Hm; simpl. apply Vset.subset_correct with (fv_expr x); [ | trivial]. unfold fv_expr; simpl. apply fv_expr_rec_subset. destruct Hi0. intros; apply Hm; simpl. apply Vset.subset_correct with (fv_expr x0); [ | trivial]. unfold fv_expr at 2; simpl. fold (fv_expr_extend x0 (fv_expr_rec Vset.empty x)). rewrite union_fv_expr_spec. apply VsetP.subset_union_l. rewrite plus_0_r; apply plus_le_compat; auto. (* OGpow *) T.dlist_inversion la. rewrite Heq in Hla |- *. destruct (Hla _ x) as [F1 [G1 H1] ]. left; trivial. destruct (Hla _ x0) as [F2 [G2 H2] ]. right; left; trivial. exists (fun _ => pplus (pcst 1) pvar). exists (fun p => pplus CGK.cost_pow_poly (pplus (G1 p) (G2 p))). intros k m p Hm; simpl; split. rewrite pplus_spec, pcst_spec, pvar_spec; trivial. rewrite pplus_spec, pplus_spec. apply plus_le_compat. apply le_trans with (peval CGK.cost_pow_poly (pred (size_nat (2^k)))). apply CGK.cost_pow_poly_spec. rewrite size_nat_pow_2; trivial. generalize (H1 k m p) (H2 k m p); clear H1 H2. case_eq (E.ceval_expr x m); simpl. case_eq (E.ceval_expr x0 m); simpl. intros i n Heqi i0 n0 Heqi0 Hi Hi0. destruct Hi. intros; apply Hm; simpl. apply Vset.subset_correct with (fv_expr x); [ | trivial]. unfold fv_expr; simpl. apply fv_expr_rec_subset. destruct Hi0. intros; apply Hm; simpl. apply Vset.subset_correct with (fv_expr x0); [ | trivial]. unfold fv_expr at 2; simpl. fold (fv_expr_extend x0 (fv_expr_rec Vset.empty x)). rewrite union_fv_expr_spec. apply VsetP.subset_union_l. rewrite plus_0_r; apply plus_le_compat; auto. (* OGinv *) T.dlist_inversion la. rewrite Heq in Hla; discriminate. (* Oxor *) T.dlist_inversion la. rewrite Heq in Hla |- *. destruct (Hla _ x) as [F1 [G1 H1] ]. left; trivial. destruct (Hla _ x0) as [F2 [G2 H2] ]. right; left; trivial. exists (fun _ => pplus (pcst 1) pvar). exists (fun p => pplus (pplus (pcst 1) pvar) (pplus (G1 p) (G2 p))). simpl; split. rewrite pplus_spec, pcst_spec, pvar_spec. simpl; unfold UT.size; trivial. generalize (H1 k m p) (H2 k m p); clear H1 H2. simpl. case_eq (E.ceval_expr x m); simpl. case_eq (E.ceval_expr x0 m); simpl. intros i n Heqi i0 n0 Heqi0 Hi Hi0. destruct Hi. intros; apply H0; simpl. apply Vset.subset_correct with (fv_expr x); [ | trivial]. unfold fv_expr; simpl. apply fv_expr_rec_subset. destruct Hi0. intros; apply H0; simpl. apply Vset.subset_correct with (fv_expr x0); [ | trivial]. unfold fv_expr at 2; simpl. fold (fv_expr_extend x0 (fv_expr_rec Vset.empty x)). rewrite union_fv_expr_spec. apply VsetP.subset_union_l. rewrite pplus_spec, pplus_spec, pplus_spec, pcst_spec, pvar_spec. apply plus_le_compat; auto. auto with arith. rewrite plus_0_r; apply plus_le_compat; trivial. Qed. Definition usupport_poly t (us:US.usupport t) : bool := match us with | Usupport => true end. Lemma usupport_poly_spec : forall t (us:US.usupport t), usupport_poly us -> exists F, exists G, PPT_support (E.Duser us) F G. Proof. intros t us; destruct us; intros _. exists (fun _ => pplus (pcst 1) pvar). exists (fun _ => pcst 1). intros k m p Hm. simpl; split. rewrite pplus_spec, pcst_spec, pvar_spec. intros; simpl; unfold UT.size; trivial. rewrite pcst_spec; trivial. Qed. End Uppt. End Entries. Module Tactics := BuildTac.Make Entries. Export Tactics. Lemma opt_sampling : forall E (x y z:Var.var (T.User Bitstring)), Var.mkV x <> y -> Var.mkV x <> z -> Var.mkV y <> z -> EqObs (Vset.singleton z) E [x <$- {0,1}^k; y <- x |x| z] E [y <$- {0,1}^k; x <- y |x| z] (Vset.add x (Vset.add y (Vset.singleton z))). Proof. intros E x y z Hxy Hxz Hyz. apply equiv_cons with ((kreq_mem (Vset.singleton z)) /-\ fun k m1 m2 => m1 x = BVxor _ (m2 y) (m2 z)). eapply equiv_strengthen; [ | apply equiv_random_permut with (f:=fun k (m1 m2:Mem.t k) v => BVxor _ (m2 z) v)]. unfold kreq_mem, andR; split. apply PermutP_weaken with (fun v1 v2 => v1 = BVxor k v2 (m2 z)). intros; subst; apply BVxor_comm. apply PermutP_bs_support_xor. intros; rewrite <- (H _ z); [ | apply Vset.singleton_correct; trivial]. split. intros ? ? Hn; Vset_mem_inversion Hn. rewrite <- Heq. repeat (rewrite Mem.get_upd_diff; [ | trivial]). rewrite H; [ | apply Vset.singleton_correct]; trivial. repeat rewrite Mem.get_upd_same. rewrite Mem.get_upd_diff, BVxor_comm, H; trivial. apply Vset.singleton_correct; trivial. eapply equiv_strengthen; [ | apply equiv_assign]. unfold upd_para, Meq, andR; intros k m1 m2 (H1, H2). simpl E.eval_expr; unfold O.eval_op; simpl T.app_op. intros ? ? Hn; Vset_mem_inversion Hn. rewrite <- Heq, Mem.get_upd_diff, Mem.get_upd_same; trivial. auto. rewrite <- Heq0, Mem.get_upd_same, Mem.get_upd_diff, H2, (H1 _ z). rewrite BVxor_assoc, BVxor_nilpotent, BVxor_0_r; trivial. apply Vset.singleton_correct; trivial. trivial. rewrite <- Heq1. repeat (rewrite Mem.get_upd_diff; [ | auto]). rewrite H1; [ | apply Vset.singleton_correct]; trivial. Qed.
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies ! This file was ported from Lean 3 source module order.concept ! leanprover-community/mathlib commit 1e05171a5e8cf18d98d9cf7b207540acb044acae ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Data.Set.Lattice /-! # Formal concept analysis This file defines concept lattices. A concept of a relation `r : α → β → Prop` is a pair of sets `s : Set α` and `t : Set β` such that `s` is the set of all `a : α` that are related to all elements of `t`, and `t` is the set of all `b : β` that are related to all elements of `s`. Ordering the concepts of a relation `r` by inclusion on the first component gives rise to a *concept lattice*. Every concept lattice is complete and in fact every complete lattice arises as the concept lattice of its `≤`. ## Implementation notes Concept lattices are usually defined from a *context*, that is the triple `(α, β, r)`, but the type of `r` determines `α` and `β` already, so we do not define contexts as a separate object. ## TODO Prove the fundamental theorem of concept lattices. ## References * [Davey, Priestley *Introduction to Lattices and Order*][davey_priestley] ## Tags concept, formal concept analysis, intent, extend, attribute -/ open Function OrderDual Set variable {ι : Sort _} {α β γ : Type _} {κ : ι → Sort _} (r : α → β → Prop) {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} /-! ### Intent and extent -/ /-- The intent closure of `s : Set α` along a relation `r : α → β → Prop` is the set of all elements which `r` relates to all elements of `s`. -/ def intentClosure (s : Set α) : Set β := { b | ∀ ⦃a⦄, a ∈ s → r a b } #align intent_closure intentClosure /-- The extent closure of `t : Set β` along a relation `r : α → β → Prop` is the set of all elements which `r` relates to all elements of `t`. -/ def extentClosure (t : Set β) : Set α := { a | ∀ ⦃b⦄, b ∈ t → r a b } #align extent_closure extentClosure variable {r} theorem subset_intentClosure_iff_subset_extentClosure : t ⊆ intentClosure r s ↔ s ⊆ extentClosure r t := ⟨fun h _ ha _ hb => h hb ha, fun h _ hb _ ha => h ha hb⟩ #align subset_intent_closure_iff_subset_extent_closure subset_intentClosure_iff_subset_extentClosure variable (r) theorem gc_intentClosure_extentClosure : GaloisConnection (toDual ∘ intentClosure r) (extentClosure r ∘ ofDual) := fun _ _ => subset_intentClosure_iff_subset_extentClosure #align gc_intent_closure_extent_closure gc_intentClosure_extentClosure theorem intentClosure_swap (t : Set β) : intentClosure (swap r) t = extentClosure r t := rfl #align intent_closure_swap intentClosure_swap theorem extentClosure_swap (s : Set α) : extentClosure (swap r) s = intentClosure r s := rfl #align extent_closure_swap extentClosure_swap @[simp] theorem intentClosure_empty : intentClosure r ∅ = univ := eq_univ_of_forall fun _ _ => False.elim #align intent_closure_empty intentClosure_empty @[simp] theorem extentClosure_empty : extentClosure r ∅ = univ := intentClosure_empty _ #align extent_closure_empty extentClosure_empty @[simp] theorem intentClosure_union (s₁ s₂ : Set α) : intentClosure r (s₁ ∪ s₂) = intentClosure r s₁ ∩ intentClosure r s₂ := Set.ext fun _ => ball_or_left #align intent_closure_union intentClosure_union @[simp] theorem extentClosure_union (t₁ t₂ : Set β) : extentClosure r (t₁ ∪ t₂) = extentClosure r t₁ ∩ extentClosure r t₂ := intentClosure_union _ _ _ #align extent_closure_union extentClosure_union @[simp] theorem intentClosure_unionᵢ (f : ι → Set α) : intentClosure r (⋃ i, f i) = ⋂ i, intentClosure r (f i) := (gc_intentClosure_extentClosure r).l_supᵢ #align intent_closure_Union intentClosure_unionᵢ @[simp] theorem extentClosure_unionᵢ (f : ι → Set β) : extentClosure r (⋃ i, f i) = ⋂ i, extentClosure r (f i) := intentClosure_unionᵢ _ _ #align extent_closure_Union extentClosure_unionᵢ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note: Can be proved by simp. so not marked as @[simp] -- @[simp] theorem intentClosure_unionᵢ₂ (f : ∀ i, κ i → Set α) : intentClosure r (⋃ (i) (j), f i j) = ⋂ (i) (j), intentClosure r (f i j) := (gc_intentClosure_extentClosure r).l_supᵢ₂ #align intent_closure_Union₂ intentClosure_unionᵢ₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note: Can be proved by simp. so not marked as @[simp] -- @[simp] theorem extentClosure_Union₂ (f : ∀ i, κ i → Set β) : extentClosure r (⋃ (i) (j), f i j) = ⋂ (i) (j), extentClosure r (f i j) := intentClosure_unionᵢ₂ _ _ #align extent_closure_Union₂ extentClosure_Union₂ theorem subset_extentClosure_intentClosure (s : Set α) : s ⊆ extentClosure r (intentClosure r s) := (gc_intentClosure_extentClosure r).le_u_l _ #align subset_extent_closure_intent_closure subset_extentClosure_intentClosure theorem subset_intentClosure_extentClosure (t : Set β) : t ⊆ intentClosure r (extentClosure r t) := subset_extentClosure_intentClosure _ t #align subset_intent_closure_extent_closure subset_intentClosure_extentClosure @[simp] theorem intentClosure_extentClosure_intentClosure (s : Set α) : intentClosure r (extentClosure r <| intentClosure r s) = intentClosure r s := (gc_intentClosure_extentClosure r).l_u_l_eq_l _ #align intent_closure_extent_closure_intent_closure intentClosure_extentClosure_intentClosure @[simp] theorem extentClosure_intentClosure_extentClosure (t : Set β) : extentClosure r (intentClosure r <| extentClosure r t) = extentClosure r t := intentClosure_extentClosure_intentClosure _ t #align extent_closure_intent_closure_extent_closure extentClosure_intentClosure_extentClosure theorem intentClosure_anti : Antitone (intentClosure r) := (gc_intentClosure_extentClosure r).monotone_l #align intent_closure_anti intentClosure_anti theorem extentClosure_anti : Antitone (extentClosure r) := intentClosure_anti _ #align extent_closure_anti extentClosure_anti /-! ### Concepts -/ variable (α β) /-- The formal concepts of a relation. A concept of `r : α → β → Prop` is a pair of sets `s`, `t` such that `s` is the set of all elements that are `r`-related to all of `t` and `t` is the set of all elements that are `r`-related to all of `s`. -/ structure Concept extends Set α × Set β where /-- The axiom of a `Concept` stating that the closure of the first set is the second set. -/ closure_fst : intentClosure r fst = snd /-- The axiom of a `Concept` stating that the closure of the second set is the first set. -/ closure_snd : extentClosure r snd = fst #align concept Concept initialize_simps_projections Concept (+toProd, -fst, -snd) namespace Concept variable {r α β} {c d : Concept α β r} attribute [simp] closure_fst closure_snd @[ext] theorem ext (h : c.fst = d.fst) : c = d := by obtain ⟨⟨s₁, t₁⟩, h₁, _⟩ := c obtain ⟨⟨s₂, t₂⟩, h₂, _⟩ := d dsimp at h₁ h₂ h substs h h₁ h₂ rfl #align concept.ext Concept.ext theorem ext' (h : c.snd = d.snd) : c = d := by obtain ⟨⟨s₁, t₁⟩, _, h₁⟩ := c obtain ⟨⟨s₂, t₂⟩, _, h₂⟩ := d dsimp at h₁ h₂ h substs h h₁ h₂ rfl #align concept.ext' Concept.ext' theorem fst_injective : Injective fun c : Concept α β r => c.fst := fun _ _ => ext #align concept.fst_injective Concept.fst_injective theorem snd_injective : Injective fun c : Concept α β r => c.snd := fun _ _ => ext' #align concept.snd_injective Concept.snd_injective instance : Sup (Concept α β r) := ⟨fun c d => { fst := extentClosure r (c.snd ∩ d.snd) snd := c.snd ∩ d.snd closure_fst := by rw [← c.closure_fst, ← d.closure_fst, ← intentClosure_union, intentClosure_extentClosure_intentClosure] closure_snd := rfl }⟩ instance : Inf (Concept α β r) := ⟨fun c d => { fst := c.fst ∩ d.fst snd := intentClosure r (c.fst ∩ d.fst) closure_fst := rfl closure_snd := by rw [← c.closure_snd, ← d.closure_snd, ← extentClosure_union, extentClosure_intentClosure_extentClosure] }⟩ instance : SemilatticeInf (Concept α β r) := (fst_injective.semilatticeInf _) fun _ _ => rfl @[simp] theorem fst_subset_fst_iff : c.fst ⊆ d.fst ↔ c ≤ d := Iff.rfl #align concept.fst_subset_fst_iff Concept.fst_subset_fst_iff @[simp] theorem fst_ssubset_fst_iff : c.fst ⊂ d.fst ↔ c < d := Iff.rfl #align concept.fst_ssubset_fst_iff Concept.fst_ssubset_fst_iff @[simp] theorem snd_subset_snd_iff : c.snd ⊆ d.snd ↔ d ≤ c := by refine' ⟨fun h => _, fun h => _⟩ · rw [← fst_subset_fst_iff, ← c.closure_snd, ← d.closure_snd] exact extentClosure_anti _ h · rw [← c.closure_fst, ← d.closure_fst] exact intentClosure_anti _ h #align concept.snd_subset_snd_iff Concept.snd_subset_snd_iff @[simp] theorem snd_ssubset_snd_iff : c.snd ⊂ d.snd ↔ d < c := by rw [ssubset_iff_subset_not_subset, lt_iff_le_not_le, snd_subset_snd_iff, snd_subset_snd_iff] #align concept.snd_ssubset_snd_iff Concept.snd_ssubset_snd_iff theorem strictMono_fst : StrictMono (Prod.fst ∘ toProd : Concept α β r → Set α) := fun _ _ => fst_ssubset_fst_iff.2 #align concept.strict_mono_fst Concept.strictMono_fst theorem strictAnti_snd : StrictAnti (Prod.snd ∘ toProd : Concept α β r → Set β) := fun _ _ => snd_ssubset_snd_iff.2 #align concept.strict_anti_snd Concept.strictAnti_snd instance : Lattice (Concept α β r) := { Concept.instSemilatticeInfConcept with sup := (· ⊔ ·) le_sup_left := fun c d => snd_subset_snd_iff.1 <| inter_subset_left _ _ le_sup_right := fun c d => snd_subset_snd_iff.1 <| inter_subset_right _ _ sup_le := fun c d e => by simp_rw [← snd_subset_snd_iff] exact subset_inter } instance : BoundedOrder (Concept α β r) where top := ⟨⟨univ, intentClosure r univ⟩, rfl, eq_univ_of_forall fun _ _ hb => hb trivial⟩ le_top _ := subset_univ _ bot := ⟨⟨extentClosure r univ, univ⟩, eq_univ_of_forall fun _ _ ha => ha trivial, rfl⟩ bot_le _ := snd_subset_snd_iff.1 <| subset_univ _ instance : SupSet (Concept α β r) := ⟨fun S => { fst := extentClosure r (⋂ c ∈ S, (c : Concept _ _ _).snd) snd := ⋂ c ∈ S, (c : Concept _ _ _).snd closure_fst := by simp_rw [← closure_fst, ← intentClosure_unionᵢ₂, intentClosure_extentClosure_intentClosure] closure_snd := rfl }⟩ instance : InfSet (Concept α β r) := ⟨fun S => { fst := ⋂ c ∈ S, (c : Concept _ _ _).fst snd := intentClosure r (⋂ c ∈ S, (c : Concept _ _ _).fst) closure_fst := rfl closure_snd := by simp_rw [← closure_snd, ← extentClosure_Union₂, extentClosure_intentClosure_extentClosure] }⟩ instance : CompleteLattice (Concept α β r) := { Concept.instLatticeConcept, Concept.instBoundedOrderConceptToLEToPreorderToPartialOrderInstSemilatticeInfConcept with sup := Concept.instSupConcept.sup le_supₛ := fun _ _ hc => snd_subset_snd_iff.1 <| binterᵢ_subset_of_mem hc supₛ_le := fun _ _ hc => snd_subset_snd_iff.1 <| subset_interᵢ₂ fun d hd => snd_subset_snd_iff.2 <| hc d hd inf := Concept.instInfConcept.inf infₛ_le := fun _ _ => binterᵢ_subset_of_mem le_infₛ := fun _ _ => subset_interᵢ₂ } @[simp] theorem top_fst : (⊤ : Concept α β r).fst = univ := rfl #align concept.top_fst Concept.top_fst @[simp] theorem top_snd : (⊤ : Concept α β r).snd = intentClosure r univ := rfl #align concept.top_snd Concept.top_snd @[simp] theorem bot_fst : (⊥ : Concept α β r).fst = extentClosure r univ := rfl #align concept.bot_fst Concept.bot_fst @[simp] theorem bot_snd : (⊥ : Concept α β r).snd = univ := rfl #align concept.bot_snd Concept.bot_snd @[simp] theorem sup_fst (c d : Concept α β r) : (c ⊔ d).fst = extentClosure r (c.snd ∩ d.snd) := rfl #align concept.sup_fst Concept.sup_fst @[simp] theorem sup_snd (c d : Concept α β r) : (c ⊔ d).snd = c.snd ∩ d.snd := rfl #align concept.sup_snd Concept.sup_snd @[simp] theorem inf_fst (c d : Concept α β r) : (c ⊓ d).fst = c.fst ∩ d.fst := rfl #align concept.inf_fst Concept.inf_fst @[simp] theorem inf_snd (c d : Concept α β r) : (c ⊓ d).snd = intentClosure r (c.fst ∩ d.fst) := rfl #align concept.inf_snd Concept.inf_snd @[simp] theorem supₛ_fst (S : Set (Concept α β r)) : (supₛ S).fst = extentClosure r (⋂ c ∈ S, (c : Concept _ _ _).snd) := rfl #align concept.Sup_fst Concept.supₛ_fst @[simp] theorem supₛ_snd (S : Set (Concept α β r)) : (supₛ S).snd = ⋂ c ∈ S, (c : Concept _ _ _).snd := rfl #align concept.Sup_snd Concept.supₛ_snd @[simp] theorem infₛ_fst (S : Set (Concept α β r)) : (infₛ S).fst = ⋂ c ∈ S, (c : Concept _ _ _).fst := rfl #align concept.Inf_fst Concept.infₛ_fst @[simp] theorem infₛ_snd (S : Set (Concept α β r)) : (infₛ S).snd = intentClosure r (⋂ c ∈ S, (c : Concept _ _ _).fst) := rfl #align concept.Inf_snd Concept.infₛ_snd instance : Inhabited (Concept α β r) := ⟨⊥⟩ /-- Swap the sets of a concept to make it a concept of the dual context. -/ @[simps] def swap (c : Concept α β r) : Concept β α (swap r) := ⟨c.toProd.swap, c.closure_snd, c.closure_fst⟩ #align concept.swap Concept.swap #align concept.swap_to_prod Concept.swap_toProd @[simp] theorem swap_swap (c : Concept α β r) : c.swap.swap = c := ext rfl #align concept.swap_swap Concept.swap_swap @[simp] theorem swap_le_swap_iff : c.swap ≤ d.swap ↔ d ≤ c := snd_subset_snd_iff #align concept.swap_le_swap_iff Concept.swap_le_swap_iff @[simp] theorem swap_lt_swap_iff : c.swap < d.swap ↔ d < c := snd_ssubset_snd_iff #align concept.swap_lt_swap_iff Concept.swap_lt_swap_iff /-- The dual of a concept lattice is isomorphic to the concept lattice of the dual context. -/ @[simps] def swapEquiv : (Concept α β r)ᵒᵈ ≃o Concept β α (Function.swap r) where toFun := swap ∘ ofDual invFun := toDual ∘ swap left_inv := swap_swap right_inv := swap_swap map_rel_iff' := swap_le_swap_iff #align concept.swap_equiv Concept.swapEquiv #align concept.swap_equiv_symm_apply Concept.swapEquiv_symm_apply #align concept.swap_equiv_apply Concept.swapEquiv_apply end Concept
module Data.Cotree import Data.Colist import Data.Maybe import Data.Tree %default total -------------------------------------------------------------------------------- -- Cotrees: Potentially infinte trees -------------------------------------------------------------------------------- mutual ||| A potentially infinite rose tree public export record Cotree (a : Type) where constructor MkCotree value : a forest : Inf (Coforest a) ||| A potentially finit stream of trees public export Coforest : Type -> Type Coforest = Colist . Cotree public export singleton : a -> Cotree a singleton a = MkCotree a Nil public export unfold : (f : b -> (a,Colist b)) -> b -> Cotree a unfold f vb = let (va,bs) = f vb in MkCotree va $ unfoldF bs where unfoldF : Colist b -> Coforest a unfoldF [] = [] unfoldF (h :: t) = unfold f h :: unfoldF t public export iterate : (f : a -> Colist a) -> a -> Cotree a iterate f a = unfold (\v => (v, f v)) a public export expand : (a -> Colist a) -> Cotree a -> Cotree a expand f (MkCotree v vs) = let MkCotree v2 vs2 = iterate f v in MkCotree v2 (run vs vs2) where run : Coforest a -> Coforest a -> Coforest a run [] ys = ys run (x :: xs) ys = expand f x :: run xs ys -------------------------------------------------------------------------------- -- To and from Tree -------------------------------------------------------------------------------- public export fromTree : Tree a -> Cotree a fromTree (MkTree v fo) = MkCotree v (fromForest fo) where fromForest : Forest a -> Coforest a fromForest [] = [] fromForest (x :: xs) = fromTree x :: fromForest xs ||| Converts a Cotree to a tree of the given maximum depth and width. ||| The maximum numbers of elements in the tree will be ||| maxWidth ^ maxDepth. public export toTree : (maxDepth : Nat) -> (maxWidth : Nat) -> Cotree a -> Tree a toTree 0 _ (MkCotree v fo) = MkTree v [] toTree (S k) mw (MkCotree v fo) = MkTree v (toForest mw fo) where toForest : Nat -> Coforest a -> Forest a toForest 0 _ = [] toForest (S n) [] = [] toForest (S n) (t :: ts) = toTree k mw t :: toForest n ts -------------------------------------------------------------------------------- -- Functor and Applicative -------------------------------------------------------------------------------- public export mapCotree : (a -> b) -> Cotree a -> Cotree b mapCotree f (MkCotree v vs) = MkCotree (f v) (mapForest vs) where mapForest : Coforest a -> Coforest b mapForest [] = [] mapForest (h :: t) = mapCotree f h :: mapForest t public export interleave : Cotree (a -> b) -> Cotree a -> Cotree b interleave tf@(MkCotree vf fs) ta@(MkCotree va as) = MkCotree (vf va) (interleaveFs fs) where interleaveAs : Coforest a -> Coforest b interleaveAs [] = [] interleaveAs (h :: t) = interleave tf h :: interleaveAs t interleaveFs : Coforest (a -> b) -> Coforest b interleaveFs [] = interleaveAs as interleaveFs (h :: t) = interleave h ta :: interleaveFs t public export bind : Cotree a -> (a -> Cotree b) -> Cotree b bind (MkCotree v vs) f = let MkCotree w ws = f v in MkCotree w (run vs ws) where run : Coforest a -> Coforest b -> Coforest b run [] ys = ys run (x :: xs) ys = bind x f :: run xs ys public export bindMaybe : Cotree (Maybe a) -> (a -> Cotree (Maybe b)) -> Cotree (Maybe b) bindMaybe (MkCotree mv tas) f = case map f mv of Nothing => MkCotree Nothing (run tas Nil) Just (MkCotree mb tbs) => MkCotree mb (run tas tbs) where run : Coforest (Maybe a) -> Coforest (Maybe b) -> Coforest (Maybe b) run [] ys = ys run (x :: xs) ys = bindMaybe x f :: run xs ys -------------------------------------------------------------------------------- -- Shrinking -------------------------------------------------------------------------------- public export shrink : (maxSteps : Nat) -> Cotree (Maybe a) -> List a shrink maxSteps x = run maxSteps [x] where run : Nat -> Coforest (Maybe a) -> List a run _ Nil = Nil run 0 _ = Nil run (S k) (h :: t) = case h.value of Just a => a :: run k h.forest Nothing => run k t public export mapShrink : (maxSteps : Nat) -> (a -> Maybe b) -> Cotree a -> List b mapShrink ms f = shrink ms . mapCotree f public export shrinkIf : (maxSteps : Nat) -> (a -> Bool) -> Cotree a -> List a shrinkIf ms p = mapShrink ms (\a => if p a then Just a else Nothing) ||| Prunes a cotree up to the given depth and width. public export pruneTo : (width : Nat) -> (depth : Nat) -> Cotree a -> Cotree a pruneTo _ 0 (MkCotree v _ ) = MkCotree v Nil pruneTo w (S d) (MkCotree v vs) = MkCotree v $ (map (pruneTo w d) $ keep w vs) where keep : Nat -> Colist t -> Colist t keep _ [] = [] keep 0 _ = [] keep (S k) (x :: xs) = x :: keep k xs ||| Removes all children from a cotree public export prune : Cotree a -> Cotree a prune = pruneTo 0 0 -------------------------------------------------------------------------------- -- Interfaces -------------------------------------------------------------------------------- public export Functor Cotree where map = mapCotree public export Applicative Cotree where pure = singleton (<*>) = interleave -------------------------------------------------------------------------------- -- Filtering -------------------------------------------------------------------------------- public export takeUntil : (a -> Bool) -> Cotree a -> Cotree a takeUntil f (MkCotree v vs) = if f v then MkCotree v [] else MkCotree v (takeUntilF vs) where takeUntilF : Coforest a -> Coforest a takeUntilF [] = vs takeUntilF (MkCotree x xs :: ts) = if f x then [MkCotree x []] else MkCotree x (takeUntilF xs) :: takeUntilF ts public export takeBeforeNothing : Cotree (Maybe a) -> Maybe (Cotree a) takeBeforeNothing (MkCotree Nothing _) = Nothing takeBeforeNothing (MkCotree (Just v) vs) = Just (MkCotree v (run vs)) where run : Coforest (Maybe a) -> Coforest a run [] = [] run ((MkCotree Nothing _) :: _) = [] run ((MkCotree (Just v) vs) :: ts) = MkCotree v (run vs) :: run ts public export takeBefore : (a -> Bool) -> Cotree a -> Maybe (Cotree a) takeBefore f = takeBeforeNothing . map (\a => toMaybe (f a) a) public export %inline takeWhile : (a -> Bool) -> Cotree a -> Maybe (Cotree a) takeWhile f = takeBefore (not . f) public export %inline mapMaybe : (a -> Maybe b) -> Cotree a -> Maybe (Cotree b) mapMaybe f = takeBeforeNothing . map f
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Ejemplo: Ecuacion de Poisson 1D pero resuelto con FEniCS -d2u/dx2 = 1 0 < x < 1 u(0) = 0 y u(1) = 0 en los bordes. """ from __future__ import print_function from fenics import * # Defino la malla nx = 5 #numero de intervalos minx, maxx = 0.0, 1.0 mesh = IntervalMesh(nx, minx, maxx)#malla en 1D V = FunctionSpace(mesh, 'P',1)#Lagrange Finite Element # Defino las condiciones de borde def borde_D(x, on_boundary): #retorna un boolean tol = 1.E-14 return on_boundary and near(x[0], 1., tol) def borde_I(x, on_boundary): tol = 1.E-14 return on_boundary and near(x[0], 0., tol) bc_der = DirichletBC(V, Constant(0.0), borde_D) bc_iz = DirichletBC(V, Constant(0.0), borde_I) bc = [bc_iz, bc_der] # Comienzo la formulacion variacional u = TrialFunction(V) v = TestFunction(V) f = Constant(1.0) #Definicion abstracta a = dot(grad(u), grad(v))*dx #o inner L = f*v*dx # Resuelvo u = Function(V) solve(a == L, u, bc) print('Tipo de variable:',type(u)) import matplotlib.pyplot as plt #Extraigo los datos de la solucion u. uh = u.compute_vertex_values(mesh) print('Cantidad de celdas:',nx) print('Cantidad de vertices:',len(uh)) fig, axs = plt.subplots(1,1) import numpy as np xu = np.linspace(0.0, 1.0, len(uh),endpoint = True) axs.plot(xu,uh,'ro',markersize=10) #Comparo con solucion exacta xe = np.arange(0.0,1.0,0.001) ue = -0.5*xe*(xe-1.) axs.plot(xe,ue,'b') ##Tambien se puede calcular en los mismos puntos que uh (para calcular errores) class Resultado(UserExpression): def eval(self, values, x): values[0] = -0.5*x[0]*(x[0]-1.0) u_D = Resultado(degree=1) u_De = u_D.compute_vertex_values(mesh) ##error_max = np.max(np.abs(u_De - uh)) # Calcula el error en la norma L2 error_L2 = errornorm(u_D, u, 'L2') ##print('Error maximo:',error_max) print('Error en L2:',error_L2) axs.plot(xu,u_De,'.b',markersize=10) plt.title('Soluciones comparadas') plt.show()
175 meters from Malmö Central Station is where our ne centre Epic will open in 2019. Conveniently located with proximity to major bus, train and airport links. The centre is only a short walk away from the pulse of Lilla Torg with its variety of restaurants. Close by is Malmö Live with culture, entertainment , shopping and night life on your door step.
\name{metro.areas} \alias{metro.areas} \docType{data} \title{ %% ~~ data name/kind ... ~~ } \description{ %% ~~ A concise (1-5 lines) description of the dataset. ~~ } \usage{data("metro.areas")} \format{ A data frame with 366 observations on the following 5 variables. \describe{ \item{\code{metro_area}}{a character vector} \item{\code{mun_population_2010}}{a numeric vector} \item{\code{metro_population_2010}}{a numeric vector} \item{\code{state_code}}{a numeric vector} \item{\code{mun_code}}{a numeric vector} } } \details{ %% ~~ If necessary, more details than the __description__ above ~~ } \source{ %% ~~ reference to a publication or URL from which the data were obtained ~~ } \references{ %% ~~ possibly secondary sources and usages ~~ } \examples{ data(metro.areas) ## maybe str(metro.areas) ; plot(metro.areas) ... } \keyword{datasets}
import sys import math import numpy as np from src.GMLA import gmla from src.PTVA import ptva from src.load import load from src.infect import infect_graph from src.color_nodes import coloring from src import accuracy as acc def main(): ## Handle inputs if len(sys.argv)<3: print("Please pass the algo and dataset name...") return algo = str(sys.argv[1]).lower() title = sys.argv[2] ## Load graph G, _ = load(title) ## Infect graph G, arrivalTime, sourceNodes = infect_graph(G, title=title) ## Take observers k0 = math.ceil(math.sqrt(len(G))) np.random.seed(23) observers = np.random.choice(len(G),k0, replace=False).tolist() ## mean and variance t=[] for i in observers: if(arrivalTime[i]!=-1): t.append(arrivalTime[i]) mn = np.mean(t) sigma2 = np.var(t) ## assigning time attr to each node. for i in range(0, k0): G.nodes[observers[i]]['time'] = t[i] ## Run algos score = [] if algo == 'ptva': score = ptva.PTVA(G, observers, k0, sigma2, mn) elif algo == 'gmla': score = gmla.GMLA(G, observers, k0, sigma2, mn) else: print("Error: Enter the correct algo name") return scoreList = [score[i][0] for i in range(5)] nodes = [list(a)[0] for a in G.nodes(data=True)] coloring(title, G, nodes, scoreList, observers, algo) print() print(f'Sources : {sourceNodes}') print(f'Predicted : {scoreList}') print(f'accuracy : {acc.accuracy(sourceNodes,scoreList)} %') if __name__ == '__main__': main()
function a = double(t) %DOUBLE Convert tenmat to double array. % % See also TENMAT. % %MATLAB Tensor Toolbox. %Copyright 2012, Sandia Corporation. % This is the MATLAB Tensor Toolbox by T. Kolda, B. Bader, and others. % http://www.sandia.gov/~tgkolda/TensorToolbox. % Copyright (2012) Sandia Corporation. Under the terms of Contract % DE-AC04-94AL85000, there is a non-exclusive license for use of this % work by or on behalf of the U.S. Government. Export of this data may % require a license from the United States Government. % The full license terms can be found in the file LICENSE.txt a = t.data;
% Wrapper for vl_nnlogScale2Scale block % inputs{1} : s : 1 x 1 x 1 x b % outputs{1}: y : 1 x 1 x 1 x b classdef logScale2Scale < dagnn.Layer methods function outputs = forward(~, inputs, ~) useGPU = isa(inputs{1}, 'gpuArray'); if useGPU outputs{1} = gpuArray( vl_nnlogScale2Scale(gather(inputs{1})) ); else outputs{1} = vl_nnlogScale2Scale(inputs{1}); end end function [derInputs, derParams] = backward(~, inputs, ~, derOutputs) useGPU = isa(inputs{1}, 'gpuArray'); if useGPU derInputs{1} = gpuArray( vl_nnlogScale2Scale(gather(inputs{1}), gather(derOutputs{1})) ); else derInputs{1} = vl_nnlogScale2Scale(inputs{1}, derOutputs{1}); end derParams = {}; end function outputSizes = getOutputSizes(~, inputSizes) outputSizes = inputSizes{1}; end function obj = logScale2Scale(varargin) obj.load(varargin); end end end
Dave Wittmann Insurance and Financial Agency provides insurance for businesses using specialized truck equipment in Little Chute, Appleton, Kaukauna, Kimberly, Neenah, Wrightstown, and surrounding areas. Whether you repair, distribute, or manufacture specialized truck equipment, you will need a versatile insurance plan to match the services offered by your business. Dave Wittmann Insurance and Financial Agency will provide you with the attention to detail required to come up with a unique protection plan for you and your business. We understand the intricacies of specialized truck equipment industry. Contact Dave Wittmann Insurance and Financial Agency today. Our representatives are here to help you build an insurance bundle that’s right for your business.
/* * BRAINS * (B)LR (R)everberation-mapping (A)nalysis (I)n AGNs with (N)ested (S)ampling * Yan-Rong Li, [email protected] * Thu, Aug 4, 2016 */ /*! * \file reconstruct_line2d.c * \brief reconstruct 2d line and BLR model. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <float.h> #include <gsl/gsl_interp.h> #include "brains.h" void *best_model_line2d; /*!< best model */ void *best_model_std_line2d; /*!< standard deviation of the best model */ /*! * postprocessing. */ void postprocess2d() { char posterior_sample_file[BRAINS_MAX_STR_LENGTH]; int num_ps, i, j, k, nc; double *pm, *pmstd; double *lag; void *posterior_sample, *post_model; double mean_lag, mean_lag_std, sum1, sum2; int size_of_modeltype = num_params * sizeof(double); best_model_line2d = malloc(size_of_modeltype); best_model_std_line2d = malloc(size_of_modeltype); if(thistask == roottask) { // initialize smoothing workspace smooth_init(n_vel_data_ext, Vline_data_ext); char fname[200]; FILE *fp, *fcon, *fline, *ftran, *fline1d; double *Fline1d, dV; // velocity grid width, in term of wavelength of Hbeta. dV = (Vline_data[n_vel_data-1]-Vline_data[0])/(n_vel_data-1) * parset.linecenter/C_Unit; Fline1d = malloc(n_line_data * sizeof(double)); // get number of lines in posterior sample file get_posterior_sample_file(dnest_options_file, posterior_sample_file); //file for posterior sample fp = fopen(posterior_sample_file, "r"); if(fp == NULL) { fprintf(stderr, "# Error: Cannot open file %s.\n", posterior_sample_file); exit(0); } //file for continuum reconstruction sprintf(fname, "%s/%s", parset.file_dir, "data/con_rec.txt"); fcon = fopen(fname, "w"); if(fcon == NULL) { fprintf(stderr, "# Error: Cannot open file %s.\n", fname); exit(0); } //file for line reconstruction sprintf(fname, "%s/%s", parset.file_dir, "data/line2d_rec.txt"); fline = fopen(fname, "w"); if(fline == NULL) { fprintf(stderr, "# Error: Cannot open file %s.\n", fname); exit(0); } //file for line reconstruction sprintf(fname, "%s/%s", parset.file_dir, "data/line_rec.txt"); fline1d = fopen(fname, "w"); if(fline1d == NULL) { fprintf(stderr, "# Error: Cannot open file %s.\n", fname); exit(0); } //file for transfer function sprintf(fname, "%s/%s", parset.file_dir, "data/tran2d_rec.txt"); ftran = fopen(fname, "w"); if(ftran == NULL) { fprintf(stderr, "# Error: Cannot open file %s.\n", fname); exit(0); } // read number of lines if(fscanf(fp, "# %d", &num_ps) < 1) { fprintf(stderr, "# Error: Cannot read file %s.\n", posterior_sample_file); exit(0); } printf("# Number of points in posterior sample: %d\n", num_ps); lag = malloc(num_ps * sizeof(double)); post_model = malloc(size_of_modeltype); posterior_sample = malloc(num_ps * size_of_modeltype); force_update = 1; which_parameter_update = -1; // force to update the transfer function which_particle_update = 0; mean_lag = 0.0; nc = 0; Fcon_rm = Fcon_rm_particles[which_particle_update]; TransTau = TransTau_particles[which_particle_update]; Trans2D_at_veldata = Trans2D_at_veldata_particles[which_particle_update]; Fline2d_at_data = Fline_at_data_particles[which_particle_update]; for(i=0; i<num_ps; i++) { // read lines for(j=0; j<num_params; j++) { if(fscanf(fp, "%lf", (double *)post_model + j) < 1) { fprintf(stderr, "# Error: Cannot read file %s.\n", posterior_sample_file); exit(0); } } fscanf(fp, "\n"); //store model memcpy(posterior_sample+i*size_of_modeltype, post_model, size_of_modeltype); //calculate_con_from_model(post_model + num_params_blr *sizeof(double)); calculate_con_from_model_semiseparable(post_model + num_params_blr *sizeof(double)); calculate_con_rm(post_model); gsl_interp_init(gsl_linear, Tcon, Fcon_rm, parset.n_con_recon); transfun_2d_cal(post_model, Vline_data_ext, Trans2D_at_veldata, n_vel_data_ext, 0); calculate_line2d_from_blrmodel(post_model, Tline_data, Vline_data_ext, Trans2D_at_veldata, Fline2d_at_data, n_line_data, n_vel_data_ext); // calculate integrated line fluxes for(j = 0; j < n_line_data; j++) { Fline1d[j] = 0.0; for(k=0; k<n_vel_data; k++) { Fline1d[j] += Fline2d_at_data[j * n_vel_data_ext + (k+n_vel_data_incr)] * dV /line_scale; } } // calculate mean time lag sum1 = 0.0; sum2 = 0.0; for(j=0; j<parset.n_tau; j++) { for(k=0; k<n_vel_data_ext; k++) { sum1 += Trans2D_at_veldata[j * n_vel_data_ext + k] * TransTau[j]; sum2 += Trans2D_at_veldata[j * n_vel_data_ext + k]; } } // take care of zero transfer function if(sum2 > 0.0) { lag[i] = sum1/sum2; mean_lag += lag[i]; nc++; } else { lag[i] = -DBL_MAX; } //if( i % (num_ps/10+1) == 0) { // output continuum for(j=0; j<parset.n_con_recon; j++) { fprintf(fcon, "%e %e\n", Tcon[j]*(1.0+parset.redshift), Fcon[j]/con_scale); } fprintf(fcon, "\n"); // output 2d line for(j=0; j<n_line_data; j++) { for(k=0; k<n_vel_data; k++) { fprintf(fline, "%e ", Fline2d_at_data[j * n_vel_data_ext + (k+n_vel_data_incr)]/line_scale); } fprintf(fline, "\n"); } fprintf(fline, "\n"); // output transfer function for(j=0; j<parset.n_tau; j++) { fprintf(ftran, "%e ", TransTau[j]); for(k=0; k<n_vel_data; k++) { fprintf(ftran, "%e ", Trans2D_at_veldata[j * n_vel_data_ext + (k+n_vel_data_incr)]); } fprintf(ftran, "\n"); } fprintf(ftran, "\n"); // output 1d line for(j = 0; j<n_line_data; j++) { fprintf(fline1d, "%e %e\n", Tline_data[j]*(1.0+parset.redshift), Fline1d[j]); } fprintf(fline1d, "\n"); } } smooth_end(); fclose(fp); fclose(fcon); fclose(fline); fclose(ftran); fclose(fline1d); /* calculate mean lags */ mean_lag /= (nc); mean_lag_std = 0.0; for(i=0; i<num_ps; i++) { if(lag[i] > -DBL_MAX) mean_lag_std += (lag[i] - mean_lag) * (lag[i] - mean_lag); } if(nc > 1) mean_lag_std = sqrt(mean_lag_std/(nc -1.0)); else mean_lag_std = 0.0; printf("Mean time lag: %f+-%f\n", mean_lag, mean_lag_std); pm = (double *)best_model_line2d; pmstd = (double *)best_model_std_line2d; for(j=0; j<num_params; j++) { pm[j] = pmstd[j] = 0.0; } for(i=0; i<num_ps; i++) { for(j =0; j<num_params; j++) pm[j] += *((double *)posterior_sample + i*num_params + j ); } for(j=0; j<num_params; j++) pm[j] /= num_ps; for(i=0; i<num_ps; i++) { for(j=0; j<num_params; j++) pmstd[j] += pow( *((double *)posterior_sample + i*num_params + j ) - pm[j], 2.0 ); } for(j=0; j<num_params; j++) { if(num_ps > 1) pmstd[j] = sqrt(pmstd[j]/(num_ps-1.0)); else pmstd[j] = 0.0; } for(j = 0; j<num_params_blr + num_params_var; j++) printf("Best params %d %f +- %f\n", j, *((double *)best_model_line2d + j), *((double *)best_model_std_line2d+j) ); free(lag); free(post_model); free(posterior_sample); free(Fline1d); } return; } /*! * this function run dnest sampleing, reconstruct light curves using the best estimates for parameters. */ void reconstruct_line2d() { int i, argc=0; char **argv; //configure restart of dnest argv = malloc(9*sizeof(char *)); for(i=0; i<9; i++) { argv[i] = malloc(BRAINS_MAX_STR_LENGTH*sizeof(char)); } //setup argc and argv strcpy(argv[argc++], "dnest"); strcpy(argv[argc++], "-s"); strcpy(argv[argc], parset.file_dir); strcat(argv[argc++], "/data/restart2d_dnest.txt"); if(parset.flag_restart == 1) { strcpy(argv[argc++], "-r"); strcpy(argv[argc], parset.file_dir); strcat(argv[argc], "/"); strcat(argv[argc++], "data/restart2d_dnest.txt"); } if(parset.flag_postprc == 1) { strcpy(argv[argc++], "-p"); } if(parset.flag_temp == 1) { sprintf(argv[argc++], "-t%f", parset.temperature); } if(parset.flag_sample_info == 1) { strcpy(argv[argc++], "-c"); } //level-dependent sampling { strcpy(argv[argc++], "-l"); } reconstruct_line2d_init(); smooth_init(n_vel_data_ext, Vline_data_ext); dnest_line2d(argc, argv); smooth_end(); if(parset.flag_exam_prior != 1 && parset.flag_para_name != 1) { postprocess2d(); // calculate light curves using the best model if(thistask == roottask) { force_update = 1; which_parameter_update = -1; which_particle_update = 0; Fcon_rm = Fcon_rm_particles[which_particle_update]; TransTau = TransTau_particles[which_particle_update]; Trans2D_at_veldata = Trans2D_at_veldata_particles[which_particle_update]; Fline2d_at_data = Fline_at_data_particles[which_particle_update]; //calculate_con_from_model(best_model_line2d + num_params_blr *sizeof(double)); calculate_con_from_model_semiseparable(best_model_line2d + num_params_blr *sizeof(double)); calculate_con_rm(best_model_line2d); gsl_interp_init(gsl_linear, Tcon, Fcon_rm, parset.n_con_recon); FILE *fp; char fname[200]; int i, j; sprintf(fname, "%s/%s", parset.file_dir, parset.pcon_out_file); fp = fopen(fname, "w"); if(fp == NULL) { fprintf(stderr, "# Error: Cannot open file %s\n", fname); exit(-1); } for(i=0; i<parset.n_con_recon; i++) { fprintf(fp, "%e %e %e\n", Tcon[i]*(1.0+parset.redshift), Fcon[i] / con_scale, Fcerrs[i] / con_scale); } fclose(fp); smooth_init(n_vel_data_ext, Vline_data_ext); // recovered line2d at data points transfun_2d_cal(best_model_line2d, Vline_data_ext, Trans2D_at_veldata, n_vel_data_ext, parset.flag_save_clouds); calculate_line2d_from_blrmodel(best_model_line2d, Tline_data, Vline_data_ext, Trans2D_at_veldata, Fline2d_at_data, n_line_data, n_vel_data_ext); sprintf(fname, "%s/%s", parset.file_dir, parset.pline2d_data_out_file); fp = fopen(fname, "w"); if(fp == NULL) { fprintf(stderr, "# Error: Cannot open file %s\n", fname); exit(-1); } fprintf(fp, "# %d %d\n", n_line_data, n_vel_data); for(i=0; i<n_line_data; i++) { fprintf(fp, "# %f\n", Tline_data[i]*(1.0+parset.redshift)); for(j=0; j<n_vel_data; j++) { fprintf(fp, "%e %e\n", Wline_data[j], Fline2d_at_data[i*n_vel_data_ext + (j+n_vel_data_incr)] / line_scale); } fprintf(fp, "\n"); } fclose(fp); sprintf(fname, "%s/%s", parset.file_dir, parset.tran2d_data_out_file); fp = fopen(fname, "w"); if(fp == NULL) { fprintf(stderr, "# Error: Cannot open file %s\n", fname); exit(-1); } fprintf(fp, "# %d %d\n", parset.n_tau, n_vel_data); for(i=0; i<parset.n_tau; i++) { fprintf(fp, "# %f\n", TransTau[i]); for(j=0; j<n_vel_data; j++) { fprintf(fp, "%e %e\n", Vline_data[j], Trans2D_at_veldata[i*n_vel_data_ext + (j+n_vel_data_incr)]); } fprintf(fp, "\n"); } fclose(fp); smooth_end(); // recovered line2d at specified points smooth_init(parset.n_vel_recon, TransV); which_parameter_update = -1; which_particle_update = 0; transfun_2d_cal(best_model_line2d, TransV, Trans2D, parset.n_vel_recon, 0); /* there is no data for spectral broadening at given specified epoch, using the mean value * and set InstRes_err=0.0. */ double *pm = (double *)best_model_line2d; if(parset.flag_InstRes > 0) { parset.flag_InstRes = 0; /* force to be uniform prior */ double instres_mean = 0.0; for(i=0; i<n_line_data; i++) { instres_mean += instres_epoch[i]; } parset.InstRes = instres_mean/n_line_data; parset.InstRes_err = 0.0; instres_mean = 0.0; for(i=0; i<n_line_data; i++) { instres_mean += pm[num_params_blr_model+num_params_nlr+i]; } pm[num_params_blr_model + num_params_nlr ] = instres_mean/n_line_data; } /* similarly, there is no data for line center information at given specified epoch, * using the mean value */ if(parset.flag_linecenter < 0) { parset.flag_linecenter = 1; /* force to be uniform prior, note num_params_linecenter is still unchanged */ double linecenter_mean = 0.0; for(i=0; i<n_line_data; i++) { linecenter_mean += pm[idx_linecenter + i]; } pm[idx_linecenter] = linecenter_mean/n_line_data; } calculate_line2d_from_blrmodel(best_model_line2d, Tline, TransV, Trans2D, Fline2d, parset.n_line_recon, parset.n_vel_recon); sprintf(fname, "%s/%s", parset.file_dir, parset.pline2d_out_file); fp = fopen(fname, "w"); if(fp == NULL) { fprintf(stderr, "# Error: Cannot open file %s\n", fname); exit(-1); } fprintf(fp, "# %d %d\n", parset.n_line_recon, parset.n_vel_recon); for(i=0; i<parset.n_line_recon; i++) { fprintf(fp, "# %f\n", Tline[i]*(1.0+parset.redshift)); for(j=0; j<parset.n_vel_recon; j++) { fprintf(fp, "%e %e\n", (1.0 + TransV[j]/C_Unit) * parset.linecenter * (1.0+parset.redshift), Fline2d[i*parset.n_vel_recon + j] / line_scale); } fprintf(fp, "\n"); } fclose(fp); // output 2d transfer function sprintf(fname, "%s/%s", parset.file_dir, parset.tran2d_out_file); fp = fopen(fname, "w"); if(fp == NULL) { fprintf(stderr, "# Error: Cannot open file %s\n", fname); exit(-1); } fprintf(fp, "# %d %d\n", parset.n_tau, parset.n_vel_recon); for(i=0; i<parset.n_tau; i++) { fprintf(fp, "# %f\n", TransTau[i]); for(j=0; j<parset.n_vel_recon; j++) { fprintf(fp, "%e %e\n", TransV[j]*VelUnit, Trans2D[i*parset.n_vel_recon + j]); } fprintf(fp, "\n"); } fclose(fp); smooth_end(); } } reconstruct_line2d_end(); //clear up argv for(i=0; i<9; i++) { free(argv[i]); } free(argv); return; } /*! * this function initializes 2d reconstruction. */ void reconstruct_line2d_init() { int i, j; double dT, Tspan; Tspan = Tcon_data[n_con_data -1] - Tcon_data[0]; /* set time grid for continuum */ /*if(parset.time_back > 0.0) Tcon_min = Tcon_data[0] - parset.time_back; else Tcon_min = Tcon_data[0] - fmax(0.05*Tspan, Tspan/2.0 + (Tcon_data[0] - Tline_data[0]));*/ Tcon_min = Tcon_data[0] - time_back_set - 10.0; Tcon_max = Tcon_data[n_con_data-1] + fmax(0.05*Tspan, 20.0); Tcon_max = fmax(Tcon_max, Tline_data[n_line_data -1] + 10.0); /* The time span should cover that of the emission line data */ if(thistask == roottask) printf("Tcon_min_max: %f %f\n", Tcon_min - Tcon_data[0], Tcon_max - Tcon_data[n_con_data-1]); dT = (Tcon_max - Tcon_min)/(parset.n_con_recon -1); for(i=0; i<parset.n_con_recon; i++) { Tcon[i] = Tcon_min + i*dT; } /* set Larr_rec */ for(i=0;i<parset.n_con_recon;i++) { Larr_rec[i*nq + 0]=1.0; for(j=1; j<nq; j++) Larr_rec[i*nq + j] = pow(Tcon[i], j); } //TransTau = malloc(parset.n_tau * sizeof(double)); //Trans2D_at_veldata = malloc(parset.n_tau * n_vel_data * sizeof(double)); TransV = malloc(parset.n_vel_recon * sizeof(double)); Trans2D = malloc(parset.n_tau * parset.n_vel_recon * sizeof(double)); //Fline2d_at_data = malloc(n_line_data * n_vel_data * sizeof(double)); Tline = malloc(parset.n_line_recon * sizeof(double)); Fline2d = malloc(parset.n_line_recon * parset.n_vel_recon * sizeof(double)); Tline_min = Tline_data[0] - fmin(0.1*(Tline_data[n_line_data - 1] - Tline_data[0]), 10.0); if(parset.time_back <= 0.0) Tline_min = fmax(Tline_min, Tcon_min + time_back_set); Tline_max = Tline_data[n_line_data -1] + fmin(0.1*(Tline_data[n_line_data - 1] - Tline_data[0]), 10.0); Tline_max = fmin(Tline_max, Tcon_max - 1.0); /* The time span should be smaller than that of the continuum */ if(thistask == roottask) printf("Tline_min_max: %f %f\n", Tline_min - Tline_data[0], Tline_max - Tline_data[n_line_data -1]); dT = (Tline_max - Tline_min)/(parset.n_line_recon - 1); for(i=0; i<parset.n_line_recon; i++) { Tline[i] = Tline_min + i*dT; } double vel_max_set = Vline_data_ext[n_vel_data_ext -1], vel_min_set = Vline_data_ext[0]; double dVel = (vel_max_set- vel_min_set)/(parset.n_vel_recon -1.0); for(i=0; i<parset.n_vel_recon; i++) { TransV[i] = vel_min_set + dVel*i; } sprintf(dnest_options_file, "%s/%s", parset.file_dir, "src/OPTIONS2D"); if(thistask == roottask) { get_num_particles(dnest_options_file); } MPI_Bcast(&parset.num_particles, 1, MPI_INT, roottask, MPI_COMM_WORLD); Fcon = malloc(parset.n_con_recon * sizeof(double *)); Fcon_rm_particles = malloc(parset.num_particles * sizeof(double *)); Fcon_rm_particles_perturb = malloc(parset.num_particles * sizeof(double *)); for(i=0; i<parset.num_particles; i++) { Fcon_rm_particles[i] = malloc(parset.n_con_recon * sizeof(double)); Fcon_rm_particles_perturb[i] = malloc(parset.n_con_recon * sizeof(double)); } TransTau_particles = malloc(parset.num_particles * sizeof(double *)); TransTau_particles_perturb = malloc(parset.num_particles * sizeof(double *)); for(i=0; i<parset.num_particles; i++) { TransTau_particles[i] = malloc(parset.n_tau * sizeof(double)); TransTau_particles_perturb[i] = malloc(parset.n_tau * sizeof(double)); } Trans2D_at_veldata_particles = malloc(parset.num_particles * sizeof(double *)); Trans2D_at_veldata_particles_perturb = malloc(parset.num_particles * sizeof(double *)); for(i=0; i<parset.num_particles; i++) { Trans2D_at_veldata_particles[i] = malloc(parset.n_tau * n_vel_data_ext * sizeof(double)); Trans2D_at_veldata_particles_perturb[i] = malloc(parset.n_tau * n_vel_data_ext * sizeof(double)); } Fline_at_data_particles = malloc(parset.num_particles * sizeof(double *)); Fline_at_data_particles_perturb = malloc(parset.num_particles * sizeof(double *)); for(i=0; i<parset.num_particles; i++) { Fline_at_data_particles[i] = malloc(n_line_data * n_vel_data_ext * sizeof(double)); Fline_at_data_particles_perturb[i] = malloc(n_line_data * n_vel_data_ext * sizeof(double)); } clouds_tau = malloc(parset.n_cloud_per_task * sizeof(double)); clouds_weight = malloc(parset.n_cloud_per_task * sizeof(double)); clouds_vel = malloc(parset.n_cloud_per_task * parset.n_vel_per_cloud * sizeof(double)); if(parset.flag_save_clouds && thistask == roottask) { if(parset.n_cloud_per_task <= 10000) icr_cloud_save = 1; else icr_cloud_save = parset.n_cloud_per_task/10000; char fname[200]; sprintf(fname, "%s/%s", parset.file_dir, parset.cloud_out_file); fcloud_out = fopen(fname, "w"); if(fcloud_out == NULL) { fprintf(stderr, "# Error: Cannot open file %s\n", fname); exit(-1); } } return; } /*! * this function finalizes 2d reconstruction. */ void reconstruct_line2d_end() { free(Tline); //free(Fline2d_at_data); free(Fline2d); //free(TransTau); free(TransV); free(Trans2D); //free(Trans2D_at_veldata); int i; for(i=0; i<parset.num_particles; i++) { free(Fcon_rm_particles[i]); free(Fcon_rm_particles_perturb[i]); } free(Fcon); free(Fcon_rm_particles); free(Fcon_rm_particles_perturb); free(Fline_at_data); free(par_fix); free(par_fix_val); free(best_model_line2d); free(best_model_std_line2d); for(i=0; i<parset.num_particles; i++) { free(Trans2D_at_veldata_particles[i]); free(Trans2D_at_veldata_particles_perturb[i]); free(TransTau_particles[i]); free(TransTau_particles_perturb[i]); free(Fline_at_data_particles[i]); free(Fline_at_data_particles_perturb[i]); } free(Trans2D_at_veldata_particles); free(Trans2D_at_veldata_particles_perturb); free(TransTau_particles); free(TransTau_particles_perturb); free(Fline_at_data_particles); free(Fline_at_data_particles_perturb); for(i=0; i<num_params; i++) { free(par_range_model[i]); free(par_prior_gaussian[i]); } free(par_range_model); free(par_prior_gaussian); free(par_prior_model); free(clouds_tau); free(clouds_weight); free(clouds_vel); if(parset.flag_save_clouds && thistask==roottask) { fclose(fcloud_out); } if(thistask == roottask) { printf("Ends reconstruct_line2d.\n"); } return; } /*! * this function calculate probability at initial step. */ double prob_initial_line2d(const void *model) { double prob_line = 0.0, var2, dy, var2_se; int i, j; double *pm = (double *)model; which_particle_update = dnest_get_which_particle_update(); Fcon_rm = Fcon_rm_particles[which_particle_update]; //calculate_con_from_model(model + num_params_blr*sizeof(double)); calculate_con_from_model_semiseparable(model + num_params_blr*sizeof(double)); calculate_con_rm(model); gsl_interp_init(gsl_linear, Tcon, Fcon_rm, parset.n_con_recon); TransTau = TransTau_particles[which_particle_update]; Trans2D_at_veldata = Trans2D_at_veldata_particles[which_particle_update]; Fline2d_at_data = Fline_at_data_particles[which_particle_update]; which_parameter_update = -1; transfun_2d_cal(model, Vline_data_ext, Trans2D_at_veldata, n_vel_data_ext, 0); calculate_line2d_from_blrmodel(model, Tline_data, Vline_data_ext, Trans2D_at_veldata, Fline2d_at_data, n_line_data, n_vel_data_ext); var2_se = (exp(pm[num_params_blr-1])-1.0) * (exp(pm[num_params_blr-1])-1.0) * line_error_mean_sq; for(i=0; i<n_line_data; i++) { for(j=0; j<n_vel_data; j++) { //note mask with error < 0.0 if(Flerrs2d_data[i] > 0.0) { dy = Fline2d_data[i*n_vel_data + j] - Fline2d_at_data[i * n_vel_data_ext + (j+n_vel_data_incr)]; var2 = Flerrs2d_data[i*n_vel_data+j]*Flerrs2d_data[i*n_vel_data+j] + var2_se; prob_line += (-0.5 * (dy*dy)/var2) - 0.5*log(var2 * 2.0*PI); } } } return prob_line; } /*! * this function calculate probability at restart step. */ double prob_restart_line2d(const void *model) { double prob_line = 0.0, var2, dy, var2_se; int i, j; double *pm = (double *)model; which_particle_update = dnest_get_which_particle_update(); Fcon_rm = Fcon_rm_particles[which_particle_update]; //calculate_con_from_model(model + num_params_blr*sizeof(double)); calculate_con_from_model_semiseparable(model + num_params_blr*sizeof(double)); calculate_con_rm(model); gsl_interp_init(gsl_linear, Tcon, Fcon_rm, parset.n_con_recon); TransTau = TransTau_particles[which_particle_update]; Trans2D_at_veldata = Trans2D_at_veldata_particles[which_particle_update]; Fline2d_at_data = Fline_at_data_particles[which_particle_update]; which_parameter_update = num_params + 1; // so as not to update clouds. transfun_2d_cal(model, Vline_data_ext, Trans2D_at_veldata, n_vel_data_ext, 0); calculate_line2d_from_blrmodel(model, Tline_data, Vline_data_ext, Trans2D_at_veldata, Fline2d_at_data, n_line_data, n_vel_data_ext); var2_se = (exp(pm[num_params_blr-1])-1.0) * (exp(pm[num_params_blr-1])-1.0) * line_error_mean_sq; for(i=0; i<n_line_data; i++) { for(j=0; j<n_vel_data; j++) { //note mask with error < 0.0 if(Flerrs2d_data[i] > 0.0) { dy = Fline2d_data[i*n_vel_data + j] - Fline2d_at_data[i * n_vel_data_ext + (j+n_vel_data_incr)]; var2 = Flerrs2d_data[i*n_vel_data+j]*Flerrs2d_data[i*n_vel_data+j] + var2_se; prob_line += (-0.5 * (dy*dy)/var2) - 0.5*log(var2 * 2.0*PI); } } } return prob_line; } /*! * this function calculate probability. * * At each MCMC step, only one parameter is updated, which only changes some values; thus, * optimization that reuses the unchanged values can improve computation efficiency. */ double prob_line2d(const void *model) { double prob_line = 0.0, var2, dy, var2_se; int i, j; double *pm = (double *)model; which_particle_update = dnest_get_which_particle_update(); // only update continuum reconstruction when the corresponding parameters are updated if(which_parameter_update >= num_params_blr) { Fcon_rm = Fcon_rm_particles_perturb[which_particle_update]; //calculate_con_from_model(model + num_params_blr*sizeof(double)); calculate_con_from_model_semiseparable(model + num_params_blr*sizeof(double)); calculate_con_rm(model); gsl_interp_init(gsl_linear, Tcon, Fcon_rm, parset.n_con_recon); } else /* continuum has no change, use the previous values */ { Fcon_rm = Fcon_rm_particles[which_particle_update]; gsl_interp_init(gsl_linear, Tcon, Fcon_rm, parset.n_con_recon); } // only update transfer function when BLR model is changed. // or when forced to updated if( (which_parameter_update < num_params_blr-1) || force_update == 1) { TransTau = TransTau_particles_perturb[which_particle_update]; Trans2D_at_veldata = Trans2D_at_veldata_particles_perturb[which_particle_update]; transfun_2d_cal(model, Vline_data_ext, Trans2D_at_veldata, n_vel_data_ext, 0); } else { TransTau = TransTau_particles[which_particle_update]; Trans2D_at_veldata = Trans2D_at_veldata_particles[which_particle_update]; } /* no need to calculate line when only systematic error parameter of line are updated. * otherwise, always need to calculate line. */ if( which_parameter_update != num_params_blr-1 || force_update == 1 ) { Fline2d_at_data = Fline_at_data_particles_perturb[which_particle_update]; calculate_line2d_from_blrmodel(model, Tline_data, Vline_data_ext, Trans2D_at_veldata, Fline2d_at_data, n_line_data, n_vel_data_ext); var2_se = (exp(pm[num_params_blr-1])-1.0) * (exp(pm[num_params_blr-1])-1.0) * line_error_mean_sq; for(i=0; i<n_line_data; i++) { for(j=0; j<n_vel_data; j++) { //note mask with error < 0.0 if(Flerrs2d_data[i] > 0.0) { dy = Fline2d_data[i*n_vel_data + j] - Fline2d_at_data[i * n_vel_data_ext + (j+n_vel_data_incr)]; var2 = Flerrs2d_data[i*n_vel_data+j]*Flerrs2d_data[i*n_vel_data+j] + var2_se; prob_line += (-0.5 * (dy*dy)/var2) - 0.5*log(var2 * 2.0*PI); } } } } else { /* re-point */ Fline2d_at_data = Fline_at_data_particles[which_particle_update]; var2_se = (exp(pm[num_params_blr-1])-1.0) * (exp(pm[num_params_blr-1])-1.0) * line_error_mean_sq; for(i=0; i<n_line_data; i++) { for(j=0; j<n_vel_data; j++) { //note mask with error < 0.0 if(Flerrs2d_data[i] > 0.0) { dy = Fline2d_data[i*n_vel_data + j] - Fline2d_at_data[i * n_vel_data_ext + (j+n_vel_data_incr)]; var2 = Flerrs2d_data[i*n_vel_data+j]*Flerrs2d_data[i*n_vel_data+j] + var2_se; prob_line += (-0.5 * (dy*dy)/var2) - 0.5*log(var2 * 2.0*PI); } } } } return prob_line; }
(* Title: HOL/Auth/flash_data_cub_lemma_on_inv__107.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 flash_data_cub Protocol Case Study*} theory flash_data_cub_lemma_on_inv__107 imports flash_data_cub_base begin section{*All lemmas on causal relation between inv__107 and some rule r*} lemma n_PI_Remote_GetVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Get src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Get src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Remote_GetXVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_GetX src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_GetX src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Remote_PutXVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_PI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_PI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Remote_ReplaceVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_PI_Remote_Replace src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_PI_Remote_Replace src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_NakVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Nak dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Nak dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Nak__part__2Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Get__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Get__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Get__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_HeadVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Head N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_PutVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_Get_Put_DirtyVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_Get_Put_Dirty src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_NakVsinv__107: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_PutVsinv__107: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_Get_Put src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_Get_Put_HomeVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Get_Put_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_Nak__part__2Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_Nak__part__2 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_GetX__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__0 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E)) (eqn (IVar (Field (Field (Ident ''Sta'') ''Dir'') ''HomeHeadPtr'')) (Const true))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_GetX__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_GetX__part__1 src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P3 s" apply (cut_tac a1 a2 b1, simp, rule_tac x="(neg (andForm (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''UniMsg'') p__Inv4) ''Cmd'')) (Const UNI_GetX)) (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''CacheState'')) (Const CACHE_E))))" in exI, auto) done then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_2Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_2 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_3Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_3 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_4Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_4 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_5Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_5 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_6Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_6 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_7_NODE_Get__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_7_NODE_Get__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_HomeVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_Home_NODE_GetVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_8_Home_NODE_Get N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8Vsinv__107: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_8_NODE_GetVsinv__107: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_8_NODE_Get N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__0Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__0 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_9__part__1Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_9__part__1 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10_HomeVsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_10_Home N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_10Vsinv__107: assumes a1: "(\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src pp where a1:"src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_Local_GetX_PutX_10 N src pp" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>pp~=p__Inv4)\<or>(src~=p__Inv4\<and>pp=p__Inv4)\<or>(src~=p__Inv4\<and>pp~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>pp~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>pp~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Local_GetX_PutX_11Vsinv__107: assumes a1: "(\<exists> src. src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src where a1:"src\<le>N\<and>r=n_NI_Local_GetX_PutX_11 N src" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4)\<or>(src~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_NakVsinv__107: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_Nak src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutXVsinv__107: assumes a1: "(\<exists> src dst. src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain src dst where a1:"src\<le>N\<and>dst\<le>N\<and>src~=dst\<and>r=n_NI_Remote_GetX_PutX src dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(src=p__Inv4\<and>dst~=p__Inv4)\<or>(src~=p__Inv4\<and>dst=p__Inv4)\<or>(src~=p__Inv4\<and>dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(src=p__Inv4\<and>dst~=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(src~=p__Inv4\<and>dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_GetX_PutX_HomeVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_GetX_PutX_Home dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Put dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_Put dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))\<or>((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))" by auto moreover { assume c1: "((formEval (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true)) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume c1: "((formEval (neg (eqn (IVar (Field (Para (Field (Ident ''Sta'') ''Proc'') p__Inv4) ''InvMarked'')) (Const true))) s))" have "?P1 s" proof(cut_tac a1 a2 b1 c1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately have "invHoldForRule s f r (invariants N)" by satx } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_Remote_PutXVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_PutX dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Remote_PutX dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_NI_InvVsinv__107: assumes a1: "(\<exists> dst. dst\<le>N\<and>r=n_NI_Inv dst)" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" (is "?P1 s \<or> ?P2 s \<or> ?P3 s") proof - from a1 obtain dst where a1:"dst\<le>N\<and>r=n_NI_Inv dst" apply fastforce done from a2 obtain p__Inv4 where a2:"p__Inv4\<le>N\<and>f=inv__107 p__Inv4" apply fastforce done have "(dst=p__Inv4)\<or>(dst~=p__Inv4)" apply (cut_tac a1 a2, auto) done moreover { assume b1: "(dst=p__Inv4)" have "?P1 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } moreover { assume b1: "(dst~=p__Inv4)" have "?P2 s" proof(cut_tac a1 a2 b1, auto) qed then have "invHoldForRule s f r (invariants N)" by auto } ultimately show "invHoldForRule s f r (invariants N)" by satx qed lemma n_PI_Local_GetX_PutX__part__0Vsinv__107: assumes a1: "r=n_PI_Local_GetX_PutX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_WbVsinv__107: assumes a1: "r=n_NI_Wb " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_StoreVsinv__107: assumes a1: "\<exists> src data. src\<le>N\<and>data\<le>N\<and>r=n_Store src data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_3Vsinv__107: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_3 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_1Vsinv__107: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_1 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__1Vsinv__107: assumes a1: "r=n_PI_Local_GetX_GetX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_GetX__part__0Vsinv__107: assumes a1: "r=n_PI_Local_GetX_GetX__part__0 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_Store_HomeVsinv__107: assumes a1: "\<exists> data. data\<le>N\<and>r=n_Store_Home data" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_ReplaceVsinv__107: assumes a1: "r=n_PI_Local_Replace " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_existsVsinv__107: assumes a1: "\<exists> src pp. src\<le>N\<and>pp\<le>N\<and>src~=pp\<and>r=n_NI_InvAck_exists src pp" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_PutXVsinv__107: assumes a1: "r=n_PI_Local_PutX " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_PutVsinv__107: assumes a1: "r=n_PI_Local_Get_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ShWbVsinv__107: assumes a1: "r=n_NI_ShWb N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__0Vsinv__107: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__0 N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_ReplaceVsinv__107: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_Replace src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_GetX_Nak_HomeVsinv__107: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_GetX_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutXAcksDoneVsinv__107: assumes a1: "r=n_NI_Local_PutXAcksDone " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX__part__1Vsinv__107: assumes a1: "r=n_PI_Local_GetX_PutX__part__1 " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Remote_Get_Nak_HomeVsinv__107: assumes a1: "\<exists> dst. dst\<le>N\<and>r=n_NI_Remote_Get_Nak_Home dst" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_exists_HomeVsinv__107: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_exists_Home src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Replace_HomeVsinv__107: assumes a1: "r=n_NI_Replace_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Local_PutVsinv__107: assumes a1: "r=n_NI_Local_Put " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_ClearVsinv__107: assumes a1: "r=n_NI_Nak_Clear " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_Get_GetVsinv__107: assumes a1: "r=n_PI_Local_Get_Get " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_Nak_HomeVsinv__107: assumes a1: "r=n_NI_Nak_Home " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_InvAck_2Vsinv__107: assumes a1: "\<exists> src. src\<le>N\<and>r=n_NI_InvAck_2 N src" and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_PI_Local_GetX_PutX_HeadVld__part__1Vsinv__107: assumes a1: "r=n_PI_Local_GetX_PutX_HeadVld__part__1 N " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done lemma n_NI_FAckVsinv__107: assumes a1: "r=n_NI_FAck " and a2: "(\<exists> p__Inv4. p__Inv4\<le>N\<and>f=inv__107 p__Inv4)" shows "invHoldForRule s f r (invariants N)" apply (rule noEffectOnRule, cut_tac a1 a2, auto) done end
Our Community Support Scheme has now donated over £150,000 to deserving causes throughout Nottinghamshire, Derbyshire and surrounding areas since the Scheme was established in 2008. The milestone was reached when the Scheme’s trustees agreed to distribute another £20,000 to 40 groups in 2017 looking for funding to help bring their plans to life. The Community Support Scheme was established to provide financial assistance to a range of local community groups, clubs and charities that selflessly devote their time and energy to improve the quality of life for communities throughout our region. Applications are invited from organisations that assist the disadvantaged; promote and encourage participation in sporting activities or the arts; support education; or benefit the environment. A total of 387 donations have now been made to local community groups since May 2008 with beneficiaries including Over 60's Youthful Group, Age UK Notts, Chesterfield Amateur Boxing Club, Mansfield First Responders, Nottinghamshire Wildlife Trust, Central Nottinghamshire MIND, Mansfield Senior Reds Walking Football Club, Mansfield and North Nottinghamshire Society for Deaf People and many, many more. The Society’s donations have helped groups in our heartland area fund a variety of things, including new kayaks and associated safety equipment, defibrillators, a fibre optic carpet for those living with autism, and even a lawnmower for a local crown bowling club to maintain its facilities. Gev Lynott, Chief Executive Officer at the Society, said “We’re delighted to have helped so many great causes across the region through our Community Support Scheme. I am always amazed by the selfless generosity of individuals who give their time week in, week out, to provide invaluable support to improve the lives of others. To find out more about our Community Support Scheme or to download an application form, click here.
!######################################################## ! Program : PAMMPT ! TYPE : Main program ! PURPOSE : Solve the PAM using DMFT away from half-filling ! with modified itertive perturbation scheme (MPT) ! AUTHORS : Adriano Amaricci !######################################################## module COMMON USE BROYDEN USE COMMON_VARS implicit none !Put here vars in common with the BROYDN function real(8) :: xmu0,n,n0 complex(8),allocatable :: sigma(:),fg(:),fg0(:),gamma(:) complex(8),allocatable :: sigmap(:),fgp(:),fg0p(:) real(8),allocatable :: wr(:) end module COMMON function funcv(x) USE COMMON USE DMFT_IPT implicit none real(8),dimension(:),intent(in) :: x real(8),dimension(size(x)) :: funcv real(8) :: zn0 xmu0=x(1) fg0 = one/(cmplx(wr,eps) + xmu0 - ed0 - gamma -U*(n-0.5d0)) n0=sum(fermi(wr,beta)*aimag(fg0))/sum(aimag(fg0)) funcv(1)=n-n0 write(*,"(3(f13.9))")n,n0,xmu0 end function funcv program pammpt USE DMFT_IPT USE COMMON USE IOTOOLS implicit none integer :: i,iloop real(8) :: x(1) logical :: check,converged complex(8) :: zeta,alpha real(8) :: np,gzero,gmu,ntot,shift complex(8),allocatable :: sold(:) call read_input("inputIPT.in") allocate(fg(1:L),sigma(1:L),fg0(1:L),gamma(1:L)) allocate(fgp(1:L),fg0p(1:L),sigmap(1:L)) allocate(sold(1:L)) allocate(wr(1:L)) ! wm = pi/beta*real(2*arange(1,L)-1,8) ! tau = linspace(0.d0,beta,L+1,mesh=dtau) gmu=xmu ; gzero=0.d0 if((ed0-ep0) > 0.d0)gzero=0.5*(ep0+ed0+sqrt((ep0-ed0)**2 + 4*Vpd**2)) if((ed0-ep0) < 0.d0)gzero=0.5*(ep0+ed0-sqrt((ep0-ed0)**2 + 4*Vpd**2)) if((ed0-ep0) /=0.d0)xmu=gmu+gzero !true ED chemical potential write(*,*)'shift mu to (from) = ',xmu,'(',gmu,')' write(*,*)'shift is = ',gzero wr = linspace(-wmax,wmax,L,mesh=fmesh) sigma=zero ; xmu0=xmu ; D=2.d0*ts iloop=0 ; converged=.false. ; sold=sigma do while (.not.converged) iloop=iloop+1 write(*,"(A,i5)")"DMFT-loop",iloop do i=1,L alpha = cmplx(wr(i),eps) +xmu -ed0 - sigma(i) sigmap(i) = Vpd**2/alpha zeta = cmplx(wr(i),eps) +xmu -ep0 - sigmap(i) fgp(i) = gfbether(wr(i),zeta,D) fg(i) = one/alpha + Vpd**2/alpha**2*fgp(i) enddo n = sum(fermi(wr,beta)*aimag(fg))/sum(aimag(fg)) np = 2.d0*sum(aimag(fgp(:))*fermi(wr(:),beta))/sum(aimag(fgp(:))) ntot = np+2.d0*n !Get the hybridization functions: \Gamma(w+xmu) gamma= cmplx(wr,eps) + xmu - ed0 - sigma - one/fg !Fix the xmu0 w/ condition n0=n x(1)=xmu call broydn(x,check) !this changes n0,xmu0 xmu0=x(1) sigma= solve_mpt_sopt(fg0,wr,n,n0,xmu0) sigma=weight*sigma + (1.d0-weight)*sold sold=sigma converged=check_convergence(sigma,eps_error,Nsuccess,Nloop) call splot("ndVSiloop.ipt",iloop,2.d0*n,append=TT) call splot("npVSiloop.ipt",iloop,np,append=TT) call splot("ntotVSiloop.ipt",iloop,ntot,append=TT) enddo call splot("nd.np.ntot.ipt",n,np,ntot,append=TT) call splot("DOS.ipt",wr,-aimag(fg)/pi,-aimag(fgp)/pi,append=printf) call splot("Sigma_realw.ipt",wr,sigma,append=printf) call splot("Sigmap_realw.ipt",wr,sigmap,append=printf) call splot("G_realw.ipt",wr,fg,append=printf) call splot("Gp_realw.ipt",wr,fgp,append=printf) ! Lk=(Nx+1)**2 ! call pam_getenergy_spt(Lk) ! contains ! !+-------------------------------------------------------------------+ ! !PROGRAM : ! !TYPE : Subroutine ! !PURPOSE : ! !COMMENT : ! !+-------------------------------------------------------------------+ ! subroutine pam_getenergy_spt(Lk) ! integer :: Lk,Lm ! real(8) :: nd,np,docc,Etot,Ekin,Epot,Ehyb,Eepsi,Emu,nk(Lk),npk(Lk) ! real(8) :: epsi,de ! complex(8),allocatable :: gf(:),sf(:),gff(:) ! complex(8),allocatable :: gp(:),sp(:),gpp(:) ! real(8),allocatable :: gtau(:),gptau(:) ! complex(8) :: gamma,alpha ! Lm=int(L*beta/pi);if(beta<1)Lm=L;if(Lm<L)Lm=L ! Lm=2**14 ! allocate(gf(Lm),sf(Lm),gtau(0:L),gff(L)) ! allocate(gp(Lm),sp(Lm),gptau(0:L),gpp(L)) ! call getGmats(wr,fg,gf,beta) ! call getGmats(wr,fgp,gp,beta) ! call getGmats(wr,sigma,sf,beta) ! call getGmats(wr,sigmap,sp,beta) ! call splot("Giw.ipt",(/(pi/beta*dble(2*i-1),i=1,Lm)/),gf) ! call splot("Gpiw.ipt",(/(pi/beta*dble(2*i-1),i=1,Lm)/),gp) ! call cfft_iw2tau(gf,gtau,beta) ! call cfft_iw2tau(gp,gptau,beta) ! call splot("Gtau.ipt",(/(dble(i)*beta/dble(L),i=0,L)/),gtau(0:L)) ! call splot("Gptau.ipt",(/(dble(i)*beta/dble(L),i=0,L)/),gptau(0:L)) ! nd=-2.d0*gtau(L) ! np=-2.d0*gptau(L) ! !Energy && k-dispersed quantities ! Ekin=0.d0 ! de=2.d0*D/dble(Lk) ! do ik=1,Lk ! epsi=-D + de*dble(ik) ! do i=1,L ! w=pi/beta*dble(2*i-1) ! gamma=xi*w+xmu-ed0-sf(i) ! alpha=xi*w+xmu-ep0-epsi ! gff(i)=one/(gamma - vpd**2/alpha) ! gpp(i)=one/(alpha-sp(i)) ! enddo ! call cfft_iw2tau(gff,gtau,beta) ! call cfft_iw2tau(gpp,gptau,beta) ! nk(ik)=-gtau(L) ! npk(ik)=-gptau(L) ! Ekin=Ekin + nk(ik)*epsi/dble(Lk) ! enddo ! Epot=dot_product(conjg(sf(:)),gf(:)) ! Ehyb=4.d0*dot_product(conjg(sp(:)),gp(:)) ! Ehyb=2.d0*Ehyb/beta ! Epot=2.d0*Epot/beta ! docc=0.5*nd - 0.25d0 ! if(u>=1.d-2)docc = Epot/U + 0.5*nd - 0.25d0 ! Eepsi=ed0*(nd-1.d0) + ep0*(np-1.d0) ! Emu=-xmu*(ntot-2.d0) ! Etot=Ekin+Epot+Ehyb+Eepsi+Emu ! write(*,"(A,f13.9)")"docc =",docc ! write(*,"(A,f13.9)")"nd =",nd ! write(*,"(A,f13.9)")"np =",np ! write(*,"(A,f13.9)")"ntot =",np+nd ! write(*,"(A,f13.9)")"Etot =",Etot ! write(*,"(A,f13.9)")"Ekin =",Ekin ! write(*,"(A,f13.9)")"Epot =",Epot ! write(*,"(A,f13.9)")"Ehyb =",Ehyb ! write(*,"(A,f13.9)")"Eepsi =",Eepsi ! write(*,"(A,f13.9)")"Emu =",Emu ! call splot("nkVSepsik.ipt",(/(-D + de*dble(ik),ik=1,Lk )/),nk(1:Lk),npk(1:Lk)) ! call splot("EtotVS"//trim(extension),xout,Ekin+Epot,append=TT) ! call splot("EkinVS"//trim(extension),xout,Ekin,append=TT) ! call splot("EpotVS"//trim(extension),xout,Epot,append=TT) ! call splot("EhybVS"//trim(extension),xout,Ehyb,append=TT) ! call splot("EmuVS"//trim(extension),xout,Emu,append=TT) ! call splot("EepsiVS"//trim(extension),xout,Eepsi,append=TT) ! call splot("doccVS"//trim(extension),xout,docc,append=TT) ! deallocate(gf,sf,gtau,gff) ! deallocate(gp,sp,gptau,gpp) ! end subroutine pam_getenergy_spt ! !******************************************************************* ! !******************************************************************* ! !******************************************************************* end program pammpt
\section{CPU core architecture} In this section reader can found informations about CPU core. For example, count of registers, instructions, memory organization and so on. \subsection{CPU Features} \begin{itemize} \item $2^{24}$ word addressed memory \item 16 registers for both integers and floats \item Integer ALU with fast multiplier and divider \item Fast FPU with single precision format \item Fast barrel shifter \item Almost all instructions are done in 3 cycles (Load, decode and execute) \end{itemize}
Wear your rhodium plated Chrysalis Roses bracelet and show your romantic side. Roses have long been given as a symbol of everlasting love. Symbolising beauty, devotion and admiration. Gorgeous roses represent all things divine and show respect.
""" mblocks(X, listbl) Make blocks from a matrix. * `X` : X-data. * `listbl` : A vector whose each component defines the colum numbers defining a block in `X` . The length of `listbl` is the number of blocks. The function returns a list of blocks. ## Examples ```julia n = 5 ; p = 10 X = rand(n, p) listbl = [3:4, 1, [6; 8:10]] X_bl = mblocks(X, listbl) ``` """ function mblocks(X, listbl) nbl = length(listbl) zX = list(nbl, Matrix{Float64}) @inbounds for i = 1:nbl zX[i] = ensure_mat(X[:, listbl[i]]) end zX end """ blockscal(X, weights = ones(size(X, 1)); listbl, scal = nothing) Autoscale blocks of a matrix. * `X` : List (vector) of blocks (matrices) of X-data. Each component of the list is a block. * `weights` : Weights of the observations (rows). Only used if `scal = nothing`. * `scal` : If `nothing`, each block is autoscaled (i.e. divided) by the the square root of the sum of the variances of each column of the block. Else, `scal` must be a vector defining the scaling values dividing the blocks. The function returns the scaled blocks, and the scaling values. Vector `weights` (row-weighting) is internally normalized to sum to 1. ## Examples ```julia n = 5 ; p = 10 X = rand(n, p) listbl = [3:4, 1, [6; 8:10]] X_bl = mblocks(X, listbl) scal = nothing #scal = [3.1 2 .7] res = blockscal(X_bl; scal = scal) ; res.X res.scal sum(colvars(res.X[1])) X_concat = reduce(hcat, res.X) ``` """ function blockscal(X, weights = ones(size(X[1], 1)); scal = nothing) weights = mweights(weights) nbl = length(X) if isnothing(scal) scal = list(nbl, Float64) @inbounds for i = 1:nbl scal[i] = sqrt(sum(colvars(X[i], weights))) end end Xs = list(nbl, Matrix{Float64}) @inbounds for i = 1:nbl Xs[i] = X[i] / scal[i] end (X = Xs, scal = scal) end
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020 Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Abstract.Types module LibraBFT.Abstract.BFT where -- This is a utility function to make it easy to provide the bft-assumption -- for the abstract EpochConfig by by assuming that at most bizF members are byzantine -- and that authorsN ≥ suc (3 * bizF) and that a list of Members is a quorum if it -- contains at least authorsN ∸ bizF distinct Members.
[STATEMENT] lemma nprv_exiE: assumes n: "nprv F (exi x \<phi>)" and nn: "nprv (insert \<phi> F) \<psi>" and 0[simp]: "F \<subseteq> fmla" "finite F" "\<phi> \<in> fmla" "x \<in> var" "\<psi> \<in> fmla" and x: "x \<notin> \<Union> (Fvars ` F)" "x \<notin> Fvars \<psi>" shows "nprv F \<psi>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. nprv F \<psi> [PROOF STEP] proof- [PROOF STATE] proof (state) goal (1 subgoal): 1. nprv F \<psi> [PROOF STEP] have "nprv F (imp (exi x \<phi>) \<psi>)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. nprv F (imp (exi x \<phi>) \<psi>) [PROOF STEP] unfolding nprv_def [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp (scnj F) (imp (exi x \<phi>) \<psi>)) [PROOF STEP] apply(rule prv_imp_com) [PROOF STATE] proof (prove) goal (4 subgoals): 1. exi x \<phi> \<in> fmla 2. scnj F \<in> fmla 3. \<psi> \<in> fmla 4. prv (imp (exi x \<phi>) (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. exi x \<phi> \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (3 subgoals): 1. scnj F \<in> fmla 2. \<psi> \<in> fmla 3. prv (imp (exi x \<phi>) (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. scnj F \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<psi> \<in> fmla 2. prv (imp (exi x \<phi>) (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<psi> \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp (exi x \<phi>) (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp (exi x \<phi>) (imp (scnj F) \<psi>)) [PROOF STEP] apply(rule prv_exi_imp_gen) [PROOF STATE] proof (prove) goal (5 subgoals): 1. x \<in> var 2. \<phi> \<in> fmla 3. imp (scnj F) \<psi> \<in> fmla 4. x \<notin> Fvars (imp (scnj F) \<psi>) 5. prv (imp \<phi> (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. x \<in> var [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (4 subgoals): 1. \<phi> \<in> fmla 2. imp (scnj F) \<psi> \<in> fmla 3. x \<notin> Fvars (imp (scnj F) \<psi>) 4. prv (imp \<phi> (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<phi> \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (3 subgoals): 1. imp (scnj F) \<psi> \<in> fmla 2. x \<notin> Fvars (imp (scnj F) \<psi>) 3. prv (imp \<phi> (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. imp (scnj F) \<psi> \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (2 subgoals): 1. x \<notin> Fvars (imp (scnj F) \<psi>) 2. prv (imp \<phi> (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. x \<notin> Fvars (imp (scnj F) \<psi>) [PROOF STEP] using x [PROOF STATE] proof (prove) using this: x \<notin> \<Union> (Fvars ` F) x \<notin> Fvars \<psi> goal (1 subgoal): 1. x \<notin> Fvars (imp (scnj F) \<psi>) [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp \<phi> (imp (scnj F) \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp \<phi> (imp (scnj F) \<psi>)) [PROOF STEP] apply(rule prv_imp_com) [PROOF STATE] proof (prove) goal (4 subgoals): 1. scnj F \<in> fmla 2. \<phi> \<in> fmla 3. \<psi> \<in> fmla 4. prv (imp (scnj F) (imp \<phi> \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. scnj F \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (3 subgoals): 1. \<phi> \<in> fmla 2. \<psi> \<in> fmla 3. prv (imp (scnj F) (imp \<phi> \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<phi> \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<psi> \<in> fmla 2. prv (imp (scnj F) (imp \<phi> \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<psi> \<in> fmla [PROOF STEP] by auto [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp (scnj F) (imp \<phi> \<psi>)) [PROOF STEP] subgoal [PROOF STATE] proof (prove) goal (1 subgoal): 1. prv (imp (scnj F) (imp \<phi> \<psi>)) [PROOF STEP] using assms(3-5) assms(7) nn nprv_def nprv_impI [PROOF STATE] proof (prove) using this: F \<subseteq> fmla finite F \<phi> \<in> fmla \<psi> \<in> fmla nprv (insert \<phi> F) \<psi> nprv ?F ?\<phi> \<equiv> prv (imp (scnj ?F) ?\<phi>) \<lbrakk>nprv (insert ?\<phi> ?F) ?\<psi>; ?F \<subseteq> fmla; finite ?F; ?\<phi> \<in> fmla; ?\<psi> \<in> fmla\<rbrakk> \<Longrightarrow> nprv ?F (imp ?\<phi> ?\<psi>) goal (1 subgoal): 1. prv (imp (scnj F) (imp \<phi> \<psi>)) [PROOF STEP] by blast [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] . [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] . [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] . [PROOF STATE] proof (state) this: nprv F (imp (exi x \<phi>) \<psi>) goal (1 subgoal): 1. nprv F \<psi> [PROOF STEP] thus ?thesis [PROOF STATE] proof (prove) using this: nprv F (imp (exi x \<phi>) \<psi>) goal (1 subgoal): 1. nprv F \<psi> [PROOF STEP] using n assms nprv_mp [PROOF STATE] proof (prove) using this: nprv F (imp (exi x \<phi>) \<psi>) nprv F (exi x \<phi>) nprv F (exi x \<phi>) nprv (insert \<phi> F) \<psi> F \<subseteq> fmla finite F \<phi> \<in> fmla x \<in> var \<psi> \<in> fmla x \<notin> \<Union> (Fvars ` F) x \<notin> Fvars \<psi> \<lbrakk>nprv ?F (imp ?\<phi> ?\<psi>); nprv ?F ?\<phi>; ?F \<subseteq> fmla; finite ?F; ?\<phi> \<in> fmla; ?\<psi> \<in> fmla\<rbrakk> \<Longrightarrow> nprv ?F ?\<psi> goal (1 subgoal): 1. nprv F \<psi> [PROOF STEP] by blast [PROOF STATE] proof (state) this: nprv F \<psi> goal: No subgoals! [PROOF STEP] qed
short time I had set out for India with the ambassador, attended only by a small suite on account of the length of the journey, and the badness of the roads. However, as was my duty, I took writh me ten camels, laden with rich presents for the Sultan. We had been travelling for about a month, when one day we saw a cloud of dust moving swiftly towards us; and as soon as it came near, we found that the dust concealed a band of fifty robbers. Our men barely numbered half, and as we were also hampered by the camels, there was no use in fighting, so we tried to over­awe them by informing them who we were, and whither we were going. The robbers, however, only laughed, and declared that was none of their business, and, without more words, attacked us brutally. I defended myself to the last, wounded though I was, but at length, seeing that resistance was hopeless, and that the ambassador and all our followers were made prisoners, I put spurs to my horse and rode away as fast as I could, till the poor beast fell dead from a wound in his side. I managed to jump off without any injury, and looked about to see if I was pursued. But for the moment I was safe, for, as I imagined, the robbers were all engaged in quarrelling over their booty. I found myself in a country that was quite new to me, and dared not return to the main road lest I should as:ain fall into the hands of the robbers. Luckily my wound was only a slight one, and after binding it up as well as I could, I walked on for the rest of the day, till I reached a cave at the foot of a mountain, where I passed the night in peace, making my supper off some fruits I had gathered on the way.
[STATEMENT] lemma collapse_flipped_signed: "prappend_signed_list [(s,b)] [(s,\<not>b)] = []" [PROOF STATE] proof (prove) goal (1 subgoal): 1. prappend_signed_list [(s, b)] [(s, \<not> b)] = [] [PROOF STEP] using prappend_signed_list.simps(3)[of "[]" "(s,b)"] [PROOF STATE] proof (prove) using this: prappend_signed_list ([] @ [(s, b)]) (?y # ?ys) = (if ?y = flip_signed (s, b) then prappend_signed_list [] ?ys else [] @ (s, b) # ?y # ?ys) goal (1 subgoal): 1. prappend_signed_list [(s, b)] [(s, \<not> b)] = [] [PROOF STEP] by simp
""" SurfaceFluxes Surface fluxes parameters, shared by multiple models including the atmosphere, ocean. """ module SurfaceFluxes include("UniversalFunctions.jl") end # module SurfaceFluxes
theory AbstractMultiPaxosR2Correctness imports AbstractMultiPaxosR1 AbstractMultiPaxosR2 Simulations begin locale ampr2_proof = IOA + quorums quorums + ampr2_ioa quorums leader + r1:ampr1_ioa quorums leader for quorums :: "'a set set" and leader :: "bal \<Rightarrow> 'a" + fixes ampr2_ioa :: "(('v, 'a, 'l) ampr2_state, 'v paxos_action) ioa" and ampr1_ioa :: "(('v, 'a, 'l) ampr1_state, 'v paxos_action) ioa" defines "ampr2_ioa \<equiv> ioa" and "ampr1_ioa \<equiv> r1.ioa" begin definition ref_map where "ref_map s \<equiv> \<lparr> ampr1_state.propCmd = propCmd s, ampr1_state.ballot = ballot s, ampr1_state.vote = (\<lambda> i a . vote s $ a $ i), ampr1_state.suggestion = suggestion s, ampr1_state.onebs = onebs s, ampr1_state.leader = ampr2_state.leader s\<rparr>" term "ampr1_ioa" term "ampr2_ioa" lemma "is_ref_map ref_map ampr2_ioa ampr1_ioa" proof (auto simp add:is_ref_map_def simp del:split_paired_Ex) fix s assume "s \<in> ioa.start ampr2_ioa" thus "ref_map s \<in> ioa.start ampr1_ioa" by (simp add:ref_map_def ampr1.simps ampr2_ioa_def ampr1_ioa_def ioa_def start_def) next fix s t a assume a1:"reachable ampr2_ioa s" and a2:"s \<midarrow>a\<midarrow>ampr2_ioa\<longrightarrow> t" let ?e = "(ref_map s, [(a, ref_map t)])" have "refines ?e s a t ampr1_ioa ref_map" proof (auto simp add:refines_def ioa_simps trace_match_def trace_def schedule_def filter_act_def) show "(ref_map s, a, ref_map t) \<in> ioa.trans ampr1_ioa" using a2 apply (simp add:ampr2_ioa_def ioa_def is_trans_def trans_def) apply (simp add:ampr1_ioa_def ampr1.ioa_def ampr1.trans_def) apply (induct rule:trans_cases_2) apply (simp_all add:simps ampr1.simps ref_map_def)[2] (* join_ballot *) apply (induct a) apply auto[2] apply (auto simp add:ref_map_def ampr1.simps simps)[1] (* do_vote *) apply (induct a) apply auto[2] subgoal premises prems for a i v proof - have "ampr1.do_vote a i v (ref_map s) (ref_map t)" using prems by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff) thus ?thesis by auto qed (* suggest *) apply (induct a) apply auto[2] subgoal premises prems for a i b v proof - have "ampr1.suggest a i b v (ref_map s) (ref_map t)" using prems by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff) thus ?thesis by auto qed (* catch_up *) apply (induct a) apply auto[2] subgoal premises prems for l1 l2 i v proof - have "ampr1.catch_up l1 l2 i v (ref_map s) (ref_map t)" using prems by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff) thus ?thesis by auto qed (* acquire_leadership *) apply (induct a) apply auto[2] subgoal premises prems for aa q proof - have "ampr1.acquire_leadership aa q (ref_map s) (ref_map t)" using prems by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff) thus ?thesis by auto qed done qed thus "\<exists> e . refines e s a t ampr1_ioa ref_map" by blast qed end
Abstract: We prove uniqueness in law for a class of parabolic stochastic partial differential equations in an interval driven by a functional A(u) of the temperature u times a space-time white noise. The functional A(u) is Hölder continuous in u of order greater than 1/2. Our method involves looking at an associated system of infinite-dimensional stochastic differential equations and we obtain a uniqueness result for such systems.
function y = nanstd(varargin) %Replacement for Matlab NANSTD Standard deviation, ignoring NaNs. % y = sqrt(nanvar(varargin{:})); return;
#' tidy_stats method for manova objects #' #' Creates a tidystats data frame for a manova object. #' #' @param model A manova object #' #' @import dplyr #' @import tidyr #' @importFrom magrittr %>% #' #' @export tidy_stats.summary.manova <- function(model) { # Extract statistics output <- as_data_frame(model$stats) %>% rename( `df model` = Df, `df numerator` = `num Df`, `df denominator` = `den Df`, p = `Pr(>F)` ) %>% mutate( term = model$row.names, order = 1:n()) %>% gather("statistic", "value", -term, -order) %>% arrange(order) %>% select(-order) %>% filter(!is.na(value)) # Add method output$method <- "MANOVA" return(output) }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} -- This is a selection of useful functions and definitions -- from the standard library that we tend to use a lot. module LibraBFT.Prelude where open import Level renaming (suc to ℓ+1; zero to ℓ0; _⊔_ to _ℓ⊔_) public 1ℓ : Level 1ℓ = ℓ+1 0ℓ open import Agda.Builtin.Unit public open import Function using (_∘_; _∘′_; id; case_of_; _on_; typeOf; flip; const; _∋_; _$_) public identity = id infixl 1 _&_ _&_ = Function._|>_ open import Data.Unit.NonEta public open import Data.Empty public -- NOTE: This function is defined to give extra documentation when discharging -- absurd cases where Agda can tell by pattern matching that `A` is not -- inhabited. For example: -- > absurd (just v ≡ nothing) case impossibleProof of λ () infix 0 absurd_case_of_ absurd_case_of_ : ∀ {ℓ₁ ℓ₂} (A : Set ℓ₁) {B : Set ℓ₂} → A → (A → ⊥) → B absurd A case x of f = ⊥-elim (f x) open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_; _≥?_ to _≥?ℕ_; compare to compareℕ; Ordering to Orderingℕ) public max = _⊔_ min = _⊓_ open import Data.Nat.DivMod using (_/_) div = _/_ open import Data.Nat.Properties hiding (≡-irrelevant ; _≟_) public open import Data.List renaming (map to List-map ; filter to List-filter ; lookup to List-lookup; tabulate to List-tabulate; foldl to List-foldl) hiding (fromMaybe; [_]) public foldl' = List-foldl open import Data.List.Properties renaming (≡-dec to List-≡-dec; length-map to List-length-map; map-compose to List-map-compose; filter-++ to List-filter-++; length-filter to List-length-filter) using (∷-injective; length-++; map-++-commute; sum-++-commute; map-tabulate; tabulate-lookup; ++-identityʳ; ++-identityˡ) public open import Data.List.Relation.Binary.Subset.Propositional renaming (_⊆_ to _⊆List_) public open import Data.List.Relation.Unary.Any using (Any; here; there) renaming (lookup to Any-lookup; map to Any-map; satisfied to Any-satisfied ;index to Any-index; any to Any-any) public open import Data.List.Relation.Unary.Any.Properties using (¬Any[]) renaming ( map⁺ to Any-map⁺ ; map⁻ to Any-map⁻ ; concat⁺ to Any-concat⁺ ; concat⁻ to Any-concat⁻ ; ++⁻ to Any-++⁻ ; ++⁺ʳ to Any-++ʳ ; ++⁺ˡ to Any-++ˡ ; singleton⁻ to Any-singleton⁻ ; tabulate⁺ to Any-tabulate⁺ ; filter⁻ to Any-filter⁻ ) public open import Data.List.Relation.Unary.All using (All; []; _∷_) renaming (head to All-head; tail to All-tail; lookup to All-lookup; tabulate to All-tabulate; reduce to All-reduce; map to All-map) public open import Data.List.Relation.Unary.All.Properties hiding (All-map) renaming ( tabulate⁻ to All-tabulate⁻ ; tabulate⁺ to All-tabulate⁺ ; map⁺ to All-map⁺ ; map⁻ to All-map⁻ ; ++⁺ to All-++ ) public open import Data.List.Membership.Propositional using (_∈_; _∉_) public open import Data.List.Membership.Propositional.Properties renaming (∈-filter⁺ to List-∈-filter⁺; ∈-filter⁻ to List-∈-filter⁻) public open import Data.Vec using (Vec; []; _∷_) renaming (replicate to Vec-replicate; lookup to Vec-lookup ;map to Vec-map; head to Vec-head; tail to Vec-tail ;updateAt to Vec-updateAt; tabulate to Vec-tabulate ;allFin to Vec-allFin; toList to Vec-toList; fromList to Vec-fromList ;_++_ to _Vec-++_) public open import Data.Vec.Relation.Unary.All using ([]; _∷_) renaming (All to Vec-All; lookup to Vec-All-lookup) public open import Data.Vec.Properties using () renaming (updateAt-minimal to Vec-updateAt-minimal ;[]=⇒lookup to Vec-[]=⇒lookup ;lookup⇒[]= to Vec-lookup⇒[]= ;lookup∘tabulate to Vec-lookup∘tabulate ;≡-dec to Vec-≡-dec) public open import Data.List.Relation.Binary.Pointwise using (decidable-≡) public open import Data.Bool renaming (_≟_ to _≟Bool_) hiding (_≤?_; _<_; _<?_; _≤_; not) public open import Data.Maybe renaming (map to Maybe-map; zip to Maybe-zip ; _>>=_ to _Maybe->>=_) hiding (align; alignWith; zipWith) public -- a non-dependent eliminator maybeS : ∀ {a b} {A : Set a} {B : Set b} → (x : Maybe A) → B → ((x : A) → B) → B maybeS {B = B} x f t = maybe {B = const B} t f x maybeHsk : ∀ {A B : Set} → B → (A → B) → Maybe A → B maybeHsk b a→b = λ where nothing → b (just a) → a→b a open import Data.Maybe.Relation.Unary.Any renaming (Any to Maybe-Any; dec to Maybe-Any-dec) hiding (map; zip; zipWith; unzip ; unzipWith) public maybe-any-⊥ : ∀{a}{A : Set a} → Maybe-Any {A = A} (λ _ → ⊤) nothing → ⊥ maybe-any-⊥ () headMay : ∀ {A : Set} → List A → Maybe A headMay [] = nothing headMay (x ∷ _) = just x lastMay : ∀ {A : Set} → List A → Maybe A lastMay [] = nothing lastMay (x ∷ []) = just x lastMay (_ ∷ x ∷ xs) = lastMay (x ∷ xs) open import Data.Maybe.Properties using (just-injective) renaming (≡-dec to Maybe-≡-dec) public open import Data.Fin using (Fin; suc; zero; fromℕ; fromℕ< ; toℕ ; cast) renaming (_≟_ to _≟Fin_; _≤?_ to _≤?Fin_; _≤_ to _≤Fin_ ; _<_ to _<Fin_; inject₁ to Fin-inject₁; inject+ to Fin-inject+; inject≤ to Fin-inject≤) public fins : (n : ℕ) → List (Fin n) fins n = Vec-toList (Vec-allFin n) open import Data.Fin.Properties using (toℕ-injective; toℕ<n) renaming (<-cmp to Fin-<-cmp; <⇒≢ to <⇒≢Fin; suc-injective to Fin-suc-injective) public open import Relation.Binary.PropositionalEquality hiding (decSetoid) public open import Relation.Binary.HeterogeneousEquality using (_≅_) renaming (cong to ≅-cong; cong₂ to ≅-cong₂) public open import Relation.Binary public data Ordering : Set where LT EQ GT : Ordering compare : ℕ → ℕ → Ordering compare m n with <-cmp m n ... | tri< a ¬b ¬c = LT ... | tri≈ ¬a b ¬c = EQ ... | tri> ¬a ¬b c = GT ≡-irrelevant : ∀{a}{A : Set a} → Irrelevant {a} {A} _≡_ ≡-irrelevant refl refl = refl to-witness-lemma : ∀{ℓ}{A : Set ℓ}{a : A}{f : Maybe A}(x : Is-just f) → to-witness x ≡ a → f ≡ just a to-witness-lemma (just x) refl = refl open import Relation.Nullary hiding (Irrelevant; proof) public open import Relation.Nullary.Decidable hiding (map) public open import Data.Sum renaming ([_,_] to either; map to ⊎-map; map₁ to ⊎-map₁; map₂ to ⊎-map₂) public open import Data.Sum.Properties using (inj₁-injective ; inj₂-injective) public ⊎-elimˡ : ∀ {ℓ₀ ℓ₁}{A₀ : Set ℓ₀}{A₁ : Set ℓ₁} → ¬ A₀ → A₀ ⊎ A₁ → A₁ ⊎-elimˡ ¬a = either (⊥-elim ∘ ¬a) id ⊎-elimʳ : ∀ {ℓ₀ ℓ₁}{A₀ : Set ℓ₀}{A₁ : Set ℓ₁} → ¬ A₁ → A₀ ⊎ A₁ → A₀ ⊎-elimʳ ¬a = either id (⊥-elim ∘ ¬a) open import Data.Product renaming (map to ×-map; map₂ to ×-map₂; map₁ to ×-map₁; <_,_> to split; swap to ×-swap) hiding (zip) public fst = proj₁ open import Data.Product.Properties public module _ {ℓA} {A : Set ℓA} where NoneOfKind : ∀ {ℓ} {P : A → Set ℓ} → List A → (p : (a : A) → Dec (P a)) → Set ℓA NoneOfKind xs p = List-filter p xs ≡ [] postulate -- TODO-1: Replace with or prove using library properties? Move to Lemmas? NoneOfKind⇒ : ∀ {ℓ} {P : A → Set ℓ} {Q : A → Set ℓ} {xs : List A} → (p : (a : A) → Dec (P a)) → {q : (a : A) → Dec (Q a)} → (∀ {a} → P a → Q a) -- TODO-1: Use proper notation (Relation.Unary?) → NoneOfKind xs q → NoneOfKind xs p infix 4 _<?ℕ_ _<?ℕ_ : Decidable _<_ m <?ℕ n = suc m ≤?ℕ n infix 0 if-yes_then_else_ infix 0 if-dec_then_else_ if-yes_then_else_ : ∀ {ℓA ℓB} {A : Set ℓA} {B : Set ℓB} → Dec A → (A → B) → (¬ A → B) → B if-yes (yes prf) then f else _ = f prf if-yes (no prf) then _ else g = g prf if-dec_then_else_ : ∀ {ℓA ℓB} {A : Set ℓA} {B : Set ℓB} → Dec A → B → B → B if-dec x then f else g = if-yes x then const f else const g open import Relation.Nullary.Negation using (contradiction; contraposition) public open import Relation.Binary using (Setoid; IsPreorder) public open import Relation.Unary using (_∪_) public open import Relation.Unary.Properties using (_∪?_) public -- Injectivity for a function of two potentially different types (A and B) via functions to a -- common type (C). Injective' : ∀ {b c d e}{B : Set b}{C : Set c}{D : Set d} → (hB : B → D) → (hC : C → D) → (_≈_ : B → C → Set e) → Set _ Injective' {C = C} hB hC _≈_ = ∀ {b c} → hB b ≡ hC c → b ≈ c Injective : ∀ {c d e}{C : Set c}{D : Set d} → (h : C → D) → (_≈_ : Rel C e) → Set _ Injective h _≈_ = Injective' h h _≈_ Injective-≡ : ∀ {c d}{C : Set c}{D : Set d} → (h : C → D) → Set _ Injective-≡ h = Injective h _≡_ Injective-int : ∀{a b c d e}{A : Set a}{B : Set b}{C : Set c}{D : Set d} → (_≈_ : A → B → Set e) → (h : C → D) → (f₁ : A → C) → (f₂ : B → C) → Set (a ℓ⊔ b ℓ⊔ d ℓ⊔ e) Injective-int _≈_ h f₁ f₂ = ∀ {a₁} {b₁} → h (f₁ a₁) ≡ h (f₂ b₁) → a₁ ≈ b₁ NonInjective : ∀{a b c}{A : Set a}{B : Set b} → (_≈_ : Rel A c) → (A → B) → Set (a ℓ⊔ b ℓ⊔ c) NonInjective {A = A} _≈_ f = Σ (A × A) (λ { (x₁ , x₂) → ¬ (x₁ ≈ x₂) × f x₁ ≡ f x₂ }) NonInjective-≡ : ∀{a b}{A : Set a}{B : Set b} → (A → B) → Set (a ℓ⊔ b) NonInjective-≡ = NonInjective _≡_ NonInjective-≡-preds : ∀{a b}{A : Set a}{B : Set b}{ℓ₁ ℓ₂ : Level} → (A → Set ℓ₁) → (A → Set ℓ₂) → (A → B) → Set (a ℓ⊔ b ℓ⊔ ℓ₁ ℓ⊔ ℓ₂) NonInjective-≡-preds Pred1 Pred2 f = Σ (NonInjective _≡_ f) λ { ((a₀ , a₁) , _ , _) → Pred1 a₀ × Pred2 a₁ } NonInjective-≡-pred : ∀{a b}{A : Set a}{B : Set b}{ℓ : Level} → (P : A → Set ℓ) → (A → B) → Set (a ℓ⊔ b ℓ⊔ ℓ) NonInjective-≡-pred Pred = NonInjective-≡-preds Pred Pred NonInjective-∘ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c} → {f : A → B}(g : B → C) → NonInjective-≡ f → NonInjective-≡ (g ∘ f) NonInjective-∘ g ((x0 , x1) , (x0≢x1 , fx0≡fx1)) = ((x0 , x1) , x0≢x1 , (cong g fx0≡fx1)) -------------------------------------------- -- Handy fmap and bind for specific types -- _<M$>_ : ∀{a b}{A : Set a}{B : Set b} → (f : A → B) → Maybe A → Maybe B _<M$>_ = Maybe-map <M$>-univ : ∀{a b}{A : Set a}{B : Set b} → (f : A → B)(x : Maybe A) → {y : B} → f <M$> x ≡ just y → ∃[ x' ] (x ≡ just x' × f x' ≡ y) <M$>-univ f (just x) refl = x , (refl , refl) maybe-lift : {A : Set} → {mx : Maybe A}{x : A} → (P : A → Set) → P x → mx ≡ just x → maybe {B = const Set} P ⊥ mx maybe-lift {mx = just .x} {x} P px refl = px <M$>-nothing : ∀ {a b}{A : Set a}{B : Set b}(f : A → B) → f <M$> nothing ≡ nothing <M$>-nothing _ = refl _<⊎$>_ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c} → (A → B) → C ⊎ A → C ⊎ B f <⊎$> (inj₁ hb) = inj₁ hb f <⊎$> (inj₂ x) = inj₂ (f x) _⊎⟫=_ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c} → C ⊎ A → (A → C ⊎ B) → C ⊎ B (inj₁ x) ⊎⟫= _ = inj₁ x (inj₂ a) ⊎⟫= f = f a -- Syntactic support for more faithful model of Haskell code Either : ∀ {a b} → Set a → Set b → Set (a ℓ⊔ b) Either A B = A ⊎ B pattern Left x = inj₁ x pattern Right x = inj₂ x isLeft : ∀ {a b} {A : Set a} {B : Set b} → Either A B → Bool isLeft (Left _) = true isLeft (Right _) = false isRight : ∀ {a b} {A : Set a} {B : Set b} → Either A B → Bool isRight = Data.Bool.not ∘ isLeft -- a non-dependent eliminator eitherS : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} (x : Either A B) → ((x : A) → C) → ((x : B) → C) → C eitherS eab fa fb = case eab of λ where (Left a) → fa a (Right b) → fb b module _ {ℓ₀ ℓ₁ ℓ₂ : Level} where EL-type = Set ℓ₁ → Set ℓ₂ → Set ℓ₀ EL-level = ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₀ -- Utility to make passing between `Either` and `EitherD` more convenient record EitherLike (E : EL-type) : Set (ℓ+1 EL-level) where field fromEither : ∀ {A : Set ℓ₁} {B : Set ℓ₂} → Either A B → E A B toEither : ∀ {A : Set ℓ₁} {B : Set ℓ₂} → E A B → Either A B open EitherLike ⦃ ... ⦄ public EL-func : EL-type → Set (ℓ+1 EL-level) EL-func EL = ⦃ mel : EitherLike EL ⦄ → Set EL-level instance EitherLike-Either : ∀ {ℓ₁ ℓ₂} → EitherLike{ℓ₁ ℓ⊔ ℓ₂}{ℓ₁}{ℓ₂} Either EitherLike.fromEither EitherLike-Either = id EitherLike.toEither EitherLike-Either = id -- an approximation of Haskell's backtick notation for making infix operators; in Agda, must have -- spaces between f and backticks flip' : _ -- Avoids warning about definition and syntax declaration being in different scopes flip' = flip syntax flip' f = ` f ` open import Data.String as String hiding (_==_ ; _≟_ ; concat) check : Bool → List String → Either String Unit check b t = if b then inj₂ unit else inj₁ (String.intersperse "; " t) -- TODO-1: Maybe this belongs somewhere else? It's in a similar -- category as Optics, so maybe should similarly be in a module that -- is separate from the main project? ------------------ -- Guard Syntax -- -- -- Example Usage: -- -- > f : ℕ → ℕ -- > f x = grd‖ x ≟ℕ 10 ≔ 12 -- > ‖ otherwise≔ 40 + 2 -- -- -- > g : ℕ ⊎ ℕ → ℕ -- > g x = case x of λ -- > { (inj₁ x) → grd‖ x ≤? 10 ≔ 2 * x -- > ‖ otherwise≔ 42 -- > ; (inj₂ y) → y -- > } -- -- To type: ‖ --> \Vert -- ≔ --> \:= record ToBool {a}(A : Set a) : Set a where field toBool : A → Bool open ToBool {{ ... }} public not : ∀ {b} {B : Set b} ⦃ _ : ToBool B ⦄ → B → Bool not b = Data.Bool.not (toBool b) instance ToBool-Bool : ToBool Bool ToBool-Bool = record { toBool = id } ToBool-Dec : ∀{a}{A : Set a} → ToBool (Dec A) ToBool-Dec = record { toBool = ⌊_⌋ } toWitnessT : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ true → P toWitnessT {d = yes proof} _ = proof toWitnessF : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ false → ¬ P toWitnessF{d = no proof} _ = proof infix 3 _≔_ data GuardClause {a}{b}(A : Set a) : Set (a ℓ⊔ ℓ+1 b) where _≔_ : {B : Set b}{{ bb : ToBool B }} → B → A → GuardClause A infix 3 otherwise≔_ data Guards {a}{b}(A : Set a) : Set (a ℓ⊔ ℓ+1 b) where otherwise≔_ : A → Guards A clause : GuardClause{a}{b} A → Guards{a}{b} A → Guards A infixr 2 _‖_ _‖_ : ∀{a}{b}{A : Set a} → GuardClause{a}{b} A → Guards A → Guards A _‖_ = clause infix 1 grd‖_ grd‖_ : ∀{a}{b}{A : Set a} → Guards{a}{b} A → A grd‖_ (otherwise≔ a) = a grd‖_ (clause (b ≔ a) g) = if toBool b then a else (grd‖ g) Any-satisfied-∈ : ∀{a ℓ}{A : Set a}{P : A → Set ℓ}{xs : List A} → Any P xs → Σ A (λ x → P x × x ∈ xs) Any-satisfied-∈ (here px) = _ , (px , here refl) Any-satisfied-∈ (there p) = let (a , px , prf) = Any-satisfied-∈ p in (a , px , there prf) f-sum : ∀{a}{A : Set a} → (A → ℕ) → List A → ℕ f-sum f = sum ∘ List-map f record Functor {ℓ₁ ℓ₂ : Level} (F : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where infixl 4 _<$>_ field _<$>_ : ∀ {A B : Set ℓ₁} → (A → B) → F A → F B fmap = _<$>_ open Functor ⦃ ... ⦄ public record Applicative {ℓ₁ ℓ₂ : Level} (F : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where infixl 4 _<*>_ field pure : ∀ {A : Set ℓ₁} → A → F A _<*>_ : ∀ {A B : Set ℓ₁} → F (A → B) → F A → F B open Applicative ⦃ ... ⦄ public instance ApplicativeFunctor : ∀ {ℓ₁ ℓ₂} {F : Set ℓ₁ → Set ℓ₂} ⦃ _ : Applicative F ⦄ → Functor F Functor._<$>_ ApplicativeFunctor f xs = pure f <*> xs record Monad {ℓ₁ ℓ₂ : Level} (M : Set ℓ₁ → Set ℓ₂) : Set (ℓ₂ ℓ⊔ ℓ+1 ℓ₁) where infixl 1 _>>=_ _>>_ field return : ∀ {A : Set ℓ₁} → A → M A _>>=_ : ∀ {A B : Set ℓ₁} → M A → (A → M B) → M B _>>_ : ∀ {A B : Set ℓ₁} → M A → M B → M B m₁ >> m₂ = m₁ >>= λ _ → m₂ open Monad ⦃ ... ⦄ public instance MonadApplicative : ∀ {ℓ₁ ℓ₂} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → Applicative M Applicative.pure MonadApplicative = return Applicative._<*>_ MonadApplicative fs xs = do f ← fs x ← xs return (f x) instance Monad-Either : ∀ {ℓ}{C : Set ℓ} → Monad{ℓ}{ℓ} (Either C) Monad.return (Monad-Either{ℓ}{C}) = inj₂ Monad._>>=_ (Monad-Either{ℓ}{C}) = either (const ∘ inj₁) _&_ Monad-Maybe : ∀ {ℓ} → Monad {ℓ} {ℓ} Maybe Monad.return (Monad-Maybe{ℓ}) = just Monad._>>=_ (Monad-Maybe{ℓ}) = _Maybe->>=_ Monad-List : ∀ {ℓ} → Monad {ℓ}{ℓ} List Monad.return Monad-List x = x ∷ [] Monad._>>=_ Monad-List x f = concat (List-map f x) maybeSMP : ∀ {ℓ} {A B : Set} {m : Set → Set ℓ} ⦃ _ : Monad m ⦄ → m (Maybe A) → B → (A → m B) → m B maybeSMP ma b f = do x ← ma case x of λ where nothing → pure b (just j) → f j fromMaybeM : ∀ {ℓ} {A : Set} {m : Set → Set ℓ} ⦃ _ : Monad m ⦄ → m A → m (Maybe A) → m A fromMaybeM ma mma = do mma >>= λ where nothing → ma (just a) → pure a forM_ : ∀ {ℓ} {A B : Set} {M : Set → Set ℓ} ⦃ _ : Monad M ⦄ → List A → (A → M B) → M Unit forM_ [] _ = return unit forM_ (x ∷ xs) f = f x >> forM_ xs f -- NOTE: because 'forM_' is defined above, it is necessary to -- call 'forM' with parenthesis (e.g., recursive call in definition) -- to disambiguate it for the Agda parser. forM : ∀ {ℓ} {A B : Set} {M : Set → Set ℓ} ⦃ _ : Monad M ⦄ → List A → (A → M B) → M (List B) forM [] _ = return [] forM (x ∷ xs) f = do fx ← f x fxs ← (forM) xs f return (fx ∷ fxs) foldrM : ∀ {ℓ₁ ℓ₂} {A B : Set ℓ₁} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → (A → B → M B) → B → List A → M B foldrM _ b [] = return b foldrM f b (a ∷ as) = foldrM f b as >>= f a foldlM : ∀ {ℓ₁ ℓ₂} {A B : Set ℓ₁} {M : Set ℓ₁ → Set ℓ₂} ⦃ _ : Monad M ⦄ → (B → A → M B) → B → List A → M B foldlM _ z [] = pure z foldlM f z (x ∷ xs) = do z' ← f z x foldlM f z' xs foldM = foldlM foldM_ : {A B : Set} {M : Set → Set} ⦃ _ : Monad M ⦄ → (B → A → M B) → B → List A → M Unit foldM_ f a xs = foldlM f a xs >> pure unit open import LibraBFT.Base.Util public record Eq {a} (A : Set a) : Set a where infix 4 _≟_ _==_ _/=_ field _≟_ : (a b : A) → Dec (a ≡ b) _==_ : A → A → Bool a == b = toBool $ a ≟ b _/=_ : A → A → Bool a /= b = not (a == b) open Eq ⦃ ... ⦄ public elem : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → A → List A → Bool elem x = toBool ∘ Any-any (x ≟_) instance Eq-Nat : Eq ℕ Eq._≟_ Eq-Nat = _≟ℕ_ Eq-Maybe : ∀ {a} {A : Set a} ⦃ _ : Eq A ⦄ → Eq (Maybe A) Eq._≟_ Eq-Maybe nothing nothing = yes refl Eq._≟_ Eq-Maybe (just _) nothing = no λ () Eq._≟_ Eq-Maybe nothing (just _) = no λ () Eq._≟_ Eq-Maybe (just a) (just b) with a ≟ b ... | no proof = no λ where refl → proof refl ... | yes refl = yes refl infixl 9 _!?_ _!?_ : {A : Set} → List A → ℕ → Maybe A [] !? _ = nothing (x ∷ _ ) !? 0 = just x (_ ∷ xs) !? (suc n) = xs !? n -- Like a Haskell list-comprehension for ℕ : [ n | n <- [from .. to] ] fromToList : ℕ → ℕ → List ℕ fromToList from to with from ≤′? to ... | no ¬pr = [] ... | yes pr = fromToList-le from to pr [] where fromToList-le : ∀ (from to : ℕ) (klel : from ≤′ to) (acc : List ℕ) → List ℕ fromToList-le from ._ ≤′-refl acc = from ∷ acc fromToList-le from (suc to) (≤′-step klel) acc = fromToList-le from to klel (suc to ∷ acc) _ : fromToList 1 1 ≡ 1 ∷ [] _ = refl _ : fromToList 1 2 ≡ 1 ∷ 2 ∷ [] _ = refl _ : fromToList 2 1 ≡ [] _ = refl
(* 7. Hierarchies *) (* 7.1 Structure interface *) (* Mathcomp Book Z-module *) (* algebra/zmodp.v をもとに、修正した。 *) From mathcomp Require Import all_ssreflect. From mathcomp Require Import fintype finset fingroup ssralg finalg. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Section Ord. (* ordinal の定義 *) Locate "'I_ _". (* ordinal n *) Print ordinal. (* Inductive ordinal (n : nat) : predArgType := Ordinal : forall m : nat, m < n -> 'I_n *) Check @Ordinal : forall n m : nat, m < n -> 'I_n. (* Ordinal n m H : 'I_n Ordinal は値コンストラクタであり、'I_n 型の(自然数にすると)m になる値である。 H2_3 は m < n であることの証明。 *) Variable H2_3 : 2 < 3. Check @Ordinal 3 2 H2_3 : 'I_3. End Ord. Section ZpDef. Variable p' : nat. Local Notation p := p'.+1. Implicit Types x y z : 'I_p. Check 'I_p : predArgType. (* dが0より大きいとき、dで割った余りは、dより小さい。 *) Check ltn_pmod : forall m d : nat, 0 < d -> m %% d < d. (* +1 したものは、0より大きい。 *) Check ltn0Sn : forall n : nat, 0 < n.+1. (* Standard injection; val (inZp i) = i %% p *) (* 'I_p 型の(自然数にすると)(i %% p) になる値である。 *) Definition inZp i := @Ordinal p (i %% p) (ltn_pmod i (ltn0Sn p')). (* Definition inZp i := Ordinal (ltn_pmod i (ltn0Sn p')). *) Check inZp 0 : 'I_p. Check inZp p.-1 : 'I_p. Check inZp p : 'I_p. Check inZp p.+1 : 'I_p. (* *************** *) (* zmod Operations *) (* *************** *) Definition Zp0 : 'I_p := ord0. Definition Zp1 := inZp 1. Definition Zp_opp x := inZp (p - x). Definition Zp_add x y := inZp (x + y). Definition Zp_mul x y := inZp (x * y). Definition Zp_inv x := if coprime p x then inZp (egcdn x p).1 else x. (* coprime 互いに素。egcdn 拡張GCD。 *) (* Additive group structure. *) Lemma modZp x : x %% p = x. Proof. by rewrite modn_small ?ltn_ord. Qed. Lemma modZp2 x : x %% p = (x + p) %% p. (* suhara *) Proof. rewrite modnDr. by rewrite modn_small ?ltn_ord. Qed. Lemma modZp3 x : forall m n, (x + m * p) %% p = (x + n * p) %% p. (* suhara *) Proof. move=> m n. rewrite addnC modnMDl. rewrite addnC modnMDl. done. Qed. Lemma valZpK x : inZp x = x. Proof. by apply: val_inj; rewrite /= modZp. Qed. Lemma valZpK2 x : inZp x = inZp (x + p). (* suhara *) Proof. apply: val_inj. Check val : 'I_p -> nat. (* これが単射であることをつかう。 *) rewrite /= modZp2. done. Restart. by apply: val_inj; rewrite /= modZp2. Qed. Lemma valZpK3 x : forall m n, inZp (x + m * p) = inZp (x + n * p). (* suhara *) Proof. move=> m n. apply: val_inj. rewrite /=. Check modZp3 x m n. by rewrite (modZp3 x m n). Qed. Lemma Zp_add0z : left_id Zp0 Zp_add. Proof. exact: valZpK. Qed. Lemma Zp_addNz : left_inverse Zp0 Zp_opp Zp_add. Proof. by move=> x; apply: val_inj; rewrite /= modnDml subnK ?modnn // ltnW. Qed. Lemma Zp_addA : associative Zp_add. Proof. by move=> x y z; apply: val_inj; rewrite /= modnDml modnDmr addnA. Qed. Lemma Zp_addC : commutative Zp_add. Proof. by move=> x y; apply: val_inj; rewrite /= addnC. Qed. Fail Check inZp 0 + inZp 1. (* zmod : additive abelian groups , see ssralg *) Definition Zp_zmodMixin := ZmodMixin Zp_addA Zp_addC Zp_add0z Zp_addNz. (* ssralg *) Canonical Zp_zmodType := Eval hnf in ZmodType 'I_p Zp_zmodMixin. (* ssralg *) Canonical Zp_finZmodType := Eval hnf in [finZmodType of 'I_p]. (* finalg *) Canonical Zp_baseFinGroupType := Eval hnf in [baseFinGroupType of 'I_p for +%R]. Canonical Zp_finGroupType := Eval hnf in [finGroupType of 'I_p for +%R]. (* *************** *) (* Ring operations *) (* *************** *) Lemma Zp_mul1z : left_id Zp1 Zp_mul. Proof. by move=> x; apply: val_inj; rewrite /= modnMml mul1n modZp. Qed. Lemma Zp_mulC : commutative Zp_mul. Proof. by move=> x y; apply: val_inj; rewrite /= mulnC. Qed. Lemma Zp_mulz1 : right_id Zp1 Zp_mul. Proof. by move=> x; rewrite Zp_mulC Zp_mul1z. Qed. Lemma Zp_mulA : associative Zp_mul. Proof. by move=> x y z; apply: val_inj; rewrite /= modnMml modnMmr mulnA. Qed. Lemma Zp_mul_addr : right_distributive Zp_mul Zp_add. Proof. by move=> x y z; apply: val_inj; rewrite /= modnMmr modnDm mulnDr. Qed. Lemma Zp_mul_addl : left_distributive Zp_mul Zp_add. Proof. by move=> x y z; rewrite -!(Zp_mulC z) Zp_mul_addr. Qed. Lemma Zp_mulVz x : coprime p x -> Zp_mul (Zp_inv x) x = Zp1. Proof. move=> co_p_x; apply: val_inj; rewrite /Zp_inv co_p_x /= modnMml. by rewrite -(chinese_modl co_p_x 1 0) /chinese addn0 mul1n mulnC. Qed. Lemma Zp_mulzV x : coprime p x -> Zp_mul x (Zp_inv x) = Zp1. Proof. by move=> Ux; rewrite /= Zp_mulC Zp_mulVz. Qed. Lemma Zp_intro_unit x y : Zp_mul y x = Zp1 -> coprime p x. Proof. case=> yx1; have:= coprimen1 p. by rewrite -coprime_modr -yx1 coprime_modr coprime_mulr; case/andP. Qed. Lemma Zp_inv_out x : ~~ coprime p x -> Zp_inv x = x. Proof. by rewrite /Zp_inv => /negPf->. Qed. Lemma Zp_mulrn x n : x *+ n = inZp (x * n). Proof. apply: val_inj => /=; elim: n => [|n IHn]; first by rewrite muln0 modn_small. by rewrite !GRing.mulrS /= IHn modnDmr mulnS. Qed. Import GroupScope. Lemma Zp_mulgC : @commutative 'I_p _ mulg. Proof. exact: Zp_addC. Qed. Lemma Zp_abelian : abelian [set: 'I_p]. Proof. exact: FinRing.zmod_abelian. Qed. Lemma Zp_expg x n : x ^+ n = inZp (x * n). Proof. exact: Zp_mulrn. Qed. Lemma Zp1_expgz x : Zp1 ^+ x = x. Proof. by rewrite Zp_expg; apply: Zp_mul1z. Qed. Lemma Zp_cycle : setT = <[Zp1]>. Proof. by apply/setP=> x; rewrite -[x]Zp1_expgz inE groupX ?mem_gen ?set11. Qed. Lemma order_Zp1 : #[Zp1] = p. Proof. by rewrite orderE -Zp_cycle cardsT card_ord. Qed. End ZpDef. Implicit Arguments Zp0 [[p']]. Implicit Arguments Zp1 [[p']]. Implicit Arguments inZp [[p']]. Section ZpRing. Variable p' : nat. Local Notation p := p'.+2. Check 'I_p. Check Zp1 : 'I_p. Check 0 : 'I_p. Lemma Zp_nontrivial : Zp1 != 0 :> 'I_p. Proof. by []. Qed. Print GRing.ComRing.RingMixin. Definition Zp_ringMixin := ComRingMixin (@Zp_mulA _) (@Zp_mulC _) (@Zp_mul1z _) (@Zp_mul_addl _) Zp_nontrivial. Canonical Zp_ringType := Eval hnf in RingType 'I_p Zp_ringMixin. Canonical Zp_finRingType := Eval hnf in [finRingType of 'I_p]. Canonical Zp_comRingType := Eval hnf in ComRingType 'I_p (@Zp_mulC _). Canonical Zp_finComRingType := Eval hnf in [finComRingType of 'I_p]. (* inverse の unit をもつ ring *) Definition Zp_unitRingMixin := ComUnitRingMixin (@Zp_mulVz _) (@Zp_intro_unit _) (@Zp_inv_out _). Canonical Zp_unitRingType := Eval hnf in UnitRingType 'I_p Zp_unitRingMixin. Canonical Zp_finUnitRingType := Eval hnf in [finUnitRingType of 'I_p]. Canonical Zp_comUnitRingType := Eval hnf in [comUnitRingType of 'I_p]. Canonical Zp_finComUnitRingType := Eval hnf in [finComUnitRingType of 'I_p]. Lemma Zp_nat n : n%:R = inZp n :> 'I_p. Proof. by apply: val_inj; rewrite [n%:R]Zp_mulrn /= modnMml mul1n. Qed. Lemma natr_Zp (x : 'I_p) : x%:R = x. Proof. by rewrite Zp_nat valZpK. Qed. Lemma natr_negZp (x : 'I_p) : (- x)%:R = - x. Proof. by apply: val_inj; rewrite /= Zp_nat /= modn_mod. Qed. Import GroupScope. Lemma unit_Zp_mulgC : @commutative {unit 'I_p} _ mulg. Proof. by move=> u v; apply: val_inj; rewrite /= GRing.mulrC. Qed. Lemma unit_Zp_expg (u : {unit 'I_p}) n : val (u ^+ n) = inZp (val u ^ n) :> 'I_p. Proof. apply: val_inj => /=; elim: n => [|n IHn] //. by rewrite expgS /= IHn expnS modnMmr. Qed. End ZpRing. Definition Zp_trunc p := p.-2. Notation "''Z_' p" := 'I_(Zp_trunc p).+2 (at level 8, p at level 2, format "''Z_' p") : type_scope. Section EQ. Variable p' : nat. Local Notation p := p'.+1. Canonical Zp_eqType := [eqType of 'Z_p]. Goal inZp 1 = inZp 1 :> 'Z_p. Proof. rewrite /inZp. Undo 1. by apply/eqP. Qed. End EQ. (* ***** *) (* Mathcomp Book Original *) (* ***** *) Section MCB. Variable m n : nat. Definition Zmn := ('Z_m * 'Z_n)%type. Canonical Zmn_eqType := [eqType of Zmn]. Canonical Zmn_zmodType := [zmodType of Zmn]. Canonical Zmn_ringType := [ringType of Zmn]. Check 0 : 'Z_m. Check 0 : 'Z_n. Check (0, 0) : Zmn. Goal (0, 0) = (0, 0) :> Zmn. Proof. by apply/eqP. Qed. (* have Zp_mulrAC := @mulrAC [ringType of 'Z_p]. *) End MCB. (* END *) Check @Zp0 3 : 'I_4. Check @inZp 3 0 : 'I_4. (* 0 *) Check @Zp1 3 : 'I_4. Check @inZp 3 1 : 'I_4. (* 1 *) Check @inZp 3 2 : 'I_4. (* 2 *) Check @inZp 3 3 : 'I_4. (* 3 *) Check @inZp 3 4 : 'I_4. (* 0 *) Check @inZp 3 5 : 'I_4. (* 1 *) Check @inZp 3 6 : 'I_4. (* 2 *) Check @inZp 3 7 : 'I_4. (* 3 *) Goal @inZp 3 0 = @inZp 3 4. Proof. Check 0 : 'I_4. Fail Check 4 : 'I_4. Check inZp 0 : 'I_4. Check inZp 4 : 'I_4. Set Printing Implicit. (* XXXX *) Check @valZpK2 3 0. apply (@valZpK2 3 0). Qed. Locate "_ + _". (* Zmodule の add でない。 *)
## Introduction The WBK method is an approximation technique for approximating solutions to the time-independent Schrödinger equation with non-constant potential. It is named after Wentzel, Kramers, and Brillouin. In 1923, three years prior to the development of the WKB method, a British mathematician Harold Jeffreys also developed it. But it was not very popular back then. In England, people also call it the JWKB method for the contribution made by Jeffreys. ## Derivation of WKB The Schrödinger equation with non-constant potential is, \begin{equation} -\frac{\hbar^2}{2m} \frac{d^2 \psi}{dx^2} + V(x)\psi = E\psi. \end{equation} We assume $E>V(x)$ and rewrite it as \begin{equation} \frac{d^2 \psi}{dx^2}= -\frac{p^2}{\hbar^2} \psi, \end{equation} where $p(x)=\sqrt{2m[E-V(x)]}$ is the classical momentum of a particle with total energy E and potential $V(x)$. The general solution of this equation has the form \begin{equation} \psi(x) = A(x)e^{i\phi(x)}, \end{equation} where $A(x)$ is the amplitude and $\phi(x)$ is the phase, both as a function of x. Then we can calculate the first and the second derivative of $\psi$ and plug them back to the Schrödinger equation to get \begin{equation} A'' + 2i A' \phi' + iA\phi'' - A(\phi')^2 = - \frac{p^2}{\hbar^2}A. \end{equation} The real and imaginary part each gives us an equation. The imaginary part is \begin{equation} 2A'\phi' + A\phi'' = 0. \end{equation} Its solution is \begin{equation} A = \frac{C}{\sqrt{\phi'}}, \end{equation} where $C$ is a real number. The real part is \begin{equation} A'' - A (\phi')^2 = -\frac{p^2}{\hbar^2}A. \end{equation} Unfortunately this equation cannot be solved in most cases. Here, the approximation comes in. By assuming $A(x)$ varies slowly as a function of $x$, we can make $A''=0$. Then we can solve it to get \begin{equation} \phi(x) = \pm \frac{1}{\hbar} \int p(x)dx. \end{equation} Therefore, the general solution is given by \begin{equation} \psi(x) = \frac{C}{\sqrt{p(x)}} e^{\pm \frac{i}{\hbar} \int p(x)dx}. \end{equation} For $E<V$, we need to take $p(x)$ to absolute value to keep it a real function. Please see Chapter 8 of Griffiths' Introduction to Quantum Mechanics for a more detailed discussion. Professor Barton Zwiebach's lecture presented another derivation. It's very interesting as well. ## Validity of WKB The argument we used in the derivation for the approximation is rather mathematical. A more physical way to look it is that the probability of finding a particle at location $x$ is inversely proportional to its momentum. It agrees with our intuition. If a particle moves fast at one location, it's less likely to be found by us. Professor Zwiebach derived some more formal inequalities to justify the validity of the WKB approximation. Dropping the second derivative term leads to the inequality. \begin{equation} \lambda \frac{d \lambda(x)}{dx} << \lambda. \end{equation} There are several others, but this one makes the most sense physically. It says that the wavelength change over one de Broglie wavelength is much smaller than the de Broglie wavelength itself. This is the physical assumption of this approximation. For a potential barrier with sloping walls, if the energy of the incoming particle is less than the potential of the barrier in one portion of it. The points where $E=V$ is called the turning points. The WKB method is only valid away from those turning points. As we move close to the turning points, the derivative of the local de Broglie wavelength blows up. ## The Connection Formulas To approximate the solution near the turning points, people developed the connection formulas. Its derivation is rather involved. So I decide to not talk about it here. The idea is that we use a straight line to approximate the potential near the turning points. Then find a "patching" wave function to connect both sides. The connection formulas that joining the WKB solutions at a turning point $x_1$ is \begin{equation} \psi(x) = \begin{cases} & \frac{2D}{\sqrt{p(x)}} sin[ \frac{1}{\hbar} \int_{x}^{x_1}p(x')dx' + \frac{\pi}{4} ], \quad \text{if } x<x_1; \\ & \frac{D}{\sqrt{|p(x)|}} exp[ -\frac{1}{\hbar} \int_{x}^{x_1}p(x')dx' + \frac{\pi}{4} ], \quad \text{if } x>x_1. \\ \end{cases} \end{equation} Using WKB with connection formulas, we can calculate the bound state energies and transmission coefficient without actually solving the Schrödinger equation. ## Analytical Solution of a Finite Rectangular Potential Barrier We derived the expressions for the transmission coefficient the conditions that the wave function and its first derivative must be continues everywhere. We wrote down the boundary conditions \begin{aligned} \psi_1 (0) &= \psi_2 (0) \\ \psi_1' (0) &= \psi_2' (0) \\ \psi_2 (L) &= \psi_3 (L) \\ \psi_2' (L) &= \psi_3' (L). \end{aligned} Then we solved for the transmission coefficient $T$ for three cases: $E<V_0$, $E>V_0$, and $E=V_0$. We have done one of those three cases in homework 4. The other two are similar. ### Case 1: $E<V_0$ We have \begin{equation} T = \bigg[ 1 + \frac{V_0^2 sinh^2(k L)}{4E(V_0-E)} \bigg]^{-1}, \end{equation} where $k=\sqrt{2m(V_0 - E)} / \hbar$. This is the quantum tunneling case. Classically, particles with energy less than the potential barrier have zero chance going through. But in a quantum system, the particle has some probability tunneling through. This probability is exponentially decayed as the width of of the barrier increases. ### Case 2: $E>V_0$ \begin{equation} T = \bigg[ 1 + \frac{V_0^2 sin^2(k L)}{4E(E-V_0)} \bigg]^{-1}, \end{equation} where $k=\sqrt{2m(E - V_0)} / \hbar$. Classically, particles with energy greater than the potential barrier would go through certainly. But the quantum scenario, the transmission coefficient actually oscillates as a function of the width and potential of the barrier and the energy of the particle. ### Case 3: $E=V_0$ \begin{equation} T = \bigg[ 1 + mL^2 V_0 / 2\hbar^2 \bigg]^{-1}. \end{equation} In the case $E=V_0$ the transmission coefficient depends on the width and potential of the barrier. ### Plot of the Transmission Coefficient T In the following graph, I plotted the three cases separately and combined them to form a single graph. We can see the exponential decay of the transmission coefficient as the width of the barrier increases. And in the region that $E>V_0$, $T$ oscillates and trends to 1. ```python import numpy as np import scipy.constants as sc import matplotlib.pyplot as plt # suppress divide by zero warnings import warnings; warnings.simplefilter('ignore') ``` ```python # constants are imported from the scipy physical constants library hbar = sc.physical_constants['reduced Planck constant in eV s'][0] m_e = sc.physical_constants['electron mass energy equivalent'][0] ``` ```python T_l = lambda e_, l_, v_: (1 + (v_**2 * np.sinh(l_*np.sqrt(2*m_e*(v_-e_))/hbar)**2)/(4*e_*(v_-e_)))**-1 T_eq = lambda e_, l_, v_: (1 + m_e*l_**2 * v_ / (2*hbar**2))**-1 T_g = lambda e_, l_, v_: (1 + (v_**2 * np.sin(l_*np.sqrt(2*m_e*(e_-v_))/hbar)**2)/(4*e_*(e_-v_)))**-1 ``` ```python n = 100 l = 10E-9 # m vs = [0.05, 0.1, 0.5, 1] # eV plt.figure() for v in vs: es_lv = np.linspace(0, v*((n-1)/n), n-1) es_gv = np.linspace(v*((n+1)/n), v*3, n*2) es = np.append(es_lv, v) es = np.concatenate((es, es_gv)) leq = np.append(T_l(es_lv, l, v), T_eq(v, l, v)) Ts = np.concatenate((leq, T_g(es_gv, l, v))) es_v = es / v plt.plot(es_v, Ts, label=f'v={v} eV') plt.vlines(1, 0, 1, linestyles='dashed') plt.xlabel('E / V_0') plt.ylabel('T') plt.legend() plt.show() ``` ## The WKB approximation of a Finite Rectangular Potential Barrier ### WKB inside of the Barrier Since the wave function of an electron passing through a finite rectangular potential barrier is known. We can compare the exact analytical solution with the one getting from the WKB approximation. The first thing I tried is to solve for the transmission coefficient using the WKB wave function inside the barrier. \begin{equation} \psi_2(x) = \frac{C}{\sqrt{p}} e^{\frac{p}{\hbar}x} + \frac{D}{\sqrt{p}} e^{-\frac{p}{\hbar}x}, \\ \end{equation} where $p=\sqrt{2m(V_0 - E)}$. The phase part is the result of the integral $\int_{0}^{L}|p(x')|dx'$. Then we use the boundary conditions to solve for the transmission coefficient T. \begin{align} T = \bigg\vert \frac{F}{A} \bigg\vert^2 = \bigg\vert \bigg[ \frac{1}{2} e^{ikL-\frac{pL}{\hbar}} \big(1+\frac{p}{ik\hbar} \big) \big(1+\frac{ik\hbar}{p} \big) + \frac{1}{2} e^{ikL+\frac{pL}{\hbar}} \big(1-\frac{p}{ik\hbar} \big) \big(1-\frac{ik\hbar}{p} \big) \bigg]^{-1} \bigg\vert^2. \end{align} This equation could be farther simplified. But since we are plotting it with a program. This form works perfectly fine. For a rectangular potential barrier with a flat top. The second derivative term of the amplitude of the wave equation is zero. So dropping it in the approximation would not affect the result. Any of its deviation from the exact analytical solution should be because WKB doesn't work very well near the boundaries. ### WKB for Potential with Sloping Walls The way of getting the exponential decay part of the transmission coefficient was presented in both homework 4 and the Griffiths book. It's give by \begin{equation} T \approx e^{-2\gamma}, \\ \end{equation} where $\gamma = \frac{1}{\hbar}\int_0^L |p(x)|dx$. The problem 8.10 of the Griffiths book also talks about the WKB solution of a scattering from barrier with sloping walls. It uses the connection formula. The expression is \begin{equation} T = \frac{e^{-2\gamma}}{ [1-(e^{-\gamma /2})^2]^2 }, \\ \end{equation} where $\gamma = \frac{1}{\hbar}\int_0^L |p(x)|dx$. I'm not sure if it applies to a finite rectangular potential barrier with vertical walls. But it would be interesting to see how it looks. ```python gamma = lambda e_, l_, v_: np.exp(l_/hbar*np.sqrt(2*m_e*(v_-e_))) T_wkb = lambda e_, l_, v_: np.exp(-2*gamma(e_, l_, v_)) / np.power(1 - np.power(np.exp(-gamma(e_, l_, v_)/2), 2), 2) p = lambda e_, v_: np.sqrt(2*m_e*(v_ - e_)) k = lambda e_: np.sqrt(2*m_e*e_)/hbar T_test = lambda e_, v_, l_: np.power(np.absolute( ((1+p(e_, v_)/(k(e_)*hbar*1j))*(0.5*np.exp(k(e_)*l_*1j - p(e_, v_)*l_/hbar)*(1+(k(e_)*hbar*1j)/p(e_, v_))) + (1-p(e_, v_)/(k(e_)*hbar*1j))*(0.5*np.exp(k(e_)*l_*1j + p(e_, v_)*l_/hbar)*(1-(k(e_)*hbar*1j)/p(e_, v_))))**-1 ) , 2) ``` ```python l = 10E-9 v = 1 es_lv = np.linspace(0, v*((n-1)/n), n-1) es_vv = es_lv / v plt.plot(es_vv, T_test(es_lv, v, l), label='WKB') plt.plot(es_vv, T_wkb(es_lv, l, v), label='WKB-connection') plt.plot(es_vv, T_l(es_lv, l, v), label='Analytical') plt.xlabel('E / V_0') plt.ylabel('T') plt.legend() plt.show() ``` The results agree with the approximation. As the energy of the particle approaches the potential of the barrier, the transmission coefficient starts to deviate from the exact solution. ```python l = 5E-9 v = 1 es_lv = np.linspace(0, v*((n-1)/n), n-1) es_vv = es_lv / v plt.plot(es_vv, T_test(es_lv, v, l), label='WKB') plt.plot(es_vv, T_wkb(es_lv, l, v), label='WKB-connection') plt.plot(es_vv, T_l(es_lv, l, v), label='Analytical') plt.xlabel('E / V_0') plt.ylabel('T') plt.legend() plt.show() ``` Another assumption of the WKB approximation is that the size of the aperture is much larger than the de Broglie wavelength of the incoming particle. So I reduced the width of the potential barrier by half and tested how it affects the transmission coefficient T. For the exact solution, T increases overall. It agrees with our intuition since a particle is more likely to tunnel through a narrower potential barrier. But in this case, the WKB solution deviates even more from the exact solution. ## References - Griffiths, D. J. (2004). Introduction to Quantum Mechanics (2nd Edition). Pearson Prentice Hall. ISBN: 0131118927 - Barton Zwiebach. 8.06 Quantum Physics III. Spring 2018. Massachusetts Institute of Technology: MIT OpenCourseWare, https://ocw.mit.edu. License: Creative Commons BY-NC-SA.
Figures for top states show firstly the states where most people called ALCARAZ live. This obviously tends to be biased towards the most populous states. The second set of figures show where people called ALCARAZ represent the biggest proportion of the population. So, in this case, there are more people called ALCARAZ in California than any other state, but you are more likely to find a ALCARAZ by picking someone at random in California than anywhere else. The following names have similar spellings or pronunciations as ALCARAZ. The following words are slight variants of ALCARAZ that are likely to be possible typos or misspellings in written material.
Our Board of Directors has just released our 2019-2022 strategic plan to enhance our organization and support our mission to provide a non-judgmental home with compassionate care for people living with HIV. In its 25th year serving people living with HIV, Hope House is seeking outstanding individuals to start as Care Partners for various shifts throughout the week. Each year on the first Monday in August, Hope House takes over the St. Croix River! The Scott Zahren Memorial Cruise – Cruize for a Cauze, is a casual cocktail affair with live music, dinner, and dancing. Started in 1991, Hope House is an Adult Foster Care Organization that provides services to persons living with HIV who otherwise could not live independently. Hope House of St. Croix Valley was founded in 1991 by two St. Croix Valley residents, Teresa and Casey vanderBent. Their research on AIDS housing found that people living with AIDS were an almost invisible group receiving the least amount of services in Washington County and that Minnesotans with AIDS had few housing opportunities. In April 1991, a Board of Directors was formed, reflecting the organization’s strong community support. Hope House of St. Croix Valley was incorporated on May 7, 1991 and was granted tax-exempt status on September 30, 1991.
function [efeaturesdj, adjlistdj] = mcmcGetAllEdgeData(spfeatures, imsegs, adjlist) for f = 1:numel(imsegs) disp([num2str(f) ': getting edge data']) npertype = imsegs(f).nseg*4; [efeaturesdj{f}, adjlistdj{f}] = mcmcGetDisjointEdgeData(imsegs(f), spfeatures{f}, npertype, adjlist{f}); disp(num2str([imsegs(f).nseg size(adjlist{f}, 1) size(adjlistdj{f},1)])) end
function scatter3sph(X,Y,Z,varargin) %SCATTER3SPH (X,Y,Z) Plots a 3d scatter plot with 3D spheres % SCATTER3SPH is like scatter3 only drawing spheres with volume, instead % of flat circles, at coordinates specified by vectors X, Y, Z. All three % vectors have to be of the same length. % SCATTER3SPH(X,Y,Z) draws the spheres with the default size and color. % SCATTER3SPH(X,Y,Z,'size',S) draws the spheres with sizes S. If length(S)= 1 % the same size is used for all spheres. % SCATTER3SPH(X,Y,Z,'color',C) draws the spheres with colors speciffied in a % N-by-3 matrix C as RGB values. % Parameter names can be abreviated to 3 letters. For example: 'siz' or % 'col'. Case is irrelevant. % % Example % %Coordinates % X= 100*rand(9,1); Y= 100*rand(9,1); Z= 100*rand(9,1); % % %Colors: 3 blue, 3 red and 3 green % C= ones(3,1)*[0 0 1]; % C= [C;ones(3,1)*[1 0 0]]; % C= [C;ones(3,1)*[0 1 0]]; % % %Spheres sizes % S= 5+10*rand(9,1); % % figure(1); % scatter3sph(X,Y,Z,'size',S,'color',C); % axis equal % axis tight % view(125,20); % grid ON %-- Some checking... if nargin < 3 error('Need at least three arguments'); return; end if mean([length(X),length(Y),length(Z)]) ~= length(X) error ('Imput vectors X, Y, Z are of different lengths'); return; end %-- Defaults C= ones(length(X),1)*[0 0 1]; S= 0.1*max([X;Y;Z])*ones(length(X),1); %-- Extract optional arguments for j= 1:2:length(varargin) string= lower(varargin{j}); switch string(1:min(3,length(string))) case 'siz' S= varargin{j+1}; if length(S) == 1 S= ones(length(X),1)*S; elseif length(S) < length(X) error('The vector of sizes must be of the same length as coordinate vectors (or 1)'); return end case 'col' C= varargin{j+1}; if size(C,2) < 3 error('Colors matrix must have 3 columns'); return; end if size(C,1) == 1 C= ones(length(X),1)*C(1:3); elseif size(C,1) < length(X) error('Colors matrix must have the same number of rows as length of coordinate vectors (or 1)'); return end otherwise error('Unknown parameter name. Allowed names: ''size'', ''color'' '); end end %-- Sphere facets [sx,sy,sz]= sphere(20); %-- Plot spheres hold on for j= 1:length(X) surf(sx*S(j)+X(j), sy*S(j)+Y(j), sz*S(j)+Z(j),... 'LineStyle','none',... 'AmbientStrength',0.4,... 'FaceColor',C(j,:),... 'SpecularStrength',0.8,... 'DiffuseStrength',1,... 'FaceAlpha',0.65,... 'SpecularExponent',2); end light('Position',[0 0 1],'Style','infinit','Color',[1 1 1]); lighting gouraud view(30,15)
Formal statement is: lemma centre_in_ball [simp]: "x \<in> ball x e \<longleftrightarrow> 0 < e" Informal statement is: The centre of a ball is in the ball if and only if the radius is positive.
The complex conjugate of a quotient is the quotient of the complex conjugates.
module Mod_DC_Driver use typre use Mod_DistributedContainer use Mod_DriverInterface implicit none private public DC_Driver, ExtractDriver, DC_Driver_Const !The extended types type, extends(DistributedContainer) :: DC_Driver class(DriverInterface), pointer :: a => NULL() contains procedure :: GetValue end type interface DC_Driver_Const procedure constructor end interface DC_Driver_Const contains subroutine GetValue(this,value) class(DC_Driver) :: this class(DriverInterface), pointer :: value value => this%a end subroutine GetValue function constructor(value) class(DC_Driver), pointer :: constructor class(DriverInterface), target :: value allocate(constructor) constructor%a => value end function constructor subroutine ExtractDriver(myDC,myDriver) class(DistributedContainer), pointer :: myDC class(DriverInterface), pointer :: myDriver select type (myDC) type is (DC_Driver) call myDC%GetValue(myDriver) end select end subroutine end module
{-# LANGUAGE MultiParamTypeClasses #-} module Stats where import Control.Applicative import Control.Monad.State import Data.Random import Data.Random.Distribution.Exponential import Data.Random.Source.PureMT import qualified Data.Vector as V import Data.Word import qualified Statistics.Sample.Histogram as S seed :: Word64 seed = 123 sampleStream :: (Num t, Distribution d t) => d t -> [t] sampleStream distribution = evalState (iterateM $ sample distribution) (pureMT seed) iterateM :: (Applicative m) => m a -> m [a] iterateM f = liftA2 (:) f (iterateM f) sampleVector :: (Num t, Distribution d t) => d t -> Int -> V.Vector t sampleVector distribution size = V.fromList . take size $ sampleStream distribution sampleExp :: Int -> V.Vector Double sampleExp = sampleVector (Exp 1) sampleExp' :: Int -> V.Vector Double sampleExp' = fmap (negate . log) . sampleVector StdUniform expHistograms :: (V.Vector Double, V.Vector Double) expHistograms = S.histogram 30 (sampleExp 1000) expHistograms' :: (V.Vector Double, V.Vector Double) expHistograms' = S.histogram 30 (sampleExp' 1000) mean :: Floating a => V.Vector a -> a mean xs = V.sum xs / fromIntegral (V.length xs) var :: Floating a => V.Vector a -> a var xs = mean (fmap (** 2) xs) - mean xs ** 2 isCloseWithTolerance :: (Ord a, Floating a) => a -> a -> a -> a -> Bool isCloseWithTolerance aTol rTol x y = abs (x - y) <= aTol + rTol * abs y isClose :: (Ord a, Floating a) => a -> a -> Bool isClose = isCloseWithTolerance 1e-8 1e5
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Documentation """ __author__ = "R. Adda, M.Charpentier, E. Vazquez" __copyright__ = "CentraleSupelec, 2020" __license__ = "MIT" __maintainer__ = "E. Vazquez" __email__ = "[email protected]" __status__ = "alpha" import math import matplotlib.pyplot as plt import numpy as np from scipy.integrate import ode def SEIRD(t, x, theta, const_params): # Computes... # # Inputs: # t # x # theta = [R, T_inf, T_inc , pfatal] # ... # Output: # dx # ... # ... R0 = theta[0] # Basic Reproduction Rate Tinf = theta[1] # Infection Time Tinc = theta[2] # Incubation Time pfatal = math.pow(10, theta[3]) # Death proportion for I compartment N = const_params[0] Gamma = const_params[1] mu = const_params[2] S = x[0] E = x[1] I = x[2] R = x[3] D = x[4] gamma = 1 / Tinf a = 1 / Tinc beta = gamma * R0 dS = Gamma - mu * S - beta / N * I * S dE = beta / N * I * S - (mu + a) * E dI = a * E - gamma * (1 + pfatal) * I dR = gamma * I - mu * R dD = gamma * pfatal * I dx = [dS, dE, dI, dR, dD] return dx def SEIRD_with_cutoff(t, x, theta, const_params): # Computes... # # Inputs: # t # x # theta = [R, beta_cut, T_inf, T_inc , pfatal] # ... # Output: # dx # ... # ... R0 = theta[0] # Basic Reproduction Rate beta_cut = theta[1] Tinf = theta[2] # Infection Time Tinc = theta[3] # Incubation Time pfatal = pow(10, theta[4]) # Death proportion for I compartment N = const_params[0] Gamma = const_params[1] mu = const_params[2] cutoff_time = const_params[3] lift_time = const_params[4] S = x[0] E = x[1] I = x[2] R = x[3] D = x[4] gamma = 1 / Tinf a = 1 / Tinc if t >= cutoff_time and t < lift_time: beta = beta_cut * gamma * R0 else: beta = gamma * R0 dS = Gamma - mu * S - beta / N * I * S dE = beta / N * I * S - (mu + a) * E dI = a * E - gamma * (1 + pfatal) * I dR = gamma * I - mu * R dD = gamma * pfatal * I dx = [dS, dE, dI, dR, dD] return dx def SIRD_with_cutoff(t, x, theta, const_params): # Computes... # # Inputs: # t # x # theta = [R, beta_cut, T_inf, T_inc , pfatal] # ... # Output: # dx # ... # ... R0 = theta[0] # Basic Reproduction Rate beta_cut = theta[1] Tinf = theta[2] # Infection Time pfatal = pow(10, theta[3]) # Death proportion for I compartment N = const_params[0] Gamma = const_params[1] mu = const_params[2] cutoff_time = const_params[3] lift_time = const_params[4] S = x[0] I = x[1] R = x[2] D = x[3] gamma = 1 / Tinf if t >= cutoff_time and t < lift_time: beta = beta_cut * gamma * R0 else: beta = gamma * R0 dS = Gamma - mu * S - beta / N * I * S dI = beta / N * I * S - mu * I - gamma * (1 + pfatal) * I dR = gamma * I - mu * R dD = gamma * pfatal * I dx = [dS, dI, dR, dD] return dx class model: ''' Attributes model_type : f : RHS of the ODE ... ... theta : parameters t : time axis for simulation x : [S (Susceptible), E (Exposed), I (Infectious), R (Recovered), D (Death)] along time Methods simulate ... plot ''' def __init__(self, config, tobs): # Initialization # 1. Model choice self.set_model_type(config) # 2. set regional parameters self.set_regional_params(config) # 3. simulation parameters self.set_simulation_params(config) # 4. build t and preallocate x self.prepare_simulations(config, tobs) def set_model_type(self, config): # Model type self.model_type = config['model_type'] if self.model_type == 'SEIRD': self.f = SEIRD self.state_dim = 5 # state dim self.state_ref = {'S': 0, 'E':1, 'I':2, 'R':3, 'D':4} self.theta_dim = 5 # theta dim elif self.model_type == 'SEIRD_with_cutoff': self.f = SEIRD_with_cutoff self.state_dim = 5 # state dim self.state_ref = {'S': 0, 'E':1, 'I':2, 'R':3, 'D':4} self.theta_dim = 6 # theta dim elif self.model_type == 'SIRD_with_cutoff': self.f = SIRD_with_cutoff self.state_dim = 4 # state dim self.state_ref = {'S': 0, 'I':1, 'R':2, 'D':3} self.theta_dim = 5 # theta dim else: raise('model type is not implemented') def set_regional_params(self, config): # Regional parameters if self.model_type == 'SEIRD': self.regional_params = [config['N'], config['Gamma'], config['mu']] elif self.model_type == 'SEIRD_with_cutoff': self.regional_params = [config['N'], config['Gamma'], config['mu'], config['cutoff_time'], config['lift_time']] elif self.model_type == 'SIRD_with_cutoff': self.regional_params = [config['N'], config['Gamma'], config['mu'], config['cutoff_time'], config['lift_time']] def set_simulation_params(self, config): # Simulation parameters self.time_step = config['sim_step'] self.sim_duration = config['sim_duration'] def prepare_simulations(self, config, tobs): # build t and preallocate x self.t = np.arange(0, self.sim_duration, self.time_step) self.x = np.zeros([self.t.shape[0], self.state_dim]) # preallocation # start date, assume a a datetime object for t0_ref and convert to numpy datetime object self.t0_refdate = np.datetime64(config['t0_refdate']) # assume a pandas dataframe of timestamp objects and convert to numpy datetime objects tobs_rel = [tobs[i] - self.t0_refdate for i in range(tobs.shape[0])] # pdb.set_trace() # build a tobs_idx array in order to retrieve observations with self.x[self.tobs_idx] self.tobs_rel = [tobs_rel[i].days for i in range(len(tobs_rel))] k = 0 self.tobs_idx = [] for i in range(len(self.tobs_rel)): t = self.tobs_rel[i] while k < self.t.shape[0]: if self.t[k] >= t: self.tobs_idx.append(k) break k += 1 # pdb.set_trace() def y_from_tobs(self): # Helper function to retrieve fatalities at tobs fatalities_idx = self.state_ref['D'] return self.x[self.tobs_idx, fatalities_idx] def simulate(self, theta): # ODE integration happens here # Set theta self.theta = theta # State initialization t0 = theta[-1] if self.model_type in ['SEIRD', 'SEIRD_with_cutoff']: x0 = [self.regional_params[0] - 1, 0, 1, 0, 0] elif self.model_type == 'SIRD_with_cutoff': x0 = [self.regional_params[0] - 1, 1, 0, 0] # ODE initialization # r = ode(f).set_integrator('vode', method='adams', with_jacobian=False) r = ode(self.f).set_integrator('lsoda', with_jacobian=False) r.set_initial_value(x0, t0).set_f_params(self.theta, self.regional_params) idx_start = 0 while self.t[idx_start] < t0: idx_start += 1 # Run simulation for i in range(idx_start + 1, self.t.shape[0]): # NB1: r.successful() is not tested # NB2: r.t is self-incrementing t = self.t[i] r.integrate(t) self.x[i, :] = r.y def plot(self, semilog=True): # Simple plot if semilog: plt.semilogy(self.t, self.x[:, self.state_ref['S']], label="Susceptible") plt.semilogy(self.t, self.x[:, self.state_ref['E']], label="Exposed") plt.semilogy(self.t, self.x[:, self.state_ref['I']], label="Infectious") plt.semilogy(self.t, self.x[:, self.state_ref['R']], label="Recovered") plt.semilogy(self.t, self.x[:, self.state_ref['D']], label="Death") plt.ylim((0.1, np.max(self.x[:, self.state_ref['S']]))) else: plt.plot(self.t, self.x[:, self.state_ref['E']], label="Exposed") plt.plot(self.t, self.x[:, self.state_ref['I']], label="Infectious") plt.plot(self.t, self.x[:, self.state_ref['D']], label="Death") plt.title("Propagation model SEIR(D)") plt.grid(True) plt.legend() plt.show() def plot_with_obs(self, yobs, ax=None, transparency=1): # Simple plot if ax is None: fig, ax = plt.subplots() plt.xlabel('Time (days)') plt.ylabel(r'$\log_{10}(y(t))$') idx = np.where(yobs > 0) tobs = np.array(self.tobs_rel) tobs = tobs[idx[0]] yobs = yobs[idx[0]] # pdb.set_trace() plt.semilogy(self.t, self.x[:, self.state_ref['I']], label='Prediction', color='C4', alpha=transparency / 2) plt.semilogy(self.t, self.x[:, self.state_ref['D']], label='Prediction', color='C7', alpha=transparency) plt.semilogy(tobs, yobs, label='Observed', linestyle='dashed', marker='o', color='C1') return ax
module Physics import World %access export inspectWorld : Host -> String inspectWorld w = foldWorld w $ \_, i, k, e => "(id: " ++ show k ++ ", health: " ++ show (health i e) ++ ");" attack' : Int -> Key -> Host -> Host attack' d k w = fst $ withEntity w k $ \_, i, e => (attack i d e, ())
Recent developments in several industrial economies, particularly in the three largest ones, raise important issues about how to judge the stance of monetary policy. In the United States, recovery from the recent recession has been exceptionally sluggish, whereas inflation has fallen to its lowest level in two decades. In Japan, growth has slowed considerably during the past eighteen months. In Germany, by contrast, inflationary pressures surged in 1991–92 following unification, although more recently growth has stagnated. At the same time, the evolution of broad monetary aggregates—which the monetary authorities have preferred to target or monitor—suggests that monetary conditions have been tight in the United States and Japan but easy in Germany. But other indicators—including nominal and real short-term interest rates, the slope of yield curves, and narrow monetary aggregates—suggest that monetary policy has eased in the United States and in Japan, whereas it has tightened significantly in Germany. This annex examines the experiences of these three countries and, more briefly, those of selected other industrial economies in order to assess the reliability of indicators of the stance of monetary policy. The analysis shows that contradictions among the various indicators, as is now the case, often occur over the course of the business cycle. Moreover, the growth of the broad monetary aggregates now appears to be giving misleading indications of the true stance of monetary policy and of its probable effect on future growth and inflation. Appropriately assessing the stance of monetary policy and the need for policy adjustments therefore requires examination of a range of indicators. In the United States, the recovery from the recession that began in the third quarter of 1990 has been unusually sluggish by historical standards: growth in the first four quarters following the trough has been only about half that in the weakest previous postwar recovery (Chart 20). Although several factors have contributed to this disappointing performance, there has been concern that the slow growth of M2, which has fallen below the bottom of the Federal Reserve’s target band, indicates that monetary policy has not eased enough to sustain a robust recovery (Chart 21). This behavior apparently contrasts with earlier experience, when a fall in velocity, typically due to a surge in M2, has usually preceded a pickup in output growth by about four quarters. 1As identified by the National Bureau of Economic Research. The recent behavior of M2 has been sufficiently unusual to suggest that this aggregate may no longer be very useful for assessing the stance of monetary policy.1 During the 1970s, a positively sloped yield curve was associated with rapid growth of M2 relative to M1. After financial deregulation in the 1980s, however, this relationship apparently broke down; since the mid-1980s, an inverted yield curve has been associated with rapid growth of M2 relative to M1. The recent pattern reflects the fact that low short-term interest rates and high long-term rates reduce the attractiveness of short-term assets in M2 relative to both demand deposits and longer-term assets, thereby reducing the growth of M2. Other factors have also contributed to the recent slowdown in the growth of M2. On the demand side, households and businesses may have been liquidating short-term assets in order to reduce their debt burden by paying down loans. On the supply side, depository institutions have been increasing the spread between the return on assets (loans) and the cost of liabilities (deposits, including time deposits) in response to low profitability, regulatory pressure to boost capital-asset ratios, slack loan demand during the recession and subsequent period of slow growth, and the perception that some loans are now riskier than before. As banks have consolidated the asset side of their balance sheets, they have had less need to raise funds and therefore have offered relatively low returns on instruments such as time deposits. Finally, asset shifts associated with closures of insolvent savings and loan institutions have reportedly slowed the growth of monetary aggregates. Indicators other than M2 suggest that the stance of monetary policy in the United States has eased substantially. In particular, the narrow aggregate M1 has been growing robustly, and the dollar has weakened as short-term nominal interest rates have fallen to their lowest levels in three decades. Short-term real interest rates are now close to zero, the lowest level since real interest rates were negative in the early 1980s. Long-term interest rates, however, have fallen only modestly, resulting in a very steep yield curve. In contrast to the often confusing signals provided by monetary aggregates, the yield curve has proved to be a reliable indicator of economic activity, with a lag of about four quarters.2 In the 1974–75 recession, the yield curve became steeply inverted about four quarters before output growth turned negative; it then became positive as output recovered. A similar pattern occurred in the 1981–82 recession. The recent steepness of the yield curve has been signaling an upturn in economic activity for some time and is consistent with a recovery in output growth in 1993, although the process of resolving private sector balance sheet difficulties may continue to restrain the pace of expansion. In Japan, as in the United States, the monetary aggregate monitored by the central bank (M2 + CD) has barely grown over the past eighteen months, suggesting very tight monetary conditions (Chart 22).3 This slow growth was preceded by unusually rapid growth in 1990, however, and to that extent may reflect a return of the aggregate to its underlying trend. The evolution of the monetary aggregates was also influenced by the sharp rise in market interest rates in 1990 and their subsequent decline through 1991. As interest rates rose in 1990, funds were shifted out of postal deposits, which are not included in M2 + CD, because returns did not rise as quickly as interest rates paid on other assets. Prime lending rates also rose more slowly than market rates in late 1990 and early 1991; in response, firms borrowed at prime and reinvested in CDs. As interest rates fell during 1991, funds were shifted back into postal deposits, and firms unwound their positions in CDs, with the result that growth of M2 + CD was unusually slow. 1 CD, certificate of deposit. Indicators other than M2 + CD suggest that the stance of monetary policy has loosened somewhat. The growth of the narrow aggregate M1 increased during 1990–91 and, although it declined somewhat in 1992, it was at about the same level as average growth in the 1980s. In addition, short-term rates have fallen by over 300 basis points in the past eighteen months in Japan, and real short-term interest rates are at their lowest level in more than a decade (except for a brief period in 1989). Short-term rates have also fallen about a percentage point below long-term rates. As in other countries, a positively sloped yield curve is associated with high growth of the narrow aggregate compared with the broad one. However, the factors underlying the recent behavior of monetary aggregates and other indicators in Japan are not completely understood, and it is therefore unusually difficult to judge whether current monetary conditions can sustain adequate growth in 1993. In particular, as in several other industrial countries, the collapse of equity and real estate prices has eroded the capital base of the banking sector, has resulted in a rise in nonperforming loans, and may also be depressing household consumption. The prospect that these effects may prove as pervasive and long-lasting as in other industrial countries suggests that the current stance of monetary policy in Japan is not overly expansionary. In Germany, the twelve-month growth rates of the broad monetary aggregate M3 during the first nine months of 1992 were running well above the target range of 3.5 to 5.5 percent established by the Bundesbank (Chart 23).4 The rapid growth of M3 has been cited as an indication that monetary policy has been too loose. By contrast, following an upward surge during 1991 because of German monetary unification, M1 grew relatively moderately, despite a probable increase in the use of the deutsche mark in Eastern Europe and the former Soviet Union. Although moderate M1 growth suggests tight monetary policy, the divergence between the growth rates of the aggregates has complicated the assessment of the stance of policy. Historically, M3 has tended to grow more rapidly than M1 in response to a flattening or inversion of the yield curve—as has occurred during the past two years—because relatively high short-term rates increase the attractiveness of the short-term interest-bearing assets in M3. In addition, the prospect of the introduction of a withholding tax on interest income in mid-1992 may have induced movement out of longer-term assets and into the relatively liquid interest-bearing assets contained in M3. Monetary unification has made movements in both the narrow and broad monetary aggregates misleading as indicators of monetary stance.5 In addition to a substantial once-and-for-all increase in money stocks of perhaps 15 percent, unification increased the demand for money from the eastern Länder. It will be difficult to evaluate how the behavior of asset holders and borrowers in east Germany will evolve; hence, the growth rates of the monetary aggregates may prove to be misleading guides to underlying economic conditions. Whereas M3 and M1 have been providing mixed signals, other indicators suggest that monetary policy in Germany is now quite tight. Short-term nominal and, more important, real interest rates are very high by postwar standards. This has put considerable upward pressure on the deutsche mark and contributed to the recent turmoil in the ERM. Short-term interest rates are also now well above long-term rates, resulting in a yield curve that is as steeply inverted as at any time in recent history. As in the United States, an inverted yield curve has been a reliable indicator that monetary policy is exerting significant downward pressure on output growth. Two previous episodes of inflationary pressure followed by monetary tightening are helpful in assessing the indicators of monetary stance. Germany experienced a surge of inflationary pressure in the early 1970s, as did other countries. In response, the Bundesbank raised nominal and real short-term interest rates, and the yield curve became steeply inverted. The downturn of economic activity in Germany during 1974–75 and the subsequent reduction of inflation testify to the success of the tight stance of monetary policy. Nonetheless, M3 continued to grow rapidly from early 1973 through late 1974, even as M1 growth collapsed. In 1979, the second oil shock triggered another inflationary upsurge, which was again accompanied by a tightening of monetary conditions. As in 1973–74, the growth of M1 fell sharply, even turning negative in 1981, whereas the growth rate of M3 remained relatively stable. The yield curve became inverted as short rates rose sharply, and, as in the previous episode, this was followed by a fall in output, although the disinflationary impact may have been blunted by the fall in the value of the deutsche mark relative to the dollar, which reflected in part very tight monetary policy in the United States. In light of both of these episodes, the current monetary indicators suggest a slowing of the German economy and receding inflationary pressures. Recent difficulties in interpreting the behavior of monetary aggregates have not been limited to the three largest economies. In the United Kingdom, rising inflation became a key policy concern by late 1988, particularly in view of the prospect of entry into the ERM (which occurred in 1990). Monetary policy, which has used MO as the only targeted aggregate since 1987, was tightened considerably beginning in 1988 and over the course of 1989, remained tight through most of 1990, and then eased modestly beginning in late 1990. Short-term rates were pushed well above long-term rates from mid-1988 through late 1990 and then eased gradually to only about a percentage point above long-term rates during 1991, although they remained very high in real terms. In response, economic growth slackened somewhat during 1989, and a prolonged recession began in the third quarter of 1990. Meanwhile, inflation (measured by the “headline” twelve-month change in the retail price index) has fallen below 4 percent. The growth of the broad monetary aggregate M4 remained high relative to that of the narrow aggregate throughout 1989 and into 1990. As economic activity began to weaken, the growth of M4 fell to levels not seen since the 1960s, suggesting an economy declining into a deepening recession. In contrast, the growth of the narrower aggregate began to fall in mid-1988, providing a more reliable indication of the earlier tightening of monetary stance in 1988 and 1989. The recent behavior of narrow money suggests an economy that is only barely growing. The situation in the United Kingdom in 1989 and early 1990 was thus similar to the current situation in Germany: a tight monetary stance accompanied by rapid growth of broad monetary aggregates. Monetary conditions were eased following the pound sterling’s entry into the ERM in late 1990, with short-term interest rates falling from 15 percent to 9½ percent in September 1992. Since sterling left the ERM, short-term rates fell further to 7¼ percent in early December—about 1 percentage point below long-term rates—and the pound has depreciated in effective terms by about 16 percent. These changes amount to a substantial easing of monetary conditions and should stimulate economic activity in 1993. In Canada, where no monetary aggregate is targeted, inflation became the key policy concern during 1988–90, and monetary policy tightened considerably. Short-term interest rates were pushed up from mid-1988 until mid-1990 and stood more than 2½ percentage points above long-term rates from early 1989 until late 1990. As the economy slowed and inflation eased, short-term rates fell more than 700 basis points and were about 3 percentage points below long-term rates in August 1992. From already low levels in 1988, growth of the narrow monetary aggregate M1 declined further during 1989 and turned negative during 1990. In contrast, growth of the broad monetary aggregate picked up over the course of 1988–89, reached a peak for the decade at the end of 1989, and remained high through 1990. Since early 1991, growth of the broad aggregate has declined somewhat, whereas the growth of the narrow aggregate has picked up. The evolution of real output growth, which began to slow in late 1989 and turned negative in mid-1990, confirms the assessment of monetary policy indicated by the behavior of interest rates and the narrow aggregate. The behavior of the broad aggregate, in contrast, has been less useful as a guide to the impact of policy. In Australia, determined efforts to combat inflation were clearly under way during 1989 as interest rates on short-term treasury bills were pushed to nearly 18 percent, 4 percentage points above long-term rates. The twelve-month growth of the narrow monetary aggregate M1 declined sharply from 36 percent at the beginning of 1989 to slightly below zero in early 1990. In contrast, the twelve-month growth of the broad monetary aggregate M3 rose to a peak of over 30 percent in mid-1989, ran above 20 percent by year-end, and was above 10 percent throughout 1990. Growth began to slow late in 1989; by mid-1990 a recession had begun, and inflation was falling. Again, the narrow aggregate appears to have reflected the stance of monetary policy more accurately than has the broad aggregate. The recovery that began in late 1991 is consistent with the sharp pickup in growth of the narrow aggregate, the persistent declines in short-term interest rates, and the increasingly positive slope of the yield curve since early 1991. At the same time, the broad aggregate has grown only slowly. September 1990 Staff Studies for the World Economic Outlook, by the Research Department of the International Monetary Fund. October 1990 World Economic Outlook: A Survey by the Staff of the International Monetary Fund. November 1990 Multilateral Official Debt Rescheduling: Recent Experience, by Michael G. Kuhn with Jorge P. Guzman. May 1991 International Capital Markets: Developments and Prospects, by a Staff Team from the Exchange and Trade Relations and Research Departments. May 1991 World Economic Outlook: A Survey by the Staff of the International Monetary Fund. October 1991 World Economic Outlook: A Survey by the Staff of the International Monetary Fund. December 1991 Private Market Financing for Developing Countries, by a Staff Team from the Exchange and Trade Relations Department. May 1992 World Economic Outlook: A Survey by the Staff of the International Monetary Fund. May 1992 Developments in International Exchange and Payments Systems, by a Staff Team from the Exchange and Trade Relations Department. August 1992 Issues and Developments in International Trade Policy, by a Staff Team led by Margaret Kelly and Anne Kenny McGuirk. September 1992 International Capital Markets: Developments, Prospects, and Policy Issues, by Morris Goldstein, David Folkerts-Landau, Mohamed El-Erian, Steven Fries, and Liliana Rojas-Suarez. October 1992 World Economic Outlook: A Survey by the Staff of the International Monetary Fund. December 1992 Private Market Financing for Developing Countries, by a Staff Team from the Policy Development and Review Department led by Charles Collyns. January 1993 World Economic Outlook—Interim Assessment: A Survey by the Staff of the International Monetary Fund. This annex was prepared by Robert P. Ford. M1 comprises demand deposits at commercial banks and currency. M2 comprises M1, savings deposits, overnight repurchases and Eurodollars, small time deposits, and money market mutual shares. The recent slowdown in M2 growth has been concentrated in small time deposits, which are interest-bearing, nonliquid instruments issued in denominations of less than $100,000. See the analysis in John Wenninger and John Partlan, “Small Time Deposits and the Recent Weakness of M2,” Federal Reserve Bank of New York Quarterly Review, Vol. 17 (Spring 1992), pp. 21–35. For econometric evidence, see Arturo Estrella and Gikas A. Hardouvelis, “The Term Structure as a Predictor of Real Economic Activity,” Journal of Finance, Vol. 46 (June 1991), pp. 555–76. They find that the term structure is a better predictor of real output than the short-term real interest rate and the index of leading indicators. M1 comprises currency and demand deposits. M2 + CD comprises M1, all other deposits with financial institutions, and certificates of deposit (CDs). M1 comprises “sight” deposits and currency. M3 comprises M1, time deposits, funds borrowed for a period of less than four years, and savings deposits. The Bundesbank’s target range is based on an estimate of potential output growth and on the medium-term target of price stability. One sign of potential instability in money demand is the clear break in the relationship between monetary aggregates and nominal income. The steady decline in M3 velocity has been reversed since sometime in 1989, even after adjusting money stocks for the once-and-for-all change associated with unification. On the first point, see Jeroen J.M. Kremers and Timothy D. Lane, “Economic and Monetary Integration and the Aggregate Demand for Money in the EMS,” Staff Papers (IMF), Vol. 27 (December 1990), pp. 777–805, and the references contained therein. On the second point, see Tamim A. Bayoumi and Peter B. Kenen, “Using an EC-Wide Monetary Aggregate in Stage Two of EMU, “IMF Working Paper 92/56 (July 1992). The issue of an EC monetary aggregate is far from settled, however, as is indicated by the comment on Kremers and Lane by David Barr, “The Demand for Money in Europe,” Staff Papers (IMF), Vol. 39 (September 1992), pp. 718–29.
module Examples.AuthorityLattice import public DepSec.Lattice %access public export %default total data Principal : Type where Top : Principal Alice : Principal Bob : Principal Chuck : Principal Bot : Principal implementation JoinSemilattice Principal where join Top b = Top join Alice Top =Top join Alice Alice = Alice join Alice Bob = Top join Alice Chuck = Top join Alice Bot = Alice join Bob Top = Top join Bob Alice = Top join Bob Bob = Bob join Bob Chuck = Top join Bob Bot = Bob join Chuck Top = Top join Chuck Alice = Top join Chuck Bob = Top join Chuck Chuck = Chuck join Chuck Bot = Chuck join Bot b = b associative Top b c = Refl associative Alice Top c = Refl associative Alice Alice Top = Refl associative Alice Alice Alice = Refl associative Alice Alice Bob = Refl associative Alice Alice Chuck = Refl associative Alice Alice Bot = Refl associative Alice Bob Top = Refl associative Alice Bob Alice = Refl associative Alice Bob Bob = Refl associative Alice Bob Chuck = Refl associative Alice Bob Bot = Refl associative Alice Chuck Top = Refl associative Alice Chuck Alice = Refl associative Alice Chuck Bob = Refl associative Alice Chuck Chuck = Refl associative Alice Chuck Bot = Refl associative Alice Bot c = Refl associative Bob Top c = Refl associative Bob Alice Top = Refl associative Bob Alice Alice = Refl associative Bob Alice Bob = Refl associative Bob Alice Chuck = Refl associative Bob Alice Bot = Refl associative Bob Bob Top = Refl associative Bob Bob Alice = Refl associative Bob Bob Bob = Refl associative Bob Bob Chuck = Refl associative Bob Bob Bot = Refl associative Bob Chuck Top = Refl associative Bob Chuck Alice = Refl associative Bob Chuck Bob = Refl associative Bob Chuck Chuck = Refl associative Bob Chuck Bot = Refl associative Bob Bot c = Refl associative Chuck Top c = Refl associative Chuck Alice Top = Refl associative Chuck Alice Alice = Refl associative Chuck Alice Bob = Refl associative Chuck Alice Chuck = Refl associative Chuck Alice Bot = Refl associative Chuck Bob Top = Refl associative Chuck Bob Alice = Refl associative Chuck Bob Bob = Refl associative Chuck Bob Chuck = Refl associative Chuck Bob Bot = Refl associative Chuck Chuck Top = Refl associative Chuck Chuck Alice = Refl associative Chuck Chuck Bob = Refl associative Chuck Chuck Chuck = Refl associative Chuck Chuck Bot = Refl associative Chuck Bot c = Refl associative Bot b c = Refl commutative Top Top = Refl commutative Top Alice = Refl commutative Top Bob = Refl commutative Top Chuck = Refl commutative Top Bot = Refl commutative Alice Top = Refl commutative Alice Alice = Refl commutative Alice Bob = Refl commutative Alice Chuck = Refl commutative Alice Bot = Refl commutative Bob Top = Refl commutative Bob Alice = Refl commutative Bob Bob = Refl commutative Bob Chuck = Refl commutative Bob Bot = Refl commutative Chuck Top = Refl commutative Chuck Alice = Refl commutative Chuck Bob = Refl commutative Chuck Chuck = Refl commutative Chuck Bot = Refl commutative Bot Top = Refl commutative Bot Alice = Refl commutative Bot Bob = Refl commutative Bot Chuck = Refl commutative Bot Bot = Refl idempotent Top = Refl idempotent Alice = Refl idempotent Bob = Refl idempotent Chuck = Refl idempotent Bot = Refl
""" Reference: The origin code of GPT paper from openai (https://github.com/openai/finetune-transformer-lm) """ using ArgParse using Flux using Flux: onecold, gradient, logitcrossentropy import Flux.Optimise: update! using BytePairEncoding using Transformers using Transformers.Basic using Transformers.GenerativePreTrain using Transformers.Datasets using Transformers.Datasets: StoryCloze function parse_commandline() s = ArgParseSettings() @add_arg_table s begin "--gpu", "-g" help = "use gpu" action = :store_true "--epoch", "-e" help = "epoch" arg_type = Int default = 3 "task" help = "task name" required = true range_tester = x -> x ∈ ["rocstories"] end return parse_args(ARGS, s) end const args = parse_commandline() if args["gpu"] @eval using CuArrays end const startsym = "_start_" const delisym = "_deli_" const clfsym = "_clf_" const unksym = "<unk>" const anslabel = ["1", "2"] const anv = Vocabulary(anslabel, "1") gptm, embedm, bpe = load_gpt_pretrain(12; startsym=startsym, delisym=delisym, clfsym=clfsym, unksym=unksym) const gpt = gpu(gptm) const embed = gpu(embedm) const clf = gpu(Dense(768, 1)) const ansdrop = Dropout(0.1) function transform(s1, s2, s3, s4, c1, c2, y) x = [startsym; segment(bpe, s1); segment(bpe, s2); segment(bpe, s3); segment(bpe, s4); delisym] x1 = [x; segment(bpe, c1); clfsym] x2 = [x; segment(bpe, c2); clfsym] x1, x2, y end function acc(p, y) pred = onecold(collect(p)) sum(pred .== collect(y)) / length(y) end function loss(x1, x2, y, x1_mask, x2_mask, c1_index, c2_index) e1 = embed(x1) e2 = embed(x2) t1 = gpt(e1, x1_mask) t2 = gpt(e2, x2_mask) lm = lmloss(embed, onehot(embed, x1), t1, x1_mask) + lmloss(embed, onehot(embed, x2), t2, x2_mask) c1 = gather(t1, c1_index) c2 = gather(t2, c2_index) p1 = clf(c1) p2 = clf(c2) p = vcat(p1, p2) p = ansdrop(p, 1) ##### turn onehot to real float array yd = tofloat(Float32, onehot(anv, y)) ##### cl = logitcrossentropy(p, yd) #unstable type will cause performance issue convert(Float32, 0.5) * lm + cl, p end const rocs = StoryCloze() const ps = params(embed, gpt, clf) const opt = ADAM(6.25e-5) const Batch = 4 function test() Flux.testmode!(gpt) Flux.testmode!(ansdrop) println("eval:") i::Int = 0 al::Float64 = 0. devl = dataset(Test, rocs) while (batch = get_batch(devl, Batch)) !== nothing tdb = transform.(batch...) b1, b2, y = batched(tdb) b1_mask = getmask(b1) b2_mask = getmask(b2) c1i = [(findfirst(isequal(clfsym), x), i) for (i, x) in enumerate(b1)] c2i = [(findfirst(isequal(clfsym), x), i) for (i, x) in enumerate(b2)] b1, b2 = embed.Vocab(b1,b2) y = anv(y) b1,b2,y,b1_mask,b2_mask,c1i,c2i = device(b1,b2,y,b1_mask,b2_mask,c1i,c2i) _, p = loss(b1, b2, y, b1_mask, b2_mask, c1i, c2i) a = acc(p, y) al += a i += 1 end al /= i Flux.testmode!(gpt, false) Flux.testmode!(ansdrop, false) @show al end function train!(epoch) global Batch, rocs, opt, ps for e = 1:epoch println("start training: $e") datas = dataset(Train, rocs) i::Int = 0 al::Float64 = 0. while (batch = get_batch(datas, Batch)) !== nothing tdb = transform.(batch...) b1, b2, y = batched(tdb) b1_mask = getmask(b1) b2_mask = getmask(b2) c1i = [(findfirst(isequal(clfsym), x), i) for (i, x) in enumerate(b1)] c2i = [(findfirst(isequal(clfsym), x), i) for (i, x) in enumerate(b2)] b1, b2 = embed.Vocab(b1,b2) y = anv(y) b1,b2,y,b1_mask,b2_mask,c1i,c2i = device(b1,b2,y,b1_mask,b2_mask,c1i,c2i) l, p = loss(b1, b2, y, b1_mask, b2_mask, c1i, c2i) #@show l a = acc(p, y) al += a grad = gradient(()->l, ps) i+=1 update!(opt, ps, grad) i%16==0 && @show al/i end test() end end train!(args["epoch"])
\chapter{Mechanical perturbation control of cardiac alternans} \section{Introduction}
(*There is still a design under consideration. It intends to give a rich way with term quotations to represent and report error messages in the logic programming based reasoning. *) theory PLPR_error_msg imports Phi_Logic_Programming_Reasoner begin section \<open>Error Reporting\<close> subsection \<open>Encoding of Text\<close> typedecl "text" setup \<open>Sign.mandatory_path "text"\<close> consts literal :: \<open>(text \<Rightarrow> text) \<Rightarrow> text\<close> "term" :: \<open>'a::{} \<Rightarrow> text\<close> type :: \<open>'a::{} itself \<Rightarrow> text\<close> cat :: \<open>text \<Rightarrow> text \<Rightarrow> text\<close> newline :: \<open>text\<close> "text" :: \<open>text \<Rightarrow> text\<close> setup \<open>Sign.parent_path\<close> text \<open>We use the name of a lambda variable to encode an arbitrary string text.\<close> nonterminal "text_" syntax "_text_" :: \<open>text_ \<Rightarrow> text\<close> ("TEXT'(_')" [1] 1000) syntax "_text_literal_" :: \<open>cartouche \<Rightarrow> text_\<close> ("_") syntax "_text_term_" :: \<open>logic \<Rightarrow> text_\<close> ("_" [1000] 999) syntax "_text_prop_" :: \<open>prop \<Rightarrow> text_\<close> ("_" [1000] 999) syntax "_text_newline_" :: \<open>text_\<close> ("\<newline>") syntax "_text_cat_" :: \<open>text_ \<Rightarrow> text_ \<Rightarrow> text_\<close> ("_ _" [1,2] 1) ML \<open> structure Text_Encoding = struct val escape_string = String.translate (fn #"." => "\001" | x => str x) val recovery_string = String.translate (fn #"\001" => "." | x => str x) local open Ast fun dest_literal (Appl [Constant \<^syntax_const>\<open>_constrain\<close>, x, _]) = dest_literal x | dest_literal (Appl [Constant \<^syntax_const>\<open>_bound\<close>, x]) = dest_literal x | dest_literal (Variable x) = recovery_string x fun decode_text_ast' ret (Appl [Constant \<^const_syntax>\<open>text.literal\<close>, Appl [Constant \<^syntax_const>\<open>_abs\<close>, x, _]]) = Variable (cartouche (dest_literal x))::ret | decode_text_ast' ret (Appl [Constant \<^const_syntax>\<open>text.term\<close>, tm]) = tm::ret | decode_text_ast' ret (Appl [Constant \<^const_syntax>\<open>text.type\<close>, tm]) = tm::ret | decode_text_ast' ret (Constant \<^const_syntax>\<open>text.newline\<close>) = (Constant \<^syntax_const>\<open>_text_newline_\<close>)::ret | decode_text_ast' ret (Appl [Constant \<^const_syntax>\<open>text.cat\<close>, tmA, tmB]) = decode_text_ast' (decode_text_ast' ret tmB) tmA | decode_text_ast' _ ast = raise AST ("decode_text_ast", [ast]) in fun decode_text _ (\<^const>\<open>text.literal\<close> $ Abs (text, _, _)) = [Pretty.str (recovery_string text)] | decode_text ctxt (Const (\<^const_name>\<open>text.term\<close>, _) $ x) = [Syntax.pretty_term ctxt x] | decode_text ctxt (Const (\<^const_name>\<open>text.type\<close>, _) $ \<^Const_>\<open>Pure.type T\<close>) = [Syntax.pretty_typ ctxt T] | decode_text ctxt (\<^const>\<open>text.cat\<close> $ A $ B) = decode_text ctxt A @ decode_text ctxt B | decode_text _ (\<^const>\<open>text.newline\<close>) = [Pretty.brk 0] | decode_text ctxt (\<^const>\<open>text.text\<close> $ X) = decode_text ctxt X | decode_text _ tm = raise TERM ("decode_text", [tm]) fun decode_text_pretty ctxt X = Pretty.block (Pretty.separate "" (decode_text ctxt X)) fun decode_text_str ctxt X = Pretty.string_of (decode_text_pretty ctxt X) fun decode_text_ast ast = case decode_text_ast' [] ast of [] => Variable "" | [x] => x | l => Appl l end end \<close> parse_ast_translation \<open> let open Ast fun dest_literal (Appl [Constant \<^syntax_const>\<open>_constrain\<close>, x, _]) = dest_literal x | dest_literal (Appl [Constant \<^syntax_const>\<open>_text_literal_\<close>, x]) = dest_literal x | dest_literal (Variable x) = String.substring (x, 7, size x - 15) (*7 for size of \ <open> and 15 for size of \ <open> \ <close>*) fun encode_literal str = Appl [Constant \<^const_syntax>\<open>text.literal\<close>, Appl [Constant \<^syntax_const>\<open>_abs\<close>, Appl [Constant \<^syntax_const>\<open>_constrain\<close>, Variable (Text_Encoding.escape_string str), Constant \<^type_syntax>\<open>text\<close>], Appl [Constant \<^syntax_const>\<open>_constrain\<close>, Constant \<^const_syntax>\<open>undefined\<close>, Constant \<^type_syntax>\<open>text\<close>]]] fun parse (Appl [Constant \<^syntax_const>\<open>_text_literal_\<close>, tm]) = encode_literal (dest_literal tm) | parse (Appl [Constant \<^syntax_const>\<open>_text_prop_\<close>, tm]) = parse (Appl [Constant \<^syntax_const>\<open>_text_term_\<close>, tm]) | parse (Appl [Constant \<^syntax_const>\<open>_text_term_\<close>, (tm as Appl [Constant \<^syntax_const>\<open>_TYPE\<close>, _])]) = Appl [Constant \<^const_syntax>\<open>text.type\<close>, tm] | parse (Appl [Constant \<^syntax_const>\<open>_text_term_\<close>, tm]) = Appl [Constant \<^const_syntax>\<open>text.term\<close>, tm] | parse (Constant \<^syntax_const>\<open>_text_newline_\<close>) = Constant \<^const_syntax>\<open>text.newline\<close> | parse (Appl [Constant \<^syntax_const>\<open>_text_cat_\<close>, tmA, tmB]) = Appl [Constant \<^const_syntax>\<open>text.cat\<close>, parse tmA, parse tmB] in [(\<^syntax_const>\<open>_text_\<close>, (fn ctxt => fn [ast] => Appl [Constant \<^const_syntax>\<open>text.text\<close>, parse ast]))] end\<close> print_ast_translation \<open>[(\<^const_syntax>\<open>text.text\<close>, (fn ctxt => fn [ast] => Ast.Appl [Ast.Constant \<^syntax_const>\<open>_text_\<close>, Text_Encoding.decode_text_ast ast]))]\<close> subsection \<open>Reasoners for Printing Message\<close> subsubsection \<open>Tracing\<close> definition TRACING :: \<open>text \<Rightarrow> bool\<close> where [iff]: \<open>TRACING x \<longleftrightarrow> True\<close> lemma TRACING_I: \<open>TRACING x\<close> unfolding TRACING_def .. \<phi>reasoner_ML TRACING 1200 (\<open>TRACING ?x\<close>) = \<open>fn (ctxt,sequent) => let val \<^const>\<open>Trueprop\<close> $ (\<^const>\<open>TRACING\<close> $ text) = Thm.major_prem_of sequent val str = Text_Encoding.decode_text_str ctxt text val _ = tracing str in Seq.single (ctxt, @{thm TRACING_I} RS sequent) end\<close> subsubsection \<open>Warning\<close> definition WARNING :: \<open>text \<Rightarrow> bool\<close> where [iff]: \<open>WARNING x \<longleftrightarrow> True\<close> lemma WARNING_I: \<open>WARNING x\<close> unfolding WARNING_def .. \<phi>reasoner_ML WARNING 1200 (\<open>WARNING ?x\<close>) = \<open>fn (ctxt,sequent) => let val \<^const>\<open>Trueprop\<close> $ (\<^const>\<open>WARNING\<close> $ text) = Thm.major_prem_of sequent val str = Text_Encoding.decode_text_str ctxt text val _ = warning str in Seq.single (ctxt, @{thm WARNING_I} RS sequent) end\<close> subsubsection \<open>Fail\<close> text \<open>Fail ends the current search branch but does not terminate the whole reasoning.\<close> definition FAIL :: \<open>text \<Rightarrow> bool\<close> where [iff]: \<open>FAIL x \<longleftrightarrow> False\<close> definition FAIL' :: \<open>text \<Rightarrow> prop\<close> where [iff]: \<open>FAIL' x \<equiv> (\<And>P. PROP P)\<close> \<phi>reasoner_ML FAIL 1200 (\<open>FAIL ?x\<close> | \<open>PROP FAIL' ?x'\<close>) = \<open>fn (ctxt,sequent) => let val text = case Thm.major_prem_of sequent of \<^const>\<open>Trueprop\<close> $ (\<^const>\<open>FAIL\<close> $ X) => X | \<^const>\<open>FAIL'\<close> $ X => X val str = Text_Encoding.decode_text_str ctxt text val _ = warning str in Seq.empty end\<close> subsubsection \<open>Error\<close> text \<open>Fail terminates the whole reasoning.\<close> definition ERROR :: \<open>text \<Rightarrow> bool\<close> where [iff]: \<open>ERROR x \<longleftrightarrow> False\<close> definition ERROR' :: \<open>text \<Rightarrow> prop\<close> where [iff]: \<open>ERROR' x \<equiv> (\<And>P. PROP P)\<close> \<phi>reasoner_ML ERROR 1200 (\<open>ERROR ?x\<close> | \<open>PROP ERROR' ?x'\<close>) = \<open>fn (ctxt,sequent) => let val text = case Thm.major_prem_of sequent of \<^const>\<open>Trueprop\<close> $ (\<^const>\<open>ERROR\<close> $ X) => X | \<^const>\<open>ERROR'\<close> $ X => X val str = Text_Encoding.decode_text_str ctxt text val _ = error str in Seq.empty end\<close> end
lemma AE_ball_countable: assumes [intro]: "countable X" shows "(AE x in M. \<forall>y\<in>X. P x y) \<longleftrightarrow> (\<forall>y\<in>X. AE x in M. P x y)"
-- ---------------------------------------------------------------- [ Effs.idr ] -- Module : Effs.idr -- Copyright : (c) Jan de Muijnck-Hughes -- License : see LICENSE -- --------------------------------------------------------------------- [ EOH ] ||| Effectful definitions module GRL.Lang.Common.Effs import System import Effects import Effect.System import Effect.StdIO import Effect.State import Effect.Exception import Effect.File import Data.AVL.Dict import Lightyear import Lightyear.Char import Lightyear.Strings import Lightyear.StringFile import GRL.Common import GRL.Model import GRL.IR import GRL.Builder import GRL.Lang.Common.Error import GRL.Eval %access export -- ----------------------------------------------------------------- [ Context ] public export GEnv : Type -> Type GEnv val = Dict String val Default (GEnv a) where default = empty -- ------------------------------------------------------- [ Effectful Context ] public export Lang : Type -> Type -> Type Lang cTy rTy = Eff rTy [ SYSTEM , FILE_IO () , STDIO , STATE (GEnv cTy) , EXCEPTION GError] ||| Read in a language specification readLangFile : Parser a -> String -> Lang ty a readLangFile p f = do res <- parseFile (NoSuchFileError) (ParserError) p f case res of Left err => raise err Right ast => pure ast ||| Add element to the context. getElem : String -> Lang cTy cTy getElem id = do env <- get case (lookup id env) of Nothing => raise $ NoSuchIdentError id Just e => pure e evaluateE : GModel -> Maybe Strategy -> Lang cTy EvalResult evaluateE m strat = pure $ evaluate FORWARD strat m processArgs : List String -> Lang cTy (String, Maybe String) processArgs Nil = raise NoFileError processArgs [x] = raise NoFileError processArgs [x,y] = pure (y, Nothing) processArgs (x::y::z::xs) = pure (y, Just z) -- ------------------------------------------------------------------ [ Pretty ] showRes : (GoalNode -> String) -> EvalResult -> Lang cTy () showRes pfunc res = case toString res pfunc of Nothing => raise BadModelError Just res => putStrLn res -- --------------------------------------------------------------------- [ EOF ]
theory PropLogic imports Main begin datatype formula = V string | NOT formula | And formula formula (infix "AND" 203) | Or formula formula (infix "OR" 202) | Imp formula formula (infix "\<rightarrow>" 201) fun Iff ::"formula \<Rightarrow> formula \<Rightarrow> formula" (infix "\<leftrightarrow>" 200) where "Iff a b = (a \<rightarrow> b) AND (b \<rightarrow> a)" type_synonym state = "string \<Rightarrow> bool" fun evalFol :: "formula \<Rightarrow> state \<Rightarrow> bool" where "evalFol (V n) s = s n" | "evalFol (NOT f) s = (\<not> evalFol f s)" | "evalFol (a AND b) s = (evalFol a s \<and> evalFol b s)" | "evalFol (a OR b) s = (evalFol a s \<or> evalFol b s)" | "evalFol (a \<rightarrow> b) s = (evalFol a s \<longrightarrow> evalFol b s)" fun nnfNot :: "formula \<Rightarrow> formula" where "nnfNot (NOT a) = a" | "nnfNot (a OR b) = (nnfNot a AND nnfNot b)" | "nnfNot (a AND b) = (nnfNot a OR nnfNot b)" | "nnfNot other = NOT other" fun toNNF :: "formula \<Rightarrow> formula" where "toNNF (V s) = V s" | "toNNF (NOT f) = nnfNot (toNNF f)" | "toNNF (a AND b) = toNNF a AND toNNF b" | "toNNF (a OR b) = toNNF a OR toNNF b" | "toNNF (a \<rightarrow> b) = nnfNot (toNNF a) OR toNNF b" abbreviation equiv :: "formula \<Rightarrow> formula \<Rightarrow> bool" (infix "\<sim>" 199) where "a \<sim> b \<equiv> (\<forall>s. evalFol a s = evalFol b s)" value "toNNF (NOT (V ''p'' \<rightarrow> V ''p'' AND V ''q''))" lemma nnfNot_equiv: "evalFol (nnfNot f) s = (\<not> evalFol f s)" by(induction f rule: nnfNot.induct, auto) lemma nnf_equiv: "toNNF f \<sim> f" by(induction f rule: toNNF.induct, auto simp add: nnfNot_equiv) text{* function to test if a formula is in NNF *} fun inNNF :: "formula \<Rightarrow> bool" where "inNNF (V v) = True" | "inNNF (NOT (V a)) = True" | "inNNF (NOT _) = False" | "inNNF (a AND b) = (inNNF a \<and> inNNF b)" | "inNNF (a OR b) = (inNNF a \<and> inNNF b)" | "inNNF (_ \<rightarrow> _) = False" lemma nnfNot_preserve_inNNF: "inNNF f \<Longrightarrow> inNNF (nnfNot f)" by(induction f rule: inNNF.induct, auto) lemma nnf_inNNF: "inNNF (toNNF f)" using nnfNot_preserve_inNNF by(induction f, auto) text{* test if a formula is in DNF *} fun noAnd :: "formula \<Rightarrow> bool" where "noAnd (V _) = True" | "noAnd (_ AND _) = False" | "noAnd (a OR b) = (noAnd a \<and> noAnd b)" | "noAnd (NOT v) = noAnd v" | "noAnd (a \<rightarrow> b) = (noAnd a \<and> noAnd b)" fun distrAndOverOr_and :: "formula \<Rightarrow> formula \<Rightarrow> formula" where "distrAndOverOr_and (f1 OR f2) f3 = (distrAndOverOr_and f1 f3 OR distrAndOverOr_and f2 f3)" | "distrAndOverOr_and f3 (f1 OR f2) = (distrAndOverOr_and f3 f1 OR distrAndOverOr_and f3 f2)" | "distrAndOverOr_and a b = a AND b" lemma distrAndOverOr_and_equiv : "distrAndOverOr_and a b \<sim> (a AND b)" by(induction a b rule: distrAndOverOr_and.induct, auto) fun distrAndOverOr :: "formula \<Rightarrow> formula" where "distrAndOverOr (a AND b) = distrAndOverOr_and (distrAndOverOr a) (distrAndOverOr b)" | "distrAndOverOr (a OR b) = (distrAndOverOr a) OR distrAndOverOr b" | "distrAndOverOr (a \<rightarrow> b) = (distrAndOverOr a) \<rightarrow> distrAndOverOr b" | "distrAndOverOr other = other" lemma distrAndOverOr_equiv: "distrAndOverOr f \<sim> f" using distrAndOverOr_and_equiv by(induction f rule: distrAndOverOr.induct, auto) fun toDNF :: "formula \<Rightarrow> formula" where "toDNF f = distrAndOverOr (toNNF f)" value "toDNF ((V ''q1'' OR NOT (NOT (V ''q2''))) AND (NOT (V ''r1'') \<rightarrow> V ''r2''))" lemma toDNF_equiv: "toDNF f \<sim> f" proof- have "toDNF f \<sim> toNNF f" using distrAndOverOr_equiv by auto then show ?thesis using nnf_equiv by auto qed value "toDNF ((V ''1'' OR V ''2'' ) AND (V ''3'' OR V ''4'' ))" fun distrOrOverAnd_or :: "formula \<Rightarrow> formula \<Rightarrow> formula" where "distrOrOverAnd_or (f1 AND f2) f3 = (distrOrOverAnd_or f1 f3 AND distrOrOverAnd_or f2 f3)" | "distrOrOverAnd_or f3 (f1 AND f2) = (distrOrOverAnd_or f3 f1 AND distrOrOverAnd_or f3 f2)" | "distrOrOverAnd_or a b = a OR b" lemma distrOrOverAnd_or_equiv : "distrOrOverAnd_or a b \<sim> (a OR b)" by(induction a b rule: distrOrOverAnd_or.induct, auto) fun distrOrOverAnd :: "formula \<Rightarrow> formula" where "distrOrOverAnd (a OR b) = distrOrOverAnd_or (distrOrOverAnd a) (distrOrOverAnd b)" | "distrOrOverAnd (a AND b) = (distrOrOverAnd a) AND distrOrOverAnd b" | "distrOrOverAnd (a \<rightarrow> b) = (distrOrOverAnd a) \<rightarrow> distrOrOverAnd b" | "distrOrOverAnd other = other" lemma distrOrOverAnd_equiv: "distrOrOverAnd f \<sim> f" using distrOrOverAnd_or_equiv by (induction f rule: distrOrOverAnd.induct, auto) fun toCNF :: "formula \<Rightarrow> formula" where "toCNF f = distrOrOverAnd (toNNF f)"
= = Professional boxing record = =
module PrintFloat where import AlonzoPrelude import PreludeShow import PreludeList import PreludeString import PreludeNat open AlonzoPrelude open PreludeShow open PreludeList, hiding(_++_) open PreludeString open PreludeNat typeS : Char -> Set typeS 'f' = Float show : (c : Char) -> (typeS c) -> String show 'f' f = showFloat f data Unit : Set where unit : Unit data Format : Set where stringArg : Format natArg : Format intArg : Format floatArg : Format charArg : Format litChar : Char -> Format badFormat : Char -> Format data BadFormat (c:Char) : Set where format' : List Char -> List Format format' ('%' :: 's' :: fmt) = stringArg :: format' fmt format' ('%' :: 'n' :: fmt) = natArg :: format' fmt -- format' ('%' :: 'd' :: fmt) = intArg :: format' fmt format' ('%' :: 'f' :: fmt) = floatArg :: format' fmt format' ('%' :: 'c' :: fmt) = charArg :: format' fmt format' ('%' :: '%' :: fmt) = litChar '%' :: format' fmt format' ('%' :: c :: fmt) = badFormat c :: format' fmt format' (c :: fmt) = litChar c :: format' fmt format' [] = [] format : String -> List Format format s = format' (toList s) -- Printf1 : Format -> Set -- Printf1 floatArg = Float Printf' : List Format -> Set Printf' (stringArg :: fmt) = String × Printf' fmt Printf' (natArg :: fmt) = Nat × Printf' fmt Printf' (intArg :: fmt) = Int × Printf' fmt Printf' (floatArg :: fmt) = Float × Printf' fmt Printf' (charArg :: fmt) = Char × Printf' fmt Printf' (badFormat c :: fmt) = BadFormat c Printf' (litChar _ :: fmt) = Printf' fmt Printf' [] = Unit × Unit Printf : String -> Set Printf fmt = Printf' (format fmt) printf' : (fmt : List Format) -> Printf' fmt -> String printf' (stringArg :: fmt) < s | args > = s ++ printf' fmt args printf' (natArg :: fmt) < n | args > = showNat n ++ printf' fmt args printf' (intArg :: fmt) < n | args > = showInt n ++ printf' fmt args printf' (floatArg :: fmt) < x | args > = showFloat x ++ printf' fmt args printf' (charArg :: fmt) < c | args > = showChar c ++ printf' fmt args printf' (litChar c :: fmt) args = fromList (c :: []) ++ printf' fmt args printf' (badFormat _ :: fmt) () printf' [] < unit | unit > = "" printf : (fmt : String) -> Printf fmt -> String printf fmt = printf' (format fmt) -- mainS = show 'f' 3.14 -- mainS = printf' (format "%f") < 3.14 | < unit | unit > > mainS = printf "pi = %f" < 3.14159 | < unit | unit > > -- mainS = fromList ( 'p' :: [] )
There had been an overwhelming Conservative @-@ Unionist majority in the Lords since the Liberal split in 1886 . With the Liberal Party attempting to push through significant welfare reforms with considerable popular support , this seemed certain to cause problems in the relationship between the Houses . Between 1906 and 1909 , several important measures were being considerably watered down or rejected outright : for example , Birrell introduced the Education Bill 1906 , which was intended to address nonconformist grievances arising from the Education Act 1902 , but which was amended by the Lords to such an extent that it was effectively a different bill , upon which the Commons dropped the bill . This led to the 26 June 1907 resolution in the House of Commons declaring that the Lords ' power should be curtailed , put forward by Liberal Prime Minister Henry Campbell @-@ Bannerman . In 1909 , hoping to force an election , the Lords rejected the financial bill based on the government budget ( the " People 's Budget " ) put forward by David Lloyd George , by 350 votes to 75 . This , according to the Commons , was " a breach of the Constitution , and a usurpation of the rights of the Commons " . The Lords suggested that the Commons justify its position as representing the will of the people : it did this through the January 1910 general election . The Liberal government lost heavily , but remained in majority with the help of a significant number of Irish Nationalist and Labour MPs . The Irish Nationalists saw the continued power of the Lords as detrimental to securing Irish Home Rule . Following the election , the Lords relented on the budget ( since reintroduced by the government ) , it passing the Lords on 28 April , a day after the Commons .
function [node,elem] = cuboidmesh(cuboid,h) %% CUBEHEXMESH uniform mesh of cuboid % % [node,elem] = cuboidmesh([x0,x1,y0,y1,z0,z1],h) generates a uniform mesh of the % cuboid [x0,x1]*[y0,y1]*[z0,z1] with mesh size h. % % Example % % % Copyright (C) Long Chen. See COPYRIGHT.txt for details. x0 = cuboid(1); x1 = cuboid(2); y0 = cuboid(3); y1 = cuboid(4); z0 = cuboid(5); z1 = cuboid(6); [x,y,z] = meshgrid(x0:h:x1,y0:h:y1,z0:h:z1); node = [x(:),y(:),z(:)]; %% Generate elements nx = size(x,1) - 1; % number of cells in x-direction ny = size(y,2) - 1; % number of cells in y-direction nz = size(z,2) - 1; % number of cells in z-direction elem = zeros(nx*ny*nz,8); cellidx = 1:nx*ny*nz; [i, j, k] = ind2sub([nx ny nz],cellidx); % index of cells in subscript form s =[ nx+1, ny+1, nz+1]; elem(cellidx,1) = sub2ind3(s,i,j,k); elem(cellidx,2) = sub2ind3(s,i,j+1,k); elem(cellidx,3) = sub2ind3(s,i+1,j+1,k); elem(cellidx,4) = sub2ind3(s,i+1,j,k); elem(cellidx,5) = sub2ind3(s,i,j,k+1); elem(cellidx,6) = sub2ind3(s,i,j+1,k+1); elem(cellidx,7) = sub2ind3(s,i+1,j+1,k+1); elem(cellidx,8) = sub2ind3(s,i+1,j,k+1); function idx = sub2ind3(siz,i,j,k) nr = siz(1); nc = siz(2); nv = siz(3); if (max(j)>nc) || (max(i)>nr) || (max(k)>nv) error(message('MATLAB:mysub2ind:IndexOutOfRange')); end idx = (k-1)*nr*nc + (j-1)*nr+i; end end
lemma infnorm_Max: fixes x :: "'a::euclidean_space" shows "infnorm x = Max ((\<lambda>i. \<bar>x \<bullet> i\<bar>) ` Basis)"
## Beam configuration examples from Beam module from sympy ```python import numpy as np import sympy as sp from sympy.physics.continuum_mechanics.beam import Beam # https://docs.sympy.org/latest/modules/physics/continuum_mechanics/beam_problems.html sp.init_printing() ``` ```python # 3 point bending example x, E, I, F = sp.symbols('x E I F') l = sp.symbols('l', positive=True) # the l sign b3p = Beam(l, E, I) R1,R2 = sp.symbols('R1 R2') b3p.apply_load(R1, 0, -1) b3p.apply_load(R2, l, -1) b3p.apply_load(-F, l/2, -1) b3p.bc_deflection = [(0, 0),(l, 0)] b3p.solve_for_reaction_loads(R1, R2) ``` ```python # 4 point bending example x, E, I, F = sp.symbols('x E I F') l = sp.symbols('l', positive=True) b4p = Beam(l, E, I) R1,R2 = sp.symbols('R1 R2') b4p.apply_load(R1, 0, -1) b4p.apply_load(R2, l, -1) b4p.apply_load(-F, l/3, -1) b4p.apply_load(-F, 2*l/3, -1) b4p.bc_deflection = [(0, 0),(l, 0)] b4p.solve_for_reaction_loads(R1, R2) ``` ```python # single moment example x, E, I, F = sp.symbols('x E I F') l = sp.symbols('l', positive=True) # the l sign bmo = Beam(l, E, I) R1,R2 = sp.symbols('R1 R2') bmo.apply_load(R1, 0, -1) bmo.apply_load(R2, l, -1) bmo.apply_load(F, l/2, -2) bmo.bc_deflection = [(0, 0),(l, 0)] bmo.solve_for_reaction_loads(R1, R2) ``` ```python # distrubuted load simple beam example E,I,M,V = sp.symbols('E I M V') bdi = Beam(l, E, I) E,I,R1,R2 = sp.symbols('E I R1 R2') bdi.apply_load(R1, 0, -1) bdi.apply_load(R2, l, -1) bdi.apply_load(-F, 0, 0) bdi.bc_deflection = [(0, 0),(l, 0)] bdi.solve_for_reaction_loads(R1, R2) ``` ```python # 3 span distributed load example x, E, I, F = sp.symbols('x E I F') l = sp.symbols('l', positive=True) b3s = Beam(l, E, I) R1,R2,R3,R4 = sp.symbols('R1 R2 R3 R4') b3s.apply_load(R1, 0, -1) b3s.apply_load(R2, l/3, -1) b3s.apply_load(R3, 2*l/3, -1) b3s.apply_load(R4, l, -1) b3s.apply_load(-F, 0, 0) b3s.bc_deflection = [(0, 0),(l/3, 0),(2*l/3, 0),(l, 0)] b3s.solve_for_reaction_loads(R1, R2, R3,R4) ``` ```python # fixed support example E, I, F = sp.symbols('E I F') # l = sp.symbols('l', positive=True) bf = Beam(l, E, I) R1,R2 = sp.symbols('R1 R2') M1, M2 = sp.symbols('M1, M2') bf.apply_load(R1, 0, -1) bf.apply_load(M1, 0, -2) bf.apply_load(R2, l, -1) bf.apply_load(M2, l, -2) bf.apply_load(-F, l/2, -1) bf.bc_deflection = [(0, 0),(l, 0)] bf.bc_slope = [(0, 0),(l, 0)] bf.solve_for_reaction_loads(R1, R2, M1, M2) ```
[STATEMENT] lemma frac_eq: "frac x = x \<longleftrightarrow> 0 \<le> x \<and> x < 1" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (frac x = x) = ((0::'a) \<le> x \<and> x < (1::'a)) [PROOF STEP] by (simp add: frac_unique_iff)
module AgdaCheatSheet where open import Level using (Level) open import Data.Nat open import Data.Bool hiding (_<?_) open import Data.List using (List; []; _∷_; length) -- https://alhassy.github.io/AgdaCheatSheet/CheatSheet.pdf {- ------------------------------------------------------------------------------ -- dependent function A function whose RESULT type depends on the VALUE of the argument. -- given value of type A -- return result of type B a (a : A) → B a E.g., generic identity -- input -- the type of X -- value of type X -- output a function X → X -} id0 : (X : Set) → X → X id0 X x = x id1 id2 id3 : (X : Set) → X → X id1 X = λ x → x id2 = λ X x → x id3 = λ (X : Set) (x : X) → x -- call it sad : ℕ sad = id0 ℕ 3 {- ------------------------------------------------------------------------------ -- implicits In above, type arg can be inferred. Use curly braces to mark arg as implicit. -} id : {X : Set} → X → X id x = x -- call it nice : ℕ nice = id 3 -- call with explicit implicit explicit : ℕ explicit = id {ℕ} 3 -- call with explicit inferred implicit explicit’ : ℕ explicit’ = id0 _ 3 {- ------------------------------------------------------------------------------ -- specifying arguments {x : _} {y : _} (z : _) → · · · ≈ ∀ {x y} z → · · · (a1 : A) → (a2 : A) → (b : B) → · · · ≈ (a1 a2 : A) (b : B) → · · · ------------------------------------------------------------------------------ -- dependent datatypes -- data -- name -- arguments -- type of the datatype -- constructors and their types -} data Vec {ℓ : Level} (A : Set ℓ) : ℕ → Set ℓ where [] : Vec A 0 _::_ : {n : ℕ} → A → Vec A n → Vec A (1 + n) {- For a given A, type of Vec A is N → Set. Means Vec A is a FAMILY of types indexed by natural numbers: - For each n, there is a TYPE Vec A n. Vec is - parametrised by A (and ℓ) - indexed by n A is type of elements n is length only way to Vec A 0 is via [] only way to Vec A (1 + n) is via _::_ enables safe head (since empty impossible) -} head : {A : Set} {n : ℕ} → Vec A (1 + n) → A head (x :: xs) = x {- ------------------------------------------------------------------------------ -- universes ℓ arg says Vec is universe polymorphic - can vectors of numbers and also vectors of types Levels are essentially natural numbers: - constructurs - lzero - lsuc - _t_ : max of two levels NO UNIVERSE OF ALL UNIVERSES: - Set n has type Set n+1 for any n - the type (n : Level) → Set n - is not itself typeable — i.e., is not in Set ℓ for any ℓ — Agda errors saying it is a value of Set ω ------------------------------------------------------------------------------ -- functions defined by pattern matching ALL cases must terminate : so recursive calls must be made on structurally smaller arg -} infixr 40 _++_ _++_ : {A : Set} {n m : ℕ} → Vec A n → Vec A m → Vec A (n + m) [] ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) {- Append type encodes property : length of catenation is sum of args lengths - Different types can have the same constructor names. - Mixifx operators can be written prefix by having all underscores mentioned; e.g., - In def, if an arg is not needed, use _ (wildcard pattern) ------------------------------------------------------------------------------ -- Curry-Howard Correspondence — Propositions as Types Logic Programming Example Use in Programming ================================================================================ proof / proposition element / type “p is a proof of P” ≈ “p is of type P” true singleton type return type of side-effect only methods false empty type return type for non-terminating methods ⇒ function type → methods with an input and output type ∧ product type × simple records of data and methods ∨ sum type + enumerations or tagged unions ∀ dependent function type Π return type varies according to input value ∃ dependent product type Σ record fields depend on each other’s values natural deduction type system ensuring only “meaningful” programs hypothesis free variable global variables, closures modus ponens function application executing methods on arguments ⇒ -introduction λ-abstraction parameters acting as local variables to method definitions induction; elimination rules Structural recursion for-loops are precisely N-induction Signature, term Syntax; interface, record type, class Algebra, Interpretation Semantics; implementation, instance, object Free Theory Data structure Inference rule Algebraic datatype constructor Monoid Untyped programming / composition Category Typed programming / composition ------------------------------------------------------------------------------ -- equality example of propositions-as-types : definition of identity relation (the least reflexive relation) -} data _≡_ {A : Set} : A → A → Set where refl : {x : A} → x ≡ x {- states that refl {x} - is a proof of l ≡ r - whenever l and r simplify to x - by definition chasing only Use it to prove Leibniz’s substitutivity rule, “equals for equals”: -} subst : {A : Set} {P : A → Set} {l r : A} → l ≡ r -- must be of the form refl {x} for some canonical form x → P l -- if l and r are both x, then P l and P r are the same type → P r -- matching on proof l ≡ r gave infor about the rest of the program’s type subst refl it = it ------------------------------------------------------------------------------ -- modules - namespace management -------------------------------------------------- -- SIMPLE MODULES module M where N : Set N = ℕ private x : ℕ x = 3 y : N y = x + 1 -- using it - public names accessible by qualification or by opening them locally or globally use0 : M.N use0 = M.y use1 : ℕ use1 = y where open M {- if open, then causes y in M' to duplicate open M use2 : ℕ use2 = y -} -------------------------------------------------- -- PARAMETERISED MODULES : by arbitrarily many values and types (but not by other modules) module M’ (x : ℕ) where y : ℕ y = x + 1 -- names are functions --exposed : (x : ℕ) → ℕ --exposed = M’.y -- TODO compile error -- using it use’0 : ℕ use’0 = M’.y 3 module M” = M’ 3 use” : ℕ use” = M”.y use’1 : ℕ use’1 = y where open M’ 3 {- “Using Them”: - names in parameterised modules are are treated as functions - can instantiate some parameters and name the resulting module - can still open them as usual -------------------------------------------------- -- ANONYMOUS MODULES -- named-then-immediately-opened modules module _ {A : Set} {a : A} · · · ≈ module T {A : Set} {a : A} · · · open T -- use-case : to approximate the informal phrase -- “for any A : Set and a : A, we have · · · ” -- so common that variable keyword was introduced -- Names in · · · are functions of only those variable-s they actually mention. variable A : Set a : A -------------------------------------------------- -- opening, using, hiding, renaming open M hiding (n0; ...; nk) : treat ni as private open M using (n0; ...; nk) : treat only ni as public open M renaming (n0 to m0; ...; nk to mk) : use names mi instead of ni import X.Y.Z : Use the definitions of module Z which lives in file ./X/Y/Z.agda. open M public : Treat the contents of M as if it is the public contents of the current module Splitting a program over several files improves type checking performance, since only need to type check files influenced by the change. ------------------------------------------------------------------------------ -- records : record ≈ module + data with one constructor -} record PointedSet : Set1 where constructor MkIt {- optional -} field Carrier : Set point : Carrier {- like a module, so can add derived definitions -} blind : {A : Set} → A → Carrier blind = λ a → point -- construct without named constructor ex0 : PointedSet ex0 = record {Carrier = ℕ; point = 3} -- construct with named constructor ex1 : PointedSet ex1 = MkIt ℕ 3 open PointedSet ex2 : PointedSet Carrier ex2 = ℕ point ex2 = 3 {- Start with ex2 = ?, then in the hole enter C-c C-c RET to obtain the co-pattern setup. Two tuples are the same when they have the same components. Likewise a record is defined by its projections, whence co-patterns. If you’re using many local definitions, you likely want to use co-patterns. To enable projection of the fields from a record, each record type comes with a module of the same name. This module is parameterised by an element of the record type and contains projection functions for the fields. -} useR0 : ℕ useR0 = PointedSet.point ex0 {- use¹ : ℕ use¹ = point where open PointedSet ex0 -- TODO compile error -} open PointedSet use² : ℕ use² = blind ex0 true -- pattern match on records use³ : (P : PointedSet) → Carrier P use³ record {Carrier = C; point = x} = x use4 : (P : PointedSet) → Carrier P use4 (MkIt C x) = x {- ------------------------------------------------------------------------------ -- TODO Interacting with the real world —Compilation, Haskell, and IO ------------------------------------------------------------------------------ -- absurd patterns When no constructor are matchable - match the pattern () - provide no right hand side (since no way to could provide an arg to the function) E.g., numbers smaller than a given natural number -} {- Fin n ∼= numbers i with i < n -} data Fin : ℕ → Set where fzero : {n : ℕ} → Fin (suc n) -- smaller than suc n for any n fsuc : {n : ℕ} → Fin n → Fin (suc n) -- if i smaller than n then fsuc i is smaller than suc n. {- for each n, the type Fin n contains n elements - Fin 2 has elements fsuc fzero and fzero - Fin 0 has no elements safe indexing function -} _!!_ : {A : Set} {n : ℕ} → Vec A n → Fin n → A [] !! () -- n is necessarily 0, but no way to make an element of type Fin 0 -- so use absurd pattern (x :: xs) !! fzero = x (x :: xs) !! fsuc i = xs !! i -- Logically “anything follows from false” becomes the following program: data False : Set where magic : {Anything-you-want : Set} → False → Anything-you-want magic () {- do magic x = ? then case split on x yields the program ------------------------------------------------------------------------------ -- isTrue pattern : passing around explicit proof objects -- when not possible/easy to capture a desired precondition in types -} -- An empty record has only one value: record {} -} record True : Set where isTrue : Bool → Set isTrue true = True isTrue false = False _<0_ : ℕ → ℕ → Bool _ <0 zero = false zero <0 suc y = true suc x <0 suc y = x <0 y find : {A : Set} (xs : List A) (i : ℕ) → isTrue (i <0 length xs) → A find [] i () find (x ∷ xs) zero pf = x find (x ∷ xs) (suc i) pf = find xs i pf head’ : {A : Set} (xs : List A) → isTrue (0 <0 length xs) → A head’ [] () head’ (x ∷ xs) _ = x -- Unlike the _!!_ definition -- rather than there being no index into the empty list -- there is no proof that a natural number i is smaller than 0 {- ------------------------------------------------------------------------------ Mechanically Moving from Bool to Set —Avoiding “Boolean Blindness” proposition represented as type whose elements denote proofs Why use? - awkward to request an index be “in bounds” in the find method, - easier to encode this using Fin - likewise, head’ is more elegant type when the non-empty precondition is part of the datatype definition, as in head. recipe : from Boolean functions to inductive datatype families 1. Write the Boolean function. 2. Throw away all the cases with right side false. 3. Every case that has right side true corresponds to a new nullary constructor. 4. Every case that has n recursive calls corresponds to an n-ary constructor. following these steps for _<0_: -} data _<1_ : ℕ → ℕ → Set where z< : {y : ℕ} → zero <1 y s< : {x y : ℕ} → x <1 y → suc x <1 suc y {- then prove - soundness : constructed values correspond to Boolean-true statements ensured by the second step in recipe - completeness : true things correspond to terms formed from constructors. -} completeness : {x y : ℕ} → isTrue (x <0 y) → x <1 y completeness {x} {zero} () completeness {zero} {suc y} p = z< completeness {suc x} {suc y} p = s< (completeness p) {- begin with completeness {x} {y} p = ? then want case on p but that requires evaluating x <0 y which requires we know the shapes of x and y. shape of proofs usually mimics the shape of definitions they use ------------------------------------------------------------------------------ record Payload (A : Set) : Set field pPayload : [a] record BlockType (A : Set) : Set = Proposal (Payload a) Author | NilBlock | Genesis record LastVoteInfo fields lviLiDigest :: HashValue lviRound :: Round lviIsTimeout :: Bool -}
[GOAL] C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C U : TopologicalSpace.Opens ↑X s : Sieve U hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) U ⊢ Presieve.IsSheafFor (F ⋙ coyoneda.obj (op c)) s.arrows [PROOFSTEP] obtain rfl | hne := eq_or_ne U ⊥ [GOAL] case inl C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊥ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊥ ⊢ Presieve.IsSheafFor (F ⋙ coyoneda.obj (op c)) s.arrows [PROOFSTEP] intro _ _ [GOAL] case inl C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊥ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊥ x✝ : Presieve.FamilyOfElements (F ⋙ coyoneda.obj (op c)) s.arrows a✝ : Presieve.FamilyOfElements.Compatible x✝ ⊢ ∃! t, Presieve.FamilyOfElements.IsAmalgamation x✝ t [PROOFSTEP] rw [@exists_unique_iff_exists _ ⟨fun _ _ => _⟩] [GOAL] case inl C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊥ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊥ x✝ : Presieve.FamilyOfElements (F ⋙ coyoneda.obj (op c)) s.arrows a✝ : Presieve.FamilyOfElements.Compatible x✝ ⊢ ∃ x, Presieve.FamilyOfElements.IsAmalgamation x✝ x [PROOFSTEP] refine' ⟨it.from _, fun U hU hs => IsTerminal.hom_ext _ _ _⟩ [GOAL] case inl C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊥ hs✝ : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊥ x✝ : Presieve.FamilyOfElements (F ⋙ coyoneda.obj (op c)) s.arrows a✝ : Presieve.FamilyOfElements.Compatible x✝ U : TopologicalSpace.Opens ↑X hU : U ⟶ ⊥ hs : s.arrows hU ⊢ IsTerminal (F.obj (op U)) [PROOFSTEP] rwa [le_bot_iff.1 hU.le] [GOAL] C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊥ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊥ x✝ : Presieve.FamilyOfElements (F ⋙ coyoneda.obj (op c)) s.arrows a✝ : Presieve.FamilyOfElements.Compatible x✝ ⊢ ∀ (x x_1 : (F ⋙ coyoneda.obj (op c)).obj (op ⊥)), x = x_1 [PROOFSTEP] apply it.hom_ext [GOAL] case inr C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C U : TopologicalSpace.Opens ↑X s : Sieve U hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) U hne : U ≠ ⊥ ⊢ Presieve.IsSheafFor (F ⋙ coyoneda.obj (op c)) s.arrows [PROOFSTEP] convert Presieve.isSheafFor_top_sieve (F ⋙ coyoneda.obj (@op C c)) [GOAL] case h.e'_5.h.h.e'_4 C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C U : TopologicalSpace.Opens ↑X s : Sieve U hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) U hne : U ≠ ⊥ ⊢ s = ⊤ [PROOFSTEP] rw [← Sieve.id_mem_iff_eq_top] [GOAL] case h.e'_5.h.h.e'_4 C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C U : TopologicalSpace.Opens ↑X s : Sieve U hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) U hne : U ≠ ⊥ ⊢ s.arrows (𝟙 U) [PROOFSTEP] have := (U.eq_bot_or_top hind).resolve_left hne [GOAL] case h.e'_5.h.h.e'_4 C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C U : TopologicalSpace.Opens ↑X s : Sieve U hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) U hne : U ≠ ⊥ this : U = ⊤ ⊢ s.arrows (𝟙 U) [PROOFSTEP] subst this [GOAL] case h.e'_5.h.h.e'_4 C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊤ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊤ hne : ⊤ ≠ ⊥ ⊢ s.arrows (𝟙 ⊤) [PROOFSTEP] obtain he | ⟨⟨x⟩⟩ := isEmpty_or_nonempty X [GOAL] case h.e'_5.h.h.e'_4.inl C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊤ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊤ hne : ⊤ ≠ ⊥ he : IsEmpty ↑X ⊢ s.arrows (𝟙 ⊤) [PROOFSTEP] exact (hne <| SetLike.ext'_iff.2 <| Set.univ_eq_empty_iff.2 he).elim [GOAL] case h.e'_5.h.h.e'_4.inr.intro C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊤ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊤ hne : ⊤ ≠ ⊥ x : ↑X ⊢ s.arrows (𝟙 ⊤) [PROOFSTEP] obtain ⟨U, f, hf, hm⟩ := hs x _root_.trivial [GOAL] case h.e'_5.h.h.e'_4.inr.intro.intro.intro.intro C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊤ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊤ hne : ⊤ ≠ ⊥ x : ↑X U : TopologicalSpace.Opens ↑X f : U ⟶ ⊤ hf : s.arrows f hm : x ∈ U ⊢ s.arrows (𝟙 ⊤) [PROOFSTEP] obtain rfl | rfl := U.eq_bot_or_top hind [GOAL] case h.e'_5.h.h.e'_4.inr.intro.intro.intro.intro.inl C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊤ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊤ hne : ⊤ ≠ ⊥ x : ↑X f : ⊥ ⟶ ⊤ hf : s.arrows f hm : x ∈ ⊥ ⊢ s.arrows (𝟙 ⊤) [PROOFSTEP] cases hm [GOAL] case h.e'_5.h.h.e'_4.inr.intro.intro.intro.intro.inr C : Type u inst✝ : Category.{v, u} C X : TopCat hind : X.str = ⊤ F : Presheaf C X it : IsTerminal (F.obj (op ⊥)) c : C s : Sieve ⊤ hs : s ∈ GrothendieckTopology.sieves (Opens.grothendieckTopology ↑X) ⊤ hne : ⊤ ≠ ⊥ x : ↑X f : ⊤ ⟶ ⊤ hf : s.arrows f hm : x ∈ ⊤ ⊢ s.arrows (𝟙 ⊤) [PROOFSTEP] convert hf