Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invariants over next states #6

Closed
ekiwi opened this issue Apr 20, 2019 · 2 comments
Closed

Invariants over next states #6

ekiwi opened this issue Apr 20, 2019 · 2 comments

Comments

@ekiwi
Copy link
Contributor

ekiwi commented Apr 20, 2019

Is there a way to include the next state of a signal in an invariant.

For example, let's say I want to prove termination of a system through the invariant that a counter is always decreasing. Trying to write an invariant like this gives me a syntax error:

invariant counter_decreases : counter < counter';

Is there a different way to express this?

@pramodsu
Copy link
Contributor

One can't refer to the next state, but it is possible to refer to the previous state of the variable n using the expression past(n). This is more or less equivalent. Here a model similar in spirit to what you want to do:

module main
{
    var n : integer;
    var inited : boolean;

    init {
        assume (n > 0);
        inited = false;
    }
    
    next {
        n' = n - 1;
        inited' = true;
    }

    invariant n_decreases: inited ==> (n < past(n));

    control {
        v = unroll(10);
        check;
        v.print_results;
        // v.print_cex(n);
    }
}

Note we need the flag inited because past(v) is undefined in the initial state so it ends up taking unconstrained values.

Also past(v) is just an abbreviation for history(v, 1); history(v, n) returns the value of the variable v, n steps ago. n must be an integer literal. We don't allow history(v, n) where n is a variable of type integer. Like past, it is undefined for the first n - 1 steps of the system.

@ekiwi
Copy link
Contributor Author

ekiwi commented Apr 20, 2019

That's great! Thank you pramod!
I wasn't aware of the past and history functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants