Да-нет в среде Mathcad  · Web viewBoole’s . origami . In the study, you will learn about Boolean . and fuzzy. logic, about the features of its application in programming.Mathematics:

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Да-нет в среде Mathcad

Sdudy 11

Study 11Yes-No in the Mathcad environmentorBoole’s origami

In the study, you will learn about Boolean and fuzzy logic, about the features of its application in programming.Comment by Nori Massimiliano: Binary or infinite-value logic

Mathematics: Boolean function, Boolean algebra, Boolean function extremum, fuzzy logic.

Physics: switches of electrical circuits, voting machine.

IT: Boolean operators, tree operator, vectorization of computer calculations.

Etude site: https://www.ptcusercommunity.com/thread/127818Comment by Valery Ochkov: ???

In Mathcad 15 environment, there are operators implemented as prefix and infix operators - see the right-hand side of Fig. 11.1, which return only two values: 1 (not zero) or 0 (zero): Yes - No, True - False. These operators are collected on the Boolean toolbar in Mathcad 15 (see the left part of Figure 11.1) and Comparison in Mathcad Prime (see Figure 11.2).

Fig.11.1. Panel of Boolean operators in Mathcad 15 environment (left)

Comment by Валерий Очков: Заменить

Fig.11.2. Panel of Boolean operators in Mathcad Prime environment

Sometimes Boolean[footnoteRef:1] operators (or, otherwise, Boolean functions) are called binary or logical. The operands of these operators (the arguments of these functions) in the Mathcad environment can be real numbers, however a number different from zero is perceived as true while zero as false. [1: The word "Boolean" comes from the name of George Boole - English mathematician and logic professor of mathematics at the Royal College of Cork (now Cork University College). G. Boole is the creator of symbolic logic.]

In some programming languages (Pascal, for example), you can start working with Boolean and other types of variables only after they are listed in the variable type declaration. This is done to save computer's memory: much less space is allocated for storing the Boolean variable than for storing an integer, and even more so material. In our days the memory of a computer, as a rule, is not a limiting factor in solving problems, and such pre-declaration of variable types is abandoned. So, at least, it's in the Mathcad environment.Comment by Nori Massimiliano: Furthermore in VBA a Boolean variable must be declared and it is by default initialized as false.

We will talk about Boolean functions [63], starting from the problems that arise when working with them in the Mathcad environment or in other mathematical programs, as well as in programming languages, and in general, when using digital computer technology, which is based on the binary "atom" - Elementary element of memory, located in one of two states (charged-discharged, magnetized-demagnetized, etc.). From "atoms" (bits) are made "molecules" (bytes), which in turn form new "connections" - variables, arrays of variables (see Etude 2), etc. - everything that programmers operate. Arithmetic and other actions on numbers variables and on arrays of variables is essentially nothing but a variety of Boolean (bitwise) operations.

1. The Bases of Boolean Mathematics1.1. Boolean functions of one argument

There are four basic Boolean functions of one argument: see Table 11.1, but in practice only one - f1 works, which is called negation (inversion). The other three functions return either their argument (function f2), or the constants 1 (f3) and 0 (f4).Comment by Nori Massimiliano: A boolean function is a mathematical function that maps arguments to a value, where the allowable values of range (the function arguments) and domain (the function value) are just one of two values— true and false (or 0 and 1). The study of boolean functions is known as Boolean logic.

Table 11.1. Boolean functions of one argument

a

f1

f2

f3

f4

0

1

0

1

0

1

0

1

1

0

Notation

¬a

a

1

0

Not(a)

 

 

 

!a

¬a

In the first row of the notation graphics in Table 11.1 (and Table 11.2 below),are shown the Mathcad operators, that are used to implement the Boolean function. The symbol (prefix [footnoteRef:2] operator of negation or inversion) is present on the panels shown in Fig. 11.1 and 11.2. [2: A prefix by definition means that the operator symbol is placed before the operand. In the Mathcad environment, there are postfix built-in operators also - the factorial operator, for example, (5!), Where the operator symbol (!) is placed after the operand (5). The infix operator has two arguments, and its symbol is between them (an example is an addition operator with two operand terms). In the Mathcad 15 environment, there is also a tree-like user operator - see Fig. 11.7 and 11.12 below.]

