reserve i,j,k,n,m for Nat,
        X for set,
        b,s for bag of X,
        x for object;
reserve O for Ordinal,
        R for right_zeroed add-associative right_complementable
          right_unital distributive non trivial doubleLoopStr,
        p for Polynomial of O, R;
reserve O for Ordinal,
        R for right_zeroed add-associative right_complementable
             right_unital distributive non trivial doubleLoopStr,
        p for Polynomial of O, R;

theorem Th77:
  ex K3 be INT -valued Polynomial of 8,F_Real st
    for x1,x2,x3,P,R,N be Nat,V be Integer st
        x1 is odd & x2 is odd & P > 0 &
        N > sqrt x1 + 2*sqrt x2 + 4*sqrt x3 +R
      holds
        (x1 is square & x2 is square  & x3 is square & P divides R & V>=0)
      iff
        ex z be Nat st for f be Function of 8,F_Real
              st f = <%z,x1,4*x2,16*x3%>^<%R,P,N,V%> holds eval(K3,f) = 0
proof
  set M = the Jpolynom of 4,F_Complex;
  set Ree = F_Real;
  reconsider RR=Ree as Field;
  consider  K2 be INT -valued Polynomial of 6,F_Real such that
A1:  (for f be Function of 6,F_Real st f.5 <>0
  holds eval(K2,f) = (power F_Real).(f/.5,8)*
  eval(Jsqrt M, @ <%- f.0 + (f.4/f.5),f.1,f.2,f.3%>)) and
A2:    for f be INT -valued Function of 6,F_Real st f.5 <>0 &
    eval(K2,f) = 0 holds f.5 divides f.4 by Th76;
  consider K28 be Polynomial of 6+2,Ree such that
A3: rng K28 c= rng K2 \/ {0.Ree} and
       for b be bag of 6+2 holds b in Support K28 iff b|6 in Support K2 &
                 for i st i >= 6 holds b.i=0 and
      for b be bag of 6+2 st b in Support K28 holds K28.b = K2.(b|6) and
A4:  for x being Function of 6, Ree,
         y being Function of (6+2), Ree st y|6=x
       holds eval(K2,x) = eval(K28,y) by Th75;
  rng K28 c= INT by A3,INT_1:def 2;
  then reconsider K28 as INT -valued Polynomial of 8,Ree by RELAT_1:def 19;
  set nb = (EmptyBag 8) +*(6,1),n=Monom(1.Ree,nb),
  vb = (EmptyBag 8) +*(7,1),v=Monom(- 1.Ree,vb),
  zb = (EmptyBag 8) +*(0,1),z=Monom(1.Ree,zb);
  reconsider v as INT -valued Polynomial of 8,Ree;
  set znv = z + n *' v;
  reconsider K3= Subst(K28,0,znv) as INT -valued Polynomial of 8,Ree;
  take K3;
A6: 0 in Segm 6 & 1 in Segm 6 & 2 in Segm 6 & 3 in Segm 6 &
  4 in Segm 6 & 5 in Segm 6 by NAT_1:44;
A7: 0 in Segm 8 & 1 in Segm 8 & 2 in Segm 8 & 3 in Segm 8 &
  4 in Segm 8 & 5 in Segm 8 & 6 in Segm 8 & 7 in Segm 8 by NAT_1:44;
  let x1,x2,x3,P,R,N be Nat,V be Integer such that
A8:    x1 is odd & x2 is odd & P > 0 &
  N > sqrt x1 + 2*sqrt x2 + 4*sqrt x3 +R;
  thus (x1 is square & x2 is square  & x3 is square & P divides R & V>=0)
  implies ex z be Nat st for f be Function of 8,F_Real
  st f = <%z,x1,4*x2,16*x3%>^<%R,P,N,V%> holds eval(K3,f) = 0
  proof
    assume
A9: x1 is square & x2 is square & x3 is square & P divides R & V>=0;
    then consider z1 be Integer such that
A10:  -z1 = sqrt x1 + 2* sqrt x2 + 4 *sqrt x3 and
A11:  eval(Jsqrt M,@<%z1,x1,4*x2,16*x3%>)=0 by Th74;
    consider d be Nat such that
A12: P*d = R by NAT_D:def 3,A9;
    set zd = - z1+d;
