Hacker Newsnew | past | comments | ask | show | jobs | submit | mag487's commentslogin

That code is doing a lot more than just layout and styling.


It may be a useful sanity check to simulate the experiment multiple times to see the result:

  def choose_coin
    rand < 0.001 ? 1 : 0.5
  end
   
  def flip_coin(coin)
    rand < coin ? :heads : :tails
  end
   
  def all_10_heads?(coin)
    10.times { return false if flip_coin(coin) == :tails }
    true
  end
   
  next_flip = { :heads => 0, :tails => 0 }
   
  1000000.times do
    coin = choose_coin
    next unless all_10_heads? coin
    next_flip[flip_coin(coin)] += 1
  end
   
  puts next_flip[:heads].to_f / (next_flip[:heads] + next_flip[:tails])


What's really interesting is that there are probabilistic programming languages where you can write a program that does a simulation just like you did, but the execution engine can compute the probabilities exactly and much faster too. It does this by computing along all possible paths in the program, and keeping track of the probability mass of each path, and then summing them all up in the end.

http://en.wikipedia.org/wiki/Probabilistic_programming_langu...


Completely shameless plug for a tiny probabilistic programming language that I wrote as an embedded DSL in Haskell:

https://github.com/chris-taylor/hs-probability

The code that solves this problem is:

  solve = do
    coin   <- choose (999/1000) fair biased
    tosses <- replicateM 10 coin
    condition (tosses == replicate 10 Head)
    nextToss <- coin
    return nextToss
   where
    fair   = choose (1/2) Head Tail
    biased = certainly Head


It's hard to imagine that even those could total more than a small fraction of the purported 500 MLOC. The JDK is only a few million lines of code.


I'm having a really hard time believing that figure.


That's a really good point. I hadn't been completely sold on the value of promises over callbacks before, but this seems like a very unambiguous advantage. I can't think of an obvious, clean way to do this with callbacks that doesn't go a long way toward simply re-implementing promises.

I imagine an advocate of core.async would argue that they have a good analog for canceled promises, though, namely closing channels. On the other hand, closed channels will still yield nil when read from; the procedures trying to read from a closed channel would need to check for that.


> I can't think of an obvious, clean way to do this with callbacks that doesn't go a long way toward simply re-implementing promises.

I may be misunderstanding your point, but you could name the callback function, and give the function object itself a "cancel()" method which alters its behavior to do nothing.


Yes, but that doesn't give you a great way to deal with attaching and canceling multiple callbacks simultaneously. If you want to perform several independent asynchronous actions after some other operation finishes, you have to collect them into a single giant callback in one location. And as you mention, the function has to keep track of some piece of mutable state in order to decide whether it's cancelled or not before firing off those operations. So why not give the function a mutable array of asynchronous operations to perform to begin with, which you can then add to at any time? And at that point, you already have a something very close to a promise.


How's that? JS is single-threaded.


Wouldn't that just mean the event loop cycles faster, lending credence to the gp's snark?


