Top Banner
Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop
29

Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

Mar 28, 2015

Download

Documents

Zoé Maldonado
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

Cognitive Computing: 2012

Consciousness and Computation: computing machinery & intelligence

3. EMULATION

Mark Bishop

Page 2: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 2

The Universal Machine Norma

Thesis: “With suitable coding of data, every algorithm can be represented as a flowchart program for NORMA.”

But how? Some obvious criticisms of NORMA include...

1: NORMA does not define enough operations and tests: No assignment, multiply, subtract, divide etc.

2: NORMA data types are too restricted: No provision for negative or floating point numbers.

3: Access to data is too restricted: No provision for ARRAYs of numbers.

4: The restriction to flowchart programs is too restrictive: No mechanism for procedures. At the very least one needs to be able to refer to

labels indirectly so that sub-routines can be constructed. 5: Other criticisms include:

The lack of string handling. No logical shifts etc.

The criticisms [1..4] are considered the most important.

Page 3: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 3

Informal ‘proof’ of thesis

To demonstrate that every algorithm can be coded as a NORMA flowchart program it is necessary to show how each of the main criticisms [1..4] can be answered.

Specify a new machine NORMA+ which has the desired feature.

Show how any program in NORMA+ can be –recoded as a flowchart program for NORMA.

Page 4: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 4

Answer to 1st criticism

Assignment to a constant (eg. A := 0)

Theorem: “Every WHILE program can be mapped onto a corresponding flowchart program”.

WHILE (A <> 0) DO A := A -1; END;

This WHILE program can be written as a ‘macro’.

Similar macros can be written for (A := 1), (A := 2) etc.

Page 5: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 5

Addition

A := A + B using [a];

Consider a macro to calculate (A := A + B). We need to use an extra register a, hence we write the macro as {A := A + B using a}

a := 0;

WHILE (B <> 0) DO {adds B into A and makes a copy of B}A := A + 1;a := a + 1;B := B - 1;

END;

WHILE (a <> 0) DO {resets B to original value}a := a - 1;B := B + 1;

END;

Page 6: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 6

Assignment to a register

A := B using [a];

A := 0;

A := A + B using a;

Page 7: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 7

Subtraction

A := A - B using [a, b];

a := B using b;

WHILE (a <> 0) DOA := A - 1;

a := a - 1;

END;

Page 8: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 8

Register Test Operations 1

?(A < 2) using [a, b];

IF ?(A < 2) THEN L2: TRUE ELSE L1: FALSE END;

a := A using b;

IF (a = 0) THEN GOTO L2;a := a - 1;

IF (a = 0) THEN GOTO L2;

L1: FALSE;L2: TRUE;

Page 9: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 9

Multiplication

A := A x B using a, b, c;

a := A using b;b := B using c;

A := 0;

WHILE (b <> 0) DOA := A + a using c;b := b - 1;

END;

Page 10: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 10

Division

A := A DIV B using [a..e]; {Remainder held in e}

e := A using a;

A := 0;

WHILE (e >= B using [a..c]) DOe := e - B using d; {[a..c] still in use}INC A

END;

Page 11: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

NORMA and primes: on testing for integer division

Div (A, B)? {True iff A is exactly divisible by B}

a := A;

WHILE (a >= B) DO a := a – B;

IF (a = 0) THEN GOTO Label-Divisible

ELSE GOTO Label-NOT-Divisible

10/04/23 (c) Bishop: Consciousness and Computations 11

Page 12: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

On the testing for prime

aPrime (A)? {NB. Zero and one are neither prime nor composite}

IF (A < 2) THEN GOTO [Label-NOT-Prime]

j := A - 1;