From these functions it is possible to compose more complex functions of one argument, but they, as a rule, are not required. Let's see how, for example, the function operates. If a=1, then , , . If a = 0, then , , . The table of values tells us that , so it is meaningful to replace a simple function with a basic Boolean function.

1.2. Boolean functions of two arguments

The basic Boolean functions of two arguments are sixteen: see Table 11.2.

Table 11.2. Boolean functions of two arguments

Comment by Nori Massimiliano: Instead of “и” “e”, instead of “или” “o” Italian corresponding

Table 11.2 is contingently divided into two halves - the "nominal" (f1 — f8) and the nameless (f9 — f16). Here are the names of the first eight functions. Rather, seven (another "gorgeous seven" - see etude 4): two functions (f5 and f6) are called the same - implication or logical consequence.

· f1 —conjunction (logical multiplication);

· f2 —disjunction (logical addition);

· f3 — равнозначность (эквивалентность, тождественность); equivalence (equivalence, identity);

· f4 — неравнозначность (неэквивалентность, разделительная дизъюнкция, сумма по модулю 2); non-equivalence (nonequivalence, separating disjunction, sum modulo 2);

· f5 and f6 — implication (logical consequence): f5 - implication from a to b, f6 - implication from b to a;

· f7 —Pierce function (Webb function, the Dagger function, the anti-disjunction - we'll talk about it in detail: see Figures 11.7 and 11.8);

· f8 — function (prime) of Scheffer (anti-conjunction);Comment by Nori Massimiliano:  Also called a Sheffer stroke or stroke function. There are five primitive logical constants or functions, namely negation (∼), conjunction (∧), disjunction (∨), implication (⊃), and equivalence (≡). Logicians showed that they can be reduced to negation and disjunction. In 1913, the American logician H. M. Sheffer proposed obtaining all of them from a single binary truth–function , which he symbolized by a vertical stroke (∣). With this notation, p∣q is read as not both p and q. Accordingly, negation (∼p) can be defined as p∣p; disjunction (p ∧ q) can be defined as (p∣p)∣(q∣q), and so on. The truth–table for the Sheffer stroke function is: p q p|q T T F T F T F T T F F T “A function from which all others may be obtained is called a Sheffer function, after the discoverer of the stroke function.” Goodstein, Development of Mathematical Logic  Is it true?

The other eight functions of Table 11.2 (f9 — f16, as well as the last three functions of Table 11.1), we repeat, have neither names nor practical applications [footnoteRef:3]. These are either constants (f15 and f16), or functions of only one argument (f11 — f14). The name, and even that conditionally, can be given only to the functions f9 and f10: the inversion (negation) of the implication. But these two functions, as a rule, apply only to real arguments: the example π > e = 1 (yes, the numerical value of the ratio of the length of the circle to its diameter is greater than the numerical value of the base of the natural logarithm). [3: In the Mathcad Prime environment, there is one more operator that returns zero or one: It is , the set membership operator. This infix operator determines whether its first operand belongs to one of the possible numeric sets (the second operand): C is a complex number, Q is a rational number (this operator belongs to the symbolic math), R is a real number, and Z is an integer (see Figure 12.1 in etude 12).]

Figure 11.3 shows the calling operators in the Mathcad 15 environment of some basic Boolean functions of two arguments from Table 11.2. These operators are implemented in the form of infix operators - operators, the symbol of which, as already noted, is between two operand arguments. The arrow over the vector operands in Fig. 11.3 is a special vectorization operator, i.e. elementwise execution of the action on vectors.

Fig. 11.3. Operators for calling Boolean functions in Mathcad 15

For some operators shown in Fig. 11.3, there can only be Boolean operands (0 or 1), and for others - also real ones: 0.1, 0.9, 2.5, etc. Figure 11.4 shows the operation of the operators Exclusive or[footnoteRef:4] (Xor) and Not equal to real operands: not with 0 and 1, but with 0.1 and 0.9. These operators for Boolean operands (Figure 11.3) gave identical answers, while for real operands (Figure 11.4) the answers are different. Comment by Nori Massimiliano: This reminds me of this point of Latin Grammar: vel (or, inclusive) and aut (Xor, exclusive), both corresponding to Italian “o”: “tamen vel virtus tua me vel vicinitas”, “nam pro deum atque hominum fidem quid vis tibi aut quid quaeris?”Terentius, Heautontimorumenos [4: By the way, our conversational "or" is often not simple "or", namely "exclusive or". When we ask, for example: "Do you go to the cinema or stay at home?", We put this question in the "exclusive" or "because". a person cannot be at the same time in the cinema and at home. And further. In the written texts (and in this book too) appeared a hybrid "and" and "or", which only recently the editors ceased to remove from manuscripts: "and / or".]

Fig. 11.4. Operator "Exclusive" or "Not equal" with real arguments

The answer of the first operator in Fig. 11.4 (only zeros) is due to the fact that numbers other than zero are perceived as units (Truth) by Boolean functions of the Mathcad package. This is due to the fact that in earlier versions of Mathcad there were no And and Or operators, and Boolean operations were implemented through arithmetic operators of multiplication and addition - see Fig. 11.5. If you add two units (the Or operator), you get a two (true) - a number that is different from zero.

Fig. 11.5. The implementation of logical multiplication and logical addition in the Mathcad package of earlier versions

Boolean functions And and Or are often illustrated by an electrical circuit: the serial connection of switches (devices in two possible positions 0 and 1) is a conjunction (logical multiplication), and the parallel one is a disjunction (logical addition). In Fig. 11.6 also shows a less trivial example - the electrical analogue of the equivalence (Eqv): a circuit for connecting two switches, so that the light is independently switched on and extinguished from two different places. Such switches will be useful in a long corridor or on the stairs of a multi-storey building, in a suburban area and in other places. On the author's site http://twtmas.mpei.ac.ru/mas/Worksheets/Book_MC_12/4_25_Logic.mcd you can work with such a virtual switch.

Fig. 11.6. The electrical analogs of the three Boolean functions And, Or and Eqv

Tables 11.1 and 11.2 attempt to collect all the names of the base functions and the symbols of the basic operators used to implement the Boolean algebra. The list is, of course, incomplete. You can extend it with examples from other programming languages (Pascal, Fortran, etc.) and mathematical programs (Maple, MatLab, Mathematica, etc.).Comment by Nori Massimiliano: For instance in VBA, Two functionality are used:logical/bitwise operators defined in Visual Basic. + And, Not, Or, Xor, AndAlso, OrElse, IsFalse, IsTrue comparison operators defined in Visual Basic. < <= > >= = <> Is Operator + IsNot Operator + Like Operator +

It is possible to note some redundancy of the functions collected in Tables 11.1 and 11.2. In specific programming languages, there is a certain limited set of built-in Boolean functions and operators, with which you can make any other Boolean functions. To prove the sufficiency of such a set for produce any Boolean operators is a difficult mathematical task. If a finite number of functions are chosen, the actions that are subordinate to special rules are described with them and the possibility of realizing all other functions by means of these functions and actions is proved, then it is said an algebra[footnoteRef:5]. [5: An algebra is a non-empty set of elements of any nature with associated algebraic operations satisfying given axioms. The subject of algebra studies are not the elements, but the algebraic operations. There are several types of algebras. One of the most important and most studied types are groups, i.e. algebras with one associative binary operation, including a unit and each element having an inverse element. The most important types of algebras with two binary operations are rings and fields. Operations in them are usually called addition and multiplication. ]

Here is a list of such functions and operators embedded in popular software environments:

· BASIC programming language: Not, And, Or, Xor and Imp

· C programming language: !, & (logical multiplication), && (bitwise conjunction), !=, ║and = =

· mathematical program Mathcad: ¬, ^, ˅ and (see Figures 11.1 and 11.2)

The programmer can enter missing binary functions (operators) into the program itself through the mechanism of user functions, and we'll show it below.

Distinction of binary functions and operators into main (basic) and auxiliary ones appeared long before computers and was legitimized in the form of binary algebras (in parentheses their base notation):

· algebra of logic (¬, &, ˅, → and ↔);

· Boolean algebra (¬, & and ˅);

· Zhegalkin algebra (&, ˅ and );

· Peirce algebra (↓);

· Sheffer algebra (│).

The last two binary algebras are noteworthy because in their basis there is only one binary function ↓ or |, from which it is possible to build all the remaining ones.

Fig. 11.7. Creating the Boolean Peirce function in the Mathcad environment using negation and logical addition

or

or

With the unique Pierce function, we determine all the remaining functions

Fig. 11.8. Building the Boolean functions using the Pierce function

Figure 11.8 shows the Mathcad 15 document, where other Boolean functions are built using the Pierce function (↓ - see Fig. 11.7): one function of one argument (negation, inversion - Not) and five functions of two arguments: And, Or, Imp, Sheffer's stroke (|) and Eqv. The last three functions (Imp, Sheffer's stroke and Eqv) are defined using previously defined functions. This is done to make the drawing more compact, but you can refuse the mechanism of embedding user functions for example, (Imp (a, b): = Or (Not (a), b))and operate "for the purity of the experiment" only by Pierce's (stroke) function.

