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

Improved Property Syntax #81

Open
DavePearce opened this issue Aug 24, 2020 · 0 comments
Open

Improved Property Syntax #81

DavePearce opened this issue Aug 24, 2020 · 0 comments

Comments

@DavePearce
Copy link
Member

DavePearce commented Aug 24, 2020

Currently, the syntax for properties is pretty awful. Here's an example from the standard library:

// Check if two arrays equal for a given subrange
public property equals<T>(T[] lhs, T[] rhs, int start, int end)
// Arrays must be big enough to hold subrange
where |lhs| >= end && |rhs| >= end
// All items in subrange match
where all { i in start..end | lhs[i] == rhs[i] }

The essential point of properties (as it stands) are that they receive special status within the theorem prover. Specifically, properties can be inlined during the verification process. This provides significant additional expressivity over functions which are treated as uninterpreted during verification. In some sense, properties are like macros. Key points arising:

  • Properties vs Functions. What is the essential difference here? One difference is that a function can hide its implementation (and, hence, change it at a later date). There are examples within the standard library (e.g. in std::array) with vaguely non-trivial implementations.
  • Expression Syntax. The most obvious way to improve the syntax of properties is to allow an expression body. Combined with e.g. conditional expressions or general terms (Term Language? #80), this makes them quite powerful. A key arises around what restrictions (if any) should be placed on properties. Currently, properties can be recursive but, obviously, cannot contain loops. Should we allow them to contain loops?
  • Specification Elements. Currently, properties cannot have pre-conditions or post-conditions. Does this still make sense?

Example 1

property sum(int[] arr, int i) -> int:
    if i >= |arr|:
        0
    else:
        arr[i] + sum(arr,i+1)

Example 2

type Link is { int data, LinkedList next }
type LinkedList is null | &Link

property disjoint(LinkstList l1, LinkedList l2):
    if l1 is null || l2 is null:
       true
    else:
       l1 != l2 && disjoint(l1->next, l2)

This is an interesting example as I'm trying to use a property in an impure fashion.

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

1 participant