Skip to content

Commit

Permalink
first theorem implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddoret committed Dec 20, 2024
1 parent f7d35f7 commit 77f6c80
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 28 deletions.
61 changes: 42 additions & 19 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/punctilious/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import _latin_alphabet_uppercase_serif_italic
# import _latin_alphabet_lowercase_serif_roman
import _operators_1
import _operators_1_representations

# import _propositional_logic_1
# import _tao_analysis_1_2006
Expand All @@ -34,7 +35,10 @@
greek_alphabet_uppercase_serif_italic = _greek_alphabet_uppercase_serif_italic.GreekAlphabetUppercaseSerifItalic()
latin_alphabet_lowercase_serif_italic = _latin_alphabet_lowercase_serif_italic.LatinAlphabetLowercaseSerifItalic()
latin_alphabet_uppercase_serif_italic = _latin_alphabet_uppercase_serif_italic.LatinAlphabetUppercaseSerifItalic()

operators_1 = _operators_1.Operators1()
# TODO: Resume here to assure operators are enriched with representations.
operators_1_representations = _operators_1_representations.Operators1Representations()

# tao_analysis_1_2006 = _tao_analysis_1_2006.TaoAnalysis12006()
pass
Binary file modified src/punctilious/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified src/punctilious/__pycache__/_formal_language.cpython-312.pyc
Binary file not shown.
Binary file not shown.
9 changes: 5 additions & 4 deletions src/punctilious/_formal_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __repr__(self):
return self.connector.__str__() + self.arguments.__str__()

def __str__(self):
return self.connector.__str__() + self.arguments.__str__()
return self.represent()

@property
def arguments(self) -> FormulaArguments:
Expand All @@ -67,7 +67,6 @@ def arguments(self) -> FormulaArguments:
def connector(self) -> Connector:
return self[0]

@property
def represent(self):
return self.connector.rep_formula(argument=self.arguments)

Expand Down Expand Up @@ -428,9 +427,11 @@ def rep_formula(self, argument: FormulaArguments | None = None):
- a1, a2, ..., an are the formula arguments.
"""
if self.formula_representation is None:
raise ValueError(f'Connector {self.slug} has no formula representation.')
raise ValueError(f'Connector {self.uid} has no formula representation.')
connector: str = self.rep()
argument = ensure_formula_arguments(argument)
variables = {'connector': self, 'argument': argument}
argument_representations = tuple(a.represent() for a in argument)
variables = {'connector': connector, 'argument': argument_representations}
return self.formula_representation.rep(variables=variables)

@property
Expand Down
24 changes: 24 additions & 0 deletions src/punctilious/_operators_1_representations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import _util
import _representation
import _formal_language
import _bundling


class Operators1Representations(_bundling.YamlFileBundle):
"""A punctilious package of well-known mathematical operators."""
_singleton = None
_singleton_initialized = None

def __init__(self):
if self.__class__._singleton_initialized is None:
path = 'data.representations'
resource = 'operators_1.yaml'
super().__init__(path=path, resource=resource)
self.__class__._singleton_initialized = True
_util.get_logger().debug(
f'Operators1Representations 1 singleton ({id(self)}) initialized.')

def __new__(cls, *args, **kwargs):
if cls._singleton is None:
cls._singleton = super(Operators1Representations, cls).__new__(cls)
return cls._singleton
Binary file modified tests/__pycache__/test_formula.cpython-312-pytest-8.3.2.pyc
Binary file not shown.
Binary file not shown.
9 changes: 4 additions & 5 deletions tests/test_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ def test_formula(self):
p = create_atomic_connector('P')
q = create_atomic_connector('Q')
r = create_atomic_connector('R')
lnot = create_function('not')
land = create_function('and')
is_a_proposition = create_function('is-a-proposition')
land = pu.operators_1.conjunction
lnot = pu.operators_1.negation

phi1 = pu.Formula(p)
assert str(phi1) == 'P()'
assert str(phi1) == 'P'

phi2 = pu.Formula(land, (p, q,))
assert str(phi2) == 'and(P(), Q())'
assert str(phi2) == 'and(P, Q)'

phi3 = pu.Formula(lnot, (p,))
assert str(phi3) == 'not(P())'
Expand Down

0 comments on commit 77f6c80

Please sign in to comment.