HOL-Theorem-Prover / HOL

Canonical sources for HOL4 theorem-proving system. Branch develop is where “mainline development” occurs; when develop passes our regression tests, master is merged forward to catch up.
https://hol-theorem-prover.org
Other
616 stars 138 forks source link

Add a ‘while’ constant to state_transformer theory #31

Closed mn200 closed 11 years ago

mn200 commented 12 years ago

There is a natural notion of while loop for state monads. With our do notation, you'd like to have it satisfy the following theorem:

while guard body = 
  do 
     gval <- guard;
     if gval then 
        do 
          body;
          while guard body
        od
     else return ()
  od

I think it should be possible to define this in terms of our existing WHILE combinator. Something like

mwhile g b = SND (g (WHILE (FST o g) (SND o b o SND o g)))
mn200 commented 11 years ago

To make this type-check, you actually need:

Define`
  mwhile g b = SND o g o WHILE (FST o g) (SND o b o SND o g)
`;

This is a version of the notion that allows for a side-effecting guard g.

The issue is that this can’t be made to satisfy the desired “monadic” characterisation because of problems when it’s undefined. In particular, this definition calls WHILE on the initial state, but the characterisation calls the guard first, and then calls itself recursively on the resulting state.