Download presentation

Presentation is loading. Please wait.

Published byZoe Maldonado Modified over 3 years ago

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

2
01/04/2014(c) Bishop: Consciousness and Computations2 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.

3
01/04/2014(c) Bishop: Consciousness and Computations3 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.

4
01/04/2014(c) Bishop: Consciousness and Computations4 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.

5
01/04/2014(c) Bishop: Consciousness and Computations5 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;

6
01/04/2014(c) Bishop: Consciousness and Computations6 Assignment to a register A := B using [a]; A := 0; A := A + B using a;

7
01/04/2014(c) Bishop: Consciousness and Computations7 Subtraction A := A - B using [a, b]; a := B using b; WHILE (a <> 0) DO A := A - 1; a := a - 1; END;

8
01/04/2014(c) Bishop: Consciousness and Computations8 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;

9
01/04/2014(c) Bishop: Consciousness and Computations9 Multiplication A := A x B using a, b, c; a := A using b; b := B using c; A := 0; WHILE (b <> 0) DO A := A + a using c; b := b - 1; END;

10
01/04/2014(c) Bishop: Consciousness and Computations10 Division A := A DIV B using [a..e]; {Remainder held in e} e := A using a; A := 0; WHILE (e >= B using [a..c]) DO e := e - B using d; {[a..c] still in use} INC A END;

11
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 01/04/2014(c) Bishop: Consciousness and Computations11

12
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] 01/04/2014(c) Bishop: Consciousness and Computations12

13
On calculating the k th prime A := PRIME (K){Stores the K th 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; 01/04/2014(c) Bishop: Consciousness and Computations13

14
01/04/2014(c) Bishop: Consciousness and Computations14 Answer to criticism 2 Representing negative numbers An 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

15
01/04/2014(c) Bishop: Consciousness and Computations15 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.

16
01/04/2014(c) Bishop: Consciousness and Computations16 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.

17
01/04/2014(c) Bishop: Consciousness and Computations17 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.

18
01/04/2014(c) Bishop: Consciousness and Computations18 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 = P 1 a1 × P 2 a2 × P 3 a3... × P n an, where P j = j th prime.

19
01/04/2014(c) Bishop: Consciousness and Computations19 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.

20
01/04/2014(c) Bishop: Consciousness and Computations20 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 / bIf b divides exactly into a = aotherwise

21
01/04/2014(c) Bishop: Consciousness and Computations21 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.

22
01/04/2014(c) Bishop: Consciousness and Computations22 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;

23
01/04/2014(c) Bishop: Consciousness and Computations23 Proof of theorem 2 The test ?(A [n] = 0) uses the test div (P n, A) to RETURN the correct value, where P n = 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.

24
01/04/2014(c) Bishop: Consciousness and Computations24 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}

25
01/04/2014(c) Bishop: Consciousness and Computations25 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.

26
01/04/2014(c) Bishop: Consciousness and Computations26 Jump tables

27
01/04/2014(c) Bishop: Consciousness and Computations27 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}

28
01/04/2014(c) Bishop: Consciousness and Computations28 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.

29
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. 01/04/2014(c) Bishop: Consciousness and Computations29

Similar presentations

OK

Basic Operators. What is an operator? using expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.

Basic Operators. What is an operator? using expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on human resource department Ppt on chromosomes and genes share Ppt on new product development steps Ppt on animal food habits Ppt on lcd tv technology Ppt on resistance temperature detector equation Ppt on acute coronary syndrome icd Ppt on world food day File type ppt on cyber crime unit Ppt on economic order quantity models