NUMBER19

index · ← GALOIS_2 · GALOIS_3 →
:: Elementary Number Theory Problems. {P}art {XIX}
::  by Karol P\kak
::
:: Received December 21, 2025
:: Copyright (c) 2025-2026 Association of Mizar Users
::           (Stowarzyszenie Uzytkownikow Mizara, Bialystok, Poland).
:: This code can be distributed under the GNU General Public Licence
:: version 3.0 or later, or the Creative Commons Attribution-ShareAlike
:: License version 4.0 or later, subject to the binding interpretation
:: detailed in file COPYING.interpretation.
:: See COPYING.GPL and COPYING.CC-BY-SA for the full text of these
:: licenses, or see http://www.gnu.org/licenses/gpl.html and
:: http://creativecommons.org/licenses/by-sa/4.0/.

environ

 vocabularies NUMBERS, RLVECT_1, ALGSTR_0, XBOOLE_0, FINSEQ_1, NAT_1, RELAT_1,
      REALSET1, ARYTM_3, TARSKI, ORDINAL4, PARTFUN1, XXREAL_0, FUNCT_1,
      SUBSET_1, STRUCT_0, BINOP_1, VECTSP_1, LATTICES, SUPINF_2, ARYTM_1,
      GROUP_1, CARD_1, MESFUNC1, COMPLFLD, COMPLEX1, CARD_3, POLYNOM1,
      POLYNOM3, SGRAPH1, INT_1, ALGSEQ_1, VECTSP_2, POLYNOM5, AFINSQ_1,
      POLYNOM2, FUNCOP_1, XCMPLX_0, HURWITZ, FINSEQ_2, VALUED_0, ZFMISC_1,
      REAL_1, QC_LANG1, C0SP1, FUNCSDOM, FINSEQ_3, FUNCT_7, FUNCT_2, ALGNUM_1,
      FINSET_1, ORDINAL1, UPROOTS, MEMBERED, INT_3, GAUSSINT, INT_2, NEWTON,
      RAT_1, NUMBER13, FINSEQ_4, JORDAN3, NAT_3, ABIAN, MOEBIUS1, POWER,
      EULER_1, NUMBER02, NUMBER12, INT_6, PARTFUN3, CALCUL_2, GROEB_1,
      NUMBER10, NUMBER14, NUMERAL1, FINSEQ_5, RFINSEQ, PEPIN, NUMBER19;
 notations TARSKI, XBOOLE_0, SUBSET_1, RELAT_1, REALSET1, MEMBERED, ORDINAL1,
      NUMBERS, XCMPLX_0, XREAL_0, ALGSTR_0, VECTSP_2, FUNCT_1, RELSET_1,
      PARTFUN1, FUNCT_2, XXREAL_0, FINSEQ_1, INT_1, NAT_1, FUNCOP_1, STRUCT_0,
      RLVECT_1, VFUNCT_1, GROUP_1, COMPLEX1, COMPLFLD, AFINSQ_1, AFINSQ_2,
      ALGSEQ_1, POLYNOM3, POLYNOM4, POLYNOM5, VECTSP_1, HURWITZ, BASEL_2,
      FINSEQ_2, RVSUM_1, GROUP_4, C0SP1, ALGNUM_1, ZFMISC_1, CARD_1, FINSET_1,
      DOMAIN_1, INT_3, NEWTON, GAUSSINT, RAT_1, INT_2, FINSEQ_4, WSIERP_1,
      FVSUM_1, NUMBER13, POWER, NAT_3, ABIAN, PEPIN, MOEBIUS1, EULER_1,
      RECDEF_1, RFINSEQ, FINSEQ_5, FINSEQ_6, VALUED_0, PARTFUN3, INT_6, NAT_D,
      NUMBER02, NUMBER10, NUMBER12, CALCUL_2, NUMBER14, NUMERAL1;
 constructors REALSET1, POLYNOM4, NAT_D, FVSUM_1, VFUNCT_1, ALGSEQ_1, BINOP_2,
      HURWITZ, BASEL_2, RATFUNC1, RING_3, GROUP_4, ALGNUM_1, WSIERP_1,
      NUMBER13, WELLORD2, NEWTON03, ABIAN, POWER, AFINSQ_2, NAT_3, EULER_1,
      PEPIN, RECDEF_1, MOEBIUS1, RFINSEQ, FINSEQ_5, FINSEQ_6, NUMBER02,
      PYTHTRIP, NUMBER10, NUMBER12, NEWTON04, NUMBER14, NUMERAL1, CALCUL_2;
 registrations XBOOLE_0, ORDINAL1, RELSET_1, XCMPLX_0, XXREAL_0, XREAL_0,
      NAT_1, INT_1, FINSEQ_1, STRUCT_0, VECTSP_1, COMPLFLD, ALGSTR_1, POLYNOM3,
      POLYNOM4, POLYNOM5, FUNCOP_1, CARD_1, VFUNCT_1, FUNCT_2, MEMBERED,
      FUNCT_1, NUMBERS, FINSEQ_2, VALUED_0, FINSET_1, SUBSET_1, RLVECT_1,
      RATFUNC1, RING_5, FIELD_4, NEWTON04, INT_3, GAUSSINT, NEWTON, WSIERP_1,
      COMPLEX1, NEWTON03, MOEBIUS1, FOMODEL0, RVSUM_1, RFINSEQ, ABIAN,
      FINSEQ_5, POWER, NUMBER03, NUMBER13, NAT_6, JORDAN1D, PARTFUN3, FINSEQ_9,
      NUMBER10, INT_6, NUMBER14, HILB10_4, AFINSQ_1, AFINSQ_2, RVSUM_4,
      CALCUL_2, NAT_5;
 requirements NUMERALS, SUBSET, REAL, BOOLE, ARITHM;
 definitions TARSKI;
 equalities FINSEQ_1, POLYNOM3, COMPLEX1, BASEL_2, XCMPLX_0, STRUCT_0, INT_3;
 expansions INT_1, ORDINAL1, INT_2;
 theorems GROUP_1, VECTSP_1, ALGSEQ_1, NAT_1, FUNCT_1, FUNCT_2, XREAL_1,
      VECTSP_2, INT_1, FINSEQ_1, RLVECT_1, POLYNOM4, TARSKI, POLYNOM3,
      XBOOLE_1, POLYNOM2, FUNCOP_1, XCMPLX_1, XCMPLX_0, COMPLFLD, POLYNOM5,
      XXREAL_0, COMPLEX1, FINSEQ_2, FINSEQ_3, ORDINAL1, PARTFUN1, NAT_D,
      HURWITZ, ALGSTR_0, C0SP1, FIELD_6, RELAT_1, RING_2, XBOOLE_0, NEWTON04,
      STRUCT_0, POLYALG1, CARD_2, RING_4, INT_2, NAT_5, FVSUM_1, ZFMISC_1,
      VALUED_0, RVSUM_1, CARD_1, GROUP_4, FINSEQ_5, UPROOTS, BHSP_5, RING_5,
      RING_3, ALGNUM_1, SUBSET_1, LIOUVIL2, REALSET1, ASYMPT_1, MOEBIUS1,
      ABSVALUE, RAT_1, NEWTON, PREPOWER, FINSEQ_4, PRE_FF, WSIERP_1, NUMBER13,
      GAUSSINT, NUMBER14, NUMBER04, MEMBERED, ENUMSET1, NOMIN_2, QUATERNI,
      EULER_1, NUMBER08, NAGATA_2, NUMBER09, NUMBER02, NAT_6, GR_CY_3,
      NUMBER15, NAT_3, NUMBER16, NAT_2, NEWTON03, NEWTON02, EULER_2, ABIAN,
      INT_4, INT_8, POWER, PEPIN, FINSEQ_6, PARTFUN3, HILB10_5, NUMBER10,
      NUMBER12, INT_6, PRIMRECI, MOEBIUS2, NAT_4, XPRIMES1, NUMERAL1, NUMERAL2,
      NUMBER11, AFINSQ_1, AFINSQ_2, NUMBER01, XPRIMES0, LATSTONE, POLYVIE1,
      FIELD_15, SIN_COS, NEWTON01, CALCUL_2;
 schemes NAT_1, FUNCT_2, FINSEQ_1, FINSEQ_2, FUNCT_1, AFINSQ_1;

begin :: Preliminaries

reserve n,m,k,i,a,b,c,d,s for Nat,
        p for Prime;

registration
  let f be positive-yielding real-valued FinSequence;
  cluster Rev f -> positive-yielding;
  coherence
  proof
A1: rng f = rng Rev f by FINSEQ_5:57;
    for r being Real st r in rng f holds 0 < r by PARTFUN3:def 1;
    hence thesis by A1,PARTFUN3:def 1;
  end;
  let n be Nat;
  cluster f/^n -> positive-yielding;
  coherence
  proof
    (f|n)^(f/^n) = f;
    hence thesis by NUMBER08:37;
  end;
  cluster f|n -> positive-yielding;
  coherence;
end;

registration
  let f be positive-yielding real-valued FinSequence;
  let n,m be Nat;
  cluster mid(f,n,m) -> positive-yielding;
  coherence
  proof
