Forums - Open Redstone Engineers
Logic gate formulas - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: ORE General (https://forum.openredstone.org/forum-39.html)
+--- Forum: Tutorials (https://forum.openredstone.org/forum-24.html)
+---- Forum: Advanced Tutorials (https://forum.openredstone.org/forum-26.html)
+----- Forum: Concepts (https://forum.openredstone.org/forum-28.html)
+----- Thread: Logic gate formulas (/thread-12558.html)



Logic gate formulas - Splavacado100 - 07-02-2017

Me and Data are working on a hex ALU, i.e. inputs have 16 states, and I devised a common formula for make logic gates with n input states. Sorry if this post doesn't go into much detail, I will update it with a much more in-depth explanation.

OR gate: max(x,y)
AND gate min(x,y)

Now the XOR gate is a little tricky but I've found a formula: |x-y|. Now, when doing hex subtraction, compactors have the function max(0, back - side), only using one side. You can using max(x - y, y - x) when doing a hex XOR. Simply put, and XOR gate is the absolute difference between the inputs. The max function is easier, just combine all lines, highest signal strength wins. For the min function, first do invert on each input, i.e. 15-x, then combine (max) each line, then hex invert back again. This is actually the structure of a common and gate, just now using hex NOTs instead of binary NOTs. Please comment any questions!


RE: Logic gate formulas - Matthew - 07-02-2017

max wont work for OR, 8 OR 1... 1000(8ss) 0001(1ss) Max of 8 and 1 is 8... but 8 is not (8 OR 1) so... similar issue with AND


RE: Logic gate formulas - Splavacado100 - 07-02-2017

Data, the formula is for 16 state logic, 16 different input stats. The hex inputs don't represent 4 bits of binary.


RE: Logic gate formulas - Matthew - 07-02-2017

(07-02-2017, 12:38 AM)Splavacado100 Wrote: Data, the formula is for 16 state logic, 16 different input stats. The hex inputs don't represent 4 bits of binary.

Oh, well then you are not doing boolean logic... So i would not call it OR, AND etc. I don't know the correct terminology for what you are doing but saying boolean functions alone is true/false inputs/outputs only.


RE: Logic gate formulas - Splavacado100 - 07-02-2017

AND and OR aren't exclusively for binary, are they?


RE: Logic gate formulas - Matthew - 07-02-2017

(07-02-2017, 12:53 AM)Splavacado100 Wrote: AND and OR aren't exclusively for binary, are they?

Then are indeed Tongue When you read AND, OR, etc. The default supposition is boolean unless otherwise specified.


RE: Logic gate formulas - ph1234k - 07-04-2017

(07-02-2017, 01:22 AM)Matthew Wrote:
(07-02-2017, 12:53 AM)Splavacado100 Wrote: AND and OR aren't exclusively for binary, are they?

Then are indeed Tongue When you read AND, OR, etc. The default supposition is boolean unless otherwise specified.

They are not indeed. In fact AND, OR and NOT are just other names for MIN, MAX and COMPLEMENT and it does not matter how many states you have, they are defined for and work the same for all such systems. 

e.g. 0 MIN 0 = 0. 1 MIN 0 = 0. 0 MIN 1 = 0. 1 MIN 1 = 1. 

As for boolean logic, if you wanted to do that then you do it and you can convert it to a single line of redstone with a hex converter if you like. 
This post though is about 16 state logic, not 2 state logic. 16 state logic is particularly interesting over 2 state logic as it allows more realistic modeling. For instance, instead of saying something is "hot/1" or "not hot/0" you can say that something has a degree of truthfulness to being called hot between "0/not hot" and "15/hot" so that "10" can be used for instance as a degree to which calling something hot is true and still not represent it as an absolute truth. It allows more accurate modeling of the real world for such concepts and is also known as "Fuzzy Logic".

More information can be found here: https://en.wikipedia.org/wiki/Fuzzy_logic


RE: Logic gate formulas - ph1234k - 07-04-2017

I actually designed such an ALU when the comparators were first released and attempted to make a computer based around 16 state logic, I ran into issues on how to address certain things though. Specifically, what functions to include in a fuzzy logic ALU.


RE: Logic gate formulas - Matthew - 07-06-2017

(07-04-2017, 08:43 AM)ph1234k Wrote: I actually designed such an ALU when the comparators were first released and attempted to make a computer based around 16 state logic, I ran into issues on how to address certain things though. Specifically, what functions to include in a fuzzy logic ALU.

Can fuzzy logic do anything usefull in redstone cpus like generate partial products to multiply? also if i'm not mistaken when reading a logical function the default assumption is boolean. I believe most of if not all algorithms on ore use boolean logic except for decoders. So where is the use case for "fuzzy logic"


RE: Logic gate formulas - ph1234k - 07-08-2017

Well, yes Fuzzy Logic can do everything that boolean can do. It just has more states. I won't comment on people's default assumptions however there was nothing to be assumed here since in the original post it was explained that he was using 16 states. Since it was explicitly stated, we need no assumption. Your reply here is referencing a use case in which I had created a partial ALU (didn't have adder/subtractor, only logic functions as I was tinkering with a 4 bit adder using comparators at the time and didn't complete it), also a use case is exactly what the original post here is about.

I am not sure how usage cases outside of the post would be relevant unless they were directly related however you could image a general purpose ALU based on 16 state logic which would be programmed to check outputs of some device (a chest that is part of a sorting machine for example) and then take action on the output (allowing a drain of the chest before filling to prevent the hopper from backing up and ruining the sorting functionality for example). In this example, yes you can do it without a computer and yes you could do it in boolean assuming you convert the output of the comparator but it is just an example. Like all logic devices, the limitations are based on how you can use the signal to interact with other hardware and your imagination.


RE: Logic gate formulas - Matthew - 07-08-2017

(07-08-2017, 06:49 AM)ph1234k Wrote: I am not sure how usage cases outside of the post would be relevant unless they were directly related however you could image a general purpose ALU based on 16 state logic which would be programmed to check outputs of some device (a chest that is part of a sorting machine for example) and then take action on the output (allowing a drain of the chest before filling to prevent the hopper from backing up and ruining the sorting functionality for example). In this example, yes you can do it without a computer and yes you could do it in boolean assuming you convert the output of the comparator but it is just an example. Like all logic devices, the limitations are based on how you can use the signal to interact with other hardware and your imagination.

First of all it still is a computer... i dont know what tf you are on about there... umm and also yes my point still remains doing anything like multiplication, division, or useful logical operations (boolean) require converting to binary. Except in the mult and divs case but if you don't convert it will take you hundreds of time longer to perform them.... in other words fuzzy logic in a cpu meant to do math and arithmetic is trash. idk correct me if i'm wrong.


RE: Logic gate formulas - ph1234k - 07-08-2017

No, you don't have to do any conversion to perform what you refer to as "useful operations". Remember these functions are already equivalent to the boolean functions, there is simply more states. That means you can do everything you can with 2 states, plus more.

It is quite simple to perform the exact equivalent of boolean:

Boolean example:
State 1 AND State 0 = State 0

16 state example:
State 15 AND State 0 = State 0

Actually any state would work for an and gate, however using the max state is particularly useful as boolean 1 is a max state and so the complement of the max state is the min state which also holds true in any number of states in any logic. So in 16 state, NOT 15 = 0. In 2 state, NOT 1 = 0.

The difference in the systems is that adding more states allows more accurate representation of real world concepts where everything is not "TRUE" or "FALSE" while still allowing you to use both "TRUE" and "FALSE". By no means does adding states somehow limit what you can do over systems with less states. The exact same computational power is there, again with the addition of states representing degrees of truth.

EDIT: I didn't address you concern with the word computer in my last post. I used the word computer in reference to a general purpose computer or ALU as was provided in context there. No you do not need one of these devices to perform the example, you connect a comparator to the chest to pull the signal, then place a repeater at the level you want to unload at as your decoder to binary (or wire it so that the level would trigger or subtract from it with another comparator to only output from there when the signal surpasses the threshold and so on), connect that to an inverter which powers the hopper that empties the chest. The point there was that for any application in which a general purpose computer can be made to do, there is always the ability to do it with a specialized circuit which would be more compact and faster. I was simply acknowledging this fact.


RE: Logic gate formulas - Matthew - 07-09-2017

(07-08-2017, 07:18 PM)ph1234k Wrote: No, you don't have to do any conversion to perform what you refer to as "useful operations". Remember these functions are already equivalent to the boolean functions, there is simply more states. That means you can do everything you can with 2 states, plus more.

It is quite simple to perform the exact equivalent of boolean:

Boolean example:
State 1 AND State 0 = State 0

16 state example:
State 15 AND State 0 = State 0

Actually any state would work for an and gate, however using the max state is particularly useful as boolean 1 is a max state and so the complement of the max state is the min state which also holds true in any number of states in any logic. So in 16 state, NOT 15 = 0. In 2 state, NOT 1 = 0.

The difference in the systems is that adding more states allows more accurate representation of real world concepts where everything is not "TRUE" or "FALSE" while still allowing you to use both "TRUE" and "FALSE". By no means does adding states somehow limit what you can do over systems with less states. The exact same computational power is there, again with the addition of states representing degrees of truth.

EDIT: I didn't address you concern with the word computer in my last post. I used the word computer in reference to a general purpose computer or ALU as was provided in context there. No you do not need one of these devices to perform the example, you connect a comparator to the chest to pull the signal, then place a repeater at the level you want to unload at as your decoder to binary (or wire it so that the level would trigger or subtract from it with another comparator to only output from there when the signal surpasses the threshold and so on), connect that to an inverter which powers the hopper that empties the chest. The point there was that for any application in which a general purpose computer can be made to do, there is always the ability to do it with a specialized circuit which would be more compact and faster. I was simply acknowledging this fact.
Everything you're saying is correct... but when it comes to simple arithmetic fuzzy logic is horrible. If we where doing probability calculations or something along those lines its super useful... but the thing is no one is lol... Pretty much everyone builds basic cpus that perform simple arithmetic. Assuming that's what you want to build, fuzzy logic is not the right choice to handle the job. Edit (assuming the fuzzy logic is higher than 2 states)

*mic drop


RE: Logic gate formulas - Matthew - 07-09-2017

(07-08-2017, 07:18 PM)ph1234k Wrote: Remember these functions are already equivalent to the boolean functions, there is simply more states.

Boolean (bit-wise) - 8 AND 1 = 0

Fuzzy (16 state) - 8 AND 1 = 8

suuuurrrreeee......  "equivalent"

its only equivalent when you limit the fuzzy logic to 2 states lol


RE: Logic gate formulas - Matthew - 07-09-2017

In other words hex signal strength arithmetic in redstone is crap. like... really super poopy crap


RE: Logic gate formulas - ph1234k - 07-11-2017

I hope you don't take this the wrong way, but I do not think you have any idea what you are talking about (EDIT: I mean when it comes to fuzzy logic and how to represent binary numbers for arithmetic in logic systems. I don't really mean "no idea" as you have at least some decent understanding of boolean logic).

" but when it comes to simple arithmetic fuzzy logic is horrible."

In what way do you think this could possibly be true? Exactly what part of it seems horrible to you? Please be specific and do not continue making general statements that hold no information about what you are implying.

"If we where doing probability calculations or something along those lines its super useful"

That is just incorrect, while fuzzy logic deals with uncertainties, those uncertainties are not the same as probability.
A probability deals with likelihood, chances that something may happen while fuzzy logic deals with degrees of truth.
In probability, if you were presented with "This chest has a 0.7 probability of being full" we mean that there is a chance that the chest is full or not. I  fuzzy logic, if you are presented with "This chest is 0.7 full" it means that the chest is full by some definition of full. This contrasts deeply with probability where an event's occurrence is uncertain as the only thing that is uncertain is the definition of "full".

"""
Boolean (bit-wise) - 8 AND 1 = 0

Fuzzy (16 state) - 8 AND 1 = 8

suuuurrrreeee......  "equivalent"

its only equivalent when you limit the fuzzy logic to 2 states lol
"""

This is also incorrect. You do not seem to understand what you are representing. There is either one of two possibilities:
1. We are dealing with a single bit(line of redstone indicating a binary signal)
That means your example should be:
Boolean: 1 AND 1 = 1 (A signal strength of 8 in a boolean system is just "ON" or "1")
16 state: 8 AND 1 = 1 (An incorrect way to represent a binary number in 16 state, however in this case it still works as the line is "ON", correctly it should be 15 AND 15 = 15 as you must be able to invert to 0 when dealing with binary)
When you hook these up to a lamp for example, you will see that the lamp turns on in both cases.

2. We are dealing with 4 bits(lines of redstone indicating a binary signal where you are for some reason denoting numerals in decimal while working with binary)
This means your example should be:
Boolean: 1/0/0/0 AND 0/0/0/1 = 0/0/0/0
16 state: 15/0/0/0 AND 0/0/0/15 = 0/0/0/0 (or even with the incorrect representation of state 8 8/0/0/0 AND 0/0/0/8 = 0/0/0/0)
If you hook these to four lamps for example, you will see that none of the lamps turn on.

Binary and boolean are not the same. Boolean is logic dealing with 2 states, binary is a number system which you can represent with absolutely anything that has at least 2 different symbols/states for representation. I am assuming that you were attempting number 2 in this case, sending the binary representation of the decimal number "8" through for a bitwise AND operation. Bitwise implies you are operating on bits (meaning binary digits, not boolean digits), you still have to correctly represent the numbers you are dealing with, no matter what the state limit of the used logic system is.

"In other words hex signal strength arithmetic in redstone is crap. like... really super poopy crap"
Back to my question of "How is it crap?", hoping that you actually explain what your issue with it is.


RE: Logic gate formulas - Splavacado100 - 07-11-2017

(07-09-2017, 10:02 AM)Matthew Wrote:
(07-08-2017, 07:18 PM)ph1234k Wrote: Remember these functions are already equivalent to the boolean functions, there is simply more states.

Boolean (bit-wise) - 8 AND 1 = 0

Fuzzy (16 state) - 8 AND 1 = 8

suuuurrrreeee......  "equivalent"

its only equivalent when you limit the fuzzy logic to 2 states lol

By the way, hexnary and of (8,1) is 1, not 8. Get your facts straight before you argue.

Also ph1234k, matthew was talking about the different answers you get with bitwise binary and 1 digit hexnary, ie:

Bitwise:
8 AND 1 = 1000 AND 0001 = 0000 = 0

Hexnary:
8 AND 1 = min(8, 1) = 1

tldr: 4 bits of bitwise binary are not 1 digit of hexnary.