reserve n,i,j,k for Nat;
reserve T for TuringStr,
  s for All-State of T;

theorem Th27:
  for s being All-State of SumTuring, t be Tape of SumTuring, head
,n1,n2 be Element of NAT st s=[0,head,t] & t storeData <*head,n1,n2 *> holds s
is Accept-Halt & (Result s)`2_3=1+head &
   (Result s)`3_3 storeData <*1+head,n1+n2 *>
proof
  reconsider F=0 as Symbol of SumTuring by Lm2;
  let s be All-State of SumTuring, t be Tape of SumTuring, h,n1,n2 be Element
  of NAT;
  assume that
A1: s=[0,h,t] and
A2: t storeData <*h,n1,n2 *>;
A3: t.(h+n1+2)=0 by A2,Th19;
  set j3=h+n1+n2+4-1;
  reconsider h1=h+1 as Element of INT by INT_1:def 2;
A4: h < h1 by XREAL_1:29;
  set t1=Tape-Chg(t,h1,F);
A5: h+1+1+n1=h+n1+2;
  reconsider p4=4 as State of SumTuring by Lm1;
  reconsider m3=j3 as Element of INT by INT_1:def 2;
  set j2=j3-1;
  reconsider m2=j2 as Element of INT by INT_1:def 2;
  set j1=n1+n2+1;
  set Rs=(Computation s).(n1+1+(n2+1)+1+1+(1+1)+(j1+1));
  reconsider p2=2 as State of SumTuring by Lm1;
  reconsider i2=h1+1 as Element of INT by INT_1:def 2;
  reconsider nk=h1+1+n1 as Element of INT by INT_1:def 2;
  set i3=h+1+1+n1+1;
  reconsider n3=i3 as Element of INT by INT_1:def 2;
A6: j2-1=h+j1;
  reconsider T=1 as Symbol of SumTuring by Lm2;
  set t2=Tape-Chg(t1,nk,T);
A7: h1+1 <= h+1+1+n1 & h1 < h1+1 by NAT_1:11,XREAL_1:29;
  set i4=h+n1+n2+4;
  reconsider p0=0 as State of SumTuring by Lm1;
  set s1= [p0,h1,t];
A8: t.h=0 by A2,Th19;
  h <= h+n1 by NAT_1:11;
  then
A9: h+2 <= h+n1+2 by XREAL_1:7;
A10: t.(h+n1+n2+4)=0 by A2,Th19;
  h <= h+(n1+n2) by NAT_1:11;
  then
A11: h+4 <= h+n1+n2+4 by XREAL_1:7;
  then
A12: h1 < h+3 & h+4-1 <= j3 by XREAL_1:8,9;
A13: h1 < h+2 by XREAL_1:8;
  then
A14: h1 < h+n1+2 by A9,XXREAL_0:2;
A15: t.h=0 by A2,Th19;
A16: t1.h=0 & t1.(h+n1+2)=0 & t1.(h+n1+n2+4)=0 & (for i be Integer st h1 < i
  & i < h+1+1+n1 holds t1.i=1) & for i be Integer st h+n1+2 < i & i < h+n1+n2+4
  holds t1.i=1
  proof
    thus t1.h=0 by A15,A4,Th26;
    thus t1.(h+n1+2)=0 by A3,A9,A13,Th26;
    h1 < h+4 by XREAL_1:8;
    hence t1.(h+n1+n2+4)=0 by A10,A11,Th26;
    hereby
      let i be Integer;
      assume that
A17:  h1 < i and
A18:  i < h+1+1+n1;
A19:  h < i by A4,A17,XXREAL_0:2;
      thus t1.i=t.i by A17,Th26
        .=1 by A2,A5,A18,A19,Th19;
    end;
    hereby
      let i be Integer;
      assume that
A20:  h+n1+2 < i and
A21:  i < h+n1+n2+4;
      thus t1.i=t.i by A14,A20,Th26
        .=1 by A2,A20,A21,Th19;
    end;
  end;
A22: for i be Integer st h+1+1 <= i & i < h+1+1+n1 holds t1.i=1
  proof
    let i be Integer;
    assume that
A23: h+1+1 <= i and
A24: i < h+1+1+n1;
    h1 < h1+1 by XREAL_1:29;
    then h1 < i by A23,XXREAL_0:2;
    hence thesis by A16,A24;
  end;
  set t3=Tape-Chg(t2,j3,F);
