Commit e6fa1b3d authored by Frank Huch's avatar Frank Huch
Browse files

correct formulas

parent da21ea6d
......@@ -34,14 +34,14 @@
1. *Binary Numbers*
In the lecture we presented natural numbers as Peano numbers. However, this representation is very inefficient for large numbers. We therefore want to present natural numbers as binary numbers.
* We distinguish the number $0$, represented as `o`, and positive numbers $>0$ represented as `pos(N)`.
* Positive numbers are represented as a bit sequence, where the most significant bit is always $1$, so there are no leading zeros. Positive numbers consist of the following functors.
* We distinguish the number 0, represented as `o`, and positive numbers >0 represented as `pos(N)`.
* Positive numbers are represented as a bit sequence, where the most significant bit is always 1, so there are no leading zeros. Positive numbers consist of the following functors.
* A term of the form `o(N)` represents the number $2\cdot N$,
* a term of the form `i(N)` represents the number $2\cdot N+1$ and
* the atom `i` represents the number $1$ (most significant bit).
* A term of the form `o(N)` represents the number 2*N,
* a term of the form `i(N)` represents the number 2*N+1 and
* the atom `i` represents the number 1 (most significant bit).
The number $0$ is therefore called `o`, $1$ as `pos(i)` and $4$ as `pos(o(o(i))`. Hence, the outermost functor represents the least significant bit.
The number 0 is therefore called `o`, 1 as `pos(i)` and 4 as `pos(o(o(i))`. Hence, the outermost functor represents the least significant bit.
1. Define the following predicates based on this number representation.
......@@ -50,27 +50,27 @@
**Note:** Use auxiliary predicates such as `addP`, which are defined on positive numbers. Furthermore, use the following equations and develop equations for further combinations if necessary.
$$\begin{align*}
1+1 &=2\\
1+(2\cdot N) &=2\cdot N+1\\
1+(2\cdot N+1) &=2\cdot (N+1)
\end{align*}$$
~~~
1+1 =2
1+(2\cdot N) =2\cdot N+1
1+(2\cdot N+1) =2\cdot (N+1)
~~~
2. When used in the opposite direction, e.g. with a query like `add(X, Y, pos(o(i)))`, Prolog computes all solutions, but, unfortunately, does not terminate. The reason is, that the Prolog program does not know that the sum of two positive numbers is greater than each summand, and thus increasing summands are tried.
Implement for positive numbers $>0$ a predicate `lessP(X, Y)` that is satisfied, when `X` is less than `Y`. Then use this predicate to improve the previous implementation of `add`.
Implement for positive numbers >0 a predicate `lessP(X, Y)` that is satisfied, when `X` is less than `Y`. Then use this predicate to improve the previous implementation of `add`.
1. *Boolean Operations*
Implement Boolean functions `and`, `or`, and `not` as predicates working on the values `true` and `false`. Make sure that negation is also possible. Therefore, you must provide an explicit result as an additional parameter of your predicate.
Also implement the following three Boolean expressions as Prolog predicates `ex1(X, Y, Z, Res)`, `ex2(X, Y, Z, Res)`, and `ex3(X, Y, Z, Res)`.
* \$$(x\wedge y)\vee z$$
* \$$(x\wedge y)\vee ((y\wedge z)\wedge z)$$
* \$$(x\wedge (\neg y)\wedge z)\vee ((z\wedge y)\vee z)$$
* (X /\ Y) \/ Z
* (X /\ Y) \/ ((Y /\ Z) /\ Z)
* (X /\ (not Y) /\ Z) \/ ((Z /\ Y) \/ Z)
Specify queries that can be used to answer the following questions. Give the answer of the Prolog system as well as an additional explanation.
* Which results do you get for the values `X = true`, `Y = false` and `Z = true`?
* Which assignments yield `true` as result?
* Is the third equation dependent on $x$ or $z$?
* Is the third equation dependent on `X` or `Z`?
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment