Condition et Logique Booléenne
0)Rappel
Condition : if/elif/else
Python :
if condition 1 :
conséquence 1 (le alors est implicite)
elif condition 2 :
conséquence 2
else :
conséquence 3
Non
Condition 1
Non
Oui Condition 2
Conséquence 1
Non
Condition 3
Oui
Conséquence 2 Oui
Conséquence 3
Pseudo Code :
SI condition 1
ALORS conséquence 1
SI NON SI condition 2
ALORS conséquence 2
SI NON conséquence 3
FIN SI
I / les variables booléenne :
Soit vrai / True
Chaque condition est
Soit fausse / False
If A :
If B :
Cons 1
A
B X
Cons1 X
La logique booléenne combine l’ensemble des conditions
Dans ce cas, la simplifacation est :
SI A ET B
Langage Naturel
ALORS cons1
FIN SI
If A and B :
cons1 Python
II / Les portes logiques (de base)
Non/not
a (entrée) S = not (a) (sortie)
0 1
1 0
ET / and (et simultanément)
a b S = a and b Opérateur logique
0 0 0 S = a and b
0 1 0
1 0 0
1 1 1
S=a*b
OU / or (ou bien)
a b S = a and b Opérateur logique
0 0 0 S = a or b
0 1 1
1 0 1 S=a+b
1 1 1
Application :
S = (a and b) or c
1. a = False, b = True, c = False
S=a*b+C
2. Faire de même pour toutes les valeurs possibles de a, b et c
a b c S = (a and b) or c
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
III / Les portes logiques combinés
NON OU / nor = fusion (non,ou)
a b S1 = a or b S2 = not(S1)
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0
S = not (a or b) = a nor b
= contraire (a + b)
NON ET / nand = fusion (non, et)
a b S1 = a and b S2 = not(S1)
0 0 0 1
0 1 0 1
1 0 0 1
1 1 1 0
S = not (a or b) = a nand b
= contraire (a * b) = contraire (ab)
Application :
1. Faire la table de vérité de not (a) and not (b)
2. Dresser la table de vérité de not (a) or not (b)
3. En déduire 2 théorèmes
a b not(a) not(b) not(a) and
not(b)
0 0 1 1 1
0 1 1 0 0
1 0 0 1 0
1 1 0 0 0
not (a) and not (b) = a nor b
a b not(a) not(b) not(a) or not(b)
0 0 1 1 1
0 1 1 0 1
1 0 0 1 1
1 1 0 0 0
not (a) or not (b) = a nand b