[docs]classFunction(BaseModel):"""Represents a function f(x) in predicate logic."""name:str=Field(...,description="Function name (e.g., f, g, h).")parameters:List[str]=Field(...,description="List of parameter variable names.")function:Callable[...,Any]
[docs]defevaluate(self,context:Dict[str,Any])->Any:"""Evaluate the function using context for parameter values."""args=[context[param]forparaminself.parameters]returnself.function(*args)
[docs]classRelation(LogicalExpression):"""Represents a predicate relation R(x, y, ...)."""name:str=Field(...,description="Relation name (e.g., P, Q, R).")parameters:List[str]=Field(...,description="List of parameter variable names.")
[docs]defevaluate(self,context:Dict[str,bool])->bool:"""Evaluates a predicate relation based on the truth values in context."""key=f"{self.name}({', '.join(self.parameters)})"returncontext.get(key,False)