...
Sign in
Computer Science

Semantics

Semantics

Share:

Masterclass: Semantics — How Logic Inherits Meaning

Imagine receiving a text message from a friend that reads:

"Colorless green ideas sleep furiously."

Grammatically, this sentence is flawless. It has a subject, an adjective, a verb, and an adverb. It compiles without syntax errors in your brain's language processor.

But does it mean anything? How can an idea be green? How can green be colorless? How do ideas sleep—let alone furiously?

This highlights one of the most fundamental distinctions in Computer Science and Mathematical Logic: Syntax vs. Semantics.

  • Syntax is the set of rules defining structural arrangements ( grammar, code formatting, or legal arrangements of symbols).
  • Semantics is the mechanism that bridges structural symbols to meaning, context, and truth in reality.

Without semantics, your code is merely dead, hollow symbols sitting on a screen. Semantics is the spark that gives logic life, execution context, and power.


Act I: Syntax vs. Semantics (The Code Analogy)

To see this distinction in software, consider two lines of code:

# Line 1: Syntactically Invalidx = + * 5 # Line 2: Syntactically Valid, Semantically Problematicresult = "User" / 0
  1. Line 1 triggers a Syntax Error. The compiler rejects it immediately because the arrangement of symbols violates the language's grammar rules.
  2. Line 2 passes syntax analysis with flying colors! The syntax checker sees VARIABLE = STRING / NUMBER and approves it. But when executed, it crashes with a Semantic Error (TypeError or ZeroDivisionError). Division has no valid operational meaning when applied to text and zero.

Syntax asks: "Is this properly built?"
Semantics asks: "What does this actually do or represent?"


Act II: The Parallel Universes of Logic (Interpretations)

In Propositional Logic, syntax allows us to build complex formulas using variable symbols like PP and QQ, combined with logical operators like ∨\lor (OR), ∧\land (AND), and ¬\neg (NOT).

However, on its own, PP is just an abstract letter. To give PP meaning, we need an Interpretation (often denoted as II).

Think of an Interpretation as a specific Parallel Universe or State of the World. Mathematically, an interpretation is a function that maps abstract atomic propositions to concrete truth values: ⊤\top (True) or ⊥\bot (False).

A Real-World Analogy:

  • Let PP = "It is raining outside."
  • Let QQ = "I am holding an umbrella."

Now let's observe how our logic behaves across different universes:

  • In Universe A (A stormy afternoon):IA(P)=⊤,IA(Q)=⊤I_A(P) = \top, \quad I_A(Q) = \top

  • In Universe B (A clear sunny morning):IB(P)=⊥,IB(Q)=⊥I_B(P) = \bot, \quad I_B(Q) = \bot

The underlying logical symbols PP and QQ do not change, but their semantic evaluation changes completely depending on which universe (II) we inhabit.

graph TD
    A[Raw Logical Formula: P ∧ Q] --> B[Interpretation Engine]
    
    subgraph Universe A: Stormy
        I_A[P = True, Q = True] --> B
        B -->|Evaluates under I_A| AnsA[Evaluates to TRUE]
    end

    subgraph Universe B: Sunny
        I_B[P = False, Q = False] --> B
        B -->|Evaluates under I_B| AnsB[Evaluates to FALSE]
    end

Act III: Decoding the Mathematical Notation

Academic logic uses formal notation to articulate these concepts precisely. Let's demystify the core semantic symbols step-by-step.

The Semantic Turnstile Symbol (⊨\models)

When reading papers or logic textbooks, you will frequently run into this notation:

I⊨ϕI \models \phi

This symbol (⊨\models) is called the Double Turnstile or Semantic Entailment / Satisfaction symbol.

  • Read I⊨ϕI \models \phi as: "II satisfies ϕ\phi" or "II is a model of ϕ\phi".
  • It simply means: "In Universe II, the formula ϕ\phi evaluates to True (⊤\top)."

Conversely, if the formula evaluates to False (⊥\bot) in that universe, we write:

I⊭ϕI \not\models \phi

(Read as: "II does not satisfy ϕ\phi")

concrete Example:

Let formula ϕ=P∨Q\phi = P \lor Q (where ∨\lor represents OR).

  1. In Universe A where IA(P)=⊤I_A(P) = \top and IA(Q)=⊤I_A(Q) = \top: IA⊨(P∨Q)I_A \models (P \lor Q)
  2. In Universe C where IC(P)=⊥I_C(P) = \bot and IC(Q)=⊥I_C(Q) = \bot: IC⊭(P∨Q)I_C \not\models (P \lor Q)

Act IV: The Three Spectra of Truth

Once we establish how interpretations assign meaning to formulas, we can classify logical formulas based on how they behave across all possible universes.

                        [ Logical Formulas ]
                                 |
         +-----------------------+-----------------------+
         |                                               |
  [ Satisfiable ]                                 [ Unsatisfiable ]
  (True in AT LEAST ONE world)                     (True in ZERO worlds)
         |                                               |
         +-----------------------+                       |
         |                       |                       |
  [ Contingent ]             [ Valid / Tautology ]       |