A13: R/P = (d*P)/(P*1) = d/1 =d by A12,A8,XCMPLX_1:91;
    set f6 = <%zd%>^<%x1%>^<%4*x2%>^<%16*x3%>^<%R%>^<%P%>;
    reconsider F6=@f6 as Function of 6,F_Real;
A14: F6.5 = P & F6.0 =zd & F6.4 = R & F6.5 = P & F6.1 = x1  &
    F6.2 = 4*x2 & F6.3 = 16*x3 by AFINSQ_1:47;
A15: eval(K2,F6) = (power F_Real).(F6/.5,8)*
    eval(Jsqrt M, @ <%- F6.0 + (F6.4/F6.5),F6.1,F6.2,F6.3%>) by A14,A1,A8
    .= 0 by A11,A14,A13;
    set zdv = zd+N*V;
    set f8 = <%zdv%>^<%x1%>^<%4*x2%>^<%16*x3%>^<%R%>^<%P%>^<%N%>^<%V%>;
    reconsider f=@f8 as Function of 8,F_Real;
    set y = zdv + N*(-V);
    reconsider Y=y,zzR=zdv,NR=N,VR=V as Element of Ree by XREAL_0:def 1;
    reconsider Yr=Y,zzr=zzR,Nr=NR,Vr=VR as Element of RR;
    zdv is set & x1 is set & 4*x2 is set & 16*x3 is set & R is set
    & P is set & N is set & V is set by TARSKI:1;
    then
A16:f.0= zdv & f.1 = x1 & f.2 = 4*x2 & f.3 = 16*x3 & f.4 = R
    & f.5 = P & f.6 = N & f.7 = V by AFINSQ_1:49;
A17:eval(zb,f) = power(Ree).(f.0,1) by A7,Th14
    .= zzR by GROUP_1:50,A16;
A18:eval(z,f) = 1.Ree * eval(zb,f) by POLYNOM7:13
    .= zzR by A17;
A19:eval(vb,f) = power(Ree).(f.7,1) by A7,Th14
    .= VR by GROUP_1:50,A16;
A20:eval(v,f) = (-1.Ree) * eval(vb,f) by POLYNOM7:13
    .= -VR by A19
    .= -Vr;
A21:eval(nb,f) = power(Ree).(f.6,1) by A7,Th14
    .= NR by GROUP_1:50,A16;
A22:eval(n,f) = (1.Ree) * eval(nb,f) by POLYNOM7:13
    .= Nr by A21;
