""" This module hosts propositions. """ from __future__ import annotations from typing import Callable from .terms import Term from dataclasses import dataclass class Prop: """ A proposition is a logical statement. It can be proven by the proof checker, or it can be used as a hypothesis to prove another proposition. """ def as_assumption(self, goal : Prop) -> list[list[tuple[list[Prop], Prop]]]: """ Propositions can simplify the proof by creating simpler theorems and sub-lemmas to prove instead. If this proposition is part of the assumptions, this function helps transform the goal into simpler sub-goals. :return: Tuples of added assumptions with a new goal. :rtype: list[list[tuple[list[Prop], Prop]]] """ return [] def as_proof(self) -> list[list[tuple[list[Prop], Prop]]]: """ Determine which hypotheses are required in the context to prove this proposition. The function returns a list of various methods to prove the proposition. If any of the methods is an empty list, it means the proposition requires no assumptions and can instead be computed. :return: Methods to prove this proposition. :rtype: list[tuple[list[Prop], Prop]] """ return [] @dataclass(frozen=True) class And(Prop): """ The logical and-operator `P ^ Q`. """ P : Prop Q : Prop @dataclass(frozen=True) class Eq(Prop): """ Compare whether two terms are equal. """ x : Term y : Term def as_assumption(self, goal: Prop) -> list[list[tuple[list[Prop], Prop]]]: return [] def as_proof(self) -> list[list[tuple[list[Prop], Prop]]]: return super().as_proof() @dataclass(frozen=True) class Exists(Prop): """ Create a statement that demonstrates there exists an x such that the given statement is true. """ x : Callable[[Term], Prop] @dataclass(frozen=True) class ForAll(Prop): """ Create a statement that is true for all x """ x : Callable[[Term], Prop] @dataclass(frozen=True) class Implies(Prop): """ The logical operator `P -> Q`. """ P : Prop Q : Prop @dataclass(frozen=True) class Or(Prop): """ The logical and-operator `P v Q`. """ P : Prop Q : Prop