1

Is there syntax for rules such as:

P => P'
-----------
P + Q => P'

Or would I need to redefine the semantics with evaluation contexts?

There is a book on Big-Step SOS from 2010 on the Kframework website using old syntax:

crl < A1 / A2,Sigma > => < I1 /Int I2 >
if < A1,Sigma > => < I1 > /\ < A2,Sigma > => < I2 > /\ I2 =/= 0 .

It appears to do what I'm looking for, but I'm not sure if new syntax exists for it.

laifs
  • 197
  • 1
  • 2
  • 11
  • 1
    The syntax you're using is from Maude, not from K. So this may be from the old KMaude backend, which hasn't been around/maintained for years. Maude allows specifying rewrite side-conditions in the `if ...` clause (the equivalent of K's `requires ...` clause), so that you can say that `< A1, Sigma > => < I1 >` is a side-condition of the original expression. – ehildenb Apr 30 '20 at 19:44
  • 1
    K does not support this directly right now, but there are ways to get the same behavior by saving off the current context, evaluating `A1` in it, then evaluating `A2` in it, then combining the results. – ehildenb Apr 30 '20 at 19:46

1 Answers1

1

You could do something like this (psuedocode):

configuration <k> $PGM </k>
              <state> WHATEVER_YOUR_STATE_IS </state>

syntax KItem ::= evaluateInContext ( Exp , StateCell )
syntax Exp ::= Exp "/" Exp | "HOLE1" | "HOLE2" | Value
syntax Value ::= Int

rule <k> A1 / A2 => evaluateInContext(A1, <state> STATE </state>) ~> evaluateInContext(A2, <state> STATE </state>) ~> HOLE1 / HOLE2 ... </k>
     <state> STATE </state>

rule <k> evaluateInContext(A, <state> STATE </state>) => A ... </k>
     <state> _ => STATE </state>

rule <k> V:Value ~> evaluateInContext(A, S) => evaluateInContext(A, S) ~> V ... </k>

rule <k> V:Value ~> V':Value ~> HOLE1 / HOLE2 => V' /Int V ... </k>

So you can always pass around configurations as first-class citizens.

An example of this is in KEVM, where we use this sort of mechanism to save/retrieve a list of callstacks.


Update to address comment.

If you want to check that a subterm makes a state transition, you can change it to something like this (psuedo-code again):

syntax KItem ::= "evaluated?" "(" Exp "," State ")" 
rule <k> evaluateInContext(A, <state> STATE </state>) => A ~> evaluated?(A, <state> STATE </state> ... </k>
     <state> _ => STATE </state>

rule <k> V:Value ~> evaluated?(A, <state> STATE </state>) => DO_SOMETHING_WHEN_EVALUATED ... </k>
rule <k> NOT_VALUE:Exp ~> evaluated?(A, <state> STATE </state>) => DO_SOMETHING_WHEN_NOT_EVALUATED ... </k>

Note that here I'm using "has reduced to sort Value" to determine if it's "evaluated", but you can of course have any side-condition you like for determining that.

ehildenb
  • 316
  • 1
  • 5
  • Thank you for the answer. This is very useful, particularly the state part. Would this help if I have, say, a term `A | B` and want `A | B => A'` if `A` can make a transition `A -> A'`? Another part of my problem is checking whether a sub-term can make a transition. – laifs May 01 '20 at 01:11
  • 1
    Yes, it's possible, but once again you need to build the machinery yourself. I've updated the answer to address your comment. – ehildenb May 01 '20 at 09:36