reserve x,y,z for Real,
  a,b,c,d,e,f,g,h for Nat,
  k,l,m,n,m1,n1,m2,n2 for Integer,
  q for Rational;
reserve fs,fs1,fs2,fs3 for FinSequence;
reserve D for non empty set,
  v,v1,v2,v3 for object,
  fp for FinSequence of NAT,
  fr,fr1,fr2 for FinSequence of INT,
  ft for FinSequence of REAL;
reserve x,y,t for Integer;

theorem
  len fp>=2 & (for b,c st b in dom fp & c in dom fp & b<>c holds (fp.b
gcd fp.c)=1) implies for fr st len fr=len fp holds ex fr1 st (len fr1=len fp &
  for b st b in dom fp holds (fp.b)*(fr1.b)+(fr.b)=(fp.1)*(fr1.1)+(fr.1))
proof
  defpred CC[FinSequence of NAT] means for fr st len fr=len $1 holds ex fr1 st
(len fr1=len $1 & for b st b in dom $1 holds ($1.b)*(fr1.b)+(fr.b)=($1.1)*(fr1.
  1)+(fr.1));
  defpred RP[FinSequence of NAT] means for b,c st b in dom $1 & c in dom $1 &
  b<>c holds ($1.b gcd $1.c)=1;
  defpred TH[set] means ex f being FinSequence of NAT st f = $1 &
  ((len f>=2 & RP[f]) implies CC[f]);
A1: now
    let fp;
    let d be Element of NAT such that
A2: TH[fp];
    set k=len fp;
    set fp1=fp^<*d*>;
    now
      assume that
A3:   len fp1>=2 and
A4:   RP[fp1];
A5:   len fp1=k+1 by FINSEQ_2:16;
      now
        per cases by A3,XXREAL_0:1;
        suppose
A6:       len fp1=2;
          now
            let fr such that
            len fr=len fp1;
            1 in dom fp1 & 2 in dom fp1 by A6,FINSEQ_3:25;
            then fp1.1 gcd fp1.2=1 by A4;
            then (fp1.1 gcd fp1.2) divides (fr.1 - fr.2) by INT_2:12;
            then consider m,n such that
A7:         (fp1.1)*m+(fp1.2)*n=fr.1-fr.2 by Th33;
            reconsider x=-m,y=n as Element of INT by INT_1:def 2;
            take fr1=<*x,y*>;
            thus len fr1=len fp1 by A6,FINSEQ_1:44;
            let b;
            assume b in dom fp1;
            then
A8:         b in Seg len fp1 by FINSEQ_1:def 3;
            now
              per cases by A6,A8,FINSEQ_1:2,TARSKI:def 2;
              suppose
                b=1;
                hence (fp1.b)*(fr1.b)+(fr.b)=(fp1.1)*(fr1.1)+(fr.1);
              end;
              suppose
A9:             b=2;
                (fp1.2)*n-(fp1.1)*(-m)=fr.1-fr.2 by A7;
                hence
                (fp1.b)*(fr1.b)+(fr.b)=(fp1.1)*(fr1.1)+(fr.1) by A9,
XCMPLX_1:34;
              end;
            end;
            hence (fp1.b)*(fr1.b)+(fr.b)=(fp1.1)*(fr1.1)+fr.1;
          end;
          hence CC[fp1];
        end;
        suppose
A11:      len fp1 > 2;
A12:      RP[fp]
          proof
A13:        dom fp c= dom fp1 by FINSEQ_1:26;
            let b,c such that
A14:        b in dom fp & c in dom fp and
A15:        b<>c;
            fp1.b=fp.b & (fp1.c)=fp.c by A14,FINSEQ_1:def 7;
            hence thesis by A4,A14,A15,A13;
          end;
A16:      k+1 > 1+1 by A11,FINSEQ_2:16;
          then
A17:      k >= 1+1 by NAT_1:13;
          now
            let fr2;
            assume
A18:        len fr2=len fp1;
            then consider
            fr being FinSequence of INT,m being Element of INT such
            that
A19:        fr2=fr^<*m*> by FINSEQ_2:19;
A20:        k + 1=len fr + 1 by A5,A18,A19,FINSEQ_2:16;
            then consider fr1 such that
            len fr1=k and
A21:        for b st b in dom fp holds (fp.b)*(fr1.b)+(fr.b)=(fp.1)*(
            fr1.1)+(fr .1) by A2,A16,A12,NAT_1:13;
            a in dom fp implies fp.a gcd d=1
            proof
A22:          (len fp+1) in dom fp1 by A5,FINSEQ_5:6;
A23:          dom fp c= dom fp1 & fp1.(len fp+1)=d by FINSEQ_1:26,42;
              assume
A24:          a in dom fp;
              len fp+1>len fp by NAT_1:13;
              then
A25:          len fp+1 <> a by A24,FINSEQ_3:25;
              fp1.a=fp.a by A24,FINSEQ_1:def 7;
              hence thesis by A4,A24,A23,A25,A22;
            end;
            then Product(fp) gcd d=1 by Th36;
            then (Product(fp) gcd d) divides (fr2.(k+1)-(fp.1)*(fr1.1)-fr2.1)
            by INT_2:12;
            then consider m1,n1 such that
