• API
• FAQ
• Tools
• Archive
SHARE
TWEET # kingjulio545 a guest Mar 26th, 2020 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. So the cond is a logic function that is called for logical operations / conditions.
2.
3. 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.
4. So what I did was I broke it down as follows (if you check the code formatting):
5.
6. 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)
7.
8. // Logic NOT gate
9. (= op 'not)
10.
11.     The logic not gate is simpler since its essentially a negation and reverse of operations.
12.     A OUTPUT
13.     0 1
14.     1 0
15.     Then I evaluated the resulting expression if it was paired with an and, or, not. It is then evaluated as shown depth first.
16.
17. // Logic AND gate
18. (= op 'and)
19.     The process here is longer since:
20.     A B OUTPUT
21.     0 0 0
22.     0 1 0
23.     1 0 0
24.     1 1 1
25.
26.     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.
27.
28. // Logic OR gate
29. (= op 'or)
30.     The process here is longer since:
31.     A B OUTPUT
32.     0 0 0
33.     0 1 1
34.     1 0 1
35.     1 1 1
36.
37.     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.
38.
39. Summary:
40. 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).
41.
42. Example: (-1 * -1 * -1 * -1)
43. * 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.
44.
45. 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.
46.
47. 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.
Top