agent_logic.proofs
Logical proofs module.
This module provides tools for constructing and validating logical proofs, including inference rules and proof verification systems.
- class agent_logic.proofs.InferenceRules[source]
Bases:
objectExtends formal rules of inference for proofs with additional logical principles.
- static absorption(p, p_implies_q)[source]
Absorption Rule: (P → Q) implies (P → (P ∧ Q)). P → Q ⊢ P → (P ∧ Q)
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
- static addition(p, q)[source]
Addition: If P is true, then (P ∨ Q) must be true. P ⊢ (P ∨ Q)
- Return type:
- Parameters:
- static associative_rule(expression)[source]
Associative Law: (P ∨ (Q ∨ R)) ≡ ((P ∨ Q) ∨ R) (P ∧ (Q ∧ R)) ≡ ((P ∧ Q) ∧ R)
- Return type:
- Parameters:
expression (LogicalExpression)
- static biconditional_elimination(p_iff_q)[source]
Biconditional Elimination: If (P ↔ Q) is true, then (P → Q) and (Q → P) must be true. (P ↔ Q) ⊢ (P → Q), (Q → P)
- Return type:
List[LogicalExpression]- Parameters:
p_iff_q (LogicalExpression)
- static biconditional_introduction(p_implies_q, q_implies_p)[source]
Biconditional Introduction: If (P → Q) is true and (Q → P) is true, then (P ↔ Q) must be true. (P → Q), (Q → P) ⊢ (P ↔ Q)
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
q_implies_p (LogicalExpression)
- static conjunction_elimination(p_and_q)[source]
Conjunction Elimination: If (P ∧ Q) is true, then P and Q must be true separately. (P ∧ Q) ⊢ P, Q
- Return type:
List[LogicalExpression]- Parameters:
p_and_q (LogicalExpression)
- static conjunction_introduction(p, q)[source]
Conjunction Introduction: If P is true and Q is true, then (P ∧ Q) is true. P, Q ⊢ (P ∧ Q)
- Return type:
- Parameters:
- static constructive_dilemma(p_implies_q, r_implies_s, p_or_r)[source]
Constructive Dilemma: If (P → Q) is true, (R → S) is true, and (P ∨ R) is true, then (Q ∨ S) must be true. (P → Q), (R → S), (P ∨ R) ⊢ (Q ∨ S)
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
r_implies_s (LogicalExpression)
p_or_r (LogicalExpression)
- static constructive_negation(p_implies_false)[source]
Constructive Negation: If (P → ⊥) is true, then ¬P must be true. (P → ⊥) ⊢ ¬P
- Return type:
- Parameters:
p_implies_false (LogicalExpression)
- static destructive_dilemma(p_implies_q, r_implies_s, not_q_or_not_s)[source]
Destructive Dilemma: If (P → Q) is true, (R → S) is true, and (¬Q ∨ ¬S) is true, then (¬P ∨ ¬R) must be true. (P → Q), (R → S), (¬Q ∨ ¬S) ⊢ (¬P ∨ ¬R)
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
r_implies_s (LogicalExpression)
not_q_or_not_s (LogicalExpression)
- static disjunctive_syllogism(p_or_q, not_p)[source]
Disjunctive Syllogism: If (P ∨ Q) is true and ¬P is true, then Q must be true. (P ∨ Q), ¬P ⊢ Q
- Return type:
- Parameters:
p_or_q (LogicalExpression)
not_p (LogicalExpression)
- static distributive_rule(expression)[source]
Distributive Law: (P ∧ (Q ∨ R)) ≡ ((P ∧ Q) ∨ (P ∧ R)) (P ∨ (Q ∧ R)) ≡ ((P ∨ Q) ∧ (P ∨ R))
- Return type:
- Parameters:
expression (LogicalExpression)
- static hypothetical_syllogism(p_implies_q, q_implies_r)[source]
Hypothetical Syllogism: If (P → Q) is true and (Q → R) is true, then (P → R) must be true. (P → Q), (Q → R) ⊢ (P → R)
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
q_implies_r (LogicalExpression)
- static law_of_excluded_middle(p)[source]
Law of Excluded Middle: P ∨ ¬P is always true. ⊢ (P ∨ ¬P)
- Return type:
- Parameters:
- static modus_ponens(p, p_implies_q)[source]
Modus Ponens: If P is true and (P → Q) is true, then Q must be true. P, (P → Q) ⊢ Q
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
- static modus_tollens(not_q, p_implies_q)[source]
Modus Tollens: If ¬Q is true and (P → Q) is true, then ¬P must be true. ¬Q, (P → Q) ⊢ ¬P
- Return type:
- Parameters:
not_q (LogicalExpression)
p_implies_q (LogicalExpression)
- static negation_elimination(not_not_p)[source]
Negation Elimination: If ¬(¬P) is true, then P must be true. ¬(¬P) ⊢ P
- Return type:
- Parameters:
not_not_p (LogicalExpression)
- static negation_introduction(p_implies_false)[source]
Negation Introduction: If (P → ⊥) is true, then ¬P must be true. (P → ⊥) ⊢ ¬P
- Return type:
- Parameters:
p_implies_false (LogicalExpression)
- static proof_by_contradiction(assumption, contradiction)[source]
Reductio ad Absurdum (Proof by Contradiction): If assuming P leads to ⊥, then ¬P must be true. P ⊢ ⊥ ⟹ ¬P
- Return type:
- Parameters:
assumption (LogicalExpression)
contradiction (LogicalExpression)
- static transitivity_of_implication(p_implies_q, q_implies_r)[source]
Transitivity of Implication: If (P → Q) and (Q → R) hold, then (P → R) holds. (P → Q), (Q → R) ⊢ (P → R)
- Return type:
- Parameters:
p_implies_q (LogicalExpression)
q_implies_r (LogicalExpression)
- class agent_logic.proofs.Proof(**data)[source]
Bases:
BaseModelRepresents a structured proof with step-by-step reasoning.
A proof consists of a sequence of steps, each building on previous steps according to valid rules of inference. The proof is valid if each step follows logically from the steps it depends on.
- Parameters:
steps (List[ProofStep])
debug (bool)
- steps
List of ProofStep objects making up the proof.
- debug
Boolean flag to enable or disable debug output during validation.
- apply_inference(step, known_statements)[source]
Applies inference rules dynamically based on the step’s justification.
Extracts the referenced statements from previous steps, and applies the appropriate inference rule to derive the current step.
- Parameters:
step (
ProofStep) – The current proof step being validated.known_statements (
Dict[int,LogicalExpression]) – Dictionary mapping step numbers to their logical expressions.
- Return type:
Optional[LogicalExpression]- Returns:
The derived logical expression, or None if inference failed.
- debug: bool
- classmethod from_dict(data)[source]
Reconstructs a proof from a dictionary representation.
- Parameters:
data (
Dict) – Dictionary containing a “steps” list with proof step data.- Return type:
- Returns:
Reconstructed Proof object.
- is_valid()[source]
Validates the proof by ensuring logical correctness of each step.
The validation process checks that: 1. All referenced dependencies exist 2. Each step follows logically from its dependencies using the specified rule 3. The derived statement matches the claimed statement
- Return type:
bool- Returns:
Boolean indicating whether the proof is valid.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- steps: List[ProofStep]
- class agent_logic.proofs.ProofStep(**data)[source]
Bases:
BaseModelRepresents a single step in a structured proof.
Each step consists of a logical statement, a justification for that statement, and optional references to previous steps that support the justification.
- Parameters:
step_number (int)
statement (LogicalExpression)
justification (str)
dependencies (List[int] | None)
- step_number
Sequential number identifying this step in the proof.
- statement
The logical expression being asserted at this step.
- justification
Name of the inference rule or justification for this step.
- dependencies
List of step numbers that this step depends on, or None if this is a premise.
- dependencies: Optional[List[int]]
- justification: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- statement: LogicalExpression
- step_number: int
- class agent_logic.proofs.QuantifierRules[source]
Bases:
objectInference rules for quantifiers (∀, ∃).
- static existential_generalization(predicate, variable)[source]
P(a) ⊢ ∃x P(x) Replace a constant with a quantified variable.
- Return type:
- Parameters:
predicate (Relation)
variable (str)
- static existential_instantiation(quantifier, constant)[source]
∃x P(x) ⊢ P(a) Introduce a fresh constant.
- Return type:
- Parameters:
quantifier (ExistentialQuantifier)
constant (str)
- static universal_elimination(quantifier, constant)[source]
∀x P(x) ⊢ P(a) Replace variable x with constant a.
- Return type:
- Parameters:
quantifier (UniversalQuantifier)
constant (str)
- class agent_logic.proofs.Unification[source]
Bases:
objectHandles unification for first-order logic terms.
Modules
Proof system module for logical reasoning. |
|