The operators ==,===,!= e!= = can you consider "fuzzy logic"?

Doubt is simple and just out of curiosity, from a mathematical point of view, we have something like comparators by proportion (or of Fuzzy Logic):

Example:

Described representation:

x pode ser de 1 até 100 igual a y

Representing with PHP:

if($x >= 1 and $x <= 100){
    echo 'x é ' . $x . '/100 igual a y';
}

In PHP, we have the comparison operators:

  • ==
  • ===
  • !=
  • !==

Knowing the said mathematical concept previously, did the PHP interpreter use this concept to understand these operators?

Note: the doubt is not about the difference between them, but rather, if we take into account mathematical logic only if we can consider as operators of Fuzzy Logic, that is, of equality based on proportion.

Author: Jefferson Quesado, 2018-03-06

2 answers

Is not a fuzzy logic operator per se. Not strongly. But it can be considered a Boolean operator, so in a way would also be fuzzy. So to the question " is it a fuzzy logic operator?", I answer 11.39%.

To begin with, we need to define what is a operator of typeto then define what is a operator of fuzzy logic.

The description of what a BinaryOperator of Java 8 is that a binary operator a binary function in which the operands and the output are of the same type. read the documentation . On top, it's like this:

public interface BinaryOperator<T> extends BiFunction<T,T,T> {
}

Mathematically, an N-ário operator is a function that receives n operands of the same type and the return is also of the same type. In the case, to consider ==, ===, != and !== as operators, they should only be considered at the level of operands that are also of Fuzzy Logic.

But for those in particular, regardless of which are the operands, the return is only SIM or NÃO. No third term.

But, what is Boolean logic? Formally, it is composed of 3 axioms:

  • identity
  • no contradiction
  • third deleted

You can read more about the subject in this answer . And what is fuzzy logic? It is a change in these axioms, more specifically the removal of the excluded third. In the case, fuzzy logic allows you to have something 11.3% truth. The change is that there are 2 values (already predicted in the Boolean) and that there is a whole continuous interval between these values.

In this case, Boolean logic can be mapped to fuzzy as follows:

  • SIM ==> 1
  • NÃO ==> 0

Reverse mapping is not possible. The cardinality of the boolean set of values is finite, there is no way to make a bijection for the continuous that is the fuzzy set of values. You can even make a overjection, but it would not be the reverse function. If there was a function that transforms boolean values into fuzzy called bool2fuzzy and the function that transforms from fuzzy logic to boolean called fuzzy2bool, the following formulas are correct:

seja fuz uma variável pertencente a Difuso
se fuz não pertencer a {0, 1}:
    bool2fuzzy(fuzzy2bool(fuz)) != fuz
senão:
    bool2fuzzy(fuzzy2bool(fuz)) == fuz

Operators in programming language vs operators in mathematics

Well, I must have messed up your head, ser? Yes or no? 67%?

In mathematics, an operator (binary) is something like this:

Q function, Q In Q

Already in programming languages, we do not use the notion pure mathematics of what an operator is. For example, you can do "123" + 4 in PHP, Java and other languages. In this case, programming languages use syntactic operators . A syntactic operator does not enter the realm of mathematics, but the realm of syntax. In the case, for binary syntactic operator is who fills the space of <op> in grammatical production below:

grammatical production representing a binary operation

Then, in the case of programming languages, the structure determines whether something is called an operator or not. Even this answer reinforces this.

Conclusion

  • binary operators in mathematics map 2 objects into a third object, as long as all these 3 objects belong to the"same universe"
  • programming languages call "operators" something that fits into the structure of operation
  • comparison, strong or loose, equality or difference, are Boolean logic operators (mathematically speaking when they treat boolean values as input)
  • comparison, strong or loose, equality or difference, are 11.39% fuzzy logic operators
  • this answer is 73% correct
 24
Author: Jefferson Quesado, 2019-09-27 17:10:00

Has nothing to do with one thing. The presence of different equality operators has to do with"weak typing".

= = e != test equality, and if necessary implicitly convert the type of one of The compared values to enable comparison. For example, " 2 " = = 2 is true because the string is converted to number before making the comparison. But it has nothing fuzzy: "2" = = 2.0000000001 remains false.

Something similar happens to others operators, so PHP has a specific concatenation operator, because " 2 " + " 2 "returns 4, then" 2". "2" returns "22".

Already = = = e != = Test identity , which for simple types is the same thing as equality without type conversion. "2" = = = 2 is false, "2" === "2" it's true, 2 = = = 2 is true.

Taking advantage of the opportunity, some concepts related to Types:

Weak typing: makes implicit conversions. Examples: Javascript, PHP.

Typing strong: does not make implicit conversions. Examples: Python, C, C++...

Dynamic typing: a variable can switch types throughout the scope. Examples: Python, PHP, Javascript.

Static typing: a variable cannot switch types. Examples: C, C++.

Although each language has a character, there are almost always exceptions. For example, Python, C, and C++ use strong typing, but allow the use of variables of other types instead of a boolean condition , making the implicit conversion. It is also common to "automatic type promotion" when e.g. an integer is added to a floating point.

Ultra-modern languages like Swift, Rust, Go use very strong typing, do not even type promotions, nor automatic conversion numér numeric types, as experience shows that these conversions and promotions are endless sources of bugs.

 6
Author: epx, 2019-08-30 02:51:39