agent_logic.core.base
Base module for logical expressions.
This module provides the base class for all logical expressions in the logic system. It defines the common interface that all logical expressions must implement, including evaluation, variable extraction, and serialization.
Classes
|
Recursive base class for logical expressions. |
- class agent_logic.core.base.LogicalExpression(**data)[source]
Bases:
BaseModelRecursive base class for logical expressions.
This abstract class defines the interface for all logical expressions in the system. Concrete implementations include Proposition, Not, and BinaryOp.
- model_config
Pydantic model configuration to allow arbitrary types.
- depth()[source]
Computes the depth of the logical expression tree.
- Return type:
int- Returns:
Integer representing the depth of the expression tree.
- Raises:
NotImplementedError – This is an abstract method that must be implemented by subclasses.
- evaluate(context)[source]
Recursively evaluates the expression under a given truth assignment.
- Parameters:
context (
Dict[str,bool]) – Dictionary mapping variable names to truth values. Example: {“P”: True, “Q”: False}- Return type:
bool- Returns:
Boolean result of evaluating the expression.
- Raises:
NotImplementedError – This is an abstract method that must be implemented by subclasses.
- classmethod from_dict(data)[source]
Recursively reconstructs an expression from a dictionary.
- Parameters:
data (
Dict) – Dictionary representation of a logical expression. Must include a ‘type’ field.- Return type:
- Returns:
Reconstructed logical expression.
- Raises:
ValueError – If the data is not a dictionary, doesn’t have a type field, or has an unknown expression type.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].