Daily Rambam · Techie Talmid · Standard

Mishneh Torah, Mourning 2

StandardTechie TalmidJanuary 9, 2026

Hoo boy, buckle up, fellow data-miners of Torah! We're diving deep into the Mishneh Torah, specifically Hilchot Aveilut (Laws of Mourning), chapter 2. This isn't just about who you mourn for; it's about the intricate logic gates and conditional statements that govern our relationships and responsibilities. Think of it as debugging the human condition, one kinsman at a time! We’re going from intermediate to expert, so grab your IDEs and let’s get coding!

Problem Statement: The "Bug Report" in the Sugya

Our core "bug report" in this section of Mishneh Torah, Aveilut 2, is: Defining the precise set of relationships that trigger the obligation of mourning (aveilut) and the related obligation of a priest to contract ritual impurity (tumah) for a deceased relative.

This seems straightforward, like a simple if-then statement. If relative_type == 'parent' then mourn = True. But as we'll see, the system is far more complex, with nested conditions, inheritance (not in the programming sense, but the familial one!), and even "permissions" that can override default behaviors. The "bugs" emerge when we try to implement this with a naive algorithm. We might incorrectly classify a relationship, miss an edge case, or apply a rule in the wrong context.

The system needs to handle:

  1. Core Relationship Mapping: Identifying the primary familial ties that mandate mourning by Torah law (d'Oraita) and Rabbinic law (d'Rabbanan).
  2. Status Modifiers: How factors like marriage status (for sisters), lineage (for priests), or even conversion can alter these obligations.
  3. Contextual Rendering: The obligation to mourn with another mourner in their presence, and how this differs for various relationships.
  4. Priestly Specifics: The unique rules for Kohanim (priests) regarding ritual impurity, which are directly tied to mourning obligations but introduce a separate, albeit related, set of conditions. This is like a separate module with its own API, interacting with the core mourning module.

The challenge is that the mourn variable isn't a simple boolean. It has nuances: mourn_level (d'Oraita vs. d'Rabbanan), mourn_context (in presence vs. out of presence), and for priests, tumah_obligation (yes/no, and under what conditions). We need a robust data structure and a well-defined algorithm to navigate these dependencies.

Text Snapshot

