git @ Cat's Eye Technologies Eqthy / 89fd147
Add 'Context' type, minor edits elsewhere as well. Chris Pressey 1 year, 2 months ago
6 changed file(s) with 22 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
6262 detrimental to simplicity, and vice versa.
6363
6464 It has been implemented in Python 3 in about 720 lines of code; the core
65 verifier module is less than 150 lines of code. For more details, see
66 the [Implementations](#implementations) section below.
65 (term manipulation and verifier modules) is about 340 lines of code. For
66 more details, see the [Implementations](#implementations) section below.
6767
6868 It is also possible for a human to write Eqthy documents by hand, and
6969 to read them, without much specialized knowledge. The base logic
108108
109109 ### Desired Examples
110110
111 * [Interior algebra](https://en.wikipedia.org/wiki/Interior_algebra) (corresponding to the modal logic S4)
112111 * [Relation algebra](https://en.wikipedia.org/wiki/Relation_algebra)
113 * Johnson's 1892 axiom system given in Meredith and Prior's 1967 paper [Equational Logic](https://projecteuclid.org/download/pdf_1/euclid.ndjfl/1093893457)
114 * The theorem of ring theory given in [Equational Logic, Spring 2017](https://people.math.sc.edu/mcnulty/alglatvar/equationallogic.pdf) by McNulty (but it's a bit of a monster all right)
112 * Johnson's 1892 axiom system given in Meredith and Prior's 1967 paper
113 [Equational Logic](https://projecteuclid.org/download/pdf_1/euclid.ndjfl/1093893457)
114 * The theorem of ring theory given in [Equational Logic, Spring 2017](https://people.math.sc.edu/mcnulty/alglatvar/equationallogic.pdf)
115 by George McNulty (but it's a bit of a monster all right)
115116
116117 ### Aspirational Items
117118
1212 I'm told they are subtlely different, but aren't their axioms basically the same? The difference
1313 may be too subtle to matter for our purposes here.
1414
15 Anyway, I'm writing this so I can have an algebra of sets to base some further set-based
16 definitions on, in lieu of having an actual set theory.
15 Anyway, I'm writing this so I can have an theory of sets to base further definitions on.
16 I don't have a "proper" set theory (defining ZFC in equational logic is rather out
17 of the question), and it would seem awkward to base some of those further definitions
18 on Boolean algebra, so this algebra of sets will need to suffice for a basis.
1719
1820 Commutative properties:
1921
2323 axiom (#inter-id) inter(A, u) = A
2424 axiom (#union-comp) union(A, comp(A)) = u
2525 axiom (#inter-comp) inter(A, comp(A)) = e
26
2627 axiom (#union-de-morg) comp(inter(A, B)) = union(comp(A), comp(B))
2728 axiom (#inter-de-morg) comp(union(A, B)) = inter(comp(A), comp(B))
2829
44 from argparse import ArgumentParser
55 import codecs
66 import sys
7 from typing import List, Dict
7 from typing import List
88
9 from eqthy.objects import Theorem
9 from eqthy.objects import Context
1010 from eqthy.parser import Parser
1111 from eqthy.verifier import Verifier
1212
5353
5454 options = argparser.parse_args(args)
5555
56 context: Context = {}
5657 try:
57 context: Dict[str, Theorem] = {}
5858 for filename in options.input_files:
5959 with codecs.open(filename, 'r', encoding='UTF-8') as f:
6060 text = f.read()
33
44 """Objects in the Eqthy document structure."""
55 from dataclasses import dataclass
6 from typing import List, Union
6 from typing import List, Dict, Union
77 from .terms import Eqn, Term, Variable
88
99
6060 class Document:
6161 axioms: List[Axiom]
6262 theorems: List[Theorem]
63
64
65 Context = Dict[str, Theorem]
44 from typing import Dict, Union, Any
55
66 from eqthy.objects import (
7 Document, Theorem, Step,
7 Context, Document, Theorem, Step,
88 Reflexivity, Substitution, Congruence, Reference
99 )
1010 from eqthy.terms import (
1818
1919
2020 class Verifier:
21 def __init__(self, document: Document, verbose: bool = True, context: Union[Dict[str, Theorem], None] = None):
21 def __init__(self, document: Document, verbose: bool = True, context: Union[Context, None] = None):
2222 self.axioms = document.axioms
2323 self.theorems = document.theorems
2424 self.verbose = verbose
25 self.context: Dict[str, Theorem] = context or {}
25 self.context: Context = context or {}
2626 self.rules: Dict[str, RewriteRule] = {}
2727
2828 for axiom in self.axioms:
3737 self.rules[name + '_1'] = RewriteRule(pattern=lhs, substitution=rhs)
3838 self.rules[name + '_2'] = RewriteRule(pattern=rhs, substitution=lhs)
3939
40 def verify(self) -> Dict[str, Theorem]:
40 def verify(self) -> Context:
4141 for theorem in self.theorems:
4242 self.verify_theorem(theorem)
4343 self.register(theorem.name, theorem.eqn.lhs, theorem.eqn.rhs)