agent_logic.core.functions

Classes

Function(**data)

Represents a function f(x) in predicate logic.

Relation(**data)

Represents a predicate relation R(x, y, ...).

class agent_logic.core.functions.Function(**data)[source]

Bases: BaseModel

Represents a function f(x) in predicate logic.

Parameters:
  • name (str)

  • parameters (List[str])

  • function (Callable[[...], Any])

depth()[source]
Return type:

int

evaluate(context)[source]

Evaluate the function using context for parameter values.

Return type:

Any

Parameters:

context (Dict[str, Any])

classmethod from_dict(data)[source]
Return type:

Function

Parameters:

data (Dict)

function: Callable[..., Any]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
parameters: List[str]
to_dict()[source]
Return type:

Dict

variables()[source]
Return type:

List[str]

class agent_logic.core.functions.Relation(**data)[source]

Bases: LogicalExpression

Represents a predicate relation R(x, y, …).

Parameters:
  • name (str)

  • parameters (List[str])

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]

Evaluates a predicate relation based on the truth values in context.

Return type:

bool

Parameters:

context (Dict[str, bool])

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:

Relation

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].

name: str
parameters: List[str]
to_dict()[source]

Recursively converts expression to a dictionary.

Return type:

Dict

Returns:

Dictionary representation of the logical expression.

Raises:

NotImplementedError – This is an abstract method that must be implemented by subclasses.

variables()[source]

Recursively extracts all variables in the expression.

Return type:

List[str]

Returns:

List of variable names used in the expression.

Raises:

NotImplementedError – This is an abstract method that must be implemented by subclasses.