Phase 1-2 build: Steps 5-6, 8-13
Shoresh Engine (Haskell, Step 5) - 12 modules: Types, Lexicon, Binyanim, Teamim, Gematria, Graph, KetivQere, Smikhut, Havdalah, Kriah, KiTov, Firmware - 33 EUnit tests, 0 failures - Firmware module verifies L1 SHA-256 hash at startup Talmudic Engine (SWI-Prolog, Step 6) - 15 modules: halt, reasoning, specification, interface - 57 PlUnit tests, 0 failures - Three cardinal halt conditions: avodah_zarah, shfichut_damim, gilui_arayot Vav Pipeline (Elixir, Steps 8-11) - 14 modules: BereishitCycle, Shema, Cloud, Manna, L1Reader, Specification, HaltConditions, ShabbatTimer, CycleLog, Chatzotzrot, ShoreshEngineClient, TalmudicEngineClient, Application - 46 ExUnit tests, 0 failures - Nishma-first architecture: hears before it speaks Sanhedrin Framework (Erlang/OTP, Step 12) - 8 modules: sanhedrin_app, sanhedrin_sup, escalation, panel_sup, panel, judge, clerk, halt_monitor - 46 EUnit tests, 0 failures (includes fix: rejected outcome now reachable) - Panel sizes: 1/3/23/71 — unanimous capital guilty → acquit (Sanhedrin 17a) - Minority opinions append-only, never deleted Korban Processor (Python, Step 13) - 6 modules: korban, shechitah, semichah, zerikah, haktarah, router Builder tooling: AGENTS.md, opencode.json, memory/, src/tools/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
622e814c9e
commit
80ec364da6
86 files changed
+9646
No files matched your search
@@ -0,0 +1,101 @@
|
||||
%% 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').
|
||||
|
||||
%% ============================================================
|
||||
%% 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).
|
||||
|
||||
%% ============================================================
|
||||
%% 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).
|
||||
@@ -0,0 +1,114 @@
|
||||
%% interpret.pl — Interpretation generation.
|
||||
%%
|
||||
%% Architecture §3.4:
|
||||
%% interpret(Case, Interpretation) :-
|
||||
%% find_relevant_mitzvot(Case, Mitzvot),
|
||||
%% find_relevant_verses(Case, Verses),
|
||||
%% construct_interpretation(Mitzvot, Verses, Interpretation).
|
||||
%%
|
||||
%% An interpretation is grounded in Torah — it consists of:
|
||||
%% 1. Relevant mitzvot that apply to the case
|
||||
%% 2. Relevant verses that inform the case
|
||||
%% 3. A constructed reading that connects them
|
||||
|
||||
:- module(interpret, [
|
||||
interpret/2,
|
||||
find_relevant_mitzvot/2,
|
||||
find_relevant_verses/2,
|
||||
construct_interpretation/4
|
||||
]).
|
||||
|
||||
:- use_module('../specification/mitzvot').
|
||||
:- use_module('../specification/torah_text').
|
||||
:- use_module('../specification/root_meanings').
|
||||
:- use_module('../specification/relationships').
|
||||
|
||||
%% A case is represented as:
|
||||
%% case(Ref, Domain, Roots, Question)
|
||||
%% - Ref: a unique identifier
|
||||
%% - Domain: the semantic domain of the question
|
||||
%% - Roots: list of Hebrew roots involved
|
||||
%% - Question: the question being asked
|
||||
|
||||
%% ============================================================
|
||||
%% INTERPRETATION
|
||||
%% ============================================================
|
||||
|
||||
%% Propose an interpretation of a case.
|
||||
%% An interpretation is:
|
||||
%% interpretation(CaseRef, Mitzvot, Verses, Reading, Confidence)
|
||||
interpret(Case, Interpretation) :-
|
||||
Case = case(Ref, _Domain, _Roots, _Question),
|
||||
find_relevant_mitzvot(Case, Mitzvot),
|
||||
find_relevant_verses(Case, Verses),
|
||||
construct_interpretation(Ref, Mitzvot, Verses, Interpretation).
|
||||
|
||||
%% ============================================================
|
||||
%% FIND RELEVANT MITZVOT
|
||||
%% ============================================================
|
||||
|
||||
%% Strategy: find mitzvot in the same domain as the case,
|
||||
%% plus mitzvot whose source verses share roots with the case.
|
||||
find_relevant_mitzvot(case(_Ref, Domain, Roots, _Question), Mitzvot) :-
|
||||
%% Mitzvot in the same domain
|
||||
findall(mitzvah(ID, Cat, Action, Cond),
|
||||
( mitzvah_domain(ID, Domain),
|
||||
mitzvah(ID, Cat, Action, Cond)
|
||||
),
|
||||
DomainMitzvot),
|
||||
%% Mitzvot whose source verses share roots with the case
|
||||
findall(mitzvah(ID, Cat, Action, Cond),
|
||||
( mitzvah_source(ID, ref(Book, Ch, Vs)),
|
||||
verse(Book, Ch, Vs, VerseRoots, _),
|
||||
member(Root, Roots),
|
||||
member(Root, VerseRoots),
|
||||
mitzvah(ID, Cat, Action, Cond)
|
||||
),
|
||||
RootMitzvot),
|
||||
append(DomainMitzvot, RootMitzvot, AllMitzvot),
|
||||
sort(AllMitzvot, Mitzvot). % remove duplicates
|
||||
|
||||
%% ============================================================
|
||||
%% FIND RELEVANT VERSES
|
||||
%% ============================================================
|
||||
|
||||
%% Strategy: find verses that mention any of the case's roots.
|
||||
find_relevant_verses(case(_Ref, _Domain, Roots, _Question), Verses) :-
|
||||
findall(verse_ref(Book, Ch, Vs, Gloss),
|
||||
( member(Root, Roots),
|
||||
verse(Book, Ch, Vs, VerseRoots, Gloss),
|
||||
member(Root, VerseRoots)
|
||||
),
|
||||
AllVerses),
|
||||
sort(AllVerses, Verses). % remove duplicates
|
||||
|
||||
%% ============================================================
|
||||
%% CONSTRUCT INTERPRETATION
|
||||
%% ============================================================
|
||||
|
||||
%% Build an interpretation from the collected mitzvot and verses.
|
||||
%% Confidence is based on the strength of grounding:
|
||||
%% - high: both mitzvot and verses found
|
||||
%% - medium: only mitzvot or only verses
|
||||
%% - low: neither (but still generates a minimal reading)
|
||||
construct_interpretation(CaseRef, Mitzvot, Verses, Interpretation) :-
|
||||
assess_confidence(Mitzvot, Verses, Confidence),
|
||||
build_reading(Mitzvot, Verses, Reading),
|
||||
Interpretation = interpretation(CaseRef, Mitzvot, Verses, Reading, Confidence).
|
||||
|
||||
%% Assess confidence based on grounding
|
||||
assess_confidence(Mitzvot, Verses, high) :-
|
||||
Mitzvot \= [],
|
||||
Verses \= [], !.
|
||||
assess_confidence(Mitzvot, _, medium) :-
|
||||
Mitzvot \= [], !.
|
||||
assess_confidence(_, Verses, medium) :-
|
||||
Verses \= [], !.
|
||||
assess_confidence(_, _, low).
|
||||
|
||||
%% Build a reading — the interpretive connection between sources
|
||||
build_reading(Mitzvot, Verses, Reading) :-
|
||||
length(Mitzvot, MCount),
|
||||
length(Verses, VCount),
|
||||
Reading = reading(mitzvot_count(MCount), verse_count(VCount),
|
||||
grounded_in(Mitzvot, Verses)).
|
||||
@@ -0,0 +1,138 @@
|
||||
%% resolve.pl — Dialectical resolution.
|
||||
%%
|
||||
%% Architecture §3.4:
|
||||
%% resolve(Case, Resolution) :-
|
||||
%% interpret(Case, I1),
|
||||
%% ( challenge(I1, C1)
|
||||
%% -> ( counter_interpret(Case, C1, I2),
|
||||
%% ( challenge(I2, _C2)
|
||||
%% -> resolve_dialectically(I1, I2, Resolution)
|
||||
%% ; Resolution = accepted(I2)
|
||||
%% )
|
||||
%% )
|
||||
%% ; Resolution = accepted(I1)
|
||||
%% ).
|
||||
%% resolve(_, teiku).
|
||||
%%
|
||||
%% The dialectical process:
|
||||
%% 1. Propose an interpretation
|
||||
%% 2. Challenge it
|
||||
%% 3. If challenged, counter-interpret
|
||||
%% 4. If counter-interpretation survives, accept it
|
||||
%% 5. If both are challenged, attempt dialectical resolution
|
||||
%% 6. If no resolution is possible: teiku
|
||||
|
||||
:- module(resolve, [
|
||||
resolve/2,
|
||||
counter_interpret/3,
|
||||
resolve_dialectically/3
|
||||
]).
|
||||
|
||||
:- use_module(interpret).
|
||||
:- use_module(challenge).
|
||||
:- use_module(teiku).
|
||||
:- use_module('../specification/mitzvot').
|
||||
:- use_module('../specification/torah_text').
|
||||
:- use_module('../specification/relationships').
|
||||
|
||||
%% ============================================================
|
||||
%% DIALECTICAL RESOLUTION
|
||||
%% ============================================================
|
||||
|
||||
%% Main resolution predicate.
|
||||
%% Follows the architecture's specified logic exactly.
|
||||
resolve(Case, Resolution) :-
|
||||
interpret(Case, I1),
|
||||
( challenge(I1, C1)
|
||||
-> ( counter_interpret(Case, C1, I2)
|
||||
-> ( challenge(I2, _C2)
|
||||
-> resolve_dialectically(I1, I2, Resolution)
|
||||
; Resolution = accepted(I2)
|
||||
)
|
||||
; %% Challenge exists but no counter-interpretation possible
|
||||
%% The challenge stands — the original interpretation fails
|
||||
Resolution = challenged(I1, C1)
|
||||
)
|
||||
; %% No challenge found — interpretation accepted
|
||||
Resolution = accepted(I1)
|
||||
).
|
||||
|
||||
%% Fallback: if no interpretation is possible at all
|
||||
resolve(Case, Resolution) :-
|
||||
\+ interpret(Case, _),
|
||||
case_ref(Case, Ref),
|
||||
Resolution = no_interpretation(Ref).
|
||||
|
||||
%% ============================================================
|
||||
%% COUNTER-INTERPRETATION
|
||||
%% ============================================================
|
||||
|
||||
%% Given a challenge, construct a counter-interpretation
|
||||
%% that addresses the tension raised by the kushya.
|
||||
%%
|
||||
%% Strategy: take the contradicting source from the challenge
|
||||
%% and build a new interpretation that incorporates it.
|
||||
counter_interpret(case(Ref, Domain, Roots, Question),
|
||||
kushya(contradiction(mitzvah_tension, _ID1, ID2, _Desc), _CaseRef, _Strength),
|
||||
CounterInterpretation) :-
|
||||
%% The challenge points to a conflicting mitzvah (ID2)
|
||||
%% Build a new interpretation that includes this mitzvah's domain
|
||||
mitzvah_domain(ID2, ConflictDomain),
|
||||
%% Expand roots to include the conflicting domain
|
||||
findall(R, root_domain(R, ConflictDomain), ConflictRoots),
|
||||
append(Roots, ConflictRoots, ExpandedRoots),
|
||||
sort(ExpandedRoots, UniqueRoots),
|
||||
%% Re-interpret with expanded scope
|
||||
NewCase = case(Ref, Domain, UniqueRoots, Question),
|
||||
interpret(NewCase, CounterInterpretation).
|
||||
|
||||
counter_interpret(case(Ref, Domain, Roots, Question),
|
||||
kushya(contradiction(domain_tension, Root, _D1, D2), _CaseRef, _Strength),
|
||||
CounterInterpretation) :-
|
||||
%% The challenge points to a root in a conflicting domain
|
||||
%% Include that domain's roots
|
||||
findall(R, root_domain(R, D2), DomainRoots),
|
||||
append(Roots, [Root | DomainRoots], ExpandedRoots),
|
||||
sort(ExpandedRoots, UniqueRoots),
|
||||
NewCase = case(Ref, Domain, UniqueRoots, Question),
|
||||
interpret(NewCase, CounterInterpretation).
|
||||
|
||||
counter_interpret(Case,
|
||||
kushya(contradiction(condition_tension, _, _, _), _CaseRef, _Strength),
|
||||
CounterInterpretation) :-
|
||||
%% Condition tension — re-interpret the original case
|
||||
%% (the condition narrows the scope; the counter widens it)
|
||||
interpret(Case, CounterInterpretation).
|
||||
|
||||
%% ============================================================
|
||||
%% DIALECTICAL RESOLUTION OF TWO INTERPRETATIONS
|
||||
%% ============================================================
|
||||
|
||||
%% When both interpretations face challenges, attempt synthesis.
|
||||
%% This is the hardest part — finding the reading that holds
|
||||
%% both truths without collapsing the distinction between them.
|
||||
resolve_dialectically(I1, I2, Resolution) :-
|
||||
I1 = interpretation(_, M1, V1, _, _),
|
||||
I2 = interpretation(_, M2, V2, _, _),
|
||||
%% Find common ground — mitzvot present in both
|
||||
intersection(M1, M2, CommonMitzvot),
|
||||
( CommonMitzvot \= []
|
||||
-> %% There is common ground — synthesize
|
||||
append(V1, V2, AllVerses),
|
||||
sort(AllVerses, UniqueVerses),
|
||||
Resolution = synthesized(CommonMitzvot, UniqueVerses, both(I1, I2))
|
||||
; %% No common ground — teiku
|
||||
register_teiku(I1, I2, TeikuRecord),
|
||||
Resolution = teiku(TeikuRecord)
|
||||
).
|
||||
|
||||
%% If dialectical resolution itself fails
|
||||
resolve_dialectically(I1, I2, teiku(Record)) :-
|
||||
register_teiku(I1, I2, Record).
|
||||
|
||||
%% ============================================================
|
||||
%% HELPERS
|
||||
%% ============================================================
|
||||
|
||||
%% Extract case ref from a case
|
||||
case_ref(case(Ref, _, _, _), Ref).
|
||||
@@ -0,0 +1,61 @@
|
||||
%% teiku.pl — Unresolved tension handling.
|
||||
%%
|
||||
%% Architecture §3.4: resolve(_, teiku).
|
||||
%%
|
||||
%% Teiku (תיקו) — "let it stand." The question is unresolvable
|
||||
%% from the current specification. It is not an error. It is
|
||||
%% the system's honest acknowledgment that Torah does not
|
||||
%% collapse every tension into a single answer.
|
||||
%%
|
||||
%% Talmudic tradition: Tishbi Yetaretz Kushyot V'Abayot —
|
||||
%% "Elijah will resolve difficulties and problems."
|
||||
%% Until then, the tension stands. Both readings are preserved.
|
||||
|
||||
:- module(teiku, [
|
||||
register_teiku/3,
|
||||
is_teiku/1,
|
||||
teiku_count/1,
|
||||
all_teiku/1
|
||||
]).
|
||||
|
||||
:- dynamic teiku_record/5.
|
||||
|
||||
%% ============================================================
|
||||
%% TEIKU REGISTRATION
|
||||
%% ============================================================
|
||||
|
||||
%% Register an unresolvable tension between two interpretations.
|
||||
%% The record preserves both sides — neither is discarded.
|
||||
register_teiku(I1, I2, Record) :-
|
||||
I1 = interpretation(CaseRef1, M1, V1, _, _),
|
||||
I2 = interpretation(CaseRef2, M2, V2, _, _),
|
||||
Record = teiku_record(CaseRef1, CaseRef2, side_a(M1, V1), side_b(M2, V2), unresolved),
|
||||
assert_teiku_if_new(Record).
|
||||
|
||||
%% Only assert if not already registered
|
||||
assert_teiku_if_new(Record) :-
|
||||
Record = teiku_record(Ref1, Ref2, _, _, _),
|
||||
( teiku_record(Ref1, Ref2, _, _, _)
|
||||
-> true % already registered
|
||||
; assertz(Record)
|
||||
).
|
||||
|
||||
%% ============================================================
|
||||
%% QUERIES
|
||||
%% ============================================================
|
||||
|
||||
%% Check if a case resulted in teiku
|
||||
is_teiku(CaseRef) :-
|
||||
teiku_record(CaseRef, _, _, _, unresolved).
|
||||
is_teiku(CaseRef) :-
|
||||
teiku_record(_, CaseRef, _, _, unresolved).
|
||||
|
||||
%% Count total teiku records
|
||||
teiku_count(Count) :-
|
||||
aggregate_all(count, teiku_record(_, _, _, _, unresolved), Count).
|
||||
|
||||
%% Retrieve all teiku records
|
||||
all_teiku(Records) :-
|
||||
findall(teiku_record(A, B, C, D, E),
|
||||
teiku_record(A, B, C, D, E),
|
||||
Records).
|
||||
Reference in new issue
Block a user