--
You received this message because you are subscribed to the Google Groups "London Computation Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to london-computatio...@googlegroups.com.
To post to this group, send an email to london-comp...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/london-computation-club/A4BB1449-5D5E-4685-906B-5D8F0859CF81%40codon.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web, visit https://groups.google.com/d/msgid/london-computation-club/D5018988-B439-4D1D-A3EF-E0103461FA30%40patuzzo.co.uk.
I’m doubtful how much it adds to what Chris has already said, but this is now live: https://github.com/computationclub/computationclub.github.io/wiki/Elements-of-Computing-Systems-Chapter-12
>> def divide(x, y)
return [0, 0] if y > x
y_next = 2 * y
q, qy2_next = divide(x, y_next)
qy2 = y_next + qy2_next
if (x - qy2) < y
return [2 * q, qy2]
else
return [2 * q + 1, qy2]
end
end
=> :divide
>> divide(95, 3)
=> [0, 186]
Cheers,
-Tom
--
You received this message because you are subscribed to the Google Groups "London Computation Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to london-computatio...@googlegroups.com.
To post to this group, send email to london-comp...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/london-computation-club/2d4deeb6-3573-4842-b726-0a061ca88e38%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/london-computation-club/B623013F-FE0E-4CE3-BE6E-6D1E325403D6%40geckoboard.com.
They don't claim in the book that there's a more efficient way to implement division in jack specifically, they just state that the pseudocode algorithm they provide is suboptimal. I'd imagine it is possible through the techniques Kevin and Leo describe.The reason it's suboptimal is because a multiplication takes O(n) operations where n is the number of bits in the numerator. Division can be achieved in O(n) as well but the pseudocode uses multiplication in each step which is itself an O(n) operation. (I guess this makes their algorithm O(n^2)?)The other multiplications are 2 * y and 2 * q, which can be achieved with a simple bit-shift.Is this correct, or have I misunderstood?Chris
That does sound feasible, even in Jack. Alternatively, am I right in thinking that the initial method call could allocate a single array, and pass it down through the recursive call stack? The method would effectively return void, and deliver both results via the two-element array.
Leo
On 27 Jul 2015, at 16:44, Kevin Butler <haq...@gmail.com> wrote:
It should be possible to pass down `qy2` and mutate a single reference during the entire computation. i.e. we return from `divide` the result of `divide_inner(0, 0, &mut 0)`.
On Monday, 27 July 2015 14:56:51 UTC+1, Tom Stuart wrote:On 24 Jul 2015, at 13:06, Kevin Butler <haq...@gmail.com> wrote:
> From how I understand this, `qy2` is the amount currently accounted for in the division, and the check is testing to see if the 'current level' fits within the remaining space. When there is space we return the quotient incremented an extra time, then to match this we bump up the cumulative value `qy2` by the current `y` (which at the higher level is `2 * y` in the old multiplication algorithm).
This is great, Kevin — thanks for getting to the bottom of it! Your code certainly looks like it works.
I wonder if this is really what they meant, i.e. returning multiple values from the recursive call? It seems slightly counterproductive to have to allocate/deallocate memory every time. Is that really more efficient than just doing the flippin multiplication? Is there some other way we’re missing?
Cheers,
-Tom--
You received this message because you are subscribed to the Google Groups "London Computation Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to london-computation-club+unsub...@googlegroups.com.
To post to this group, send email to london-comp...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/london-computation-club/2d4deeb6-3573-4842-b726-0a061ca88e38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "London Computation Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to london-computation-club+unsub...@googlegroups.com.