Why would having multiple cores make the event loop cycle faster? Maybe I misunderstood and he was using "Moore's law" to refer to exponential increase in processor speed rather than transistor density (which is what I understand Moore's law to be talking about). But commercial processors aren't really getting much faster anymore.


The key phrases there are "almost surely" and "most irrational numbers." There are irrational numbers like pi which can be defined algorithmically, but taken together as a set they have zero Lebesgue measure. (In fact, they're countable.)


I didn't know that. Any link to a proof?


Consider the set P of programs that take no input and generate an infinite stream of digits. Each program in P has a finite length and is written out of a finite set of symbols, so there must only be a finite number of programs of any given length. That makes P countable. Let Q be the set of numbers described by programs in P. Each program from P describes exactly one number, so Q must also be countable. The set of irrational numbers is uncountable, so there must be an uncountable set of "complex" irrational numbers remaining after you take away all the "non complex" ones in Q.


Your proof seems to only prove that a finite number of programs (described by you) which can produce a finite number of irrational numbers, while there are infinite number of irrational numbers.

But we're surely not talking about a finite number of programs.

I'm not even sure what the Kolmogorov complexity of a "complex irrational number" means. If you need the sequence of digits and you cannot use an algorithm to produce the digits, then the complexity is infinite?


For each fixed length there are a finite number of programs of that length. If we use 8-bit bytes for the alphabet, there are 256^N programs of length N. The set of ALL programs is infinite (we don't limit the length of programs), but it is countable.

The "countable" part means we can put the set into one-to-one correspondence with the natural numbers. The correspondence starts with 0 mapping to the empty program, then 1-256 mapping to programs of a single byte, then 257-65793 mapping to the programs of two bytes, and so on. This mapping will hit each program exactly once, and it will hit every program because every individual program has a finite length.

Different types of infinities are not intuitive so don't feel bad if the concepts are confusing. These issues troubled lots of very smart mathematicians for decades. The existence of irrational numbers was hugely troubling to Pythagoreans. The existence of uncountable infinities discovered by Cantor was shocking [1].

[1]: http://en.wikipedia.org/wiki/Controversy_over_Cantor%27s_the...


In some sense, the existence of irrational numbers with no pattern in their digits is an illusory artifact of the number system. We can talk about them collectively because decimals are not required to have an end, and we have to postulate them to fill in the gaps in the number line, but such numbers lack any description or means of being separated as individuals.

But then, is any mathematical abstraction real? I guess it's all beside the point.


> But then, is any mathematical abstraction real? I guess it's all beside the point.

I actually think the reality of mathematical abstractions is hugely important because of... computer programs! In a real way, programs are the embodiment of mathematics. I want my programs to work so I need the underlying math to work as well.

That's why I'm a constructivist. I reject the law of the excluded middle because proofs that use it don't translate into real programs; they translate into programs that ask an omnipotent oracle to decide which branch to take. Constructive proofs translate into working programs.

It also ties into philosophy. I am a skeptic, so when someone tells me either A or not A must be true even if we can never know which one, I ask for proof or justification of that fact. The justifications that I get are remarkably similar to logical "proofs" that god exists, and just as fallacious. This isn't to say that there couldn't be an ultimate truth about A or a god, just that it is not logically necessary.


Interesting. I'm not all that up on philosophy, and I had to look up constructivism and the law of the excluded middle. Computers can only deal directly with discrete math, so that eliminates quite a bit of mathematics. Moreover, despite being regarded as Turing machines, you could in reality count all the states that a computer could be in, by counting the bits of memory, and you will find that it's a finite number. So computers are, in fact, only finite state machines. It's often overlooked that what makes a Turing machine a Turing machine is the infinitely-long tape. So computers occupy a fairly small sliver of the infinite universe of math.

Philosophically, my worldview is like that of science: the way to know something is by making observations and formulating and testing hypotheses. What we can observe is limited, and hypotheses are only models that are tested by successive approximations. I'm not sure I understand what you mean that that statement isn't required to have an ultimate truth. Presumably a statement like that has an answer, but the fact that something is knowable in principle doesn't mean that there's any way to get the answer. For instance, the Hubble telescope can see far away galaxies that we can never get an up close look at. The question of whether there's life somewhere else in the universe must have an answer, but we can't know what's in those galaxies; even with a better telescope, we'd be seeing what they looked like a billion years ago. Many things will never be known.


This is wrong. The square root of two was identified as irrational by the ancient Greeks, when considering the length of the diagonal of the unit square. The proof has nothing to do with decimal fractions (they didn't use decimal fractions at all).


I'm referring to irrational numbers with no pattern. Square roots can be described and the digits can be enumerated by an algorithm. The diagonalization argument shows that there can't be a description for all irrational numbers.


Just to be clear: you think that there are many irrational numbers that exist independently of which number system you use, but that there are infinitely many that do depend on the number system you use? Is that right?


Irrational numbers, by definition, include decimal numbers that have infinitely many digits after the decimal point, and there are no rules about what those digits have to be. This is powerful enough to represent any irrational number regardless of the number base. However, if you're talking about number systems, not all number systems have equal ability to represent irrational numbers. Whatever the system, to represent all the irrationals, it would have to be capable of going on forever. I think the part of my point that you're asking about is my statement that they're a side effect of decimal numbers. Irrational numbers like sqrt(2) and e have concise representations as the limits of Taylor series. Only when converted into decimals do they appear to have infinite amounts of information. So if we used Taylor series as the number system instead of decimals, simple irrationals would look simple, and we might be less inclined to treat them the same as numbers that have no finite descriptions at all.


I was under the impression that irrational numbers are numbers that simply can't be represented as a ratio. This is independent of the number system used. I'm not familiar with the Taylor series: can you use it as a number system? Isn't it simply a representation of functions (in which case, you might as well just write "sqrt(2)" as invoke anything else)?

It's tough to Google for "Taylor series number system" as you just get pages about the guitars. ;-)


I don't know if you're still reading this, but... Using Taylor series as a number system is just a hypothetical. Any systematic way of describing numbers could be a number system. Irrationals can't be represented as ratios, but beyond that, some have other finite representations, and others have none.



> In some sense, the existence of irrational numbers with no pattern in their digits is an illusory artifact of the number system.

But irrational numbers remain irrational in any integer number base. Therefore no, they aren't illusory at all, nor are they an artifact of the "number system".

> ... such numbers lack any description or means of being separated as individuals.

Also false. Many irrational numbers are easy to identify unambiguously. For example, the square roots of numbers that are not perfect squares are irrational, but they can be easily identified by squaring them.

While we're on the topic, the terms in the running sum of odd numbers are all perfect squares:

    0 + 1 =  1
    1 + 3 +  4
    4 + 5 =  9
    9 + 7 = 16
   16 + 9 = 25
As is often true in mathematics, this is easier to explain with a picture:

http://arachnoid.com/example/#Math_Example

> But then, is any mathematical abstraction real?

Certainly. Consider general relativity. It's a mathematical abstraction, and it's also real.


"Many irrational numbers are easy to identify unambiguously."

Absolutely. Cantor proved that an infinite number of others can't be identified at all, because they outnumber all possible descriptions. Some numbers can only be described by an infinitely long list of digits, one that can't be produced by a Turing machine and contains an infinite amount of irreducible information. The Kolmogorov complexity is infinite.

Newton's equations describe a mathematical model of the universe that agrees well with measurements taken under familiar conditions. Einstein's equations describe a different mathematical model, one that has good agreement with experiment over a much wider range of conditions than Newton's. But general relativity has well-known problems. Its equations give nonsense solutions under some circumstances, e.g. singularities. Physical theories are models that predict the outcomes of experiments. They're reductionist out of necessity. It's unknown and probably unknowable as to whether a perfect model is possible, but there are likely things that can't be reduced.


> Cantor proved that an infinite number of others can't be identified at all, because they outnumber all possible descriptions.

I'm tempted to say that that definition places those examples in a unique set, thus at least unambiguously identifying the set to which they belong.


This appears to be exactly the concept I was talking about. Maybe I read about these numbers some time ago and forgot that they already had a name.

http://en.wikipedia.org/wiki/Definable_number


You can identify the set of numbers with infinite Kolmogorov complexity. But you can't separate out an individual from the set.

Turing machines might not capture all numbers that can be described, but, interestingly, descriptions and Turing machines have the same cardinality.


The set of irrational numbers which can be defined algorithmically are programable, eg. they are defined by a program of finite length.


>The set of irrational numbers which can be defined algorithmically are programable

You mean "computable".


There's only a countable number of formulas of ZFC. Therefore, there's only a countable number ways of writing out a formula of ZFC that uniquely specifies a real number. Therefore, only countably many real numbers exist that have such definitions. And all countable sets of reals have zero Lebesgue measure.


Additional question: what's the Kolmogorov complexity of a irrational numberwhich is not described with a ZFC formula? And how is it described?


I haven't really studied algorithmic information theory, but I'd assume that Kolmogorov complexity isn't defined for uncomputable/undefinable numbers. Or maybe it's defined as "infinite," but either way, my guess is that such numbers are simply ignored. (Interestingly, the function which takes a computable number and outputs its Kolmogorov complexity is itself uncomputable!)


The article at least implies that the Kolmogorov complexity of uncomputable irrational numbers is larger than computable irrational numbers.


It's an awesome motto that's served them extremely well. Google's ability to frame themselves as the "good guys" is the only real marketing advantage they have.


So it's their "motto advantage" that attracts everyone in using their services? I guess giving their services away for free doesn't count for anything?


I wouldn't include their pricing structure as part of their marketing, though it doubtless attracts many users. (So do their algorithms, but those aren't included in their marketing, either.) And insofar as they have a reputation for giving away their services for free, that's a part of their heroic image.


I don't see how he's being scapegoated. What failure is he being held personally responsible for?


Not trying to defend the viability of FB ads here, but this analysis seems a little shallow. Falling within a certain demographic may not "make" you click an ad, but the same could be said of performing a search on Google. If circumstance Y makes one want to buy a product, then as long as falling within demographic X is correlated with being in Y, targeting X could be a good idea. It is (obviously) the reason why toy commercials air during children's shows and not during basketball games.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: