From 21de0d35017656c5a55528390b54b0b2ae395b44 Mon Sep 17 00:00:00 2001 From: Ferruccio Guidi Date: Fri, 8 Jan 2021 17:06:39 +0100 Subject: [PATCH] =?utf8?q?arithmetics=20for=20=CE=BB=CE=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit + advances on maximum for non-negative integers + part of nat.ma used by λδ covered in full + minor additions and corrections --- .../lambdadelta/ground/arith/arith.txt | 258 ++++++++++++++++++ .../contribs/lambdadelta/ground/arith/nat.txt | 14 +- .../lambdadelta/ground/arith/nat_iter.ma | 7 +- .../lambdadelta/ground/arith/nat_le.ma | 15 +- .../lambdadelta/ground/arith/nat_le_max.ma | 60 ++++ .../lambdadelta/ground/arith/nat_le_minus.ma | 6 +- .../ground/arith/nat_le_minus_plus.ma | 2 +- .../lambdadelta/ground/arith/nat_le_plus.ma | 2 +- .../lambdadelta/ground/arith/nat_le_pred.ma | 6 +- .../lambdadelta/ground/arith/nat_lt.ma | 18 +- .../lambdadelta/ground/arith/nat_lt_minus.ma | 20 +- .../lambdadelta/ground/arith/nat_lt_pred.ma | 2 +- .../lambdadelta/ground/arith/nat_lt_tri.ma | 32 +++ .../lambdadelta/ground/arith/nat_max.ma | 18 +- .../lambdadelta/ground/arith/nat_minus.ma | 26 +- .../ground/arith/nat_minus_plus.ma | 24 +- .../lambdadelta/ground/arith/nat_plus.ma | 37 ++- .../lambdadelta/ground/arith/nat_pred.ma | 2 +- .../lambdadelta/ground/arith/nat_pred_succ.ma | 2 +- .../lambdadelta/ground/arith/nat_succ.ma | 10 +- .../lambdadelta/ground/arith/nat_succ_iter.ma | 3 +- .../lambdadelta/ground/arith/nat_succ_tri.ma | 12 +- .../lambdadelta/ground/arith/nat_tri.ma | 4 +- .../lambdadelta/ground/arith/pnat_iter.ma | 5 +- .../lambdadelta/ground/arith/pnat_plus.ma | 6 +- .../lambdadelta/ground/arith/pnat_tri.ma | 4 +- .../lambdadelta/ground/web/ground_src.tbl | 4 +- 27 files changed, 497 insertions(+), 102 deletions(-) create mode 100644 matita/matita/contribs/lambdadelta/ground/arith/arith.txt create mode 100644 matita/matita/contribs/lambdadelta/ground/arith/nat_le_max.ma create mode 100644 matita/matita/contribs/lambdadelta/ground/arith/nat_lt_tri.ma diff --git a/matita/matita/contribs/lambdadelta/ground/arith/arith.txt b/matita/matita/contribs/lambdadelta/ground/arith/arith.txt new file mode 100644 index 000000000..1eda6fe22 --- /dev/null +++ b/matita/matita/contribs/lambdadelta/ground/arith/arith.txt @@ -0,0 +1,258 @@ +(* Equalities ***************************************************************) + +lemma minus_plus_m_m_commutative: ∀n,m:nat. n = m + n - m. +// qed-. + +lemma plus_minus_m_m_commutative (n) (m): m ≤ n → n = m+(n-m). +/2 width=1 by plus_minus_associative/ qed-. + +lemma plus_to_minus_2: ∀m1,m2,n1,n2. n1 ≤ m1 → n2 ≤ m2 → + m1+n2 = m2+n1 → m1-n1 = m2-n2. +#m1 #m2 #n1 #n2 #H1 #H2 #H +@plus_to_minus >plus_minus_associative // +qed-. + +(* Note: uses minus_minus_comm, minus_plus_m_m, commutative_plus, plus_minus *) +lemma plus_minus_minus_be: ∀x,y,z. y ≤ z → z ≤ x → (x - z) + (z - y) = x - y. +#x #z #y #Hzy #Hyx >plus_minus // >commutative_plus >plus_minus // +qed-. + +lemma lt_succ_pred: ∀m,n. n < m → m = ↑↓m. +#m #n #Hm >S_pred /2 width=2 by ltn_to_ltO/ +qed-. + +fact plus_minus_minus_be_aux: ∀i,x,y,z. y ≤ z → z ≤ x → i = z - y → x - z + i = x - y. +/2 width=1 by plus_minus_minus_be/ qed-. + +lemma le_plus_minus: ∀m,n,p. p ≤ n → m + n - p = m + (n - p). +/2 by plus_minus/ qed-. + +lemma le_plus_minus_comm: ∀n,m,p. p ≤ m → m + n - p = m - p + n. +/2 by plus_minus/ qed-. + +lemma minus_minus_comm3: ∀n,x,y,z. n-x-y-z = n-y-z-x. +// qed. + +(* Properties ***************************************************************) + +lemma eq_nat_dec: ∀n1,n2:nat. Decidable (n1 = n2). +#n1 elim n1 -n1 [| #n1 #IHn1 ] * [2,4: #n2 ] +[1,4: @or_intror #H destruct +| elim (IHn1 n2) -IHn1 /3 width=1 by or_intror, or_introl/ +| /2 width=1 by or_introl/ +] +qed-. + +lemma lt_or_eq_or_gt: ∀m,n. ∨∨ m < n | n = m | n < m. +#m #n elim (lt_or_ge m n) /2 width=1 by or3_intro0/ +#H elim H -m /2 width=1 by or3_intro1/ +#m #Hm * /3 width=1 by not_le_to_lt, le_S_S, or3_intro2/ +qed-. + +lemma monotonic_le_minus_l2: ∀x1,x2,y,z. x1 ≤ x2 → x1 - y - z ≤ x2 - y - z. +/3 width=1 by monotonic_le_minus_l/ qed. + +lemma minus_le_trans_sn: ∀x1,x2. x1 ≤ x2 → ∀x. x1-x ≤ x2. +/2 width=3 by transitive_le/ qed. + +lemma le_plus_to_minus_l: ∀a,b,c. a + b ≤ c → b ≤ c-a. +/2 width=1 by le_plus_to_minus_r/ +qed-. + +lemma le_plus_to_minus_comm: ∀n,m,p. n ≤ p+m → n-p ≤ m. +/2 width=1 by le_plus_to_minus/ qed-. + +lemma le_inv_S1: ∀m,n. ↑m ≤ n → ∃∃p. m ≤ p & ↑p = n. +#m * +[ #H lapply (le_n_O_to_eq … H) -H + #H destruct +| /3 width=3 by monotonic_pred, ex2_intro/ +] +qed-. + +(* Note: this might interfere with nat.ma *) +lemma monotonic_lt_pred: ∀m,n. m < n → 0 < m → pred m < pred n. +#m #n #Hmn #Hm whd >(S_pred … Hm) +@le_S_S_to_le >S_pred /2 width=3 by transitive_lt/ +qed. + +lemma lt_S_S: ∀x,y. x < y → ↑x < ↑y. +/2 width=1 by le_S_S/ qed. + +lemma lt_S: ∀n,m. n < m → n < ↑m. +/2 width=1 by le_S/ qed. + +lemma monotonic_lt_minus_r: +∀p,q,n. q < n -> q < p → n-p < n-q. +#p #q #n #Hn #H +lapply (monotonic_le_minus_r … n H) -H #H +@(le_to_lt_to_lt … H) -H +/2 width=1 by lt_plus_to_minus/ +qed. + +(* Inversion & forward lemmas ***********************************************) + +lemma lt_refl_false: ∀n. n < n → ⊥. +#n #H elim (lt_to_not_eq … H) -H /2 width=1 by/ +qed-. + +lemma lt_zero_false: ∀n. n < 0 → ⊥. +#n #H elim (lt_to_not_le … H) -H /2 width=1 by/ +qed-. + +lemma lt_le_false: ∀x,y. x < y → y ≤ x → ⊥. +/3 width=4 by lt_refl_false, lt_to_le_to_lt/ qed-. + +lemma le_dec (n) (m): Decidable (n≤m). +#n elim n -n [ /2 width=1 by or_introl/ ] +#n #IH * [ /3 width=2 by lt_zero_false, or_intror/ ] +#m elim (IH m) -IH +[ /3 width=1 by or_introl, le_S_S/ +| /4 width=1 by or_intror, le_S_S_to_le/ +] +qed-. + +lemma succ_inv_refl_sn: ∀x. ↑x = x → ⊥. +#x #H @(lt_le_false x (↑x)) // +qed-. + +lemma le_plus_xSy_O_false: ∀x,y. x + S y ≤ 0 → ⊥. +#x #y #H lapply (le_n_O_to_eq … H) -H H -H +/2 width=2 by le_plus_to_le/ +qed-. + +lemma plus2_le_sn_dx: ∀m1,m2,n1,n2. m1 + n1 = n2 + m2 → m1 ≤ m2 → n2 ≤ n1. +/2 width=4 by plus2_le_sn_sn/ qed-. + +lemma plus2_le_dx_sn: ∀m1,m2,n1,n2. n1 + m1 = m2 + n2 → m1 ≤ m2 → n2 ≤ n1. +/2 width=4 by plus2_le_sn_sn/ qed-. + +lemma plus2_le_dx_dx: ∀m1,m2,n1,n2. n1 + m1 = n2 + m2 → m1 ≤ m2 → n2 ≤ n1. +/2 width=4 by plus2_le_sn_sn/ qed-. + +lemma lt_S_S_to_lt: ∀x,y. ↑x < ↑y → x < y. +/2 width=1 by le_S_S_to_le/ qed-. + +(* Note this should go in nat.ma *) +lemma discr_x_minus_xy: ∀x,y. x = x - y → x = 0 ∨ y = 0. +#x @(nat_ind_plus … x) -x /2 width=1 by or_introl/ +#x #_ #y @(nat_ind_plus … y) -y /2 width=1 by or_intror/ +#y #_ >minus_plus_plus_l +#H lapply (discr_plus_xy_minus_xz … H) -H +#H destruct +qed-. + +lemma lt_inv_O1: ∀n. 0 < n → ∃m. ↑m = n. +* /2 width=2 by ex_intro/ +#H cases (lt_le_false … H) -H // +qed-. + +lemma lt_inv_S1: ∀m,n. ↑m < n → ∃∃p. m < p & ↑p = n. +#m * /3 width=3 by lt_S_S_to_lt, ex2_intro/ +#H cases (lt_le_false … H) -H // +qed-. + +lemma lt_inv_gen: ∀y,x. x < y → ∃∃z. x ≤ z & ↑z = y. +* /3 width=3 by le_S_S_to_le, ex2_intro/ +#x #H elim (lt_le_false … H) -H // +qed-. + +lemma plus_inv_O3: ∀x,y. x + y = 0 → x = 0 ∧ y = 0. +/2 width=1 by plus_le_0/ qed-. + +lemma plus_inv_S3_sn: ∀x1,x2,x3. x1+x2 = ↑x3 → + ∨∨ ∧∧ x1 = 0 & x2 = ↑x3 + | ∃∃y1. x1 = ↑y1 & y1 + x2 = x3. +* /3 width=1 by or_introl, conj/ +#x1 #x2 #x3 (nlt_inv_zero_sn … Hm) in ⊢ (??%?); -Hm ->(nlt_inv_zero_sn … Hn) in ⊢ (??%?); -Hn -// -qed-. - (* Constructions with nminus ************************************************) (*** monotonic_lt_minus_l *) @@ -38,8 +28,16 @@ qed. (* Destructions with nminus *************************************************) +(*** minus_pred_pred *) +lemma nminus_pred_bi (m) (n): 𝟎 < m → 𝟎 < n → n - m = ↓n - ↓m. +#m #n #Hm #Hn +>(nlt_inv_zero_sn … Hm) in ⊢ (??%?); -Hm +>(nlt_inv_zero_sn … Hn) in ⊢ (??%?); -Hn +// +qed-. + lemma nlt_des_minus_dx (o) (m) (n): m < n - o → o < n. -#o elim o -o +#o @(nat_ind_succ … o) -o [ #m #n nplus_succ_shift #Ho - elim (IH … Ho) -IH -Ho * #_ #H - elim (eq_inv_nzero_succ … H) - ] +| #m #o #Ho + lapply (eq_inv_nplus_bi_sn … (𝟎) Ho) -Ho + /3 width=1 by or_intror, conj/ +| #m #n #IH #o + nplus_succ_shift #Ho + elim (IH … Ho) -IH -Ho * #_ #H + elim (eq_inv_nzero_succ … H) ] qed-. diff --git a/matita/matita/contribs/lambdadelta/ground/arith/nat_plus.ma b/matita/matita/contribs/lambdadelta/ground/arith/nat_plus.ma index d9c82ae33..f7d79ccdf 100644 --- a/matita/matita/contribs/lambdadelta/ground/arith/nat_plus.ma +++ b/matita/matita/contribs/lambdadelta/ground/arith/nat_plus.ma @@ -24,22 +24,32 @@ interpretation "plus (positive integers)" 'plus m n = (nplus m n). -(* Basic rewrites ***********************************************************) +(* Basic constructions ******************************************************) (*** plus_n_O *) lemma nplus_zero_dx (m): m = m + 𝟎. // qed. +(*** plus_SO_dx *) lemma nplus_one_dx (n): ↑n = n + 𝟏. // qed. -(* Advanved rewrites (semigroup properties) *********************************) - (*** plus_n_Sm *) lemma nplus_succ_dx (m) (n): ↑(m+n) = m + ↑n. #m #n @(niter_succ … nsucc) qed. +(* Constructions with niter *************************************************) + +(*** iter_plus *) +lemma niter_plus (A) (f) (a) (n1) (n2): + f^n1 (f^n2 a) = f^{A}(n1+n2) a. +#A #f #a #n1 #n2 @(nat_ind_succ … n2) -n2 // +#n2 #IH