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

Ability to use sets in forall and exists #356

Open
byorgey opened this issue Nov 12, 2022 · 3 comments
Open

Ability to use sets in forall and exists #356

byorgey opened this issue Nov 12, 2022 · 3 comments
Labels
C-Project A larger project that may take multiple days. S-Nice to have Minor importance U-Language Design U-Testing Z-Feature Request

Comments

@byorgey
Copy link
Member

byorgey commented Nov 12, 2022

We have considered and rejected some ideas to broadly identify types and sets (#290, #282, #348). However, I wonder if there are some more limited things we could do that would be convenient. One such idea is to allow using finite set values as the domain of a forall or exists (perhaps using a different syntax to distinguish them). Like this:

A : Set(N)
A = {1 .. 10}

b : Bool
b = forall a in A. a^2 <= 100

As opposed to forall x : T. e where T must be a type and the whole expression has type Prop, forall x in X. e would have the same type as e as long as X : Set(T) and e has type Bool or Prop under the assumption x : T.

This would certainly be convenient. Right now even if you write something like forall x : N. (x <= 10) -> ... it will still try a bunch of values of x greater than 10, and it won't be able to tell you that it has exhaustively tested all the possibilities. On the other hand this might just be confusing for students.

@byorgey
Copy link
Member Author

byorgey commented Jan 26, 2023

Started thinking about this a bit. I immediately ran into the issue of how to represent this in the syntax: right now we unify lambdas, forall, and exists under the same umbrella, and binders are patterns. If we just allow this anywhere we could have stuff like \x in A. ... but I'm not sure what that should mean.

@byorgey
Copy link
Member Author

byorgey commented Feb 28, 2023

What if we just make x in A be a pattern, which matches (binding x) on anything which is an element of A. Then \x in A. ... would actually make sense although we wouldn't really want to use it, I suppose.

Hmm... we would need to allow <var> in <expr> as a pattern, where <expr> could be any expression, not just a pattern. If e : Set(T) then x in e : T. Matching against x in e would desugar to something that evaluated e exactly once, binding the result to y, then used a guard with x elem y.

@byorgey
Copy link
Member Author

byorgey commented Mar 28, 2023

I now have parsing and desugaring working in the feature/quantify-over-sets branch. However, testing doesn't work, and indeed, quantifiers with patterns don't really work at all. Currently, with the default desugaring, forall P(x). Q desugars to something like forall y:T. {? Q when y is P(x) ?} (where T is the type of the pattern P(x)), which does not have the right semantics. (exists has the same issue.) For example, forall x in {1,2,3}. x < 5 just tries all natural numbers and crashes when it happens to try a natural number that is not in the set {1,2,3}.

Clearly we need to treat patterns under forall and exists differently than patterns under lambdas. Should this happen in the desugarer?

@byorgey byorgey added C-Project A larger project that may take multiple days. and removed C-Moderate Effort Should take a moderate amount of time to address. labels Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Project A larger project that may take multiple days. S-Nice to have Minor importance U-Language Design U-Testing Z-Feature Request
Projects
None yet
Development

No branches or pull requests

1 participant