0

Can I use Coq to prove that a state machine cannot reach an invalid state? How?

Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57

2 Answers2

4

Here is how to translate stm from here to Coq.

Require Import Coq.Lists.List.                                                                                                                                                                

Inductive alpha : Set := A | B | C | D.

Fixpoint s1 (xs : list alpha) : bool :=
  match xs with
    | C :: rest => s2 rest
    | _ => false
  end

with s2 (xs : list alpha) : bool :=
  match xs with
    | nil => true
    | A :: rest => s2 rest
    | B :: rest => s2 rest
    | C :: rest => s3 rest
    | _ => false
  end

with s3 (xs : list alpha) : bool :=
  match xs with
    | D :: rest => s2 rest
    | _ => false
  end.

Here is the theorem stating that STM can't reach invalid state:

Theorem t : forall xs, s1 xs = false.

But obviously it is not true for this STM. In general case it could be proved by induction.

It will be easier to help you if you provide some more information on what is your actual state machine.

Community
  • 1
  • 1
max taldykin
  • 12,459
  • 5
  • 45
  • 64
-1

This seems more a question for a model checker than for a theorem prover.

There has been the question Can Coq be used (easily) as a model checker? about this, and there indeed is some work about using Coq as a model checker, see for example https://github.com/coq-contribs/smc, but it is probably not easy to use this for what you want to do.

Community
  • 1
  • 1
Freek Wiedijk
  • 481
  • 1
  • 3
  • 15
  • While this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Baum mit Augen Jan 20 '17 at 17:28
  • The answer essentially is: there is some work in this respect, but not really something that really is being applied. I'll edit my answer. – Freek Wiedijk Jan 20 '17 at 17:31
  • @baum-mit-augen Is my edited answer better? I hate it that I now have a -1 answer in my list, but do not know what to do about it. I would like to fix this! – Freek Wiedijk Jan 21 '17 at 08:15
  • Let me chime in -- I think you can make your answer into a great one by providing a (minimalistic) working example of how to use the library you gave the link to. – Anton Trunov Jan 21 '17 at 20:57