Converts Knights and Knaves puzzles into boolean logic, solves them step-by-step using
equivalence rules, and exports proofs as .bram files importable into
aris.bram-hub.com.
Puzzle source: http://philosophy.hku.hk/think/logic/knights.php — licensed CC BY-SA 4.0 (see LICENSE-DATA.md).
python3 scripts/convert_knights_knaves.py \
--input "data/Knights and Knaves.md" \
--output data/knights_and_knaves_logic.jsonReads the markdown puzzle file and emits a JSON file where each puzzle has:
people: list of inhabitantsutterances: each speaker's statement as a boolean formulaconstraints:knight(speaker) ↔ statementfor each utterance
python3 scripts/solve_knights_knaves.py \
--input data/knights_and_knaves_logic.json \
--output data/knights_and_knaves_solutions.jsonFor each puzzle, reduces the conjunction of constraints to DNF using boolean algebra equivalence rules, recording every transformation step. Each step in the output has:
rule: the equivalence rule appliedformula: the formula after applying the ruledescription: plain-English explanation
python3 scripts/export_bram_proof.py <puzzle_number>Writes data/bram/puzzle_<N>.bram. Options:
--input PATH— solutions JSON (default:data/knights_and_knaves_solutions.json)--output PATH— output.bramfile--author NAME— author field in metadata (default:mikehalpern)
Example:
python3 scripts/export_bram_proof.py 1
# Wrote data/bram/puzzle_1.bram
# Symbol map: Zoey->A, Mel->B
# Goal: (A ∧ ¬B)- Open aris.bram-hub.com
- Use File → Open and select a
.bramfile fromdata/bram/ - The proof loads with all equivalence steps and the goal highlighted
| Symbol | Meaning |
|---|---|
A, B, C, … |
Person variables (A = first person listed, B = second, …) |
¬ |
NOT (negation) |
∧ |
AND (conjunction) |
∨ |
OR (disjunction) |
↔ |
Biconditional (if and only if) |
⊤ |
True (tautology) |
⊥ |
False (contradiction) |
The solver uses 14 boolean algebra equivalence rules:
| Rule | Law |
|---|---|
BICONDITIONAL_EQUIVALENCE |
A ↔ B = (A ∧ B) ∨ (¬A ∧ ¬B) |
DOUBLENEGATION_EQUIV |
¬¬A = A |
DE_MORGAN |
¬(A ∧ B) = ¬A ∨ ¬B; ¬(A ∨ B) = ¬A ∧ ¬B |
DISTRIBUTION |
A ∧ (B ∨ C) = (A ∧ B) ∨ (A ∧ C) |
COMMUTATION |
A ∧ B = B ∧ A; A ∨ B = B ∨ A |
ASSOCIATION |
(A ∧ B) ∧ C = A ∧ (B ∧ C) |
COMPLEMENT |
A ∧ ¬A = ⊥; A ∨ ¬A = ⊤ |
IDENTITY |
A ∧ ⊤ = A; A ∨ ⊥ = A |
ANNIHILATION |
A ∧ ⊥ = ⊥; A ∨ ⊤ = ⊤ |
INVERSE |
¬⊤ = ⊥; ¬⊥ = ⊤ |
IDEMPOTENCE |
A ∧ A = A; A ∨ A = A |
ABSORPTION |
A ∨ (A ∧ B) = A |
REDUCTION |
A ∧ (¬A ∨ B) = A ∧ B |
ADJACENCY |
(A ∧ B) ∨ (A ∧ ¬B) = A |
python3 -m pytest tests/ -v# Display parsed logic formulas for a puzzle
python3 scripts/render_logic_formulas.py --puzzle-id 1
# View a solved puzzle's result and proof steps
python3 scripts/view_puzzle_solution.py 1 --steps