:: A Tree of Execution of a Macroinstruction
:: by Artur Korni{\l}owicz
::
:: Copyright (c) 2003-2018 Association of Mizar Users

:: LocSeq
definition
let N be with_zero set ;
let S be non empty with_non-empty_values IC-Ins-separated standard AMI-Struct over N;
let M be Subset of NAT;
deffunc H1( object ) -> set = (canonical_isomorphism_of ((RelIncl ()),())) . \$1;
func LocSeq (M,S) -> Sequence of NAT means :Def1: :: AMISTD_3:def 1
( dom it = card M & ( for m being set st m in card M holds
it . m = (canonical_isomorphism_of ((RelIncl ()),())) . m ) );
existence
ex b1 being Sequence of NAT st
( dom b1 = card M & ( for m being set st m in card M holds
b1 . m = (canonical_isomorphism_of ((RelIncl ()),())) . m ) )
proof end;
uniqueness
for b1, b2 being Sequence of NAT st dom b1 = card M & ( for m being set st m in card M holds
b1 . m = (canonical_isomorphism_of ((RelIncl ()),())) . m ) & dom b2 = card M & ( for m being set st m in card M holds
b2 . m = (canonical_isomorphism_of ((RelIncl ()),())) . m ) holds
b1 = b2
proof end;
end;

:: deftheorem Def1 defines LocSeq AMISTD_3:def 1 :
for N being with_zero set
for S being non empty with_non-empty_values IC-Ins-separated standard AMI-Struct over N
for M being Subset of NAT
for b4 being Sequence of NAT holds
( b4 = LocSeq (M,S) iff ( dom b4 = card M & ( for m being set st m in card M holds
b4 . m = (canonical_isomorphism_of ((RelIncl ()),())) . m ) ) );

theorem :: AMISTD_3:1
for n being Nat
for N being with_zero set
for S being non empty with_non-empty_values IC-Ins-separated standard AMI-Struct over N
for F being Subset of NAT st F = {n} holds
LocSeq (F,S) = 0 .--> n
proof end;

registration
let N be with_zero set ;
let S be non empty with_non-empty_values IC-Ins-separated standard AMI-Struct over N;
let M be Subset of NAT;
cluster LocSeq (M,S) -> one-to-one ;
coherence
LocSeq (M,S) is one-to-one
proof end;
end;

:: Tree of Execution
definition
let N be with_zero set ;
let S be non empty with_non-empty_values IC-Ins-separated standard AMI-Struct over N;
let M be non empty preProgram of S;
func ExecTree M -> DecoratedTree of NAT means :Def2: :: AMISTD_3:def 2
( it . {} = FirstLoc M & ( for t being Element of dom it holds
( succ t = { (t ^ <*k*>) where k is Nat : k in card (NIC ((M /. (it . t)),(it . t))) } & ( for m being Nat st m in card (NIC ((M /. (it . t)),(it . t))) holds
it . (t ^ <*m*>) = (LocSeq ((NIC ((M /. (it . t)),(it . t))),S)) . m ) ) ) );
existence
ex b1 being DecoratedTree of NAT st
( b1 . {} = FirstLoc M & ( for t being Element of dom b1 holds
( succ t = { (t ^ <*k*>) where k is Nat : k in card (NIC ((M /. (b1 . t)),(b1 . t))) } & ( for m being Nat st m in card (NIC ((M /. (b1 . t)),(b1 . t))) holds
b1 . (t ^ <*m*>) = (LocSeq ((NIC ((M /. (b1 . t)),(b1 . t))),S)) . m ) ) ) )
proof end;
uniqueness
for b1, b2 being DecoratedTree of NAT st b1 . {} = FirstLoc M & ( for t being Element of dom b1 holds
( succ t = { (t ^ <*k*>) where k is Nat : k in card (NIC ((M /. (b1 . t)),(b1 . t))) } & ( for m being Nat st m in card (NIC ((M /. (b1 . t)),(b1 . t))) holds
b1 . (t ^ <*m*>) = (LocSeq ((NIC ((M /. (b1 . t)),(b1 . t))),S)) . m ) ) ) & b2 . {} = FirstLoc M & ( for t being Element of dom b2 holds
( succ t = { (t ^ <*k*>) where k is Nat : k in card (NIC ((M /. (b2 . t)),(b2 . t))) } & ( for m being Nat st m in card (NIC ((M /. (b2 . t)),(b2 . t))) holds
b2 . (t ^ <*m*>) = (LocSeq ((NIC ((M /. (b2 . t)),(b2 . t))),S)) . m ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines ExecTree AMISTD_3:def 2 :
for N being with_zero set
for S being non empty with_non-empty_values IC-Ins-separated standard AMI-Struct over N
for M being non empty preProgram of S
for b4 being DecoratedTree of NAT holds
( b4 = ExecTree M iff ( b4 . {} = FirstLoc M & ( for t being Element of dom b4 holds
( succ t = { (t ^ <*k*>) where k is Nat : k in card (NIC ((M /. (b4 . t)),(b4 . t))) } & ( for m being Nat st m in card (NIC ((M /. (b4 . t)),(b4 . t))) holds
b4 . (t ^ <*m*>) = (LocSeq ((NIC ((M /. (b4 . t)),(b4 . t))),S)) . m ) ) ) ) );

theorem :: AMISTD_3:2
for N being with_zero set
for S being non empty with_non-empty_values IC-Ins-separated halting standard AMI-Struct over N holds ExecTree (Stop S) = TrivialInfiniteTree --> 0
proof end;