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

width issue in manual and help text #931

Closed
martin-d2 opened this issue Oct 13, 2020 · 2 comments
Closed

width issue in manual and help text #931

martin-d2 opened this issue Oct 13, 2020 · 2 comments
Labels
docs LaTeX, markdown, literate haskell, or in-REPL documentation

Comments

@martin-d2
Copy link

Hi Galois, it's me again! 😁

I might have got completely the wrong end of the stick here, but I think I might have found a couple of super minor errors in the manual and Cryptol help text. Hopefully easy to fix β€” or equally likely explain what I've misunderstood!

For the width function, the manual says width is (lg2 rounded up) but what seems to be being calculated is:
(lg2 (arg+1))
i.e., it seems to increment the argument and then take the lg2, rather than taking the lg2 and then rounding up the answer. To me, the description of the function in the manual gives the wrong answer if arg is a power of 2.

Also, on page 70 the manual incorrectly says "Note that lg2 is the floor log base 2 function."

Separately, In the help text: :? lg2 says lg2 n = width (max 1 n-1).
This doesn't seem to be the case, because lg2 1 = 0 but width (max 1 0) = width 1 = 1.

Any thoughts?

Thanks for all your amazing work on Cryptol :-)

Martin

@brianhuffman brianhuffman added the docs LaTeX, markdown, literate haskell, or in-REPL documentation label Oct 13, 2020
@brianhuffman
Copy link
Contributor

That description of width in appendix F of the book is indeed wrong, as width is not just "lg2 rounded up", but rather lg2(x+1) as you say. We should also adjust the entry for lg2 in appendix F to say that it's the ceiling of the base-2 log. We should also fix the REPL help text for the lg2 type operator, which is both unhelpful and is not a full sentence ending with a period like all the other help texts are:

Cryptol> :? lg2

    type lg2 n = width (max 1 n - 1)

Define the base 2 logarithm function in terms of width

As to the other point, your confusion about lg2 n = width (max 1 n - 1) seems to be due to you misparsing it as width (max 1 (n - 1)) instead of width ((max 1 n) - 1). The intention is that we want lg2 n = width (n - 1), but we want to avoid the undefined subtraction for n = 0, so we replace n with max 1 n. The help text for lg2 n should probably explicitly say that lg2 n = width (n - 1) for nonzero n.

brianhuffman pushed a commit that referenced this issue Oct 13, 2020
@brianhuffman brianhuffman mentioned this issue Oct 13, 2020
brianhuffman pushed a commit that referenced this issue Oct 13, 2020
This is one of the errors mentioned in issue #931.
@martin-d2
Copy link
Author

Brilliant, thanks for the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs LaTeX, markdown, literate haskell, or in-REPL documentation
Projects
None yet
Development

No branches or pull requests

2 participants