proposit-core
    Preparing search index...

    Class PremiseEngine<TArg, TPremise, TExpr, TVar>

    Single-premise expression tree mutations.

    Type Parameters

    Hierarchy

    • HierarchicalChecksumCache
      • PremiseEngine

    Implements

    Index

    Constructors

    • Type Parameters

      • TArg extends {
            checksum: string;
            combinedChecksum: string;
            descendantChecksum: string | null;
            id: string;
            version: number;
        } = {
            checksum: string;
            combinedChecksum: string;
            descendantChecksum: string | null;
            id: string;
            version: number;
        }
      • TPremise extends
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "freeform";
            }
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                derivedClaimId: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "derivation";
            } =
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "freeform";
            }
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                derivedClaimId: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "derivation";
            }
      • TExpr extends TCorePropositionalExpression = TCorePropositionalExpression
      • TVar extends
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            }
            | {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            } =
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            }
            | {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            }

      Parameters

      Returns PremiseEngine<TArg, TPremise, TExpr, TVar>

    Properties

    cachedCombinedChecksum: string | undefined
    cachedDescendantChecksum: string | null | undefined
    cachedMetaChecksum: string | undefined
    checksumDirty: boolean = true
    expressions: ExpressionManager<TExpr>
    rootExpressionId: string | undefined
    variables: VariableManager<TVar>

    Methods

    • Adds an expression to this premise's tree.

      If the expression has parentId: null it becomes the root; only one root is permitted per premise. All Structural rules (implies/iff root-only, child limits, position uniqueness, derivation root operator) are enforced at mutation time.

      As of v1.0 P-1 (non-not operator under operator) is not enforced at mutation time — the AN-1 post-hook in assistive behavior inserts the formula buffer; in permissive behavior the un-buffered state stays and surfaces via engine.validate('presentable').

      Parameters

      Returns TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>

      The added expression (with checksum) and changeset.

      If the premise already has a root expression and this one is also a root.

      If the expression's parent does not exist in this premise.

      If the expression is a variable reference and the variable has not been registered.

    • Adds an expression immediately before or after an existing sibling, with position computed automatically.

      Composite-mutation behavior (spec §8 / S-9): sibling positions are always shifted as part of the bundled op when the computed midpoint position would collide with an existing sibling. Only the minimal set of nodes is repositioned. Repositioned siblings appear in changes.expressions.modified.

      Parameters

      • siblingId: string

        The ID of the existing sibling expression.

      • relativePosition: "before" | "after"

        Whether to insert "before" or "after" the sibling.

      • expression: TExpressionWithoutPosition<TExpr>

        The expression to add (position is auto-assigned).

      Returns TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>

      The added expression (with checksum) and changeset.

      If the sibling does not exist in this premise.

      If the expression is a variable reference and the variable has not been registered.

    • Changes the operator type of an existing operator expression.

      Handles three structural cases automatically:

      • Simple change: The operator has exactly 2 children and no merge condition. Updates the operator type in-place.
      • Merge: The operator has exactly 2 children and its parent is the same type as newOperator. Dissolves the current operator and reparents its children under the parent.
      • Split: The operator has >2 children. Extracts sourceChildId and targetChildId into a new sub-operator of type newOperator, inserting a formula buffer between the parent and the new sub-operator (the buffer is part of the bundled composite mutation so the resulting tree satisfies P-1 regardless of the engine's behavior setting).

      Parameters

      • expressionId: string

        The operator expression to change.

      • newOperator: "not" | "and" | "or" | "implies" | "iff"

        The target operator type.

      • OptionalsourceChildId: string

        First child to include in a split (required when >2 children).

      • OptionaltargetChildId: string

        Second child to include in a split (required when >2 children).

      • OptionalextraFields: Partial<TExpr>

        Optional partial expression fields merged into any newly created expressions (formula buffer, new sub-operator). Structural fields (id, type, operator, parentId, position, premiseId, argumentId, argumentVersion) cannot be overridden.

      Returns TCoreMutationResult<TExpr | null, TExpr, TVar, TPremise, TArg>

      result — For simple change: the updated operator expression. For merge: null (operator was dissolved). For split: the newly created sub-operator expression. changes — Full changeset with correct hierarchical checksums.

      If the expression does not exist, is not an operator, or is "not".

      If >2 children and sourceChildId/targetChildId not provided.

      If sourceChildId/targetChildId are not children of expressionId.

    • Evaluates the premise under a three-valued expression assignment.

      Variable values are looked up using Kleene three-valued logic (null = unknown). Missing variables default to null. For inference premises (implies/iff), an inferenceDiagnostic is computed with three-valued fields unless the root is rejected.

      Parameters

      • assignment: TCoreExpressionAssignment

        The variable assignment and optional rejected expression IDs.

      • Optionaloptions: {
            requireExactCoverage?: boolean;
            resolver?: (variableId: string) => boolean | null;
            strictUnknownKeys?: boolean;
        }

        Optional evaluation options.

        • OptionalrequireExactCoverage?: boolean

          If true, the assignment must cover exactly the referenced variables.

        • Optionalresolver?: (variableId: string) => boolean | null
        • OptionalstrictUnknownKeys?: boolean

          If true, unknown variable keys in the assignment cause an error.

      Returns TCorePremiseEvaluationResult

      The premise evaluation result.

    • Returns the operator expressions a reviewer can accept or reject, in pre-order depth-first tree order.

      Excludes "not" operators (NOT is flipped via a render-time flag, not voted on) and skips formula nodes (they are traversed but never emitted). Returns [] for empty premises and premises with no operators.

      Order is stable across calls on the same PremiseEngine instance; callers typically rely on index for step-queue construction.

      Returns TExpr[]

      An array of decidable operator expression entities.

    • Returns all argument-level variables (from the shared VariableManager) sorted by ID. Since the VariableManager is shared across all premises, this returns every registered variable — not just those referenced by expressions in this premise.

      Returns TVar[]

      An array of variable entities.

    • Splices a new expression between existing nodes in the tree. The new expression inherits the tree slot of the anchor node (leftNodeId ?? rightNodeId).

      As of v1.0 P-1 (non-not operator under operator) is not enforced at mutation time — the AN-1 post-hook in assistive behavior inserts the formula buffer; in permissive behavior the un-buffered state stays and surfaces via engine.validate('presentable').

      Parameters

      • expression: TExpressionInput<TExpr>

        The expression to insert, including position and parent assignment.

      • OptionalleftNodeId: string

        The existing node to become the left child of the new expression.

      • OptionalrightNodeId: string

        The existing node to become the right child of the new expression.

      Returns TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>

      The inserted expression (with checksum) and changeset.

      If the expression is a variable reference and the variable has not been registered.

    • Removes an expression and optionally its entire descendant subtree.

      As of v1.0 the pre-mutation 0/1-child collapse cascade is gone — AN-3 (post-mutation hook in assistive mode) handles 0/1-child operator/formula collapse on the surviving parent.

      Parameters

      • expressionId: string

        The ID of the expression to remove.

      • deleteSubtree: boolean

        Whether to remove all descendants as well.

      Returns TCoreMutationResult<TExpr | undefined, TExpr, TVar, TPremise, TArg>

      The removed root expression, or undefined if not found.

      If deleteSubtree is false and the single surviving child is a root-only operator (implies/iff) that would be placed in a non-root position (S-5).

    • Reparent an existing expression onto a new parent at the given position. Bundled-composite mutation per spec §8 — the parent reference, position field, and checksum-dirty propagation update atomically in a single call. No transient orphan state is externally observable.

      Enforces Structural rules only (S-1 FK soundness, S-4 no-cycles, entity-not-found, and S-9 logical sibling-position uniqueness at the bundled-composite level — same-position collisions with the moved expression's own prior slot are tolerated as transient, since the move atomically frees that slot). Higher-tier violations never throw here — Evaluable/Derivable/Presentable issues surface through validate(tier) per spec §7.1.

      Used by the native AN-1 (formula-buffer insertion) and AN-4 (same-operator absorption) passes in src/lib/grammar/an-rules.ts, and available to repair primitives and future composite ops that need a public reparent surface (e.g. removeOrphanOperators).

      Parameters

      • expressionId: string
      • newParentId: string
      • newPosition: number

      Returns TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>

      If expressionId or newParentId does not exist in this premise.

      S-1: if newParent is not an operator or formula (a variable cannot be a parent — parity with addExpression at em.ts:418-422).

      S-1: arity — if reparenting would push newParent's child count past its operator-specific limit (unary not max 1; binary implies/iff max 2). Same-parent moves leave count unchanged and bypass this check.

      S-4: if newParentId === expressionId or newParentId is a descendant of expressionId.

      S-9: if another sibling (NOT the expression being moved) already occupies newPosition under newParentId.

      1.0.0

    • Sets a callback that checks whether adding a variable-expression to a premise would create a circular binding. Injected by ArgumentEngine to enable cross-premise cycle detection. If not set, only the direct check (within the premise itself) runs.

      Parameters

      • check: ((variableId: string, premiseId: string) => boolean) | undefined

        A function that returns true if adding the variable to the premise would create a cycle, or undefined to clear.

      Returns void

    • Sets a callback that checks whether a premise-bound variable's target premise has an empty expression tree. Injected by ArgumentEngine to enable cross-premise validation. Used during validateEvaluability.

      Parameters

      • check: ((variableId: string) => boolean) | undefined

        A function that returns true if the variable's bound premise has no root expression, or undefined to clear.

      Returns void

    • Sets a callback invoked after every mutation, or undefined to clear.

      Parameters

      • callback: (() => void) | undefined

        The mutation callback, or undefined to remove.

      Returns void

    • Sets a callback that returns the full set of variable IDs registered in the argument. Injected by ArgumentEngine.

      Parameters

      • callback: (() => Set<string>) | undefined

        A function returning the set of registered variable IDs, or undefined to clear.

      Returns void

    • Toggles negation on an expression. If the expression's parent is a NOT operator, removes the NOT (promoting the expression). Otherwise, wraps the expression with a new NOT operator.

      As of v1.0 P-1 (non-not operator under operator) and P-2 (NOT(NOT(x)) double-negation) are not enforced at mutation time. The post-mutation AN hook handles them in assistive behavior: AN-1 inserts the formula buffer between NOT and a non-not operator child; AN-2 collapses NOT(NOT(x)) → x. In permissive behavior both states stay and surface via engine.validate('presentable').

      Parameters

      • expressionId: string

        The ID of the expression to toggle negation on.

      • OptionalextraFields: Partial<TExpr>

        Optional additional fields to merge into newly created expressions (NOT and formula nodes). Structural fields (id, type, operator, parentId, position, premiseId, argumentId, argumentVersion) cannot be overridden.

      Returns TCoreMutationResult<TExpr | null, TExpr, TVar, TPremise, TArg>

      The new NOT expression when adding negation, or null when removing it, along with the changeset.

      If the expression does not exist in this premise.

    • Wraps an existing expression with a new operator and a new sibling in a single atomic operation.

      The operator takes the existing node's slot in the tree. Both the existing node and the new sibling become children of the operator. Exactly one of leftNodeId / rightNodeId must be provided — it identifies the existing node and which child slot it occupies.

      As of v1.0 P-1 (non-not operator under operator) is not enforced at mutation time — the AN-1 post-hook in assistive behavior inserts the formula buffer; in permissive behavior the un-buffered state stays and surfaces via engine.validate('presentable').

      Parameters

      • operator: TExpressionWithoutPosition<TExpr>

        The new operator expression to wrap with.

      • newSibling: TExpressionWithoutPosition<TExpr>

        The new sibling expression to add alongside the existing node.

      • OptionalleftNodeId: string

        The existing node to place as the left child.

      • OptionalrightNodeId: string

        The existing node to place as the right child.

      Returns TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>

      The inserted operator (with checksum) and changeset.

      If the new sibling is a variable reference and the variable has not been registered.

    • Wrap an existing expression in a freshly-minted formula node atomically. The formula takes the child's original parent slot (parentId + position); the child becomes the formula's sole child at position 0. Bundled-composite mutation per spec §8.

      Used by the native AN-1 (formula-buffer insertion) pass in src/lib/grammar/an-rules.ts. Composing this from addExpression + reparentExpression is not possible: the intermediate state would either (a) violate S-9 with the child still occupying the formula's target slot, or (b) trip the parent's assertChildLimit (unary not, binary implies/iff) even though the net child count of the parent is unchanged after the wrap.

      The new formula's id is minted via the engine's idGenerator accessor and returned in the mutation result. Argument fields (argumentId, argumentVersion, premiseId) are inherited from the source child.

      Parameters

      • childId: string
      • formulaId: string

      Returns TCoreMutationResult<TExpr, TExpr, TVar, TPremise, TArg>

      If childId does not exist in this premise.

      If childId is at the root (no parent to insert a buffer beneath).

      S-10: if formulaId is already used by an existing expression in this premise (entity-ID uniqueness).

      1.0.0

    • Creates a new PremiseEngine from a previously captured snapshot.

      Type Parameters

      • TArg extends {
            checksum: string;
            combinedChecksum: string;
            descendantChecksum: string | null;
            id: string;
            version: number;
        } = {
            checksum: string;
            combinedChecksum: string;
            descendantChecksum: string | null;
            id: string;
            version: number;
        }
      • TPremise extends
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "freeform";
            }
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                derivedClaimId: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "derivation";
            } =
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "freeform";
            }
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                combinedChecksum: string;
                derivedClaimId: string;
                descendantChecksum: string
                | null;
                id: string;
                type: "derivation";
            }
      • TExpr extends TCorePropositionalExpression = TCorePropositionalExpression
      • TVar extends
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            }
            | {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            } =
            | {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            }
            | {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            }

      Parameters

      Returns PremiseEngine<TArg, TPremise, TExpr, TVar>