Visualization of logical formulas
|There is a form of visual presentation, catchy, understandable to all from childhood. This form is the schedule.
FUNCTIONS AND IMAGING
- Where can I buy a puppy?
- In our town, they are sold on the market, but today the market is closed. In addition, puppies are sold every day. Puppies are quite expensive and some plain – do not know if they like you.
From overheard conversation clear that the purchase can be made to a puppy and only when four conditions are satisfied (Fig. 55):
- the market is open (this condition is denoted by P);
- the buyer has the money (Q);
- Puppies are on sale (R);
- puppy like (S).
As a result, we obtain the logical function
|X = P and Q and R and S|
wherein X is “You can buy a puppy?” (Fig. 55).
In traditional programming languages, values of logical variables are considered a pair (TRUE, FALSE) or (1, 0). From an ergonomic point of view, such an approach can not be considered successful. In fact, the use of “helluva lot of erudite” words TRUE and FALSE or mysterious numbers 1 and 0 in the example of the puppies (and any other specific example) is frivolous, misleading and does not promote an understanding of the issue.
To improve matters, as the values of the logical variables and logical functions much better to choose a simple and clear words “yes” and “no”, the semantics of which is self-explanatory and understandable even to a child. On this basis, in the language DRAGON logic functions, variables and expressions are regarded as so-ations questions. Logic function and is defined as a function that takes the value of “yes” if all of the logical variables are set to “yes.” In other cases, the function gets the value of “no” (Fig. 55) 1.
There are two ways the image features and languages DRAGON: text and visual. In the first case, an icon of a “question” within which they write a logical expression consisting of logical variables connected by logical AND operation marks (Fig. 56 left). In another case, a vertical paint N Icons “issue”, where N – number of logical variables, with each icon recorded a boolean variable (Fig. 56 right).
The visual formula in Fig. 56 shows that both methods are equivalent. Examples Fig. 57 confirm this. Recommended best practice is a visual way, as it more evident and makes it easier to find errors in complex algorithms. It should be stressed that the text method is not prohibited, but use it with caution and only in those cases when the user is convinced of its ability to guarantee the absence of errors. Experience shows that most people choose a more visual way easy. However, trained professionals who are familiar with the basics of mathematical logic, sometimes prefer a text method. Such people can be advised to master both.
Visualization function or
Logical OR function is set to “yes” if at least one logical variable is “yes.” The function is set to “no” if all of the logical variables have a value of “no” (Fig. 58).
In the language of DRAGON OR function can be written in two ways. If you select text mode, the icon draws a “question” that contains a logical expression (Fig. 59 left). When the visual method uses several icons “issue,” which combined the lower output; each icon writing a boolean variable (Fig. 59 right). From Fig. 59 and 60 it is evident that both methods are equivalent.
Visualization function is not
The function W = Z function is not called if the logical variables Z and W are inverted values, t. E. Satisfy the conditions:
if Z = yes, W = no;
if Z = no, W = yes.
The visual formula in Fig. 61 show that the sign of logical negation can be excluded from the dragon-circuit if interchanged the words “yes” and “no” on the outputs of the icon “question” (the icon located in the fork of the shoulders, should be left in place).
Exercises in Fig. 62-66 will help the reader to consolidate the material.
Visualization of complex logic functions
Consider the function
|X = (A & B and C) or (D and E andF)||(1)|
Fig. 67 shows a visual way to write this function. The figure shows that the formula (1) is divided into three parts:
1) A and B and C; 2) D and E and F; 3) the “OR” operation.
Function A and C and is represented by three icons A, B, C located on the same vertical. Similarly, paint the D and E and B.Bunch “or” being implemented by means of lines that combine lower yields icons C and F at the point K (Fig. 67).
In formula (1), some members recorded without logical negation (A, B, D, E), others – negated (B, F). Members without negation transformed into icons of A, B, D, E, whose lower outlet is marked with the word “yes.” Members of the denial of the icons in the match, and F, where the lower output is marked with the word “no” (Fig. 67). Other examples of algorithms that compute complex logic functions are shown in Fig. 68-74.
These considerations allow us to formulate two theorems.
Theorem 1. Dragon diagram containing logical connectives AND, OR, NOT inside icons “issue” can always be converted into an equivalent diagram of a dragon that does not contain these bundles.
Theorem 2. If some fragment of a dragon-circuit has one input, two outputs, and contains only the icons of “question”, the first output function calculates the X, the second output computes the logical negation of X (Fig. 67-73).
The proof of the theorems to the reader.
- In complex logic algorithms are often used conditional statements with logical expressions. Experience shows that such operators are often difficult to understand, which often leads to mistakes.
- The language used DRAGON visual logic expressions, allowing, if desired, to completely eliminate the logical connectives AND, OR, NOT of conditional statements.
- Visualization of logical formulas in many practically important cases, significantly facilitates the understanding and reduces the likelihood of errors.