Once, high hopes were placed on the Peirce algebra and on the Schaeffer algebra, in the sense of building a digital computer of the same type. Then this idea was abandoned for a number of reasons, the main one being that any computer already consists only of certain types of elements - from transistors integrated into integrated circuits (chips).

One can also note a certain insufficiency of the set of mathematical tools displayed in Tables 11.1 and 11.2. Take, for example, probably the most popular function of Boolean algebra - a conjunction (a consequence of its popularity and that it has the highest number of names and symbols for its designation - see column f1 in Table 11.2). The truth-of-truth (the truth of conjunction) column in the truth table ( so are called tables 11.1 and 11.2) should ideally be as shown in Table 11.3.Comment by Nori Massimiliano: multiplication

Table 11.3. Closed conjunction

A dash beside zero in the first column of Table 11.3 means that if the first (a) argument is zero, then there is no need to check what the second argument (b) is equal to, and vice versa. This is provided by creating some ("not lazy") programming languages - the C language, for example. When programming the same in the BASIC environment, the conditional jump on a conjunction can be written as follows:Comment by Nori Massimiliano: In VBA was added the operator AndAlso: Performs short-circuiting logical conjunction on two expressions.A logical operation is said to be short-circuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result. Short-circuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls.

If a And b Then… (1st method)

