proposit-core
    Preparing search index...

    Class ArgumentEngine<TArg, TPremise, TExpr, TVar, TClaim>

    Manages a propositional logic argument composed of premises, variable assignments, and logical roles (supporting premises and a conclusion).

    Provides premise CRUD, role management, evaluation of individual assignments, and exhaustive validity checking via truth-table enumeration.

    Type Parameters

    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;
            }
      • TClaim extends {
            checksum: string;
            frozen: boolean;
            id: string;
            type: "normal" | "citation" | "axiomatic";
            version: number;
        } = {
            checksum: string;
            frozen: boolean;
            id: string;
            type: "normal" | "citation" | "axiomatic";
            version: number;
        }

      Parameters

      Returns ArgumentEngine<TArg, TPremise, TExpr, TVar, TClaim>

    Methods

    • Registers a propositional variable for use across all premises.

      Parameters

      • variable: Omit<
            {
                argumentId: string;
                argumentVersion: number;
                checksum: string;
                claimId: string;
                claimVersion: number;
                id: string;
                symbol: string;
            },
            "checksum"
            | "descendantChecksum"
            | "combinedChecksum",
        > & Partial<
            Pick<
                {
                    argumentId: string;
                    argumentVersion: number;
                    checksum: string;
                    claimId: string;
                    claimVersion: number;
                    id: string;
                    symbol: string;
                },
                "checksum",
            >,
        > & Record<string, unknown>

        The variable entity to register.

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

      The registered variable (with checksum) and changeset.

      If variable.symbol is already in use.

      If variable.id already exists.

      If the variable does not belong to this argument.

    • Adds a premise-bound variable that references another argument's conclusion premise.

      Parameters

      • variable: Omit<
            TOptionalChecksum<
                {
                    argumentId: string;
                    argumentVersion: number;
                    boundArgumentId: string;
                    boundArgumentVersion: number;
                    boundPremiseId: string;
                    checksum: string;
                    id: string;
                    symbol: string;
                },
            >,
            "boundPremiseId",
        > & Record<string, unknown>
      • conclusionPremiseId: string

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

    • Adds a premise-bound variable that references a premise in a different argument.

      Parameters

      • variable: Omit<
            {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            },
            "checksum"
            | "descendantChecksum"
            | "combinedChecksum",
        > & Partial<
            Pick<
                {
                    argumentId: string;
                    argumentVersion: number;
                    boundArgumentId: string;
                    boundArgumentVersion: number;
                    boundPremiseId: string;
                    checksum: string;
                    id: string;
                    symbol: string;
                },
                "checksum",
            >,
        > & Record<string, unknown>

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

    • Registers a premise-bound propositional variable whose truth value is derived from another premise's evaluation.

      Parameters

      • variable: Omit<
            {
                argumentId: string;
                argumentVersion: number;
                boundArgumentId: string;
                boundArgumentVersion: number;
                boundPremiseId: string;
                checksum: string;
                id: string;
                symbol: string;
            },
            "checksum"
            | "descendantChecksum"
            | "combinedChecksum",
        > & Partial<
            Pick<
                {
                    argumentId: string;
                    argumentVersion: number;
                    boundArgumentId: string;
                    boundArgumentVersion: number;
                    boundPremiseId: string;
                    checksum: string;
                    id: string;
                    symbol: string;
                },
                "checksum",
            >,
        > & Record<string, unknown>

        The premise-bound variable entity to register.

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

      The registered variable (with checksum) and changeset.

      If variable.symbol is already in use.

      If variable.id already exists.

      If variable.boundPremiseId does not exist in this argument.

      If variable.boundArgumentId does not match this argument.

      If the variable does not belong to this argument.

    • Builds a Map keyed by a caller-supplied function over all variables. Useful for indexing by extension fields (e.g. statementId). The caller should cache the result — this is O(n) per call.

      Type Parameters

      • K

      Parameters

      • keyFn: (v: TVar) => K

        A function that extracts the map key from a variable.

      Returns Map<K, TVar>

      A Map from the extracted key to the variable.

    • Override point for subclasses to restrict cross-argument bindings. When this returns false, bindVariableToExternalPremise will throw.

      Parameters

      • _boundArgumentId: string
      • _boundArgumentVersion: number

      Returns boolean

    • Override point for subclasses to prevent forking. When this returns false, forkArgument will throw.

      Returns boolean

    • Collects all variables referenced by expressions across all premises, indexed both by variable ID and by symbol.

      Returns {
          byId: Record<string, { premiseIds: string[]; symbol: string }>;
          bySymbol: Record<string, { premiseIds: string[]; variableIds: string[] }>;
          variableIds: string[];
      }

      An object with variableIds, byId, and bySymbol indexes.

    • Creates a premise with a caller-supplied ID and registers it with this engine. Mirrors createPremise exactly, but accepts an explicit id as the first argument instead of generating one.

      Two call styles are supported:

      • Typed-bag (preferred, since 0.11.0):

        engine.createPremiseWithId(id, {
        type: "freeform", // or "derivation"
        derivedClaimId: claimId, // required when type === "derivation"
        extras: { label: "P1" },
        symbol: "P1",
        })
      • Legacy positional (kept for compatibility):

        engine.createPremiseWithId(id, extras, symbol)  // creates a freeform premise
        

      When type === "derivation", the same derivation initialization as createPremise runs: variable materialization and naked-Q tree setup.

      Parameters

      • id: string

        The ID to assign to the new premise.

      • Optionalextras: Record<string, unknown>
      • Optionalsymbol: string

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

      InvariantViolationError(CREATE_DERIVATION_REQUIRES_DERIVED_CLAIM_ID) when type === "derivation" and derivedClaimId is absent.

      InvariantViolationError(CREATE_DERIVATION_CLAIM_NOT_FOUND) when type === "derivation" and the claim is not in the library.

      If a premise with the given ID already exists.

      0.11.0 — typed-bag overload; derivation premise initialization.

    • Parameters

      • id: string
      • options: {
            derivedClaimId?: string;
            extras?: Record<string, unknown>;
            symbol?: string;
            type?: "freeform" | "derivation";
        }

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

    • Ensures a claim-bound variable for the given claim exists in this argument. If one already exists, returns it. Otherwise creates a new claim-bound variable with a fresh UUID, the current version of the claim from the ClaimLibrary, and an auto-generated symbol.

      Parameters

      • claimId: string

      Returns {
          argumentId: string;
          argumentVersion: number;
          checksum: string;
          claimId: string;
          claimVersion: number;
          id: string;
          symbol: string;
      }

      InvariantViolationError(CLAIM_NOT_FOUND) when the claim is not in the library.

      0.11.0

    • Registers a listener that is called after every mutation.

      Parameters

      • listener: () => void

        The callback to invoke on mutation.

      Returns () => void

      An unsubscribe function that removes the listener.

    • Updates fields on an existing variable. Since all premises share the same VariableManager, the update is immediately visible everywhere.

      Parameters

      • variableId: string

        The ID of the variable to update.

      • updates: Record<string, unknown>

        Fields to update. For claim-bound variables: symbol, claimId, claimVersion. For premise-bound variables: symbol, boundPremiseId, boundArgumentId, boundArgumentVersion. claimId and claimVersion must be provided together on claim-bound variables.

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

      The updated variable, or undefined if not found.

      If the new symbol is already in use by a different variable.

      If the new claim reference does not exist in the claim library.

      If updates include fields from the wrong binding type (e.g., boundPremiseId on a claim-bound variable).

      If the new boundPremiseId does not exist in this argument.

    • Validates that this argument is structurally ready for evaluation: a conclusion must be set, all role references must point to existing premises, variable ID/symbol mappings must be consistent, every premise must be individually evaluable, and all derivation premise structures must be well-formed (naked-Q invariant; since 0.11.0).

      Derivation premises with structurally broken trees are flagged with DERIVATION_STRUCTURE_INVALID_AT_EVALUATION. Use validateDerivationStructures() to isolate derivation checks without running the full evaluability sweep.

      Returns TCoreValidationResult

      A validation result with any issues found.

      0.11.0 — derivation pre-flight added to the sweep.

    • Creates a new ArgumentEngine from flat arrays of entities, as typically stored in a relational database. Expressions are grouped by their premiseId field and loaded in BFS order (roots first, then children of already-added nodes) to satisfy parent-existence requirements.

      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;
            }
      • TClaim extends {
            checksum: string;
            frozen: boolean;
            id: string;
            type: "normal" | "citation" | "axiomatic";
            version: number;
        } = {
            checksum: string;
            frozen: boolean;
            id: string;
            type: "normal" | "citation" | "axiomatic";
            version: number;
        }

      Parameters

      Returns ArgumentEngine<TArg, TPremise, TExpr, TVar, TClaim>

    • Creates a new ArgumentEngine 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;
            }
      • TClaim extends {
            checksum: string;
            frozen: boolean;
            id: string;
            type: "normal" | "citation" | "axiomatic";
            version: number;
        } = {
            checksum: string;
            frozen: boolean;
            id: string;
            type: "normal" | "citation" | "axiomatic";
            version: number;
        }

      Parameters

      Returns ArgumentEngine<TArg, TPremise, TExpr, TVar, TClaim>