Fuzzy Logic
One of the unique features of MiniScript is that it handles not only Boolean logic, but also fuzzy logic. Fuzzy logic is a superset of ordinary Boolean logic, which allows the computer to correctly process logical statements involving not only true and false, but also varying degrees of truth in between.
Brief History of Fuzzy Logic
Classic logic states that every proposition is either true or false — a claim that goes all the way back to Aristotle [1]. This was formalized most famously by George Boole in a book called The Mathematical Analysis of Logic, giving us what is now known as Boolean logic. In most computer languages today, a variable that can hold only true or false is called a Boolean variable.
However, mathematicians began to chip away at this rigid formalism in the early 20th century, starting with Jan Łukasiewicz's three-valued logic in 1920. This was then generalized to n-valued logic (for any finite n), and eventually to infinitely-many-valued logic in 1930 by by Łukasiewicz and Alfred Tarski. However this new, more sophisticated form of logical reasoning did not really catch on until the 1965 proposal of "fuzzy set theory" by computer scientist Lotfi Zadeh at the University of California, Berkeley. As part of his treatment of fuzzy set membership, Zadeh further developed and clarified fuzzy logic, which allows propositions to have various degrees of truth besides completely true or false.
A systematic mathematical study of particular types of fuzzy logics began in 1998 with a monograph called Metamathematics of Fuzzy Logic by Petr Hájek. Many other mathematicians and logicians have contributed to the field since then. Meanwhile, fuzzy logic has found extensive applications in science and industry, used in everything from experimental analysis to toaster ovens.
Fuzzy Logic in MiniScript
MiniScript represents all truth values as a number between 0 and 1, inclusive. The keyword true equates to 1, and false is the same as 0. But the logical operators and, or, and not are all defined in a way that works logically and consistently with any number in this range. (In technical terms, MiniScript implements a T-norm fuzzy logic.)
While logicians have defined these operators in various ways depending on the application, MiniScript defines them in a way that is also consistent with probability theory:
x and y | x * y |
x or y | 1 - (1-x) * (1-y) |
not x | 1 - x |
Note that when the variables involved are all exactly 0 (false) or 1 (true), this produces the standard Boolean truth tables:
0 and 0 == 0 | 0 or 0 == 0 |
0 and 1 == 0 | 0 or 1 == 1 |
1 and 0 == 0 | 1 or 0 == 1 |
1 and 1 == 1 | 1 or 1 == 1 |
However, given values between 0 and 1, MiniScript produces mathematically sensible in-between answers:
0 and 0.2 == 0 | 0 or 0.2 == 0.2 |
0.5 and 0.2 == 0.1 | 0.5 or 0.2 == 0.6 |
1 and 0.2 == 0.2 | 1 or 0.2 == 1 |
Interpretation
MiniScript's definition of and, or and not can be interpreted in terms of probability or fuzzy-logic truth. For example, suppose there are two independent events: event A will happen with a probability of 0.5, and event B has a probability of 0.2. Then the probability that they will both happen is A and B
which is 0.1; the probability that at least one will happen is A or B
, or 0.6. The probability that event B will not happen is simply not B
, or 0.8.
In terms of logical truth, the situation is the same. If we consider A to be the degree to which "Bob is tall" is true, and B to be the degree to which "Bob is fat" is true, then A and B
produces the degree to which "Bob is tall and fat" can be considered true; and A or B
represents the truth of "Bob is tall or fat".