but it is better this way:

If a Then If b Then… or If b Then If a Then… (2nd method)

The second way of coding allows not only to speed up the calculations, but also to avoid some errors - the logical expression b can make sense only if the alternative question a is answered positively. Here is a typical example of such a "programmer" situation:

If I> 0 Then If V(i) >V(i-1) Then… Comment by Nori Massimiliano: The following example shows a Function procedure that searches for a given value among the elements of an array. If the array is empty, or if the array length has been exceeded, the While statement does not test the array element against the search value.Public Function findValue(ByVal arr() As Double, ByVal searchValue As Double) As Double Dim i As Integer = 0 While i <= UBound(arr) AndAlso arr(i) <> searchValue ' If i is greater than UBound(arr), searchValue is not checked. i += 1 End While If i > UBound(arr) Then i = -1 Return iEnd Function

We can say that in the BASIC language there are two conjunctions: And and Then If.

In Tables 11.1 and 11.2, we repeat, we collected the Boolean functions of one (table 11.1) and two (table 11.2) arguments. But, returning to the conjunction, we can say that this function has not two but ... one and a half arguments - see Table 11.3.

The same non-integer number of arguments can be observed for other Boolean functions:Comment by Nori Massimiliano: In VBA OrElse Performs short-circuiting inclusive logical disjunction on two expressions.A logical operation is said to be short-circuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result. Short-circuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls.

Table 11.4. Boolean functions of one and a half, one and zero of the arguments

