reserve N for with_zero set;
reserve N for with_zero set;
reserve x,y,z,A,B for set,
  f,g,h for Function,
  i,j,k for Nat;
reserve S for IC-Ins-separated non empty
     with_non-empty_values AMI-Struct over N,
  s for State of S;
reserve N for non empty with_zero set,
 S for IC-Ins-separated non empty with_non-empty_values AMI-Struct over N,
  s for State of S;
reserve n for Nat;
reserve N for with_zero non empty set;

theorem Th17:
  for S being halting IC-Ins-separated
non empty with_non-empty_values AMI-Struct over N,
  p be NAT-defined (the InstructionsF of S)-valued Function,
  s being State of S,
    k being Nat st p halts_on s
  holds Result(p,s) = Comput(p,s,k) iff p halts_at IC Comput(p,s,k)
proof
  let S be halting IC-Ins-separated
  non empty with_non-empty_values AMI-Struct over N;
  let p be NAT-defined (the InstructionsF of S)-valued Function;
  let s be State of S, k being Nat;
  assume
A1: p halts_on s;
   then consider n being Nat such that
A2: IC Comput(p,s,n) in dom p and
A3: CurInstr(p,Comput(p,s,n)) = halt S;
  hereby
    assume
A4:    Result(p,s) = Comput(p,s,k);
    consider i being Nat such that
A5:  Result(p,s) = Comput(p,s,i) and
A6:  CurInstr(p,Result(p,s)) = halt S by A1,Def9;
    reconsider i,n as Nat;
A7:  now per cases;
     suppose i <= n;
     hence Comput(p,s,i) = Comput(p,s,n) by A5,A6,Th5;
     end;
     suppose n <= i;
     hence Comput(p,s,i) = Comput(p,s,n) by A3,Th5;
     end;
    end;
    p.IC Comput(p,s,k) = halt S by A7,A6,A4,A2,A5,PARTFUN1:def 6;
    hence p halts_at IC Comput(p,s,k) by A7,A2,A5,A4;
  end;
  assume that
A8: IC Comput(p,s,k) in dom p and
A9:  p.IC Comput(p,s,k) = halt S;
A10:  CurInstr(p,Comput(p,s,k)) = halt S by A8,A9,PARTFUN1:def 6;
    reconsider k,n as Nat;
    now per cases;
     suppose n <= k;
     hence Comput(p,s,k) = Comput(p,s,n) by A3,Th5;
     end;
     suppose k <= n;
     hence Comput(p,s,k) = Comput(p,s,n) by A10,Th5;
     end;
    end;
  hence thesis by A3,Def9,A1;
end;