A23:eval(n *' v,f) = Nr * (-Vr) by A20,A22,POLYNOM2:25
    .= multreal.(N,-VR)
    .= N*(-V) by BINOP_2:def 11;
A24: eval(znv,f) =eval(z,f) + eval(n *' v,f) by POLYNOM2:23
    .= zdv + N*(-V) by A23,A18;
A25: dom(f+*(0,Y)) = 8 =dom f by PARTFUN1:def 2;
A26:Segm 6 c= Segm 8 by NAT_1:39;
    then
A27: dom ((f+*(0,Y))|6) = 6 by PARTFUN1:def 2;
    for x st x in 6 holds f6.x = ((f+*(0,Y))|6).x
    proof
      let x such that
A28:  x in 6;
A29:  x in Segm 6 by A28;
      then reconsider x as Nat;
A30:  ((f+*(0,Y))|6).x = (f+*(0,Y)).x by A28,FUNCT_1:49;
      per cases;
      suppose x=0;
        hence thesis by A30,A14,A25,A28,A26,FUNCT_7:31;
      end;
      suppose
A31:    x<>0;
        then
A32:    (f+*(0,Y)).x = f.x by FUNCT_7:32;
        x <6=5+1 by A29,NAT_1:44;
        then x <= 5 by NAT_1:13;
        then x=0 or ... or x= 5;
        hence thesis by A31,A28,FUNCT_1:49,A16,A14,A32;
      end;
    end;
    then
A33: (f+*(0,Y))|6 = F6 by PARTFUN1:def 2,A27;
    eval(K3,f) = eval(K28, f+*(0,Y)) by A24, Th37,A7;
    then
A34: eval(K3,f) = 0 by A15,A33,A4;
    set zdv = zd+N*V;
    reconsider zdv as Element of NAT by A9,A10,INT_1:3;
    take Z=zdv;
    let F be Function of 8,F_Real such that
A35: F = <%Z,x1,4*x2,16*x3%>^<%R,P,N,V%>;
    F = <%Z%>^<%x1%>^<%4*x2%>^<%16*x3%>^<%R,P,N,V%> by A35,AFINSQ_1:def 14
    .= <%Z%>^<%x1%>^<%4*x2%>^<%16*x3%>^(<%R%>^<%P%>^<%N%>^<%V%>)
    by AFINSQ_1:def 14
    .= <%Z%>^<%x1%>^<%4*x2%>^<%16*x3%>^(<%R%>^<%P%>^<%N%>)^<%V%> by AFINSQ_1:27
    .= <%Z%>^<%x1%>^<%4*x2%>^<%16*x3%>^(<%R%>^<%P%>)^<%N%>^<%V%>
    by AFINSQ_1:27;
    hence thesis by A34,AFINSQ_1:27;
  end;
  given zz be Nat such that
A36: for f be Function of 8,F_Real st f = <%zz,x1,4*x2,16*x3%>^<%R,P,N,V%>
    holds eval(K3,f) = 0;
  <%zz,x1,4*x2,16*x3%>^<%R,P,N,V%> = @(<%zz,x1,4*x2,16*x3%>^<%R,P,N,V%>);
  then reconsider f = <%zz,x1,4*x2,16*x3%>^<%R,P,N,V%>
  as INT -valued Function of 8,F_Real;
A37:zz is set & x1 is set & 4*x2 is set & 16*x3 is set & R is set
  & P is set & N is set & V is set by TARSKI:1;
  <%zz,x1,4*x2,16*x3%> = <%zz%>^<%x1%>^<%4*x2%>^<%16*x3%> by AFINSQ_1:def 14;
  then
A38: f = <%zz%>^<%x1%>^<%4*x2%>^<%16*x3%>^(<%R%>^<%P%>^<%N%>^<%V%>)
  by AFINSQ_1:def 14
  .= <%zz%>^<%x1%>^<%4*x2%>^<%16*x3%>^(<%R%>^<%P%>^<%N%>)^<%V%> by AFINSQ_1:27
  .= <%zz%>^<%x1%>^<%4*x2%>^<%16*x3%>^(<%R%>^<%P%>)^<%N%>^<%V%> by AFINSQ_1:27
  .= <%zz%>^<%x1%>^<%4*x2%>^<%16*x3%>^<%R%>^<%P%>^<%N%>^<%V%> by AFINSQ_1:27;
  then
A39: f.0= zz & f.1 = x1 & f.2 = 4*x2 & f.3 = 16*x3 & f.4 = R
  & f.5 = P & f.6 = N & f.7 = V by A37,AFINSQ_1:49;
A40: eval(K3,f) = 0 by A36;
A41: eval(K3,f) = eval(K28, f+*(0,eval(znv,f))) by A7,Th37;
A42: dom f = Segm 8 by PARTFUN1:def 2;
  set y = - N*V + zz;
  reconsider Y=y,zzR=zz,NR=N,VR=V as Element of Ree by XREAL_0:def 1;
  reconsider Yr=Y,zzr=zzR,Nr=NR,Vr=VR as Element of RR;
A43: eval(zb,f) = power(Ree).(f.0,1) by A7,Th14
  .= zzR by GROUP_1:50,A39;
A44: eval(z,f) = 1.Ree * eval(zb,f) by POLYNOM7:13
  .= zzR by A43;
A45: eval(vb,f) = power(Ree).(f.7,1) by A7,Th14
  .= VR by GROUP_1:50,A39;
A46: eval(v,f) = (-1.Ree) * eval(vb,f) by POLYNOM7:13
  .= -VR by A45
  .= -Vr;
A47: eval(nb,f) = power(Ree).(f.6,1) by A7,Th14
  .= NR by GROUP_1:50,A39;
A48:  eval(n,f) = (1.Ree) * eval(nb,f) by POLYNOM7:13
  .= Nr by A47;
A49: eval(n *' v,f) = Nr * (-Vr) by A46,A48,POLYNOM2:25
  .= multreal.(N,-VR)
  .= N*(-V) by BINOP_2:def 11;
A50:eval(znv,f) =eval(z,f) + eval(n *' v,f) by POLYNOM2:23
  .= zz + N*(-V) by A49,A44;
  set f6 = (f+*(0,Y))|6;
A51: f6.0 = (f+*(0,Y)).0 = Y & f6.1 = (f+*(0,Y)).1 = f.1 =x1 &
  f6.2 = (f+*(0,Y)).2 = f.2 =4*x2 & f6.3 = (f+*(0,Y)).3 = f.3 =16*x3 &
  f6.4 = (f+*(0,Y)).4 = f.4 = R & f6.5 = (f+*(0,Y)).5 = f.5 =P
    by A38,A42,NAT_1:44,A6,FUNCT_1:49,FUNCT_7:31,32,A37,AFINSQ_1:49;
A52: rng f6 c= the carrier of F_Real;
  Segm 6 c= Segm 8 by NAT_1:39;
  then
A53: dom f6 = 6 by PARTFUN1:def 2;
  then reconsider f6 as Function of 6,F_Real by A52,FUNCT_2:2;
  rng (f +*(0,Y)) c= (rng f) \/{y} by FUNCT_7:100;
  then rng (f +*(0,Y)) c= INT by INT_1:def 2;
  then reconsider f6 as INT -valued Function of 6,F_Real;
A54:f6/.5 <>0 by A8,A51,A6,A53,PARTFUN1:def 6;
A55:  eval(K2,f6) = 0 by A4,A50,A40,A41;
  consider d be Nat such that
A56: P *d= R by NAT_D:def 3,A55,A51,A2,A8;
A57: R/P = (d*P)/(P*1) = d/1 =d by A56,A8,XCMPLX_1:91;
A58: (power Ree).(f6/.5,8)<>0 by A54,Th6;
  eval(K2,f6) = (power Ree).(f6/.5,8)*
  eval(Jsqrt M, @ <%- f6.0 + (f6.4/f6.5),f6.1,f6.2,f6.3%>) by A1,A8,A51;
  then
A59:eval(Jsqrt M, @ <%- y + d,x1,4*x2,16*x3%>) = 0
    by A57,A51,A4,A50,A40,A41,A58;
  then x1 is square & x2 is square & x3 is square &
  -(- y + d) <= sqrt x1+2*sqrt x2 + 4*sqrt x3 by A8,Th73;
  then
A60: - N*V + (zz - d)- (zz - d) <= sqrt x1+2*sqrt x2 + 4*sqrt x3 - (zz - d)
  by XREAL_1:9;
A61:sqrt x2 >=0 & sqrt x3 >=0 by SQUARE_1:def 2;
  0 < sqrt x1 by A8,SQUARE_1:25;
  then
A62: 0+0 < sqrt x1 + (2*sqrt x2 + 4*sqrt x3 +R) by A61;
A63: (- N*V)/(-N) >= (sqrt x1+2*sqrt x2 + 4*sqrt x3 +d - zz)/(-N)
    by A60,XREAL_1:73;
A64: (- N*V)/(-N) = V *((-N)/(-N))
  .= V*1 by A62,A8,XCMPLX_1:60;
  1*d <= P*d by XREAL_1:64,NAT_1:14,A8;
  then
A65: sqrt x1+2*sqrt x2 + 4*sqrt x3 - zz +d <=
    sqrt x1+2*sqrt x2 + 4*sqrt x3 - zz + R by A56,XREAL_1:7;
  sqrt x1+2*sqrt x2 + 4*sqrt x3 + R -zz <= sqrt x1+2*sqrt x2 +
    4*sqrt x3 + R -0 by XREAL_1:10;
  then sqrt x1+2*sqrt x2 + 4*sqrt x3 - zz +d <= sqrt x1+2*sqrt x2 +
  4*sqrt x3 + R by A65,XXREAL_0:2;
  then sqrt x1+2*sqrt x2 + 4*sqrt x3 - zz +d < N by A8,XXREAL_0:2;
  then (sqrt x1+2*sqrt x2 + 4*sqrt x3 +d - zz)/(-N) > (N)/(-N)
    by A62,A8,XREAL_1:75;
  then V > N/(-N) by A63,A64,XXREAL_0:2;
  then V > -(N/N) by XCMPLX_1:188;
  then V > -1 by A62,A8,XCMPLX_1:60;
  then V >= -1+1 by INT_1:7;
  hence thesis by A59,A8,Th73,A55,A51,A2;
end;
