reserve i,i1,i2,i3,i4,i5,j,r,a,b,x,y for Integer,
  d,e,k,n for Nat,
  fp,fk for FinSequence of INT,
  f,f1,f2 for FinSequence of REAL,
  p for Prime;
reserve fr for FinSequence of REAL;
reserve fr,f for FinSequence of INT;
reserve b,m for Nat;
reserve b for Integer;
reserve m for Integer;
reserve fp for FinSequence of NAT;

theorem Th34:
  p>2 & (for d st d in dom fp holds fp.d gcd p = 1) implies ex fr
being FinSequence of INT st len fr = len fp & (for d st d in dom fr holds fr.d
  = Lege (fp.d,p)) & Lege (Product fp,p) = Product fr
proof
  assume
A1: p>2;
  deffunc F(Nat) = Lege (fp.$1,p);
  set k = (p-'1) div 2;
  assume
A2: for d st d in dom fp holds fp.d gcd p = 1;
  set f = fp|^k;
  reconsider f as FinSequence of INT by FINSEQ_2:24,NUMBERS:17;
  consider fr being FinSequence such that
A3: len fr = len fp & for d being Nat st d in dom fr holds fr.d = F(d)
  from FINSEQ_1:sch 2;
  for d being Nat st d in dom fr holds fr.d in INT
  proof
    let d be Nat;
    assume d in dom fr;
    then fr.d = Lege (fp.d,p) by A3;
    hence thesis by INT_1:def 2;
  end;
  then reconsider fr as FinSequence of INT by FINSEQ_2:12;
A4: fp is FinSequence of REAL by FINSEQ_2:24,NUMBERS:19;
A5: len f = len fp by NAT_3:def 1;
  for d st d in dom fr holds fr.d,f.d are_congruent_mod p
  proof
    let d;
    assume
A6: d in dom fr;
    then d in dom fp by A3,FINSEQ_3:29;
    then fp.d gcd p = 1 by A2;
    then Lege (fp.d,p),(fp.d)|^k are_congruent_mod p by A1,Th28; then
A7: fr.d,(fp.d)|^k are_congruent_mod p by A3,A6;
    d in dom f by A3,A5,A6,FINSEQ_3:29;
    hence thesis by A7,NAT_3:def 1;
  end; then
A8: Product f,Product fr are_congruent_mod p by A3,A5,Th32,INT_1:14;
  Product(fp) gcd p = 1 by A2,WSIERP_1:36;
  then
  Lege (Product fp,p),(Product fp)|^((p-'1) div 2) are_congruent_mod p by A1
,Th28;
  then Lege (Product fp,p),Product f are_congruent_mod p by A4,NAT_3:15;
  then Lege (Product fp,p),Product fr are_congruent_mod p by A8,INT_1:15;
  then
A9: p divides (Lege (Product fp,p) - Product fr);
  take fr;
A10: for d st d in dom fr holds fr.d = 1 or fr.d = 0 or fr.d = -1
  proof
    let d;
    assume d in dom fr;
    then fr.d = Lege (fp.d,p) by A3;
    hence thesis by Th25;
  end;
  per cases by Th25;
  suppose
A11: Lege (Product fp,p) = 1;
    then A12: Product fr <> -1 by A1,A9,NAT_D:7;
    now
      assume Product fr = 0;
      then p = 1 by A9,A11,WSIERP_1:15;
      hence contradiction by A1;
    end;
    hence thesis by A3,A10,A11,Th31,A12;
  end;
  suppose
A13: Lege (Product fp,p) = 0;
A14:  now
      assume Product fr = -1;
      then p = 1 by A9,A13,WSIERP_1:15;
      hence contradiction by A1;
    end;
    now
      assume Product fr = 1;
      then p divides 1 by A9,A13,INT_2:10;
      then p = 1 by WSIERP_1:15;
      hence contradiction by A1;
    end;
    hence thesis by A3,A10,A13,Th31,A14;
  end;
  suppose
A15: Lege (Product fp,p) = -1;
A16:  now
      assume Product fr = 1;
      then p divides -2 by A9,A15;
      then p divides 2 by INT_2:10;
      hence contradiction by A1,NAT_D:7;
    end;
    now
      assume Product fr = 0;
      then p divides 1 by A9,A15,INT_2:10;
      then p = 1 by WSIERP_1:15;
      hence contradiction by A1;
    end;
    hence thesis by A3,A10,A15,Th31,A16;
  end;
end;
