Project 2.11 Section 2 ⚡ Embedded Relevance: Core De Morgan's Laws Boolean Logic Truth Tables Optimization Logic Inversion

2.11 Compound Boolean Expressions, Truth Tables & De Morgan's Optimization Laws

Executive Summary: Analyzing compound boolean logic and truth tables. We explore De Morgan's Laws for simplifying complex nested conditions, reducing branch instruction count in assembly, and ensuring logic inversion safety in mission-critical systems.

💻 1. Annotated Source Code

#include <iostream>
using namespace std;

int main() {
	bool isSunny = false;
	bool isWarm = false;

	cout << boolalpha;

	cout << "Is it sunny? " << isSunny << endl;
	cout << "Is it warm? " << isWarm << endl;

	return 0;
}

📐 2. Architecture & UML Class Model

📐 Boolean Multi-Sensor Fusion Decision Model
+ Public - Private # Protected
<<compilation-unit>> WeatherSensorFusion Sensor Evaluator
-isSunny : bool
-isWarm : bool
+evaluateOutdoorConditions(sunny: bool, warm: bool) : bool
+printRecommendation() : void

📚 3. Core C++ Concepts Deep-Dive

1. De Morgan's Laws

De Morgan's laws state that:

  • !(A && B) == (!A || !B)
  • !(A || B) == (!A && !B)

Applying these rules simplifies boolean condition checks in firmware.

⚡ 4. Embedded Systems & Hardware Reality

1. Reducing Branch Instructions

Simplifying complex logical conditions reduces conditional branch instructions (BNE, BEQ), minimizing CPU pipeline hazard penalties.

💡 5. Production-Ready Embedded Refactoring

Simplified, branch-efficient flight safety check:

💡 Production-Ready Refactor
#include <cstdint>

struct FlightConditions {
    bool is_battery_healthy;
    bool is_gps_locked;
    bool is_motor_armed;
};

// Simplified using De Morgan's laws for fastest early exit
constexpr bool isFlightReady(FlightConditions f) noexcept {
    return f.is_battery_healthy && f.is_gps_locked && f.is_motor_armed;
}

📝 Knowledge Verification Quiz

Test your understanding of the C++ concepts and embedded microcontroller trade-offs covered in this guide. Click any option for instant feedback.

Q1. According to De Morgan's Laws, what is the equivalent expression for '!(A && B)'?
A !A || !B
B !A && !B
C A || B
D A && !B
Detailed Explanation: De Morgan's law states that negating a logical AND produces a logical OR of the negated terms: !(A && B) ≡ (!A || !B).
Q2. According to De Morgan's Laws, what is the equivalent expression for '!(A || B)'?
A !A && !B
B !A || !B
C A && B
D !A || B
Detailed Explanation: Negating a logical OR produces a logical AND of the negated terms: !(A || B) ≡ (!A && !B).
Q3. Why does simplifying boolean expressions improve microcontroller assembly execution?
A It eliminates redundant comparison and conditional branch instructions, preventing pipeline stalls
B It increases CPU voltage
C It moves variables into Flash ROM
D It converts integers to floating point
Detailed Explanation: Simplified boolean expressions generate fewer conditional jumps in assembly, preventing branch mispredictions.
Q4. In the truth table for logical AND (A && B), how many out of the 4 input combinations yield 'true'?
A 1 combination (only when both A and B are true)
B 2 combinations
C 3 combinations
D 4 combinations
Detailed Explanation: Logical AND yields true only when both operands are true ($1 \times 1 = 1$).