1

Does K have a notion of global state that rules can access? e.g. Say a configuration C => C'. I want to transition iff C' doesn't exist in a set of explored states, and then update the global set of explored states by adding C'to it.

I'm trying to explore all reachable states of a program non-deterministically (using the --search option). However, each path explored is independent, which means each path would not be aware of configurations seen in the other paths if I were to pass the explored set in the configuration itself.

If there's no global state, what's the best practice for this kind of behaviour? Is there a way to non-deterministically explore transitions within some bigger environment that each independent path is able to access?

laifs
  • 197
  • 1
  • 2
  • 11

1 Answers1

1

You can always emulate this behavior yourself if needed, but it is quite cumbersome and a little bit error prone:

configuration <myConfig>
                <k> $PGM:Pgm </k>
                <someOtherCells> .SomeOtherSort </someOtherCells>
              </myConfig>
              <states> .List </states>

syntax Pgm ::= "saveConfig" | "loadConfig" Int | "isExplored?"

syntax Bool ::= "#isExplored?" "(" MyConfigCell "," List ")"

rule <myConfig> <k> saveConfig => . ... </k> ... </myConfig> #as CONFIGURATION
     <states> ... (.List(CONFIGURATION)) </states>

rule (<myConfig> <k> loadConfig IDX ~> REST </k> ... </myConfig> => STATES[IDX])
     <states> STATES </states>
  requires IDX <Int size(STATES)

rule <myConfig> <k> isExplored? => #isExplored?(CONFIGURATION, STATES) ... </k> ... </myConfig> #as CONFIGURATION
     <states> STATES </states>

Then you need to provide the definition of whether a state has been explored or not via #isExplored? function. Direct equality may work (using ==K) but likely not. Chances are you want to only actually compare some subset of the cells there.

Unfortunately, this state-folding functionality is not built into the Haskell backend yet. It could, of course, automatically check every new visited state to see if it's one that has been explored before, and if so stop searching on that execution path. If you need this functionality, please open an issue at https://github.com/kframework/kore repository, and explain your use-case. No promises on it being implemented soon, but it would be nice for us to know how people want to use the tool.

ehildenb
  • 316
  • 1
  • 5
  • Thanks for the reply. For clarification, if I'm passing the explored states with the configuration, if there were multiple paths explored, wouldn't they be unaware of the explored states in the other paths? For instance, if one has two paths, say A and B, path A reaches A1 and A2, whereas path B reaches B1 and A2. My understanding is that A and B will be explored independently, maybe one some time before the other, but both will eventually be expanded. At this point, if only the configuration holds the explored states, the other path wouldn't know about A2 having been expanded. – laifs May 18 '20 at 22:12
  • 1
    You're right that A and B will be explored independently. You can restructure your semantics so that there is no branching, and you control which execution paths are explored at all time, but that can be very cumbersome. So your semantics would have to have an extra cell which says which rule it will try next, and what to do if that rule cannot apply (via an `owise` rule). You'll have to make sure you try all the rules in order, and store off states when it makes sense. – ehildenb May 20 '20 at 07:35
  • 1
    K has a `STRATEGY` module in `domains.k` for exactly this purpose, you can see a detailed example of using it here: https://github.com/kframework/kat. The `` cell lets you control which rules to try and in what order, and what to do when the semantics gets stuck, which lets us emulate the branching `--search` execution with a single line of execution which stores and restores states as needed. Honestly though, I would _not_ recommend this approach, it is very tricky to get right. Better to have native backend support for state folding. – ehildenb May 20 '20 at 07:37