kframework / k-legacy

The K tools (deprecated, see README)

Home Page:http://kframework.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rule Encoding in Kore

msaxena2 opened this issue · comments

A rule in Legacy kore is translated into Kore as follows (pasted verbatim from the codebase) -

    case definition.Rule(body, requires, ensures, att) =>
      val r = apply(requires)
      val ab = apply(body)
      val e = apply(ensures)
      val p = b.Implies(r, b.And(ab, b.Next(e))) // requires  ->  body  /\  \next ensures
      Rule(p, Attributes(apply(att)))

or in other words

(lhs ^ requires) => rhs ^ ensures is translated as 

requires -> ((lhs => rhs) ^ o(ensures))

This translation may not be correct, based on the short discussions I had with @grosu and @lucaspena . Even though this doesn't affect K's working at the moment, we might want to ensure that the Kore we get at the end of the kompile pipeline is correct.

That translation seems strange to me. Can't we simply translate it to: lhs AND requires => rhs AND ensures? At least that's what the Scala backend expects.

I admit that the translation is not correct. I realized the problem soon after I encoded it in that way, but I postponed fixing it since I wanted to think/discuss more about the reasonable solution (but sorry I hadn't have a chance to do it.)

The thing is that the correct encoding is not trivial. Note that the body is not necessarily simply in the form of lhs => rhs; the => can appear locally in multiple places.

Feel free to discuss and fix the encoding if you want.

What is wrong with the obvious desugaring, that is, lhs => rhs gets desugared to Implies(lhs,next(rhs)) ?

When the rewrites are local, I think the correct translation is to simply leave them there. Unless I'm missing some subtlety, body AND (requires => ensures) should work in all cases.

As a side note, in the next few days I will merge local rewriting functionality for the Scala backend, so we won't even have to move the rewrites to the top.

@grosu Your encoding seems to work, although I haven't thought about it that much. But, my original question is how to incorporate the requires and ensures that are not local. Indeed, I should admit that I didn't think about it that much, so there could be a simple encoding that works.