A25: t1.h1=0 by Th26;
A26: t2.h1=0 & t2.(h+n1+n2+4)=0 & for i be Integer st h1 < i & i < h+n1+n2+4
  holds t2.i=1
  proof
    thus t2.h1=0 by A25,A7,Th26;
    h+n1 <= h+n1+n2 by NAT_1:11;
    then
A27: h+1+1+n1 <= h+n1+n2+2 by A5,XREAL_1:7;
    h+n1+n2+2 < h+n1+n2+4 by XREAL_1:8;
    hence t2.(h+n1+n2+4)=0 by A16,A27,Th26;
    hereby
      let i be Integer;
      assume that
A28:  h1 < i and
A29:  i < h+n1+n2+4;
      per cases by XXREAL_0:1;
      suppose
A30:    i < h+1+1+n1;
        hence t2.i=t1.i by Th26
          .=1 by A16,A28,A30;
      end;
      suppose
        i = h+1+1+n1;
        hence t2.i=1 by Th26;
      end;
      suppose
A31:    i > h+1+1+n1;
        hence t2.i=t1.i by Th26
          .=1 by A16,A29,A31;
      end;
    end;
  end;
A32: t3.h1=0 & t3.j3=0 & for i be Integer st h1 < i & i < j3 holds t3.i=1
  proof
    thus t3.h1=0 by A26,A12,Th26;
    thus t3.j3=0 by Th26;
    hereby
      let i be Integer;
      assume that
A33:  h1 < i and
A34:  i < j3;
A35:  i < h+n1+n2+4 by A34,XREAL_1:146,XXREAL_0:2;
      thus t3.i=t2.i by A34,Th26
        .=1 by A26,A33,A35;
    end;
  end;
  then
A36: t3 is_1_between h1,h1+(n1+n2)+2;
  reconsider p3=3 as State of SumTuring by Lm1;
  set sm=[p2,n3,t2];
  reconsider n4=i4 as Element of INT by INT_1:def 2;
  set sp2=[p2,n4,t2];
  set sp3=[p3,m3,t2];
  reconsider p1=1 as State of SumTuring by Lm1;
  set s2=[p1,i2,t1];
  set sn=[p1,nk,t1];
  reconsider sn3=sn`3_3 as Tape of SumTuring;
A37: TRAN(sn) =Sum_Tran.[sn`1_3, sn3.Head(sn)] by Def14
    .=Sum_Tran.[p1,sn3.Head(sn)]
    .=Sum_Tran.[p1,t1.Head(sn)]
    .=[2,1,1] by A16,Th14;
  then
A38: offset TRAN(sn)=1;
  reconsider sn3=sp2`3_3 as Tape of SumTuring;
A39: TRAN(sp2) =Sum_Tran.[sp2`1_3, sn3.Head(sp2)] by Def14
    .=Sum_Tran.[p2,sn3.Head(sp2)]
    .=Sum_Tran.[p2,t2.Head(sp2)]
    .=[3,0,-1] by A26,Th14;
  then
A40: offset TRAN(sp2)=-1;
  Tape-Chg(sp2`3_3, Head(sp2),(TRAN(sp2))`2_3)=Tape-Chg(t2, Head(sp2), (TRAN(
  sp2))`2_3)
    .=Tape-Chg(t2,i4,(TRAN(sp2))`2_3)
    .=Tape-Chg(t2,i4,F) by A39
    .=t2 by A26,Th24;
  then
A41: Following sp2 = [(TRAN(sp2))`1_3, Head(sp2)+ offset TRAN(sp2), t2] by Lm3
    .= [3, Head(sp2)+ offset TRAN(sp2), t2] by A39
    .= [3, j3,t2] by A40;
  Tape-Chg(sn`3_3, Head(sn),(TRAN(sn))`2_3)=Tape-Chg(t1, Head(sn),(TRAN(sn))
  `2_3)
    .=Tape-Chg(t1,nk,(TRAN(sn))`2_3)
    .=t2 by A37;
  then
A42: Following sn = [(TRAN(sn))`1_3, Head(sn)+ offset TRAN(sn), t2] by Lm3
    .= [2, Head(sn)+ offset TRAN(sn), t2] by A37
    .= sm by A38;
  reconsider s3=s`3_3 as Tape of SumTuring;
A43: TRAN(s) =Sum_Tran.[s`1_3, s3.Head(s)] by Def14
    .=Sum_Tran.[0,s3.Head(s)] by A1
    .=Sum_Tran.[0,t.Head(s)] by A1
    .=Sum_Tran.[0,t.h ] by A1
    .=[0,0,1] by A2,Th14,Th19;
  then
