42
Markov chain model of machine code program execution and halting Riccardo Poli and Bill Langdon Department of Computer Science University of Essex

Markov chain model of machine code program execution and halting

  • Upload
    carol

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

Markov chain model of machine code program execution and halting. Riccardo Poli and Bill Langdon Department of Computer Science University of Essex. Halting problem. Logic states that whether or not programs halt is an undecidable problem (Turing) Probability gives answer: - PowerPoint PPT Presentation

Citation preview

Page 1: Markov chain model of machine code program execution and halting

Markov chain model of machine code program execution and halting

Riccardo Poli and Bill Langdon

Department of Computer Science

University of Essex

Page 2: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 2

Halting problem Logic states that whether or not programs halt

is an undecidable problem (Turing) Probability gives answer:

with probability 1, all programs without halt instruction do not terminate (Langdon & Poli)

Page 3: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 3

OverviewMemory and loops make linear GP Turing

complete, but what is the effect search space and fitness?

T7 computerExperiments Markov chain modelImplications

Page 4: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 4

Introduction Without memory and loops distribution of

functionality for GP programs tends to a limit as programs get bigger

True for Turing complete programs?

Page 5: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 5

T7 Minimal Turing Complete CPU 7 instructions Arithmetic unit is ADD. From + all other

operations can be obtained. E.g. Boolean logic SUB, by adding complement Multiply, by repeated addition (subroutines)

Conditional (Branch if oVerflow flag Set) Move data in memory Save and restore Program Counter (i.e. Jump) Stop if reach end of program

Page 6: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 6

T7 Architecture

Page 7: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 7

Experiments There are too many programs to test them all.

Instead we gather statistics on random samples. Chose set of program lengths 30 to 16777215 Generate 1000 programs of each length Run them from random start point with random

input Program terminates if it obeys the last instruction

(which must not be a jump) How many stop?

Page 8: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 8

Almost all T7 Programs Loop

Page 9: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 9

Model of Random Programs Before any repeated instructions;

random sequence of instructions and random contents of memory.

1 in 7 instructions is a jump to a random location

Page 10: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 10

Model of Random Programs T7 instruction set chosen to have little bias.

I.e. every state is ≈equally likely. Overflow flag set half the time. So 50% of conditional jumps BVS are active.

(1+0.5)/7 instructions takes program counter to a random location.

Implies for long programs, lengths of continuous instructions (i.e. without jumps) follows a geometric distribution with mean 7/1.5=4.67

Page 11: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 11

Program segment = random code ending with a random jump

Page 12: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 12

Forming Loops:Segments model Segments model assumes whole program is

broken into N=L/4.67 segments of equal length of continuous instructions.

Last instruction of each is a random jump. By the end of each segment, memory is re-

randomised. Jump to any part of a segment, part of which

has already been run, will form a loop. Jump to any part of the last segment will halt

the program.

Page 13: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 13

Probability of Halting i segments run so far. Chance next segment

will Form first loop = i/N Halt program = 1/N (so 1-(i+1)/N continues)

Chance of halting immediately after segment i= 1/N × (1-2/N) (1-3/N) (1-4/N) … (1-i/N)

Total halting probability given by adding these gives ≈ sqrt(π/2N) = O(N-½)

Page 14: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 14

Proportion of programs without loops falls as 1/sqrt(length)

Segments model over, but gives 1/√x scaling.

Page 15: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 15

Number of halting programsrises exponentially with length

10100 000 000

Page 16: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 16

Average run time (non-looping)

Segments model allows us to compute a bound for runtime

Expected run time grows as O(N½)

Page 17: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 17

Run time on terminating programs

Run time of non-looping programs fits Markov prediction.

Mean run time of all terminating programs length3/4

Max run time limited by small,12 bytes, memory becoming non-random

Page 18: Markov chain model of machine code program execution and halting

Markov chain model

Page 19: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 19

States State 0 = no instructions executed, yet State i = i instructions but no loops have been

executed Sink state = at least one loop was executed Halt state = the last instruction has been

successfully executed and program counter has gone beyond it.

Page 20: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 20

