Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mathesis/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ class Negation(Unary):
connective = "¬"
connective_latex = r"\neg"

class Possibility(Unary):
signature = "Poss"
connective = "◇"
connective_latex = r"\Diamond"

class Necessity(Unary):
signature = "Necc"
connective = "□"
connective_latex = r"\Box"


class Binary(Formula):
subs: tuple[Formula, Formula]
Expand Down
75 changes: 53 additions & 22 deletions mathesis/grammars.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Conjunction,
Disjunction,
Negation,
Possibility,
Necessity,
Particular,
Universal,
)
Expand All @@ -32,6 +34,12 @@ def bottom(self, v):

def negation(self, v):
return Negation(*v)

def possibility(self, v):
return Possibility(*v)

def necessity(self, v):
return Necessity(*v)

def universal(self, v):
return Universal(*v)
Expand Down Expand Up @@ -90,11 +98,24 @@ def parse(self, text_or_list: str | list):
class BasicPropositionalGrammar(Grammar):
"""Basic grammar for the propositional language."""

default_symbols = {
"top": "⊤",
"bottom": "⊥",
"negation": "¬",
"conjunction": "∧",
"disjunction": "∨",
"conditional": "→",
"necessity": "□",
"possibility": "◇",
}

grammar_rules = r"""
?fml: conditional
| disjunction
| conjunction
| negation
| necessity
| possibility
| top
| bottom
| atom
Expand All @@ -103,34 +124,44 @@ class BasicPropositionalGrammar(Grammar):
ATOM : /\w+/

atom : ATOM
top : ""
bottom : ""
negation : "¬" fml
conjunction : (conjunction | fml) "" fml
disjunction : (disjunction | fml) "" fml
conditional : fml "{conditional_symbol}" fml
necc : "" fml
poss : "" fml
top : "{top}"
bottom : "{bottom}"
negation : "{negation}" fml
conjunction : (conjunction | fml) "{conjunction}" fml
disjunction : (disjunction | fml) "{disjunction}" fml
conditional : fml "{conditional}" fml
necessity : "{necessity}" fml
possibility : "{possibility}" fml

%import common.WS
%ignore WS
""".lstrip()

def __init__(self, symbols={"conditional": "→"}):
self.grammar_rules = self.grammar_rules.format(
conditional_symbol=symbols["conditional"]
)
def __init__(self, symbols=None):
merged = self.default_symbols.copy()
if symbols is not None:
merged.update(symbols)
self.symbols = merged
self.grammar_rules = self.grammar_rules.format(**merged)
super().__init__()


class BasicGrammar(BasicPropositionalGrammar):
"""Basic grammar for the first-order language."""

default_symbols = {
**BasicPropositionalGrammar.default_symbols,
"universal": "∀",
"particular": "∃",
}

grammar_rules = r"""
?fml: conditional
| disjunction
| conjunction
| negation
| necessity
| possibility
| universal
| particular
| top
Expand All @@ -142,16 +173,16 @@ class BasicGrammar(BasicPropositionalGrammar):
TERM: /\w+/

atom : PREDICATE ("(" TERM ("," TERM)* ")")?
top : ""
bottom : ""
negation : "¬" fml
conjunction : fml "" fml
disjunction : fml "" fml
conditional : fml "{conditional_symbol}" fml
necc : "" fml
poss : "" fml
universal : "" TERM fml
particular : "" TERM fml
top : "{top}"
bottom : "{bottom}"
negation : "{negation}" fml
conjunction : fml "{conjunction}" fml
disjunction : fml "{disjunction}" fml
conditional : fml "{conditional}" fml
necessity : "{necessity}" fml
possibility : "{possibility}" fml
universal : "{universal}" TERM fml
particular : "{particular}" TERM fml

%import common.WS
%ignore WS
Expand Down
Loading