Files
bikoret/talmudic_engine/src/reasoning/challenge.pl
T
Scott KarpandClaude Opus 4.6 37390bcb8b Phase 3: Intelligence — 613 mitzvot, 13 middot, Tzara'at diagnostic
Encode all 613 mitzvot from Rambam's Sefer HaMitzvot (248 positive,
365 prohibitions). Build the 13 Middot of Rabbi Yishmael as Prolog
inference predicates for hermeneutical reasoning. Implement Tzara'at
multi-stage input validation following Vayikra 13-14. Enhance kushya
generation with kal vachomer and shnei ketuvim challenge strategies.

Architecture §4 Steps 14-15, 19-20.

New files:
  middot/   — 8 files (master + 7 rule modules)
  diagnostic/ — 4 files (tzaraat, inspection, quarantine, diagnosis)

Modified:
  mitzvot.pl     — 52 → 613 mitzvot
  relationships.pl — expanded tensions, complements, action domains
  challenge.pl   — middot-based kushya (kal vachomer, shnei ketuvim)

Tests: 293 total (184 Prolog, 76 Elixir, 33 Haskell), 0 failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 16:18:58 -04:00

131 lines
5.4 KiB
Prolog

%% challenge.pl — Kushya generation.
%%
%% Architecture §3.4:
%% challenge(Interpretation, Challenge) :-
%% mitzvah(_, _, _, _) = Contradicting,
%% contradicts(Interpretation, Contradicting),
%% Challenge = kushya(Contradicting, Interpretation).
%%
%% A kushya is a challenge grounded in Torah text.
%% It identifies a tension between the proposed interpretation
%% and another part of the specification.
%%
%% The challenge is a question, not a refutation.
%% It says: "But what about THIS verse/mitzvah?"
:- module(challenge, [
challenge/2,
find_contradiction/3,
contradicts/2,
challenge_strength/2
]).
:- use_module('../specification/mitzvot').
:- use_module('../specification/torah_text').
:- use_module('../specification/relationships').
:- use_module('../specification/root_meanings').
:- use_module('../middot/kal_vachomer').
:- use_module('../middot/shnei_ketuvim').
%% ============================================================
%% CHALLENGE GENERATION
%% ============================================================
%% Generate a challenge to an interpretation.
%% A challenge consists of:
%% kushya(Contradicting, Interpretation, Strength)
%% - Contradicting: the mitzvah or verse that creates tension
%% - Interpretation: the interpretation being challenged
%% - Strength: strong | moderate | weak
challenge(interpretation(CaseRef, Mitzvot, Verses, _Reading, _Confidence), Challenge) :-
find_contradiction(Mitzvot, Verses, Contradicting),
challenge_strength(Contradicting, Strength),
Challenge = kushya(Contradicting, CaseRef, Strength).
%% ============================================================
%% FIND CONTRADICTIONS
%% ============================================================
%% Strategy 1: Find a mitzvah that conflicts with one in the interpretation
find_contradiction(Mitzvot, _Verses, contradiction(mitzvah_tension, ID1, ID2, Desc)) :-
member(mitzvah(ID1, _, _, _), Mitzvot),
mitzvah_conflicts_with(ID1, ID2, Desc).
%% Strategy 2: Find a verse with a root in a conflicting domain
find_contradiction(_Mitzvot, Verses, contradiction(domain_tension, Root, Domain1, Domain2)) :-
member(verse_ref(Book, Ch, Vs, _), Verses),
verse(Book, Ch, Vs, VerseRoots, _),
member(Root, VerseRoots),
root_domain(Root, Domain1),
root_domain(OtherRoot, Domain2),
Domain1 \= Domain2,
domains_in_tension(Domain1, Domain2),
member(OtherRoot, VerseRoots).
%% Strategy 3: Find a mitzvah whose condition conflicts with the case context
find_contradiction(Mitzvot, _Verses, contradiction(condition_tension, ID, Action, Cond)) :-
member(mitzvah(ID, _, Action, when(Cond)), Mitzvot),
condition_creates_tension(Cond).
%% Strategy 4: Kal vachomer — if a law applies in the minor case,
%% challenge interpretations that don't account for the major case
find_contradiction(Mitzvot, _Verses, contradiction(kal_vachomer_tension, MinorDomain, MajorDomain, Law)) :-
member(mitzvah(_, _, Law, _), Mitzvot),
mitzvah_domain_for_action(Law, MinorDomain),
is_more_stringent(MinorDomain, MajorDomain).
%% Strategy 5: Shnei ketuvim — two verses in the interpretation's
%% grounding contradict each other and no resolution is offered
find_contradiction(_Mitzvot, Verses, contradiction(shnei_ketuvim_tension, Ref1, Ref2, Tension)) :-
member(verse_ref(B1, C1, Vs1, _), Verses),
member(verse_ref(B2, C2, Vs2, _), Verses),
Ref1 = ref(B1,C1,Vs1),
Ref2 = ref(B2,C2,Vs2),
Ref1 \= Ref2,
verses_contradict(Ref1, Ref2, Tension).
%% ============================================================
%% TENSION DETECTION
%% ============================================================
%% contradicts/2 — does a source contradict an interpretation?
%% This is the core logic: given an interpretation's grounding,
%% does some other part of Torah create a tension?
contradicts(interpretation(_, Mitzvot, _, _, _), Source) :-
find_contradiction(Mitzvot, [], Source).
%% Domains that are inherently in tension
domains_in_tension(judgment, mercy).
domains_in_tension(mercy, judgment).
domains_in_tension(holiness, transgression).
domains_in_tension(transgression, holiness).
domains_in_tension(death, life).
domains_in_tension(life, death).
domains_in_tension(authority, service).
domains_in_tension(service, authority).
%% Conditions that create tension (they limit universality)
condition_creates_tension(seventh_day). % Shabbat limits action
condition_creates_tension(capital_case). % Higher standard of evidence
condition_creates_tension(pursuit_in_progress). % Time pressure
condition_creates_tension(court_deliberation). % Procedural constraints
%% ============================================================
%% CHALLENGE STRENGTH
%% ============================================================
%% Assess how strong a challenge is
challenge_strength(contradiction(mitzvah_tension, _, _, _), strong).
challenge_strength(contradiction(domain_tension, _, _, _), moderate).
challenge_strength(contradiction(condition_tension, _, _, _), weak).
challenge_strength(contradiction(kal_vachomer_tension, _, _, _), strong).
challenge_strength(contradiction(shnei_ketuvim_tension, _, _, _), strong).
%% ============================================================
%% HELPERS
%% ============================================================
%% Map a mitzvah action to its domain (via relationships module)
mitzvah_domain_for_action(Action, Domain) :-
action_domain(Action, Domain).