Event diagram for program execution 1/2

Page 21: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 21

Event diagram for program execution 2/2

Page 22: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 22

p1 = probability of being the last instruction Program execution starts from a random

position Memory is randomly initialised and, so, any

jumps land at random locations Then, the probability of being at the last

instruction in a program is independent of how may (new) instructions have been executed so far.

So,

Page 23: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 23

p2 = probability of instruction causing a jump We assume that we have two types of jumps

unconditional jumps (prob. puj, where PC is given a value retrieved from memory or from a register

conditional jumps (prob. pcj)

Fag bit (which causes conditional jumps) is set

with probability pf The total probability that the current instruction

will cause a jump is

Page 24: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 24

p3= probability of new instruction after jump Program counter after a jump is a random

number between 1 and L So, the probability of finding a new

instruction is

Page 25: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 25

p4 = probability of new instruction after non-jump The more jumps we have executed the more

fragmented the map of visited instructions will look.

So, we should expect p4 to decrease as a function of the number of jumps/fragments.

Expected number of fragments (jumps) in a program having reached state i

Page 26: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 26

Each block will be preceded by at least one unvisited instruction

So, the probability of a previously executed instruction after a non-jump is

and

Page 27: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 27

A more precise model considers the probability of blocks being contiguous.

Expected number of actual blocks

hence

Page 28: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 28

State transition probabilities These are obtained by adding up “paths” in

the program execution event diagram

E.g. looping probability

Page 29: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 29

Less than L-1 instructions visited

Page 30: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 30

L-1 instructions visited

Page 31: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 31

Transition matrix For example, for T7 and L = 7 we obtain

0 instructions1 instructions2 instructions3 instructions4 instructions5 instructions6 instructionsloophalt

0 in

stru

ctio

ns

1 in

stru

ctio

ns

2 in

stru

ctio

ns

3 in

stru

ctio

ns

4 in

stru

ctio

ns

5 in

stru

ctio

ns

6 in

stru

ctio

ns

loop

halt

Page 32: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 32

Computing future state probabilities All is required is to take appropriate powers

of the Markov matrix M

Page 33: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 33

Examples

For T7, L=7 and i=3

For T7, L=7 and i=L

prob. halting in 3 instructions

prob. looping in 3 instructions

total halting probability

Page 34: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 34

Efficiency Computing halting probabilities requires a

potentially exponentially explosive computation to perform (ML)

We reordered calculations to obtain very efficient models which allow us to compute halting probabilities and expected number of instructions executed by

halting programs

for L = 10,000,000 or more (see paper for details)

Page 35: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 35

A good model?

Halting probability

Page 36: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 36

Instructions executed by halting programs

Page 37: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 37

Improved model accounting for memory correlation

Page 38: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 38

Search space characterisation From earlier work we know that for halting

programs, as the number of instructions executed grows, functionality approaches a limiting distribution.

The expected number of instructions actually executed by halting Turing complete programs indicates how close the distribution is to the limit.

E.g. for T7, very long programs have a tiny subset of their instructions executed (e.g., 1,000 instructions in programs of L = 1,000,000).

Page 39: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 39

Effective population size Often programs that do not terminate are

wasted fitness evaluations and are given zero fitness

The initial population is composed of random programs of which only a fraction p(halt) are expected to halt and so have fitness > 0.

We can use the Markov model to predict the effective population size Popsize × p(halt)

Page 40: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 40

Controlling p(halt) by varying jump probability or program length

L=10

L=100

L=1000

L=10000

Page 41: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 41

Aborting non-terminating programs The model can also be used to decide after

how many instructions to abort evaluation

time limit = m × expected instructions in halting programs

The GP runtime (at generation 0)

Page 42: Markov chain model of machine code program execution and halting

May 2006 R. Poli - University of Essex 42

Conclusions Experiment show that halting probability scales as

1/sqrt(length) Markov chain model of program execution (and

halting) is practical and accurate The halting probability 0 with length, so…

with probability 1, a program does not halt However, Turing complete GP possible if

appropriate parameter settings and/or fitness functions are used.