A44: offset TRAN(s)=1;
A45: h1 < h1+1+n1 by A7,XXREAL_0:2;
A46: for i be Integer st i3 <= i & i < i3+(n2+1) holds t2.i=1
  proof
    let i be Integer;
    assume that
A47: i3 <= i and
A48: i < i3+(n2+1);
    nk < i3 by XREAL_1:29;
    then h1 < i3 by A45,XXREAL_0:2;
    then h1 < i by A47,XXREAL_0:2;
    hence thesis by A26,A48;
  end;
  set sp5=[p4, h1, t3];
  set sp4=[p4,m2,t3];
  defpred R[Nat] means
   h+$1 < j2 implies (Computation sp4).$1=[4,j2-$1,t3];
  (the Tran of SumTuring).[p2,1] =[p2,1,1] & p2 <> the AcceptS of
  SumTuring by Def14,Th14;
  then
A49: (Computation sm).(n2+1)=[2,h+n1+n2+4,t2] by A46,Lm4;
  h1 < j3 by A12,XXREAL_0:2;
  then
A50: t2.j3=1 by A26,XREAL_1:146;
  reconsider sn3=sp3`3_3 as Tape of SumTuring;
A51: TRAN(sp3) =Sum_Tran.[sp3`1_3, sn3.Head(sp3)] by Def14
    .=Sum_Tran.[p3,sn3.Head(sp3)]
    .=Sum_Tran.[p3,t2.Head(sp3)]
    .=[4,0,-1] by A50,Th14;
  then
A52: offset TRAN(sp3)=-1;
A53: for k being Nat st R[k] holds R[k+1]
  proof
    let k be Nat;
    assume
A54: R[k];
    now
      reconsider ik=j2-k as Element of INT by INT_1:def 2;
      set k3=j2-k;
      set sk=[p4,ik,t3];
      reconsider tt=sk`3_3 as Tape of SumTuring;
      assume
A55:  h+(k+1) < j2;
      then h1+k < j2+0;
      then
A56:  h1-0 < j2-k by XREAL_1:21;
      reconsider ii=j2-k as Element of NAT by A56,INT_1:3;
      j2 <= j2+k by INT_1:6;
      then j2 -k <= j2 by XREAL_1:20;
      then j2 -k < j3 by XREAL_1:146,XXREAL_0:2;
      then
A57:  t3.ii=1 by A32,A56;
A58:  TRAN(sk) =Sum_Tran.[sk`1_3, tt.Head(sk)] by Def14
        .=Sum_Tran.[p4,tt.Head(sk)]
        .=Sum_Tran.[p4,t3.Head(sk)]
        .=[4,1,-1] by A57,Th14;
      then
A59:  offset TRAN(sk)=-1;
A60:  Tape-Chg(sk`3_3, Head(sk),(TRAN(sk))`2_3)=Tape-Chg(t3,Head(sk), (TRAN(
      sk))`2_3)
        .=Tape-Chg(t3,k3,(TRAN(sk))`2_3)
        .=Tape-Chg(t3,k3,T) by A58
        .=t3 by A57,Th24;
      h+k < h+k+1 by XREAL_1:29;
      hence (Computation sp4).(k+1)=Following sk by A54,A55,Def7,XXREAL_0:2
        .= [(TRAN(sk))`1_3, Head(sk)+ offset TRAN(sk), t3] by A60,Lm3
        .= [4, Head(sk)+ offset TRAN(sk), t3] by A58
        .= [4, j2-k+-1, t3] by A59
        .= [4, j2-(k+1), t3];
    end;
    hence thesis;
  end;
A61: R[0] by Def7;
  for k being Nat holds R[k] from NAT_1:sch 2(A61,A53);
  then
A62: (Computation sp4).j1=[4,j2-j1,t3] by A6,XREAL_1:146
    .=sp5;
  reconsider s3=s1`3_3 as Tape of SumTuring;
A63: TRAN(s1) =Sum_Tran.[s1`1_3, s3.Head(s1)] by Def14
    .=Sum_Tran.[p0,s3.Head(s1)]
    .=Sum_Tran.[p0,t.Head(s1)]
    .=Sum_Tran.[0,t.h1]
    .=[1,0,1] by A2,A4,A14,Th14,Th19;
  then
A64: offset TRAN(s1)=1;
  Tape-Chg(sp3`3_3, Head(sp3),(TRAN(sp3))`2_3)=Tape-Chg(t2, Head(sp3), (TRAN(
  sp3))`2_3)
    .=Tape-Chg(t2,j3,(TRAN(sp3))`2_3)
    .=t3 by A51;
  then
A65: Following sp3 = [(TRAN(sp3))`1_3, Head(sp3)+ offset TRAN(sp3), t3] by Lm3
    .= [4, Head(sp3)+ offset TRAN(sp3), t3] by A51
    .= sp4 by A52;
A66: now
    reconsider tt=sp5`3_3 as Tape of SumTuring;
A67: TRAN(sp5) =Sum_Tran.[sp5`1_3, tt.Head(sp5)] by Def14
      .=Sum_Tran.[4,tt.Head(sp5)]
      .=Sum_Tran.[4,t3.Head(sp5)]
      .=[5,0,0] by A32,Th14;
    then
