0
0
PHPprogramming~10 mins

DNF types (Disjunctive Normal Form) in PHP - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - DNF types (Disjunctive Normal Form)
Start with logical expression
Convert to OR of ANDs form
Identify each AND clause
Combine clauses with OR
Result: Expression in DNF
DNF means writing a logical expression as OR of AND groups. We break it down into AND parts, then join them with OR.
Execution Sample
PHP
<?php
$A = true;
$B = false;
$result = ($A && $B) || (!$A && $B);
echo $result ? 'true' : 'false';
?>
This code evaluates a DNF expression with variables A and B and prints true or false.
Execution Table
StepExpression PartEvaluationResult
1$Atruetrue
2$Bfalsefalse
3$A && $Btrue AND falsefalse
4!$ANOT truefalse
5!$A && $Bfalse AND falsefalse
6($A && $B) || (!$A && $B)false OR falsefalse
7echo $resultfalseprints 'false'
💡 Expression fully evaluated, final result is false
Variable Tracker
VariableStartAfter Step 1After Step 2Final
$Aundefinedtruetruetrue
$Bundefinedundefinedfalsefalse
$resultundefinedundefinedundefinedfalse
Key Moments - 2 Insights
Why is ($A && $B) false even though $A is true?
Because AND requires both sides true. $B is false (see step 2 and 3 in execution_table), so whole AND is false.
Why do we use OR between AND groups in DNF?
OR means if any AND group is true, whole expression is true. This matches DNF form (see step 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of !$A at step 4?
Atrue
Bfalse
Cundefined
Derror
💡 Hint
Check step 1 where $A is true, so NOT true is false at step 4.
At which step does the expression ($A && $B) || (!$A && $B) become false?
AStep 6
BStep 5
CStep 3
DStep 7
💡 Hint
Step 6 shows the OR of two false AND groups resulting in false.
If $B was true instead of false, what would be the result at step 6?
Aundefined
Bfalse
Ctrue
Derror
💡 Hint
If $B is true, then ($A && $B) is true AND true = true, so OR result is true.
Concept Snapshot
DNF means writing logic as OR of AND groups.
Syntax: (A && B) || (C && D) || ...
Each group joined by OR, inside groups use AND.
Evaluate AND groups first, then OR them.
Useful for simplifying or analyzing logic.
Full Transcript
This example shows how to evaluate a Disjunctive Normal Form (DNF) expression in PHP. We start with variables $A and $B. We check each part: $A is true, $B is false. Then we evaluate AND groups: $A && $B is false because $B is false. !$A is false because $A is true. So !$A && $B is false. Finally, we OR the two groups: false OR false is false. The program prints 'false'. This shows how DNF expressions are evaluated step by step.