git @ Cat's Eye Technologies Eqthy / bd0a1d1
Try to deal properly with Reference hints. Hit a wall. Chris Pressey 2 years ago
3 changed file(s) with 27 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
1919 qed
2020
2121 For a fuller description of the language, including a set of Falderal
22 tests, see [doc/Eqthy.md](doc/Eqthy.md).
22 tests, see **[doc/Eqthy.md](doc/Eqthy.md)**.
2323
2424 The language does not prescribe any specific usage but it is expected
2525 that one of the main reasons for a computer to read a proof written
3131 TODO
3232 ----
3333
34 * `[by previous_theorem]`
34 * Reference hints (`[by axiom-or-theorem]`) should narrow down
35 search space. We need a data structure that stores the names of
36 axioms and theorems for this to be meaningful
3537 * Document the Syntax for Comments
36 * impl: show step number or line number when cannot derive next step
38 * Show the step number or line number when cannot derive next step
39 * Allow rules to be instantiated with variable names other than the
40 ones that are specified in the rule
233233 Naming an axiom in a hint when the axiom used was not actually used there
234234 is incorrect. It is reasonable to (at least) warn the user of this mistake.
235235
236 axiom (idright) mul(A, e) = A
237 axiom (idleft) mul(e, A) = A
238 axiom (assoc) mul(A, mul(B, C)) = mul(mul(A, B), C)
239 theorem
240 A = mul(A, e)
241 proof
242 A = A
243 A = mul(A, e) [by idleft]
244 qed
245 ???> waaaaa
236 > axiom (idright) mul(A, e) = A
237 > axiom (idleft) mul(e, A) = A
238 > axiom (assoc) mul(A, mul(B, C)) = mul(mul(A, B), C)
239 > theorem
240 > A = mul(A, e)
241 > proof
242 > A = A
243 > A = mul(A, e) [by idleft]
244 > qed
245 > ???> waaaaa
246246
247247 Using the reflexivity hint when the rule used was not actually reflexivity
248248 is incorrect. It is reasonable to (at least) warn the user of this mistake.
00 # TODO: these should probably come from a "eqthy.hints" module
1 from eqthy.parser import Reflexivity, Substitution, Congruence
1 from eqthy.parser import Reflexivity, Substitution, Congruence, Reference
22 from eqthy.terms import Eqn, all_matches, expand, subterm_at_index, update_at_index, render, RewriteRule, replace
33
44
5959 raise DerivationError("No step in proof showed {}".format(render(theorem.eqn)))
6060
6161 def obtain_rewritten_step(self, step, prev):
62 rules_to_try = self.rules
6263 if step.hint is not None:
6364 self.log("==> step has hint {}", step.hint)
64 result = self.resolve_step_hint(step, prev)
65 result = self.resolve_step_hint(step, prev, rules_to_try)
6566 if result:
6667 return result
6768
6869 # if no hint or hint resolution punted, search for rule to apply
6970
70 for rule in self.rules:
71 for rule in rules_to_try:
7172 self.log(" Trying to rewrite lhs {} with {}", render(prev.eqn.lhs), render(rule))
7273 for rewritten_lhs in self.all_rewrites(rule, prev.eqn.lhs):
7374 self.log(" Using {}, rewrote {} to {}", render(rule), render(prev.eqn.lhs), render(rewritten_lhs))
8485 self.log(" Can rewrite rhs to obtain: {}", render(rewritten_eqn))
8586 return rewritten_eqn
8687
87 def resolve_step_hint(self, step, prev):
88 def resolve_step_hint(self, step, prev, rules_to_try):
89 """`rules_to_try` is passed by reference, expected to perhaps be modified"""
8890 if isinstance(step.hint, Substitution):
8991 # replace all occurrences of variable in step with term
9092 rewritten_eqn = Eqn(
110112 return step.eqn
111113 else:
112114 raise DerivationError("Could not derive {} from Reflexivity".format(render(step.eqn)))
115 elif isinstance(step.hint, Reference):
116 # TODO: narrow down rules_to_try
117 return None
113118 else:
114 # TODO do other checking on this hint instead of ignoring it
115 self.log("==> step has unacted-upon hint {}", step.hint)
119 raise NotImplementedError(str(step.hint))
116120
117121 def all_rewrites(self, rule, term):
118122 """Given a term, and a rule, return a list of the terms that would result