It can be noted that operators in Table 11.2 were originally designed to work not with binary but with real operands: ">", "<", "≥", "≤", "=" and "≠". But if we take into account the fact that zero and one are in the set of real numbers, then the inclusion of these operators in Table 11.2 is completely natural. In this series (">","<","≥","≤","=" and "≠")redundancy and insufficiency can also be noted. With redundancy, everything is more or less clear (for example, "more", is the inversion from the operator "less than or equal to", etc.).

Insufficiency can be observed, for example, when working with real variables, since in this case instead of the "equal" operator, it is more appropriate to use the "approximately equal" operator, which is not among the operators in the built-in lists. One can also recall the existence of the concepts "much more" or "much less". These relational operators also return binary values, but in fact they have not two but three arguments (operands): a comparable pair of real numbers and some kind of contextual notion of what is "about" or "much".

Figure 11.9 shows the creation of the Boolean operator “Approximately equal”. in the Mathcad 15 environment.

Fig. 11.9. Creating a Boolean operator Approximately equal to in Mathcad 15

In the Mathcad Prime environment, an option appeared that makes it possible to turn the "equals" operator into an "approximately equal" operator - see Fig. 11.10.

Fig. 11.10. Approximately equal in Mathcad Prime environment

Boolean functions in Mathcad can be used not only for logical computations. They can also be used to solve equations.

Example 1. Solve the equation:

.

For the solution, one of the solver operators described in Etude 4 could be used. And it would be nice to first plot the graphs of both sides of the equation (note that it is sufficient to plot only the interval [-4, 4], since the inequality ) in order to locate the available roots. But you can do otherwise.

We introduce the following logical variables: a := ; b :=;

c := ; p := ;

q := . Clearly, the roots of the equation will be found approximately (with the exception of the obvious integer root x = 0), so we must choose the desired step, and for each point of the above segment obtained with this step, we need to verify the truth of the statement.

.

The test statement can be simplified if we transform the original equation to the form . Such a form will make it impossible to verify the truth of the statement that both sides of the equation at each admissible point have the same signs. And for r := and t := . It will be required at each point to check the truth of the statement .

Example 2. Solve the equation .

The solution of one equation with two variables can be any (including infinite) number of points in the plane. For example, the equation has a unique solution (0,0), while the equation has infinitely many solutions - points forming a circle of unit radius and center at zero. The solutions of equations with two unknowns are discussed in Htude 4. Here we again apply the logical variables:

a := ; b :=; p := ; q := , and we will verify the truth of the statement at the points of the rectangle , , defined with a certain step in each of the variables. All the points found in this way will give us an approximate solution of the original equation.

The classical Boolean algebra operates with argument-statements that can be true or false. For example, saying a: "The student passed the math exam", saying b: "The student passed the computer science exam", saying : "The student passed the exams in mathematics and computer science". Statements can be naturally related to sets[footnoteRef:6]. For example, A is the set of students who passed the math exam; B is the of students who passed the exam in computer science. The question can be posed as follows: "Is it true or false that this student belongs to the set A ∙ B? [6: Traditionally, statements, or logical variables, are denoted by lowercase letters, and sets by capital letters. Also traditionally, the notation for logical operations in Boolean algebra and in the algebra of sets is different.]

