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

Can't use generate for length 2^^n with index [n] #1291

Closed
brianhuffman opened this issue Sep 24, 2021 · 2 comments · Fixed by #1293
Closed

Can't use generate for length 2^^n with index [n] #1291

brianhuffman opened this issue Sep 24, 2021 · 2 comments · Fixed by #1293
Assignees
Labels
typechecker Issues related to type-checking Cryptol code.

Comments

@brianhuffman
Copy link
Contributor

I was trying to use left-hand-side indexing to define a list of length 2^^n using a perfectly-sized index of type [n]. Here's a simplified version of my function definition:

table : {n, a} (fin n) => ([n] -> a) -> [2^^n]a
table f @ i = f i

But cryptol rejects this with a type error message:

[error] at Temp.cry:2:1--2:18:
  Failed to validate user-specified signature.
    in the definition of 'Main::table', at Temp.cry:2:1--2:6,
    we need to show that
      for any type n, a
      assuming
        • fin n
      the following constraints hold:
        • n >= width (max 1 (2 ^^ n) - 1)
            arising from
            use of expression generate
            at Temp.cry:2:1--2:18

Using perfectly-sized index types like this is one of the reasons for introducing left-hand-side indexing in the first place. We should make this work.

@brianhuffman
Copy link
Contributor Author

#704 seems related.

@brianhuffman brianhuffman added the typechecker Issues related to type-checking Cryptol code. label Sep 24, 2021
@brianhuffman
Copy link
Contributor Author

By the way, it seems like the type checker ought to be able to simplify max 1 (2 ^^ n) to just 2 ^^ n.

@yav yav self-assigned this Sep 27, 2021
yav added a commit that referenced this issue Sep 27, 2021
max 1 (a ^ n) ~> a ^ n    (for a >= 1)
width (2 ^ n - 1) ~> n

Fixes #1291
@yav yav closed this as completed in #1293 Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typechecker Issues related to type-checking Cryptol code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants