News for hackers. Stuff that matters.
Re:Negative Base by msoucy on Thursday June 28, 2018 @09:33AM (#17416689)
When I was part of an organization in college, part of the onboarding process was that each applicant had to have a conversation and (possibly) do a "quest" for each member. My standing quest was that I would write the first 12 or so numbers in negabinary on my whiteboard, and have them determine the next few numbers and explain what they meant. I had people sitting outside my room for hours trying to figure it out. A few did do it, and normally had some expletives for me afterward.
Re:Negative Base by bhrgunatha on Thursday June 28, 2018 @10:28AM (#17417126)
Looking at the table is bad enough, but I imagine most people looking would think "Aaah binary" and convert to decimal: 1, 6, 7, 4, 5, 26, 27, 24, 25, 30, 31, 28... That's cruel :)
Re:Negative Base by msoucy on Thursday June 28, 2018 @10:49AM (#17417275)
I probably got a little too much sadistic pleasure out of it, yes...

However, I was always willing to answer nontrivial questions, and even convert numbers to/from negabinary to help them. (The program used the Schroeppel2 implementation, to prevent them from getting too much of a clue if they somehow managed to find its source code)

Re:Negative Base by soVeryTired on Thursday June 28, 2018 @11:17AM (#17417556)
Looking at the sequence of negabinary representations, I could imagine (with the benefit of hindsight) that it wouldn't be too hard to guess the next numbers in the sequence. You'd just need to make a few observations: the rightmost digit always flips from 1 to 0. The second digit from the right reads one twice, then zero twice, etc. When you increase the length of the sequence, add two leading ones.

I'm not sure those would be enough, but just inspecting the digit-wise patterns would get you pretty far. Correctly interpreting the sequence is far harder!

Re:Negative Base by msoucy on Thursday June 28, 2018 @04:47PM (#17420351)
Yup, the actual challenge was to interpret the sequence, not just produce the next number. I recall a few people starting on that track though.
Re:Negative Base by xelxebar on Thursday June 28, 2018 @06:12PM (#17420918)
Reading those as normal binary, apparently there's significant overlap between the negabinary sequence and the sequence of n XOR 10:

https://oeis.org/search?q=1%2C+6%2C+7%2C+4%2C+5%2C+26%2C+27&...

Re:Negative Base by rocqua on Thursday June 28, 2018 @02:18PM (#17419234)
It seems to me like the n-th number repeats 2^n times, with 1 being in the middle of each sequence. From this, you could get the 13th number quite easily. Interpreting it would be a lot more difficult though.

Interestingly, normal binary has the same pattern, but with different offsets for the start of the sequence.

Re:Negative Base by macintux on Thursday June 28, 2018 @10:15AM (#17417005)
I bet they were frustrated. I was thinking of the various puzzles online trying to understand a sequence of numbers when I read about this, and realizing there's no way I'd ever have come up with the answer on my own.
Re:Negative Base by JdeBP on Thursday June 28, 2018 @09:10AM (#17416528)
Re:Negative Base by pmarreck on Thursday June 28, 2018 @12:01PM (#17418024)
Best way to represent nil, in my opinion ;)

Although it smells like a design flaw (which negabinary conveniently doesn't have)

Re:Negative Base by pphysch on Thursday June 28, 2018 @02:48PM (#17419444)
Are there common languages where -0 != +0? Or are you implying that this would be a good decision when creating a new language?
Re:Negative Base by kybernetikos on Thursday June 28, 2018 @07:29PM (#17421316)
javascript:

    > 1/(-0)
    -Infinity
    > 1/0
    Infinity
    > Object.is(0, -0)
    false
Of course = doesn't actually test equality in javascript. == reports -0 as being equal to +0, but Object.is reports them as different.
Re:Negative Base by earenndil on Friday June 29, 2018 @01:47AM (#17422657)
See now, I contest this particular defense because it groups together 'javascript' and 'good decision'.
Re:Negative Base by foxhill on Thursday June 28, 2018 @04:34PM (#17420244)
basically every language with IEEE-754[1] compliance..!

[1] - https://en.m.wikipedia.org/wiki/IEEE_754

Re:Negative Base by bzbarsky on Friday June 29, 2018 @01:26AM (#17422593)
I'd think that in all those languages, -0 == +0 tests true, though. In JavaScript even -0 === +0 tests true.

The only way to tell them apart in general is to divide by them. In some languages you might be able to type-pun and examine the bit pattern, or do things like Object.is() or whatnot.

Re:Negative Base by saagarjha on Thursday June 28, 2018 @06:28PM (#17420991)
But only when imposing a total ordering.
Re:Negative Base by foxhill on Thursday June 28, 2018 @06:33PM (#17421011)
that’s not the case, in IEE754 floating point, zero is signed - i.e negative and positive zero are distinct values
Re:Negative Base by saagarjha on Thursday June 28, 2018 @08:46PM (#17421620)
But the standard comparison operators don’t distinguish them.
Re:Negative Base by rprospero on Thursday June 28, 2018 @08:26AM (#17416277)
I think that's the first time I've ever seen someone use INTERCAL code to try and explain a concept.
Re:Negative Base by ainar-g on Thursday June 28, 2018 @08:51AM (#17416405)
For those wondering, please do read the Wiki article[1]. It's amazing.

[1] https://en.wikipedia.org/wiki/INTERCAL

Re:Negative Base by Sharlin on Thursday June 28, 2018 @09:10AM (#17416532)
See also balanced ternary [1].

[1] https://en.wikipedia.org/wiki/Balanced_ternary

Re:Negative Base by philbarr on Thursday June 28, 2018 @09:52AM (#17416822)
Which you can use to solve the puzzle:

"You have 12 coins that all look exactly the same. One is counterfeit and is either heavier or lighter than the other 11. With a balance beam scale, isolate the counterfeit coin in three moves."

Any uses for Negative-base systems?

Re:Negative Base by catpolice on Thursday June 28, 2018 @10:18AM (#17417032)
Hoo, that's one of my favorite puzzles - there was a version of it on Brooklyn Nine-Nine with no solution given, which ruined my sleep that night. I have a theory that it's actually a little harder for programmers than for other technically inclined people because the instinct to treat it as a kind of binary search problem is really hard to shake.
Re:Negative Base by TrinaryWorksToo on Thursday June 28, 2018 @10:30AM (#17417140)
Is it not a binary search problem?
Re:Negative Base by philbarr on Thursday June 28, 2018 @10:51AM (#17417289)
Not really - you can reduce it to one but you don't quite have enough information.

So I think it goes like this:

- you have 12 coins, and each one has an equal chance of being heavier or lighter than the others - so that's 24 possiblities

- you have 3 moves, and the result of each move could be one side of the beam goes down, one side goes up, or it balances. That means you can create a system that identifies 3^3 = 27 outcomes. So far so good.

- you need each of your outcomes to provide real information. if it was a binary problem that means you're not really getting any information if the beam balances

(bit sketchy on that last point, maybe someone can help with that)

Re:Negative Base by catpolice on Thursday June 28, 2018 @10:58AM (#17417365)
Yeah, the reason I suspect it tends to thwart programmers (if I recall correctly) is that there's a solution that looks a lot like binary search that _almost_ works, but the actual solution looks very different from it at every step. So the programmer will start with the one that looks like binary search, realize that it provides almost enough information, and try to squeeze a little more out of it by modifying it in little ways, when they sort of need to go back to the drawing board instead.
Re:Negative Base by wvlia5 on Saturday June 30, 2018 @02:03AM (#17429697)
"that means you're not really getting any information if the beam balances"

Wrong. If it was true, that would imply that the probability of it balancing is 1, since the information you get is -log2(probability). Obviously the probability of it balancing is lower than 1, so you do get information.

Re:Negative Base by catpolice on Monday July 02, 2018 @12:19PM (#17442958)
You don't get any information if the probability of the beam balancing is either 1 or 0. If you put everyone on the scale, the probability that it will be balanced is 0 - you don't learn anything. So the trick is to exclude some of the sample group in every measurement. You can use a binary search strategy where you divide the coins into "on the scale" and "not on the scale" groups, until you have a set of two that definitely contains the one you're searching for (and then one more measurement will tell you which one of those two it is) - but that strategy requires too many measurements, so you need to use more information at each stage, and you can't throw out coins you've determined to be non-counterfeit.
Re:Negative Base by wolfgke on Thursday June 28, 2018 @10:45AM (#17417250)
No, it is a ternary search problem.

EDIT: According to

> https://en.wikipedia.org/w/index.php?title=Balance_puzzle&ol...

if you know that one coin is different from the others, with 3 weighings, you can even detect it among 13 coins (not just 12).

Re:Negative Base by cecilpl2 on Thursday June 28, 2018 @10:45AM (#17417240)
I don't want to give too much away but consider that if you start by weighing 6 coins against the other 6, you already know what's going to happen.
Re:Negative Base by wvlia5 on Saturday June 30, 2018 @02:00AM (#17429687)
Wrong. You don't know which side will be heavier
Re:Negative Base by phamilton on Thursday June 28, 2018 @10:48AM (#17417271)
Nope. It's ternary in nature. The subproblem of "You have 3 coins, one of which is lighter than the others. On a balanced scale, figure out which one is lighter in one weighing." is a good place to start. Just enumerate all 3 possible weighings and you should be able to see the correct approach.
Re:Negative Base by emilfihlman on Thursday June 28, 2018 @04:24PM (#17420178)
How do you solve this?

ABC, one of them is different weight than the other two (either more or less)

Possible ways to weigh them:

  A v B
  A not enough information
  E C is odd one out
  B not enough information

  A v C
  A not enough information
  E B is odd one out
  C not enough information

  B v C
  B not enough information
  E A is odd one out
  C not enough information

  AB v C
  AB not enough information
  E C is odd one out
  C C is odd one out

  AC v B
  AC not enough information
  E B is odd one out
  B B is odd one out

  BC v A
  BC not enough information
  E A is odd one out
  A A is odd one out
In all possible ways to weight 3 coins, all have uncertainty which means you cannot deduce which is the odd one out.
Re:Negative Base by scrooched_moose on Thursday June 28, 2018 @05:05PM (#17420483)
Your OP stated one is lighter, not one is different.

It's easier than the 12-coin one different puzzle, but introduces the ternary concept well enough to get you started on the harder problem (there are some other complications to it as well).

Weigh 2 coins. If the scales move you've found the lighter coin. If the scales balance, it's the third coin you didn't weigh.

Re:Negative Base by emilfihlman on Thursday June 28, 2018 @06:05PM (#17420869)
Ah I got the original (12 coins, one is lighter or heavier) mixed up with 3 coins (one is lighter).
Re:Negative Base by grive on Thursday June 28, 2018 @05:24PM (#17420603)
Label each coin, divide in three stacks each time, and shuffle meaningfully each time the subsets, to remove uncertainty.
Re:Negative Base by QML on Thursday June 28, 2018 @08:50PM (#17421641)
Pretend you only had 3 coins. The idea is -- when you use the scale to measure 2 coins against each other -- you actually gain "information" about all three coins.

This is because there are 3 possible scenarios:

1. the biased coin is on the right side of the scale,

2. the biased coin is on the left side of the scale,

3. or the biased coin is the coin not measured (since the scale is balanced).

In essence, even though this scale only has 2 sides, you gain information proportional to having 3 sides.

Hence if we were to extend this to a scenario where you had n coins, of which one was biased and others fair, you would only need log_3 n measurements total to find the biased coin.

This idea has pretty neat applications. For example, if you wanted to prove that merge sort has a O(n log n) computational complexity, you can use this scale idea.

Re:Negative Base by catpolice on Thursday June 28, 2018 @10:53AM (#17417319)
Traditionally binary search involves recursively dividing the options into two roughly equal sized groups and then using a measurement to rule out every member of one of the groups (and thus half of the search space) with every step. The solution to this problem differs from that approach in certain key ways.

It is a kind of search problem, but the steps aren't recursive and you have to use several tricks to maximize the information you get out of each measurement.

Re:Negative Base by gkfasdfasdf on Thursday June 28, 2018 @11:12AM (#17417504)
I'm going to have to take this riddle bait. My solution:

Move 1: weigh 6 coins vs 6 coins. Isolate the heavier set for the next move. Move 2: weigh 3 coins vs 3 coins. Isolate the heavier set for the next move. Move 3: weigh any two of the 3 remaining coins. If one is heavier, that is the counterfeit. Otherwise (if coins are equal in weight) the remaining coin is counterfeit.

Re:Negative Base by ythn on Thursday June 28, 2018 @11:18AM (#17417565)
You failed because:

> One is counterfeit and is either heavier or lighter

It turned out the counterfeit was lighter and you discarded it after the first weighing.

Re:Negative Base by gkfasdfasdf on Thursday June 28, 2018 @12:41PM (#17418426)
Ahhhh... hmm. I thought it seemed too easy.
Re:Negative Base by gkfasdfasdf on Friday June 29, 2018 @12:31AM (#17422431)
Here are multiple solutions to the problem explained pretty clearly: http://mathforum.org/library/drmath/view/55618.html

This was a fun one to work out on paper though.

Re:Negative Base by dvfjsdhgfv on Thursday June 28, 2018 @08:33AM (#17416312)
Can anyone provide some examples of practical applications of this?
Re:Negative Base by pmarreck on Thursday June 28, 2018 @12:06PM (#17418074)
“An intellectual is a person who has discovered something more interesting than sex.”

― Aldous Huxley

Re:Negative Base by Tepix on Thursday June 28, 2018 @09:53AM (#17416829)
- Riddles.

- Obfuscation.

- Storing signed numbers in unsigned fields (nah, not really).

Re:Negative Base by wawhal on Thursday June 28, 2018 @09:42AM (#17416749)
Science need not necessarily have any practical use. That’s why it is called Science. Science, the way I define it is: Study for the sake of it.
Re:Negative Base by empath75 on Thursday June 28, 2018 @08:43AM (#17416364)
I can’t imagine there ever would be.
Re:Negative Base by vinceguidry on Thursday June 28, 2018 @08:59AM (#17416453)
I don't think anyone ever imagined a use for imaginary numbers either, but those turned out to be quite useful for reducing dimensionality. Towards the bottom of the article it states that Donald Knuth proposed imaginary base numerical systems.

So this may eventually find a use, likely with higher-dimensional math.

Re:Negative Base by roywiggins on Thursday June 28, 2018 @09:18AM (#17416594)
Imaginary numbers were useful as soon as they were invented. They are algebraically closed, unlike the real numbers, and are required for the fundamental theorem of algebra.

https://en.m.wikipedia.org/wiki/Fundamental_theorem_of_algeb...

The first use of negative roots was to find the (real) roots of certain polynomials. They were considered a mathemathical hack: useful, but specious on their own. And then it turned out that if you take them on their own terms, they're fantastically useful.

Re:Negative Base by jerf on Thursday June 28, 2018 @09:24AM (#17416628)
In addition to the other points, imaginary numbers immediately added to the representation of things we could represent. Simply rewriting existing numbers in other ways isn't all that interesting; it doesn't add anything. We already knew there's an infinite number of ways to serialize numbers to symbols. Negative base numbers don't behave differently than positive base numbers, because "negative base numbers" and "positive base numbers" are artifacts of English and don't actually exist mathematically. There are numbers, which are written in different representations, but are not actually different entities.

So there's no possible way this could be useful for "higher dimensional math" or anything, because there's no entity being added here. Higher dimensional math already uses numbers. At most there might be one or two concepts that might in some manner if you squint hard enough could be better represented by negative base numbers, but even then the positive base representation would probably still be how people actually understood it.

Re:Negative Base by vinceguidry on Thursday June 28, 2018 @10:29AM (#17417132)
> At most there might be one or two concepts that might in some manner if you squint hard enough could be better represented by negative base numbers,

That's what I was thinking.

Re:Negative Base by ainar-g on Thursday June 28, 2018 @09:04AM (#17416480)
It will be really funny if there is some bit of new, undiscovered physics, that went undiscovered for so long just because it's best described using some esoteric maths like complex base numbers.

Highly unlikely, but fun to think about.

Re:Negative Base by throwaway37585 on Thursday June 28, 2018 @12:15PM (#17418167)
Are there any examples where the representation of a number matters in physics?
Re:Negative Base by jfoutz on Thursday June 28, 2018 @12:30PM (#17418322)
I recall some effort in moving from imperial measurement to metric. Reality itself does not care, but the math sure gets easier if you carefully select units.

Actually, another neat example is analog vs digital computation. your models can get very different answers. I recall some Mandelbrot guy talking about that.

Re:Negative Base by retzkek on Thursday June 28, 2018 @01:42PM (#17418955)
See Gaussian (cgs) units for an example, compare Coulomb's law in cgs and SI: https://en.wikipedia.org/wiki/Gaussian_units#Unit_of_charge
Re:Negative Base by gota on Thursday June 28, 2018 @08:47AM (#17416389)
Well, the number of digits tell you the sign of the number, right? It could save a sign bit

I think the ideal wikipedia page for this kind of thing has a 'Properties' section from which to start thinking about this

Re:Negative Base by misja111 on Thursday June 28, 2018 @10:01AM (#17416905)
The bit saved for the sign is lost because you need more bits to represent a number.
Re:Negative Base by gota on Thursday June 28, 2018 @12:32PM (#17418339)
True, and it seems you actually need exactly one extra bit for all positive numbers
Re:Negative Base by fwdpropaganda on Thursday June 28, 2018 @09:30AM (#17416670)
So in your mind people are just coming up with these things for no reason, is that it?
Re:Negative Base by empath75 on Thursday June 28, 2018 @09:39AM (#17416725)
It’s fun and interesting to figure out. There are lots of ways to represent numbers but they don’t change the thing they represent.
Re:Negative Base by JadeNB on Thursday June 28, 2018 @10:23AM (#17417078)
> There are lots of ways to represent numbers but they don’t change the thing they represent.

Different representations of the same thing are not useless; one might make an argument (which I can only back up off the top of my head with mathematical examples, but I suspect that there are also many in the physical sciences) that they are at the root of much progress. The canonical example is to try to do positive-integer arithmetic with Arabic versus Roman numerals; they represent exactly the same thing, but I'll bet you can compute 16 ⨉ 17, but not XVI ⨉ XXIII (without converting), in your head.

Re:Negative Base by scentoni on Thursday June 28, 2018 @10:47AM (#17417262)

    XVI ⨉ XXIII
  = XVI ⨉ (XVI + I)
  = (XVI ⨉ XVI) + XVI
  = CCLVI + XVI
  = CCLXXII
Re:Negative Base by JadeNB on Thursday June 28, 2018 @11:04AM (#17417434)
I didn't say that it wasn't computeable, only that I bet you couldn't do it in your head.

Note that your calculation for some reason (EDIT: ah, maybe because my Arabic-numeral problem has 16 ⨉ 17?) replaces XXIII = 23 by XVII = 17, and then black-boxes the calculation XVI ⨉ XVI = CCLVI (which I at least wouldn't know without converting).

Re:Negative Base by jjaredsimpson on Thursday June 28, 2018 @12:38PM (#17418399)
I agree. You can use the same algorithm for computing both. But Arabic has better constants. Because it's a discrete convolution instead of grouping and aggregating.

      1 6
    1 1 6
    7 7 42
    1, 6+7, 42 = 100 + 130 + 42 = 272
Same process in Roman

      X V I
    X C L X
    X C L X
    I X V I
    I X V I
    I X V I
    CC LL(=C) XXXXX(=L) VVV(=XV) III = CCCLXVIII = 16*23=368
This supports the arguments that Arabic numbers really are better suited for things like multiplying. They don't have the property that multiplication is convolution, so you can't even do things like truncate your computation to get an approximation.

There's probably a way to formalize this with an entropy argument: that roman numerals are inefficient encoding. Because given some n-length string of numerals, firstly many are invalid encodings, and secondly among the valid numerals there isn't a uniform distribution from strings to integers. Something like that.

Re:Negative Base by JadeNB on Thursday June 28, 2018 @01:29PM (#17418859)
> I agree. You can use the same algorithm for computing both.

Although it's in some sense the same algorithm, the Roman-numeral version requires far more memorisation. For example, once I know that 2 ⨉ 3 = 6, I know without further memorisation (or, rather, with only a meta-memorisation that generalises readily to other contexts) that 20 ⨉ 30 = 600; but, even once I know that II ⨉ III = VI, I have to memorise separately that XX ⨉ XXX = DC.

> This supports the arguments that Arabic numbers really are better suited for things like multiplying. They don't have the property that multiplication is convolution

I think "They" here is "Roman numerals", not (as the structure seems to suggest) "Arabic numerals", right?

Re:Negative Base by dumbfoundded on Thursday June 28, 2018 @12:03PM (#17418047)
Taken one step further, could you have irrational bases?

i^1 = i

i^2 = -1

i^3 = -i

i^4 = 1

Re:Negative Base by pmarreck on Thursday June 28, 2018 @12:11PM (#17418132)
Re:Negative Base by dumbfoundded on Thursday June 28, 2018 @12:35PM (#17418367)
thank you!
Re:Negative Base by joker3 on Thursday June 28, 2018 @04:25PM (#17420188)
How do you divide by numbers other than -2?