A26:        Product(fp)*m1+d*n1=fr2.(k+1)-(fp.1)*(fr1.1)-fr2.1 by Th33;
            reconsider x=-n1 as Element of INT by INT_1:def 2;
            deffunc F(Nat) = Product Del(fp,$1)*m1+fr1.$1;
            consider s2 being FinSequence such that
A27:        len s2=k & for a being Nat st a in dom s2 holds s2.a=F(a)
            from FINSEQ_1:sch 2;
A28:        for a being Nat st a in dom s2 holds s2.a in INT
            proof
              let a be Nat;
              assume
A29:          a in dom s2;
              reconsider a as Element of NAT by ORDINAL1:def 12;
              s2.a=Product Del(fp,a)*m1+fr1.a by A27,A29;
              hence thesis by INT_1:def 2;
            end;
A30:        dom s2 = Seg k by A27,FINSEQ_1:def 3;
            reconsider s2 as FinSequence of INT by A28,FINSEQ_2:12;
            take fr3=s2^<*x*>;
            thus len fr3=len fp1 by A5,A27,FINSEQ_2:16;
            let b such that
A31:        b in dom fp1;
            thus (fp1.b)*(fr3.b)+(fr2.b)=(fp1.1)*(fr3.1)+(fr2.1)
            proof
A32:          c in Seg k implies (fp1.c)*(fr3.c)=Product(fp)*m1+(fp.c)*( fr1.c)
              proof
                assume
A33:            c in Seg k;
                then c in dom s2 by A27,FINSEQ_1:def 3;
                then
A34:            fr3.c = s2.c by FINSEQ_1:def 7
                  .=Product Del(fp,c)*m1+fr1.c by A27,A30,A33;
  for n being Nat st n in dom fp holds fp.n in REAL by XREAL_0:def 1;
  then
A35:      fp is FinSequence of REAL by FINSEQ_2:12;
A36:            c in dom fp by A33,FINSEQ_1:def 3;
                then fp.c = fp1.c by FINSEQ_1:def 7;
                hence
                (fp1.c)*(fr3.c)=(fp.c)*Product Del(fp,c)*m1+(fp.c)*(fr1.c
                ) by A34
                  .=Product(fp)*m1+(fp.c)*(fr1.c) by A36,Lm16,A35;
              end;
A37:          1<=b by A31,FINSEQ_3:25;
A38:          b<=k+1 by A5,A31,FINSEQ_3:25;
              now
                per cases by A38,NAT_1:8;
                suppose
A39:              b<=k;
                  then 1<=k by A37,XXREAL_0:2;
                  then
A40:              1 in Seg k;
                  then 1 in dom fr by A20,FINSEQ_1:def 3;
                  then
A41:              fr2.1=fr.1 by A19,FINSEQ_1:def 7;
A42:              b in Seg k by A37,A39;
                  then
A43:              b in dom fp by FINSEQ_1:def 3;
                  b in dom fr by A20,A42,FINSEQ_1:def 3;
                  then
A44:              fr2.b=fr.b by A19,FINSEQ_1:def 7;
                  thus (fp1.b)*(fr3.b)+(fr2.b)= Product(fp)*m1+(fp.b)*(fr1.b)+
                  (fr2.b) by A32,A42
                    .=Product(fp)*m1+((fp.b)*(fr1.b)+(fr.b)) by A44
                    .=Product(fp)*m1+((fp.1)*(fr1.1)+(fr.1)) by A21,A43
                    .=Product(fp)*m1+(fp.1)*(fr1.1)+(fr.1)
                    .=(fp1.1)*(fr3.1)+(fr2.1) by A32,A40,A41;
                end;
                suppose
A45:              b=k+1;
                  then
A46:              fp1.b=d by FINSEQ_1:42;
A47:              fr2.b-((fp.1)*(fr1.1)+fr2.1) =d*n1+ Product(fp)*m1 by A26,A45
;
                  1<=k by A17,XXREAL_0:2;
                  then 1 in Seg k;
                  then
                  (fp1.1)*(fr3.1)+(fr2.1)= Product(fp)*m1+(fp.1)*(fr1.1)+
                  (fr2.1) by A32
                    .=fr2.b+d*(-n1) by A47;
                  hence thesis by A27,A45,A46,FINSEQ_1:42;
                end;
              end;
              hence thesis;
            end;
          end;
          hence CC[fp1];
        end;
      end;
      hence CC[fp1];
    end;
    hence TH[fp1];
  end;
A48: TH[<*>NAT]
     proof
       take <*>NAT;
       thus thesis;
   end;
  for fp holds TH[fp] from FINSEQ_2:sch 2(A48,A1);
  then ex f being FinSequence of NAT st f = fp &
  ((len f>=2 & RP[f]) implies CC[f]);
  hence thesis;
end;