WHILE NOT (Div (A, j) DO j := j – 1;

IF (j = 1) THEN GOTO [Label-Prime] ELSE GOTO [Label-NOT-Prime]

10/04/23 (c) Bishop: Consciousness and Computations 12

Page 13: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

On calculating the kth prime

A := PRIME (K) {Stores the Kth prime in A, where the 1st prime is 2}

A := 0;

k := K;

WHILE (k <> 0) DO

k := k – 1;

A := A + 1;

WHILE NOT ( aPrime (A) ) DO A := A + 1;

END;

10/04/23 (c) Bishop: Consciousness and Computations 13

Page 14: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 14

Answer to criticism 2

Representing negative numbersAn arbitrary integer m can easily be represented as the order pair (n, d) of non negative integers:

n = |m|

d = 0 IF (m >= 0)d = 1 otherwise

Page 15: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 15

Representing fixed length real numbers Using a similar idea to that used for negative numbers, operations on a non

negative rational number r can be defined in terms of the ordered pair (a, b), where (b > 0) and (r = a/b).

Since arithmetic on rationals conforms to the following rules: Addition & Subtraction

(a,b) ± (c,d) = (ad ± bc, bd)

Multiplication (a,b) × (c,d) = (ac, bd)

Division (a,b) / (c,d) = (ad, bc) iff (c <> 0)

Equality ?((a,b) = (c,d)) iff (ad = bc)

... there is no problem constructing appropriate NORMA programs using fixed length reals.

Page 16: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 16

Answer to 3rd criticism

• To answer criticism 3 we define a new machine SAM (Simple Array Machine) with more flexible access to data.

• SAM augments NORMA by possessing the array of registers, A[1], A [2] .... A [n]

• in addition to the standard registers A,B .... Y, which are now referred to as index registers.

• The operations defined by SAM are those of NORMA plus the array operations:

• A [J] := A [J] + 1;• A [J] := A [J] - 1; where J is any index register.

• A [n] := A [n] + 1;• A [n] := A [n] - 1; where n is any positive integer.

Page 17: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 17

Array test operations

SAM also has the array test operations:

?(A [J] = 0)?(A [n] = 0)

SAMs input and output functions are the same as NORMAs except that the input function also initialises each array register to zero.

Page 18: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 18

Theorem 2: NORMA can simulate SAM

Proof: We have to show how any given program P for SAM can be translated into a NORMA program Q such that:

NORMA (Q) = SAM (P)

Method: Pack all of SAM array into a single NORMA register.

If at some stage in the computation a SAM array contains [a1, a2, .. an] then at the equivalent stage a NORMA register will contain A.

A = P1a1 × P2

a2 × P3a3 ... × Pn

an, where Pj = jth prime.

Page 19: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 19

Increment indexed array

To define Q from P, we translate each SAM instruction into a sequence of NORMA instructions as follows:

All index register instructions are left unchanged. Array operations of the form A [J] := A [J] + 1 are translated into:

B := PRIME (J); A := A × B

Where PRIME is the PRIME number function defined earlier.

Page 20: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 20

Decrement indexed array

Array operations of the form A [J] := A [J] - 1 are translated into:

B := PRIME (J);

A := A DIV B;

Where DIV is a special integer division defined by:

a DIV b = a / b If b divides exactly into a

= a otherwise

Page 21: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 21

Testing an array element

A test of the form ?(A [J] <> 0) is translated into:

B := PRIME (J)

RETURN div (A, B)

Where div (A ,B) is TRUE when A is exactly divisible by B and FALSE otherwise.

ie. The test div (A, B) will return TRUE just in the case that A [J] ≠ 0.

Page 22: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 22

INC and DEC array using a constant index, n

An operation of the form (A [n] = A [n] + 1) is translated into:

B := PRIME (n);A := A × B;

Similarly (A [n] = A [n] - 1) is translated into:

B := PRIME (n);A := A DIV B;

Page 23: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 23

Proof of theorem 2

The test ?(A [n] = 0) uses the test div (Pn, A) to RETURN the correct value, where Pn = PRIME (n).

Now each operation and test of Q must be replaced by the corresponding NORMA macro;

And if we ensure that Q initially sets A to 1 to represent the input condition of SAMs array then …

… the simulation clearly works and hence Theorem 2 is proved.

Page 24: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 24

Answer to criticism 4 - only flowcharts

To answer criticism 4 we need to define a new machine SIM (Simple Indirect Machine).

In a SIM program P with labels (1 .. l .. k), the operations defined by SIM are those given by NORMA plus the following two Indirect Jump calls:

l: GOTO (A); {GOTO a where a is the content of register A}

l: IF (T) THEN GOTO (A); {IF TRUE GOTO label a}

Page 25: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 25

Theorem 3: NORMA can simulate SIM

Proof: We have to show how any given program P for SIM can be translated into a NORMA program Q such that:

NORMA (Q) = SIM (P)

Method: Use a Jump Table.

For each register (eg. A) that appears in the program we need to define an extra segment of code, tableA.

Page 26: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 26

Jump tables

Page 27: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 27

For the SIM Indirected jump

This extra code can be added after instruction k of SIM program P.

We can now replace the new SIM instructions by the following NORMA code:

SIM l: GOTO (A);

NORMA l: GOTO tableA; {Where tableA is label of jump table for

the A reg}

Page 28: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

10/04/23 (c) Bishop: Consciousness and Computations 28

The SIM indirected test SIM

l: IF (T) THEN GOTO (A);

NORMA l: IF (T) THEN GOTO tableA; {Where tableA is label of the jump table for the A

register}

Now each operation and test of SIM Q must be replaced by the corresponding NORMA macro.

It is now clear that the resulting NORMA program Q is equivalent to the SIM program P.

The simulation clearly works and hence Theorem 3 is proved.

Page 29: Cognitive Computing: 2012 Consciousness and Computation: computing machinery & intelligence 3. EMULATION Mark Bishop.

HOMEWORK:Implement NORMA_STACK

Prove that the machine NORMA_STACK is no more powerful than the universal machine NORMA by designing two MACROs to implement:

(a) X=POP which removes the top value from the STACK and places it into the X register;

(b) PUSH (X) which places the contents of the X register on to the top of the STACK;

and submit a short (no more than 1-page) report detailing their operation.

10/04/23 (c) Bishop: Consciousness and Computations 29