Such a natural correspondence of Boolean algebra and algebra of sets allows one to take advantage of this or that interpretation of the statements. Thus, a geometric visual representation of the relations between statements (sets) in a Boolean algebra is represented by circles[footnoteRef:7] or other figures. Such figure is called a Venn diagram [footnoteRef:8]. Element 1 of Boolean algebra is the universal set, or a true statement, it can be represented as a square and denoted by the letter Ω. To the element 0 corresponds an empty set, or a false statement, it can be denoted by Ø. Some non-empty set A, or some statement а, is represented as a circle or another figure located in a square. What lies outside the set A is the complement of A or the negation of the statement а, that is, ¬A. The sum (disjunction) of two sets A and B is represented as a union of the figures representing them and can be indicated by the symbol "+". The product (conjunction) of two sets A and B is represented as an intersection of the two figures representing them and can be designated by the symbol "∙". The Venn diagram is used to illustrate the validity of axioms and Boolean algebra theorems, as well as to represent the relations between logical statements. As a special case of Euler circles, the Venn diagram depicts a finite Boolean algebra, clearly describing all its properties and combinations of these properties. For n = 3, this diagram is usually represented as three circles with centers at the vertices of an equilateral triangle and with the same radius, slightly smaller than the length of the side of the triangle. All this design is placed in a square.Comment by Nori Massimiliano: from wikipedia [7: In solving a whole series of problems, Leonard Euler used the idea of representing sets by means of circles. However, this method was used by the eminent German philosopher and mathematician Gottfried Wilhelm Leibniz for geometric interpretation of logical connections between concepts even before Euler. The German mathematician Ernst Schröder used the method of Euler circles in the book "The Algebra of Logic".] [8: In mathematical logic, such figures were introduced by the English mathematician John Venn, who described them in detail in his book Symbolic Logic, published in London in 1881.]

With the help of Venn diagrams, you can simplify or compose several Boolean functions from table functions. It allows us to understand the validity of logical identities. Clearly, the same figures on the Venn diagram correspond to the (left and right) parts of the logical expressions. Thus, the union of the circle A and the intersection A ∙ B is the circle A, therefore, we get that A + A ∙ B = A. Note that for any statement (set) A the Boolean expression а + (¬а) is true, i.e. A + (¬A) = Ω. The same is equivalent to the property ¬ (¬а) = а, which is also called the "Excluded Third Law". Indeed, if A is a circle inside a square, then (¬A) is a part of a square without a circle, but then ¬ (¬A) is the part of the square from which the part of the square without the circle is excluded; just the circle.

We list the main properties of Boolean algebra. They are easy to understand by giving the statements a, b, c the values "true" and "false", or by shading certain areas on the Venn diagram for the sets A, B and C.

1. А+А = А;

2. А∙А = А;

3. А+В = В+А;

4. А∙В = В∙А;

5. А+А∙В = А;

6. А+(В+С) = (А+В)+С;

7. А∙(В∙С) = (А∙В) ∙С;

8. А∙(В+С) = А∙В+А∙С;

9. (А+В)∙(А+С) = А+ В∙С;

10. А+Ω = Ω;

11. ¬ Ω = Ø;

12. ¬ Ø = Ω;

13. А+ Ø = А;

14. А∙Ω = А;

15. А∙ Ø = Ø;

16. А+(¬ А) = Ω;

17. А∙(¬ А) = Ø;

18. ¬ (А+В) = (¬А)∙ (¬В);

19. ¬ (А∙В) = (¬А)+ (¬В);

20. ¬ (¬А)=А.

These properties are most often used to prove equalities that define complex statements or sets.

For example, you want to simplify a logical statement f(a,b,c)=aabbc(¬a)c. Of course, you can, using basic logic functions, create a table of values for this function, and then look for another, simpler function with exactly the same values (if it exists). But we proceed as follows. We draw the Venn diagram in the case of the intersection of all three sets (for convenience we replaced the circles in rectangles in Fig. 11.11). Given the location of the rectangles, we see that

A+A∙B+B∙C+(¬A)∙C=A+C. Now we strictly prove this equality using the properties of a Boolean algebra:

A+A∙B+B∙C+(⌐A)∙C=(A+(⌐A)∙C)+(A∙B+B∙C)=(A+(⌐A)∙C)+B∙(A+C)= 

=(A+(⌐A))∙(A+C)+B∙(A+C)=Ω∙(A+C)+B∙(A+C)=(Ω+B)∙(A+C)=Ω∙(A+C)=A+C. 

It is not always possible to obtain a rigorous proof of the assumed equality. And if equality is not right, then it is even more difficult to find a solution, since, when carrying out the transformations, it is necessary to bring equality to a contradiction. A graphical method using Venn diagrams is not a rigorous or complete solution if the equation is verified, since in the case of a graphical solution it will be necessary to consider all possible locations of all sets. But the diagrams give an unambiguous answer in the case when the equation is not verified. Indeed, if it was possible to find, at least one example, when the equation is not true, then it is not exactly satisfied.

