Open robdockins opened 3 years ago
My comment from GaloisInc/saw-script#110 is relevant: https://github.com/GaloisInc/saw-script/issues/110#issuecomment-746482057
Another thing that bothers me about
ruleOfProp
is that it has the names of several equality operators likeboolEq
,bvEq
, andvecEq
hard-coded into it. It would be better if theSharedContext
could refer to a set of rules/axioms for turning propositions into equations, and thenruleOfProp
could work generically over this set. For example, there would be a rule like(n : Nat) -> (x y : Vec n Bool) -> EqTrue (bvEq n x y) -> Eq (Vec n Bool) x y
forbvEq
, and ifruleOfProp
was given a theorem matching the patternEqTrue (bvEq _ _ _)
then it could be composed with this rule to produce anEq
theorem that could work directly as a rewrite rule.If
ruleOfProp
was implemented this way, then we could easily extendruleOfProp
to handle new forms of theorems later, even at runtime.
This is exactly the same idea proposed above, so yes, of course I support it completely. To facilitate implementation, it would be nice to have some combinators for composing theorems with resolution/modus ponens, sort of like the OF
and COMP
operators in Isabelle.
Also I would not hard-code a special exception for ecEq
; we can add some definitions and rules like these to Cryptol.sawcore
ValidPEq : (a : sort 0) -> PEq a -> Prop;
ValidPEq a pa = (x y : a) -> ecEq a pa x y -> Eq a x y;
ecEq_Eq : (a : sort 0) -> (pa : PEq a) -> (x y : a) -> ValidPEq a pa -> EqTrue (ecEq a pa x y) -> Eq a x y;
ecEq_Eq a pa x y valid e = ...
along with some axioms (or proved theorems) stating that the various PEq
dictionary combinators preserve the ValidPEq
property.
I missed that discussion before. Yeah, it sounds like we are largely in agreement.
We could have the PEq
class carry its correctness property, which would make it pretty easy to access.
Putting the correctness property inside the dictionary would be pretty handy. Are there any potential drawbacks to doing that? The only thing I can think of is that putting a dependent type like that inside PEq
might make it harder to export certain terms to certain backends? And I guess we'd have to define PEq
as a saw-core datatype instead of a (non-dependent) record type (not a big deal).
I suppose that might be a problem if we wanted to target HOL or something, although I think we're already in pretty big trouble if we want to do that.
I forgot that saw-core records are necessarily non-dependent. That might be a little inconvenient. I think there are a few places where Verifier.SAW.Cryptol
assumes dictionaries are records, but we can probably work around that.
I guess the other problem is that we wouldn't be able to have any law-breaking PEq
instances. The problematic issues with Float equality would be an issue here. Edit: on second thought, maybe it isn't an issue for floats, as long as we phrase it as an implication instead of an equivalence.
I think it actually is an issue for floats, isn't it? We have +0 == -0
for floats, but those values are not logically equal, so the implication doesn't hold. We should probably just make a separate predicate for law-abiding Eq instances, then.
I had a go at implementing some validity rules for equality predicates, which you can see on the ValidEq
branch (af4fe14186235a6387ae8ad73e4c703140d5c18d).
I think it actually is an issue for floats, isn't it? We have
+0 == -0
for floats, but those values are not logically equal, so the implication doesn't hold. We should probably just make a separate predicate for law-abiding Eq instances, then.
Yes, you're right. I was only thinking about NaN, but issue with signed 0 goes the other way.
The
ruleOfProp
operation examines the statement of a proposition and attempts to determine if it can be used as a rewrite rule. However, it is has a number of problems we should find some way to address.1) It is unsound. For example, if it encounters a term
vecEq n a f x y
it will assume this proves the equality ofx
andy
regardless of what functionf
is supplied. Similar forpairEq
. 2) It is incomplete. Some of the primitive equality-testing functions are missing, (e.g.intEq
,intModEq
), so these will not be recognized as rewrites. 3) It is error-prone. Item 2 seems pretty directly related to the fact thatruleOfProp
must be updated as we add new equality predicates on new types, and that hasn't been done yet.Possible solution: I think we would be better off restricting the class of theorems that are accepted as rewrite rules to address soundness. E.g., we should only accept statements of the form
Eq a x y
orecEq a peq x y
. Then, add axioms for convertingEq a
into the various primitive equality tests, and apply them when proving the equations to start with. E.g.