SHARE

TWEET

# kingjulio545

a guest
Mar 26th, 2020
94
Never

**Not a member of Pastebin yet?**

**, it unlocks many cool features!**

__Sign Up__- So the cond is a logic function that is called for logical operations / conditions.
- Now this applies the lesson / concept of logic gates. Given that Prolog is itself a logical or rule based programming language, it is simply fitting that is utilizes this such lesson.
- So what I did was I broke it down as follows (if you check the code formatting):
- arg0, arg1 and depth 0 -> markers for us when it comes to sign value, depth (think of it as kind of like a marker as to where we are within the operation being conducted)
- // Logic NOT gate
- (= op 'not)
- The logic not gate is simpler since its essentially a negation and reverse of operations.
- A OUTPUT
- 0 1
- 1 0
- Then I evaluated the resulting expression if it was paired with an and, or, not. It is then evaluated as shown depth first.
- // Logic AND gate
- (= op 'and)
- The process here is longer since:
- A B OUTPUT
- 0 0 0
- 0 1 0
- 1 0 0
- 1 1 1
- Must take into account listsize and must go back to see if simplified. Since it must be in form A B, it will simplify it first until such that it is in form A B before it performs cond which results in output. Then we simply just layout the different possibilities that can occur.
- // Logic OR gate
- (= op 'or)
- The process here is longer since:
- A B OUTPUT
- 0 0 0
- 0 1 1
- 1 0 1
- 1 1 1
- Must take into account listsize and must go back to see if simplified. Since it must be in form A B, it will simplify it first until such that it is in form A B before it performs cond which results in output. Then we simply just layout the different possibilities that can occur.
- Summary:
- For the not gate, it is simply a negation which is applied to the entire list (no matter how long it is which is okay since the negation will simply be carried over until the end).
- Example: (-1 * -1 * -1 * -1)
- * This can keep going on and on, but in the end we just count how many negatives and that dictates the final sign. In the not gate, we just do the same except its not as simple as just negative 1, so we put what happens to and, or and not negation when it is applied / evaluated.
- As for the and / or gate. It requires it requires 2 inputs A and B. We try to make the gate as simple as possible and this is why we have the simplification function. So if the list is big, we simplify it to such that its listsize is 2 or 3 and we can proceed with the list contents and perform the necessary operation. As you can see the arg0 is like the A, arg1 is the B and true or false is 1 and 0.
- The number of outputs depends on the input, for a 2 input gate its 4 outputs, and for a 3 input gate, its 8 outputs. (Logic gate formula: 2 ^ n)

RAW Paste Data

We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.