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

Primitive scanl #1303

Merged
merged 7 commits into from
Dec 7, 2021
Merged

Primitive scanl #1303

merged 7 commits into from
Dec 7, 2021

Conversation

robdockins
Copy link
Contributor

This PR changes scanl to a primitive instead of a defined value in the Prelude. In addition, a few other definitions in the Prelude were reimplemented to use foldl or scanl instead of being directly recursive.

These changes are primarily intended to support the Cryptol->Coq extraction use case in SAW. That extraction currently has no way to translate recursive Cryptol programs, so it is useful to avoid them for basic functionality exposed via the Prelude. With this PR the sortBy function is the only remaining recursive definition in the Prelude.

Copy link
Contributor

@brianhuffman brianhuffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have something in the test suite that checks, for both concrete and symbolic evaluation, that the implementations of foldl and scanl match the behavior specified by their original definitions. (Actually, we should have such tests for all primitives—see #48—but we can start by making tests for new primitives as we add them.)

in the prelude to use `foldr` or `scanl`.

This leaves `sortBy` as the only remaining operation in the Cryptol
prelude defined directly by recursion.
It is convenient for Coq extraction for the constant 1 factor
to be on the left of the addition symbol.
`scanl` and `iterate` to their primitive implementations.
This speeds up concrete computation and preserves sharing for
symbolic computation.
@robdockins robdockins merged commit 435bb81 into master Dec 7, 2021
@robdockins robdockins deleted the primitive-scanl branch December 7, 2021 23:00
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

Successfully merging this pull request may close these issues.

2 participants