O
O
Oleg Petrov2018-10-19 09:02:30
Programming
Oleg Petrov, 2018-10-19 09:02:30

How is implication used in programming?

Can you give a simple example of an implication in Python or in pseudocode, but with real numbers instead of an abstract one?
Here is an example from the wiki, I don't understand it.

if 2 < 4: - #Это 0 для условия A
    if 3 < 5: #Это 0 для условия B

What then will be the next? What code would be the implication with the value 0 and 1?
Here I wrote this code:
if (a and b) or not a:
    print('Yeeea')

Everything is clear here that the implication will be true if:
A = False
A = True and B = True
otherwise is not true.
Or here is the code that implements the implication
def implies(a,b):
    if a:
        return b
    else:
        return True

The only question was how exactly does Python use implication in the work of if statements?
After all, the nested if construction will be true only if both conditions are true, if the first if (which is A) = False, then the program will never reach condition B.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2018-10-19
@sergiks

have you looked at the wiki ?

In programming languages, implication is usually used implicitly. For example, a construction that assumes the truth of condition B in a given section of the program:
if ( выражение A ) {
    if ( выражение B ) {
       сделать_что-то_полезное
    }
       else {
       <font color=Red>сбой</font>
    };
 }

will succeed if and only if the implication A→B is true. At the same time, these conditions can be safely written in one line by combining them with a conjunction operator.
if ( выражение A ) and ( выражение B ) {
    сделать_что-то_полезное
 }

With standard compiler options (Delphi, C++ Builder), the check goes on until the result becomes obvious, and if A is false, then (A and B) are false regardless of B, and there is no need to put another conditional operator.
//выражение A - ложно
 if ( выражение A ) {
    //Дальше проверка не идет
    ... if ( выражение B ) {
       сделать_что-то_полезное
    } ...
 }

In functional languages, implication can be not only a calculation rule, but also a type of relationship between data, that is, it can be processed (including executed) and created during program execution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question