Can the operators ==, ==, != and !== be considered as "fuzzy logic"?

Asked

Viewed 1,231 times

18

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

Example:

Depiction described:

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 comparison operators:

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

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

Note: The doubt is not on the difference between them, and yes, if taking into account the mathematical logic only if we can consider as operators of fuzzy logic, that is, equality based on proportion.

  • @Guilhermenascimento is not about that, but what logic languages use to identify what these operators do.

  • Your doubt seemed to me somewhat ample by your comment of now.

  • I’ll edit the question again, see if I can make it clearer, but maybe my doubt doesn’t make sense at all

  • 7

    No, they cannot. Fuzzy logic does not return "yes" or "no". Fuzzy logic is the disruption of the axiom of the third excluded from the axiomatic system of boolean logic. These operators do not return "39% equality".

  • Recommended reading: https://answall.com/q/152106/64969

  • @Jeffersonquesado ah understood now, I also made confusion. Thank you! - I withdrew the closing vote

  • 1

    The @Jeffersonquesado answered right what I wanted to know

  • @Anthraxisbr perfect, I left a +1 now that the question became a little clearer, if you allow me I have an editing suggestion, anything just make the rollback if you disagree

  • 1

    @Anthraxisbr, since the question was closed, I ended up pasting my answer into a snippet: https://gitlab.com/snippets/1702821

  • @Jeffersonquesado perfeito!

  • 2

    My position on why this question should be reopened: https://pt.meta.stackoverflow.com/q/6857/64969

Show 6 more comments

2 answers

23


It 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 for the question "is it a fuzzy logic operator?" I answer 11.39%.

To begin, we need to define what a type operator to then define what a diffuse logic operator.

The description of what a BinaryOperator of Java 8 is that a binary operator is 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-ary operator is a function that takes n operands of the same type and the return is also of the same type. In this 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 there in particular, regardless of which are the operands, the return is only SIM or NÃO. Untitled.

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

  • identity
  • non-contradiction
  • excluded third party

You can read more on the subject in that reply. And what is fuzzy logic? It is a change in these axioms, more specifically the removal of the excluded third. In this case, fuzzy logic allows you to have something 11.3% true. 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, the boolean logic can be mapped to the fuzzy one 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 do a bijection to the continuum which is the set of fuzzy values. You can even make an over, but it wouldn’t be the reverse function. If there was a function that turns the boolean values into fuzzy ones called bool2fuzzy and the function that transforms from fuzzy logic to boolean call 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 made a mess in your head, am I? Yes or no? 67%?

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

função de Q,Q em Q

Already in programming languages, we do not use the notion pure mathematics than is an operator. 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 this case, for binary syntactic operator it is the one who fills the space of <op> in the grammatical production below:

produção gramatical que representa uma operação binária

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

Completion

  • binary operators in mathematics map 2 objects on a third object, as long as all these 3 objects belong to the "same universe"
  • programming languages call "operators" something that fits the operation structure
  • comparison, strong or loose, equality or difference, are Boolean logic operators (mathematically speaking when they treat as input boolean values)
  • comparison, strong or loose, equality or difference, are 11.39% diffuse logic operators
  • this answer is 73% correct
  • 5

    +0.872, good answer

  • 6

    @bfavaretto, this answer is good and bad until it is read. Schroedinger’s answer. So this response is 0.489506 bad =D (considering the overlapping of quantum states bom^2 + ruim^2 = 1).

5

It has nothing to do with one another. 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 performing the comparison. But it has nothing diffuse: "2" == 2.0000000001 remains false.

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

Already === and !== test identity, which for simple types is the same thing as equality without type conversion. "2" === 2 is false, "2" === "2" is true, 2 === 2 is true.

Taking advantage of the opportunity, some concepts referring to types:

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

Strong typing: no implicit conversions. Examples: Python, C, C++...

Dynamic typing: a variable can change type along the scope. Examples: Python, PHP, Javascript.

Static typing: a variable cannot change type. 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 condition boolean, making the implicit conversion. Also common is the "auto type promotion" when e.g. an integer is added to a floating point number.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.