Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

10 clarifications #47

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

Merged
justinmeiners merged 17 commits into master from 10-clarifications
Dec 30, 2021
Merged

10 clarifications #47

justinmeiners merged 17 commits into master from 10-clarifications
Dec 30, 2021

Conversation

Copy link
Owner

@justinmeiners justinmeiners commented Dec 14, 2021

Copy link
Owner Author

justinmeiners commented Dec 14, 2021
edited
Loading

@aharrison24 Here is an initial pass which mostly fixes typos and footnotes with your recommendations. I am still working on the larger reorg!

Please bring them up if you think things should be different. I think everything we talked about, but I did remove some details from the Dirichlet proof footnote.

Copy link
Contributor

aharrison24 commented Dec 14, 2021
edited
Loading

I've gone ahead and read chapter 11 and had a good think about the algorithm. I think I have a reasonable understanding of what's going on now. There are certainly some things I would have appreciated knowing sooner. I've mentioned most of them in my in-line comments.

A couple of minor extra things: In the add_to_counter algorithm it would be helpful to clarify that carry is the element to be inserted and op is a binary operation such as min or max that returns one of its two inputs.

I also think it would be very valuable to have a slightly extended example of how the counter works, where multiple elements are inserted. You could do an example where the elements are characters and the binary operator is min, for instance. 'zero' could be a space character. You could push in 8 letters in an order that causes multiple slots to be occupied at the end. You can use that to show that the counter only needs log2(8) = 3 slots. You can also show that after all the elements have been inserted, the job isn't yet finished. This justifies the need for the reduce_counter operation, which performs all the remaining comparisons to get to a single 'winner'. I think that's important, because with the text as it is currently, the reduction step is never really justified. It's just presented as something that is necessary.

Copy link
Contributor

I also realised that nowhere is it explicitly stated that the counter starts out empty and has elements pushed in to it one at a time.

justinmeiners and others added 6 commits December 14, 2021 18:52
Co-authored-by: Alastair Harrison <aharrison24@gmail.com>
Co-authored-by: Alastair Harrison <aharrison24@gmail.com>
Co-authored-by: Alastair Harrison <aharrison24@gmail.com>
Co-authored-by: Alastair Harrison <aharrison24@gmail.com>
I pick this algorithm because it allows us to learn how to do decomposition
and learn these components like `list_pool` and `binary_counter` along the way.

Let me sketch the grand plan of the whole alogorithm.
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021

Choose a reason for hiding this comment

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

This information was completely missing before. This explains that we will use the linked list to store histories, and that it doesn't effect the binary_counter implementation.

aharrison24 reacted with thumbs up emoji
Copy link
Contributor

@aharrison24 aharrison24 Dec 15, 2021

Choose a reason for hiding this comment

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

This is really good!


Let us assume we have elements of type `T` that need to be paired or combined in some way,
whether with `min`, `+`, `merge`, or any other assocative operation on `T`.
What we can do is create an array called a "counter".
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021

Choose a reason for hiding this comment

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

This information now reinforces that we are talking about generic element T with generic operation.

If there is a guy in slot 2 he has won 2 games, and so on.
This structure will help us to only pair up elements that have the same power.

The following example using `min` as the operation should make this clear.
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021
edited
Loading

Choose a reason for hiding this comment

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

This specific example uses the min operation so we can more clearly talk about winners and losers.

0 1 ... 31 0 1 ... 31
x 0 ... 0 --> 0 y ... 0

Otherwise `x` wins:
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021

Choose a reason for hiding this comment

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

Example corrected.

y 0 ... 0 --> x 0 ... 0
What if the counter is full, and has no zero slots?
That's called an an **overflow**.
There is a close analogy between our counter and binary integer counting:
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021

Choose a reason for hiding this comment

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

Analogy between the two stated more clearly.

**Exercise:** If you want to implement [merge sort][merge-sort] you can use exactly the same device, since merge is associative. The idea with merge sort, is you only want to merge lists if they are roughly the same length and this helps you do it (see Chapter 12).
Write the associtative binary operation `merge` which can combine two sorted arrays into a sorted array.

**Exercise:** When we become grownups we learn about advanced data structures, such as [binomial forest][binomial]. They use the same idea. Learn about this data structure and try to figure out where
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021
edited
Loading

Choose a reason for hiding this comment

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

These other examples have been moved to exercises.

Copy link
Owner Author

I just finished the "big" revision and I think I have been able to address most of your comments. I went back to the videos to review this section and found some helpful comments I missed which address many of your concerns.

I have added comments to this code here indicating specific resolutions to concerns.
Once again, I really appreciate you working through this with me.

Copy link
Owner Author

justinmeiners commented Dec 15, 2021
edited
Loading

it would be very valuable to have a slightly extended example of how the counter works

I think that's a great idea, and added it to issue #48 .

@@ -451,8 +460,12 @@ Notice that zero is `const T&` reference because we don't plan to modify it,
but we do modify carry,
so it should be passed by value.

The second function applies the operation
to all the elements left sitting in the counter.
After we finish adding all our elements to the counter, they might not all be reduced to one element.
Copy link
Owner Author

@justinmeiners justinmeiners Dec 15, 2021

Choose a reason for hiding this comment

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

This justifies the need for the reduce_counter operation and is a quote from Alex.

Copy link
Contributor

@aharrison24 aharrison24 left a comment

Choose a reason for hiding this comment

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

This is all looking really good! I haven't had a chance to re-read both chapters from beginning to end. Will try to do that soon.

I pick this algorithm because it allows us to learn how to do decomposition
and learn these components like `list_pool` and `binary_counter` along the way.

Let me sketch the grand plan of the whole alogorithm.
Copy link
Contributor

@aharrison24 aharrison24 Dec 15, 2021

Choose a reason for hiding this comment

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

This is really good!

justinmeiners and others added 2 commits December 29, 2021 19:12
Co-authored-by: Alastair Harrison <aharrison24@gmail.com>
Co-authored-by: Alastair Harrison <aharrison24@gmail.com>
Copy link
Owner Author

justinmeiners commented Dec 30, 2021
edited
Loading

I have resolved those comments you left. I am going to merge this in for now as it is a significant improvement. Let's start a new PR for additional fixes if needed. (I will review your issue again.)

@justinmeiners justinmeiners merged commit ffbc54f into master Dec 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@aharrison24 aharrison24 aharrison24 left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /