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

saw-core terms stemming from accessing sequences with @ in Cryptol contain seemingly avoidable ites #1333

Open
nano-o opened this issue Jun 11, 2021 · 4 comments
Labels
usability An issue that impedes efficient understanding and use

Comments

@nano-o
Copy link
Contributor

nano-o commented Jun 11, 2021

The following saw-core term contains a trivial ite that checks whether the access is within bounds. Those terms can be annoying in proofs because the ite term often needs to be hoisted out before applying rewrites.
It seems that it would be easy to determine statically that the access is within bounds. Could this be implemented?

(rewrite (cryptol_ss ()) {{ \(x:[2]) -> x@1 }})

results in:

let { x@1 = Prelude.natToInt 1
    }
 in \(x : Prelude.Vec 2 Prelude.Bool) ->
      Prelude.ite Prelude.Bool
        (Prelude.intLe (Prelude.natToInt 0) x@1)
        (Prelude.at 2 Prelude.Bool x (Prelude.intToNat x@1))
        (Prelude.at 2 Prelude.Bool x 0)
@robdockins
Copy link
Contributor

The normalize_term function I've been working on (CF #1310) does a pretty good job with this.

sawscript> enable_experimental
sawscript> normalize_term {{ \(x:[2]) -> x@1 }}

[18:22:40.537] \(x : Prelude.Vec 2 Prelude.Bool) ->
  Prelude.at 2 Prelude.Bool x 1

The trick going forward will (I think) be keeping the normalization routine from doing more computation than you want.

@msaaltink
Copy link
Contributor

The feature of issue #1001 would also address this problem, if it were ever implemented.

@RyanGlScott
Copy link
Contributor

As a workaround, one can write x @ (1 : [8]) (or whatever bitvector type you prefer) to avoid the use of Integer.

@nano-o
Copy link
Contributor Author

nano-o commented Jun 21, 2021

Thanks! I've been using x1 where [x1,_] = x.

@robdockins robdockins added the usability An issue that impedes efficient understanding and use label Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usability An issue that impedes efficient understanding and use
Projects
None yet
Development

No branches or pull requests

4 participants