[math-fun] sum of binary digits
I believe the TX-0, originally lacking an add instruction, did xor foo cry foo /carry foo instead --rwg "The TX-0 (“Transistor eXperimental - 0”) is the first general-purpose programmable computer built with transistors. For easy replacement, designers placed each transistor circuit inside a "bottle," similar to a vacuum tube. Constructed at MIT´s Lincoln Laboratory, the TX-0 moved to the MIT Research Laboratory of Electronics, where it hosted some early imaginative tests of programming, including writing a Western movie shown on television, 3-D tic-tac-toe, and a maze in which a mouse found martinis and became increasingly inebriated." I can't easily find a color closeup, but the bottles were plastic and color-coded with a disk divided into quadrants. Conceptual holdovers from resistors as well as vacuum tubes (not yet derided as "fire-bottles"). I think the bottles were clearly visible in a circa 1960 Fortune Magazine article on MIT, featuring a large image of Claude Shannon in front of a TX-0 bay festooned with punched tape no doubt by the dunce photographer. You might wonder why transistors needed easy replacement. The melting point of germanium was way lower than the plastic! Silicon came later. (Thank God it did; I'd hate to live in Germanium Valley.) Hopefully, Ed Fredkin still has (or at least has digitized) his precious poster (from a GE cafeteria?) of an ugly, cowering little transistor about to be crushed by an Art Deco shoe. Caption: "Stamp them out!" Back then Fredkin had a huge TV PR fail when he predicted a nanotech robot barber that lived in your hair and maintained your expensive haircut by memorizing each hair's length. On 2016-06-03 09:16, Joerg Arndt wrote:
* rcs@xmission.com <rcs@xmission.com> [Jun 03. 2016 08:44]:
[...] Probably we can do something with (a&b) + (a|b) = a+b, and a+b = (a^b) + 2(a&b). Maybe v(a+b) <= v(a^b) + v(a&b).
From a+b = (a^b) + 2(a&b) we get (a+b)/2 = (a^b)/2 + (a&b) so
static inline ulong average(ulong x, ulong y) // Return floor( (x+y)/2 ) // Result is correct even if (x+y) wouldn't fit into a ulong // Use: x+y == ((x&y)<<1) + (x^y) // that is: sum == carries + sum_without_carries { return (x & y) + ((x ^ y) >> 1); // return y + ((x-y)>>1); // works if x>=y }
Similarly
ulong ceil_average(ulong x, ulong y) // Return ceil( (x+y)/2 ) // Result is correct even if (x+y) wouldn't fit into a ulong // Use: x+y == ((x|y)<<1) - (x^y) // ceil_average(x,y) == average(x,y) + ((x^y)&1)) { return (x | y) - ((x ^ y) >> 1); }
Best regards, jj
Rich
[...]
participants (1)
-
Bill Gosper