A68: offset TRAN(sp5)=0;
    Tape-Chg(sp5`3_3, Head(sp5),(TRAN(sp5))`2_3) =Tape-Chg(t3, Head(sp5),(
    TRAN(sp5))`2_3)
      .=Tape-Chg(t3,h1,(TRAN(sp5))`2_3)
      .=Tape-Chg(t3,h1,F) by A67
      .=t3 by A32,Th24;
    hence Following sp5 = [(TRAN(sp5))`1_3, Head(sp5)+ offset TRAN(sp5), t3]
by Lm3
      .= [5, Head(sp5)+ offset TRAN(sp5), t3] by A67
      .= [5, h1+ 0, t3] by A68;
  end;
  Tape-Chg(s1`3_3, Head(s1),(TRAN(s1))`2_3)=Tape-Chg(t, Head(s1),(TRAN(s1))`2_3
  )
    .=Tape-Chg(t,h1,(TRAN(s1))`2_3)
    .=t1 by A63;
  then
A69: Following s1 = [(TRAN(s1))`1_3, Head(s1)+ offset TRAN(s1), t1] by Lm3
    .= [1, Head(s1)+ offset TRAN(s1), t1] by A63
    .= s2 by A64;
  Tape-Chg(s`3_3, Head(s),(TRAN(s))`2_3)=Tape-Chg(t, Head(s),(TRAN(s))`2_3)
   by A1
    .=Tape-Chg(t,h,(TRAN(s))`2_3) by A1
    .=Tape-Chg(t,h,F) by A43
    .=t by A8,Th24;
  then
A70: Following s = [(TRAN(s))`1_3, Head(s)+offset TRAN(s),t] by A1,Lm3
    .= [0, Head(s)+ offset TRAN(s),t] by A43
    .= s1 by A1,A44;
  (Computation s).(1+1)= Following (Computation s).1 by Def7
    .=s2 by A70,A69,Th9;
  then (Computation s).(n1+1+(n2+1)+1+1+(1+1)) = (Computation s2).(n1+1+(n2+1
  )+1+1) by Th10;
  then (Computation s).(n1+1+(n2+1)+1+1+(1+1)) = Following (Computation s2).(
  n1+1+(n2+1)+1) by Def7
    .= Following Following (Computation s2).(n1+1+(n2+1)) by Def7
    .= Following Following (Computation (Computation s2).(n1+1)).(n2+1) by Th10
;
  then
A71: Rs=(Computation Following Following (Computation (Computation s2).(n1+
  1)).(n2+1)).(j1+1) by Th10
    .=(Computation Following Following (Computation Following (Computation
  s2).n1).(n2+1)).(j1+1) by Def7;
  (the Tran of SumTuring).[p1,1] =[p1,1,1] & p1 <> the AcceptS of
  SumTuring by Def14,Th14;
  then Rs=(Computation Following sp3).(j1+1) by A22,A42,A49,A41,A71,Lm4;
  then
A72: Rs=[5, h1, t3] by A65,A62,A66,Def7;
  then
A73: Rs`1_3 = 5
    .=the AcceptS of SumTuring by Def14;
  hence s is Accept-Halt;
  then
A74: Result s =Rs by A73,Def9;
  hence (Result s)`2_3= 1+h by A72;
  (Result s)`3_3= t3 by A72,A74;
  hence thesis by A36,Th16;
end;