Here are the key lines that form the backbone of our system's logic. Think of these as the core functions and data definitions we'll be working with.

  • Mishneh Torah, Aveilut 2:1:1 "These are the relatives for whom a person is obligated to mourn according to Scriptural Law: His mother, his father, his son, his daughter, his paternal brother and paternal sister."
    • define_mourning_obligation(relative, law_source='d'Oraita')
    • input: relative_type
    • output: True if obligated by law_source
  • Mishneh Torah, Aveilut 2:1:1 "According to Rabbinic Law, a man should also mourn for his wife if she dies while they are married."
    • if law_source == 'd'Rabbanan' and relative_type == 'wife' and status == 'married': return True
  • Mishneh Torah, Aveilut 2:1:1 "And a woman should mourn for her husband."
    • if relative_type == 'husband': return True (This seems to be implicitly d'Oraita or a very strong d'Rabbanan, often treated as primary).
  • Mishneh Torah, Aveilut 2:1:1 "Similarly, a person should mourn for a maternal brother and sister."
    • if relative_type == 'maternal_sibling': return True (Note: This is Rabbinic, as implied by contrast with paternal siblings listed as d'Oraita).
  • Mishneh Torah, Aveilut 2:1:2 "Even a priest who does not become impure for his maternal brother and sister or for his paternal sister who is married, mourns for them."
    • This highlights a separation: mourning obligation vs. priestly impurity obligation.
    • priest_tumah_exception(relative, relative_status)
  • Mishneh Torah, Aveilut 2:1:2 "For his married paternal sister who is married, he is required to mourn by Scriptural Law."
    • if relative_type == 'paternal_sister' and status == 'married' and person_type == 'priest': mourning_obligation = 'd'Oraita'
  • Mishneh Torah, Aveilut 2:1:3 "A person who has a son or a brother born by a maid-servant or a gentile woman should not mourn for them at all."
    • if relative_type in ['son', 'brother'] and parentage == 'non_jewish_or_slave': mourning_obligation = False
  • Mishneh Torah, Aveilut 2:2:1 "Whenever a person is obligated to mourn for a relative, he also mourns with that relative in his presence according to Rabbinical Law."
    • def mourn_together(mourner_A, mourner_B, deceased_relative):
    • if mourning_obligation(mourner_A, deceased_relative):
    • if relative_to_mourner_A(mourner_B) == deceased_relative or relative_to_mourner_A(deceased_relative) == mourner_B:
    • return True # Rabbinic
  • Mishneh Torah, Aveilut 2:2:2 "If a person's grandson, his son's maternal brother, or son's mother dies, he is obligated to rend his garments in the presence of his son and follow the mourning rites while in his presence. Outside his presence, he is not obligated."
    • This is a crucial conditional logic for mourn_together.
    • if mourner_B == 'son' and deceased_relative in ['grandson', 'son's_maternal_brother', 'son's_mother']: mourn_together = True (in presence only)
  • Mishneh Torah, Aveilut 2:3:1 "With regard to a wife with whom one is married: Although one must mourn for her, he does not mourn together with her for her other relatives with the exception of her father and her mother."
    • if mourning_obligation(self, wife) and relative_type_for_wife in ['father', 'mother']: mourn_together(self, wife, relative_type_for_wife) # in presence
  • Mishneh Torah, Aveilut 2:3:2 "When a man's father-in-law or mother-in-law dies, he overturns his bed and observes the mourning rites together with his wife within her presence, but not outside her presence."
    • if deceased_relative in ['father_in_law', 'mother_in_law']:
    • mourn_together(self, wife, deceased_relative) # in presence only
  • Mishneh Torah, Aveilut 2:4:1 "Similarly, it appears to me that if the wife of a person's relative dies or the husband of one of his relatives, e.g., the wife of one's son or the husband of one's daughter, one need not observe mourning rites for them."
    • mourning_obligation(self, spouse_of_relative) = False
  • Mishneh Torah, Aveilut 2:6:1 "To whom does the above apply? To males who are commanded against contracting ritual impurity. Different rules apply to female members of the priestly family."
    • if person_type == 'priestess': tumah_obligation = False
  • Mishneh Torah, Aveilut 2:6:2 "A priest is forced to contract ritual impurity to tend to his deceased wife. This obligation is Rabbinic in origin."
    • if person_type == 'priest' and deceased_relative == 'wife': tumah_obligation = True ('d'Rabbanan')
  • Mishneh Torah, Aveilut 2:8:1 "A priest may, however, become impure for the sake of his mother, even though she is a challalah and he may become impure for the sake of his son, his daughter, his brother and his sister even though they are of tarnished lineage. Even if they are illegitimate, he should become impure for their sake."
    • if person_type == 'priest' and relative_type in ['mother', 'son', 'daughter', 'brother', 'sister'] and relative_lineage == 'tarnished'/'illegitimate': tumah_obligation = True ('d'Oraita'/'d'Rabbanan' depending on specific lineage flaw)
  • Mishneh Torah, Aveilut 2:10:1 "When a priest's sister is married - even to another priest, he does not become impure for her sake, "as Leviticus 21:3 states: "his virgin sister who is close to him who has not been with a man." "
    • if person_type == 'priest' and deceased_relative == 'paternal_sister' and relative_status == 'married': tumah_obligation = False
  • Mishneh Torah, Aveilut 2:11:1 "A priest does not become impure for the sake of relatives whose family connection is doubtful..."
    • if person_type == 'priest' and relative_connection_certainty == 'doubtful': tumah_obligation = False

Flow Model: The Decision Tree of Mourning

Let's map out the core logic of mourning obligation as a decision tree. Each node represents a condition, and branches represent outcomes.

  • Root Node: Is Mourning Obligatory?

    • Condition 1: Is the deceased a primary relative (Parent, Child, Paternal Sibling)?

      • YES: Mourning = d'Oraita (Scriptural Law)
        • Check for exceptions:
          • Is it a son/brother born of a non-Jewish or slave woman?
            • YES: Mourning = False
            • NO: Proceed to Mourning = d'Oraita
          • Is it a paternal sister?
            • YES:
              • Is she married?
                • YES: Mourning = d'Oraita (even for priest)
                • NO: Mourning = d'Oraita
            • NO: Proceed to Mourning = d'Oraita
      • NO: Proceed to Condition 2.
    • Condition 2: Is the deceased a secondary relative (Spouse, Maternal Sibling)?

      • YES:
        • Is it a wife?
          • YES:
            • Is she married to the mourner?
              • YES: Mourning = d'Rabbanan (Rabbinic Law)
              • NO (e.g., betrothed but not married): Mourning = False
          • NO: (This branch likely covers husband and maternal siblings)
            • Is it a husband?
              • YES: Mourning = d'Oraita (or treated as such)
              • NO: (Implies maternal siblings)
                • Is it a maternal sibling?
                  • YES: Mourning = d'Rabbanan
                  • NO: Mourning = False
      • NO: Proceed to Condition 3.
    • Condition 3: Is the deceased a relative-in-law or spouse of a relative?

      • YES:
        • Is it father/mother-in-law?
          • YES: Mourning = d'Rabbanan (specifically for the mourn_together aspect, and indirectly for actual mourning).
          • NO: (Implies spouse of relative, or other in-laws)
            • Is it wife of son / husband of daughter?
              • YES: Mourning = False
              • NO: (Generalization based on 2:4:1) Mourning = False
      • NO: Mourning = False
  • Sub-Process: Is Priest's Tumah Obligation Active? (Triggered if Mourning is potentially active and PersonType == 'Priest')

    • Condition A: Is the deceased a priest's primary relative (Mother, Father, Son, Daughter, Paternal Brother/Sister)?
      • YES:
        • Check for disqualifying lineage/status:
          • Is it a paternal sister?
            • YES:
              • Is she married?
                • YES: Tumah = False
                • NO: Tumah = True
            • NO: (Mother, Father, Son, Daughter, Paternal Brother)
              • Is lineage tarnished/illegitimate?
                • YES: Tumah = True (even if tarnished/illegitimate)
                • NO: Tumah = True
      • NO: (Implies maternal sibling or wife)
        • Is it a wife?
          • YES: Tumah = d'Rabbanan (Rabbinic obligation for an unattended corpse)
          • NO: (Maternal sibling)
            • Is it a maternal sibling?
              • YES: Tumah = False (Based on Lev 21:2-3 focusing on "brother" implying inheritance rights, which maternal siblings don't have in the same way).
              • NO: Tumah = False
  • Sub-Process: Is Mourn Together Obligatory (d'Rabbanan)? (Triggered if Mourning is active for mourner_A for deceased)

    • Condition X: Is mourner_B the primary relative of the deceased (e.g., son of deceased)?

      • YES: Mourn_Together = True (in presence)
        • Exception: If mourner_A is the wife of the deceased's son. Then Mourn_Together = False for general relatives, but True for her parents-in-law (deceased's parents).
      • NO: Proceed to Condition Y.
    • Condition Y: Is the deceased a relative of mourner_B's spouse, and mourner_A is mourning with mourner_B?

      • YES:
        • Is deceased the father/mother of mourner_B's spouse?
          • YES: Mourn_Together = True (in presence only)
        • Is deceased the spouse of mourner_B's child?
          • YES: Mourn_Together = False
        • Is deceased the child of mourner_B's spouse?
          • YES: Mourn_Together = True (in presence only, for the mourner_B's child's sibling or parent)
      • NO: Mourn_Together = False

This tree shows the branching logic, with specific rules for priests and the "mourn together" scenario acting as distinct sub-modules.

Two Implementations: Rishon vs. Acharon as Algorithm A vs. B

Let's contrast how an earlier commentator (Rishon) and a later commentator (Acharon) might structure their understanding of these rules. We'll use pseudo-code to represent their algorithmic approach.

Algorithm A: The Rishon (e.g., Rashi, Rambam in their earlier works, or a composite)

Rishonim often build their logic directly on the Gemara and the explicit text of the Torah, with a focus on clear-cut categories and explicit scriptural derivation. Their algorithms tend to be more procedural, with a strong emphasis on defining base cases and then applying explicit conditional branches.

Assumptions:

  • Focus on explicit Scriptural derivation first, then Rabbinic additions.
  • Clear categorization of relatives.
  • Priestly laws are a significant, but somewhat separate, module.
// Algorithm A: Rishon's Logic - Procedural & Categorical

// Data Structures
enum LawSource { D_ORITA, D_RABBANNAN }
enum RelativeType { PARENT, CHILD, PATERNAL_BROTHER, PATERNAL_SISTER, MATERNAL_BROTHER, MATERNAL_SISTER, WIFE, HUSBAND, FATHER_IN_LAW, MOTHER_IN_LAW, SON_S_WIFE, DAUGHTER_S_HUSBAND, GRANDCHILD, ... }
enum Status { MARRIED, UNMARRIED, BETROTHED, CHILD_OF_SLAVE, CHILD_OF_GENTILE, ILLEGITIMATE, TARNISHED_LINEAGE }
enum PersonType { NORMAL, PRIEST, PRIESTESS }

// Core Function: Determine Mourning Obligation
function GetMourningObligation(person, deceased, person_type = NORMAL):
    mourning_level = LawSource.NONE

    // --- Stage 1: D'Oraita Relatives (Direct & Paternal Siblings) ---
    if deceased.is_parent(person) or deceased.is_child(person):
        mourning_level = LawSource.D_ORITA
    elif deceased.is_paternal_sibling(person):
        mourning_level = LawSource.D_ORITA
        // Exception: Paternal Sister
        if deceased.type == RelativeType.PATERNAL_SISTER:
            if deceased.status == Status.MARRIED:
                mourning_level = LawSource.D_ORITA // Explicitly D'Oraita even if married
            else:
                mourning_level = LawSource.D_ORITA
    
    // --- Stage 2: D'Rabbanan / Special Cases ---
    if mourning_level == LawSource.NONE:
        if person_type == PersonType.NORMAL:
            if deceased.type == RelativeType.WIFE and deceased.status == Status.MARRIED:
                mourning_level = LawSource.D_RABBANNAN
        else: // For Priests, some D'Rabbanan might be treated differently
             if deceased.type == RelativeType.WIFE and deceased.status == Status.MARRIED:
                mourning_level = LawSource.D_RABBANNAN // Mourn, but tumah is separate

        if deceased.type == RelativeType.HUSBAND: // Often treated as primary obligation
            mourning_level = LawSource.D_ORITA // Or very strong D'Rabbanan

        if deceased.type == RelativeType.MATERNAL_BROTHER or deceased.type == RelativeType.MATERNAL_SISTER:
            mourning_level = LawSource.D_RABBANNAN

        if deceased.type == RelativeType.FATHER_IN_LAW or deceased.type == RelativeType.MOTHER_IN_LAW:
            // Mourning *with* spouse is D'Rabbanan, actual mourning for oneself is implied/derived
            // For simplicity here, let's assume direct mourning is also covered under D'Rabbanan if not derived from spouse's obligation.
            // This is where Rishonim might differ in their precise categorization.
            mourning_level = LawSource.D_RABBANNAN // For the context of mourning *with* spouse.

    // --- Stage 3: Absolute Exclusions ---
    if deceased.type in [RelativeType.SON, RelativeType.BROTHER] and deceased.parentage in [Status.CHILD_OF_SLAVE, Status.CHILD_OF_GENTILE]:
        return LawSource.NONE // No mourning at all

    if deceased.type == RelativeType.WIFE and deceased.status == Status.BETROTHED:
        return LawSource.NONE // Not married yet

    if deceased.type in [RelativeType.SON_S_WIFE, RelativeType.DAUGHTER_S_HUSBAND]:
        return LawSource.NONE // Spouse of a relative

    return mourning_level

// Core Function: Determine Priest's Tumah Obligation
function GetPriestTumahObligation(priest, deceased):
    if priest.type != PersonType.PRIEST:
        return False // Not a priest

    // --- Stage 1: D'Oraita Tumah Relatives ---
    if deceased.is_parent(priest) or deceased.is_child(priest):
        // Check lineage exceptions
        if deceased.lineage in [Status.ILLEGITIMATE, Status.TARNISHED_LINEAGE]:
            return True // Priest contracts tumah even for illegitimate/tarnished lineage
        else:
            return True // Standard D'Oraita

    elif deceased.type == RelativeType.PATERNAL_BROTHER:
        if deceased.lineage in [Status.ILLEGITIMATE, Status.TARNISHED_LINEAGE]:
            return True
        else:
            return True

    elif deceased.type == RelativeType.PATERNAL_SISTER:
        if deceased.status == Status.MARRIED:
            return False // Married sister - no tumah
        else:
            return True // Unmarried sister - tumah

    // --- Stage 2: D'Rabbanan Tumah Relatives ---
    elif deceased.type == RelativeType.WIFE and deceased.status == Status.MARRIED:
        return LawSource.D_RABBANNAN // Rabbinic for wife

    // --- Stage 3: Exclusions ---
    elif deceased.type == RelativeType.MATERNAL_BROTHER or deceased.type == RelativeType.MATERNAL_SISTER:
        return False // No tumah for maternal siblings

    // Other relatives (e.g. father-in-law, spouse of relative)
    // The text implies no tumah for these, and the list of D'Oraita relatives is exhaustive.
    // So, if not explicitly listed above, it's False.
    return False

// Function for "Mourning Together"
function GetMournTogetherObligation(mourner_A, mourner_B, deceased):
    // This is always D'Rabbanan, and requires specific conditions
    if GetMourningObligation(mourner_A, deceased) == LawSource.NONE:
        return False // Cannot mourn together if not mourning individually

    // Case 1: Mourning for one's own direct descendant/ancestor/sibling, and the other person is also a direct relative of the deceased.
    // E.g., Grandfather mourns grandson. Son is present. Grandfather mourns *with* son (as son is also mourning).
    if deceased.is_parent(mourner_B) or deceased.is_child(mourner_B) or deceased.is_paternal_sibling(mourner_B):
        return True // If mourner_B is a primary mourner for the same deceased, A mourns with B.

    // Case 2: Mourning for a relative of one's spouse (e.g. father-in-law)
    if deceased.is_parent(mourner_B.spouse) and mourner_A.is_spouse(mourner_B):
        return True // Mourning father/mother-in-law with spouse

    // Case 3: Mourning for one's own child, and the other person is the child's spouse.
    // The text states you don't mourn for the spouse of your son/daughter (2:4:1)
    // So this specific interaction is NOT covered.

    // Case 4: Mourning for one's spouse.
    // Text 2:3:1 - "he does not mourn together with her for her other relatives" EXCEPT parents-in-law.
    if mourner_A.is_spouse(deceased): // This is for the primary mourner A mourning their spouse
        if deceased.is_parent(mourner_B) and mourner_A.is_spouse(mourner_B.spouse): // Mourner A mourning their spouse, mourner B is their spouse's parent. A mourns with B.
             return True // Mourning spouse, and B is spouse's parent.

    // General case from 2:2:2 - "in the presence of his son"
    // This implies that if the person is mourning for someone *below* them in the family tree (grandson, son's brother),
    // and their own son is also mourning, they mourn together.
    if deceased.is_grandchild(mourner_A) or deceased.is_childs_sibling(mourner_A, mourner_B): // Assuming mourner_B is the son
        if mourner_B.is_child(mourner_A): // If B is A's son
            return True // Mourn together in presence

    return False // Default: No obligation

Algorithm B: The Acharon (e.g., Shulchan Aruch, later commentators like Taz, Magen Avraham, Steinsaltz)

Acharonim often refine, synthesize, and add layers of interpretation. Their algorithms might be more object-oriented, with classes representing individuals and relationships, and methods defining behaviors. They might also incorporate more nuanced conditional logic and handle exceptions with more explicit sub-functions.

Assumptions:

  • Integration of Rishonim's views.
  • More structured data representation.
  • Explicit handling of exceptions and sub-conditions.
  • Focus on practical application and potential ambiguities.
// Algorithm B: Acharon's Logic - Object-Oriented & Refined

// --- Data Structures ---
class Person:
    def __init__(self, name, gender, is_priest=False):
        self.name = name
        self.gender = gender
        self.is_priest = is_priest
        self.relationships = {} // {related_person: relationship_type, ...}

class Relationship:
    def __init__(self, type, law_source, status=None, lineage=None, parentage=None):
        self.type = type # e.g., PARENT, CHILD, WIFE, PATERNAL_SISTER_MARRIED
        self.law_source = law_source # D_ORITA, D_RABBANNAN, NONE
        self.status = status # e.g., MARRIED, UNMARRIED, BETROTHED, CHILD_OF_SLAVE, CHILD_OF_GENTILE, ILLEGITIMATE, TARNISHED_LINEAGE
        self.lineage = lineage # e.g., PURE, TARNISHED, ILLEGITIMATE
        self.parentage = parentage # e.g., JEWISH, NON_JEWISH, SLAVE

class MourningSystem:
    def __init__(self):
        self.mourning_rules = {} # {(person_id, deceased_id): Relationship}
        self.priest_tumah_rules = {} # {(priest_id, deceased_id): Relationship}
        self.mourn_together_rules = {} # {(mourner_A_id, mourner_B_id, deceased_id): Boolean}

    // --- Core Method: Determine Mourning Obligation ---
    def get_mourning_obligation(self, person: Person, deceased: Person):
        relationship = self._get_relationship(person, deceased)
        if not relationship:
            return Relationship(type="UNKNOWN", law_source="NONE")

        // --- Rule Application ---
        // 1. Absolute Exclusions first
        if relationship.type in [Relationship.CHILD_OF_SLAVE_SON, Relationship.CHILD_OF_GENTILE_SON,
                                 Relationship.CHILD_OF_SLAVE_BROTHER, Relationship.CHILD_OF_GENTILE_BROTHER]:
            return Relationship(type=relationship.type, law_source="NONE")
        if relationship.type == Relationship.BETROTHED_WIFE:
            return Relationship(type=relationship.type, law_source="NONE")
        if relationship.type in [Relationship.SON_S_WIFE, Relationship.DAUGHTER_S_HUSBAND]:
            return Relationship(type=relationship.type, law_source="NONE")

        // 2. D'Oraita Base Cases
        if relationship.type in [Relationship.PARENT, Relationship.CHILD]:
            return relationship // Inherits D'Oraita status

        if relationship.type == Relationship.PATERNAL_BROTHER:
            return relationship // Inherits D'Oraita status

        if relationship.type == Relationship.PATERNAL_SISTER:
            // Married status is key here, but D'Oraita obligation remains
            return Relationship(type=relationship.type, law_source="D_ORITA", status=relationship.status)

        // 3. D'Rabbanan & Specific Derivations
        if relationship.type == Relationship.HUSBAND: // Typically treated as D'Oraita or near-equivalent
             return Relationship(type=relationship.type, law_source="D_ORITA")

        if relationship.type == Relationship.WIFE and relationship.status == Relationship.MARRIED:
            return Relationship(type=relationship.type, law_source="D_RABBANNAN")

        if relationship.type in [Relationship.MATERNAL_BROTHER, Relationship.MATERNAL_SISTER]:
            return Relationship(type=relationship.type, law_source="D_RABBANNAN")

        if relationship.type in [Relationship.FATHER_IN_LAW, Relationship.MOTHER_IN_LAW]:
            // The primary obligation here is for the 'mourn together' aspect.
            // We can represent this as a specific type of obligation or a flag.
            // For direct mourning, it's often derived from the spouse's obligation.
            // Let's assume direct mourning is D'Rabbanan if not a primary relative.
            return Relationship(type=relationship.type, law_source="D_RABBANNAN")

        // Default if no rule found
        return Relationship(type="UNKNOWN", law_source="NONE")

    // --- Method: Priest's Tumah Obligation ---
    def get_priest_tumah_obligation(self, priest: Person, deceased: Person):
        if not priest.is_priest:
            return Relationship(type="NOT_PRIEST", law_source="NONE")

        relationship = self._get_relationship(priest, deceased)
        if not relationship:
            return Relationship(type="UNKNOWN", law_source="NONE")

        // 1. D'Oraita Tumah Relatives
        if relationship.type in [Relationship.PARENT, Relationship.CHILD]:
            // Check lineage exceptions
            if relationship.lineage in [Relationship.ILLEGITIMATE, Relationship.TARNISHED_LINEAGE]:
                return Relationship(type=relationship.type, law_source="D_ORITA", lineage=relationship.lineage)
            else:
                return Relationship(type=relationship.type, law_source="D_ORITA")

        if relationship.type == Relationship.PATERNAL_BROTHER:
            if relationship.lineage in [Relationship.ILLEGITIMATE, Relationship.TARNISHED_LINEAGE]:
                return Relationship(type=relationship.type, law_source="D_ORITA", lineage=relationship.lineage)
            else:
                return Relationship(type=relationship.type, law_source="D_ORITA")

        if relationship.type == Relationship.PATERNAL_SISTER:
            if relationship.status == Relationship.MARRIED:
                return Relationship(type=relationship.type, law_source="NONE", status=relationship.status)
            else:
                return Relationship(type=relationship.type, law_source="D_ORITA", status=relationship.status)

        // 2. D'Rabbanan Tumah Relatives
        if relationship.type == Relationship.WIFE and relationship.status == Relationship.MARRIED:
            return Relationship(type=relationship.type, law_source="D_RABBANNAN", status=relationship.status)

        // 3. Exclusions
        if relationship.type in [Relationship.MATERNAL_BROTHER, Relationship.MATERNAL_SISTER]:
            return Relationship(type=relationship.type, law_source="NONE")

        // Explicitly stated negative implications from Lev 21:2-3 text analysis
        if relationship.type in [Relationship.SON_S_WIFE, Relationship.DAUGHTER_S_HUSBAND]:
            return Relationship(type=relationship.type, law_source="NONE")

        return Relationship(type="UNKNOWN", law_source="NONE")

    // --- Method: Mourning Together (D'Rabbanan) ---
    def get_mourn_together_obligation(self, mourner_A: Person, mourner_B: Person, deceased: Person):
        // Check if A is obligated to mourn deceased individually first
        mourning_A_status = self.get_mourning_obligation(mourner_A, deceased)
        if mourning_A_status.law_source == "NONE":
            return False

        // Check if B is a primary mourner for the same deceased (condition for A mourning *with* B)
        mourning_B_status = self.get_mourning_obligation(mourner_B, deceased)
        if mourning_B_status.law_source == "NONE":
            return False // B is not a mourner for this deceased

        // Case 1: Mourning for direct descendants/siblings where B is also a direct mourner
        // E.g., Grandparent (A) mourns Grandchild (D). Son (B) also mourns Grandchild (D).
        // A mourns with B in B's presence.
        if deceased.is_child(mourner_B) or deceased.is_grandchild(mourner_A) or deceased.is_childs_sibling(mourner_A, mourner_B):
             if mourner_B.is_child(mourner_A): // If B is A's child
                 return True

        // Case 2: Mourning for parents-in-law, with spouse
        // Man (A) mourns father-in-law (D). His wife (B) is also mourning D. A mourns with B.
        if deceased.is_parent(mourner_B.spouse) and mourner_A.is_spouse(mourner_B):
            return True

        // Case 3: Wife mourning her husband (deceased D). She does NOT mourn with him for *his* other relatives, EXCEPT his parents.
        if mourner_A.is_spouse(deceased):
            if deceased.is_parent(mourner_B) and mourner_A.is_spouse(mourner_B.spouse): # A is wife, B is her husband, D is B's parent. A mourns D with B.
                return True

        // Case 4: Grandson, son's maternal brother, son's mother dying. Grandparent mourns in son's presence.
        // This is about A mourning for X, and B (A's son) is present.
        if deceased.type in [Relationship.GRANDCHILD, Relationship.SONS_MATERNAL_BROTHER, Relationship.SONS_MOTHER]:
            if mourner_B.is_child(mourner_A): # If mourner_B is mourner_A's son
                return True

        return False // Default

    // Helper to get relationship object
    def _get_relationship(self, person1: Person, person2: Person):
        # This would involve a lookup in person1.relationships or person2.relationships
        # and correctly identifying the type, status, lineage etc.
        # Example: return person1.relationships.get(person2)
        pass # Placeholder for complex relationship lookup logic

The key difference is the structure: Algorithm A is like a series of stacked if/elif/else statements, very direct. Algorithm B uses classes and methods, representing entities and their behaviors, making it more modular and extensible. Acharonim often resolve ambiguities or subtle distinctions that Rishonim might have left more open, leading to more granular conditional logic in B.

Edge Cases: Inputs That Break Naïve Logic

Let's consider two scenarios that would trip up a simple, rule-based system that doesn't account for nuance. These are like unit tests that reveal bugs in a basic implementation.

Edge Case 1: The Priest and the Married Sister

  • Input:
    • Person_A: A Kohen (priest).
    • Deceased_B: Person_A's paternal sister.
    • Status_B: Married.
  • Naïve Logic: A priest is usually obligated to contract ritual impurity (tumah) for his primary relatives (mother, father, brother, sister, son, daughter). A sister is a primary relative. Therefore, the priest should become impure.
  • The "Bug": Mishneh Torah, Aveilut 2:10:1 explicitly states: "When a priest's sister is married - even to another priest, he does not become impure for her sake, "as Leviticus 21:3 states: "his virgin sister who is close to him who has not been with a man." "
  • Analysis: The term "virgin" (betulah) in the Torah's derivation is interpreted to exclude a married sister. This means the direct scriptural derivation for impurity (tumah) is blocked. However, the text in 2:1:2 states: "For his married paternal sister who is married, he is required to mourn by Scriptural Law." This creates a critical distinction:
    • Mourning Obligation: d'Oraita (Scriptural Law) - Yes.
    • Priestly Impurity Obligation: False - No.
  • Expected Output from Correct System: The GetMourningObligation function for Person_A and Deceased_B should return D_ORITA. The GetPriestTumahObligation function for Person_A and Deceased_B should return NONE (False).
  • Why it Breaks Naïve Logic: A simple system that just checks is_primary_relative and is_priest would incorrectly flag GetPriestTumahObligation as True. It needs to check the status of the sister after identifying her as a primary relative and before confirming the tumah obligation, referencing specific scriptural interpretation ("virgin sister").

Edge Case 2: The Grandparent and the Grandchild's Mother

  • Input:
    • Person_A: Grandfather.
    • Deceased_B: Person_A's son's mother (i.e., Person_A's wife, who is also the deceased's mother).
    • Person_C: Person_A's son (the deceased's brother).
  • Scenario: Deceased_B (the wife/mother) dies.
  • Naïve Logic (for mourn_together):
    1. Is Person_A obligated to mourn Deceased_B? Yes, as his wife (d'Rabbanan).
    2. Is Person_C obligated to mourn Deceased_B? Yes, as his mother (d'Oraita).
    3. Does Person_A mourn with Person_C?
      • A simple rule might say: "If A is mourning for someone, and C is also mourning for that same person, and C is A's child, then A mourns with C."
  • The "Bug": Mishneh Torah, Aveilut 2:2:2 states: "If a person's grandson, his son's maternal brother, or son's mother dies, he is obligated to rend his garments in the presence of his son and follow the mourning rites while in his presence. Outside his presence, he is not obligated."
  • Analysis: This passage creates a specific mourn_together obligation that is contingent on the presence of the son and only applies when the deceased is a grandchild, son's maternal brother, or son's mother.
    • In our scenario, Deceased_B is the "son's mother".
    • Person_A (Grandfather) is mourning Deceased_B (his wife).
    • Person_C (Son) is mourning Deceased_B (his mother).
    • The rule applies: Person_A (Grandfather) must mourn with Person_C (Son), in the son's presence. If they are not in the son's presence, the obligation to mourn together is nullified.
  • Expected Output from Correct System:
    • GetMourningObligation(Person_A, Deceased_B): D_RABBANNAN (for wife).
    • GetMourningObligation(Person_C, Deceased_B): D_ORITA (for mother).
    • GetMournTogetherObligation(Person_A, Person_C, Deceased_B): True (if in Person_C's presence), False (if not in Person_C's presence).
  • Why it Breaks Naïve Logic: A naïve system might assume that if two people are mourning the same deceased, and one is the parent of the other, the parent mourns with the child. This passage adds a crucial dependency on the specific deceased and the presence of the child as a condition for the parent's obligation to mourn together with the child. It's not just about the relationship between mourner A and mourner B, but also how the deceased relates to that hierarchy and the presence of the intermediary (the son).

Refactor: One Minimal Change to Clarify the Rule

The most complex part of this sugya, and where the most potential for "bugs" lies, is the interplay between different types of obligations (mourning vs. priestly impurity) and the contextual "mourn together" rule.

Let's focus on refactoring the definition of the mourn_together obligation, as it's highly context-dependent. The current phrasing often implies a general rule and then lists exceptions. A refactor would be to make the core definition more precise about its purpose.

Current State (Conceptual): "When you mourn someone, you also mourn with them in their presence." This is too broad.

Refactored Rule Definition:

"The obligation to 'mourn together' (mitzvah l'mitzor etzlenu) for a relative is a Rabbinic enactment designed to provide communal support and reinforce the shared experience of grief, specifically when the primary mourner is present with another relative who is also directly mourning the same deceased. Its activation is contingent on both the primary mourner's obligation and the presence of the secondary mourner, with specific exceptions and conditions based on the deceased's relationship to both parties."

Minimal Change Implementation:

Instead of thinking of mourn_together as a general rule with exceptions, let's define it as a specific type of interaction that requires direct presence and a specific relationship hierarchy or shared grief connection.

Refactored Logic for mourn_together:

  • Core Trigger: mourner_A is obligated to mourn deceased.
  • Condition 1: Shared Grief Connection: mourner_B is also obligated to mourn deceased.
  • Condition 2: Relational Link:
    • Scenario A: Direct Lineage Hierarchy: mourner_A is the parent/grandparent of mourner_B, and mourner_B is also mourning deceased (e.g., grandfather mourning grandson, with the son present). This is a strong case for mourn_together. (As per 2:2:2).
    • Scenario B: Spouse's Direct Lineage: mourner_A is mourning their spouse's parent (deceased), and mourner_B is mourner_A's spouse. (As per 2:3:2).
    • Scenario C: Spouse's Primary Mourning: mourner_A is mourning their spouse (deceased), and mourner_B is the spouse's parent, and mourner_A is mourning deceased in mourner_B's presence. (As per 2:3:1).
  • Condition 3: Presence: mourner_A must be in the presence of mourner_B (or vice-versa, depending on the specific rule interpretation, but the text emphasizes the presence of the other mourner).
  • Exclusions:
    • If mourner_A mourns deceased (their wife), they do NOT mourn with her for her other relatives, except her parents. (2:3:1)
    • If mourner_A mourns their son/daughter, and mourner_B is the spouse of the son/daughter, mourner_A does NOT mourn with mourner_B for deceased (the son/daughter's spouse). (2:4:1)

This reframing emphasizes that "mourning together" isn't an automatic extension of individual mourning, but a specific, context-dependent ritual of shared presence and support, with its own defined parameters and exclusions. It's like defining a new API endpoint: MournTogether(mourner_A, mourner_B, deceased, presence_status).

Takeaway: The Data Model of Human Connection

What does this deep dive into Mishneh Torah, Aveilut 2, teach us from a systems thinking perspective?

  1. Hierarchical and Relational Data Structures: Our familial connections aren't flat lists. They are complex graphs with weighted edges (strength of obligation) and node attributes (status, lineage). The "mourning obligation" is a property that gets calculated based on traversing this graph.
  2. Conditional Logic is King: The entire sugya is a masterclass in nested if-then-else statements, with boolean flags, enumerations (d'Oraita vs. d'Rabbanan), and state variables (married, betrothed).
  3. Module Separation and API Design: The laws for priests (tumah) are a distinct module that interacts with the core mourning module. The "mourn together" rule is another sub-module with its own set of inputs and outputs, dependent on the core module's calculations. This is excellent API design – clear inputs, specific outputs, and encapsulation of complex internal logic.
  4. Exception Handling is Crucial: The "bug reports" we identified (married sister, son's mother scenario) highlight that robust systems must have explicit exception handlers. Naïve logic fails when it encounters unexpected data states.
  5. Context Matters (The presence Parameter): The obligation to mourn together introduces a context-dependent parameter (presence). This is like a function where the output changes based on environmental variables.
  6. Data Integrity and Validation: The Mishneh Torah is essentially a rigorous data validation process for human relationships and their halachic implications. It ensures that we correctly classify relationships and apply the appropriate rules, preventing miscalculations that could lead to unintended spiritual or practical consequences.

Ultimately, the sugya teaches us that even the most deeply human obligations are governed by a profound, intricate, and logical framework. By dissecting it like code, we can appreciate its elegance and understand the divine "architecture" of our mitzvot. It's not just about rules; it's about a beautifully engineered system for navigating grief and reaffirming connection. L'Chaim!