(True in SOME,          (True in ALL worlds)             |
 False in SOME)                  |                       |
         |                       |                       |
   e.g., P ∨ Q              e.g., P ∨ ¬P            e.g., P ∧ ¬P

1. Satisfiable Formulas

A formula ϕ\phi is satisfiable if there is at least one interpretation II that makes it true.

  • Analogy: A lightweight rule like "You can enter if you have a ticket (PP) OR you are on the VIP list (QQ)."
  • Logic:P∨QP \lor Q is satisfiable because Universe A makes it true.

2. Valid Formulas (Tautologies)

A formula ϕ\phi is valid (written as ⊨ϕ\models \phi, omitting the specific II) if it evaluates to True under EVERY possible interpretation. No matter what universe you visit, a valid formula cannot be false.

  • Analogy: "It is currently raining OR it is not currently raining."
  • Logic:P∨¬PP \lor \neg P
  • Proof:
    • If I(P)=⊤I(P) = \top, then ⊤∨⊥=⊤\top \lor \bot = \top.
    • If I(P)=⊥I(P) = \bot, then ⊥∨⊤=⊤\bot \lor \top = \top.
    • In all worlds, the statement is unconditionally True.

3. Unsatisfiable Formulas (Contradictions)

A formula ϕ\phi is unsatisfiable if there is no interpretation that can make it true. It evaluates to False across every possible universe.

  • Analogy: "The light switch is ON AND the light switch is OFF at the exact same time."
  • Logic:P∧¬PP \land \neg P
  • Proof:
    • If I(P)=⊤I(P) = \top, then ⊤∧⊥=⊥\top \land \bot = \bot.
    • If I(P)=⊥I(P) = \bot, then ⊥∧⊤=⊥\bot \land \top = \bot.
    • No universe exists where this statement holds true.

Act V: Building a Semantic Evaluator in Code

To concrete our theoretical understanding, let's build a tiny Semantic Interpreter in Python.

Notice how we separate the parse tree (the Syntax) from the evaluation engine (the Semantics).

class Node:    """Base Syntax Node"""    passclass Variable(Node):    def __init__(self, name):        self.name = nameclass And(Node):    def __init__(self, left, right):        self.left = left        self.right = rightclass Not(Node):    def __init__(self, child):        self.child = child# The Semantic Engine (Evaluation Function)def evaluate(formula: Node, interpretation: dict) -> bool:    """    Evaluates formula truth value given a world state (interpretation I).    Maps abstract Syntax to concrete Semantics.    """    if isinstance(formula, Variable):        # Look up the variable's truth value in Universe 'I'        return interpretation[formula.name]        elif isinstance(formula, And):        # Semantic definition of AND: True iff both sub-terms are True        return evaluate(formula.left, interpretation) and evaluate(formula.right, interpretation)        elif isinstance(formula, Not):        # Semantic definition of NOT: Flips the truth value        return not evaluate(formula.child, interpretation)        raise ValueError("Unknown Syntax Node!")# --- DEMO ---# 1. Define Syntax: phi = P AND (NOT Q)phi = And(Variable("P"), Not(Variable("Q")))# 2. Define Universe A: P is True, Q is Falseuniverse_A = ("P" == "P", "Q" == "R") # dict representation belowinterpretation_A = ["P": True, "Q": False]# 3. Define Universe B: P is True, Q is Trueinterpretation_B = ["P": True, "Q": True]# 4. Evaluate Semantics (I ⊨ ϕ)print("Universe A Result:", evaluate(phi, ["P": True, "Q": False])) # Outputs: Trueprint("Universe B Result:", evaluate(phi, ["P": True, "Q": True]))  # Outputs: False

Summary Cheat Sheet

ConceptSymbol / TermWhat it Means
SyntaxParsing RulesThe structural arrangement of symbols without regard to truth.
SemanticsMeaning / MappingAssigning dynamic execution context and truth values to syntax.
InterpretationIIA mapped "Universe" setting atomic variables to ⊤\top or ⊥\bot.
SatisfactionI⊨ϕI \models \phiUniverse II makes formula ϕ\phi evaluate to True.
Validity⊨ϕ\models \phiFormula ϕ\phi evaluates to True in all possible universes.
Satisfiability∃I:I⊨ϕ\exists I : I \models \phiFormula ϕ\phi is True in at least one universe.

CheckpointTest Yourself

How does 'Semantics' differ from Syntax?

Lesson Milestone

Finished Reading This Lesson?

Mark this lesson complete. A chapter counts as done once all its lessons are, and that adds to your course progress.

TH

Written by

ThinkWisely Team

Have a Question or Suggestion?

We'd love to hear from you. Drop your thoughts below to help us improve ThinkWisely!