A1: (f /^ (n-'1)) | (m-'n+1) is positive-yielding;
    Rev ((f/^(m-'1)) | (n-'m+1)) is positive-yielding;
    hence thesis by A1,FINSEQ_6:def 3;
  end;
end;

theorem Th1:
  n divides m implies NatDivisors n c= NatDivisors m
proof
  assume
A1: n divides m;
  let x be object such that
A2: x in NatDivisors n;
  reconsider x as Nat by A2;
  0 < x & x divides n by A2,MOEBIUS1:39;
  hence thesis by A1,INT_2:9,MOEBIUS1:39;
end;

theorem
  for m being non zero Nat st p|^n divides m holds
    n+1 <= card NatDivisors m
proof
  let m being non zero Nat such that
A1: p|^n divides m;
  set n1=n+1;
  deffunc F(Nat) = p|^$1;
  consider f be Function such that
A2: dom f = Segm n1 and
A3: for d be Element of Segm n1 holds f.d = F(d) from FUNCT_1:sch 4;
  for x1,x2 be object st x1 in dom f & x2 in dom f & f.x1=f.x2 holds x1=x2
  proof
    let x1,x2 be object such that
A4:  x1 in dom f & x2 in dom f & f.x1=f.x2;
    reconsider x1,x2 as Nat by A4,A2;
A5:  F(x1) = f.x1 &  F(x2) =f.x2 by A4,A2,A3;
A6:  x1 < x2 & p > 1 implies p to_power x1 < p to_power x2 by POWER:39;
    x2 < x1 & p > 1 implies p to_power x2 < p to_power x1 by POWER:39;
    hence thesis by A6,A5,A4,INT_2:def 4,XXREAL_0:1;
  end;
  then
A7: card Segm n1 c= card rng f by FUNCT_1:def 4,A2,CARD_1:10;
  rng f c= {p|^k where k is Element of NAT : k <= n}
  proof
    let y be object;
    assume y in rng f;
    then consider x be object such that
A8:  x in dom f & f.x=y by FUNCT_1:def 3;
    reconsider x as Element of NAT by A8,A2;
    x < n1 by A8,A2,NAT_1:44;
    then
A9: x <= n by NAT_1:13;
    f.x = F(x) by A2,A3,A8;
    hence thesis by A9,A8;
  end;
  then rng f c= NatDivisors(p|^n) c= NatDivisors m by Th1,A1,NAT_5:19;
  then rng f c= NatDivisors m by XBOOLE_1:1;
  then card rng f c= card NatDivisors m by CARD_1:11;
  then card Segm n1 c= card Segm card NatDivisors m by A7;
  hence thesis by NAT_1:40;
end;

registration
  let p be Prime;
  cluster p-'1 -> non zero;
  coherence
  proof
    p>1 by INT_2:def 4;
    then p-'1 = p-1 >1-1 by XREAL_1:9,XREAL_1:233;
    hence thesis;
   end;
end;

theorem Th3:
   for k,m,n,p st 1 <= k <= m <= n holds
     p divides Product mid(primesFinS n,k,m) iff
       k <= 1 + primeindex p <= m
proof
  let k,m,n,p such that
A1: 1 <= k <= m <= n;
A2: len primesFinS n = n by NUMBER13:def 1;
A3: 1 <= m & k <= n by A1,XXREAL_0:2;
  set M=mid(primesFinS n,k,m);
A4:m-'k = m-k by A1,XREAL_1:233;
A5:len M = m-'k+1 by A1,A2,A3,FINSEQ_6:118;
  thus p divides Product M implies k <= 1 + primeindex p <= m
  proof
    assume p divides Product M;
    then consider i be Nat such that
A6: i in dom M & p divides M.i by HILB10_5:3;
A7: p > 1 by INT_2:def 4;
A8: 1<= i <= len M by A6,FINSEQ_3:25;
    then
A9: M.i = (primesFinS n). (i+k-'1) by A1,A2,A3,FINSEQ_6:118;
A10:1+1<= i+k by A1,A8,XREAL_1:7;
    then
A11:i+k-'1 = i+k-1 by XXREAL_0:2,XREAL_1:233;
    then reconsider ik = i+k-'1 -1 as Element of NAT
      by NAT_1:21,A10,XREAL_1:19;
A12: k +0 <= k +(i - 1) by A8,XREAL_1:6;
    i+k <= m-k+1+k by A8,A4,A5,XREAL_1:7;
    then
A13: i+k-'1 <= m+1-1 by A11,XREAL_1:9;
    then ik+1 <= m;
    then ik < m by NAT_1:13;
    then ik < n by A1,XXREAL_0:2;
    then (primesFinS n). (ik+1) = primenumber ik by NUMBER13:def 1;
    then p = primenumber ik by A7,INT_2:def 4,A6,A9;
    then ik = primeindex p by NUMBER10:def 4;
    hence thesis by A12,A11,A13;
  end;
  set I = primeindex p;
  assume
A14: k <= 1 + I <= m;
  then 1+I <= n by A1,XXREAL_0:2;
  then I < n by NAT_1:13;
  then primesFinS n.(I+1) = primenumber I by NUMBER13:def 1;
  then
A15:primesFinS n.(I+1) = p by NUMBER10:def 4;
  reconsider Ik=I+1-k as Element of NAT by A14,NAT_1:21;
A16:1+Ik+k-'1 = I+1+1 -' 1
  .= I+1;
  Ik <= m-k by A14,XREAL_1:9;
  then
A17:1 <= Ik+1 <= len M by A5,A4,XREAL_1:6,NAT_1:11;
  then
A18:M.(1+Ik) = primesFinS n.(1+I) by A16,A1,A2,A3,FINSEQ_6:118;
  Ik+1 in dom M by A17,FINSEQ_3:25;
  then M.(1+Ik) in rng M by FUNCT_1:def 3;
  hence thesis by A15,A18,NAT_3:7;
end;

theorem
  for k,m,n,a,b st 1 <= k <= m < n <= a <= b holds
          Product mid(primesFinS b,k,m),
          Product mid(primesFinS b,n,a) are_coprime
proof
  let k,m,n,o,p be Nat such that
A1:1 <= k <= m < n <= o <= p;
  set P=primesFinS p,M1 = mid(P,k,m),M2 = mid(P,n,o);
  assume not Product M1,Product M2 are_coprime;
  then Product M1 gcd Product M2 is non trivial by NAT_2:def 1;
  then consider q be prime Nat such that
A2:q divides Product M1 gcd Product M2 by NEWTON03:29;
  n <=p by A1,XXREAL_0:2;
  then
A3:m <=p by A1,XXREAL_0:2;
  Product M1 gcd Product M2 divides Product M1 by INT_2:def 2;
  then q divides Product M1 by A2,INT_2:9;
  then 1 + primeindex q <= m by A1,A3,Th3;
  then
A4:1 + primeindex q < n by A1,XXREAL_0:2;
  1 <=m by A1,XXREAL_0:2;
  then
A5:1 <=n by A1,XXREAL_0:2;
  Product M1 gcd Product M2 divides Product M2 by INT_2:def 2;
  then q divides Product M2 by A2,INT_2:9;
  hence thesis by A4,A1,A5,Th3;
end;

theorem Th5:
  for u being integer-valued FinSequence
  for m being CR_Sequence
  for z being Integer st z solves_CRT u,m
  for i st i in dom u & u.i,m.i are_coprime
     holds z,m.i are_coprime by NUMBER14:def 3,WSIERP_1:43;

theorem
  for u being integer-valued FinSequence
  for m being CR_Sequence st dom u = dom m
  for z being Nat st z solves_CRT u,m &
    for i st i in dom u holds u.i,m.i are_coprime
  holds z,Product m are_coprime
proof
  let u be integer-valued FinSequence;
  let m be CR_Sequence such that
A1:dom u = dom m;
  let z be Nat such that
A2: z solves_CRT u,m and
A3:for i st i in dom u holds u.i,m.i are_coprime;
  rng m c= NAT
  proof
    let y be object;
    assume y in rng m;
    then consider x be object such that
A4: x in dom m & m.x=y by FUNCT_1:def 3;
    reconsider x as Nat by A4;
    m.x in NAT;
    hence thesis by A4;
  end;
  then
A5:m is FinSequence of NAT by FINSEQ_1:def 4;
  for i being Nat st i in dom m holds m.i gcd z =1
  proof
    let i be Nat such that
A6: i in dom m;
    u.i,m.i are_coprime by A1,A3,A6;
    then z,m.i are_coprime by A1,A2,A6,Th5;
    hence thesis;
  end;
  hence thesis by A5,WSIERP_1:36;
end;

registration
  let f be one-to-one FinSequence;
  let n,m be Nat;
  cluster mid(f,n,m) -> one-to-one;
  coherence
  proof
    reconsider F=f as FinSequence of the non empty set\/rng f
      by XBOOLE_1:7,FINSEQ_1:def 4;
A1: (F /^ (n-'1)) | (m-'n+1) is one-to-one;
    Rev ((F/^(m-'1)) | (n-'m+1)) is one-to-one;
    hence thesis by A1,FINSEQ_6:def 3;
  end;
end;

theorem Th7:
  for k,m,n st 1 <= k <= m <= n
     holds PrimeDivisors Product mid(primesFinS n,k,m) =
       rng mid(primesFinS n,k,m)
proof
  let k,m,n such that
A1:1 <= k <= m <= n;
  set P = primesFinS n,M=mid(primesFinS n,k,m);
A2: PrimeDivisors Product M c= rng M
  proof
    let x be object such that
A3: x in PrimeDivisors Product M;
    x in {k where k is Prime : k divides Product M } by A3,NUMBER12:def 3;
    then consider p be Prime such that
A4: x = p & p divides Product M;
A5: k <= 1 + primeindex p <= m by A1,A4,Th3;
    set I = primeindex p;
A6: len primesFinS n = n by NUMBER13:def 1;
A7: 1 <= m & k <= n by A1,XXREAL_0:2;
    set M=mid(primesFinS n,k,m);
A8: m-'k = m-k by A1,XREAL_1:233;
A9: len M = m-'k+1 by A1,A6,A7,FINSEQ_6:118;
    1+I <= n by A5,A1,XXREAL_0:2;
    then I < n by NAT_1:13;
    then primesFinS n.(I+1) = primenumber I by NUMBER13:def 1;
    then
A10:primesFinS n.(I+1) = p by NUMBER10:def 4;
    reconsider Ik=I+1-k as Element of NAT by A5,NAT_1:21;
A11:1+Ik+k-'1 = I+1+1 -' 1 .= I+1;
    Ik <= m-k by A5,XREAL_1:9;
    then
A12:1 <= Ik+1 <= len M by A9,A8,XREAL_1:7,NAT_1:11;
A13:M.(1+Ik) = p  by A10,A12,A11,A1,A6,A7,FINSEQ_6:118;
    Ik+1 in dom M by A12,FINSEQ_3:25;
    hence thesis by A4,A13,FUNCT_1:def 3;
  end;
  rng M c= PrimeDivisors Product M
  proof
    let y be object such that
A14: y in rng M;
    rng M c= rng P by FINSEQ_6:119;
    then consider i be object such that
A15: i in dom P & P.i=y by A14,FUNCT_1:def 3;
    reconsider i as Nat by A15;
    1 <= i by A15,FINSEQ_3:25;
    then reconsider i1=i-1 as Nat;
    i1+1 <= len P by A15,FINSEQ_3:25;
    then i1 < len P= n by NAT_1:13,NUMBER13:def 1;
    then
A16: P.(i1+1) = primenumber i1 by NUMBER13:def 1;
A17: P.i divides Product M by A14,A15,NAT_3:7;
    P.i in { k where k is Prime : k divides Product M } by A16,A17;
    hence thesis by A15,NUMBER12:def 3;
  end;
  hence thesis by A2,XBOOLE_0:def 10;
end;

theorem
  for k,m,n st 1 <= k <= m <= n
     holds card PrimeDivisors Product mid(primesFinS n,k,m) = m-k+1
proof
  let k,m,n such that
A1: 1 <= k <= m <= n;
  set M=mid(primesFinS n,k,m);
A2: len primesFinS n = n by NUMBER13:def 1;
  1 <= m & k <= n by A1,XXREAL_0:2;
  then len M = m-'k+1 by A1,A2,FINSEQ_6:118;
  then
A3:dom M = Seg (m-'k+1) by FINSEQ_1:def 3;
A4:card rng M = card dom M by CARD_1:70;
  PrimeDivisors Product M = rng M by A1,Th7;
  hence thesis by A3,A4,A1,XREAL_1:233;
end;

theorem
  k divides n implies PrimeDivisors k c= PrimeDivisors n
proof
  assume
A1: k divides n;
  let x be object;
  assume x in PrimeDivisors k;
  then x in { p where p is Prime : p divides k } by NUMBER12:def 3;
  then consider p be Prime such that
A2:x = p & p divides k;
  p divides n by A1,A2,INT_2:9;
  then p in { p where p is Prime : p divides n };
  hence thesis by A2,NUMBER12:def 3;
end;

theorem Th10:
  n < primenumber n
proof
  defpred P[Nat] means $1 < primenumber $1;
A1:P[0];
A2:for n being Nat holds P[n] implies P[n+1]
  proof
    let n be Nat;
    assume P[n];
    then
A3: n+1 <= primenumber n by NAT_1:13;
    n < n+1 by NAT_1:13;
    then primenumber n < primenumber (n+1) by MOEBIUS2:21;
    hence thesis by A3,XXREAL_0:2;
  end;
  for n being Nat holds P[n] from NAT_1:sch 2(A1,A2);
  hence thesis;
end;

theorem
  primeindex p < p
proof
  primeindex p < primenumber primeindex p by Th10;
  hence thesis by NUMBER10:def 4;
end;

theorem Th12:
  value(n-->0,b) = 0
proof
  consider d be XFinSequence of NAT such that
A1:dom d = dom (n-->0) and
A2:for i being Nat st i in dom d holds d.i = ((n-->0).i)*(b|^i) and
A3:value(n-->0,b) = Sum d by NUMERAL1:def 1;
  for k being Nat st k in dom d holds d.k = (n-->0).k
  proof
    let i be Nat such that
A4: i in dom d;
    d.i = ((n-->0).i)*(b|^i) by A2,A4;
    hence thesis;
  end;
  then d = n-->0 by A1,AFINSQ_1:8;
  then Sum d = n*0 by AFINSQ_2:58;
  hence thesis by A3;
end;

theorem Th13:
   b > 1 & k > 0 & n > 0 implies
      value(<%1%> ^ ( n-'1 --> 0) ^ digits(k,b),b) =  k*b|^n +1
proof
  assume that
A1: b > 1 & k > 0 & n > 0;
A2: len <%1%> = 1 by AFINSQ_1:34;
  n >= 1+0 by A1,NAT_1:13;
  then len ( n-'1 --> 0) = n-'1 = n-1 by XREAL_1:233;
  then
A3: len (<%1%> ^ ( n-'1 --> 0)) = 1 + (n-1) by A2,AFINSQ_1:17;
  value(<%1%> ^ ( n-'1 --> 0),b)
    = value(<%1%>,b)+ value( n-'1 --> 0,b) *b|^1 by A2,NUMBER16:1
   .= value(<%1%>,b)+ 0 *b|^1 by Th12
   .= 1 by NUMBER11:2;
  hence value(<%1%> ^ ( n-'1 --> 0) ^ digits(k,b),b)
    = 1 + value(digits(k,b),b) * b|^n by A3,NUMBER16:1
   .= k*b|^n +1 by A1,NUMERAL1:5;
end;

theorem
  b > 1 & k > 0 & n > 0 implies
     digits(k*b|^n +1,b) =<%1%> ^( n-'1 --> 0) ^ digits(k,b)
proof
  assume
A1: b > 1 & k > 0 & n > 0;
  set N=<%1%> ^( n-'1 --> 0),D=digits(k,b),ND=N^D;
A2: len <%1%> = 1 by AFINSQ_1:34;
  n >= 1+0 by A1,NAT_1:13;
  then len ( n-'1 --> 0) = n-'1 = n-1 by XREAL_1:233;
  then
A3: len N = 1 + (n-1) by A2,AFINSQ_1:17;
  then
A4: len ND = n+len D by AFINSQ_1:17;
  1 <= len D by A1,NUMERAL1:4;
  then len N +1 <= len ND by A3,A4,XREAL_1:6;
  then
A5: len N  <= len ND -1 by XREAL_1:19;
  len ND-1 < len ND-0 by XREAL_1:15;
  then ND.(len ND-1)
    = D.(len ND-1-n) by A3,A5,AFINSQ_1:19
   .= D.(len D-1) by A4;
  then
A6: ND.(len ND-1) <> 0 by A1,NUMERAL1:def 2;
  for i being Nat st i in dom ND holds ND.i<b
  proof
    let i be Nat;
    assume i in dom ND;
    then per cases by A3,AFINSQ_1:20;
    suppose
A7:   i in dom N;
      per cases by A7,AFINSQ_1:20;
      suppose
A8:     i in dom <%1%>;
        then
A9:     N.i = <%1%>.i by AFINSQ_1:def 3;
        i in Segm 1 by A8,AFINSQ_1:33;
        then i = 0 by NAT_1:14,44;
        hence thesis by A1,A7,AFINSQ_1:def 3,A9;
      end;
      suppose ex m being Nat st m in dom (n-'1-->0) & i= len <%1%> + m;
        then consider m be Nat such that
A10:    m in dom (n-'1-->0) & i= len <%1%> + m;
        0 =(n-'1-->0).m
        .=N.i by A10,AFINSQ_1:def 3;
        hence thesis by A1,A7,AFINSQ_1:def 3;
      end;
    end;
    suppose ex m being Nat st m in dom D & i= n + m;
      then consider m be Nat such that
A11:  m in dom D & i= n + m;
      D.m < b by A11,A1,NUMERAL1:def 2;
      hence thesis by A11,A3,AFINSQ_1:def 3;
    end;
  end;
  then digits(value(ND,b),b) = ND by A1,A6,NUMBER11:5;
  hence thesis by A1,Th13;
end;

theorem
  for f,g being XFinSequence, X being set holds
    card ((f^g)"X) = card (f"X) + card (g"X)
proof
  let f,g be XFinSequence, X be set;
  (((f^g)"X)/\len f) \/ (((f^g)"X) \ len f) = ((f^g)"X);
  then
A1: card ((f^g)"X) = card (((f^g)"X)/\len f) +card (((f^g)"X) \ len f)
     by XBOOLE_1:89,CARD_2:40;
  defpred P[object,object] means
    $1 is Nat & for n being Nat st $1=n holds $2=n+len f;
A2:for x being object st x in g"X
    ex y being object st y in ((f^g)"X) \ len f & P[x,y]
  proof
    let x be object such that
A3: x in g"X;
A4: x in dom g & g.x in X by A3,FUNCT_1:def 7;
    then reconsider x as Nat;
    take y = x + len f;
    y in dom (f^g) & (f^g).y = g.x  by A4, AFINSQ_1:23,def 3;
    then
A5: y in (f^g)"X by A4,FUNCT_1:def 7;
    not y in Segm len f & Segm len f=len f by NAT_1:11,44,ORDINAL1:def 17;
    hence thesis by A5,XBOOLE_0:def 5;
  end;
  consider F be Function such that
A6: dom F = g"X & rng F c= ((f^g)"X) \ len f and
A7: for x being object st x in g"X holds P[x,F.x] from FUNCT_1:sch 6(A2);
  ((f^g)"X) \ len f c= rng F
  proof
    let x be object such that
A8: x in ((f^g)"X) \ len f;
A9: x in ((f^g)"X) & not x in len f by A8,XBOOLE_0:def 5;
A10:x in dom (f^g) & (f^g).x in X by FUNCT_1:def 7,A8;
    then reconsider x as Nat;
A11: not x in Segm len f by A9,ORDINAL1:def 17;
    then
A12: x >= len f by NAT_1:44;
A13: x< len (f^g) by A10,AFINSQ_1:66;
A14: (f^g).x = g.(x-len f) by A12,A10,AFINSQ_1:66,AFINSQ_1:19;
A15: x < len f +len g by A13,AFINSQ_1:17;
    then len f-len f <= x - len f < len g by A11,NAT_1:44,XREAL_1:9,19;
    then reconsider xL=x-len f as Element of NAT by INT_1:3;
    xL in dom g by A15,XREAL_1:19,AFINSQ_1:66;
    then
A16: xL in g"X by A10,A14,FUNCT_1:def 7;
    then F.xL = xL+len f = x by A7;
    hence thesis by A16,A6,FUNCT_1:def 3;
  end;
  then
A17: ((f^g)"X) \ len f = rng F by A6,XBOOLE_0:def 10;
  for x1,x2 be object st x1 in dom F & x2 in dom F & F.x1=F.x2 holds x1=x2
  proof
    let x1,x2 be object such that
A18: x1 in dom F & x2 in dom F & F.x1=F.x2;
    x1 in dom g & x2 in dom g by A18,A6,FUNCT_1:def 7;
    then reconsider x1,x2 as Nat;
    F.x1 = x1+len f & F.x2 = x2+len f by A6,A7,A18;
    then x1+len f= x2+len f by A18;
    hence thesis;
  end;
  then
A19: card (g"X) = card (((f^g)"X) \ len f)
    by A6,A17,CARD_1:70,FUNCT_1:def 4;
A20: ((f^g)"X)/\len f c= f"X
  proof
    let x be object;
    assume
A21: x in ((f^g)"X)/\len f;
    then (f^g).x in X & (f^g).x = f.x by AFINSQ_1:def 3,FUNCT_1:def 7;
    hence thesis by A21,FUNCT_1:def 7;
  end;
  f"X c= ((f^g)"X)/\len f
  proof
    let x be object;
    assume x in f"X;
    then
A22: x in dom f c= dom (f^g) & f.x in X by AFINSQ_1:21,FUNCT_1:def 7;
    then (f^g).x = f.x & x in dom (f^g) by AFINSQ_1:def 3;
    then x in (f^g)"X by A22,FUNCT_1:def 7;
    hence thesis by XBOOLE_0:def 4,A22;
  end;
  hence thesis by A1,A19,A20,XBOOLE_0:def 10;
end;

theorem Th16:
  b > 1 & k > 0 implies
    value( (n-->(b-'1)) ^ digits(k-'1,b),b) = k*b|^n -1
proof
  assume that
A1:b > 1 & k > 0;
  0+1 <= k by A1,NAT_1:13;
  then
A2: k-'1+1 = k-1+1 by XREAL_1:233;
  len (n-->(b-'1)) = n;
  hence value( (n-->(b-'1)) ^ digits(k-'1,b),b)
    = value( n-->(b-'1),b) + value(digits(k-'1,b),b) *b |^ n by NUMBER16:1
   .= (b|^n -1) +  value(digits(k-'1,b),b) *b |^ n by A1, NUMBER11:7
   .= (b|^n -1) +(k-'1)  *b |^ n by A1,NUMERAL1:5
   .= k * b|^n -1 by A2;
end;

theorem
  b > 1 & k > 0 & n > 0 implies
     Sum digits(k*b|^n -'1,b) >= n*(b-1)
proof
  assume
A1: b > 1 & k > 0 & n > 0;
  set D = digits(k-'1,b);
  set V=  (n-->(b-'1)) ^ D;
  k*b|^n >= 1+0 by A1,NAT_1:13;
  then
A2: value( V,b) = k*b|^n -1 = k*b|^n -'1 by A1,Th16,XREAL_1:233;
A3: k>=1+0 by A1,NAT_1:13;
  then
A4: k-'1 = k-1 by XREAL_1:233;
A5:n >= 1+0 by A1,NAT_1:13;
  then b|^n >= b by A1,PREPOWER:12;
  then
A6:b|^n > 1 & 0+1 <= k by A1,NAT_1:13,XXREAL_0:2;
  then
A7:k*b|^n >= 1*b|^n by XREAL_1:64;
A8:k*b|^n -1 = k*b|^n -'1 by A7,A6,XXREAL_0:2,XREAL_1:233;
A9:b-'1 =b-1 by A1,XREAL_1:233;
  then b-'1+1 = b;
  then
A10:b-'1 < b by NAT_1:13;
A11:len (n-->(b-'1)) = n;
  per cases by A3,XXREAL_0:1;
  suppose k=1;
    then
A12: digits(k*b|^n -'1,b) = digits(value(n-->(b-'1),b),b)
    by A8,A1,NUMBER11:7;
    set N=n-->(b-'1);
A13: for i being Nat st i in dom N holds N.i<b by A10,FUNCOP_1:7;
A14: n-1 = n-'1 by A5,XREAL_1:233;
    then n-'1 < n-'1+1=n by NAT_1:13;
    then n-'1 in Segm n = n by NAT_1:44,ORDINAL1:def 17;
    then N.((len N)-1)= b-'1 by A14,FUNCOP_1:7;
    then len N > 0 & N.((len N)-1) <> 0 &
      for i being Nat st i in dom N holds N.i<b by A13,A1,A9;
    then digits(value(n-->(b-'1),b),b) = n-->(b-'1) by NUMBER11:5,A1;
    hence thesis by A9,A12,AFINSQ_2:58;
  end;
  suppose
A15: k > 1;
A16: k-'1 <>0 by A4,A15;
A17:len D >= 1 by A1,NUMERAL1:4;
A18:len V = len  (n-->(b-'1)) + len D by AFINSQ_1:17;
    len V  >= len  (n-->(b-'1))+1 by A18,A17,XREAL_1:6;
    then
A19:len V-1  >= len  (n-->(b-'1))+1-1 by XREAL_1:9;
    len V - 0 > len V - 1 by XREAL_1:10;
    then V.(len V-1) = D.(len V-1 - n) by AFINSQ_1:18,A18,A19;
    then
A20: V.(len V-1) = D.(len D-1)<>0 by A18,A16,A1,NUMERAL1:def 2;
A21:for i being Nat st i in dom V holds V.i<b
    proof
      let i be Nat;
      assume i in dom V;
      then per cases by AFINSQ_1:20;
      suppose
A22:    i in dom (n-->(b-'1));
        then V.i = (n-->(b-'1)).i by AFINSQ_1:def 3;
        hence thesis by A10,A22,FUNCOP_1:7;
      end;
      suppose ex m being Nat st m in dom D & i= n + m;
        then consider m be Nat such that
A23:    m in dom D & i= n + m;
        D.m < b by A16,A23,A1,NUMERAL1:def 2;
        hence thesis by A23,A11,AFINSQ_1:def 3;
      end;
    end;
    Sum (n-->(b-'1)) = n * (b-'1) by AFINSQ_2:58;
    then Sum V = Sum (n-->(b-'1)) +Sum  D >= n * (b-'1) +0
      by XREAL_1:6,AFINSQ_2:55;
    hence thesis by A21,A9,A2,A20,A1,NUMBER11:5;
  end;
end;

begin :: Problem 108

:: For each odd number n > 1, the numbers n and n + 2 are prime
:: if and only if (n - 1)! is not divisible by n or n + 2.

theorem Th18:
  for n being odd natural number st n > 1 holds
    n is prime iff not n divides (n-'1)!
proof
  let n be odd natural number such that
A1:n > 1;
A2:n-'1+1 = n-1+1;
  thus n is prime implies not n divides (n-'1)!
  proof
    assume
A3: n is prime;
    n-'1+1=n-1+1;
    then n-'1 < n by NAT_1:13;
    hence thesis by A3,NAT_4:19;
  end;
  assume
A4: not n divides (n-'1)!;
  consider k be Nat such that
A5:n=2*k+1 by ABIAN:9;
  k <>0 by A1,A5;
  then k = 1 or k >= 2 by NAT_1:23;
  then per cases by XXREAL_0:1;
  suppose k = 1 or k = 2;
    hence thesis by A5,XPRIMES1:3,5;
  end;
  suppose k > 2;
    then k >= 2+1 by NAT_1:13;
    then k*2>=3*2 by XREAL_1:64;
    then
A6: n >= 6+1 by A5,XREAL_1:6;
    assume not n is prime;
    then consider a be Nat such that
A7: a divides n & a <> 1 & a <> n by A6,XXREAL_0:2;
    consider b be Nat such that
A8: n = a *b by A7,NAT_D:def 3;
A9: a<>0 & b <>0 by A8;
    then
A10:a <= n & b <= n by A8,NAT_1:24;
    b<>n
    proof
      assume b=n;
      then n*1=n*a by A8;
      hence thesis by A7, XCMPLX_1:5;
    end;
    then
A11:a < n & b < n by A10,A7,XXREAL_0:1;
    per cases;
    suppose a <>b;
      then
A12:  a < b or b<a by XXREAL_0:1;
      a <= n-'1 & b <= n-'1 by A11,A2,NAT_1:13;
      hence thesis by A4,A8,A12,A9,NUMBER16:37;
    end;
    suppose
A13:  a=b;
      a > 2
      proof
        assume a <= 2;
        then n <= 2*2 by A13,A8,XREAL_1:66;
        hence thesis by A6,XXREAL_0:2;
      end;
      then a*a > 2*a by XREAL_1:68;
      then
A14:  2*a <= n-'1 by A13,A8,A2,NAT_1:13;
      1*a < 2*a by XREAL_1:68,A9;
      then
A15:  a*(2*a) divides (n-'1)! by A14,A9,NUMBER16:37;
      a*a divides a*a*2;
      hence thesis by A4,A13,A8,A15,INT_2:9;
    end;
  end;
end;

theorem Th19:
  for n being odd natural number st n > 1 holds
    n+2 is prime
  iff
    not n+2 divides (n-'1)!
proof
  let n be odd natural number such that
A1:n > 1;
A2:n-'1 = n-1 by A1,XREAL_1:233;
  thus n+2 is prime implies not n+2 divides (n-'1)!
  proof
    assume
A3: n+2 is prime;
A4: n-'1+1=n-1+1;
    n<= n+2 by NAT_1:11;
    hence thesis by A3,A4,NAT_1:13,NAT_4:19;
  end;
  assume
A5: not n+2 divides (n-'1)!;
  consider k be Nat such that
A6:n=2*k+1 by ABIAN:9;
  k <>0 by A1,A6;
  then k = 1 or k >= 2 by NAT_1:23;
  then per cases by XXREAL_0:1;
  suppose k = 1 or k = 2;
    hence thesis by A6,XPRIMES1:5,7;
  end;
  suppose k > 2;
    then k >= 2+1 by NAT_1:13;
    then k*2>=3*2 by XREAL_1:64;
    then
A7: n >= 6+1 by A6,XREAL_1:6;
    then
A8: n > 1 & n +2 >= 7+2 by XREAL_1:6,XXREAL_0:2;
    assume not n+2 is prime;
    then consider a be Nat such that
A9: a divides n+2 & a <> 1 & a <> n+2 by A8,XXREAL_0:2;
    consider b be Nat such that
A10:n+2 = a *b by A9,NAT_D:def 3;
A11:a<>0 & b <>0 by A10;
A12:b <> 1 by A10,A9;
    1 <= a & 1 <= b by A11,NAT_1:14;
    then 1 < a & 1 < b & 2 is even by A12,A9,XXREAL_0:1;
    then 1+1 <= a & 1+1 <= b & a <> 2 & b <> 2 by A10,NAT_1:13;
    then 2 < a & 2 < b by XXREAL_0:1;
    then 2+1 <= a & 2+1 <= b by NAT_1:13;
    then 3*b <= n+2 & 3*a <= n+2 by A10,XREAL_1:64;
    then
A13: a <= (n+2)/3 & b <= (n+2)/3 by XREAL_1:77;
    7 + (2*n-3) <= n + (2*n-3) by A7,XREAL_1:6;
    then (n+2)*2 <= (n-1)*3;
    then (n+2)/3 <= (n-1)/2 by XREAL_1:102;
    then a <= (n-1)/2 & b <= (n-1)/2 by A13,XXREAL_0:2;
    then
A14: 2*a <= n-1 & 2*b <= n-1 by XREAL_1:83;
    per cases by XXREAL_0:1;
    suppose 2*a < 2*b or 2*b < 2*a;
      then
A15:  (2*a)*(2*b) divides (n-'1)! by A2,A11,A14,NUMBER16:37;
      a*b divides a*b*4;
      hence thesis by A10,A5,A15,INT_2:9;
    end;
    suppose 2*a = 2*b;
      then 1*a < 2*b by A11,XREAL_1:68;
      then
A16:  a*(2*b) divides (n-'1)! by A2,A11,A14,NUMBER16:37;
      a*b divides a*b*2;
      hence thesis by A10,A5,A16,INT_2:9;
    end;
  end;
end;

:: Problem 108
theorem
  for n being odd natural number st n > 1 holds
    n is prime & n+2 is prime
  iff
    not n divides (n-'1)! & not n+2 divides (n-'1)! by Th18,Th19;

begin :: Problem 112

:: For each integer s between 2 and 10 inclusive, find all prime numbers
:: p such that the sum of all positive integer divisors of p is equal to
:: the s^(th) power of an integer.

theorem Th21:
  Sum canFS NatDivisors p = n|^s & 2 <= s implies n = 2
proof
  assume
A1:Sum canFS NatDivisors p = n|^s & s >= 2;
A2:p <>1 by INT_2:def 4;
  NatDivisors p = {1, p} by LATSTONE:26;
  then canFS NatDivisors p = <*1,p*> or canFS NatDivisors p = <*p,1*>
    by A2,POLYVIE1:1;
  then
A3:Sum canFS NatDivisors p = 1+p by RVSUM_1:77;
A4:s > 1 by A1,XXREAL_0:2;
  n <>0 by A1,XXREAL_0:2,A3,NEWTON:11;
  then
A5:n>=1 & n-1= n-'1 by NAT_1:14,XREAL_1:233;
  p = n|^s - 1 by A3,A1;
  then consider m be Nat such that
A6: p = (n-'1)*m by NAT_D:def 3,A5,NUMBER01:11;
  m divides p by A6;
  then per cases by INT_2:def 4;
  suppose m = 1;
    then n|^1  = n|^s by A3,A6,A5,A1;
    then n <= 1 by A4,PEPIN:30;
    then n = 1 by A5,XXREAL_0:1;
    then n-'1 = 0 by A5;
    hence thesis by A6;
  end;
  suppose m = p;
    then n-'1 = 1 by A6,XCMPLX_1:7;
    hence thesis by A5;
  end;
end;

::Problem 112
theorem
  for p being Prime, n, s being Nat st
    Sum canFS NatDivisors p = n|^s & 2 <= s <= 10 holds
    (s = 2 & p = 3) or (s = 3 & p = 7) or
    (s = 5 & p = 31) or
    (s = 7 & p = 127)
proof
  let p be Prime, n,s be Nat such that
A1:Sum canFS NatDivisors p = n|^s & 2 <= s <= 10;
A2:n=2 by Th21,A1;
A3:p <>1 by INT_2:def 4;
  NatDivisors p = {1, p} by LATSTONE:26;
  then canFS NatDivisors p = <*1,p*> or canFS NatDivisors p = <*p,1*>
  by A3,POLYVIE1:1;
  then
A4:Sum canFS NatDivisors p = 1+p by RVSUM_1:77;
A5:n|^(1+1) = 2|^1*2 by A2,NEWTON:6;
  then
A6:n|^(2+1) = 4*2 by A2,NEWTON:6;
  then
A7:n|^(3+1) = 8*2 by A2,NEWTON:6;
  then
A8:n|^(4+1) = 16*2 by A2,NEWTON:6;
  then
A9:n|^(5+1) = 32*2 by A2,NEWTON:6;
  then
A10:n|^(6+1) = 64*2 by A2,NEWTON:6;
  then
A11:n|^(7+1) = 128*2 by A2,NEWTON:6;
  then
A12:n|^(8+1) = 256*2 by A2,NEWTON:6;
  then
A13:n|^(9+1) = 512*2 by A2,NEWTON:6;
  s = 0 or...or s=10 by A1;
  then per cases by A1;
  suppose
A14:s=2;
    then n|^s = 4 by A5;
    hence thesis by A14,A4,A1;
  end;
  suppose
A15: s=3;
    then n|^s = 8 by A6;
    hence thesis by A15,A4,A1;
  end;
  suppose s=4;
    then n|^s = 16 by A7;
    hence thesis by A4,A1,XPRIMES0:15;
  end;
  suppose
A16: s=5;
    then n|^s = 32 by A8;
    hence thesis by A4,A1,A16;
  end;
  suppose s=6;
    then n|^s = 64 by A9;
    hence thesis by A4,A1,XPRIMES0:63;
  end;
  suppose
A17: s=7;
    then n|^s = 128 by A10;
    hence thesis by A4,A1,A17;
  end;
  suppose s=8;
    then n|^s = 256 by A11;
    hence thesis by A4,A1,XPRIMES0:255;
  end;
  suppose s=9;
    then n|^s = 512 by A12;
    hence thesis by A4,A1,XPRIMES0:511;
  end;
  suppose s=10;
    then n|^s =1024 by A13;
    hence thesis by A4,A1,XPRIMES0:1023;
  end;
end;

begin :: Problem 113

:: Prove that no prime greater than 5 and positive integer m exists such
:: that (p-1)!+1 = p^m.

theorem Th23:
  p > 5 implies (p-'1)!+1 <>p|^m
proof
  assume that
A1:p > 5 and
A2:(p-'1)!+1 = p|^m;
A3:p > 2 by A1,XXREAL_0:2;
  then consider k be Nat such that
A4:p = 2*k+1 by ABIAN:9,PEPIN:17;
A5:p> 1 by A1,XXREAL_0:2;
A6:p-'2 = p-2 & p-'1 = p-1 by A1,XXREAL_0:2,XREAL_1:233;
  2*k = p-1 > 5-1=2*2 by A1,A4,XREAL_1:9;
  then
A7: k > 2 by XREAL_1:64;
A8:p|^m - 1 = p|^m -' 1 by NAT_1:14,XREAL_1:233;
A9:(p-'1)*(p-'1) divides (p-'1)!
  proof
A10:(p-'2)!*(p-'2+1) = (p-'2+1)! by NEWTON:15;
    1* k < p - 1 by A4,XREAL_1:68;
    then k+1 <= p-1 by INT_1:7;
    then k <= p-1-1 by XREAL_1:19;
    then 2*k divides (p-'2)! by A7,A6,NUMBER16:37;
    hence thesis by A4,A6,A10,INT_4:7;
  end;
A11:m > 0
  proof
    assume m<=0;
    then m =0;
    then (p-'1)!+1 = 1 by A2,NEWTON:4;
    then (p-'1) ! = 0;
    hence thesis;
  end;
  then
A12:m-'1=m-1 by NAT_1:14,XREAL_1:233;
  consider t be Nat such that
A13: p|^m -' 1 = (p-'1) * t by A6,A8,NUMBER01:11,NAT_D:def 3;
A14: (p-'1) divides t by INT_4:7,A9,A13,A2;
A15:p-'1 divides m
  proof
    deffunc P(Nat) = p|^($1+1)-1;
    consider P be XFinSequence such that
A16: len P = m-'1 & for n be Nat st n in m-'1 holds P.n=P(n)
    from AFINSQ_1:sch 2;
    rng P c= INT
    proof
      let y be object;
      assume y in rng P;
      then consider x be object such that
A17:  x in dom P & y=P.x by FUNCT_1:def 3;
      reconsider x as Nat by A17;
      y = P(x) in INT by A16,A17,INT_1:def 1;
      hence thesis;
    end;
    then reconsider P as XFinSequence of INT by RELAT_1:def 19;
A18:for n being Nat st n in dom P holds p-'1 divides P.n
    proof
      let n be Nat such that
A19:  n in dom P;
      p-'1 divides P(n) by A6,NUMBER01:11;
      hence thesis by A19,A16;
    end;
    t = (p|^m -' 1) div (p-'1) by A13
    .= Sum P + m by A12,A11,A16,A5,A6,A8,NUMBER01:12;
    hence thesis by A14,A18,NUMERAL2:16,INT_2:1;
  end;
  p|^m > (p-'1)!+1
  proof
    p-'1 <=m by A15,A11,INT_2:27;
    then
A20:p to_power m >= p to_power (p-'1) by A5,PRE_FF:8;
A21:p-1 > 2-1 by A3,XREAL_1:14;
    p-'1<p-'1+1=p by A6,NAT_1:13;
    then p|^(p-'1) > (p-'1) |^(p-'1) by A21,PREPOWER:10;
    then
A22:p|^m > (p-'1) |^(p-'1) by A20,XXREAL_0:2;
    p-'1 >=1+1 by A21,A6,NAT_1:13;
    then
    (p-'1) |^(p-'1) > (p-'1)! by NEWTON02:122;
    then (p-'1) |^(p-'1) >= (p-'1)!+1 by NAT_1:13;
    hence thesis by A22,XXREAL_0:2;
  end;
  hence thesis by A2;
end;

begin :: Problem 114

:: Prove that there are infinitely many prime numbers q for which there
:: is a positive integer n < q such that q divides (n-1)!+1.

theorem Th24:
  p > 5 implies
    ex q being Prime st p < q & q divides (p-'1)!+1
proof
  assume
A1:p > 5;
  consider k,m be Nat such that
A2: (p-'1)!+1 = m * p|^k & not p divides m by FIELD_15:4;
  m >= 1+1
  proof
A3: m<>0 by A2;
    assume m < 1+1;
    then 1<= m <= 1 by A3,NAT_1:13,14;
    then m = 1 by XXREAL_0:1;
    hence thesis by Th23,A1,A2;
  end;
  then consider q be Element of NAT such that
A4: q is prime & q divides m by INT_2:31;
A5: m divides (p-'1)!+1 by A2;
  then
A6:q divides (p-'1)!+1 by A4,INT_2:9;
  q > p-'1
  proof
    assume q <= p-'1;
    then q divides 1 by A6,INT_2:1,A4,NEWTON:41;
    hence thesis by A4,INT_2:13;
  end;
  then q >= p-'1+1=p-1+1 by NAT_1:13;
  then q > p by A2,A4,XXREAL_0:1;
  hence thesis by A5,A4,INT_2:9;
end;

theorem Th25:
 for n,k being Nat holds
    0 < n < k implies n!< k!
proof
  let n,k be Nat;
  assume
A1:0 < n < k;
  then n+1<=k by NAT_1:13;
  then A2:(n+1)! <= k! by SIN_COS:39;
  n+1 > 0+1 by A1,XREAL_1:6;
  then (n+1)! = n! * (n+1) > n! * 1 by NEWTON:15,XREAL_1:68;
  hence thesis by A2,XXREAL_0:2;
end;

theorem Th26:
  {q where q is Prime: ex p being Prime st p < q divides (p-'1)!+1}
    is infinite
proof
  deffunc G(object,Nat) = In(primenumber (($2)!),NAT);
  consider f be sequence of NAT such that
A1:   f.0 = 7 & for k being Nat holds f.(k+1) = G(k,f.k) from NAT_1:sch 12;
  defpred P[Nat] means f.$1 is Prime & 5 < f.$1;
A2:P[0] by A1,NAT_4:26;
A3:for n being Nat st P[n] holds P[n+1]
  proof
    let n be Nat such that
A4: P[n];
A5: f.(n+1) = In(primenumber ((f.n)!),NAT) by A1
    .= primenumber ((f.n)!);
    f.n <= (f.n)! <= primenumber ((f.n)!) by PRIMRECI:11,NEWTON:38;
    then f.n <= f.(n+1) by A5,XXREAL_0:2;
    hence thesis by A4,A5,XXREAL_0:2;
  end;
A6:for n being Nat holds P[n] from NAT_1:sch 2(A2,A3);
A7:for i,j being Nat st i <=j holds f.i <= f.j
  proof
    let i be Nat;
    defpred I[Nat] means f.i <= f.(i+$1);
A8: I[0];
A9: for j being Nat st I[j] holds I[j+1]
    proof
      let j be Nat such that
A10:  I[j];
      f.(i+j+1) = In(primenumber ((f.(i+j))!),NAT) by A1
      .= primenumber ((f.(i+j))!);
      then f.(i+j) <= (f.(i+j))! <= f.(i+j+1)
        by PRIMRECI:11,NEWTON:38;
      then  f.(i+j) <= f.(i+j+1) by XXREAL_0:2;
      hence thesis by A10,XXREAL_0:2;
    end;
A11: for j being Nat holds I[j] from NAT_1:sch 2(A8,A9);
    let j be Nat;
    assume i <=j;
    then reconsider ji=j-i as Nat by NAT_1:21;
    I[ji] by A11;
    hence thesis;
  end;
  defpred F[object,object] means
    $2 is Prime & for i,j be Nat st $1=i & $2=j holds
    j is prime & f.i < j divides (f.i-'1)!+1;
A12: for x being object st x in NAT ex y being object st y in NAT & F[x,y]
  proof
    let x be object such that
A13:x in NAT;
    reconsider i=x as Nat by A13;
    P[i] by A6;
    then consider q be Prime such that
A14: f.i < q divides (f.i-'1)!+1 by Th24;
    take q;
    thus thesis by A14,ORDINAL1:def 12;
  end;
  consider F be Function such that
A15:  dom F = NAT & rng F c= NAT and
A16:  for x being object st x in NAT holds F[x,F.x] from FUNCT_1:sch 6(A12);
  A17:for x1,x2 being object st
    x1 in dom F & x2 in dom F & F.x1=F.x2 holds x1=x2
  proof
    let x1,x2 be object such that
A18: x1 in dom F & x2 in dom F & F.x1=F.x2;
    reconsider x1,x2 as Element of NAT by A15,A18;
A19:F[x1,F.x1] & F[x2,F.x2] by A16;
    reconsider Fx1=F.x1, Fx2=F.x2 as Prime by A16;
    per cases by XXREAL_0:1;
    suppose x1=x2;
      hence thesis;
    end;
    suppose x1 < x2;
      then x1+1<= x2 by NAT_1:13;
      then
A20:  f.(x1+1) <= f.x2 by A7;
      Fx1 divides (f.x1-'1)!+1 by A16;
      then
A21:  Fx1 <= (f.x1-'1)!+1 by NAT_D:7;
      1 < f.x1 by A6,XXREAL_0:2;
      then (f.x1-'1) < f.x1-'1+1  & f.x1-'1 =  f.x1-1 > 1-1
      by NAT_1:13,XREAL_1:233,XREAL_1:14;
      then (f.x1-'1)!+1 <= (f.x1)! <= primenumber ((f.x1)!)
      by Th25,NAT_1:13,PRIMRECI:11;
      then (f.x1-'1)!+1 <= primenumber ((f.x1)!)
        = In(primenumber ((f.x1)!),NAT) by XXREAL_0:2;
      then (f.x1-'1)!+1 <= f.(x1+1) by A1;
      then (f.x1-'1)!+1 <= f.x2 by A20,XXREAL_0:2;
      hence thesis by A18,A21,A19,XXREAL_0:2;
    end;
    suppose x2 < x1;
      then x2+1<= x1 by NAT_1:13;
      then
A22:  f.(x2+1) <= f.x1 by A7;
      Fx2 divides (f.x2-'1)!+1 by A16;
      then
A23:  Fx2 <= (f.x2-'1)!+1 by NAT_D:7;
      1 < f.x2 by A6,XXREAL_0:2;
      then (f.x2-'1) < f.x2-'1+1 & f.x2-'1 = f.x2-1>1-1
        by NAT_1:13,XREAL_1:14,233;
      then (f.x2-'1)!+1 <= (f.x2)! <= primenumber ((f.x2)!)
        by Th25,NAT_1:13,PRIMRECI:11;
      then (f.x2-'1)!+1 <= primenumber ((f.x2)!)
      = In(primenumber ((f.x2)!),NAT) by XXREAL_0:2;
      then (f.x2-'1)!+1 <= f.(x2+1) by A1;
      then (f.x2-'1)!+1 <= f.x1 by A22,XXREAL_0:2;
      hence thesis by A18,A23,A19,XXREAL_0:2;
    end;
  end;
  rng F c=
    {q where q is Prime: ex p being Prime st p < q divides (p-'1)!+1}
  proof
    let y be object;
    assume y in rng F;
    then consider x be object such that
A24:  x in dom F & F.x=y by FUNCT_1:def 3;
    reconsider x as Nat by A15,A24;
    reconsider Fx=F.x as Prime by A24,A15,A16;
A25: f.x is prime by A6;
    f.x < Fx divides (f.x-'1)!+1 by A24,A15,A16;
    hence thesis by A24,A25;
  end;
  hence thesis by A17,FUNCT_1:def 4,A15,CARD_1:59;
end;

:: Problem 114
theorem
  {q where q is Prime: ex n being Nat st n < q & q divides (n-'1)!+1}
    is infinite
proof
  {q where q is Prime: ex p being Prime st p < q divides (p-'1)!+1} c=
  {q where q is Prime: ex n being Nat st n < q & q divides (n-'1)!+1}
  proof
    let x be object;
    assume x in {q where q is Prime:
      ex p being Prime st p < q divides (p-'1)!+1};
    then ex q be Prime st
    q= x & ex p being Prime st p < q divides (p-'1)!+1;
    hence thesis;
  end;
  hence thesis by Th26;
end;

begin :: Problem 118

:: There are an infinite number of positive integers k such that
:: all numbers of the form k * 2^n+1 (where n = 1, 2, ...) are composite.

theorem Th28:
  Fermat 5 = 2|^32 +1 = 641 * 6700417 & 6700417 > Fermat 4
proof
A1: 2|^(1+1) = 2|^1 *2 by NEWTON:6;
  then 2|^(2+1) = 4*2 by NEWTON:6;
  then
A2:2|^(2+3) = 4*8 by A1,NEWTON:8;
A3:2|^(2+2) = 4*4 by A1,NEWTON:8;
  then 2|^(4+4) = 16*16 by NEWTON:8;
  then
A4:2|^(8+8) = 256*256 by NEWTON:8;
A5: 2|^(16+16) = (2|^16)*(2|^16) by NEWTON:8;
  Fermat 5 = 2|^(2|^5) +1 & Fermat 4 = 2|^(2|^4) +1 by PEPIN:def 3;
  hence thesis by A3,A2,A4,A5;
end;

Lm1: for n,t being Nat holds Fermat n divides 2|^ ((2|^n)*(2*t+1)) +1
proof
  let n,t be Nat;
  set T = 2|^(2|^n);
  2|^ ((2|^n)*(2*t+1))+1 = T|^ (2*t+1)+1|^(2*t+1) &
  Fermat n = T +1 by PEPIN:def 3,NEWTON:9;
  hence thesis by NEWTON01:35;
end;

theorem Th29: (2|^32-1)*641,6700417 are_coprime
proof
  2,1 are_coprime;
  then 2,2*2+1 are_coprime by NUMBER04:64;
  then 5,5*1+2 are_coprime by NUMBER04:64;
  then 7,7*1+5 are_coprime by NUMBER04:64;
  then 12,12*1+7 are_coprime by NUMBER04:64;
  then 19,19*3+12 are_coprime by NUMBER04:64;
  then 69,69*1+19 are_coprime by NUMBER04:64;
  then 88,88*6+69 are_coprime by NUMBER04:64;
  then 597,597*1+88 are_coprime by NUMBER04:64;
  then 685,1*685+597 are_coprime by NUMBER04:64;
  then 1282,1282*5225+685 are_coprime by NUMBER04:64;
  then 6699135*1+1282,6699135 are_coprime by NUMBER04:64;
  then 6699135 + 6700417*410880,6700417 are_coprime by NUMBER04:64;
  hence thesis by Th28;
end;

Lm2: m <= 4 implies Fermat m divides 2|^32-1
proof
  assume m <= 4;
  then
A2: m = 0 or ... or m = 4;
A3: 2|^(1+1) = 2|^1 *2 by NEWTON:6;
  then A4:2|^(2+1) = 4*2 by NEWTON:6;
A5:2|^(2+2) = 4*4 by A3,NEWTON:8;
A6:2|^(2|^0) = 2|^1=2 by NEWTON:4;
A7: (2|^(2|^1)) |^(2*8) = 2|^(2*(2*8)) by NEWTON:9;
A8:(2|^(2|^2)) |^(2*4) = 2|^(4*(2*4)) by A3,NEWTON:9;
A9: (2|^(2|^3)) |^(2*2) = 2|^(8*(2*2)) by A4,NEWTON:9;
A10: (2|^(2|^4)) |^(1*2) = 2|^(16*(1*2)) by A5,NEWTON:9;
  per cases by A2;
  suppose m=0;
    then Fermat m = 2|^(2|^0)+1 by PEPIN:def 3;
    then Fermat m divides (2|^(2|^0)) |^(2*16) - 1|^(2*16) by NEWTON01:36;
    hence thesis by A6;
  end;
  suppose m=1;
    then Fermat m = 2|^(2|^1)+1 by PEPIN:def 3;
    then Fermat m divides (2|^(2|^1)) |^(2*8) - 1|^(2*8) by NEWTON01:36;
    hence thesis by A7;
  end;
  suppose m=2;
    then Fermat m = 2|^(2|^2)+1 by PEPIN:def 3;
    then Fermat m divides (2|^(2|^2)) |^(2*4) - 1|^(2*4) by NEWTON01:36;
    hence thesis by A8;
  end;
  suppose m=3;
    then Fermat m = 2|^(2|^3)+1 by PEPIN:def 3;
    then Fermat m divides (2|^(2|^3)) |^(2*2) - 1|^(2*2) by NEWTON01:36;
    hence thesis by A9;
  end;
  suppose m=4;
    then Fermat m = 2|^(2|^4)+1 by PEPIN:def 3;
    then Fermat m divides (2|^(2|^4)) |^(1*2) - 1|^(1*2) by NEWTON01:36;
    hence thesis by A10;
  end;
end;

theorem Th30:
  for k being Nat st
      k,1 are_congruent_mod (2|^32-1)*641 &
      k,-1 are_congruent_mod 6700417 &
      k > 6700417
   for n being positive Nat holds
        k*2|^n +1 is composite &
     ((Fermat 0 divides k*2|^n +1 or...or Fermat 4 divides k*2|^n +1)
   or 641 divides k*2|^n +1 or 6700417 divides k*2|^n +1)
proof
  let k be Nat such that
A1:      k,1 are_congruent_mod (2|^32-1)*641 and
A2:      k, -1 are_congruent_mod 6700417 and
A3:      k > 6700417;
  let n be positive Nat;
  consider m,t be Nat such that
A4: n = (2|^m)*(2*t+1) by NAGATA_2:1;
A5: k*2|^n +1>=1+1 by A3,NAT_1:14,XREAL_1:6;
A6: Fermat m<>1 by PEPIN:55;
  per cases;
  suppose
A7: m <= 4;
A8:  2|^n,2|^n are_congruent_mod (2|^32-1) &
    1,1 are_congruent_mod (2|^32-1) by INT_1:11;
    k,1 are_congruent_mod (2|^32-1) by A1,INT_1:20;
    then
A9: k*(2|^n),1*(2|^n)  are_congruent_mod (2|^32-1) by A8,INT_1:18;
    Fermat m divides 2|^32-1 by A7,Lm2;
    then
A10:Fermat m divides k*(2|^n)+1 - ((2|^n)+1) by A9,INT_2:9;
    Fermat m divides 2|^n +1 by A4,Lm1;
    then
A11:Fermat m divides k*(2|^n)+1 - ((2|^n)+1)+(2|^n +1) by A10,WSIERP_1:4;
    2|^n>=1 by NAT_1:14;
    then k*(2|^n) >= 1*6700417 by A3,XREAL_1:66;
    then
A12: k*(2|^n)+1 > 6700417 by NAT_1:13;
    6700417 > Fermat 4 >= Fermat m by A7,NUMBER09:31,Th28;
    then 6700417 > Fermat m by XXREAL_0:2;
    then not k*(2|^n)+1 is prime by A6,A11,A12;
    hence thesis by A7,A11,A5,NUMBER02:def 1;
  end;
  suppose m > 4;
    then m >= 4+1 by NAT_1:13;
    then per cases by XXREAL_0:1;
    suppose
A13:  m = 5;
A14:  2|^n,2|^n are_congruent_mod 641 &
      1,1 are_congruent_mod 641 by INT_1:11;
      k,1 are_congruent_mod 641 by A1,INT_1:20;
      then
A15:  k*(2|^n),1*(2|^n)  are_congruent_mod 641 by A14,INT_1:18;
      641 divides Fermat m divides 2|^ n +1 by A13,A4,Lm1,NAT_6:45;
      then 641 divides 2|^ n +1 by INT_2:9;
      then
A16:  641 divides k*(2|^n)+1 - ((2|^n)+1)+(2|^n +1) by A15,WSIERP_1:4;
      2|^n>=1 by NAT_1:14;
      then k*(2|^n) >= 1*6700417 by A3,XREAL_1:66;
      then k*(2|^n)+1 > 6700417 by NAT_1:13;
      then k*(2|^n)+1 > 641 by XXREAL_0:2;
      then not k*(2|^n)+1 is prime by A16;
      hence thesis by A16,A5,NUMBER02:def 1;
    end;
    suppose m > 5;
      then m >= 5+1 by NAT_1:13;
      then 2|^6 divides 2|^m divides n by A4,NEWTON:89;
      then consider h be Nat such that
A17:   n = 2|^6 * h by INT_2:9,NAT_D:def 3;
A18:   2|^n,2|^n are_congruent_mod 6700417 &
      1,1 are_congruent_mod 6700417 by INT_1:11;
      k*(2|^n),(-1)*(2|^n)  are_congruent_mod 6700417 by A2,A18,INT_1:18;
      then
A19:   6700417 divides k*(2|^n)+1 + ((2|^n)-1);
      6700417 divides Fermat 5 by Th28;
      then
A20:  6700417 divides 2|^(2|^5)+1 by PEPIN:def 3;
      2|^(2|^5) |^(2*1) = 2|^(2|^5 *2) by NEWTON:9
      .=2|^(2|^(5+1)) by NEWTON:6;
      then
      2|^(2|^5)+1 divides 2|^(2|^6) - 1|^(2*1) by NEWTON01:36;
      then A21:6700417 divides 2|^(2|^6) - 1 by A20,INT_2:9;
      2|^(2|^6) |^h = 2|^n by A17,NEWTON:9;
      then 2|^(2|^6) - 1 divides 2|^n - 1|^h by NEWTON01:33;
      then
A22:  6700417 divides 2|^n - 1|^h by A21,INT_2:9;
      2|^n>=1 by NAT_1:14;
      then k*(2|^n) >= 1*6700417 by A3,XREAL_1:66;
      then k*(2|^n)+1 > 6700417 by NAT_1:13;
      then not k*(2|^n)+1 is prime by A22,A19,INT_2:1;
      hence thesis by A5,A22,A19,INT_2:1,NUMBER02:def 1;
    end;
  end;
end;

theorem Th31:
  ex crt being Nat st 6700417 < crt < 2 * (2|^64-1) &
    for n being Nat holds
       crt +n * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
       crt +n * 2 * (2|^64-1), -1 are_congruent_mod 6700417  &
       crt +n * 2 * (2|^64-1), 1 are_congruent_mod 2
proof
  set P1 = (2|^32-1)*641, P2 = 6700417, P3 = 2;
  set PPP=<*P1,P2,P3*>;
A1: for i,j be Nat st i in dom PPP & j in dom PPP & i < j holds
    PPP.i, PPP.j are_coprime
  proof
    let i,j be Nat such that
A2: i in dom PPP & j in dom PPP & i < j;
A3: 1<= i & j <= len PPP = 2+1 by A2,FINSEQ_1:45,FINSEQ_3:25;
    then per cases by NAT_1:9;
    suppose
A4:   j = 2+1;
A5:   320*2+1 is odd;
      2|^32-1=2|^32-'1 by NAT_1:14,XREAL_1:233;
      then consider j be Nat such that
      A6:  (2|^32-'1)*641 = 2*j+1 by A5,ABIAN:9;
      2,1 are_coprime;
      then A7: 2,2*3350208+1 are_coprime & 2,2*j+1 are_coprime by NUMBER04:64;
      i <= 1+1 by A4,A2,NAT_1:13;
      then per cases by NAT_1:9;
      suppose i = 2;
        hence thesis by A7,A4;
      end;
      suppose i <=1;
        then i = 1 by A3,XXREAL_0:1;
        hence thesis by NAT_1:14,XREAL_1:233,A4,A7,A6;
      end;
    end;
    suppose A8:j <= 2;
      then i < 1+1 by A2,XXREAL_0:2;
      then i <= 1 by NAT_1:13;
      then A9:i = 1 by A3,XXREAL_0:1;
      1 < j by A2,A3,XXREAL_0:2;
      then 1+1 <= j by NAT_1:13;
      then j = 2 by A8,XXREAL_0:1;
      hence thesis by A9,Th29;
    end;
  end;
  A10: for i,j be Nat st i in dom PPP & j in dom PPP & i <> j holds
  PPP.i, PPP.j are_coprime
  proof
    let i,j be Nat such that A11: i in dom PPP & j in dom PPP & i <> j;
    i < j or j < i by A11,XXREAL_0:1;
    hence thesis by A1,A11;
  end;
  reconsider PPP as non empty positive-yielding Chinese_Remainder
  INT -valued
  FinSequence by A10,INT_6:def 2;
  1 in INT & -1 in INT & 2 in INT by INT_1:def 2;
  then
  reconsider B=<*1,-1,1*> as FinSequence of INT by FINSEQ_2:14;
  take crt = CRT(B,PPP);
  P1*P2 = (2|^32-1) * (641*6700417)
  .= (2|^32-1)*(2|^32+1) by Th28
  .= (2|^32*2|^32)-1*1
  .= 2|^(32+32)-1 by NEWTON:8;
  then
  A12: Product PPP = 2 * (2|^64-1) by RVSUM_1:100;
  A13:len B = 3 = len PPP by FINSEQ_1:45;
  then A14: dom B = dom PPP by FINSEQ_3:29;
  A15:crt solves_CRT B,PPP & crt < Product PPP by A14, NUMBER14:def 4;
  A16:2 in dom B by A13,FINSEQ_3:25;
  A17:3 in dom B by A13,FINSEQ_3:25;
  thus 6700417 < crt
  proof
    A18: crt, B.2 are_congruent_mod PPP.2 by A15,A16,NUMBER14:def 3;
    A19: crt, B.3 are_congruent_mod PPP.3 & B.3 = 1
    by A17,A15,NUMBER14:def 3;
    assume 6700417 >= crt;
    then per cases by XXREAL_0:1;
    suppose 6700417 = crt;
      then 0,crt are_congruent_mod 6700417 by INT_1:12;
      then 0,-1 are_congruent_mod 6700417 by A18,INT_1:15;
      hence thesis by INT_2:13;
    end;
    suppose A20:6700417 > crt;
      0,6700417 are_congruent_mod 6700417 by INT_1:12;
      then crt+0,6700417+  -1 are_congruent_mod 6700417 by A18,INT_1:16;
      then crt mod 6700417 = 6700416 mod 6700417 = 6700416
      by NAT_D:24,64;
      then 2 divides 6700416-1 by A19,NAT_D:24,A20;
      then 2 divides 3350207*2+1;
      hence thesis;
    end;
  end;
  thus crt < 2 * (2|^64-1) by A14, NUMBER14:def 4,A12;
  let n be Nat;
  1 in dom B by A13,FINSEQ_3:25;
  then crt +n * Product PPP, B.1 are_congruent_mod PPP.1
  by A14,A15,NUMBER14:30,def 3;
  hence crt +n * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 by A12;
  crt +n * Product PPP, B.2 are_congruent_mod PPP.2
  by A14,A15,NUMBER14:30,def 3,A16;
  hence crt +n * 2 * (2|^64-1), -1 are_congruent_mod 6700417 by A12;
  crt +n * Product PPP, B.3 are_congruent_mod PPP.3 & B.3 = 1
  by A17,A14,A15,NUMBER14:30,def 3;
  hence thesis by A12;
end;

::Problem 118
theorem
  {k where k is Nat: for n being positive Nat holds k*2|^n +1 is composite}
    is infinite
proof
  consider crt be Nat such that
A1: 6700417 < crt and
A2:   for n being Nat holds
    crt < 2 * (2|^64-1) &
    crt +n * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
    crt +n * 2 * (2|^64-1), -1 are_congruent_mod 6700417  &
    crt +n * 2 * (2|^64-1), 1 are_congruent_mod 2 by Th31;
  defpred P[Nat] means for n being positive Nat holds $1*2|^n +1 is composite;
  set I = {crt +k * 2 * (2|^64-1) where k is Nat: P[crt +k * 2 * (2|^64-1)]};
  (2|^32-1) * 641*6700417 =
  (2|^32-1) * (641*6700417)
  .= (2|^32-1)*(2|^32+1) by Th28
  .= (2|^32*2|^32)-1*1
  .= 2|^(32+32)-1 by NEWTON:8;
  then 2|^64-1 >= 6700417*1 by NAT_1:14,XREAL_1:64;
  then 2*(2|^64-1) >= 6700417*2 > 6700417*1 by XREAL_1:64;
  then
A3: 2*(2|^64-1) > 6700417*1 by XXREAL_0:2;
  crt +0 * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
  crt +0 * 2 * (2|^64-1), -1 are_congruent_mod 6700417 by A2;
  then P[crt+0*2*(2|^64-1)] by A1,Th30;
  then
A4: (crt+0*2*(2|^64-1)) in I;
  now let x be object;
    assume x in I;
    then ex k being Nat st
    x = crt +k * 2 * (2|^64-1) & P[crt +k * 2 * (2|^64-1)];
    hence x is natural;
  end;
  then
A5: I is non empty natural-membered set by A4,MEMBERED:def 6;
A6: for a being Nat st a in I ex b being Nat st b > a & b in I
  proof
    let a be Nat;
    assume a in I;
    then consider k be Nat such that
A7: a = crt +k * 2 * (2|^64-1) & P[crt +k * 2 * (2|^64-1)];
A8: crt +(k+1) * 2 * (2|^64-1) = a + 2*(2|^64-1)> 0 +6700417
    & a + 2*(2|^64-1)> a+0 by A7,A3,XREAL_1:8;
    crt +(k+1) * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
    crt +(k+1) * 2 * (2|^64-1), -1 are_congruent_mod 6700417 by A2;
    then P[crt+(k+1)*2*(2|^64-1)] by A8,Th30;
    then crt +(k+1) * 2 * (2|^64-1) in I;
    hence thesis by A8;
  end;
  I c= {k where k is Nat: P[k]}
  proof
    let x be object;
    assume x in I;
    then consider k be Nat such that
A9: x = crt +k * 2 * (2|^64-1) & P[crt +k * 2 * (2|^64-1)];
    thus thesis by A9;
  end;
  hence thesis by A6,A5,NUMBER04:1;
end;

begin :: Problem 119

:: There are infinitely many odd numbers k such that every number
:: of the form 2^n + k (where n = 1, 2, ...) is composite.
theorem
  for k being Nat st
    k = 15* 1000000000 * 1000000000 + 511380746 * 1000000000 + 462593381
  holds
  k > 6700417 &
  k, 1 are_congruent_mod (2|^32-1)*641 &
  k, -1 are_congruent_mod 6700417  &
  k, 1 are_congruent_mod 2 &
    (not Fermat 0 divides k*2|^(2|^5) +1
       &...&
     not Fermat 4 divides k*2|^(2|^5) +1) &
  not 6700417 divides k*2|^(2|^5) +1 &
  641 divides k*2|^(2|^5) +1
proof
  let k be Nat such that
A1:k = 15* 1000000000* 1000000000+ 511380746 * 1000000000+462593381;
  thus k > 6700417 by A1;
  k -1  = 5634204 * ((2|^32-1)*641) by A1,Th28;
  hence
A2: k, 1 are_congruent_mod (2|^32-1)*641;
  k+1 = (2314*1000000000+987372646) * 6700417 by A1;
  hence
A3: k, -1 are_congruent_mod 6700417;
  k-1 = (7* 1000000000 * 1000000000 + 755690373* 1000000000 +231296690) *2
    by A1;
  hence k, 1 are_congruent_mod 2;
A4: 2|^(1+1) = 2|^1 *2 by NEWTON:6;
  then 2|^(2+1) = 4*2 by NEWTON:6;
  then
A5:2|^(2+3) = 4*8 by A4,NEWTON:8;
  k-1 = (5* 1000000000 * 1000000000+ 170460248* 1000000000+ 820864460)*3 by A1;
  then
A6:k,1 are_congruent_mod 3;
  3*0+2=2;
  then
A7:not 3 divides 2 by NAT_4:9;
  2|^32-1 = 3 * 1431655765 by Th28;
  then 2|^32, 1 are_congruent_mod 3;
  then k*2|^32 , 1*1 are_congruent_mod 3 by A6,INT_1:18;
  then
A8: k*2|^32 +1, 1+1 are_congruent_mod 3;
  k-1 = (3* 1000000000 * 1000000000+102276149* 1000000000+ 292518676)*5 by A1;
  then
A9:k,1 are_congruent_mod 5;
  5*0+2=2;
  then
A10:not 5 divides 2 by NAT_4:9;
  2|^32-1 = 5 * 858993459 by Th28;
  then 2|^32, 1 are_congruent_mod 5;
  then k*2|^32 , 1*1 are_congruent_mod 5 by A9,INT_1:18;
  then
A11:k*2|^32 +1, 1+1 are_congruent_mod 5;
  k-1 = (912434161* 1000000000+ 556623140)*17 by A1;
  then
A12:k,1 are_congruent_mod 17;
  17*0+2=2;
  then
A13:not 17 divides 2 by NAT_4:9;
  2|^32-1 = 17 * 252645135 by Th28;
  then 2|^32, 1 are_congruent_mod 17;
  then k*2|^32 , 1*1 are_congruent_mod 17 by A12,INT_1:18;
  then
A14:k*2|^32 +1, 1+1 are_congruent_mod 17;
  k-1 = (60355567* 1000000000+    106858340)*257 by A1;
  then
A15:k,1 are_congruent_mod 257;
  257*0+2=2;
  then
A16:not 257 divides 2 by NAT_4:9;
  2|^32-1 = 257 * 16711935 by Th28;
  then 2|^32, 1 are_congruent_mod 257;
  then k*2|^32 , 1*1 are_congruent_mod 257 by A15,INT_1:18;
  then
A17:k*2|^32 +1, 1+1 are_congruent_mod 257;
  k-1 = (236681* 1000000000+ 275408740)*65537 by A1;
  then
A18:k,1 are_congruent_mod 65537;
  65537*0+2=2;
  then
A19:not 65537 divides 2 by NAT_4:9;
  2|^32-1 = 65537 * 65535 by Th28;
  then 2|^32, 1 are_congruent_mod 65537;
  then k*2|^32 , 1*1 are_congruent_mod 65537 by A18,INT_1:18;
  then
A20:k*2|^32 +1, 1+1 are_congruent_mod 65537;
  thus not Fermat 0 divides k*2|^(2|^5) +1
  &...&
  not Fermat 4 divides k*2|^(2|^5) +1
  by A8,A7,PEPIN:50,51,52,54,A11,A5,A10,A14,A13,A17,A16,
    NUMBER14:19,PEPIN:53,A20,A19;
  6700417*0+2=2;
  then
A21:not 6700417 divides 2 by NAT_4:9;
  2|^32, -1 are_congruent_mod 6700417 by Th28;
  then k*2|^32 , (-1)*(-1) are_congruent_mod 6700417 by A3,INT_1:18;
  then k*2|^32 +1, 2 are_congruent_mod 6700417;
  hence not 6700417 divides  k*2|^(2|^5) +1 by A5,A21,NUMBER14:19;
A22:k, 1 are_congruent_mod 641 by A2,INT_1:20;
  2|^32, -1 are_congruent_mod 641 by Th28;
  then k*2|^32 , (-1)*(1) are_congruent_mod 641 by A22,INT_1:18;
  hence 641 divides k*2|^(2|^5) +1 by A5;
end;

registration
  let n be Nat;
  cluster Fermat n -> odd;
  coherence
  proof
    2|^(2 |^ n)+1 is odd;
    hence thesis by PEPIN:def 3;
  end;
end;

theorem Th34:
  for n,m being non zero Nat, p st p|^n divides m
    holds Euler (p|^n) <= Euler m
proof
  let n,m be non zero Nat, p be Prime such that
A1:p|^n divides m;
  p|^1 divides p|^n by NAT_1:14,NEWTON:89;
  then consider k,w be positive Nat such that
A2:0 < k & m = w * p|^k & w,p are_coprime by A1,INT_2:9,NUMBER15:21;
  Euler m = Euler w * Euler (p|^k) by A2,WSIERP_1:10,EULER_1:21;
  then
A3: Euler m >= Euler (p|^k) *1 by NAT_1:14,XREAL_1:64;
  w,p|^n are_coprime by A2,WSIERP_1:10;
  then p |-count (p|^n) <= p |-count (p|^k) = k
  by A2,A1,EULER_1:13,NAT_3:25,30,INT_2:def 4;
  then
A4: n <= k by NAT_3:25,INT_2:def 4;
A5: k-'1+1=k-1+1 & n-'1+1 = n-1+1;
  then p|^k = p*p|^(k-'1) & p|^n = p*p|^(n-'1) by NEWTON:6;
  then
A6: Euler(p|^k) = p*p|^(k-'1) - p|^(k-'1) = p|^(k-'1)*(p-1)&
  Euler(p|^n) = p*p|^(n-'1) - p|^(n-'1) = p|^(n-'1)*(p-1)
  by NAT_1:14,INT_8:8;
  n-'1 <= k-'1 by A5,A4,XREAL_1:9;
  then p|^(n-'1) <= p|^(k-'1) by NAT_6:1;
  then p|^(n-'1)*(p-1) <= p|^(k-'1)*(p-1) by XREAL_1:64;
  hence thesis by A3,A6,XXREAL_0:2;
end;

theorem Th35:
  for k st k,1 are_congruent_mod (2|^32-1)*641 &
      k,-1 are_congruent_mod 6700417 & k > 6700417 holds
  for n being positive Nat
     holds
  k+ (2|^n) is composite &
  ((Fermat 0 divides k+ 2|^n or...or Fermat 4 divides k+ 2|^n)
     or 641 divides k+ (2|^n) or 6700417 divides k+ (2|^n))
proof
  let k be Nat such that
A1:   k,1 are_congruent_mod (2|^32-1)*641 and
A2:   k,-1 are_congruent_mod 6700417 and
A3:   k > 6700417;
  set Q = Fermat(0)* Fermat(1)*Fermat(2)*Fermat(3)*Fermat(4)*Fermat(5);
  let n be positive Nat;
A4:2,Q are_coprime
  proof
    consider k be Nat such that
A5:   Q= 2*k+1 by ABIAN:9;
    1,2 are_coprime;
    hence thesis by A5,NUMBER04:64;
  end;
  2 < Fermat(5) & 1 <= Fermat(0)* Fermat(1)*Fermat(2)*Fermat(3)*Fermat(4)
  by NAT_1:14,Th28;
  then 1+1=1*2 <= Q by XREAL_1:66;
  then
A6:Q > 1 by NAT_1:13;
  set e = n*(Euler(Q) -'1);
  Euler(Q) > 1
  proof
    Q=Fermat(0)* (Fermat(1)*Fermat(2)*Fermat(3)*Fermat(4)*Fermat(5));
    then Fermat 0 divides Q;
    then 3-1 = Euler (3|^1) <= Euler Q by Th34,PEPIN:41,50,EULER_1:20;
    hence thesis by XXREAL_0:2;
  end;
  then
A7: Euler(Q) -'1 = Euler(Q) -1  >1-1 by XREAL_1:14,233;
  then k*2|^e +1 is composite &
    (Fermat 0 divides k*2|^e +1 or...or Fermat 4 divides k*2|^e +1)
    or 641 divides k*2|^e +1 or 6700417 divides k*2|^e +1 by A1,A2,A3,Th30;
  then consider q be Nat such that
A8: q divides k*2|^e +1 and
A9: q = Fermat 0 or q = Fermat 1
    or q = Fermat 2 or q = Fermat 3 or q = Fermat 4 or q = 641 or q = 6700417;
A10: k*2|^e +1,0 are_congruent_mod q by A8;
  2|^n,2|^n are_congruent_mod q by INT_1:11;
  then
A11:(k*2|^e +1)*(2|^n),0*(2|^n) are_congruent_mod q by A10,INT_1:18;
A12: (k*2|^e +1)*(2|^n) = k*(2|^e*(2|^n)) + (2|^n)
  .= k*(2|^(e+n)) + (2|^n) by NEWTON:8
  .= k*(2|^(n*Euler Q))+ (2|^n) by A7;
A13:k,k are_congruent_mod q by INT_1:11;
A14:2|^Euler Q,1 are_congruent_mod q & k > q > 1
  proof
A15: Fermat 5 = 641 * 6700417 by Th28;
    (2|^Euler Q) mod Q = 1 = 1 mod Q by A6,A4,EULER_2:18,NAT_D:14;
    then
A16: 2|^Euler Q,1 are_congruent_mod Q by NAT_D:64;
    per cases by A9;
    suppose
A17:  q = Fermat 0;
      then Q = q * ( Fermat(1)*Fermat(2)*Fermat(3)*Fermat(4)*Fermat(5));
      hence thesis by A17,A3, A16,INT_1:20,PEPIN:50,XXREAL_0:2;
    end;
    suppose
A18:  q = Fermat 1;
      then Q = q * ( Fermat(0)*Fermat(2)*Fermat(3)*Fermat(4)*Fermat(5));
      hence thesis by A16,INT_1:20,A18,A3,PEPIN:51,XXREAL_0:2;
    end;
    suppose
A19:  q = Fermat 2;
      then Q = q * ( Fermat(0)*Fermat(1)*Fermat(3)*Fermat(4)*Fermat(5));
      hence thesis by A16,INT_1:20,A19,A3,PEPIN:52,XXREAL_0:2;
    end;
    suppose
A20:  q = Fermat 3;
      then Q = q * ( Fermat(0)*Fermat(1)*Fermat(2)*Fermat(4)*Fermat(5));
      hence thesis by A20,A3,A16,INT_1:20,PEPIN:53,XXREAL_0:2;
    end;
    suppose
A21:  q = Fermat 4;
      then Q = q * ( Fermat(0)*Fermat(1)*Fermat(2)*Fermat(3)*Fermat(5));
      hence thesis by A21,A3,A16,INT_1:20,PEPIN:54,XXREAL_0:2;
    end;
    suppose
A22:  q = 641;
      then Q = q * (6700417* Fermat(0)*Fermat(1)*Fermat(2)*Fermat(3)*Fermat(4))
      by A15;
      hence thesis by A22,A3,A16,INT_1:20,XXREAL_0:2;
    end;
    suppose
A23:  q = 6700417;
      then Q = q * (641* Fermat(0)*Fermat(1)*Fermat(2)*Fermat(3)*Fermat(4))
      by A15;
      hence thesis by A16,INT_1:20,A23,A3;
    end;
  end;
  then (2|^Euler Q) |^n,1|^n are_congruent_mod q by GR_CY_3:34;
  then k*((2|^Euler Q) |^n), k*1 are_congruent_mod q by A13,INT_1:18;
  then k*(2|^((Euler Q) *n) ), k are_congruent_mod q by NEWTON:9;
  then
A24: k*(2|^((Euler Q) *n) )+ (2|^n), k+ (2|^n) are_congruent_mod q;
  0,k*(2|^((Euler Q)*n))+ (2|^n) are_congruent_mod q by A11,A12, INT_1:14;
  then 0,k+ (2|^n) are_congruent_mod q by A24,INT_1:15;
  then
A25:k+ (2|^n),0 are_congruent_mod q by INT_1:14;
  q+0 < k+ (2|^n) by A14,XREAL_1:8;
  then
A26:not k+ (2|^n) is prime & k+ (2|^n) > 1
  by A14,A25,XXREAL_0:2;
  then k+ (2|^n) >= 1+1 by NAT_1:13;
  hence thesis by A25,A9,A26,NUMBER02:def 1;
end;

::Problem 119
theorem
  {k where k is Nat: for n being positive Nat holds 2|^n +k is composite}
    is infinite
proof
  consider crt be Nat such that
A1:6700417 < crt and
A2:  for n being Nat holds
  crt < 2 * (2|^64-1) &
  crt +n * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
  crt +n * 2 * (2|^64-1), -1 are_congruent_mod 6700417  &
  crt +n * 2 * (2|^64-1), 1 are_congruent_mod 2 by Th31;
  defpred P[Nat] means for n being positive Nat holds 2|^n +$1 is composite;
  set I = {crt +k * 2 * (2|^64-1) where k is Nat: P[crt +k * 2 * (2|^64-1)]};
  (2|^32-1) * 641*6700417 = (2|^32-1) * (641*6700417)
  .= (2|^32-1)*(2|^32+1) by Th28
  .= (2|^32*2|^32)-1*1
  .= 2|^(32+32)-1 by NEWTON:8;
  then 2|^64-1 >= 6700417*1 by NAT_1:14,XREAL_1:64;
  then 2*(2|^64-1) >= 6700417*2 > 6700417*1 by XREAL_1:64;
  then
A3: 2*(2|^64-1) > 6700417*1 by XXREAL_0:2;
  crt +0 * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
  crt +0 * 2 * (2|^64-1), -1 are_congruent_mod 6700417 by A2;
  then P[crt+0*2*(2|^64-1)] by Th35,A1;
  then
A4: (crt+0*2*(2|^64-1)) in I;
  now let x be object;
    assume x in I;
    then ex k being Nat st
      x = crt +k * 2 * (2|^64-1) & P[crt +k * 2 * (2|^64-1)];
    hence x is natural;
  end;
  then
A5:I is non empty natural-membered set
  by A4,MEMBERED:def 6;
A6: for a being Nat st a in I ex b being Nat st b > a & b in I
  proof
    let a be Nat;
    assume a in I;
    then consider k be Nat such that
A7: a = crt +k * 2 * (2|^64-1) & P[crt +k * 2 * (2|^64-1)];
A8: crt +(k+1) * 2 * (2|^64-1) = a + 2*(2|^64-1)> 0 +6700417
      & a + 2*(2|^64-1)> a+0 by A7,A3,XREAL_1:8;
    crt +(k+1) * 2 * (2|^64-1), 1 are_congruent_mod (2|^32-1)*641 &
    crt +(k+1) * 2 * (2|^64-1), -1 are_congruent_mod 6700417 by A2;
    then P[crt+(k+1)*2*(2|^64-1)] by A8,Th35;
    then crt +(k+1) * 2 * (2|^64-1) in I;
    hence thesis by A8;
  end;
  I c= {k where k is Nat: P[k]}
  proof
    let x be object;
    assume x in I;
    then ex k be Nat st x = crt +k * 2 * (2|^64-1) & P[crt +k * 2 * (2|^64-1)];
    hence thesis;
  end;
  hence thesis by A6,A5,NUMBER04:1;
end;

begin :: Lagrange basis and interpolating polynomials

theorem
  for L be non empty ZeroStr
    for p be Polynomial of L st len p = 1 holds p = <%p.0%>
proof
  let L be non empty ZeroStr;
  let p be Polynomial of L such that
A1: len p = 1;
  p.(len p-'1) <> 0.L & len p-'1 = 0 by A1,UPROOTS:18,XREAL_1:232;
  then
A2: len <%p.0%> = 1 by POLYNOM5:33;
  for k being Nat st k < len p holds p.k = <%p.0%>.k
  proof
    let k be Nat;
    assume k < len p;
    then k = 0 by A1,NAT_1:14;
    hence thesis by POLYNOM5:32;
  end;
  hence thesis by A1,A2,ALGSEQ_1:12;
end;

theorem Th38:
  for L be non empty ZeroStr
    for p be Polynomial of L st len p = 2 holds p = <%p.0, p.1%>
proof
  let L be non empty ZeroStr;
  let p be Polynomial of L such that
A1: len p = 2;
  p.(len p-'1) <> 0.L & len p-'1 = 2-1 by A1,UPROOTS:18,XREAL_1:233;
  then
A2: len <%p.0, p.1%> = 2 by POLYNOM5:40;
  for k being Nat st k < len p holds p.k = <%p.0,p.1%>.k
  proof
    let k be Nat;
    assume k < len p;
    then k = 0 or k = 1 by A1,NAT_1:23;
    hence thesis by POLYNOM5:38;
  end;
  hence thesis by A1,A2,ALGSEQ_1:12;
end;

theorem Th39:
  for R being Ring,x being Element of R, p being Polynomial of R
    holds Ext_eval(p,x) = eval(p,x)
proof
  let R be Ring,x be Element of R,p be Polynomial of R;
A1:1.R=1.R & 0.R=0.R;
A2:the addF of R = (the addF of R) | [:the carrier of R,the carrier of R:]
  .= (the addF of R) || the carrier of R by REALSET1:def 2;
  the multF of R = (the multF of R) | [:the carrier of R,the carrier of R:]
  .= (the multF of R) || the carrier of R by REALSET1:def 2;
  then R is Subring of R by A1,A2,C0SP1:def 3;
  then Ext_eval(p,In(x,R)) = In(eval(p,x),R) by ALGNUM_1:12;
  hence thesis;
end;

theorem Th40:
  for R,S being Ring st S is Subring of R
    for p being Polynomial of R for x being Element of R
    for q being Polynomial of S for y being Element of S st p=q & x=y
      holds eval(p,x)=eval(q,y)
proof
  let R,S be Ring such that
A1: S is Subring of R;
  let p be Polynomial of R; let x be Element of R;
  let q be Polynomial of S;let  y be Element of S such that
A2: p=q & x=y;
A3:eval(q,y) in the carrier of S c= the carrier of R by A1,C0SP1:def 3;
  thus eval(p,x) =Ext_eval(p,In(x,R)) by Th39
  .= Ext_eval(q,In(y,R)) by A1,A2,LIOUVIL2:14
  .= In(eval(q,y),R) by A1,ALGNUM_1:12
  .= eval(q,y) by A3,SUBSET_1:def 8;
end;

theorem Th41:
  for R being Field
    for p being Polynomial of R
    for a being Element of R st a is_a_root_of p
  holds p = (p div rpoly(1,a))*'rpoly(1,a)
proof
  let R be Field;
  let p be Polynomial of R;
  let a be Element of R such that
A1: a is_a_root_of p;
  set D=p div rpoly(1,a), RP=rpoly(1,a);
A2: - (p div rpoly(1,a)) *' rpoly(1,a)+(p div rpoly(1,a)) *' rpoly(1,a) =
  (p div rpoly(1,a)) *' rpoly(1,a)- (p div rpoly(1,a)) *' rpoly(1,a)
  .= 0_.R by POLYNOM3:29;
  p mod rpoly(1,a) = 0_. R by A1,HURWITZ:35,def 7;
  then p - (p div rpoly(1,a)) *' rpoly(1,a)+(p div rpoly(1,a)) *' rpoly(1,a)
  = 0_.R +(p div rpoly(1,a)) *' rpoly(1,a) by HURWITZ:def 6;
  then p +(0_.R) = (p div rpoly(1,a)) *' rpoly(1,a)
  by A2,POLYNOM3:26;
  hence thesis;
end;

theorem Th42:
  for R being non empty comRing
    for S being Ring st S is Subring of R
    for p,q being Polynomial of R st p is Polynomial of S
    for a being Element of R,b be Element of S st
      a=b & b is left_invertible & p = q *' rpoly(1,a)
  holds q is Polynomial of S
proof
  let R be non empty comRing;
  let S be Ring;
  assume S is Subring of R;
  then reconsider S1=S as Subring of R;
  let p,q be Polynomial of R such that A1:p is Polynomial of S;
  let a be Element of R,c be Element of S such that
A2:a=c & c is left_invertible & p = q *' rpoly(1,a);
  reconsider b=c as Element of S1;
  consider ys be Element of S1 such that
A3: ys*b = 1.S1 by A2,ALGSTR_0:def 27;
  ys in the carrier of S1 c= the carrier of R by C0SP1:def 3;
  then reconsider y=ys as Element of R;
A4:a*y = b*ys by A2,FIELD_6:16;
  then
A5: a*y = 1.R by A3,C0SP1:def 3;
  set RP=rpoly(1,a);
  defpred P[Nat] means q.$1 in the carrier of S1;
A6: RP.0 = -power(R).(a,1)= -a  & RP.1 = 1_R by HURWITZ:25,GROUP_1:50;
A7: dom p = NAT & rng p c= the carrier of S
    by A1,RELAT_1:def 19,FUNCT_2:def 1;
A8: P[0]
  proof
    consider r be FinSequence of the carrier of R such that
A9: len r = 0 + 1 & (q *' RP) . 0 = Sum r and
A10: for k being Element of NAT st k in dom r holds
    r . k = (q . (k -' 1)) * (RP . ((0 + 1) -' k)) by POLYNOM3:def 9;
A11: r.1 = (q . (1 -' 1)) * (RP . ((0 + 1) -' 1)) by A9,FINSEQ_3:25,A10;
    p.0 in rng p by A7,FUNCT_1:def 3;
    then reconsider p0 = p.0 as Element of S1 by A7;
    r = <*(q.0) * (RP.0)*> by A9,A11,FINSEQ_1:40;
    then p.0 = (q.0) * (-a) by A2,A9,A6,RLVECT_1:44
    .= - (q.0)*a by VECTSP_1:8;
    then
A12: (-(p.0))*y = (q.0)*(a*y) by GROUP_1:def 3;
    -(p.0) = -p0 by FIELD_6:17;
    then (-(p.0))*y = (-p0)*ys by FIELD_6:16;
    hence thesis by A5,A12;
  end;
A13: for i being Nat st P[i] holds P[i+1]
  proof
    let i be Nat such that
A14:P[i];
    consider r be FinSequence of the carrier of R such that
A15: len r = (i+1) + 1 & (q *' RP) . (i+1) = Sum r and
A16: for k being Element of NAT st k in dom r holds
    r . k = (q . (k -' 1)) * (RP . (((i+1) + 1) -' k)) by POLYNOM3:def 9;
    len r = i+2 by A15;
    then consider r1,r2 be FinSequence of the carrier of R such that
A17:  len r1 = i & len r2 = 2 & r = r1^r2 by FINSEQ_2:23;
    for k be Element of NAT st k in dom r1 holds r1.k = 0.R
    proof
      let k be Element of NAT such that
A18:  k in dom r1;
      dom r1 c= dom r & r.k = r1.k by A18,A17,FINSEQ_1:26,def 7;
      then
A19:  r1.k = (q . (k -' 1)) * (RP . (((i+1) + 1) -' k)) by A18,A16;
A20:  k <= i by A17,A18,FINSEQ_3:25;
      then k+0<= i+2 by XREAL_1:7;
      then
A21:  i+2-'k = i+2-k by XREAL_1:233;
      k-k <= i-k by A20,XREAL_1:9;
      then 0+2 <= i-k+2 by XREAL_1:6;
      then i+2-'k  <>0 & i+2-'k <>1 by A21;
      then (RP . (((i+1) + 1) -' k))  = 0.R by HURWITZ:26;
      hence thesis by A19;
    end;
    then Sum r1 = 0.R by POLYNOM3:1;
    then
A22: Sum r = (0.R)+Sum r2 by A17,RLVECT_1:41;
    p.(i+1) in rng p by A7,FUNCT_1:def 3;
    then reconsider qi = q.i,pi1 = p.(i+1) as Element of S1 by A7,A14;
A23: (i+1) -' 1 = i+1-1=i;
A24: ((i+1) + 1) -' (i+1) = ((i+1) + 1) - (i+1)=1;
    1<=i+1+1 by NAT_1:11;
    then
A25: (i+2) -' 1 =(i+2) - 1 =i+1;
A26: ((i+1) + 1) -' (i+2)=0 by XREAL_1:232;
    1 in dom r2 & 2 in dom r2 by A17,FINSEQ_3:25;
    then r2.1 = r.(i+1) & i+1 in dom r & r2.2 = r.(i+2) & i+2 in dom r
      by A17,FINSEQ_1:def 7,28;
    then r2 . 1 = (q . i) * (RP . 1) &
    r2 . 2 = (q . (i+1)) * (RP.0) by A16,A23,A24,A25,A26;
    then r2 = <*  (q . i) * (RP . 1), (q . (i+1)) * (RP.0)*>
      by A17,FINSEQ_1:44;
    then Sum r2 = Sum <*  (q . i) * (RP . 1)*> + Sum <* (q . (i+1)) * (RP.0)*>
      by RLVECT_1:41;
    then Sum r2 = Sum <*  (q . i) * (RP . 1)*> + (q . (i+1)) * (RP.0)
      by RLVECT_1:44;
    then p.(i+1)*y = ((q . i)  + (q . (i+1)) * (-a))*y
      by A2,A6,A15,A22,RLVECT_1:44;
    then
A27:  p.(i+1)*y + - (q . i)*y  = (q . i)*y  +
    (q . (i+1)) * (-a)*y + - (q . i)*y by VECTSP_1:def 2
    .= (q . (i+1)) * (-a)*y + ((q . i)*y   + - (q . i)*y) by RLVECT_1:def 3
    .= (q . (i+1)) * (-a)*y + (0.R) by RLVECT_1:5
    .= (q . (i+1)) * ((-a)*y) by GROUP_1:def 3
    .= (q . (i+1)) * (-a*y) by VECTSP_1:8
    .= (q . (i+1)) * (-1.R) by A4,A3,C0SP1:def 3
    .= - (q . (i+1)) * (1.R) by VECTSP_1:8
    .= - (q . (i+1));
    (q . i)*y =  qi*ys by FIELD_6:16;
    then
A28: -(q . i)*y =  -qi*ys by FIELD_6:17;
    p.(i+1)*y = pi1*ys by FIELD_6:16;
    then p.(i+1)*y + - (q . i)*y = pi1*ys+ -qi*ys by A28, FIELD_6:15;
    then -(p.(i+1)*y + - (q . i)*y) = - (pi1*ys+ -qi*ys) by FIELD_6:17;
    hence thesis by A27;
  end;
A29: for i being Nat holds P[i] from NAT_1:sch 2(A8,A13);
A30:dom q=NAT by FUNCT_2:def 1;
  rng q c= the carrier of S
  proof
    let y be object;
    assume y in rng q;
    then consider x be object such that
A31:   x in dom q & q.x=y by FUNCT_1:def 3;
    reconsider x as Nat by A31;
    thus thesis by A31,A29;
  end;
  then reconsider qs = q as sequence of S by A30,FUNCT_2:2;
  qs is finite-Support
  proof
    0. R = 0. S1 by C0SP1:def 3;
    then ex n being Nat st for i being Nat st i >= n holds qs.i = 0. S1
      by ALGSEQ_1:def 1;
    hence thesis by ALGSEQ_1:def 1;
  end;
  hence thesis;
end;

reserve L for unital add-associative right_zeroed right_complementable
  distributive non empty doubleLoopStr;

definition
  let L;
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence;
  func rpoly(f,z) -> FinSequence of the carrier of Polynom-Ring L means :Def1:
    len it = len f &
    for i being Nat st 1 <= i <= len f holds it.i = rpoly(f/.i,z/.i);
  existence
  proof
    defpred P[object,object] means $2 = rpoly(f/.$1,z/.$1);
A1:    for i be Nat st i in Seg len f
      ex x being Element of the carrier of Polynom-Ring L st P[i,x]
    proof
      let i be Nat such that i in Seg len f;
      rpoly(f/.i,z/.i) in the carrier of Polynom-Ring L by POLYNOM3:def 10;
      hence thesis;
    end;
    consider p be FinSequence of the carrier of Polynom-Ring L such that
A2:   dom p = Seg len f &
      for i be Nat st i in Seg len f holds P[i,p.i] from FINSEQ_1:sch 5(A1);
    take p;
    thus len p = len f by A2,FINSEQ_1:def 3;
    let i be Nat such that
A3: 1 <= i <= len f;
    i in Seg len f by A3;
    hence thesis by A2;
  end;
  uniqueness
  proof
    let it1,it2 be FinSequence of the carrier of Polynom-Ring L such that
A4:   len it1 = len f &
    for i being Nat st 1 <= i <= len f holds it1.i = rpoly(f/.i,z /. i) and
A5: len it2 = len f &
    for i being Nat st 1 <= i <= len f holds it2.i = rpoly(f/.i,z /. i);
    now let i be Nat such that
A6:   1 <= i & i <= len it1;
      thus it1.i =  rpoly(f/.i,z /. i) by A6,A4
      .= it2.i by A6,A4,A5;
    end;
    hence thesis by A4,A5,FINSEQ_1:14;
  end;
end;

theorem Th43:
  for z1,z2 being FinSequence of the carrier of L
    for f1,f2 being NAT-valued FinSequence st
      len f1 = len z1 & len f2 <= len z2
    holds rpoly(f1^f2,z1^z2) = rpoly(f1,z1)^rpoly(f2,z2)
proof
  let z1,z2 be FinSequence of the carrier of L;
  let f1,f2 be  NAT-valued FinSequence such that
A1:len f1 = len z1 & len f2 <= len z2;
A2:  len rpoly(f1^f2,z1^z2) = len (f1^f2) = len f1+len f2 &
  len (rpoly(f1,z1)^rpoly(f2,z2)) =
    len rpoly(f1,z1)+len rpoly(f2,z2) by Def1,FINSEQ_1:22;
A3:len rpoly(f1,z1) = len f1 & len rpoly(f2,z2) = len f2 by Def1;
  for i being Nat st 1 <= i <= len rpoly(f1^f2,z1^z2) holds
  rpoly(f1^f2,z1^z2).i = (rpoly(f1,z1)^rpoly(f2,z2)).i
  proof
    let i be Nat such that
A4: 1 <= i <= len rpoly(f1^f2,z1^z2);
A5: len f1+len f2 <= len z1+len z2 = len (z1^z2)
    by A1,FINSEQ_1:22,XREAL_1:6;
    then i <= len (z1^z2) by A2,A4,XXREAL_0:2;
    then i in dom (f1^f2) & i in dom (z1^z2) by A2,A4,FINSEQ_3:25;
    then
A6:(f1^f2)/.i= (f1^f2).i & (z1^z2)/.i = (z1^z2).i by PARTFUN1:def 6;
    per cases;
    suppose
A7:   i <=len f1;
      then
A8:   i in dom f1 & i in dom z1 & i in dom rpoly(f1,z1)
        by A1,A3,A4,FINSEQ_3:25;
      then
A9:   (rpoly(f1,z1)^rpoly(f2,z2)).i = rpoly(f1,z1).i
      by FINSEQ_1:def 7
      .= rpoly(f1/.i,z1/.i) by A4,A7,Def1;
      f1/.i = f1.i = (f1^f2).i & z1/.i = z1.i = (z1^z2).i
      by A8,PARTFUN1:def 6,FINSEQ_1:def 7;
      hence thesis by A6,A2,A4,Def1,A9;
    end;
    suppose
A10:  i > len f1;
      then reconsider I=i-len f1 as Nat by NAT_1:21;
      I+len f1 <= len f1+len f2 & I<>0 by A2,A10,A4;
      then
A11:  1<=I <= len f2 by XREAL_1:6,NAT_1:14;
      then I <= len z2 by A1,XXREAL_0:2;
      then
A12:  I in dom f2 & I in dom z2 by A11,FINSEQ_3:25;
A13:  (rpoly(f1,z1)^rpoly(f2,z2)).i = rpoly(f2,z2).I
        by A2,A3,A10,A4,FINSEQ_1:24
        .= rpoly(f2/.I,z2/.I) by A11,Def1;
      len z1 < i <= len (z1^z2) by A1,A10,A2,A4,A5,XXREAL_0:2;
      then f2/.I = f2.I = (f1^f2).i & z2/.I = z2.I = (z1^z2).i
        by A1,A2,A12,A4,PARTFUN1:def 6,FINSEQ_1:24;
      hence thesis by A6,A2,A4,Def1,A13;
    end;
  end;
  hence thesis by A2,A3,FINSEQ_1:14;
end;

theorem Th44:
  for z being Element of the carrier of L, k being Element of NAT
    holds rpoly(<*k*>,<*z*>) = <*rpoly(k,z)*>
proof
  let z be Element of the carrier of L,
  k be Element of NAT;
A1:len rpoly(<*k*>,<*z*>) = len <*k*> = 1 by Def1,FINSEQ_1:40;
  1 in Seg 1;
  then 1 in dom <*k*> & 1 in dom <*z*> by FINSEQ_1:38;
  then <*k*>/.1 = <*k*>.1 & <*z*>/.1 = <*z*>.1 by PARTFUN1:def 6;
  then rpoly(<*k*>,<*z*>).1 = rpoly(k,z) by A1,Def1;
  hence thesis by A1,FINSEQ_1:40;
end;

theorem
  for z1,z2 being FinSequence of the carrier of L
    for f being NAT-valued FinSequence st
       len f <= len z1 & len f <= len z2 & z1|len f = z2|len f
  holds rpoly(f,z1) = rpoly(f,z2)
proof
  let z1,z2 be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence such that
A1: len f <= len z1 & len f <= len z2 & z1|len f = z2|len f;
A2:len rpoly(f,z1) = len f = len rpoly(f,z2) by Def1;
  for i being Nat st 1 <= i <= len f holds rpoly(f,z1).i = rpoly(f,z2).i
  proof
    let i be Nat such that
A3: 1 <= i <= len f;
    len (z1|len f) = len f = len (z2|len f) by A1,FINSEQ_1:59;
    then i in dom (z1|len f) c= dom z1 &
    i in dom (z2|len f) c= dom z2 by A3,FINSEQ_3:25,RELAT_1:60;
    then  (z1|len f).i = z1.i = z1/.i &
    (z2|len f).i = z2.i = z2/.i by PARTFUN1:def 6, FUNCT_1:47;
    hence rpoly(f,z1).i = rpoly(f/.i,z2/.i) by A1,A3,Def1
    .= rpoly(f,z2).i by A3,Def1;
  end;
  hence thesis by A2,FINSEQ_1:14;
end;

theorem Th46:
  for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence
    for n being Nat st n < len f holds
  rpoly(f| (n+1),z) = rpoly(f|n,z) ^ <*rpoly(f/.(n+1),z/.(n+1))*>
proof
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence;
  let n be Nat such that
A1:n < len f;
  n+1 <= len f by A1,NAT_1:13;
  then
A2: len rpoly(f| (n+1),z) = len (f| (n+1)) = n+1 by FINSEQ_1:59,Def1;
A3:len rpoly(f|n,z) = len (f|n) = n by A1,FINSEQ_1:59,Def1;
  then
A4:len (rpoly(f|n,z) ^ <*rpoly(f/.(n+1),z/.(n+1))*>) = n+1 by FINSEQ_2:16;
  for i being Nat st 1 <= i <= n+1 holds
  rpoly(f| (n+1),z).i = (rpoly(f|n,z) ^ <*rpoly(f/.(n+1),z/.(n+1))*>).i
  proof
    let i be Nat such that
A5:   1 <= i <= n+1;
    i in dom (f| (n+1)) by A5,A2,FINSEQ_3:25;
    then
A6: (f| (n+1))/.i = (f| (n+1)).i = f.i & i in dom f
      by RELAT_1:57,FUNCT_1:47,PARTFUN1:def 6;
    then
A7: f.i = f/.i by PARTFUN1:def 6;
A8: rpoly(f| (n+1),z).i = rpoly((f| (n+1))/.i,z/.i) by A5,A2,Def1;
    per cases by A5,NAT_1:8;
    suppose i = n+1;
      hence thesis by A6,A7,A5,A2,Def1,A3;
    end;
    suppose
A9:   i <= n;
      then i in dom (f| n) by A5,A3,FINSEQ_3:25;
      then
A10:  (f|n)/.i = (f| n).i = f.i by FUNCT_1:47,PARTFUN1:def 6;
      (rpoly(f|n,z) ^ <*rpoly(f/.(n+1),z/.(n+1))*>).i = rpoly(f|n,z).i
      by A5,A3,A9,FINSEQ_1:64;
      hence thesis by A5,A6,A8,A10,A3,A9,Def1;
    end;
  end;
  hence thesis by A2,A4,FINSEQ_1:14;
end;

theorem Th47:
  for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence st len f=len z
    for p being Permutation of dom f
    for zp being FinSequence of the carrier of L st zp=z*p
  holds rpoly(f*p,zp) = rpoly(f,z)*p
proof
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence such that
A1: len f=len z;
  let p be Permutation of dom f;
  let zp be FinSequence of the carrier of L such that A2:zp=z*p;
A3:dom (f*p) =dom f by NEWTON04:9;
  len rpoly(f*p,zp) = len (f*p) by Def1;
  then
A4:dom rpoly(f*p,zp) = dom (f*p) by FINSEQ_3:29;
A5:len rpoly(f,z) = len f by Def1;
  then dom rpoly(f,z) = dom f by FINSEQ_3:29;
  then
A6:dom (rpoly(f,z)*p) = dom f by NEWTON04:9;
  for x being object st x in dom f holds rpoly(f*p,zp).x = (rpoly(f,z)*p).x
  proof
    let x be object such that
A7: x in dom f;
    reconsider i=x as Nat by A7;
    1 <= i <= len f & i <= len (f*p) by A7,A3,FINSEQ_3:25;
    then
A8: rpoly(f*p,zp).x = rpoly((f*p)/.i,zp/.i) by Def1;
A9: (rpoly(f,z)*p).x = rpoly(f,z).(p.x) & p.x in dom  rpoly(f,z)
    by A7,A6,FUNCT_1:11,12;
    then 1<= p.x <= len f by A5,FINSEQ_3:25;
    then
A10:rpoly(f,z).(p.x) = rpoly(f/.(p.x),z/.(p.x)) by Def1;
A11:(f*p)/.i = (f*p).i & (f*p).i = f.(p.i) & p.x in dom f
      by A7,A3,PARTFUN1:def 6,FUNCT_1:11,12;
    then
A12:f/.(p.x) = f.(p.x) by PARTFUN1:def 6;
A13:dom f = dom z by A1,FINSEQ_3:29;
    then dom zp = dom z by A2, NEWTON04:9;
    then zp/.i = zp.i & zp.i = z.(p.i) & p.i in dom z by A2,A7,
    A13,PARTFUN1:def 6,FUNCT_1:11,12;
    hence thesis by A8,A9,A10,A11,A12,PARTFUN1:def 6;
  end;
  hence thesis by A3,A4,A6,FUNCT_1:2;
end;

theorem Th48:
  for L being comRing
    for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence st len f=len z
    for p being Permutation of dom f
    for zp being FinSequence of the carrier of L st zp=z*p
  holds Product rpoly(f,z) = Product rpoly(f*p,zp)
proof
  let L be comRing;
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence such that
A1: len f=len z;
  let p be Permutation of dom f;
  let zp be FinSequence of the carrier of L such that
A2: zp=z*p;
  len f = len rpoly(f,z) by Def1;
  then
A3:dom f = dom rpoly(f,z) by FINSEQ_3:29;
  rpoly(f*p,zp) = rpoly(f,z)*p by A1,A2,Th47;
  hence thesis by A3,UPROOTS:16;
end;

theorem Th49:
  for L being non degenerated domRing-like Ring
    for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence
  holds deg ~Product rpoly(f,z) = Sum f
proof
  let L be non degenerated domRing-like Ring;
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence;
  defpred P[Nat] means $1 <= len f implies ~Product rpoly(f|$1,z)<>0_.L &
    deg ~Product rpoly(f|$1,z) = Sum (f|$1);
  len rpoly(f|0,z) = len (f|0) = 0 by Def1;
  then rpoly(f|0,z)= <*>the carrier of Polynom-Ring L;
  then
A1:Product rpoly(f|0,z) = 1_ Polynom-Ring L by GROUP_4:8;
  len 1_.L = 1 by POLYNOM4:4;
  then
A2: deg 1_. L = 1-1 by HURWITZ:def 2;
A3:P[0] by A1,A2,POLYNOM3:37;
A4:for i being Nat st P[i] holds P[i+1]
  proof
    let i be Nat such that
A5: P[i];
    set i1=i+1;
A6: ~Product <* @ rpoly(f/.i1,z/.i1)*> = rpoly(f/.i1,z/.i1) by GROUP_4:9;
    assume
A7: i1 <= len f;
A8: rpoly(f|i1,z) = rpoly(f|i,z) ^ <*@ rpoly(f/.i1,z/.i1)*>
    by Th46,A7,NAT_1:13;
A9: ~Product rpoly(f|i1,z) = (Product rpoly(f|i,z)) *
    (Product <* @ rpoly(f/.i1,z/.i1)*>) by A8,GROUP_4:5
    .= ~(Product rpoly(f|i,z)) *'  rpoly(f/.i1,z/.i1) by A6,POLYNOM3:def 10;
    then
A10:deg ~Product rpoly(f|i1,z) = deg ~(Product rpoly(f|i,z)) +
    deg rpoly(f/.i1,z/.i1) by A5,A7,NAT_1:13,HURWITZ:23;
A11: i1 in dom f by A7,FINSEQ_3:25,NAT_1:11;
    then
A12:f|i1 = (f|i)^<*f.i1*> by FINSEQ_5:10;
    deg rpoly(f/.i1,z/.i1) = f/.i1 = f.i1 by A11,HURWITZ:27,PARTFUN1:def 6;
    hence thesis by A9,UPROOTS:21,A7,NAT_1:13,A5,A12,A10,RVSUM_1:74;
  end;
  for i being Nat holds P[i] from NAT_1:sch 2(A3,A4);
  then P[len f];
  hence thesis;
end;

theorem Th50:
  for L being non degenerated comRing
    for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence
    for x being Element of the carrier of L
  ex e being FinSequence of the carrier of L st
      eval(~Product rpoly(f,z),x) = Product e &
      len e = len f &
      for i st 1<=i<=len e holds e.i = eval(rpoly(f/.i,z/.i),x)
proof
  let L be non degenerated comRing;
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence;
  let x be Element of the carrier of L;
  defpred P[Nat] means $1 <= len f implies
  ex e being FinSequence of the carrier of L st
    eval(~Product rpoly(f|$1,z),x) = Product e &
    len e = $1 &
      for i being Nat st 1<=i<=len e holds e.i = eval(rpoly(f/.i,z/.i),x);
A1:P[0]
  proof
    assume 0 <=len f;
    take e = <*>the carrier of L;
    len rpoly(f|0,z) = len (f|0) = 0 by Def1;
    then rpoly(f|0,z)= <*>the carrier of Polynom-Ring L;
    then Product rpoly(f|0,z) = 1_ Polynom-Ring L by GROUP_4:8;
    then ~Product rpoly(f|0,z) = 1_. L by POLYNOM3:37;
    then eval(~Product rpoly(f|0,z),x) = 1_L by POLYNOM4:18;
    then eval(~Product rpoly(f|0,z),x) = Product e by GROUP_4:8;
    hence thesis;
  end;
A2:for i being Nat st P[i] holds P[i+1]
  proof
    let i be Nat such that
A3:P[i];
    set i1=i+1;
    assume
A4: i1 <= len f;
    then consider e be FinSequence of the carrier of L such that
A5:      eval(~Product rpoly(f|i,z),x) = Product e and
A6:      len e = i and
A7:      for i being Nat st 1<=i<=len e holds e.i = eval(rpoly(f/.i,z/.i),x)
    by A3,NAT_1:13;
    set E=eval(rpoly(f/.i1,z/.i1),x);
    take e1= e^<*E*>;
A8: ~Product <* @ rpoly(f/.i1,z/.i1)*> = rpoly(f/.i1,z/.i1) by GROUP_4:9;
A9: rpoly(f|i1,z) = rpoly(f|i,z) ^ <*@ rpoly(f/.i1,z/.i1)*>
    by A4,Th46,NAT_1:13;
    ~Product rpoly(f|i1,z) = (Product rpoly(f|i,z)) *
    (Product <* @ rpoly(f/.i1,z/.i1)*>) by A9,GROUP_4:5
    .= ~(Product rpoly(f|i,z)) *'  rpoly(f/.i1,z/.i1) by A8,POLYNOM3:def 10;
    hence eval (~Product rpoly(f|i1,z),x) = Product e * E by A5,POLYNOM4:24
    .= Product e1 by GROUP_4:6;
    thus
A10:len e1 = i1 by A6,FINSEQ_2:16;
    let j be Nat such that A11: 1<=j<=len e1;
    per cases by A11,XXREAL_0:1;
    suppose j = len e1;
      hence e1.j = eval(rpoly(f/.j,z/.j),x) by A10,A6;
    end;
    suppose j < len e1;
      then
A12:  j <= i by A10,NAT_1:13;
      then j in dom e by A11,A6,FINSEQ_3:25;
      then e1.j = e.j by FINSEQ_1:def 7;
      hence thesis by A12,A11,A6,A7;
    end;
  end;
  for i being Nat holds P[i] from NAT_1:sch 2(A1,A2);
  then P[len f];
  hence thesis;
end;

theorem Th51:
  for L being non degenerated comRing
    for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence
    for i st i in dom f & f.i <> 0
  holds z/.i is_a_root_of ~Product rpoly(f,z)
proof
  let L be non degenerated comRing;
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence;
  let i be Nat such that
A1:i in dom f & f.i <> 0;
  consider e be FinSequence of the carrier of L such that
A2:  eval(~Product rpoly(f,z),z/.i) = Product e and
A3:  len e = len f and
A4:  for j being Nat st 1<=j<=len e
       holds e.j = eval(rpoly(f/.j,z/.j),z/.i) by Th50;
A5:eval(rpoly(f/.i,z/.i),z/.i) = 0.L
  proof
A6: eval(rpoly(1,z/.i),z/.i) = z/.i - z/.i by HURWITZ:29;
    then
A7: eval(rpoly(1,z/.i),z/.i) = 0.L by VECTSP_1:19;
A8: f.i = f/.i by PARTFUN1:def 6,A1;
    f.i >= 1 by A1,NAT_1:14;
    then per cases by A8,XXREAL_0:1;
    suppose f/.i= 1;
      hence thesis by A6,VECTSP_1:19;
    end;
    suppose f/.i> 1;
      then rpoly(1,z/.i) *' qpoly(f/.i,z/.i)= rpoly(f/.i,z/.i)
      by HURWITZ:32;
      then eval(rpoly(f/.i,z/.i),z/.i) =
      eval(rpoly(1,z/.i),z/.i)* eval(qpoly(f/.i,z/.i),z/.i) by POLYNOM4:24;
      hence thesis by A7;
    end;
  end;
  1<= i<= len e by A1,A3,FINSEQ_3:25;
  then
A9:e.i = eval(rpoly(f/.i,z/.i),z/.i) by A4;
A10:i in dom e by A1,A3,FINSEQ_3:29;
  then e/.i = 0.L by A9,A5,PARTFUN1:def 6;
  hence thesis by A2,POLYNOM5:def 7,A10,POLYNOM2:4;
end;

theorem Th52:
 for L being domRing
  for z being FinSequence of the carrier of L
    for f being NAT-valued FinSequence
      for x being Element of the carrier of L
        holds
  x is_a_root_of ~Product rpoly(f,z) iff
       ex i being Nat st i in dom f & x is_a_root_of rpoly(f/.i,z/.i)
proof
  let L be domRing;
  let z be FinSequence of the carrier of L;
  let f be NAT-valued FinSequence;
  let x be Element of the carrier of L;
  consider e be FinSequence of the carrier of L such that
A1:    eval(~Product rpoly(f,z),x) = Product e and
A2:    len e = len f and
A3:    for i being Nat st 1<=i<=len e holds e.i = eval(rpoly(f/.i,z/.i),x)
   by Th50;
A4:dom e = dom f by A2,FINSEQ_3:29;
  thus x is_a_root_of ~Product rpoly(f,z) implies
       ex i being Nat st i in dom f & x is_a_root_of rpoly(f/.i,z/.i)
  proof
    assume x is_a_root_of ~Product rpoly(f,z);
    then consider i be Nat such that
A5: i in dom e & e.i = 0.L by A1,RING_2:2,POLYNOM5:def 7;
    1<=i <=len e by A5,FINSEQ_3:25;
    then e.i = eval(rpoly(f/.i,z/.i),x) by A3;
    hence thesis by A4,A5,POLYNOM5:def 7;
  end;
  given i be Nat such that
A6:i in dom f & x is_a_root_of rpoly(f/.i,z/.i);
  1<=i <=len e by A6,A2,FINSEQ_3:25;
  then
A7: e.i = eval(rpoly(f/.i,z/.i),x) by A3;
  Product e = 0.L by A7,A4,A6,RING_2:2,POLYNOM5:def 7;
  hence thesis by A1,POLYNOM5:def 7;
end;

theorem Th53:
  for L being domRing
    for z being FinSequence of the carrier of L
  holds Roots ~Product rpoly(len z |-> 1,z) = rng z
proof
  let L be  domRing;
  let z be FinSequence of the carrier of L;
A1: Roots ~Product rpoly(len z |-> 1,z) c= rng z
  proof
    let y be object;
    assume
A2: y in Roots ~Product rpoly(len z |-> 1,z);
    then reconsider y as Element of L;
    y is_a_root_of ~Product rpoly(len z |-> 1,z) by A2,POLYNOM5:def 10;
    then consider i be Nat such that
A3: i in dom (len z |-> 1) & y is_a_root_of rpoly((len z |-> 1)/.i,z/.i)
    by Th52;
A4:len z |-> 1 = Seg len z --> 1 by FINSEQ_2:def 2;
    then (len z |-> 1)/.i = (len z |-> 1).i =1
      by A3,PARTFUN1:def 6,FINSEQ_2:57;
    then y - z/.i  = eval(rpoly((len z |-> 1)/.i,z/.i),y) =0.L
      by HURWITZ:29, A3,POLYNOM5:def 7;
    then
A5:y = z/.i by VECTSP_1:19;
A6: i in dom z by A3,A4,FINSEQ_1:def 3;
    then z/.i = z.i by PARTFUN1:def 6;
    hence thesis by A5,A6,FUNCT_1:def 3;
  end;
  rng z c= Roots ~Product rpoly(len z |-> 1,z)
  proof
    let y be object;
    assume y in rng z;
    then consider i be object such that
A7: i in dom z & z.i = y by FUNCT_1:def 3;
    reconsider i as Nat by A7;
A8: len z |-> 1 = Seg len z --> 1 by FINSEQ_2:def 2;
    i in Seg len z by A7,FINSEQ_1:def 3;
    then i in dom (len z |-> 1) & (len z |-> 1).i = 1 by A8,FINSEQ_2:57;
    then z/.i is_a_root_of ~Product rpoly(len z |-> 1,z) by Th51;
    then z/.i in Roots ~Product rpoly(len z |-> 1,z) by POLYNOM5:def 10;
    hence thesis by A7,PARTFUN1:def 6;
  end;
  hence thesis by A1,XBOOLE_0:def 10;
end;

definition
  let F be Field;
  let X be finite Subset of F, x be Element of F;
  func LagBPoly(X,x) -> Polynomial of F means :Def2:
    for z be one-to-one FinSequence of the carrier of F st rng z = X
      holds it = eval(~Product rpoly(len z|-> 1,z),x)" *
      ~Product rpoly(len z|-> 1,z);
  existence
  proof
A1: rng canFS X =X by FUNCT_2:def 3;
    then reconsider c = canFS X as one-to-one FinSequence of the carrier of F
      by FINSEQ_1:def 4;
    take L=eval(~Product rpoly(len c|-> 1,c),x)" *~Product rpoly(len c|-> 1,c);
    let z be one-to-one FinSequence of the carrier of F such that
A2: rng z = X;
    consider P be Permutation of dom z such that
A3: c = z*P & dom P = dom z & rng P = dom z by A1,A2,BHSP_5:1;
    dom c = dom z by A3,RELAT_1:27;
    then
A4: len c = len z by FINSEQ_3:29;
A5: len z = len (len z|-> 1);
    then dom z = dom (len z|-> 1) by FINSEQ_3:29;
    then reconsider PP=P as Permutation of dom (len z|-> 1);
A6: Product rpoly(len z|-> 1,z) = Product rpoly((len z|-> 1)*PP,c)
    by A3,A5,Th48;
A7: dom ((len z|-> 1)*PP) = dom PP by A3,RELAT_1:27;
    for x be object st x in dom ((len z|-> 1)*PP) holds ((len z|-> 1)*PP).x=1
    proof
      let x be object such that
A8:   x in dom ((len z|-> 1)*PP);
      PP.x in dom (len z|-> 1) by A8,FUNCT_1:11;
      then PP.x in Seg len z by A5,FINSEQ_1:def 3;
      then (len z|-> 1).(PP.x) = 1 by FINSEQ_2:57;
      hence thesis by A8,FUNCT_1:12;
    end;
    then (len z|-> 1)*PP = (dom z) --> 1 by A7,A3,FUNCOP_1:11;
    then (len z|-> 1)*PP = (Seg len z) --> 1 by FINSEQ_1:def 3;
    then (len z|-> 1)*PP = len z |-> 1 by FINSEQ_2:def 2;
    hence thesis by A6,A4;
  end;
  uniqueness
  proof
    let L1,L2 be Polynomial of F such that
A9: for z be one-to-one FinSequence of the carrier of F st rng z = X
      holds L1 = eval(~Product rpoly(len z|-> 1,z),x)" *
       ~Product rpoly(len z|-> 1,z) and
A10:for z be one-to-one FinSequence of the carrier of F st rng z = X
      holds L2 = eval(~Product rpoly(len z|-> 1,z),x)" *
       ~Product rpoly(len z|-> 1,z);
A11:rng canFS X =X by FUNCT_2:def 3;
    then reconsider z = canFS X as one-to-one FinSequence of the carrier of F
      by FINSEQ_1:def 4;
    L1 = eval(~Product rpoly(len z|-> 1,z),x)" * ~Product rpoly(len z|-> 1,z)
      by A9,A11;
    hence thesis by A10,A11;
  end;
end;

reserve F for Field;

theorem Th54:
    for X being finite Subset of F,
        x being Element of F st not x in X holds
      Roots LagBPoly(X,x) = X & eval(LagBPoly(X,x),x) = 1.F &
   deg LagBPoly(X,x) = card X
proof
  let X be finite Subset of F, x be Element of F;
  assume
A1:not x in X;
A2:rng canFS X =X by FUNCT_2:def 3;
  then reconsider z = canFS X as one-to-one FinSequence of the carrier of F
    by FINSEQ_1:def 4;
A3:LagBPoly(X,x) = eval(~Product rpoly(len z|-> 1,z),x)" *
  ~Product rpoly(len z|-> 1,z) by A2,Def2;
  then
A4: eval(LagBPoly(X,x),x) = eval(~Product rpoly(len z|-> 1,z),x)" *
    eval(~Product rpoly(len z|-> 1,z),x) by RING_5:7;
A5:Roots ~Product rpoly(len z|-> 1,z) = rng z by Th53;
  then not x is_a_root_of ~Product rpoly(len z|-> 1,z)
    by A1,A2,POLYNOM5:def 10;
  then
A6: eval(~Product rpoly(len z|-> 1,z),x)<>0.F by POLYNOM5:def 7;
  then eval(~Product rpoly(len z|-> 1,z),x)" is non zero
    by STRUCT_0:def 12,VECTSP_1:25;
  hence Roots LagBPoly(X,x) = X & eval(LagBPoly(X,x),x) = 1.F
    by A5,A2,A6,A4,VECTSP_1:def 10,A3,RING_5:19;
  eval(~Product rpoly(len z|-> 1,z),x)" is non zero
    by A6,STRUCT_0:def 12,VECTSP_1:25;
  then deg LagBPoly(X,x) = deg ~Product rpoly(len z|-> 1,z) by A3,RING_5:4;
  then deg LagBPoly(X,x) = Sum (len z|-> 1) by Th49;
  then deg LagBPoly(X,x) = (len z) * 1 by RVSUM_1:80;
  hence deg LagBPoly(X,x) = card X by FINSEQ_1:93;
end;

theorem
  for x,y be Element of F holds
      LagBPoly({y},x) =  (x-y)" * rpoly(1,y)
proof
  let x,y be Element of F;
A1:rng canFS {y} ={y} by FUNCT_2:def 3;
  then reconsider z = canFS {y} as one-to-one FinSequence of the carrier of F
  by FINSEQ_1:def 4;
A2:z = <*y*> by FINSEQ_1:94;
  then len z = 1 by FINSEQ_1:39;
  then len z|-> 1 = <*1*> by FINSEQ_2:59;
  then rpoly(len z|-> 1,z) = <*@rpoly(1,y)*> by A2,Th44;
  then
A3:Product rpoly(len z|-> 1,z) = @rpoly(1,y) by GROUP_4:9;
  thus LagBPoly({y},x) = eval(~Product rpoly(len z|-> 1,z),x)" *
  ~Product rpoly(len z|-> 1,z) by A1,Def2
  .= (x-y)" * rpoly(1,y) by A3,HURWITZ:29;
end;

theorem
  for X1,X2 being finite Subset of F,
     x being Element of F st not x in X1 & not x in X2 & X1 misses X2 holds
  LagBPoly(X1,x) *' LagBPoly(X2,x) = LagBPoly(X1\/X2,x)
proof
  let X1,X2 be finite Subset of F,x be Element of F such that
A1: not x in X1 & not x in X2 & X1 misses X2;
A2:rng canFS X1 =X1 & rng canFS X2 =X2 by FUNCT_2:def 3;
  then reconsider z1 = canFS X1,z2=canFS X2 as one-to-one FinSequence of
  the carrier of F by FINSEQ_1:def 4;
  reconsider z12 = z1^z2 as one-to-one FinSequence of the carrier of F
  by A1,A2,FINSEQ_3:91;
A3:rng z12 = X1\/X2 by A2,FINSEQ_1:31;
  set rP1= rpoly(len z1|-> 1,z1),rP2 =rpoly(len z2|-> 1,z2),
  rP12=rpoly(len (z12) |-> 1,z12);
  Roots ~Product rP1 = rng z1 by Th53;
  then not x is_a_root_of ~Product rP1 by A1,A2,POLYNOM5:def 10;
  then
A4: eval(~Product rP1,x)<>0.F by POLYNOM5:def 7;
  Roots ~Product rP2 = rng z2 by Th53;
  then not x is_a_root_of ~Product rP2 by A1,A2,POLYNOM5:def 10;
  then eval(~Product rP2,x)<>0.F by POLYNOM5:def 7;
  then
A5:(eval(~Product rP1,x)" * eval(~Product rP2,x)") =
  (eval(~Product rP2,x) * eval(~Product rP1,x))" by A4,VECTSP_2:11
  .= eval(~(Product rP1) *' ~(Product rP2),x)" by POLYNOM4:24;
A6: (len z1|-> 1)^(len z2|-> 1) = (len z1+len z2) |-> 1 by FINSEQ_2:123
  .= len (z12) |-> 1 by FINSEQ_1:22;
  len (len z1|-> 1) = len z1 & len (len z2|-> 1) = len z2;
  then rpoly(len (z1^z2) |-> 1,z12) = rpoly(len z1|-> 1,z1)^
  rpoly(len z2|-> 1,z2) by A6,Th43;
  then
A7:~Product rP12 = ~(Product rP1 * Product rP2 ) by GROUP_4:5
   .=  ~(Product rP1) *' ~(Product rP2) by POLYNOM3:def 10;
  LagBPoly(X2,x) = eval(~Product rP2,x)" * ~Product rP2 by A2,Def2;
  hence
  LagBPoly(X1,x) *' LagBPoly(X2,x) = (eval(~Product rP1,x)" * ~Product rP1) *'
  (eval(~Product rP2,x)" * ~Product rP2) by A2,Def2
  .= eval(~Product rP1,x)" * (~Product rP1 *' (eval(~Product rP2,x)" *
  ~Product rP2)) by POLYALG1:10
  .= eval(~Product rP1,x)" * (eval(~Product rP2,x)" * (~Product rP2 *'
  ~Product rP1 )) by POLYALG1:10
  .= (eval(~Product rP1,x)" * eval(~Product rP2,x)") * (~Product rP2 *'
  ~Product rP1 ) by POLYALG1:8
  .= LagBPoly(X1\/X2,x) by A5,A3,A7,Def2;
end;

definition
  let F be Field;
  let x,y be FinSequence of the carrier of F;
  func LagPoly(x,y) -> Polynomial of F means :Def3:
     ex L be FinSequence of the carrier of Polynom-Ring F st
       it = Sum L & len L = len x &
       for i being Nat st 1 <= i <= len x holds L.i =  y/.i *
       LagBPoly((rng x)\{x/.i},x/.i);
  existence
  proof
    deffunc L(object)=y/.$1 * LagBPoly((rng x)\{x/.$1},x/.$1);
    consider p be FinSequence such that
A1:   len p = len x & for k being Nat st k in dom p holds p.k=L(k)
    from FINSEQ_1:sch 2;
    rng p c= the carrier of Polynom-Ring F
    proof
      let y be object;
      assume y in rng p;
      then consider i be object such that
A2:   i in dom p & p.i = y by FUNCT_1:def 3;
      p.i = @L(i) by A2,A1;
      hence thesis by A2;
    end;
    then reconsider p as FinSequence of the carrier of Polynom-Ring F
    by FINSEQ_1:def 4;
    take IT=~(Sum p),p;
    thus thesis by A1,FINSEQ_3:25;
  end;
  uniqueness
  proof
    let IT1,IT2 be Polynomial of F;
    given L1 be FinSequence of the carrier of Polynom-Ring F such that
A3: IT1 = Sum L1 & len L1 = len x and
A4: for i being Nat st 1 <= i <= len x holds L1.i =
    y/.i * LagBPoly((rng x)\{x/.i},x/.i);
    given L2 be FinSequence of the carrier of Polynom-Ring F such that
A5: IT2 = Sum L2 & len L2 = len x and
A6: for i being Nat st 1 <= i <= len x holds L2.i =
    y/.i * LagBPoly((rng x)\{x/.i},x/.i);
    now let i be Nat;
      assume
A7:   1 <= i <= len x;
      hence L1.i = y/.i * LagBPoly((rng x)\{x/.i},x/.i) by A4
      .= L2.i by A7,A6;
    end;
    hence thesis by A3,A5,FINSEQ_1:14;
  end;
end;

theorem Th57:
  for x,y being FinSequence of the carrier of F
   for i being Nat holds
     (y/.i <>0.F implies
        Roots (y/.i * LagBPoly((rng x)\{x/.i},x/.i)) = (rng x)\{x/.i}) &
      eval(y/.i * LagBPoly((rng x)\{x/.i},x/.i),x/.i) = y/.i &
     (i in dom x & y/.i <>0.F implies
        deg (y/.i * LagBPoly((rng x)\{x/.i},x/.i)) = card rng x - 1)
proof
  let x,y be FinSequence of the carrier of F;
  let i be Nat;
  set Rx=(rng x) \ {x/.i};
  x/.i in {x/.i} by TARSKI:def 1;
  then
A1:not x/.i in Rx by XBOOLE_0:def 5;
  thus  y/.i <>0.F implies Roots (y/.i * LagBPoly(Rx,x/.i)) = Rx
  proof
    assume y/.i<>0.F;
    then y/.i is non zero by STRUCT_0:def 12;
    then Roots (y/.i * LagBPoly(Rx,x/.i)) = Roots LagBPoly(Rx,x/.i)
    by RING_5:19;
    hence thesis by A1,Th54;
  end;
  thus eval(y/.i * LagBPoly(Rx,x/.i),x/.i)
   = y/.i * eval(  LagBPoly(Rx,x/.i),x/.i) by POLYNOM5:30
  .= y/.i * 1.F by A1,Th54
  .= y/.i;
  assume
A2:i in dom x &  y/.i <>0.F;
  then y/.i is non zero by STRUCT_0:def 12;
  then
A3: deg (y/.i * LagBPoly(Rx,x/.i))= deg LagBPoly(Rx,x/.i) by RING_5:4
  .= card Rx by A1,Th54;
  x/.i = x.i in rng x by A2,PARTFUN1:def 6,FUNCT_1:def 3;
  then rng x =  Rx \/{x/.i} by ZFMISC_1:116;
  then card rng x = card Rx +1 by A1,CARD_2:41;
  hence thesis by A3;
end;

theorem
  for x,y being FinSequence of the carrier of F holds
    degree LagPoly(x,y) <= len x - 1
proof
  let x,y being FinSequence of the carrier of F;
  consider L be FinSequence of the carrier of Polynom-Ring F such that
A1:   LagPoly(x,y) = Sum L & len L = len x and
A2:   for i being Nat st 1 <= i <= len x holds
  L.i =  y/.i * LagBPoly((rng x)\{x/.i},x/.i) by Def3;
  consider f be sequence of Polynom-Ring F such that
A3:  Sum L = f.(len L) & f.0 = 0.(Polynom-Ring F) and
A4:  for j being Nat,v be Element of Polynom-Ring F
       st j < len L & v = L.(j + 1) holds f.(j + 1) = f.j + v
     by RLVECT_1:def 12;
  defpred P[Nat] means $1 <= len L implies deg ~(f.$1) <= len x - 1;
  ~(f.0) =  0_.(F) by A3,POLYNOM3:def 10;
  then deg ~(f.0) = 0 - 1 <= len x - 1 by XREAL_1:9,HURWITZ:20;
  then
A5:P[0];
A6:for n st P[n] holds P[n+1]
  proof
    let n be Nat such that
A7: P[n];
    set n1=n+1;
    assume
A8: n1 <= len L;
A9: n1 in dom L & n1 in dom x by A8,A1,NAT_1:11,FINSEQ_3:25;
    then
A10:L.n1 = L/.n1 by PARTFUN1:def 6;
    then f.n1 = f.n + L/.n1 by A8,NAT_1:13,A4;
    then ~(f.n1) = ~(f.n) + ~(L/.n1) by POLYNOM3:def 10;
    then
A11: deg ~(f.n1) <= max(deg ~(f.n),deg ~(L/.n1)) by HURWITZ:22;
A12: L.n1 = y/.n1 * LagBPoly((rng x)\{x/.n1},x/.n1)
      by NAT_1:11,A8,A1,A2;
    deg ~(L/.n1) <= len x -1
    proof
      per cases;
      suppose y/.n1 <>0.F;
        then
A13:      deg ~(L/.n1) = card rng x  -1 by A10,A12,Th57,A9;
        dom x = Seg len x by FINSEQ_1:def 3;
        then card rng x <= card dom x = len x by CARD_2:47;
        hence thesis by A13,XREAL_1:9;
      end;
      suppose y/.n1 = 0.F;
        then L/.n1 = 0_.F by A12,A10,RING_4:8;
        then deg ~(L/.n1) = 0 - 1 <= len x - 1 by XREAL_1:9,HURWITZ:20;
        hence thesis;
      end;
    end;
    then max(deg ~(f.n),deg ~(L/.n1)) <= len x -1
      by A8,NAT_1:13,A7,XXREAL_0:16;
    hence thesis by A11,XXREAL_0:2;
  end;
  for n being Nat holds P[n] from NAT_1:sch 2(A5,A6);
  then P[len L];
  hence thesis by A1,A3;
end;

theorem Th59:
  for x,y being FinSequence of the carrier of F st x is one-to-one
    for i being Nat st i in dom x holds
       eval(LagPoly(x,y),x/.i) = y/.i
proof
  let x,y be FinSequence of the carrier of F such that
A1: x is one-to-one;
  let i be Nat such that
A2:i in dom x;
  consider L be FinSequence of the carrier of Polynom-Ring F such that
A3:   LagPoly(x,y) = Sum L & len L = len x and
A4:   for i being Nat st 1 <= i <= len x holds
  L.i =  y/.i * LagBPoly((rng x)\{x/.i},x/.i) by Def3;
  consider f be sequence of Polynom-Ring F such that
A5: Sum L = f.(len L) & f.0 = 0.(Polynom-Ring F) and
A6: for j being Nat,v be Element of Polynom-Ring F
       st j < len L & v = L.(j + 1) holds f.(j + 1) = f.j + v
    by RLVECT_1:def 12;
A7:1<= i <= len x by A2,FINSEQ_3:25;
A8:x/.i = x.i in rng x by A2,PARTFUN1:def 6,FUNCT_1:def 3;
A9:for n being Nat st n+1 <= len x & n+1 <> i holds
   eval(~(f.n),x/.i) = eval(~(f.(n+1)),x/.i)
  proof
    let n be Nat;
    set n1=n+1;
    assume
A10: n+1 <= len x & n+1 <> i;
    then
A11: n1 in dom L & n1 in dom x by NAT_1:11,A3,FINSEQ_3:25;
    then
A12: L.n1 = L/.n1 & x.n1 = x/.n1 by PARTFUN1:def 6;
    then f.n1 = f.n + L/.n1 by A10,NAT_1:13,A3,A6;
    then ~(f.n1) = ~(f.n) + ~(L/.n1) by POLYNOM3:def 10;
    then
A13: eval(~(f.n1),x/.i) = eval(~(f.n),x/.i)+eval(~(L/.n1),x/.i)
      by POLYNOM4:19;
A14: L.n1 = y/.n1 * LagBPoly((rng x)\{x/.n1},x/.n1) by NAT_1:11,A10,A4;
    eval(~(L/.n1),x/.i) = 0.F
    proof
      per cases;
      suppose y/.n1 <>0.F;
        then
A15:      Roots (~(L/.n1)) = rng x\{x/.n1} by Th57,A14,A12;
        x/.i in rng x\{x/.n1}
        by ZFMISC_1:56,A10,FUNCT_1:def 4,A1,A2,A11,A8,A12;
        then x/.i is_a_root_of ~(L/.n1) by A15,POLYNOM5:def 10;
        hence thesis by POLYNOM5:def 7;
      end;
      suppose y/.n1 = 0.F;
        then L/.n1 = 0_.F by A14,A12,RING_4:8;
        hence thesis by POLYNOM4:17;
      end;
    end;
    hence thesis by A13;
  end;
  defpred P[Nat] means $1 < i implies eval(~(f.$1),x/.i) =0.F;
  0.(Polynom-Ring F)= 0_.(F) by POLYNOM3:def 10;
  then
A16:P[0] by A5,POLYNOM4:17;
A17:for n being Nat st P[n] holds P[n+1] by A9,A7,NAT_1:13,XXREAL_0:2;
A18: for n being Nat holds P[n] from NAT_1:sch 2(A16,A17);
  defpred Q[Nat] means i <= $1 <= len x implies eval(~(f.$1),x/.i) = y/.i;
A19:Q[0] by A2,FINSEQ_3:25;
A20:for n being Nat st Q[n] holds Q[n+1]
  proof
    let n be Nat such that
A21: Q[n];
    set n1=n+1;
    assume
A22: i <= n1 <=len x;
    then per cases by XXREAL_0:1;
    suppose
A23:  i = n1;
      then n < i by NAT_1:13;
      then
A24:  eval(~(f.n),x/.i) =0.F by A18;
      n1 in dom L & n1 in dom x by NAT_1:11,A3,A22,FINSEQ_3:25;
      then
A25:  L.n1 = L/.n1 & x.n1 = x/.n1 by PARTFUN1:def 6;
      then f.n1 = f.n + L/.n1 by A22,NAT_1:13,A3,A6;
      then ~(f.n1) = ~(f.n) + ~(L/.n1) by POLYNOM3:def 10;
      then
A26:  eval(~(f.n1),x/.i) = eval(~(f.n),x/.i)+eval(~(L/.n1),x/.i)
        by POLYNOM4:19;
      L.n1 = y/.i * LagBPoly((rng x)\{x/.i},x/.i)
        by A22,NAT_1:11,A23,A4;
      hence thesis by A26, A24,A25,Th57;
    end;
    suppose i < n1;
      hence thesis by A21,A22,A9,NAT_1:13;
    end;
  end;
  for n being Nat holds Q[n] from NAT_1:sch 2(A19,A20);
  then eval(~(f.(len x)),x/.i) = y/.i by A7;
  hence thesis by A3,A5;
end;

definition
  let F be unital add-associative right_zeroed right_complementable
         distributive non empty doubleLoopStr;
  let z be FinSequence of the carrier of F;
  let i be Nat;
  func LagIPoly(z,i) -> Polynomial of F equals
     Product rpoly(len Del(z,i) |-> 1,Del(z,i));
  coherence
  proof
    ~Product rpoly(len Del(z,i) |-> 1,Del(z,i)) is Polynomial of F;
    hence thesis;
  end;
end;

theorem
  for z being FinSequence of the carrier of L
    for i being Nat st not i in dom z holds
      LagIPoly(z,i) = Product rpoly(len z |-> 1,z)
proof
  let z be FinSequence of the carrier of L;
  let i be Nat;
  assume not i in dom z;
  then Del(z,i) = z by WSIERP_1:def 1;
  hence thesis;
end;

theorem Th61:
  for z being FinSequence
    for i being Nat st z is_one-to-one_at i holds
      rng Del(z,i) = rng z \ {z.i}
proof
  let z be FinSequence;
  let i be Nat such that
A1: z is_one-to-one_at i;
  not z.i in rng Del(z,i)
  proof
    assume z.i in rng Del(z,i);
    then consider x be object such that
A2: x in dom Del(z,i) & Del(z,i).x = z.i by FUNCT_1:def 3;
    reconsider x as Nat by A2;
A3: i in dom z by A1,FINSEQ_4:3;
    then
A4: len z = len Del(z,i)+1 by WSIERP_1:def 1;
A5: 1 <= x <= len Del(z,i) by A2,FINSEQ_3:25;
    then
A6: x < len z by A4,NAT_1:13;
    then 1<= x+1 <= len z by NAT_1:11,13;
    then
A7: x in dom z & x+1 in dom z by A5,A6,FINSEQ_3:25;
    per cases;
    suppose
A8:   x < i;
      then Del(z,i).x = z.x by A3,WSIERP_1:def 1;
      hence thesis by A8,A1,A2,A7,FINSEQ_4:3;
    end;
    suppose
A9:   x >= i;
      then Del(z,i).x = z.(x+1) by A3,WSIERP_1:def 1;
      then x+1 = i by A1,A2,A7,FINSEQ_4:3;
      hence thesis by A9,NAT_1:13;
    end;
  end;
  then
A10:rng Del(z,i) c= (rng z) \{z.i} by FINSEQ_3:106,ZFMISC_1:34;
  (rng z) \{z.i} c= rng Del(z,i)
  proof
    let y be object such that
A11:  y in (rng z) \{z.i};
    consider x be object such that
A12:  x in dom z & z.x = y by A11,FUNCT_1:def 3;
    reconsider x as Nat by A12;
A13:  i in dom z by A1,FINSEQ_4:3;
    then
A14: len z = len Del(z,i)+1 by WSIERP_1:def 1;
A15: 1<= x <= len z by A12,FINSEQ_3:25;
A16: 1<= i <= len z by A13,FINSEQ_3:25;
    x<>i by A11,ZFMISC_1:56,A12;
    then per cases by XXREAL_0:1;
    suppose
A17:  x < i;
      then x < len z by A16,XXREAL_0:2;
      then x <= len Del(z,i) by A14,NAT_1:13;
      then
A18:  x in dom Del(z,i) by A15,FINSEQ_3:25;
      Del(z,i).x = z.x by A17,A13,WSIERP_1:def 1;
      hence thesis by A12,A18,FUNCT_1:def 3;
    end;
    suppose
A19:  x > i;
      then reconsider x1=x-1 as Nat;
      x1+1 > i by A19;
      then
A20:  x1 >= i by NAT_1:13;
      then
A21:  x1 >= 1 by A16,XXREAL_0:2;
      x1+1 <= len Del(z,i)+1 by A13,A15,WSIERP_1:def 1;
      then x1 <= len Del(z,i) by XREAL_1:6;
      then
A22:  x1 in dom Del(z,i) by A21,FINSEQ_3:25;
      Del(z,i).x1 = z.(x1+1) by A13,A20,WSIERP_1:def 1;
      hence thesis by A12,A22,FUNCT_1:def 3;
    end;
  end;
  hence thesis by A10,XBOOLE_0:def 10;
end;

theorem
  for z being FinSequence of the carrier of F
    for i being Nat st i in dom z & z is one-to-one holds
      LagBPoly(rng z \ {z.i}, z/.i) =
        eval(LagIPoly(z,i),z/.i)" * LagIPoly(z,i)
proof
  let z be FinSequence of the carrier of F;
  let i be Nat such that
A1: i in dom z & z is one-to-one;
  reconsider D=Del(z,i) as one-to-one FinSequence of the carrier of F
    by A1,NAT_5:6;
  rng D = rng z \ {z.i} by Th61,A1,FINSEQ_4:4;
  hence LagBPoly(rng z \ {z.i}, z/.i) =
  eval(~Product rpoly(len D|-> 1,D),z/.i)" * LagIPoly(z,i) by Def2
  .= eval(LagIPoly(z,i),z/.i)" * LagIPoly(z,i);
end;

theorem Th63:
  for n,k being Nat st 1 <= k <= n
    for z being FinSequence of INT.Ring st z = idseq n
  holds
     eval(LagIPoly(z,k),In(k,INT.Ring))
    = (-1) |^ (n-'k) * ((n-'k)!) * ((k-'1)!)
      & for i being Nat st 1<= i <=n & i <> k holds
          In(i,INT.Ring) is_a_root_of LagIPoly(z,k)
proof
  let n,k be Nat such that
A1:1 <= k <= n;
  let z be FinSequence of INT.Ring such that
A2: z = idseq n;
  set D=Del(z,k);
A3:len z = n by A2;
  then
A4:k in dom z by A1,FINSEQ_3:25;
  then
A5:len D+1 = n by A3,WSIERP_1:def 1;
A6:len (len D |-> 1) = len D;
  eval(LagIPoly(z,k),In(k,INT.Ring)) =
  eval(~Product rpoly(len D |-> 1,D),In(k,INT.Ring));
  then consider e be FinSequence of the carrier of INT.Ring such that
A7:  eval(LagIPoly(z,k),In(k,INT.Ring)) = Product e and
A8:  len e = len (len D |-> 1) and
A9:  for i being Nat st 1<=i<=len e holds
    e.i = eval(rpoly((len D |-> 1)/.i,D/.i),In(k,INT.Ring)) by Th50;
  defpred P[Nat] means $1 < k implies
  Product (e|$1) = (k-'1) ! / ((k-'1-'$1)!);
  e|0 = <*>the carrier of INT.Ring;
  then
A10:Product (e|0) = 1_ INT.Ring by GROUP_4:8;
A11: k-'1 = k-1 by A1,XREAL_1:233;
  (k-'1-'0) = k-'1-0;
  then
A12:P[0] by A10,XCMPLX_1:60;
A13:for i being Nat st P[i] holds P[i+1]
  proof
    let i be Nat such that
A14:P[i];
    set i1=i+1;
    assume
A15:i1< k;
    then
A16:i1 < n by A1,XXREAL_0:2;
    then
A17:i1 <= len D by A5,NAT_1:13;
A18:i1 <= len e by A16,A8,A5,NAT_1:13;
A19:1<=i1 by NAT_1:11;
    then
A20:i1 in dom (len D |-> 1) & i1 in dom D & i1 in Seg len D
      by A17,A6,FINSEQ_3:25;
    then
A21:(len D |-> 1)/.i1 = (len D |-> 1).i1 = 1 & D/.i1 = D.i1
      by PARTFUN1:def 6,FINSEQ_2:57;
A22:i1 in Seg n by A19,A16;
    D.i1=z.i1 by A4,A15,WSIERP_1:def 1;
    then
A23: D.i1 = i1 by A2,A22,FINSEQ_2:49;
A24: e.i1 = eval(rpoly((len D |-> 1)/.i1,D/.i1),In(k,INT.Ring))
    by NAT_1:11,A17,A8,A9
    .= In(k,INT.Ring) - D/.i1 by A21,HURWITZ:29;
    k = k-'1+1 by A11;
    then
A25:i1 <= k-'1 by A15,NAT_1:13;
    then i < k-'1 by NAT_1:13;
    then
A26: k-'1-'i = k-'1-i by XREAL_1:233;
A27:k-i1 <>0 by A15;
    k-'1-'i1 = k-'1-i1 by A25, XREAL_1:233;
    then (k-'1-'i1)+1 = k-'1-'i by A26;
    then
A28: (k-'1-'i)! = ((k-'1-'i1)!) *(k-i1) by A26,A11,NEWTON:15;
    i1 in dom e by A18,NAT_1:11,FINSEQ_3:25;
    then e|i1 = (e|i)^<*e.i1*> by FINSEQ_5:10;
    hence Product (e|i1) = Product (e|i) * (In(k,INT.Ring) - D/.i1)
      by A24,GROUP_4:6
    .= (k-'1) ! / ((k-'1-'i)!) *(k-i1)
      by A15,NAT_1:13,A14,A23,A20,PARTFUN1:def 6
    .= (k-'1) ! / ((k-'1-'i1)!) by A28,A27,XCMPLX_1:92;
  end;
A29: for i being Nat holds P[i] from NAT_1:sch 2(A12,A13);
  k = k-'1+1 by A11;
  then
A30:k-'1 < k by NAT_1:13;
A31: Product (e| (k-'1)) = (k-'1) ! / ((k-'1-'(k-'1))!) by A29,A30;
A32:(k-'1-'(k-'1))! = 1 by NEWTON:12,XREAL_1:232;
  then
A33: Product (e| (k-'1)) = (k-'1) ! by A31;
  defpred H[Nat] means k <= $1 < n implies
  Product (e|$1) =  (-1) |^ ($1+1-'k) * (($1+1-'k)!) * ((k-'1)!);
A34:H[0] by A1;
A35:for i being Nat st H[i] holds H[i+1]
  proof
    let i be Nat such that
A36: H[i];
    set i1=i+1;
    assume
A37: k<=i1< n;
    then
A38: i1 <= len D by A5,NAT_1:13;
A39: i1 <= len e by A8,A37,A5,NAT_1:13;
    1<=i1 by NAT_1:11;
    then i1 in dom (len D |-> 1) & i1 in dom D & i1 in Seg len D
      by A38,A6,FINSEQ_3:25;
    then
A40: (len D |-> 1)/.i1 = (len D |-> 1).i1 = 1 & D/.i1 = D.i1
    by PARTFUN1:def 6,FINSEQ_2:57;
    1<=i1+1 <= n by A37,NAT_1:11,13;
    then
A41: i1+1 in Seg n;
A42: D.i1=z.(i1+1) by A4,A37,WSIERP_1:def 1;
A43: e.i1 = eval(rpoly((len D |-> 1)/.i1,D/.i1),In(k,INT.Ring))
      by NAT_1:11,A38,A8,A9
    .= In(k,INT.Ring) - D/.i1 by A40,HURWITZ:29;
    i1 in dom e by A38,A8,NAT_1:11,FINSEQ_3:25;
    then e|i1 = (e|i)^<*e.i1*> by FINSEQ_5:10;
    then
A44: Product (e|i1) = Product (e|i) * (In(k,INT.Ring) - D/.i1)
      by A43,GROUP_4:6;
    per cases by A37,XXREAL_0:1;
    suppose
A45:  i1=k;
      (In(k,INT.Ring) - D/.i1) = k - (i1+1) by A42,A2,A41,FINSEQ_2:49,A40
      .= (-1) |^(i1+1-'k) * ((i1+1-'k)!) by A45,NEWTON:13;
      hence thesis by A44,A32,A45,A31;
    end;
    suppose
A46:  k < i1;
      k< i1+1 by A46,NAT_1:13;
      then
A47:  i1+1-'k = i1+1-k & i1-'k = i1-k by A46,XREAL_1:233;
      then i1+1-'k = i1-'k+1;
      then
A48:  ((i1-'k)!) * (i1+1-'k) = (i1+1-'k)! by NEWTON:15;
A49:  In(k,INT.Ring) - D/.i1 = k - (i1+1) by A42,A2,A41,FINSEQ_2:49,A40
      .= -( i1+1-'k) by A47;
      i1 in dom e by A39,NAT_1:11,FINSEQ_3:25;
      then e|i1 = (e|i)^<*e.i1*> by FINSEQ_5:10;
      then
A50:  Product (e|i1) = Product (e|i) * (In(k,INT.Ring) - D/.i1)
      by A43,GROUP_4:6;
A51:  - ((-1) |^ (i1-'k)) = (-1)* ((-1) |^ (i1-'k))
      .= ( -1) |^ (i1-'k +1) by NEWTON:6
      .= ( -1) |^ (i1+1-'k) by A47;
      Product (e|i1) = (-1) |^ (i1+1-'k) * ((i1+1-'k)!) * ((k-'1)!)
      by A51,A48,A50,A36,A46,A37,NAT_1:13,A49;
      hence thesis;
    end;
  end;
A52: for i being Nat holds H[i] from NAT_1:sch 2(A34,A35);
  thus eval(LagIPoly(z,k),In(k,INT.Ring))
  = (-1) |^ (n-'k) * ((n-'k)!) * ((k-'1)!)
  proof
    per cases by A1,XXREAL_0:1;
    suppose k < n;
      then k <= len e < n by A5,A8,NAT_1:13;
      then Product (e|len e) =  (-1) |^ (n-'k) * ((n-'k)!) * ((k-'1)!)
        by A52,A5,A8;
      hence thesis by A7;
    end;
    suppose
A53:  k = n;
      n-'k = 0 by A53,XREAL_1:232;
      then (-1) |^(n-'k) = 1 & (n-'k) ! =1 by NEWTON:4,12;
      hence thesis by A7,A53,A33,A5,A8;
    end;
  end;
  let i be Nat such that
A54: 1<= i <=n & i <> k;
  per cases;
  suppose
A55:i < k;
    then i< n by A1,A54,XXREAL_0:1;
    then i <= len D by A5,NAT_1:13;
    then
A56:i in dom D & i in dom (len D |-> 1) & i in Seg len D
    & i in Seg n by A6,A54,FINSEQ_3:25;
    then (len D |-> 1).i = 1 by FINSEQ_2:57;
    then
A57: D.i = D/.i is_a_root_of ~Product rpoly(len D |-> 1,D)
      by A56,Th51,PARTFUN1:def 6;
    D.i = z.i by A4,A55,WSIERP_1:def 1
    .= In(i,INT.Ring) by A2,A56,FINSEQ_2:49;
    hence thesis by A57;
  end;
  suppose A58:i>=k;
    then reconsider i1=i-1 as Nat by A1;
    i1+1>k by A54,A58,XXREAL_0:1;
    then
A59:i1>=k by NAT_1:13;
    then
A60:i1 >=1 by A1,XXREAL_0:2;
    i1 <= n-1 by A54,XREAL_1:9;
    then
A61:i1 in dom D & i1 in dom (len D |-> 1) & i1 in Seg len D
    & i in Seg n by A5,A60,A6,A54,FINSEQ_3:25;
    then (len D |-> 1).i1 = 1 by FINSEQ_2:57;
    then
A62: D.i1 = D/.i1 is_a_root_of ~Product rpoly(len D |-> 1,D)
    by A61,Th51,PARTFUN1:def 6;
    D.i1 = z.(i1+1) by A59,A4,WSIERP_1:def 1
    .= In(i,INT.Ring) by A2,A61,FINSEQ_2:49;
    hence thesis by A62;
  end;
end;

theorem
  for n being Nat, y being n-element FinSequence of INT
     ex p being Polynomial of INT.Ring st
         for k being Nat st 1 <= k <= n holds
  eval(p,In(k,INT.Ring)) = 1 + ((k-'1)!) * ((n-'k)!) * y.k
proof
  let n be Nat, y be n-element FinSequence of INT;
  rng idseq n c= INT by RELAT_1:def 19;
  then reconsider z = idseq n as FinSequence of INT.Ring
  by FINSEQ_1:def 4;
  deffunc L(Nat)=In(((-1) |^ (n-'$1))*(y.$1),INT.Ring) * LagIPoly(z,$1);
  consider L be FinSequence such that
A1: len L = n & for k being Nat st k in dom L holds L.k=L(k)
  from FINSEQ_1:sch 2;
  rng L c= the carrier of Polynom-Ring INT.Ring
  proof
    let y be object;
    assume y in rng L;
    then consider i be object such that
A2: i in dom L & L.i = y by FUNCT_1:def 3;
    reconsider i as Nat by A2;
    L.i = @L(i) by A2,A1;
    hence thesis by A2;
  end;
  then reconsider L as FinSequence of the carrier of Polynom-Ring INT.Ring
  by FINSEQ_1:def 4;
  take IT=1_.INT.Ring +(~Sum L);
  consider f be sequence of Polynom-Ring INT.Ring such that
A3: Sum L = f.(len L) & f.0 = 0.(Polynom-Ring INT.Ring) and
A4: for j being Nat,v be Element of Polynom-Ring INT.Ring
    st j < len L & v = L.(j + 1) holds f.(j + 1) = f.j + v
    by RLVECT_1:def 12;
  let k be Nat such that
A5:1 <= k <= n;
  len z = n;
  then
A6:k in dom z & k in Seg n by A5,FINSEQ_3:25;
  then
A7: z.k=k by FINSEQ_2:49;
A8:z/.k = z.k in rng z by A6,PARTFUN1:def 6,FUNCT_1:def 3;
A9:for w being Nat st w+1 <= len z & w+1 <> k holds
  eval(~(f.w),z/.k) = eval(~(f.(w+1)),z/.k)
  proof
    let w be Nat;
    set w1=w+1;
    assume
A10: w1 <= len z & w1 <> k;
A11: w1 in dom L & w1 in dom z by A10,A1,NAT_1:11,FINSEQ_3:25;
    then
A12: L.w1 = L/.w1 & z.w1 = z/.w1 by PARTFUN1:def 6;
    then f.w1 = f.w + L/.w1 by A10,NAT_1:13,A1,A4;
    then ~(f.w1) = ~(f.w) + ~(L/.w1) by POLYNOM3:def 10;
    then
A13: eval(~(f.w1),z/.k) = eval(~(f.w),z/.k)+eval(~(L/.w1),z/.k)
      by POLYNOM4:19;
A14: L.w1 = L(w1) by A11,A1;
    1<= w1 <=n & w1 <> k by NAT_1:11,A10;
    then
A15: eval(LagIPoly(z,w1),In(k,INT.Ring)) = 0.INT.Ring
      by A5,Th63,POLYNOM5:def 7;
    eval(L(w1),In(k,INT.Ring)) =
    In(((-1) |^ (n-'w1))*(y.w1),INT.Ring) *
    eval(LagIPoly(z,w1),In(k,INT.Ring)) by RING_5:7;
    hence thesis by A15,A14,A12,A13, A7,A8;
  end;
  defpred P[Nat] means $1 < k implies eval(~(f.$1),z/.k) =0.INT.Ring;
  0.(Polynom-Ring INT.Ring)= 0_.(INT.Ring) by POLYNOM3:def 10;
  then
A16:P[0] by A3,POLYNOM4:17;
A17:for i being Nat st P[i] holds P[i+1] by A9, A5,NAT_1:13,XXREAL_0:2;
A18: for i being Nat holds P[i] from NAT_1:sch 2(A16,A17);
  defpred Q[Nat] means k <= $1 <= len z implies
  eval(~(f.$1),z/.k) = ((n-'k)!) * ((k-'1)!) * y.k;
A19:Q[0] by A5;
A20:for i being Nat st Q[i] holds Q[i+1]
  proof
    let i be Nat such that
A21: Q[i];
    set i1=i+1;
    assume
A22: k <= i1 <=len z;
    then per cases by XXREAL_0:1;
    suppose
A23:   k = i1;
      then i < k by NAT_1:13;
      then
A24:   eval(~(f.i),z/.k) =0.INT.Ring by A18;
A25:   i1 in dom L & i1 in dom z by A1,A22,NAT_1:11,FINSEQ_3:25;
      then
A26:   L.i1 = L/.i1 & z.i1 = z/.i1 by PARTFUN1:def 6;
      then f.i1 = f.i + L/.i1 by A22,NAT_1:13,A1,A4;
      then ~(f.i1) = ~(f.i) + ~(L/.i1) by POLYNOM3:def 10;
      then A27:eval(~(f.i1),z/.k) = eval(~(f.i),z/.k)+eval(~(L/.i1),z/.k)
        by POLYNOM4:19;
      eval(L(i1),In(k,INT.Ring)) = In(((-1) |^ (n-'k))*(y.k),INT.Ring) *
      eval(LagIPoly(z,k),In(k,INT.Ring)) by A23,RING_5:7;
      then eval(L(i1),In(k,INT.Ring)) =
        (((-1) |^ (n-'k))*(y.k)) * ((-1) |^ (n-'k) * ((n-'k)!) * ((k-'1)!))
        by A5,Th63
      .= ( (-1) |^ (n-'k)) * ((-1) |^ (n-'k)) * ((n-'k)!) * ((k-'1)!) *y.k
      .= ( (-1) |^ ((n-'k)+(n-'k))) * ((n-'k)!) * ((k-'1)!) *y.k by NEWTON:8
      .= ( (-1) |^ (2*(n-'k))) * ((n-'k)!) * ((k-'1)!) *y.k
      .= 1 * ((n-'k)!) * ((k-'1)!) *y.k;
      hence thesis by A25,A1,A24,A26,A27,A7,A8;
    end;
    suppose k < i1;
      hence thesis by A22,A9,A21,NAT_1:13;
    end;
  end;
A28: for n being Nat holds Q[n] from NAT_1:sch 2(A19,A20);
  eval(IT,In(k,INT.Ring)) = eval(1_.INT.Ring,In(k,INT.Ring))+
  eval(~Sum L,In(k,INT.Ring)) by POLYNOM4:19
  .= 1.INT.Ring + eval(~Sum L,In(k,INT.Ring)) by POLYNOM4:18
  .= 1 + ((n-'k)!) * ((k-'1)!) * y.k by A7,A8,A28,A5,A3,A1;
  hence thesis;
end;

registration
  let i be Rational;
  reduce In(i,F_Rat) to i;
  reducibility by SUBSET_1:def 8,RAT_1:def 2,GAUSSINT:def 14;
end;

begin :: Problem 127

:: Prove that there is no polynomial f(x) with integer coefficients
:: such that f(1) = 2, f(2) = 3 and f(3) = 5.
:: However, for every integer m > 1, there exists a polynomial f(x)
:: with rational coefficients such that f(k) = P.k for k = 1, 2, ...,
:: where P.k denotes the k^(th) prime number.

:: Problem 127 part 1
theorem
  not ex p being Polynomial of INT.Ring st
    eval(p,In(1,INT.Ring))=2 & eval(p,In(3,INT.Ring))=5
proof
  set IR=INT.Ring, i1 = In(1,IR),i2 = In(2,IR),i3 = In(3,IR),i5 = In(5,IR);
  given p be Polynomial of INT.Ring such that
     A1: eval(p,i1)=2 & eval(p,i3)=5;
  set IR=INT.Ring, t = i2 * 1_.IR, g = p - t;
  reconsider G=g as Polynomial of F_Rat by RING_3:47,LIOUVIL2:7;
  reconsider I1= i1,I2=i2,I3=i3 as Element of F_Rat
    by RING_3:47,LIOUVIL2:6;
A2: eval(t,i1) = i2*eval(1_.IR,i1) by RING_5:7
  .= i2* 1.IR by POLYNOM4:18
  .= i2;
A3: eval(t,i3) = i2*eval(1_.IR,i3) by RING_5:7
  .= i2* 1.IR by POLYNOM4:18
  .= i2;
  eval(G,I1) = eval(g,i1) by RING_3:47,Th40
  .= i2-i2 by A2,A1,POLYNOM4:21
  .= 0.IR
  .= 0.F_Rat by RING_3:47,C0SP1:def 3;
  then
A4:G = (G div rpoly(1,I1))*'rpoly(1,I1) by Th41,POLYNOM5:def 7;
  i1*i1 = 1.IR;
  then reconsider h = (G div rpoly(1,I1)) as Polynomial of IR
    by RING_3:47,A4,Th42,ALGSTR_0:def 27;
  reconsider hi3=eval(h,i3) as Integer;
  eval(rpoly(1,I1),I3) = I3-I1 by HURWITZ:29
  .= i2;
  then eval(G,I3) = eval(G div rpoly(1,I1),I3) * I2 by A4,POLYNOM4:24
  .= eval(h,i3) * i2 by RING_3:47,Th40;
  then
A5: eval(g,i3) = eval(h,i3) * i2 by RING_3:47,Th40;
  eval(g,i3) = eval(p,i3) - eval(t,i3) by POLYNOM4:21
  .= i3 by A1,A3;
  then 2 divides 3 & 2 divides 3+-1 by A5;
  then 2 divides -1 by INT_2:1;
  hence thesis by INT_2:13;
end;

:: Problem 127 part 2
theorem
  for n being Nat
     for i,z being FinSequence of the carrier of F_Rat st
       i = idseq n & z = primesFinS(n)
     for k being Nat st k < n holds
         eval(LagPoly(i,z),In(k+1,F_Rat)) = primenumber k
proof
  let n be Nat;
  let i,z be FinSequence of the carrier of F_Rat such that
A1: i = idseq n & z = primesFinS(n);
  let k be Nat such that
A2:k < n;
A3:i is one-to-one by A1,FINSEQ_2:55;
A4:n= len i by A1;
A5:1<= k+1 <= n by A2,NAT_1:11,13;
  then
A6:k+1 in dom i & k+1 in Seg n by A4,FINSEQ_3:25;
  then
A7:i/.(k+1) = i.(k+1) by PARTFUN1:def 6
  .= (k+1) by A1,A6,FINSEQ_2:49;
  len z  = n by A1,NUMBER13:def 1;
  then k+1 in dom z by A5,FINSEQ_3:25;
  then z/.(k+1) = z.(k+1) by PARTFUN1:def 6
  .= primenumber k by A1,A2,NUMBER13:def 1;
  hence eval(LagPoly(i,z),In(k+1,F_Rat))= primenumber k by A7,A6,A3,Th59;
end;

begin :: Problem 129

:: Provide an example of a reducible polynomial, f(x), with integer
:: coefficients, for which the values of f(x) for m distinct positive
:: integers are all prime numbers.

theorem
  for n being Nat
    ex p,q being Polynomial of INT.Ring st degree p > 0 & degree q > 0 &
      for i being Nat st i <= n holds
         eval(p *' q ,In(primenumber i,INT.Ring)) = primenumber i
proof
  let n be Nat;
  rng primesFinS(n+1) c= INT = the carrier of INT.Ring
    by VALUED_0:def 5;
  then reconsider z = primesFinS(n+1) as FinSequence of INT.Ring
    by FINSEQ_1:def 4;
  take p = 1_.INT.Ring + ~Product rpoly(len z |-> 1,z);
  take q = <%0.INT.Ring, 1.INT.Ring%>;
A1:len z = n+1 by NUMBER13:def 1;
A2:Sum (len z |-> 1) = 1*(len z) by RVSUM_1:80;
  deg ~Product rpoly(len z |-> 1,z) = n+1 by A1,A2,Th49;
  then
A3: len (~Product rpoly(len z |-> 1,z))-1=n+1 by HURWITZ:def 2;
A4:len 1_.INT.Ring = 1 by POLYNOM4:4;
  len 1_.INT.Ring<> len ~Product rpoly(len z |-> 1,z) by A3,A4;
  then len p = max(len 1_.INT.Ring, len ~Product rpoly(len z |-> 1,z))
    by POLYNOM4:7;
  then deg p = n+1+1-1 by A3,A4,HURWITZ:def 2;
  hence degree p > 0;
  len q = 2 by POLYNOM5:40;
  then degree q = 2-1 by HURWITZ:def 2;
  hence degree q > 0;
  let i be Nat such that
A5:i <= n;
A6: eval(q,In(primenumber i,INT.Ring)) =
  0.INT.Ring + 1.INT.Ring*In(primenumber i,INT.Ring)
  by POLYNOM5:44
  .= In(primenumber i,INT.Ring);
A7:eval(1_.INT.Ring,In(primenumber i,INT.Ring)) = 1.INT.Ring by POLYNOM4:18;
A8:i < n+1 by A5,NAT_1:13;
  then
A9: In(primenumber i,INT.Ring) = z.(i+1)  by NUMBER13:def 1;
A10: len (len z |-> 1) = len z;
  1<= i+1 <= n+1 by A8,NAT_1:11,13;
  then
A11:i+1 in dom z = dom (len z |-> 1) & i+1 in Seg len z
    by A1,A10,FINSEQ_3:25,29;
  then (len z |-> 1).(i+1) = 1 & z/.(i+1) = z.(i+1)
    by FINSEQ_2:57,PARTFUN1:def 6;
  then 0.INT.Ring = eval(~Product rpoly(len z |-> 1,z),
  In(primenumber i,INT.Ring))
    by A11,Th51,A9,POLYNOM5:def 7;
  then eval(p,In(primenumber i,INT.Ring)) = 1.INT.Ring +
  0.INT.Ring by A7,POLYNOM4:19
   .= 1.INT.Ring;
  hence eval(p *' q ,In(primenumber i,INT.Ring))
   = 1.INT.Ring * In(primenumber i,INT.Ring) by A6,POLYNOM4:24
  .= primenumber i;
end;

begin :: Problem 130

:: Show that if f(x) is a non-constant polynomial with integer coefficients,
:: then the congruence f(x)==0(mod p) has a solution for an infinite number
:: of primes p.

theorem Th68:
  for L being unital well-unital non degenerated
      non empty multLoopStr_0 st L is domRing-like
  for x being Element of L
        for i being Nat st (power L).(x,i) = 0.L holds x = 0.L
proof
  let L be unital well-unital non degenerated non empty multLoopStr_0
    such that
A1: L is domRing-like;
  let x be Element of L;
  defpred P[Nat] means (power L).(x,$1) = 0.L implies x = 0.L;
  (power L).(x,0) = 1_L by GROUP_1:def 7;
  then
A2:P[0];
A3:for i st P[i] holds P[i+1]
  proof
    let i be Nat such that
A4: P[i];
    reconsider I=i as Element of NAT by ORDINAL1:def 12;
    assume
A5: (power L).(x,i+1) = 0.L & x<>0.L;
    then 0.L = (power L).(x,I) * x by GROUP_1:def 7;
    hence thesis by A4,A5,A1,VECTSP_2:def 1;
  end;
  for i holds P[i] from NAT_1:sch 2(A2,A3);
  hence thesis;
end;

theorem Th69:
  for L being domRing-like commutative non degenerated
    associative add-associative right_zeroed right_complementable
    distributive Abelian well-unital unital non empty doubleLoopStr
  for p being Polynomial of L st p.0 <> 0.L
    ex q being Polynomial of L st
       len p = len q &
       q.0 = 1.L &
       (for i being Element of NAT st 0 < i holds q.i =
       (p.i) * ((power L).(p.0,i-'1))) &
       for x being Element of L holds eval(p,(p.0) * x) = (p.0) * eval(q,x)
proof
  let L be domRing-like commutative non degenerated
    associative add-associative right_zeroed right_complementable
    distributive Abelian well-unital unital non empty doubleLoopStr;
  let p be Polynomial of L such that A1:p.0 <> 0.L;
  defpred Q[Element of NAT,object] means
    ($1 = 0 implies $2= 1.L) &
    ($1 > 0 implies $2 = (p.$1) * (power L).(p.0,$1-'1));
A2:for x being Element of NAT ex y being Element of L st Q[x,y]
  proof
    let x be Element of NAT;
    per cases;
    suppose
A3:    x=0;
      take 1.L;
      thus thesis by A3;
    end;
    suppose
A4:    x>0;
      take (p.x) * (power L).(p.0,x-'1);
      thus thesis by A4;
    end;
  end;
  consider q be sequence of L such that
A5: for n be Element of NAT holds Q[n,q.n] from FUNCT_2:sch 3(A2);
  now
    let n be Nat;
    assume
A6:  n >= len p+1;
    reconsider nn = n as Element of NAT by ORDINAL1:def 12;
A7:  len p is_at_least_length_of p by ALGSEQ_1:def 3;
    n > len p by A6,NAT_1:13;
    then
A8:  p.nn = 0.L by A7,ALGSEQ_1:def 2;
    q.nn = (p.nn) * (power L).(p.0,nn-'1) by A5,A6;
    hence q.n = 0.L by A8;
  end;
  then reconsider q as Polynomial of L by ALGSEQ_1:def 1;
  take q;
A9: now let i be Nat such that
A10: i >= len p;
    reconsider I=i as Element of NAT by ORDINAL1:def 12;
A11: len p is_at_least_length_of p by ALGSEQ_1:def 3;
    then
A12: p.i = 0.L by A10,ALGSEQ_1:def 2;
    i>0 by A11,A10,ALGSEQ_1:def 2,A1;
    hence q.i = (p.I) * (power L).(p.0,I-'1) by A5
    .= 0.L by A12;
  end;
  for m being Nat st m is_at_least_length_of q holds len p<=m
  proof
    let m be Nat such that
A13: m is_at_least_length_of q & len p > m;
    reconsider lp=len p -1 as Nat by A13;
    q.m = 0.L by A13,ALGSEQ_1:def 2;
    then
A14: m<>0 by A5;
    for i being Nat st i >= m holds p.i=0.L
    proof
      let i be Nat such that
A15:   i >= m  & p.i <>0.L;
      reconsider I=i as Element of NAT by ORDINAL1:def 12;
      i >0 by A15,A14;
      then q.i = (p.I) * (power L).(p.0,I-'1) by A5;
      then (power L).(p.0,I-'1) = 0.L
        by A15,A13,ALGSEQ_1:def 2,VECTSP_2:def 1;
      hence thesis by A1,Th68;
    end;
    then m is_at_least_length_of p by ALGSEQ_1:def 2;
    hence thesis by A13,ALGSEQ_1:def 3;
  end;
  hence
A16: len p = len q & q.0 = 1.L
  by A9,A5,ALGSEQ_1:def 2,ALGSEQ_1:def 3;
  thus for i being Element of NAT st 0 < i holds
  q.i = (p.i) * ((power L).(p.0,i-'1)) by A5;
  let x be Element of L;
  consider P be FinSequence of the carrier of L such that
A17: eval(p,(p.0) * x) = Sum P & len P = len p and
A18: for n be Element of NAT st n in  dom P holds
  P.n = p.(n-'1) * (power L).((p.0) * x,n-'1)
    by POLYNOM4:def 2;
  consider Q be FinSequence of the carrier of L such that
A19:    eval(q, x) = Sum Q & len Q = len (q) and
A20: for n be Element of NAT st n in dom Q holds
    Q .n = (q).(n-'1) * (power L).(x,n-'1)
     by POLYNOM4:def 2;
  reconsider Q as Element of (len q)-tuples_on the carrier of L
    by A19,FINSEQ_2:92;
  len P = len ((p.0) * Q) by A17,A16,CARD_1:def 7;
  then
A21:dom P = dom ((p.0) * Q) by FINSEQ_3:29;
  for k being Nat st k in dom P holds P.k = ((p.0)*Q).k
  proof
    let k be Nat such that
A22: k in dom P;
    reconsider K=k as Element of NAT by ORDINAL1:def 12;
    set k1=K-'1;
    dom P = dom Q by A16,A17,A19,FINSEQ_3:29;
    then Q .K = q.k1 * (power L).(x,k1) by A22,A20;
    then
A23:((p.0)*Q).K = (p.0) * (q.k1 * (power L).(x,k1))
      by A21,A22,FVSUM_1:50;
    per cases;
    suppose
A24:   k1>0;
      then k1>=1+0 by NAT_1:8;
      then k1-'1=k1-1 by XREAL_1:233;
      then k1-'1+1=k1;
      then
A25:    (p.0) * ((power L).(p.0,k1-'1)) = (power L).(p.0,k1)
        by GROUP_1:def 7;
      ((p.0)*Q).K = (p.0)* ((p.k1)* ((power L).(p.0,k1-'1)) * (power L).(x,k1))
        by A5,A24,A23
        .= (p.0) * ( (p.k1) * (((power L).(p.0,k1-'1)) * (power L).(x,k1)))
        by GROUP_1:def 3
        .= (p.k1) * ((p.0) * (((power L).(p.0,k1-'1)) * (power L).(x,k1)))
        by GROUP_1:def 3
        .= (p.k1) * ( ((p.0) * ((power L).(p.0,k1-'1))) * (power L).(x,k1))
        by GROUP_1:def 3
        .= (p.k1) * (power L).((p.0)*x,k1) by GROUP_1:52,A25;
      hence thesis by A22,A18;
    end;
    suppose
A26:  k1=0;
      then ((p.0)*Q).K = (p.0) * (1.L * (power L).(x,k1)) by A5,A23
        .= (p.k1) * 1_ L by A26,GROUP_1:def 7
        .= (p.k1) * (power L).((p.0) * x,k1) by A26,GROUP_1:def 7;
      hence thesis by A22,A18;
    end;
  end;
  then P = (p.0)*Q by A21,FINSEQ_1:13;
  hence eval(p,(p.0) * x) = (p.0) * eval(q,x) by A17,A19,FVSUM_1:73;
end;

theorem Th70:
  for L being unital well-unital Abelian  add-associative right_zeroed
    right_complementable left-distributive associative non empty doubleLoopStr
  for p being Polynomial of L
    for x being Element of L
      ex d being Element of L st eval(p,x) = d*x + p.0
proof
  let L be unital well-unital Abelian  add-associative right_zeroed
    right_complementable left-distributive associative non empty doubleLoopStr;
  let p be Polynomial of L;
  let x be Element of L;
  consider F be FinSequence of the carrier of L such that
A1: eval(p,x) = Sum F & len F = len p and
A2: for n be Element of NAT st n in dom F holds
      F.n = p.(n-'1) * (power L).(x,n-'1) by POLYNOM4:def 2;
  defpred P[Nat] means 1 <= $1 <= len p implies
    ex d being Element of L st Sum(F|$1) = d*x + p.0;
A3: P[0];
A4: for i being Nat st P[i] holds P[i+1]
  proof
    let i be Nat such that
A5: P[i];
    assume
A6: 1 <= i+1 <= len p;
    reconsider I=i as Element of NAT by ORDINAL1:def 12;
    set i1=I+1;
    i1 in dom F by A6,A1,FINSEQ_3:25;
    then
A7: F|i1 = (F|i)^<*F.i1*> by FINSEQ_5:10;
A8: F.i1 = p.(i1-'1) * (power L).(x,i1-'1) by A6,A1,FINSEQ_3:25,A2;
    then A9: Sum (F|i1) = Sum (F|i) + p.(i1-'1) * (power L).(x,i1-'1)
      by A7,FVSUM_1:71;
    per cases;
    suppose
A10:  i=0;
      then len (F|i)=0;
      then Sum (F|i) = 0.L by RLVECT_1:75;
      then Sum (F|i1)= p.0 * 1_L by A9,A10,GROUP_1:def 7
      .= 0.L*x + p.0;
      hence thesis;
    end;
    suppose
A11:  i>0;
      then consider d be Element of L such that
A12:  Sum(F|i) = d*x + p.0 by A5,A6,NAT_1:13,14;
      reconsider e = I-1 as Element of NAT  by A11,NAT_1:20;
      e+1=I;
      then
A13:  (power L).(x,I) = (power L).(x,e) * x by GROUP_1:def 7;
      Sum (F|i1) = (d*x + p.0) + p.I * (power L).(x,I)
      by A12,A8,A7,FVSUM_1:71
       .= p.0 + (d*x + p.I * (power L).(x,I)) by RLVECT_1:def 3
       .= p.0 + (d*x + p.I * (power L).(x,e) * x) by A13,GROUP_1:def 3
       .= p.0 + (d + p.I * (power L).(x,e) )*x by VECTSP_1:def 3;
      hence thesis;
    end;
  end;
  for i being Nat holds P[i] from NAT_1:sch 2(A3,A4);
  then
A14: P[len p];
  per cases by NAT_1:14;
  suppose
    len p = 0;
    then p = 0_.(L) by POLYNOM4:5;
    then eval(p,x) = 0.L*x + p.0 by POLYNOM4:17;
    hence thesis;
  end;
  suppose
    1<= len p;
    hence thesis by A1,A14;
  end;
end;

Lm3:
for p be Polynomial of F_Complex st len p > 2
  for r be Real
     ex e be Real st
        for z be Element of F_Complex st e < |.z.|
         holds |.eval(p,z).| > r
proof
  let p be Polynomial of F_Complex such that A1: len p > 2;
  let r be Real;
  set N=NormPolynomial(p);
  A2: len N = len p  by A1,POLYNOM5:57;
  then N.(len N-'1) = 1.F_Complex by A1,POLYNOM5:56;
  then N.(len N-'1) = 1 by COMPLFLD:def 1;
  then A3: |. N.(len N-'1) .| =1;
  deffunc G(Nat) = In(|.N.($1-'1).|,REAL);
  consider F be FinSequence of REAL such that
A4: len F = len N and
A5: for n be Nat st n in dom F holds F.n = G(n) from FINSEQ_2:sch 1;
  take e = (|. p.(len p-'1) .|") * |. r+1 .| + |. Sum F .|;
  let z be Element of F_Complex such that A6: e < |.z.|;
  A7: for n be Element of NAT st n in dom F holds F.n = |.N.(n-'1).|
  proof
    let n be Element of NAT;
    assume n in dom F;
    hence F.n = G(n) by A5
    .= |.N.(n-'1).|;
  end;
  for n st n in dom F holds F.n >= 0
  proof
    let n;
    assume n in dom F;
    then F.n = |.N.(n-'1).| by A7;
    hence thesis;
  end;
  then
A8: |. Sum F .| = Sum F by RVSUM_1:84,COMPLEX1:43;
  e >= |. Sum F .| +0 by XREAL_1:6;
  then  |.z.| > |. Sum F .| by A6,XXREAL_0:2;
  then |.eval(N,z).| >= |.z.| by A8,A7,A1,A2,A3,A4,POLYNOM5:72;
  then  |.eval(N,z).| >= (|. p.(len p-'1) .|") * |. r+1 .| + |. Sum F .|
    >= (|. p.(len p-'1) .|") * |. r+1 .| +0
    by A6,XXREAL_0:2,XREAL_1:6;
  then
A9: |.eval(N,z).| >= (|. p.(len p-'1) .|") * |. r+1 .| by XXREAL_0:2;
A10:p.(len p-'1) <> 0.F_Complex by A1,UPROOTS:18;
  then
A11:p.(len p-'1) <> 0 by COMPLFLD:def 1;
A12:( (|. p.(len p-'1) .|") * |. r+1 .|) * |. p.(len p-'1) .|
    = |. r+1 .|* ((|. p.(len p-'1) .|")  * |. p.(len p-'1) .| )
   .= |. r+1 .| * 1 by A11,XCMPLX_0:def 7;
  eval(N,z) * p.(len p-'1) = eval(p,z) / p.(len p-'1) * p.(len p-'1)
    by A1,POLYNOM5:58;
  then eval(N,z) * p.(len p-'1) = eval(p,z) by A10,VECTSP_2:22;
  then |. eval(N,z) .| * |. p.(len p-'1) .| = |.eval(p,z).|
    by COMPLEX1:65;
  then |.eval(p,z).| >= |.r+1 .| >= r+1 by A12,A9,XREAL_1:64,ABSVALUE:4;
  then |.eval(p,z).| >= r+1 > r+0 by XXREAL_0:2,XREAL_1:6;
  hence thesis by XXREAL_0:2;
end;

theorem Th71:
  for p be Polynomial of F_Complex st len p >= 2
    for r be Real ex e be Real st
    for z be Element of F_Complex st e < |.z.|
  holds |.eval(p,z).| > r
proof
  let p be Polynomial of F_Complex;
  assume len p >= 2;
  then per cases by XXREAL_0:1;
  suppose
A1: len p=2;
    then
A2: p = <%p.0, p.1%> by Th38;
    set N1 = |. p.1 .|;
    p.(len p-'1) <> 0.F_Complex & len p-'1 = 2-1 by A1,UPROOTS:18,XREAL_1:233;
    then
A3: p.1 <> 0 by COMPLFLD:def 1;
    let r be Real;
    take e = N1" * |. r .| + |. - p.0 .| * N1";
    let z be Element of F_Complex such that
A4: e < |.z.|;
A5: (N1" * |. r .| + |. - p.0 .|* N1" )*N1 < |.z.| * N1 by A4,A3,XREAL_1:68;
A6: (N1" * |. r .| *N1)= |. r .| * (N1"*N1)
      .= |. r .| * 1 by A3,XCMPLX_0:def 7;
A7: |.  - p.0 .|* N1" *N1 = |.  - p.0 .|* (N1" *N1)
      .= |.  - p.0 .|*1 by A3,XCMPLX_0:def 7;
    (N1" * |. r .| + |. - p.0 .|* N1" )*N1 = |. r .| + |. - p.0 .| by A6,A7;
    then A8: |. r .|  < |.z.| * N1  - |. - p.0 .| by A5,XREAL_1:20;
    reconsider z1=z  * p.1,z2= - (p.0) as Complex;
A9: |. z  * (p.1) .| - |. - (p.0) .| <= |. z * p.1 - - p.0 .| by COMPLEX1:59;
A10: z * p.1 - - p.0 = z * p.1  + - - p.0
    .= z * p.1+p.0;
    |.z.| * N1 = |.z * p.1  .| by COMPLEX1:65;
    then |. r .| < |. z * p.1   -   - p.0 .| by A8,A9,XXREAL_0:2;
    then
A11: |. r .| < |. eval(p,z) .| by A2,POLYNOM5:44,A10;
    r <= |. r .| by COMPLEX1:76;
    hence thesis by A11,XXREAL_0:2;
  end;
  suppose len p > 2;
    hence thesis by Lm3;
  end;
end;

:: Problem 130
theorem
  for f being Polynomial of INT.Ring st degree f > 0 holds
    {p where p is Prime:  ex x being Element of INT.Ring st
          eval(f,x),0 are_congruent_mod p} is infinite
proof
  let f be Polynomial of INT.Ring such that A1: degree f > 0;
  len f - 1 > 0 by A1,HURWITZ:def 2;
  then len f - 1+1 > 0+1 by XREAL_1:6;
  then A2: len f >= 1+1 by NAT_1:13;
  per cases;
  suppose
    A3: f.0 = 0.INT.Ring;
    SetPrimes c= {p where p is Prime:  ex x being Element of INT.Ring st
      eval(f,x),0 are_congruent_mod p}
    proof
      let y be object;
      assume y in SetPrimes;
      then reconsider y as Prime by NEWTON:def 6;
      eval(f,f.0) = 0 by A3,POLYNOM5:31;
      then ex x being Element of INT.Ring st
      eval(f,x),0 are_congruent_mod y by INT_1:11;
      hence thesis;
    end;
    hence thesis;
  end;
  suppose
    f.0 <> 0.INT.Ring;
    then consider f1 be Polynomial of INT.Ring such that
A4:   len f = len f1 & f1.0 = 1.INT.Ring  and
      for i being Element of NAT st 0 < i holds
           f1.i = (f.i) * ((power INT.Ring).(f.0,i-'1))  and
A5:   for x being Element of INT.Ring holds eval(f,(f.0) * x) = (f.0) *
        eval(f1,x) by Th69;
    set n = the Element of NAT;
    ex m be Element of NAT st
    for n being Nat st n >=m holds |.eval(f1,In(n!,INT.Ring)).| > 1
    proof
      reconsider g1=f1 as Polynomial of F_Complex by ALGNUM_1:4,LIOUVIL2:7;
      len f1=len g1 by ALGNUM_1:4,LIOUVIL2:8;
      then consider e be Real such that
A6:   for z be Element of F_Complex st e < |.z.|
        holds |.eval(g1,z).| > 1 by A4,A2,Th71;
      set E = |. [/ e \].| +1;
      consider n be Element of NAT such that
A7:   n! <= E & E < (n+1)! &
      for m be Element of NAT st m! <= E & E < (m+1)! holds m = n
        by NAT_1:14,ASYMPT_1:57;
      take N = n+1;
      let i be Nat such that
A8:   i >=N;
      i! >= N! by A8,ASYMPT_1:56;
      then
A9:   i! > E by A7,XXREAL_0:2;
      e <= [/ e \] <= |. [/ e \].| by INT_1:def 7,COMPLEX1:76;
      then e <= |. [/ e \].| < E by NAT_1:13,XXREAL_0:2;
      then
A10:  e < E by XXREAL_0:2;
      i! in COMPLEX by XCMPLX_0:def 2;
      then
A11:  i! in the carrier of F_Complex by COMPLFLD:def 1;
      then i! = In(i!,F_Complex) by SUBSET_1:def 8;
      then e < |.In(i!,F_Complex).| by A10,A9,XXREAL_0:2;
      then |.eval(g1,In(i!,F_Complex)).| > 1 by A6;
      hence thesis by ALGNUM_1:4,Th40,A11,SUBSET_1:def 8;
    end;
    then consider m be Element of NAT such that
A12:  for n st n >=m holds |.eval(f1,In(n!,INT.Ring)).| > 1;
    defpred P[Nat] means ex x being Element of INT.Ring st
      eval(f,x),0 are_congruent_mod $1;
    set X = {p where p is Prime:  P[p] & p >= m};
A13:for n being Nat st n >= m ex p being Prime st p > n & P[p]
    proof
      let n be Nat such that
A14:  n >= m;
      set N=In(n!,INT.Ring);
      consider k be Element of INT.Ring such that
A15:  eval(f1,N) = k*N + f1.0 by Th70;
      |. k*N + 1 .| > 1 by A4,A15,A14,A12;
      then consider p be Prime such that
A16:  p divides |. k*N + 1 .| by MOEBIUS1:5;
A17:  p divides k*N+1 by A16,NUMBER14:4;
A18:  p > n
      proof
        assume p <= n;
        then p divides k*N by NEWTON:41,INT_2:2;
        then p divides 1 by A17,INT_2:1;
        then p =1 or p = -1 by INT_2:13;
        hence thesis by INT_2:def 4;
      end;
      eval(f,(f.0) * N) = (f.0) * eval(f1,N) by A5
      .= (f.0) * (k*N+1) by A4,A15;
      then eval(f,(f.0) * N),0 are_congruent_mod p by A17,INT_2:2;
      hence thesis by A18;
    end;
    for y being object st y in X holds y is natural
    proof
      let y be object;
      assume y in X;
      then ex p be Prime st y=p & P[p] & p >= m;
      hence thesis;
    end;
    then reconsider X as natural-membered set by MEMBERED:def 6;
A19: X is non empty
    proof
      consider p be Prime such that
A20:  p > m & P[p] by A13;
      p in X by A20;
      hence thesis;
    end;
A21: for a being Nat st a in X ex b being Nat st b > a & b in X
    proof
      let a be Nat;
      assume a in X;
      then consider p be Prime such that
A22:  a=p & P[p] & p >= m;
      consider q be Prime such that
A23:  q > p & P[q] by A22,A13;
      q >=m  by A22,A23,XXREAL_0:2;
      then q in X by A23;
      hence thesis by A22,A23;
    end;
    X c= {p where p is Prime: P[p]}
    proof
      let y be object;
      assume y in X;
      then ex p be Prime st y=p & P[p] & p >= m;
      hence thesis;
    end;
    hence thesis by A21,A19,NUMBER04:1;
  end;
end;

begin :: Preliminaries to Problems 132, 133 and 134.

theorem Th73:
  k in seq(n,m) iff n < k <= n+m
proof
  thus k in seq(n,m) implies n < k <= n+m
  proof
    assume
A1: k in seq(n,m);
    then 1+n <= k by CALCUL_2:1;
    hence thesis by A1,CALCUL_2:1,NAT_1:13;
  end;
  assume
A2:n < k <= n+m;
  then n+1 <= k by NAT_1:13;
  hence thesis by A2,CALCUL_2:1;
end;

theorem Th74:
  k in primeNumbers(n,m) iff n < k <= n+m & k is prime
proof
  thus k in primeNumbers(n,m) implies n < k <= n+m & k is prime
  proof
    assume k in primeNumbers(n,m);
    then k in seq(n,m) /\ SetPrimes by NUMBER14:def 17;
    hence thesis by Th73,NEWTON:def 6;
  end;
  assume n < k <= n+m & k is prime;
  then k in seq(n,m) & k in SetPrimes by Th73,NEWTON:def 6;
  then k in seq(n,m) /\ SetPrimes by XBOOLE_0:def 4;
  hence thesis by NUMBER14:def 17;
end;

theorem Th75:
  for n1,m1,n2,m2 being Nat st n1+m1 <= n2 holds
       seq(n1,m1) misses seq(n2,m2)
proof
  let n1,m1,n2,m2 be Nat such that
A1: n1+m1 <= n2;
  assume seq(n1,m1) meets seq(n2,m2);
  then consider x be object such that
A2:x in seq(n1,m1) & x in seq(n2,m2) by XBOOLE_0:3;
  reconsider x as Nat by A2;
  n2 < x <= n1+m1 by A2,Th73;
  hence thesis by A1,XXREAL_0:2;
end;

theorem Th76:
  for n1,m1,n2,m2 being Nat st n1+m1 <= n2 holds
       primeNumbers(n1,m1) misses primeNumbers(n2,m2)
proof
  let n1,m1,n2,m2 be Nat such that
A1: n1+m1 <= n2;
  primeNumbers(n1,m1)= seq(n1,m1)/\ SetPrimes &
  primeNumbers(n2,m2)= seq(n2,m2)/\ SetPrimes by NUMBER14:def 17;
  hence thesis by A1,Th75,XBOOLE_1:76;
end;

theorem Th77:
  seq(n,m) \/ seq(n+m,k) = seq(n,m+k)
proof
A1:seq(n,m) c= seq(n,m+k)
  proof
    let x be object such that
A2: x in seq(n,m);
    reconsider x as Nat by A2;
A3: n < x <=n+m <= n+m+k by A2,Th73,NAT_1:11;
    then x <= n+m+k=n+(m+k) by XXREAL_0:2;
    hence thesis by A3,Th73;
  end;
  seq(n+m,k) c= seq(n,m+k)
  proof
    let x be object such that
A4: x in seq(n+m,k);
    reconsider x as Nat by A4;
A5: n <= n+m < x <= n+m+k=n+(m+k) by A4,Th73,NAT_1:11;
    then n < x by XXREAL_0:2;
    hence thesis by A5,Th73;
  end;
  then
A6: seq(n,m) \/ seq(n+m,k) c= seq(n,m+k) by A1,XBOOLE_1:8;
  seq(n,m+k) c= seq(n,m) \/ seq(n+m,k)
  proof
    let y be object;
    assume
A7: y in seq(n, m + k);
    then reconsider y as Nat;
A8: n <  y <= n + (m + k) = n+m+k by A7,Th73;
    per cases;
    suppose  y <= n + m;
      then y in seq(n, m) by A8, Th73;
      hence thesis by XBOOLE_0:def 3;
    end;
    suppose  y > n + m;
      then y in seq(n + m, k) by A8, Th73;
      hence thesis by XBOOLE_0:def 3;
    end;
  end;
  hence thesis by A6,XBOOLE_0:def 10;
end;

theorem Th78:
  primeNumbers(n,m) \/ primeNumbers(n+m,k)
    =
  primeNumbers(n,m+k)
proof
  primeNumbers(n,m)= seq(n,m)/\ SetPrimes &
  primeNumbers(n+m,k)= seq(n+m,k)/\ SetPrimes by NUMBER14:def 17;
  hence primeNumbers(n,m)\/primeNumbers(n+m,k)
    = (seq(n,m)\/ seq(n+m,k))/\ SetPrimes by XBOOLE_1:23
   .= seq(n,m+k) /\ SetPrimes by Th77
   .= primeNumbers(n,m+k) by NUMBER14:def 17;
end;

theorem Th79:
   card primeNumbers(n,m+k)
     =
   card primeNumbers(n,m) + card primeNumbers(n+m,k)
proof
  card (primeNumbers(n,m) \/ primeNumbers(n+m,k)) =
    card primeNumbers(n,m) + card primeNumbers(n+m,k)
    by CARD_2:40,Th76;
  hence thesis by Th78;
end;

theorem Th80:
  (n+1 is prime implies primeNumbers(n,1)={n+1}) &
  (not n+1 is prime implies primeNumbers(n,1)={})
proof
  hereby assume
A1: n+1 is prime;
    n < n+1 by NAT_1:13;
    then
A2: n+1 in primeNumbers(n,1) by A1,Th74;
    primeNumbers(n,1) c= {n+1}
    proof
      let y be object such that
A3:   y in primeNumbers(n,1);
      reconsider y as Nat by A3;
      n < y by A3,Th74;
      then n+1 <= y <= n+1 by A3,Th74,NAT_1:13;
      then y = n+1 by XXREAL_0:1;
      hence thesis by TARSKI:def 1;
    end;
    hence primeNumbers(n,1)={n+1} by A2,ZFMISC_1:33;
  end;
  assume
A4:not n+1 is prime;
  assume primeNumbers(n,1)<>{};
  then consider y be object such that
A5:y in primeNumbers(n,1) by XBOOLE_0:def 1;
  reconsider y as Nat by A5;
  n<y by A5,Th74;
  then n+1 <= y <= n+1 by A5,Th74,NAT_1:13;
  then y = n+1 by XXREAL_0:1;
  hence thesis by A4,A5,Th74;
end;

theorem Th81:
  (n+1 is prime implies card primeNumbers(n,1)=1) &
  (not n+1 is prime implies card primeNumbers(n,1)=0)
proof
  hereby assume n+1 is prime;
    then primeNumbers(n,1)={n+1} by Th80;
    hence card primeNumbers(n,1)=1 by CARD_1:30;
  end;
  assume not n+1 is prime;
  then primeNumbers(n,1)={} by Th80;
  hence thesis;
end;

Lm4: card primeNumbers(n,4) =
       card primeNumbers(n,1) + card primeNumbers(n+1,1) +
       card primeNumbers(n+2,1) + card primeNumbers(n+3,1)
proof
A1:card primeNumbers(n+1+1,1+1) =
     card primeNumbers(n+1+1,1) + card primeNumbers(n+1+1+1,1) by Th79;
A2:card primeNumbers(n+1,2+1) =
     card primeNumbers(n+1,1) + card primeNumbers(n+1+1,2) by Th79;
  card primeNumbers(n,3+1) =
     card primeNumbers(n,1) + card primeNumbers(n+1,3) by Th79;
  hence thesis by A1,A2;
end;

theorem Th82:
  for n,k st k > 0 &
     ((n+1 is prime & n+k+1 is prime) or
     (not n+1 is prime & not n+k+1 is prime))
  holds
     card primeNumbers(n+1,k) = card primeNumbers(n,k)
proof
  let n,k such that
A1:k > 0 and
A2:(n+1 is prime & n+k+1 is prime) or
  (not n+1 is prime & not n+k+1 is prime);
  reconsider k1=k-1 as Nat by A1;
A3:card primeNumbers(n,1+k1)
  = card primeNumbers(n,1) + card primeNumbers(n+1,k1) by Th79;
  per cases by A2;
  suppose n+1 is prime & n+k+1 is prime;
    then card primeNumbers(n,1)=1 & card primeNumbers(n+1+k1,1) = 1
    by Th81;
    hence thesis by Th79,A3;
  end;
  suppose not n+1 is prime & not n+k+1 is prime;
    then card primeNumbers(n,1)=0 & card primeNumbers(n+1+k1,1) = 0
    by Th81;
    hence thesis by Th79,A3;
  end;
end;

theorem Th83:
  for n,k st k > 0 &
     not n+1 is prime & n+k+1 is prime
  holds
     card primeNumbers(n+1,k) = card primeNumbers(n,k)+1
proof
  let n,k be Nat such that
A1:k > 0 and
A2:not n+1 is prime & n+k+1 is prime;
  reconsider k1=k-1 as Nat by A1;
A3:card primeNumbers(n,1+k1)
    = card primeNumbers(n,1) + card primeNumbers(n+1,k1) by Th79;
  card primeNumbers(n,1)=0 & card primeNumbers(n+1+k1,1) = 1 by A2,Th81;
  hence thesis by Th79,A3;
end;

theorem Th84:
  for n,k st k > 0 &
     n+1 is prime & not n+k+1 is prime
  holds
     card primeNumbers(n+1,k) = card primeNumbers(n,k)-1
proof
  let n,k be Nat such that
A1:k > 0 and
A2:n+1 is prime & not n+k+1 is prime;
  reconsider k1=k-1 as Nat by A1;
A3:card primeNumbers(n+1,k1+1) =
  card primeNumbers(n+1,k1) + card primeNumbers(n+1+k1,1) by Th79;
A4:card primeNumbers(n,1+k1)
  = card primeNumbers(n,1) + card primeNumbers(n+1,k1) by Th79;
  card primeNumbers(n,1)=1 & card primeNumbers(n+1+k1,1) = 0 by A2,Th81;
  hence thesis by A3,A4;
end;

Lm5:
  card primeNumbers(0,21) = 8 &
  card primeNumbers(0,100)=25
proof
  0+1 = 1 & 1+1 = 2 & 2+1 = 3 & 3+1 = 4;
  then card primeNumbers(0,1)=0 & card primeNumbers(0+1,1)=1
    & card primeNumbers(0+2,1)=1 & card primeNumbers(0+3,1)=0
    by Th81,XPRIMES1:2,3,XPRIMES0:1,4;
  then
A1: card primeNumbers(0+0,4) = 0+1+1+0=2 by Lm4;
  4+1 = 5 & 5+1 = 6 & 6+1 = 7 & 7+1 = 8;
  then card primeNumbers(4,1)=1 & card primeNumbers(4+1,1)=0
    & card primeNumbers(4+2,1)=1 & card primeNumbers(4+3,1)=0
    by Th81,XPRIMES1:5,7,XPRIMES0:6,8;
  then card primeNumbers(0+4,4) = 1+0+1+0=2 by Lm4;
  then
A2: card primeNumbers(0,4+4) = 2 + 2=4 by Th79,A1;
  8+1 = 9 & 9+1 = 10 & 10+1 = 11 & 11+1 = 12;
  then card primeNumbers(8,1)=0 & card primeNumbers(8+1,1)=0
    & card primeNumbers(8+2,1)=1 & card primeNumbers(8+3,1)=0
    by Th81,XPRIMES1:11,XPRIMES0:9,10,12;
  then card primeNumbers(0+8,4) = 0+0+1+0=1 by Lm4;
  then
A3: card primeNumbers(0,8+4) = 4 + 1=5 by Th79,A2;
  12+1 = 13 & 13+1 = 14 & 14+1 = 15 & 15+1 = 16;
  then card primeNumbers(12,1)=1 & card primeNumbers(12+1,1)=0
    & card primeNumbers(12+2,1)=0 & card primeNumbers(12+3,1)=0
    by Th81,XPRIMES1:13,XPRIMES0:14,15,16;
  then card primeNumbers(0+12,4) = 1+0+0+0=1 by Lm4;
  then
A4: card primeNumbers(0,12+4) = 5 + 1=6 by Th79,A3;
  16+1 = 17 & 17+1 = 18 & 18+1 = 19 & 19+1 = 20;
  then card primeNumbers(16,1)=1 & card primeNumbers(16+1,1)=0
    & card primeNumbers(16+2,1)=1 & card primeNumbers(16+3,1)=0
    by Th81,XPRIMES1:17,19,XPRIMES0:18,20;
  then card primeNumbers(0+16,4) = 1+0+1+0=2 by Lm4;
  then
A5: card primeNumbers(0,16+4) = 6 + 2=8 by Th79,A4;
  21=20+1;
  then card primeNumbers(0+20,1) = 0 by Th81,XPRIMES0:21;
  then card primeNumbers(0,20+1) = card primeNumbers(0,20) + 0
    by Th79;
  hence card primeNumbers(0,21) = 8 by A5;
  20+1 = 21 & 21+1 = 22 & 22+1 = 23 & 23+1 = 24;
  then card primeNumbers(20,1)=0 & card primeNumbers(20+1,1)=0
    & card primeNumbers(20+2,1)=1 & card primeNumbers(20+3,1)=0
  by Th81,XPRIMES1:23,XPRIMES0:21,22,24;
  then card primeNumbers(0+20,4) = 0+0+1+0=1 by Lm4;
  then
A6: card primeNumbers(0,20+4) = 8 + 1=9 by Th79,A5;
  24+1 = 25 & 25+1 = 26 & 26+1 = 27 & 27+1 = 28;
  then card primeNumbers(24,1)=0 & card primeNumbers(24+1,1)=0
    & card primeNumbers(24+2,1)=0 & card primeNumbers(24+3,1)=0
    by Th81,XPRIMES0:25,26,27,28;
  then card primeNumbers(0+24,4) = 0+0+0+0=0 by Lm4;
  then
A7: card primeNumbers(0,24+4) = 9 + 0=9 by Th79,A6;
  28+1 = 29 & 29+1 = 30 & 30+1 = 31 & 31+1 = 32;
  then card primeNumbers(28,1)=1 & card primeNumbers(28+1,1)=0
    & card primeNumbers(28+2,1)=1 & card primeNumbers(28+3,1)=0
    by Th81,XPRIMES1:29,31,XPRIMES0:30,32;
  then card primeNumbers(0+28,4) = 1+0+1+0=2 by Lm4;
  then
A8: card primeNumbers(0,28+4) = 9 + 2=11 by Th79,A7;
  32+1 = 33 & 33+1 = 34 & 34+1 = 35 & 35+1 = 36;
  then card primeNumbers(32,1)=0 & card primeNumbers(32+1,1)=0
    & card primeNumbers(32+2,1)=0 & card primeNumbers(32+3,1)=0
    by Th81,XPRIMES0:33,34,35,36;
  then card primeNumbers(0+32,4) = 0+0+0+0=0 by Lm4;
  then
A9: card primeNumbers(0,32+4) = 11 + 0=11 by Th79,A8;
  36+1 = 37 & 37+1 = 38 & 38+1 = 39 & 39+1 = 40;
  then card primeNumbers(36,1)=1 & card primeNumbers(36+1,1)=0
    & card primeNumbers(36+2,1)=0 & card primeNumbers(36+3,1)=0
    by Th81,XPRIMES1:37,XPRIMES0:38,39,40;
  then card primeNumbers(0+36,4) = 1+0+0+0=1 by Lm4;
  then
A10: card primeNumbers(0,36+4) = 11 + 1=12 by Th79,A9;
  40+1 = 41 & 41+1 = 42 & 42+1 = 43 & 43+1 = 44;
  then card primeNumbers(40,1)=1 & card primeNumbers(40+1,1)=0
    & card primeNumbers(40+2,1)=1 & card primeNumbers(40+3,1)=0
    by Th81,XPRIMES1:41,43,XPRIMES0:42,44;
  then card primeNumbers(0+40,4) = 1+0+1+0=2 by Lm4;
  then
A11: card primeNumbers(0,40+4) = 12 + 2=14 by Th79,A10;
  44+1 = 45 & 45+1 = 46 & 46+1 = 47 & 47+1 = 48;
  then card primeNumbers(44,1)=0 & card primeNumbers(44+1,1)=0
    & card primeNumbers(44+2,1)=1 & card primeNumbers(44+3,1)=0
    by Th81,XPRIMES1:47,XPRIMES0:45,46,48;
  then card primeNumbers(0+44,4) = 0+0+1+0=1 by Lm4;
  then
A12: card primeNumbers(0,44+4) = 14 + 1=15 by Th79,A11;
  48+1 = 49 & 49+1 = 50 & 50+1 = 51 & 51+1 = 52;
  then card primeNumbers(48,1)=0 & card primeNumbers(48+1,1)=0
    & card primeNumbers(48+2,1)=0 & card primeNumbers(48+3,1)=0
    by Th81,XPRIMES0:49,50,51,52;
  then card primeNumbers(0+48,4) = 0+0+0+0=0 by Lm4;
  then
A13: card primeNumbers(0,48+4) = 15 + 0=15 by Th79,A12;
  52+1 = 53 & 53+1 = 54 & 54+1 = 55 & 55+1 = 56;
  then card primeNumbers(52,1)=1 & card primeNumbers(52+1,1)=0
    & card primeNumbers(52+2,1)=0 & card primeNumbers(52+3,1)=0
    by Th81,XPRIMES1:53,XPRIMES0:54,55,56;
  then card primeNumbers(0+52,4) = 1+0+0+0=1 by Lm4;
  then
A14: card primeNumbers(0,52+4) = 15 + 1=16 by Th79,A13;
  56+1 = 57 & 57+1 = 58 & 58+1 = 59 & 59+1 = 60;
  then card primeNumbers(56,1)=0 & card primeNumbers(56+1,1)=0
    & card primeNumbers(56+2,1)=1 & card primeNumbers(56+3,1)=0
    by Th81,XPRIMES1:59,XPRIMES0:57,58,60;
  then card primeNumbers(0+56,4) = 0+0+1+0=1 by Lm4;
  then
A15: card primeNumbers(0,56+4) = 16 + 1=17 by Th79,A14;
  60+1 = 61 & 61+1 = 62 & 62+1 = 63 & 63+1 = 64;
  then card primeNumbers(60,1)=1 & card primeNumbers(60+1,1)=0
    & card primeNumbers(60+2,1)=0 & card primeNumbers(60+3,1)=0
    by Th81,XPRIMES1:61,XPRIMES0:62,63,64;
  then card primeNumbers(0+60,4) = 1+0+0+0=1 by Lm4;
  then
A16: card primeNumbers(0,60+4) = 17 + 1=18 by Th79,A15;
  64+1 = 65 & 65+1 = 66 & 66+1 = 67 & 67+1 = 68;
  then card primeNumbers(64,1)=0 & card primeNumbers(64+1,1)=0
    & card primeNumbers(64+2,1)=1 & card primeNumbers(64+3,1)=0
    by Th81,XPRIMES1:67,XPRIMES0:65,66,68;
  then card primeNumbers(0+64,4) = 0+0+1+0=1 by Lm4;
  then
A17: card primeNumbers(0,64+4) = 18 + 1=19 by Th79,A16;
  68+1 = 69 & 69+1 = 70 & 70+1 = 71 & 71+1 = 72;
  then card primeNumbers(68,1)=0 & card primeNumbers(68+1,1)=0
    & card primeNumbers(68+2,1)=1 & card primeNumbers(68+3,1)=0
    by Th81,XPRIMES1:71,XPRIMES0:69,70,72;
  then card primeNumbers(0+68,4) = 0+0+1+0=1 by Lm4;
  then
A18: card primeNumbers(0,68+4) = 19 + 1=20 by Th79,A17;
  72+1 = 73 & 73+1 = 74 & 74+1 = 75 & 75+1 = 76;
  then card primeNumbers(72,1)=1 & card primeNumbers(72+1,1)=0
    & card primeNumbers(72+2,1)=0 & card primeNumbers(72+3,1)=0
    by Th81,XPRIMES1:73,XPRIMES0:74,75,76;
  then card primeNumbers(0+72,4) = 1+0+0+0=1 by Lm4;
  then
A19: card primeNumbers(0,72+4) = 20 + 1=21 by Th79,A18;
  76+1 = 77 & 77+1 = 78 & 78+1 = 79 & 79+1 = 80;
  then card primeNumbers(76,1)=0 & card primeNumbers(76+1,1)=0
    & card primeNumbers(76+2,1)=1 & card primeNumbers(76+3,1)=0
    by Th81,XPRIMES1:79,XPRIMES0:77,78,80;
  then card primeNumbers(0+76,4) = 0+0+1+0=1 by Lm4;
  then
A20: card primeNumbers(0,76+4) = 21 + 1=22 by Th79,A19;
  80+1 = 81 & 81+1 = 82 & 82+1 = 83 & 83+1 = 84;
  then card primeNumbers(80,1)=0 & card primeNumbers(80+1,1)=0
    & card primeNumbers(80+2,1)=1 & card primeNumbers(80+3,1)=0
    by Th81,XPRIMES1:83,XPRIMES0:81,82,84;
  then card primeNumbers(0+80,4) = 0+0+1+0=1 by Lm4;
  then
A21: card primeNumbers(0,80+4) = 22 + 1=23 by Th79,A20;
  84+1 = 85 & 85+1 = 86 & 86+1 = 87 & 87+1 = 88;
  then card primeNumbers(84,1)=0 & card primeNumbers(84+1,1)=0
    & card primeNumbers(84+2,1)=0 & card primeNumbers(84+3,1)=0
    by Th81,XPRIMES0:85,86,87,88;
  then card primeNumbers(0+84,4) = 0+0+0+0=0 by Lm4;
  then
A22: card primeNumbers(0,84+4) = 23 + 0=23 by Th79,A21;
  88+1 = 89 & 89+1 = 90 & 90+1 = 91 & 91+1 = 92;
  then card primeNumbers(88,1)=1 & card primeNumbers(88+1,1)=0
    & card primeNumbers(88+2,1)=0 & card primeNumbers(88+3,1)=0
    by Th81,XPRIMES1:89,XPRIMES0:90,91,92;
  then card primeNumbers(0+88,4) = 1+0+0+0=1 by Lm4;
  then
A23: card primeNumbers(0,88+4) = 23 + 1=24 by Th79,A22;
  92+1 = 93 & 93+1 = 94 & 94+1 = 95 & 95+1 = 96;
  then card primeNumbers(92,1)=0 & card primeNumbers(92+1,1)=0
    & card primeNumbers(92+2,1)=0 & card primeNumbers(92+3,1)=0
    by Th81,XPRIMES0:93,94,95,96;
  then card primeNumbers(0+92,4) = 0+0+0+0=0 by Lm4;
  then
A24: card primeNumbers(0,92+4) = 24 + 0=24 by Th79,A23;
  96+1 = 97 & 97+1 = 98 & 98+1 = 99 & 99+1 = 100;
  then card primeNumbers(96,1)=1 & card primeNumbers(96+1,1)=0
    & card primeNumbers(96+2,1)=0 & card primeNumbers(96+3,1)=0
    by Th81,XPRIMES1:97,XPRIMES0:98,99,100;
  then card primeNumbers(0+96,4) = 1+0+0+0=1 by Lm4;
  then card primeNumbers(0,96+4) = 24 + 1=25 by Th79,A24;
  hence thesis;
end;

theorem Th85:
  card primeNumbers(1,100) = 26 &
  (for k being Nat st
    k = 0 or k = 2 or k = 3 or k = 4 or k = 9 or k = 10 holds
  card primeNumbers(k,100) = 25) &
  for k being Nat st
    k = 5 or k = 6 or k = 7 or k = 8 holds
     card primeNumbers(k,100) < 25
proof
   not 0+1 is prime & 0+100+1 is prime by XPRIMES1:101;
   then
A1:card primeNumbers(0+1,100) = 25+1=26 by Lm5,Th83;
   1+1 is prime & not 1+100+1 is prime by XPRIMES0:102,XPRIMES1:2;
   then
A2:card primeNumbers(1+1,100) = 26-1=25 by A1,Th84;
A3:2+1 is prime & 2+100+1 is prime by XPRIMES1:3,103;
   then
A4:card primeNumbers(2+1,100) = 25 by A2,Th82;
A5: not 3+1 is prime & not 3+100+1 is prime by XPRIMES0:4,104;
   then
A6:card primeNumbers(3+1,100) = 25 by A4,Th82;
  4+1 is prime & not 4+100+1 is prime by XPRIMES0:105,XPRIMES1:5;
   then
A7:card primeNumbers(4+1,100) = 25-1=24 by A6,Th84;
  not 5+1 is prime & not 5+100+1 is prime by XPRIMES0:6,106;
   then
A8:card primeNumbers(5+1,100) = 24 by A7,Th82;
  6+1 is prime & 6+100+1 is prime by XPRIMES1:7,107;
   then
A9:card primeNumbers(6+1,100) = 24 by A8,Th82;
  not 7+1 is prime & not 7+100+1 is prime by XPRIMES0:8,108;
   then
A10:card primeNumbers(7+1,100) = 24 by A9,Th82;
  not 8+1 is prime & 8+100+1 is prime by XPRIMES0:9,XPRIMES1:109;
   then
A11:card primeNumbers(8+1,100) = 24+1 by A10,Th83;
  not 9+1 is prime & not 9+100+1 is prime by XPRIMES0:10,110;
  hence thesis by Lm5,A1,A3,A5,A4,A7,A8,A9,A10,A11,Th82;
end;

theorem Th86:
  for n,k,p being Integer st p divides k
    holds n in multiples(p) iff n+k in multiples(p)
proof
  let n,k,p be Integer such that
A1:p divides k;
  thus n in multiples(p) implies n+k in multiples(p)
  proof
    assume n in multiples(p);
    then p divides n by NUMBER14:62;
    hence thesis by NUMBER14:62,A1,WSIERP_1:4;
  end;
  assume n+k in multiples(p);
  then p divides n+k by NUMBER14:62;
  hence thesis by NUMBER14:62,A1,INT_2:1;
end;

theorem Th87:
  s in seq(n,k) iff s+d in seq(n+d,k)
proof
  hereby assume s in seq(n,k);
    then n < s <=n+k by Th73;
    then n+d < s+d <=n+k+d=n+d+k by XREAL_1:7,8;
    hence s+d in seq(n+d,k) by Th73;
  end;
  assume s+d in seq(n+d,k);
  then n+d < s+d <=n+d+k=n+k+d by Th73;
  then n < s <=n+k by XREAL_1:7,8;
  hence thesis by Th73;
end;

theorem Th88:
  for p,q,r,s,t being Integer st
          p divides d & q divides d &r divides d &
          s divides d & t divides d
  holds
     card (seq(n,k)  /\ (multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t)))
  =
     card (seq(n+d,k)  /\ (multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t)))
proof
  let p,q,r,s,t be Integer such that
A1: p divides d & q divides d &r divides d &
          s divides d & t divides d;
  set S=seq(n,k),Sd=seq(n+d,k);
  set Mp=multiples(p),Mq=multiples(q),Mr=multiples(r),
       Ms=multiples(s),Mt=multiples(t),M=Mp\/Mq\/Mr\/Ms\/Mt;
  reconsider D=d as Element of NAT by ORDINAL1:def 12;
  deffunc F(Element of NAT) = $1+D;
  consider f be Function of NAT,NAT such that
A2:for x being Element of NAT holds f.x = F(x) from FUNCT_2:sch 4;
A3:dom f = NAT by FUNCT_2:def 1;
A4:f.:(S/\M) c= (Sd/\M)
  proof
    let y be object;assume y in f.:(S/\M);
    then consider x be object such that
A5:  x in dom f & x in S/\M & y = f.x  by FUNCT_1:def 6;
    reconsider x as Element of NAT by A5;
    x in Mp\/Mq\/Mr\/Ms or x in Mt by A5,XBOOLE_0:def 3;
    then x in Mp\/Mq\/Mr or x in Ms or x in Mt by XBOOLE_0:def 3;
    then x in Mp\/Mq or x in Mr or x in Ms or x in Mt by XBOOLE_0:def 3;
    then x in Mp or x in Mq or x in Mr or x in Ms or x in Mt by XBOOLE_0:def 3;
    then x+D in Mp or x+D in Mq or x+D in Mr or x+D in Ms or x+D in Mt
      by A1,Th86;
    then x+D in Mp \/ Mq or x+D in Mr or x+D in Ms or x+D in Mt
      by XBOOLE_0:def 3;
    then x+D in Mp \/ Mq \/ Mr or x+D in Ms or x+D in Mt by XBOOLE_0:def 3;
    then x+D in Mp \/ Mq \/ Mr \/ Ms or x+D in Mt by XBOOLE_0:def 3;
    then x+D in M & x+D in Sd by XBOOLE_0:def 3,A5,Th87;
    then x+D in M/\Sd by XBOOLE_0:def 4;
    hence thesis by A2,A5;
  end;
  Sd /\M c= f.:(S/\M)
  proof
    let y be object;
    assume
A6: y in Sd/\M;
    then reconsider y as Nat;
    n+d < y by A6,Th73;
    then d=n+d-n <= y-0 by XREAL_1:13;
    then reconsider yd=y-d as Element of NAT by NAT_1:21;
A7: y = yd+D;
    then
A8: f.yd = y by A2;
    y in Mp \/ Mq \/ Mr \/ Ms or y in Mt by A6,XBOOLE_0:def 3;
    then y in Mp \/ Mq \/ Mr or y in Ms or y in Mt by XBOOLE_0:def 3;
    then y in Mp \/ Mq or y in Mr or y in Ms or y in Mt by XBOOLE_0:def 3;
    then y in Mp or y in Mq or y in Mr or y in Ms or y in Mt
      by XBOOLE_0:def 3;
    then yd in Mp or yd in Mq or yd in Mr or yd in Ms or yd in Mt
      by A7,A1,Th86;
    then yd in Mp \/ Mq or yd in Mr or yd in Ms or yd in Mt by XBOOLE_0:def 3;
    then yd in Mp \/ Mq \/ Mr or yd in Ms or yd in Mt by XBOOLE_0:def 3;
    then yd in Mp \/ Mq \/ Mr \/ Ms or yd in Mt by XBOOLE_0:def 3;
    then yd in M & yd in S by A7,A6,Th87,XBOOLE_0:def 3;
    then yd in M/\S by XBOOLE_0:def 4;
    hence thesis by A8,A3,FUNCT_1:def 6;
  end;
  then
A9:Sd /\M = f.:(S/\M) by A4,XBOOLE_0:def 10;
A10:f is one-to-one
  proof
    now let x1,x2 be object;
      assume
A11:  x1 in NAT & x2 in NAT & f.x1=f.x2;
      then reconsider n1=x1,n2=x2 as Element of NAT;
      f.x1=n1+D & f.x2=n2+D by A2;
      hence x1=x2 by A11;
    end;
    hence thesis by A3,FUNCT_1:def 4;
  end;
  (S/\M),f.:(S/\M) are_equipotent by A10,A3,XBOOLE_1:1,CARD_1:33;
  hence thesis by A9,CARD_1:5;
end;

theorem Th89:
  for p,q,r,s,t being Integer st
        p divides d & q divides d &r divides d &
        s divides d & t divides d
  holds
      card (seq(n,d) /\ (multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t)))
   =
      card (seq(n+k,d)  /\ (multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t)))
proof
  let p,q,r,s,t be Integer such that A1:
          p divides d & q divides d &r divides d &
          s divides d & t divides d;
  per cases;
  suppose d=0;
    then seq(n,d)={} = seq(n+k,d) by CALCUL_2:2;
    hence thesis;
  end;
  suppose A2:d>0;
    set km=k mod d,kd = k div d;
    set M=multiples(p)\/multiples(q)\/multiples(r)\/
    multiples(s)\/multiples(t);
    km < d by A2,INT_1:58;
    then reconsider dkm=d-km as Element of NAT by NAT_1:21;
A3: seq(n,km)/\M misses seq(n+km,dkm)/\M by Th75,XBOOLE_1:76;
    seq(n,km+dkm) = seq(n,km)\/seq(n+km,dkm) by Th77;
    then seq(n,d)/\M = (seq(n,km)/\M)\/(seq(n+km,dkm)/\M) by XBOOLE_1:23;
    then
A4: card (seq(n,d)/\M) =
    card (seq(n,km)/\M) + card (seq(n+km,dkm)/\M) by A3,CARD_2:40;
    A5:seq(n+k,dkm)/\M misses seq(n+k+dkm,km)/\M by Th75,XBOOLE_1:76;
    seq(n+k,dkm+km) = seq(n+k,dkm)\/seq(n+k+dkm,km) by Th77;
    then seq(n+k,d)/\M = (seq(n+k,dkm)/\M)\/(seq(n+k+dkm,km)/\M)
    by XBOOLE_1:23;
    then
A6: card (seq(n+k,d)/\M) =
    card (seq(n+k,dkm)/\M) + card (seq(n+k+dkm,km)/\M) by A5,CARD_2:40;
A7: k = kd *d + km by A2,INT_1:59;
    then
A8: n+km+kd*d = n+k;
    p divides kd*d & q divides kd*d &r divides kd*d &
    s divides kd*d & t divides kd*d by A1,INT_2:2;
    then
A9: card (seq(n+km,dkm)/\M) = card (seq(n+k,dkm)/\M) by A8,Th88;
A10:n+k+dkm = n+(kd+1)*d by A7;
    p divides (kd+1)*d & q divides (kd+1)*d &r divides (kd+1)*d &
    s divides (kd+1)*d & t divides (kd+1)*d by A1,INT_2:2;
    hence thesis by A4,A6,A9,A10,Th88;
  end;
end;

theorem Th90:
  for p,q,r,s,t being Integer st
       p divides d & q divides d & r divides d &
       s divides d & t divides d
  holds
  card (seq(n,k*d) /\ (multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t)))
  =
  k*card (seq(0,d) /\ (multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t)))
proof
  let p,q,r,s,t be Integer such that
A1:       p divides d & q divides d &r divides d &
          s divides d & t divides d;
  set M=multiples(p)\/multiples(q)\/multiples(r)\/
                   multiples(s)\/multiples(t);
  defpred P[Nat] means $1*card (seq(0,d)/\M) = card (seq(n,$1*d)  /\M);
  seq(n,0*d)={} by CALCUL_2:2;
  then
A2:P[0];
A3:for i being Nat holds P[i] implies P[i+1]
  proof
    let i be Nat such that
A4: P[i];
A5: card (seq(0+(n+i*d),d)/\M) = card (seq(0,d)/\M) by A1,Th89;
A6: seq(n,i*d)/\M misses seq(n+i*d,d)/\M by Th75,XBOOLE_1:76;
    seq(n,i*d+d) = seq(n,i*d)\/seq(n+i*d,d) by Th77;
    then seq(n,i*d+d)/\M = (seq(n,i*d)/\M)\/(seq(n+i*d,d)/\M) by XBOOLE_1:23;
    then  card (seq(n,i*d+d)/\M) =
    card (seq(n,i*d)/\M) + card (seq(n+i*d,d)/\M) by A6,CARD_2:40;
    hence thesis by A4,A5;
  end;
  for i being Nat holds P[i] from NAT_1:sch 2(A2,A3);
  hence thesis;
end;

theorem Th91:
  4 = card (seq(6*n,6) /\ (multiples(2)\/multiples(3)))
    & {6*n+1,6*n+5} = (seq(6*n,6) \ (multiples(2)\/multiples(3)))
proof
  set S=seq(6*n,6);
  set M2=multiples(2),M3=multiples(3);
  6*n < 6*n+1 <= 6*n+1+5=6*n+6 by NAT_1:11,13;
  then
A1: 6*n+1 in S by Th73;
  6*n+0 < 6*n+5 < 6*n+5+1=6*n+6 by NAT_1:13,XREAL_1:6;
  then
A2: 6*n+5 in S by Th73;
  6*n+1 = 2*(3*n)+1 & 6*n+1 = 3*(2*n)+1;
  then not 6*n+1 in M2 & not 6*n+1 in M3 by NUMBER14:62,NAT_4:9;
  then not 6*n+1 in M2\/M3 by XBOOLE_0:def 3;
  then
A3: 6*n+1 in S\(M2\/M3) by A1,XBOOLE_0:def 5;
  6*n+5 = 2*(3*n+2)+1 & 6*n+5 = 3*(2*n+1)+2;
  then not 6*n+5 in M2 & not 6*n+5 in M3 by NUMBER14:62,NAT_4:9;
  then not 6*n+5 in M2\/M3 by XBOOLE_0:def 3;
  then 6*n+5 in S\(M2\/M3) by A2,XBOOLE_0:def 5;
  then
A4:{6*n+1,6*n+5} c= S\(M2\/M3) by A3,ZFMISC_1:32;
A5: S\(M2\/M3)  c= {6*n+1,6*n+5}
  proof
    let y be object;
    assume
A6: y in S\(M2\/M3);
    then reconsider y as Nat;
    not y in M2\/M3 by A6,XBOOLE_0:def 5;
    then
A7: not y in M2 & not y in M3 by XBOOLE_0:def 3;
    6*n+1 <= y <= 6*n+6 by A6,CALCUL_2:1;
    then y = 6*n+1+0 or ... or y = 6*n+1+5 by NAT_1:62;
    then per cases;
    suppose y = 6*n+1+0 or y = 6*n+1+4;
      hence thesis by TARSKI:def 2;
    end;
    suppose y = 6*n+1+1;
      then y = 2*(3*n+1);
      then 2 divides y;
      hence thesis by A7,NUMBER14:62;
    end;
    suppose y = 6*n+1+2;
      then y = 3*(2*n+1);
      then 3 divides y;
      hence thesis by A7,NUMBER14:62;
    end;
    suppose y = 6*n+1+3;
      then y = 2*(3*n+2);
      then 2 divides y;
      hence thesis by A7,NUMBER14:62;
    end;
    suppose y = 6*n+1+5;
      then y = 2*(3*n+3);
      then 2 divides y;
      hence thesis by A7,NUMBER14:62;
    end;
  end;
  then
A8: S\(M2\/M3)  = {6*n+1,6*n+5} by A4,XBOOLE_0:def 10;
  6*n+1<>6*n+5;
  then
A9:card (S\(M2\/M3))=2 by A8,CARD_2:57;
A10:card S = 6 by NUMBER14:73;
  S = (S/\(M2\/M3)) \/ (S\(M2\/M3));
  then 6 = card (S/\(M2\/M3)) + card (S\(M2\/M3))
    by A10,XBOOLE_1:89,CARD_2:40;
  hence thesis by A4,XBOOLE_0:def 10,A5,A9;
end;

theorem Th92:
  22 = card (seq(0,30) /\ (multiples(2)\/multiples(3)\/multiples(5)))
proof
  set M2=multiples(2),M3=multiples(3),M23=M2\/M3,M5=multiples(5),M = M23\/M5;
  set S = seq(0,30);
  M23\/M5 = M23 \/ (M5 \ M23) by XBOOLE_1:39;
  then
A1:S/\M = (S/\M23)\/(S/\(M5\ M23)) by XBOOLE_1:23;
A2: card (S/\M23) = 20
  proof
    6=2*3;
    then
A3:   2 divides 6 & 3 divides 6;
    M23 = M23\/M3 by XBOOLE_1:6
    .= M23\/M3\/M3 by XBOOLE_1:6
    .= M23\/M3\/M3\/M3 by XBOOLE_1:6;
    then card(seq(0,5*6)/\M23) = 5* card(seq(0*6,6)/\M23) by A3,Th90
    .= 5*4 by Th91;
    hence thesis;
  end;
A4:S/\(M5\ M23) = {5,25}
  proof
    2*2+1=5 & 12*2+1=25;
    then not 2 divides 5 & not 2 divides 25;
    then
A5: not 5 in M2 & not 25 in M2 by NUMBER14:62;
    3*1+2=5 & 8*3+1=25;
    then not 5 in M3 & not 25 in M3 by NAT_4:9,NUMBER14:62;
    then
A6: not 5 in M23 & not 25 in M23 by A5,XBOOLE_0:def 3;
    5*1=5 & 5*5=25;
    then 5 divides 5 & 5 divides 25;
    then 5 in M5 & 25 in M5 by NUMBER14:62;
    then
A7: 5 in M5\ M23 & 25 in M5\ M23 by A6,XBOOLE_0:def 5;
    0<5<=0+30 & 0<25<=0+30;
    then 5 in S & 25 in S by Th73;
    then 5 in S/\(M5\ M23) & 25 in S/\(M5\ M23) by A7,XBOOLE_0:def 4;
    then
A8: {5,25} c= S/\(M5\ M23) by ZFMISC_1:32;
    S/\(M5\ M23)c= {5,25}
    proof
      let y be object;
      assume
A9:   y in S/\(M5\ M23);
      then reconsider y as Nat;
A10:  y in M5 & not y in M23 by A9,XBOOLE_0:def 5;
      then consider k be Nat such that
A11:  y = 5*k by NAT_D:def 3,NUMBER14:62;
      not y in M2 & not y in M3 by A10,XBOOLE_0:def 3;
      then
A12:  not 2 divides y & not 3 divides y by NUMBER14:62;
      0*5 = 0 < 5*k <= 0+30 =5*6 by A9,A11,Th73;
      then 0 < k <=6 by XREAL_1:68;
      then k=0 or ... or k = 6;
      then per cases by A9,A11,Th73;
      suppose k=2 or k=4 or k=6;
        then y = 2*5 or y = 2*(5*2) or y = 2*(5*3) by A11;
        hence thesis by A12;
      end;
      suppose k=3;
        hence thesis by A11,A12;
      end;
      suppose k = 1 or k=5;
        hence thesis by A11,TARSKI:def 2;
      end;
    end;
    hence thesis by A8,XBOOLE_0:def 10;
  end;
A13:card (S/\(M5\ M23)) = 2 by A4,CARD_2:57;
  M23 misses (M5 \ M23) by XBOOLE_1:79;
  then card (S/\M) = card (S/\M23) + card (S/\(M5\ M23))
   by A1,XBOOLE_1:76,CARD_2:40;
  hence thesis by A2,A13;
end;

Lm6:for i being Nat holds
      not i in multiples(2)\/multiples(3)\/multiples(5) iff
     not 2 divides i & not 3 divides i & not 5 divides i
proof
  let i be Nat;
  hereby
    assume  not i in multiples(2)\/multiples(3)\/multiples(5);
    then not i in multiples(2)\/multiples(3) & not i in  multiples(5)
    by XBOOLE_0:def 3;
    then not i in  multiples(2) & not i in  multiples(3) &
    not i in  multiples(5) by XBOOLE_0:def 3;
    hence not 2 divides i & not 3 divides i & not 5 divides i
      by NUMBER14:62;
  end;
  assume  not 2 divides i & not 3 divides i &
  not 5 divides i;
  then A1:not i in  multiples(2) & not i in  multiples(3) &
  not i in  multiples(5) by NUMBER14:62;
  then not i in  multiples(2)\/ multiples(3) by XBOOLE_0:def 3;
  hence thesis by A1,XBOOLE_0:def 3;
end;

Lm7:
  for n,c being Nat st 0 <= n < 30 &
     c = card (seq(n,100) /\
             (multiples(2)\/multiples(3)\/multiples(5)))
     holds
      c >= 72 & (c = 72 implies n = 9 or n= 10)
proof
   let n,c be Nat such that
A1:0<= n < 30 and
A2 :c = card (seq(n,100) /\
             (multiples(2)\/multiples(3)\/multiples(5)));
   set M2=multiples(2),M3=multiples(3),M23=M2\/M3,M5=multiples(5),M = M23\/M5;
A3:seq(n,10)/\M misses seq(n+10,30*3)/\M by Th75,XBOOLE_1:76;
   seq(n,10+30*3) = seq(n,10)\/seq(n+10,30*3) by Th77;
   then seq(n,10+30*3)/\M = (seq(n,10)/\M)\/(seq(n+10,30*3)/\M) by XBOOLE_1:23;
   then
A4: card (seq(n,10+30*3)/\M) =
   card (seq(n,10)/\M) + card (seq(n+10,30*3)/\M) by A3,CARD_2:40;
A5: card (seq(n+10,30*3)/\M) = 66
   proof
     30= 2*3*5 = 2*(3*5) = 3*(2*5);
     then
A6:  2 divides 30 & 3 divides 30 & 5 divides 30;
     M = M\/M5 by XBOOLE_1:6
     .= M\/M5\/M5 by XBOOLE_1:6;
     then card(seq(n+10,30*3)/\M) = 3* card(seq(0,30)/\M) by A6,Th90
     .= 3*22 by Th92;
     hence thesis;
   end;
   A7: 2 divides 2*2; A8: 2 divides 2*3; A9: 2 divides 2*4;
   A10: 2 divides 2*5; A11:2 divides 2*6; A12:2 divides 2*7;
   A13:2 divides 2*8; A14:2 divides 2*9; A15:2 divides 2*10;
   A16:2 divides 2*11; A17:2 divides 2*12; A18:2 divides 2*13;
   A19:2 divides 2*14; A20:2 divides 2*15; A21:2 divides 2*16;
   A22:2 divides 2*17; A23:2 divides 2*18; A24:2 divides 2*19;
   A25:3 divides 3*3; A26:3 divides 3*5; A27:3 divides 3*7;
   A28:3 divides 3*9; A29:3 divides 3*11; A30:3 divides 3*13;
   A31:5 divides 5*5; A32:5 divides 5*7;
A33: 10 in M & 12 in M & 14 in M & 15 in M & 16 in M & 18 in M & 20 in M
     by Lm6,A10,A11,A12,A26,A13,A14,A15;
A34:seq(9,10)\M c={11,13,17,19}
   proof
    let y be object such that
A35: y in seq(9,10)\M;
     reconsider y as Nat by A35;
     10=9+1 <= y <=9+10 by CALCUL_2:1,A35;
     then y = 10+0 or ... or y = 10+9 by NAT_1:62;
     hence thesis by A33,A35,XBOOLE_0:def 5,ENUMSET1:def 2;
   end;
A36:seq(10,10)\M c={11,13,17,19}
   proof
     let y be object such that
A37: y in seq(10,10)\M;
     reconsider y as Nat by A37;
     11=10+1 <= y <=10+10=11+9 by A37,CALCUL_2:1;
     then y = 11+0 or ... or y = 11+9 by NAT_1:62;
     hence thesis by A33,A37,XBOOLE_0:def 5,ENUMSET1:def 2;
   end;
   card (seq(9,10)\M)<= card {11,13,17,19}<= 4 &
   card (seq(10,10)\M)<= card {11,13,17,19} by A34,A36,NAT_1:43,CARD_2:52;
   then
A38: card (seq(9,10)\M)<=4 & card (seq(10,10)\M) <= 4
   by XXREAL_0:2;
A39: for x,y,z being Element of NAT
   for i,j being Nat st
   (for k being Nat st (i+1+0= k or... or i+1+(j+9)=k) & not k in M holds
   k=x or k=y or k = z)
   holds for w being Nat st i<=w <= i+j holds card (seq(w,10)\M )<=3
   proof
     let x,y,z be Element of NAT;
     let i,j be Nat such that
A40: for k being Nat st (i+1+0= k or... or i+1+(j+9)=k) & not k in M holds
     k=x or k=y or k = z;
     let w be Nat such that
A41: i<=w <= i+j;
     seq(w,10)\M c= {x,y,z}
     proof
       let a be object such that
A42:   a in seq(w,10)\M;
       reconsider a as Nat by A42;
A43:   a in seq(w,10) & not a in M by A42,XBOOLE_0:def 5;
       w < a <= w+10 <= i+j+10 by A41,Th73,A42,XREAL_1:6;
       then i < a <= i+j+10 by A41,XXREAL_0:2;
       then i+1+0 = i+1 <= a <= i+j+10 = i+1+(j+9) by NAT_1:13;
       then i+1+0= a or... or i+1+(j+9)=a by NAT_1:62;
       then a=x or a=y or a = z by A40,A43;
       hence thesis by ENUMSET1:def 1;
     end;
     then  card (seq(w,10)\M) <= card  {x,y,z} <= 3 by NAT_1:43,CARD_2:51;
     hence thesis by XXREAL_0:2;
   end;
A44: n <>9 & n <>10 implies card (seq(n,10)\M) <= 3
   proof
     assume
A45: n <>9 & n <>10;
     per cases by A1;
     suppose
A46:   0 <= n <= 2+0=2;
       for k being Nat st (0+1+0= k or... or 0+1+(2+9)=k) & not k in M holds
       k=1+0 or k=1+6 or k = 1+10
       proof
         let k be Nat;
         assume that
A47:     0+1+0= k or... or 0+1+(2+9)=k and
A48:     not k in M;
         1+0= k or... or 1+11=k by A47;
         hence thesis by A48,A7,A8,A9,A10,A11, A25,Lm6;
       end;
       hence thesis by A46,A39;
     end;
     suppose 2 < n <= 6;
       then
A49:   3= 2+1 <= n <= 3+3 by NAT_1:13;
       for k being Nat st (3+1+0= k or... or 3+1+(3+9)=k) & not k in M holds
       k=4+3 or k=4+7 or k = 4+9
       proof
         let k be Nat;
         assume that
A50:     3+1+0= k or... or 3+1+(3+9)=k and A51:not k in M;
         4+0= k or... or 4+12=k by A50;
         hence thesis by A51,A7,A8,A9,A10,A11,A12,A13,A25,A26,Lm6;
       end;
       hence thesis by A49,A39;
     end;
     suppose 6 < n <= 8;
       then
A52:   7= 6+1 <= n <= 7+1 by NAT_1:13;
       for k being Nat st (7+1+0= k or... or 7+1+(1+9)=k) & not k in M holds
       k=8+3 or k=8+5 or k = 8+9
       proof
         let k be Nat;
         assume that
A53:     7+1+0= k or... or 7+1+(1+9)=k and
A54:     not k in M;
         8+0= k or... or 8+10=k by A53;
         hence thesis by A54,A9,A10,A11,A12,A13,A14,A25,A26,Lm6;
       end;
       hence thesis by A52,A39;
     end;
     suppose 8 < n <= 10;
       then 9=8+1<=n <= 9+1 by NAT_1:13;
       hence thesis by A45,NAT_1:9;
     end;
     suppose 10 < n <= 12;
       then
A55:   11= 10+1 <= n <= 11+1 by NAT_1:13;
       for k being Nat st (11+1+0= k or... or 11+1+(1+9)=k) & not k in M holds
       k=12+1 or k=12+5 or k =12+7
       proof
         let k be Nat;
         assume that
A56:     11+1+0= k or... or 11+1+(1+9)=k and
A57:     not k in M;
         12+0= k or... or 12+10=k by A56;
         then per cases;
         suppose 12+0= k or 12+1= k;
           hence thesis by A57,A11,Lm6;
         end;
         suppose 12+2= k or 12+3= k;
           hence thesis by A57,A12,A26,Lm6;
         end;
         suppose 12+4= k or 12+5= k;
           hence thesis by A57,A13,Lm6;
         end;
         suppose 12+6= k or 12+7= k;
           hence thesis by A57,A14, Lm6;
         end;
         suppose 12+8= k or 12+9= k or 12+10= k;
           hence thesis by A57,A15,A16,A27, Lm6;
         end;
       end;
       hence thesis by A55,A39;
     end;
     suppose 12 < n <= 18;
       then
A58:   13= 12+1 <= n <= 13+5 by NAT_1:13;
       for k being Nat st (13+1+0= k or... or 13+1+(5+9)=k) & not k in M holds
       k=14+3 or k=14+5 or k =14+9
       proof
         let k be Nat;
         assume that
A59:     13+1+0= k or... or 13+1+(5+9)=k and
A60:     not k in M;
         14+0= k or... or 14+14=k by A59;
         hence thesis by A60,A12,A13,A14,A15,A16,A17,A18,A19,A26,A27,
           A28,A31,Lm6;
       end;
       hence thesis by A58,A39;
     end;
     suppose 18 < n <= 26;
       then
A61:   19= 18+1 <= n <= 19+7 by NAT_1:13;
       for k being Nat st (19+1+0= k or... or 19+1+(7+9)=k) & not k in M holds
       k=20+3 or k=20+9 or k =20+11
       proof
         let k be Nat;
         assume that
A62:     19+1+0= k or... or 19+1+(7+9)=k and
A63:     not k in M;
         20+0= k or... or 20+16=k by A62;
         then per cases;
         suppose 20+0 = k or 20+1 = k or  20+2 = k or 20+3 = k;
           hence thesis by A63,A15,A16,A27, Lm6;
         end;
         suppose 20+4 = k or 20+5 = k or  20+6 = k or 20+7 = k;
           hence thesis by A63,A17,A31,A18,A28,Lm6;
         end;
         suppose 20+8 = k or 20+9 = k or  20+10 = k or 20+11 = k;
           hence thesis by A63,A19,A20,Lm6;
         end;
         suppose 20+12 = k or 20+13 = k or  20+14 = k or 20+15 = k
           or 20+16 = k;
           hence thesis by A63,A21,A29,A22,A32,A23,Lm6;
         end;
       end;
       hence thesis by A61,A39;
     end;
     suppose 26 < n < 30=29+1;
       then
A64:   27= 26+1 <= n <= 27+2 by NAT_1:13;
       for k being Nat st (27+1+0= k or... or 27+1+(2+9)=k) & not k in M holds
         k=27+2 or k=27+4 or k =27+10
       proof
         let k be Nat;
         assume that
A65:     27+1+0= k or... or 27+1+(2+9)=k and A66:not k in M;
         28+0= k or... or 28+11=k by A65;
         then per cases;
         suppose k = 28+0 or k = 28+1;
           hence thesis by A66,A19,Lm6;
         end;
         suppose k = 28+2 or k = 28+3;
           hence thesis by A66,A20,Lm6;
         end;
         suppose k = 28+4 or k = 28+5;
           hence thesis by A66,A21,A29,Lm6;
         end;
         suppose k = 28+6 or k = 28+7;
           hence thesis by A66,A22,A32,Lm6;
         end;
         suppose k = 28+8 or k = 28+9;
           hence thesis by A66,A23,Lm6;
         end;
         suppose k = 28+10 or k = 28+11;
           hence thesis by A66,A24,A30,Lm6;
         end;
       end;
       hence thesis by A64,A39;
     end;
   end;
A67:card seq(n,10) = 10 by NUMBER14:73;
   seq(n,10) = (seq(n,10)/\M) \/ (seq(n,10)\M);
   then  10 = card (seq(n,10)/\M) + card (seq(n,10)\M)
     by A67,XBOOLE_1:89,CARD_2:40;
   then
A68: card (seq(n,10)/\M) = 10 - card (seq(n,10)\M);
A69: n <>9 & n <>10 implies c > 72
   proof
     assume  n <>9 & n <>10;
     then card (seq(n,10)/\M)>= 10-3 by A44,A68,XREAL_1:10;
     then card (seq(n,10+30*3)/\M) >= 66+7=72+1 by A4,A5,XREAL_1:6;
     hence thesis by A2,NAT_1:13;
   end;
   n=9 or n=10 implies c >= 72
   proof
     assume n=9 or n=10;
     then card (seq(n,10)/\M)>= 10-4 by A38,A68,XREAL_1:10;
     then card (seq(n,10+30*3)/\M) >= 66+6=72 by A4,A5,XREAL_1:6;
     hence thesis by A2;
   end;
   hence thesis by A69;
end;

theorem Th93:
  c = card (seq(n,100) /\
              (multiples(2)\/multiples(3)\/multiples(5)))
  implies
    c >= 72 & (c = 72 implies n mod 30 = 9 or n mod 30 = 10)
proof
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M = M2\/M3\/M5;
  assume
A1: c = card (seq(n,100)/\ M);
  set nm=n mod 30,nd = n div 30;
A2: n = nd *30 + nm by INT_1:59;
  30= 2*3*5 = 2*(3*5) = 3*(2*5);
  then 2 divides 30 & 3 divides 30 & 5 divides 30;
  then
A3:2 divides nd*30 & 3 divides nd*30 & 5 divides nd*30 by INT_2:2;
  M = M\/M5 by XBOOLE_1:6
  .= M\/M5\/M5 by XBOOLE_1:6;
  then
A4: c = card(seq(nm,100)/\M) by A1,A2,A3,Th88;
  nm < 30 by INT_1:58;
  hence thesis by Lm7,A4;
end;

Lm8:
  for n,c being Nat st 0 <= n < 210 &
     c = card (seq(n,100) /\
             (multiples(2)\/multiples(3)\/multiples(5)\/multiples(7)))
     holds
      c >= 75 & (c = 75 implies n = 9 or n= 10 or n = 99 or n = 100)
proof
  let n,c be Nat such that
A1:0<= n < 210 and
A2: c = card (seq(n,100) /\
             (multiples(2)\/multiples(3)\/multiples(5)\/multiples(7)));
  set S=seq(n,100);
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M7=multiples(7),
    M235=M2\/M3\/M5, M = M235\/M7;
  M = M235 \/ (M7 \ M235) by XBOOLE_1:39;
  then
A3: S/\M = (S/\M235)\/(S/\(M7\ M235)) by XBOOLE_1:23;
A4:S/\M235 misses S/\(M7 \ M235) by XBOOLE_1:76,79;
  then
A5: card (S/\M) = card (S/\M235) + card (S/\(M7\ M235))
    by A3,CARD_2:40;
  not 2 divides 24*2+1 & not 3 divides 3*16+1 &
  not 5 divides 5*9 +4 & 7 divides 7*7 by NAT_4:9;
  then not 49 in M235 & 49 in M7 by Lm6,NUMBER14:62;
  then
A6: 49 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 38*2+1 & not 3 divides 3*25+2 & not 5 divides 5*15 +2
  & 7 divides 11*7 by NAT_4:9;
  then not 77 in M235 & 77 in M7 by Lm6,NUMBER14:62;
  then
A7: 77 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 45*2+1 & not 3 divides 3*30+1 & not 5 divides 5*18 +1 &
  7 divides 13*7 by NAT_4:9;
  then  not 91 in M235 & 91 in M7 by Lm6,NUMBER14:62;
  then
A8: 91 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 59*2+1 & not 3 divides 3*39+2 & not 5 divides 5*23 +4
  & 7 divides 17*7 by NAT_4:9;
  then  not 119 in M235 & 119 in M7 by Lm6,NUMBER14:62;
  then
A9: 119 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 66*2+1 & not 3 divides 3*44+1 & not 5 divides 5*26 +3
  & 7 divides 19*7 by NAT_4:9;
  then not 133 in M235 & 133 in M7 by Lm6,NUMBER14:62;
  then
A10: 133 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 80*2+1 & not 3 divides 3*53+2 & not 5 divides 5*32 +1
  & 7 divides 23*7 by NAT_4:9;
  then not 161 in M235 & 161 in M7 by Lm6,NUMBER14:62;
  then
A11: 161 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 101*2+1 & not 3 divides 3*67+2 & not 5 divides 5*40 +3
  & 7 divides 29*7  by NAT_4:9;
  then not 203 in M235 & 203 in M7 by Lm6,NUMBER14:62;
  then
A12: 203 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 108*2+1 & not 3 divides 3*72+1 & not 5 divides 5*43 +2
  & 7 divides 31*7 by NAT_4:9;
  then not 217 in M235 & 217 in M7 by Lm6,NUMBER14:62;
  then
A13: 217 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 129*2+1 & not 3 divides 3*86+1 & not 5 divides 5*51 +4
  & 7 divides 37*7 by NAT_4:9;
  then  not 259 in M235 & 259 in M7 by Lm6,NUMBER14:62;
  then
A14: 259 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 143*2+1 & not 3 divides 3*95+2 & not 5 divides 5*57 +2
  & 7 divides 41*7 by NAT_4:9;
  then  not 287 in M235 & 287 in M7 by Lm6,NUMBER14:62;
  then
A15: 287 in M7 \ M235 by XBOOLE_0:def 5;
  not 2 divides 150*2+1 & not 3 divides 3*100+1 & not 5 divides 5*60 +1
  & 7 divides 43*7 by NAT_4:9;
  then  not 301 in M235 & 301 in M7 by Lm6,NUMBER14:62;
  then
A16: 301 in M7 \ M235 by XBOOLE_0:def 5;
A17:for i,j,k being Element of NAT st n < i < j < k <= n+100
  & i in M7\ M235 & j in M7\ M235 & k in M7\ M235
  holds card (S/\(M7\ M235)) >= 3
  proof
    let i,j,k be Element of NAT such that
A18: n < i < j < k <= n+100
    and
A19: i in M7\ M235 & j in M7\ M235 & k in M7\ M235;
A20: i < k & n < j < n+100 by A18,XXREAL_0:2;
    then i < n+100 & n < k by A18,XXREAL_0:2;
    then i in S & j in S & k in S by A18,A20,Th73;
    then i in S/\(M7\ M235) & j in S/\(M7\ M235) & k in S/\(M7\ M235)
      by A19,XBOOLE_0:def 4;
    then card {i,j,k} <= card (S/\(M7\ M235)) by NAT_1:43,NOMIN_2:1;
    hence thesis by A18,CARD_2:58;
  end;
A21:card (S/\(M7\ M235)) >= 3
  proof
    per cases by A1;
    suppose
A22:  0<= n <= 18;
      100+0<=100+n by XREAL_1:6;
      then n < 49 < 77 < 91 <= n+100 by A22,XXREAL_0:2;
      hence thesis by A6,A7,A8,A17;
    end;
    suppose
A23:  18< n <= 76;
      then 18+1 <= n by NAT_1:13;
      then 100+19<=100+n by XREAL_1:6;
      then n < 77 < 91 <119 <= n+100 by A23,XXREAL_0:2;
      hence thesis by A7,A8,A9,A17;
    end;
    suppose
A24:  76< n <= 118;
      then 76+1 <= n by NAT_1:13;
      then 100+77<=100+n by XREAL_1:6;
      then n < 119 < 133 < 161 <= n+100 by A24,XXREAL_0:2;
      hence thesis by A9,A10,A11,A17;
    end;
    suppose
A25:  118< n <= 160;
      then 118+1 <= n by NAT_1:13;
      then 100+119<=100+n by XREAL_1:6;
      then n < 161 < 203 < 217 <= n+100 by A25,XXREAL_0:2;
      hence thesis by A11,A12,A13,A17;
    end;
    suppose
A26:  160< n <= 202;
      then 160+1 <= n by NAT_1:13;
      then 100+161<=100+n by XREAL_1:6;
      then n < 203 < 217 < 259 <= n+100 by A26,XXREAL_0:2;
      hence thesis by A12,A13,A14,A17;
    end;
    suppose
A27:  202< n < 210;
      then 202+1 <= n by NAT_1:13;
      then 100+203<=100+n by XREAL_1:6;
      then n < 259 < 287 < 301 <= n+100 by A27,XXREAL_0:2;
      hence thesis by A14,A15,A16,A17;
    end;
  end;
A28:card (S/\M235) >= 72 by Th93;
  then card (S/\M) >= 72 + 3 by A21,A5,XREAL_1:7;
  hence c >= 75 by A2;
  assume
A29:c = 75;
  then 72+3 = card (S/\M235) + card (S/\(M7\ M235)) by A2,A4,A3,CARD_2:40;
  then card (S/\M235) <= 72 by A21,XREAL_1:8;
  then
A30: card (S/\M235) = 72 by A28,XXREAL_0:1;
  then n mod 30 = 9 or n mod 30 = 10 by Th93;
  then consider t be Nat such that
A31: n = 30*t +9 & 9 < 30 or n = 30*t +10 & 10 < 30 by NAT_D:def 2;
A32:for i,j,k,l being Element of NAT st n < i < j < k < l <= n+100
    & i in M7\ M235 & j in M7\ M235 & k in M7\ M235 & l in M7\M235
    holds card (S/\(M7\ M235)) > 3
  proof
    let i,j,k,l be Element of NAT such that
A33: n < i < j < k < l <= n+100 and
A34: i in M7\ M235 & j in M7\ M235 & k in M7\ M235 & l in M7\M235;
A35: i < k & j < l & n < j & k < n+100 by A33,XXREAL_0:2;
    then
A36:n < k & i < l & j < n+100 by A33,XXREAL_0:2;
    n < l & i < n+100 by A35,XXREAL_0:2;
    then i in S & j in S & k in S & l in S by A33,A35,A36,Th73;
    then i in S/\(M7\ M235) & j in S/\(M7\ M235) & k in S/\(M7\ M235)
      & l in S/\(M7\ M235) by A34,XBOOLE_0:def 4;
    then card {i,j,k,l} <= card (S/\(M7\ M235)) by QUATERNI:5,NAT_1:43;
    then  card (S/\(M7\ M235)) >= 4 = 3+1 by A33,A35,CARD_2:59;
    hence thesis by NAT_1:13;
  end;
  t < 6+1
  proof
    assume t >= 6+1;
    then 30*t >= 7*30 by XREAL_1:64;
    then 30*t+9 > 7*30+0 & 30*t +10>7*30+0 by XREAL_1:8;
    hence thesis by A1,A31;
  end;
  then t <=6 by NAT_1:13;
  then t=0 or ... or t=6;
  then per cases;
  suppose t=0 or t = 3;
    hence thesis by A31;
  end;
  suppose t=1 or t= 2;
    hence thesis by A29,A2,A5,A30,A31,A32,A7,A8,A9,A10;
  end;
  suppose t=4;
    hence thesis by A29,A2,A31,A5,A30,A32,A10,A11,A12,A13;
  end;
  suppose t=5;
    hence thesis by A29,A2,A5,A30,A31,A32,A14,A11,A12,A13;
  end;
  suppose t=6;
    hence thesis by A29,A2,A5,A30,A31,A32,A14,A15,A12,A13;
  end;
end;

theorem Th94:
  c = card (seq(n,100) /\
           (multiples(2)\/multiples(3)\/multiples(5)\/multiples(7)))
  implies
    c >= 75 &
   (c = 75 implies
       n mod 210 = 9 or n mod 210 = 10 or n mod 210 = 99 or n mod 210 = 100)
proof
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M7=multiples(7),
  M = M2\/M3\/M5\/M7;
  assume
A1: c = card (seq(n,100)/\ M);
  set nm=n mod 210,nd = n div 210;
A2: n = nd *210 + nm by INT_1:59;
  2 divides 2*(3*5*7) & 3 divides 3*(2*5*7) &
  5 divides 5*(2*3*7) & 7 divides 7*(2*3*5);
  then
A3:2 divides nd*210 & 3 divides nd*210 & 5 divides nd*210
  & 7 divides nd*210 by INT_2:2;
  M = M\/M7 by XBOOLE_1:6;
  then
A4: c = card(seq(nm,100)/\M) by A1,A2,A3,Th88;
  nm < 210 by INT_1:58;
  hence thesis by Lm8,A4;
end;

Lm9:for i being Nat holds
      not i in multiples(2)\/multiples(3)\/multiples(5)\/multiples(7) iff
     not 2 divides i & not 3 divides i & not 5 divides i & not 7 divides i
proof
  let i be Nat;
  hereby
    assume  not i in multiples(2)\/multiples(3)\/multiples(5)
    \/multiples(7);
    then not i in multiples(2)\/multiples(3)\/multiples(5) &
      not i in  multiples(7) by XBOOLE_0:def 3;
    then not i in multiples(2)\/multiples(3) & not i in multiples(5) &
      not i in  multiples(7) by XBOOLE_0:def 3;
    then not i in  multiples(2) & not i in  multiples(3) &
       not i in  multiples(5) & not i in  multiples(7) by XBOOLE_0:def 3;
    hence not 2 divides i & not 3 divides i & not 5 divides i &
      not 7 divides i by NUMBER14:62;
  end;
  assume  not 2 divides i & not 3 divides i &
    not 5 divides i & not 7 divides i;
  then
A1:not i in  multiples(2) & not i in  multiples(3) &
        not i in  multiples(5) & not i in  multiples(7)
   by NUMBER14:62;
  then not i in  multiples(2)\/ multiples(3) by XBOOLE_0:def 3;
  then not i in multiples(2)\/multiples(3)\/multiples(5)
    by A1,XBOOLE_0:def 3;
  hence thesis  by A1,XBOOLE_0:def 3;
end;

theorem Th95:
  0 <= n < 2*3*5*7*11 implies
    76 <= card (seq(n,100) /\
     (multiples(2)\/multiples(3)\/multiples(5)\/multiples(7)\/multiples(11)))
proof
  assume
A1:0 <= n < 2*3*5*7*11;
  set S=seq(n,100);
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M7=multiples(7),
  M11=multiples(11), M2357=M2\/M3\/M5\/M7, M = M2357\/M11;
  assume
A2:card (S/\M) < 76;
  M = M2357 \/ (M11 \ M2357) by XBOOLE_1:39;
  then
A3: S/\M = (S/\M2357)\/(S/\(M11\ M2357)) by XBOOLE_1:23;
  S/\M2357 misses S/\(M11 \ M2357) by XBOOLE_1:76,79;
  then A4: card (S/\M) = card (S/\M2357) + card (S/\(M11\ M2357))
    by A3,CARD_2:40;
    card (S/\M) < 75+1 by A2;
  then
A5:card (S/\M2357)+0 <= card (S/\M)<=75 by NAT_1:13,A4,XREAL_1:7;
  then
A6:card (S/\M2357)<= 75 by XXREAL_0:2;
  card (S/\M2357) >= 75 by Th94;
  then
A7:card (S/\M2357) = 75 by A6,XXREAL_0:1;
  then n mod 210 = 9 or n mod 210 = 10 or n mod 210 = 99 or n mod 210 = 100
    by Th94;
  then consider t be Nat such that
A8:   n = 210*t +9 & 9 < 210 or n = 210*t +10 & 10 < 210 or
  n = 210*t +99 & 99 < 210 or n = 210*t +100 & 100 < 210 by NAT_D:def 2;
A9: S/\(M11\ M2357) = {} by XREAL_1:8, A4,A5,A7;
A10: t < 10+1
  proof
    assume t >= 10+1;
    then 210*t >= 11*210 by XREAL_1:64;
    then 210*t+9 > 11*210+0 & 210*t+10 > 11*210+0 &
    210*t+99 > 11*210+0 & 210*t+100 > 11*210+0 by XREAL_1:8;
    hence thesis by A1,A8;
  end;
A11: for i,k being Nat st i+1 < k <= i+100 & k in M11 \ M2357
     holds i<>n & i+1<>n
  proof
    let i,k be Nat such that
A12: i+1 < k <= i+100 & k in M11 \ M2357;
    i < k & k < i+100+1 = i+1+100 by A12,NAT_1:13;
    then k in seq(i,100) & k in seq(i+1,100) by A12,Th73;
    hence thesis by A9,A12,XBOOLE_0:def 4;
  end;
  t <=10 by A10,NAT_1:13;
  then t=0 or ... or t=10;
  then per cases;
  suppose A13: t=0;
    not 2 divides 5*2+1 & not 3 divides 3*3+2 & not 5 divides 2*5+1 &
    not 7 divides 1*7+4 & 11 divides 11*1 by NAT_4:9;
    then not 11 in M2357 & 11 in M11 by Lm9,NUMBER14:62;
    then A14: 11 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 60*2+1 & not 3 divides 40*3+1 & not 5 divides 24*5+1 &
    not 7 divides 17*7+2 & 11 divides 11*11 by NAT_4:9;
    then not 121 in M2357 & 121 in M11 by Lm9,NUMBER14:62;
    then A15: 121 in M11 \ M2357 by XBOOLE_0:def 5;
    9+1 < 11 <= 9+100 & 99+1 < 121 <= 99+100;
    hence thesis by A13,A8,A11,A14,A15;
  end;
  suppose A16: t=1;
    not 2 divides 159*2+1 & not 3 divides 106*3+1 & not 5 divides 63*5+4 &
    not 7 divides 45*7+4 & 11 divides 11*29 by NAT_4:9;
    then not 319 in M2357 & 319 in M11 by Lm9,NUMBER14:62;
    then A17: 319 in M11 \ M2357 by XBOOLE_0:def 5;
    219+1 < 253 <= 219+100 & 309+1 < 319 <= 309+100;
    hence thesis by A16,A8,A11,A17;
  end;
  suppose A18: t=2;
    not 2 divides 225*2+1 & not 3 divides 150*3+1 & not 5 divides 90*5+1 &
    not 7 divides 64*7+3 & 11 divides 11*41 by NAT_4:9;
    then not 451 in M2357 & 451 in M11 by Lm9,NUMBER14:62;
    then A19: 451 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 291*2+1 & not 3 divides 194*3+1 & not 5 divides 116*5+3 &
    not 7 divides 83*7+2 & 11 divides 11*53 by NAT_4:9;
    then not 583 in M2357 & 583 in M11 by Lm9,NUMBER14:62;
    then A20: 583 in M11 \ M2357 by XBOOLE_0:def 5;
    429+1 < 451 <= 429+100 & 519+1 < 583 <= 519+100;
    hence thesis by A18,A8,A11,A19,A20;
  end;
  suppose A21: t=3;
    not 2 divides 368*2+1 & not 3 divides 245*3+2 & not 5 divides 147*5+2 &
    not 7 divides 105*7+2 & 11 divides 11*67 by NAT_4:9;
    then not 737 in M2357 & 737 in M11 by Lm9,NUMBER14:62;
    then A22: 737 in M11 \ M2357 by XBOOLE_0:def 5;
    639+1 < 649 <= 639+100 & 729+1 < 737 <= 729+100;
    hence thesis by A21,A8,A11,A22;
  end;
  suppose A23: t=4;
    not 2 divides 434*2+1 & not 3 divides 289*3+2 & not 5 divides 173*5+4 &
    not 7 divides 124*7+1 & 11 divides 11*79 by NAT_4:9;
    then not 869 in M2357 & 869 in M11 by Lm9,NUMBER14:62;
    then A24: 869 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 489*2+1 & not 3 divides 326*3+1 & not 5 divides 195*5+4 &
    not 7 divides 139*7+6 & 11 divides 11*89 by NAT_4:9;
    then not 979 in M2357 & 979 in M11 by Lm9,NUMBER14:62;
    then A25: 979 in M11 \ M2357 by XBOOLE_0:def 5;
    849+1 < 869 <= 849+100 & 939+1 < 979 <= 939+100;
    hence thesis by A23,A8,A11,A24,A25;
  end;
  suppose A26: t=5;
    not 2 divides 533*2+1 & not 3 divides 355*3+2 & not 5 divides 213*5+2 &
    not 7 divides 152*7+3 & 11 divides 11*97 by NAT_4:9;
    then not 1067 in M2357 & 1067 in M11 by Lm9,NUMBER14:62;
    then A27: 1067 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 588*2+1 & not 3 divides 392*3+1 & not 5 divides 235*5+2 &
    not 7 divides 168*7+1 & 11 divides 11*107 by NAT_4:9;
    then not 1177 in M2357 & 1177 in M11 by Lm9,NUMBER14:62;
    then A28: 1177 in M11 \ M2357 by XBOOLE_0:def 5;
    1059+1 < 1067 <= 1059+100 & 1149+1 < 1177 <= 1149+100;
    hence thesis by A26,A8,A11,A27,A28;
  end;
  suppose A29: t=6;
    not 2 divides 665*2+1 & not 3 divides 443*3+2 & not 5 divides 266*5+1 &
    not 7 divides 190*7+1 & 11 divides 11*121 by NAT_4:9;
    then not 1331 in M2357 & 1331 in M11 by Lm9,NUMBER14:62;
    then A30: 1331 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 698*2+1 & not 3 divides 465*3+2 & not 5 divides 279*5+2 &
    not 7 divides 199*7+4 & 11 divides 11*127 by NAT_4:9;
    then not 1397 in M2357 & 1397 in M11 by Lm9,NUMBER14:62;
    then A31: 1397 in M11 \ M2357 by XBOOLE_0:def 5;
    1269+1 < 1331 <= 1269+100 & 1359+1 < 1397 <= 1359+100;
    hence thesis by A29,A8,A11,A30,A31;
  end;
  suppose A32: t=7;
    not 2 divides 786*2+1 & not 3 divides 524*3+1 & not 5 divides 314*5+3 &
    not 7 divides 224*7+5 & 11 divides 11*143 by NAT_4:9;
    then not 1573 in M2357 & 1573 in M11 by Lm9,NUMBER14:62;
    then A33: 1573 in M11 \ M2357 by XBOOLE_0:def 5;
    1479+1 < 1507 <= 1479+100 & 1569+1 < 1573 <= 1569+100;
    hence thesis by A32,A8,A11,A33;
  end;
  suppose A34: t=8;
    not 2 divides 863*2+1 & not 3 divides 575*3+2 & not 5 divides 345*5+2 &
    not 7 divides 246*7+5 & 11 divides 11*157 by NAT_4:9;
    then not 1727 in M2357 & 1727 in M11 by Lm9,NUMBER14:62;
    then A35: 1727 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 896*2+1 & not 3 divides 597*3+2 & not 5 divides 358*5+3 &
    not 7 divides 256*7+1 & 11 divides 11*163 by NAT_4:9;
    then not 1793 in M2357 & 1793 in M11 by Lm9,NUMBER14:62;
    then A36: 1793 in M11 \ M2357 by XBOOLE_0:def 5;
    1689+1 < 1727 <= 1689+100 & 1779+1 < 1793 <= 1779+100;
    hence thesis by A34,A8,A11,A35,A36;
  end;
  suppose A37: t=9;
    not 2 divides 995*2+1 & not 3 divides 663*3+2 & not 5 divides 398*5+1 &
    not 7 divides 284*7+3 & 11 divides 11*181 by NAT_4:9;
    then not 1991 in M2357 & 1991 in M11 by Lm9,NUMBER14:62;
    then A38: 1991 in M11 \ M2357 by XBOOLE_0:def 5;
    1899+1 < 1903 <= 1899+100 & 1989+1 < 1991 <= 1989+100;
    hence thesis by A37,A8,A11,A38;
  end;
  suppose A39: t=10;
    not 2 divides 1061*2+1 & not 3 divides 707*3+2 & not 5 divides 424*5+3 &
    not 7 divides 303*7+2 & 11 divides 11*193 by NAT_4:9;
    then not 2123 in M2357 & 2123 in M11 by Lm9,NUMBER14:62;
    then A40: 2123 in M11 \ M2357 by XBOOLE_0:def 5;
    not 2 divides 1149*2+1 & not 3 divides 766*3+1 & not 5 divides 459*5+4 &
    not 7 divides 328*7+3 & 11 divides 11*209 by NAT_4:9;
    then not 2299 in M2357 & 2299 in M11 by Lm9,NUMBER14:62;
    then A41: 2299 in M11 \ M2357 by XBOOLE_0:def 5;
    2109+1 < 2123 <= 2109+100 & 2199+1 < 2299 <= 2199+100;
    hence thesis by A39,A8,A11,A40,A41;
  end;
end;

theorem Th96:
   11 <= n implies card primeNumbers(n,100) <= 24
proof
  assume A1:11 <= n;
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M7=multiples(7),
    M11=multiples(11), M2357=M2\/M3\/M5\/M7, M = M2357\/M11;
  set S=seq(n,100);
  A2:primeNumbers(n,100) misses (S/\M)
  proof
    assume primeNumbers(n,100) meets (S/\M);
    then consider x be object such that
    A3:  x in primeNumbers(n,100) & x in S/\M by XBOOLE_0:3;
    reconsider x as Nat by A3;
    A4:x is prime & n < x by A3,Th74;
    x in M2357 or x in M11 by A3,XBOOLE_0:def 3;
    then 2 divides x or 3 divides x or 5 divides x or 7 divides x
      or 11 divides x by Lm9,NUMBER14:62;
    then x=2 or x=3 or x=5 or x=7 or x=11  by A4;
    hence contradiction by A3,Th74,A1,XXREAL_0:2;
  end;
  primeNumbers(n,100) = S/\SetPrimes by NUMBER14:def 17;
  then card (primeNumbers(n,100) \/ (S/\M)) <= card S = 100
    by NAT_1:43,NUMBER14:73,XBOOLE_1:8;
  then
A5: card  primeNumbers(n,100) + card (S/\M) <= 100 by A2,CARD_2:40;
  set nm=n mod 2310,nd = n div 2310;
A6: n = nd *2310 + nm by INT_1:59;
  2 divides 2*(3*5*7*11) & 3 divides 3*(2*5*7*11) &
    5 divides 5*(2*3*7*11) & 7 divides 7*(2*3*5*11)
   & 11 divides 11*(2*3*5*7);
  then
A7: 2 divides nd*2310 & 3 divides nd*2310 & 5 divides nd*2310
  & 7 divides nd*2310 & 11 divides nd*2310 by INT_2:2;
A8:card (S/\M) = card(seq(nm,100)/\M) by A6,A7,Th88;
  nm < 2310 by INT_1:58;
  then card(S/\M) >= 76 by A8,Th95;
  then card  primeNumbers(n,100) + card (S/\M)- card (S/\M)
  <= 100-76 by A5,XREAL_1:13;
  hence thesis;
end;

Lm10:for n being Nat st 0 <= n < 6 holds
     card (seq(n,21) /\
             (multiples(2)\/multiples(3))) >= 13
proof
  let n be Nat such that
A1:0<= n < 6;
  set M2=multiples(2),M3=multiples(3),M23=M2\/M3;
A2:seq(n,3)/\M23 misses seq(n+3,6*3)/\M23 by Th75,XBOOLE_1:76;
  seq(n,3+6*3) = seq(n,3)\/seq(n+3,6*3) by Th77;
  then seq(n,3+18)/\M23 = (seq(n,3)/\M23)\/(seq(n+3,3*6)/\M23) by XBOOLE_1:23;
  then
A3: card (seq(n,3+6*3)/\M23) =
  card (seq(n,3)/\M23) + card (seq(n+3,6*3)/\M23) by A2,CARD_2:40;
A4: card (seq(n+3,6*3)/\M23) = 12
  proof
A5: 2 divides 2*3 & 3 divides 2*3;
    M23 = M23\/M3 by XBOOLE_1:6
    .= M23\/M3\/M3 by XBOOLE_1:6
    .= M23\/M3\/M3\/M3 by XBOOLE_1:6;
    then card(seq(n+3,6*3)/\M23) = 3* card(seq(0*6,6)/\M23) by A5,Th90
    .= 3*4 by Th91;
    hence thesis;
  end;
A6:for i,n being Nat holds i in seq(n,3)/\M23 iff
  n < i <= n+ 3 & (2 divides i or 3 divides i )
  proof
    let i,n be Nat;
    hereby assume
A7:   i in seq(n,3)/\M23;
      i in M2 or i in M3 by A7,XBOOLE_0:def 3;
      hence n < i <= n+3 & (2 divides i or 3 divides i) by A7,NUMBER14:62,Th73;
    end;
    assume n < i <= n+ 3 & ( 2 divides i or 3 divides i);
    then
A8:   (i in M2 or i in M3) & i in seq(n,3) by Th73,NUMBER14:62;
    then i in M23 by XBOOLE_0:def 3;
    hence thesis by A8,XBOOLE_0:def 4;
  end;
  seq(n,3)/\M23 is non empty
  proof
    n < 5+1 by A1;
    then n <=5 by NAT_1:13;
    then n=0 or ... or n = 5;
    then per cases;
    suppose n = 0 or n=1;
      then n < 2 <= n+3 & 2 divides 2;
      hence thesis by A6;
    end;
    suppose n = 2 or n=3;
      then n < 2*2 <= n+3 & 2 divides 2*2;
      hence thesis by A6;
    end;
    suppose n = 4 or n=5;
      then n < 2*3 <= n+3 & 2 divides 2*3;
      hence thesis by A6;
    end;
  end;
  then card (seq(n,3+6*3)/\M23) >= 12+1 by A3,A4,NAT_1:14,XREAL_1:6;
  hence thesis;
end;

theorem Th97:
  0 <= n < 2*3*5 implies
    14 <= card (seq(n,21) /\
             (multiples(2)\/multiples(3)\/multiples(5)))
proof
  assume
A1:0 <= n < 2*3*5;
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M23=M2\/M3,
  M = M23\/M5,S=seq(n,21);
A2: card (S/\M23) >= 13
  proof
    set nm=n mod 6,nd = n div 6;
A3: n = nd *6 + nm by INT_1:59;
    2 divides 2*3 & 3 divides 2*3;
    then
A4: 2 divides nd*6 & 3 divides nd*6  by INT_2:2;
    M23 = M23\/M3 by XBOOLE_1:6
    .= M23\/M3\/M3 by XBOOLE_1:6
    .= M23\/M3\/M3\/M3 by XBOOLE_1:6;
    then
A5: card (S/\M23) = card(seq(nm,21)/\M23) by A3,A4,Th88;
    nm < 6 by INT_1:58;
    hence thesis by A5,Lm10;
  end;
A6:for i being Nat holds i in S/\(M5 \ M23) iff
  n < i <= n+ 21 & 5 divides i & not 2 divides i & not 3 divides i
  proof
    let i be Nat;
    hereby assume
A7:   i in S/\(M5 \ M23);
      then
A8:   i in S & i in (M5 \ M23);
      i in M5 & not i in M23 by A7,XBOOLE_0:def 5;
      then not i in M2 & not i in M3 by XBOOLE_0:def 3;
      hence n < i <= n+21 & 5 divides i & not 2 divides i
      & not 3 divides i by A8,NUMBER14:62,Th73;
    end;
    assume n < i <= n+21 & 5 divides i & not 2 divides i & not 3 divides i;
    then
A9: not i in M2 & not i in M3 & i in M5 & i in seq(n,21)
    by Th73,NUMBER14:62;
    then not i in M23 by XBOOLE_0:def 3;
    then i in M5\M23 by A9,XBOOLE_0:def 5;
    hence thesis by A9,XBOOLE_0:def 4;
  end;
  S/\(M5 \ M23) is non empty
  proof
    per cases;
    suppose
A10:  n < 5;
A11:  5 <= 5+(n+ 16)= n+21 by NAT_1:11;
      2*2+1=5 & 3*1+2 =5;
      then not 2 divides 5 & not 3 divides 5 by NAT_4:9;
      hence thesis by A10,A11,A6;
    end;
    suppose
A12:  5 <= n < 25;
      then
A13:  5+20 <= n+ 21 by XREAL_1:7;
      2*12+1=25 & 3*8+1 =25;
      then not 2 divides 25 & not 3 divides 25 & 5 divides 5*5 by NAT_4:9;
      hence thesis by A12,A13,A6;
    end;
    suppose n >= 25;
      then
A14:  25+10 <= n+21 by XREAL_1:7;
A15:  n < 35 by A1,XXREAL_0:2;
      2*17+1=35 & 3*11+2 =35;
      then not 2 divides 35 & not 3 divides 35 & 5 divides 7*5 by NAT_4:9;
      hence thesis by A14,A15,A6;
    end;
  end;
  then
A16:card (S/\(M5 \ M23)) >= 1 by NAT_1:14;
  M23\/M5 = M23 \/ (M5 \ M23) by XBOOLE_1:39;
  then
A17:S/\M = (S/\M23)\/(S/\(M5\ M23)) by XBOOLE_1:23;
  S/\M23 misses S/\(M5 \ M23) by XBOOLE_1:76,79;
  then card (S/\M) = card (S/\M23) + card (S/\(M5\ M23))
    by A17,CARD_2:40;
  then card (S/\M) >= 13+1 by A16,A2,XREAL_1:7;
  hence thesis;
end;

theorem Th98:
  5 <= n implies card primeNumbers(n,21) <= 7
proof
  assume
A1:5 <= n;
  set M2=multiples(2),M3=multiples(3),M5=multiples(5),M=M2\/M3\/M5;
  set S=seq(n,21);
A2:primeNumbers(n,21) misses (S/\M)
  proof
    assume primeNumbers(n,21) meets (S/\M);
    then consider x be object such that
A3:  x in primeNumbers(n,21) & x in S/\M by XBOOLE_0:3;
    reconsider x as Nat by A3;
A4: x is prime & n < x by A3,Th74;
    2 divides x or 3 divides x or 5 divides x by A3,Lm6;
    then x=2 or x=3 or x=5 by A4;
    hence contradiction by A3,Th74,A1,XXREAL_0:2;
  end;
  primeNumbers(n,21) = S/\SetPrimes by NUMBER14:def 17;
  then card (primeNumbers(n,21) \/ (S/\M)) <= card S = 21
    by NAT_1:43,NUMBER14:73,XBOOLE_1:8;
  then
A5:card  primeNumbers(n,21) + card (S/\M) <= 21 by A2,CARD_2:40;
  set nm=n mod 30,nd = n div 30;
A6: n = nd *30 + nm by INT_1:59;
  2 divides 2*(3*5) & 3 divides 3*(2*5) & 5 divides 5*(2*3);
  then
A7:2 divides nd*30 & 3 divides nd*30 & 5 divides nd*30 by INT_2:2;
  M = M\/M5 by XBOOLE_1:6
  .= M\/M5\/M5 by XBOOLE_1:6;
  then
A8:card (S/\M) = card(seq(nm,21)/\M) by A6,A7,Th88;
  nm < 30 by INT_1:58;
  then card(S/\M) >= 14 by A8,Th97;
  then card  primeNumbers(n,21) + card (S/\M)- card (S/\M)
  <= 21-14 by A5,XREAL_1:13;
  hence thesis;
end;

begin ::Problem 132

:: The only case' where the sequences k+l, k+2, ..., k+100
:: contain maximal numbers of primes (26) is when n = 1.

theorem
  card primeNumbers(1,100) = 26 &
    for n being Nat st n <> 1 holds card primeNumbers(n,100) < 26
proof
  thus card primeNumbers(1,100) = 26 by Th85;
  let n be Nat such that
A1: n <> 1;
  set S=card primeNumbers(n,100);
  per cases;
  suppose n <=10;
    then n=0 or ... or n=10;
    then card S = 25 or card S < 25 by A1,Th85;
    hence thesis by XXREAL_0:2;
  end;
  suppose  n>10;
    then n >=10+1 by NAT_1:13;
    then card S <= 24 by Th96;
    hence thesis by XXREAL_0:2;
  end;
end;

begin ::Problem 133

:: The sequences k+l, k+2, ..., k+100 contain exactly 25 prime numbers
:: in only six cases: k = 0, 2, 3, 4, 9 and 10.

theorem
  {n where n is Nat: card primeNumbers(n,100) = 25} = {0,2,3,4,9,10}
proof
A1: {n where n is Nat: card primeNumbers(n,100) = 25} c= {0,2,3,4,9,10}
  proof
    let x be object;
    assume x in {n where n is Nat: card primeNumbers(n,100) = 25};
    then consider n be Nat such that
A2: x=n & card primeNumbers(n,100) = 25;
    n < 10+1 by A2,Th96;
    then n <=10 by NAT_1:13;
    then n=0 or ... or n=10;
    hence thesis by A2,Th85,ENUMSET1:def 4;
  end;
  {0,2,3,4,9,10} c= {n where n is Nat: card primeNumbers(n,100) = 25}
  proof
    let x be object;
    assume
A3: x in {0,2,3,4,9,10};
    then reconsider n=x as Nat;
    n=0 or n=2 or n=3 or n=4 or n=9 or n=10 by A3,ENUMSET1:def 4;
    then card primeNumbers(n,100) = 25 by Th85;
    hence thesis;
  end;
hence thesis by A1,XBOOLE_0:def 10;
end;

begin :: Problem 134

:: The sequences k+l, k+2, ..., k+21 contain exactly 8 prime numbers
:: in only three cases: when k = 0, 1 or 2.

theorem
  {n where n is Nat: card primeNumbers(n,21) = 8} = {0,1,2}
proof
  not 0+1 is prime & not 0+21+1 is prime by XPRIMES0:22;
  then
A1:card primeNumbers(0+1,21) = 8 by Lm5,Th82;
  1+1 is prime & 1+21+1 is prime by XPRIMES1:2,23;
  then
A2:card primeNumbers(1+1,21) = 8 by A1,Th82;
  2+1 is prime & not 2+21+1 is prime by XPRIMES0:24,XPRIMES1:3;
  then
A3:card primeNumbers(2+1,21) = 8-1 by A2,Th84;
A4:not 3+1 is prime & not 3+21+1 is prime by XPRIMES0:4,25;
A5:{n where n is Nat: card primeNumbers(n,21) = 8} c= {0,1,2}
  proof
    let x be object;
    assume x in {n where n is Nat: card primeNumbers(n,21) = 8};
    then consider n be Nat such that
A6: x=n & card primeNumbers(n,21) = 8;
    n < 5=4+1 by A6,Th98;
    then n <= 4 by NAT_1:13;
    then n= 0 or ... or n = 4;
    hence thesis by A6,A3,A4,Th82,ENUMSET1:def 1;
  end;
  {0,1,2} c= {n where n is Nat: card primeNumbers(n,21) = 8}
  proof
    let x be object;
    assume x in {0,1,2};
    then x=0 or x=1 or x=2 by ENUMSET1:def 1;
    hence thesis by Lm5,A1,A2;
  end;
  hence thesis by A5,XBOOLE_0:def 10;
end;