Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Axiomatizing the Natural Numbers Notes for Ch.3 of.

Similar presentations


Presentation on theme: "UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Axiomatizing the Natural Numbers Notes for Ch.3 of."— Presentation transcript:

1 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Axiomatizing the Natural Numbers Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta

2 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Constants, function, intended interpretation The domain: the natural numbers and a special symbol S Two constants: one and zero One function one --- denotes the number 1 zero---denotes S; it does not denote a number! b(N,zero) –denotes 2 x N’, where N denotes the number N’ b(N,one) –denotes 2 x N’ + 1

3 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Mnemonic A number represented in b notation can be read as a binary number by replacing one with 1 and zero with 0. Example: b(b(b(one, zero),one), one) 1 0 1 1 (decimal 11) b(b(b(one, one), one), one) 1 1 1 1 (decimal 15) B(b(b(b(one,one),zero),one),zero) 1 1 0 1 0 (decimal 26)

4 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering number numb(N) is true if N denotes (“has the form of”) a number. For short, we may say, “if N is a number.” Use numb, because number/1 is predefined in CILOG numb(one). numb(b(N,zero))  numb(N). numb(b(N,one))  numb(N).

5 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering successor succ(N,M) is true if M denotes the successor of (the “number after”) N succ(one, b(one, zero)). succ(b(N, zero), b(N, one))  numb(N) & numb(M). succ(b(N,one), b(M,zero)) <- succ(N,M). –Adding 1 to 1 results in 0 with a carry of 1. The carry may propagate. –Check it!

6 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Plus plus(X,Y,Z) is true if the number denoted by Z is the sum of the numbers denoted by X and Y (i.e., Z’ = X’ + Y’, or simply Z = X + Y). plus(one, Y, Z) <- succ(Y, Z). plus(X, Y, Z) <- succ(XMinus1, X) & succ(Y, YPlus1) & plus(XMinus1, YPlus1, Z). X + Y = Z iff (X-1) + (Y+1) = Z

7 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Times X * Y = Z iff (X-1) * Y + Y = Z times(one, Y, Y). times(X,Y,Z) <- succ(XMinus1, X) & times(XMinus1,Y,Z1) & plus(Z1,Y,Z).

8 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering is Is does expression evaluation We use is1 because “is” is predefined in CILOG. is1(E,E) <- numb(E). is1(V, X+Y) <- is1(V1,X) & is1(V2,Y) & plus(V1,V2,V). is1(V, X*Y) <- is1(V1,X) & is1(V2,Y) & times(V1,V2,V). is1(V, X-Y) <- is1(V1,X) & is1(V2,Y) & plus(V2,V,V1).

9 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Less than lt(one, b(N,zero)) <- numb(N). lt(one, b(N,one)) <- numb(N). lt(N,M) <- succ(NMinus1,N) & succ(MMinus1,M) & lt(NMinus1, MMinus1).

10 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Not Equal neq(N,M) <- lt(N,M). neq(N,M) <- lt(M,N).

11 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Complexity of plus Each time the second clause of plus is applied, the first argument is decremented by one: plus takes linear time in the value of the first argument. This is exponential time in the size of the binary representation of a number! A more efficient plus (linear in the size of the representation) can be obtained by simulating addition by hand (with carry). We call it bplus.

12 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Efficient plus bplus(one, X, S)  succ(X,S). bplus(b(N,D),one,S)  succ(b(N,D),S). bplus(b(R,zero),b(S,zero),b(RS,zero))  bplus(R,S,RS). bplus(b(R,zero),b(S,one),b(RS,one))  bplus(R,S,RS). bplus(b(R,one),b(S,zero),b(RS,one))  bplus(R,S,RS). bplus(b(R,one),b(S,zero),b(SRS,zero))  bplus(R,S,RS) & succ(RS,SRS).

13 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Complexity of times Each time the second clause of times is applied, the first argument is decremented by one and plus is called: Plus takes quadratic time in the value of the first argument. This is doubly exponential in the size of the binary representation! A more efficient (quadratic in the size of the representation) solution is obtained by simulating hand multiplication. We call this btimes.

14 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Efficient times btimes(one,X,X). btimes(b(R,zero), S, b(RS,zero)  btimes(R,S,RS). btimes(b(R,one), S, RSS)  btimes(R,S,RS) & bplus(S,b(RS,zero), RSS). When the third clause is applied, one number is “stripped” at the end of the multiplicand. This appears to be linear-time, but it is not, because the addend in bplus grows in size.


Download ppt "UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Axiomatizing the Natural Numbers Notes for Ch.3 of."

Similar presentations


Ads by Google