Re: [math-fun] We can't have mental gymnastics without a floor exercise.
WFL> On 1/14/14, Bill Gosper <billgosper@gmail.com> wrote: On 2013-12-06, at 9:36 AM, Adam P. Goucher wrote: Half-integers are rounded to the nearest even integer. Exercise: Write Round using only Floor, +, -, *, /, and of course, \[NotHumpDownHump]. --rwg (And please stay off the nonEuclidean parallel bars.) And what the San-Fairy-Ann does a \[NotHumpDownHump] look like --- assuming it can be persuaded to remain stationary for a period extended sufficiently to permit visual identification? <WFL Two squat Ωs humping belly-to-belly, under a slash to be more salacious. I can't find a UTF8(!), but unslashed is ≎. It's code 53 in http://www.dessci.com/en/support/mathtype/tech/encodings/mathmat3.htm "not geometrically equivalent". Non WFL>SPOILER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x -> 2[(2 x + 1)/4] < WFL No, Round[1] ≠ 0. So far, Julian has sent the only correct solution, albeit a bit homely. --rwg
Half-integers are rounded to the nearest even integer.
Exercise: Write Round using only Floor, +, -, *, /,
... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... 0. I assume we are allowed constants too. 1. So we can (very familiarly) almost do it with floor(x+1/2). This rounds up all half-integers, whereas we need to round half of them down instead. 2. So it's wrong by the sum of an infinite stream of delta functions. 3. We can get an infinite stream of deltas, but not quite the right ones, by considering floor(x)+floor(-x) which is -1 except at integers where it's 0. Call this G(x). 4. So -1-G(x) is 0 except at integers where it's -1. 5. We need something that's mostly 0 except at 1/2, 5/2, ... so the correction we need is -1-G(x/2-1/4). Putting it together, we get floor(x+1/2) - floor(x/2-1/4) - floor(1/4-x/2) - 1. Two minutes of Python confirms this (well, actually two minutes of Python originally showed that I'd made a sign error, but I fixed it up). -- g
participants (2)
-
Bill Gosper -
Gareth McCaughan