А

А∙В

В

В∙С

С

(¬ A)∙C

The Venn diagram for A + A ∙ B + B ∙ C + (¬ A) ∙ C.

Clearly, the use of the diagram is especially convenient if there are a lot of statements.

If we talk not about the classical Boolean algebra, but about the actual programming practice, it should be recognized that the variables appearing in Tables 11.1 and 11.2 can take not two (0 or 1) but three values: 0, 1 and indefinitely. This feature we have already fixed in Tables 11.3 and 11.4, where instead of specific values of the arguments (0 or 1) there is a dash. In programming languages, there are tools that handle such "dashes" in truth tables. If the argument of the Boolean function is not defined, then the calculation can either be interrupted by an error message, or go through the third scenario.Comment by Nori Massimiliano: In VBA Boolean Function are initialized as false

Arguments of Boolean functions can take not two but three, but ... an infinite set of real values. This set is divided into two extremely unequal parts: zero and nonzero (¬0, if we speak in the language of Table 11.1 for non-zero numbers, which we repeat, Boolean functions of the Mathcad package are perceived as units). It also happens that the Boolean function returns not only zeros and ones. Here, for example, how the Or function works in one of the implementations of the BASIC language (or rather, the version of the BASIC language, which was completed with the popular PC "Iskra-226" - http://www.ic.kz/~ksxi/musei/int6.htm the tracing machine "Wang-2000"): see table 11.5.

Table 11.5. "Disjunctive conjunction"

It is possible to admit also such work of the expanded operator Or: see the table 11.6.

Table 11.6. Extended conjunction (disjunction)

It's one thing when the first argument (operand) is not zero, the other - when the second, and the third - when both are not zero at the same time.

Summarizing our analysis of Tables 11.1 and 11.2, we can say that the described Boolean functions in real computer implementations can have non-binary arguments and return again non-binary results. But there is no special non-binary meaning in this. Simply, we repeat, for technological reasons, the real variables in the described implementations of programming languages (BASIC, Mathcad) "concurrently" play the role of binary ones. Boolean functions take their real arguments "binary": zero is zero ("No", "False"), and the rest is a unit ("Yes", "True").

This, one might say, "categorical" behavior of the described built-in functions contradicts the provisions of fuzzy sets theory (see Etude 12) and fuzzy logic theory (64, 65). It is necessary, for example, to process on the computer not only the "black and white" (binary) answers of the questionnaire type "Yes (1)" - "No (0)", but also the "color" (real) answers: "Yes (1) "," Yes, rather than no (0.75, for example) "," No, yes, no (0.5) "," Rather no than yes (0.25, for example) "and" No (0) ". If we talk not about statistics, but about electrical engineering and return to the electrical circuits, which are often used to illustrate the work of Boolean functions (see Figure 11.6), it is possible to mention the fact that now in everyday life switches smoothly change the glow of lamps from 100% to zero. Such devices were earlier used in theaters and cinemas. Doctors say that a smooth transition from light to darkness through the twilight does not spoil the eyesight. (In cinemas, light is extinguished smoothly, of course, not for medical reasons, but for other reasons - if the light is abruptly extinguished, panic may occur.)

There are many other examples that lead to the fact that the arguments of the functions listed in Tables 11.1 and 11.2 can and should not only be binary, but also real numbers from zero to one. And the functions listed in Tables 11.1 and 11.2 must return real values that smoothly change from zero to one. Here's how, for example, you can specify a "smooth" negation function - see Fig. 11.12.

Fig. 11.12. Smooth negation

"Smooth" conjunctions (And) and "smooth" disjunction (Or) [footnoteRef:9] turn out on their own if one remembers that one of the notations of the conjunction is min (minimum - see column f1 in Table 11.2), and one of the disjunction symbols is max (maximum - see column f2):Comment by Nori Massimiliano: What is the english equivalent of четкой логикой: Boolean Logic,  two-valued logic  [9: Some Mathcad users find it difficult to remember that ^ is a logical multiplication, and ˅ is a logical addition. Therefore, it will not be superfluous to introduce into account the user-defined functions And and Or, even if we work only with Boolean logic.]

And(a, b) := min(a, b) Or(a, b) := min(a, b)

Figures 11.13 - 11.16 show a three-dimensional graphical representation of fuzzy Boolean functions And, Or and Eqv. The latter function is represented in two variants of Eqv (Figure 11.15) and Eqv1 (Figure 11.16).

Fig. 11.13. Fuzzy Graph And

Fig. 11.14. Fuzzy Graph Or

Fig. 11.15. Fuzzy Graph Eqv

Fig. 11.16. Fuzzy Graph Eqv (second option)

The broken surfaces shown in Figures 11.13-11.16 and 11.19 below are similar to the Japanese origami figures, folded from a sheet of paper.

Figure 11.17 shows the creation of fuzzy Boolean functions and their display on the graphs of lines of the same level (on contour charts).

Fig. 11.17. Fuzzy Boolean functions

1.3. Functions of many arguments

Boolean functions of three arguments are 256, and four ... Reader, define it yourself!Comment by Nori Massimiliano: 216 =65536From http://mathworld.wolfram.com/BooleanFunction.htmlConsider a Boolean algebra of subsets generated by a set , which is the set of subsets of that can be obtained by means of a finite number of the set operations union, intersection, and complementation. Then each of the elements of is called a Boolean function generated by (Comtet 1974, p. 185). Each Boolean function has a unique representation (up to order) as a union of complete products. It follows that there are inequivalent Boolean functions for a set with cardinality (Comtet 1974, p. 187).

The functions And and Or, if they are identified with the min and max functions (see above), can have a variable number of arguments - with Boolean (0 or 1) or fuzzy (from 0 to 1) values. This property is also possessed by some other Boolean functions.

What kind? Reader, find again this by yourself!Figures 11.18 and 11.19 show the formation in Mathcad of a fuzzy function of three arguments, returning ... the decision of the jury, which can issue no longer "black and white" answers (guilty - innocent), but ... "color": guilty of 30%, innocent by 70%, etc. In the electric analogue of the voting machine, the switches (0 or 1) are replaced by rheostats (from 0 to 1).

A sad note

It is said that in the United States, an electric chair leads to the death of several people. In this case, the real switch is activated by only one person. The remaining members of this execution include fake switches. And no one knows where the fake, and where the real switch. Such a somewhat sanctimonious procedure makes it possible for each such executioner to think that it was not him, but someone else was the cause of the person's death. If all the actual switches are changed with rheostats (see Figure 11.18 below), smoothly changing the voltage, then death can be replaced by non-lethal punishment: the convicted criminal will receive an electric shock (strong or weak), but will remain alive.

Fig. 11.18. Voting machine: parallel (Or) connection in series (And) connected switches (rheostats)

Fig. 11.19. Function of fuzzy voting of three members of the jury

The Verdict function, shown in Fig. 11.19, with binary arguments returns a binary response, and for real arguments it returns a real one, naturally. The corresponding "Boolean die" (origami) is shown at a = 0.7 - we see a hybrid of the conjunction with disjunction: the fuzzy (from 0 to 1) opinion of one member of the jury smoothly translates the verdict from the Or area (see Figure 11.14) to the And area (see Figure 11.13).

Task for readers:

1. Create a function similar to the one shown in Fig. 11.19, but not for three, but for any number of jury members who make their verdict vague - a real number from 0 to 1.

2. Create a Boolean function to turn on the light from anywhere.

3. Find online logic puzzles and try to solve them using the tools described in this etude.

2

abf

1

f

2

f

3

f

4

f

5

f

6

f

7

f

8

f

9

f

10

f

11

f

12

f

13

f

14

f

15

f

16

000010111100110010

010101010101100110

100101100110011010

111110110000001110

˄˅=≠≥≤><¬�a¬�bab10

*+↔<>→→↓I

×o≡><¬�And¬�Or

∙OrXor

e||Eqv!=ImpImp

Andmax==

&

&&

min

Notation