News for hackers. Stuff that matters.

MikeBattaglia

> Exploits will always be able to chained, and everything will always be exploitable. Including AI systems.

Good point. Also, discovering exploits is also equivalent to the halting problem. So both things are impossible in the general case.

Re:The Elements of Differentiable Programming on Saturday March 23, 2024 @02:40PM (#39802152)
This is a good question that doesn't have a short answer. There are some different philosophical opinions about this.

One way to look at this is to note that even with forward mode autodiff, there have generally historically been two different viewpoints for the whole thing, which I'll call the "computer science" view and the "algebraic" view.

The computer science view involves things that look computational graphs with nodes that look like {"value": 123, "deriv": 456}. We are storing real values along with propagated partial derivatives. We have a custom * operator which sets a * b = {"value": a.value * b.value, "deriv": a.value * b.deriv + b.value * a.deriv}. Other functions, like exp, sin, cos, log, etc are also extended to handle these kinds of input. There's a ton of literature that views things using this kind of framework going back to the 1960s.

The algebraic view uses dual numbers. Instead of writing {"value": 123, "deriv": 456}, we write 123 + 456h. We get the same results as the above: (a + bh) * (c + dh) = ac + (ad + bc)h. We can extend many functions in a natural way to the dual plane, such as exp, sin, cos, log, and get values there. There's also plenty of literature on these, going back to the late 1800s.

A modern view is to note that these two things are *identical*. It isn't that forward mode autodiff "uses" dual numbers; it is dual numbers. The set of elements of the form {"value": x, "deriv": y}, with addition and multiplication as stated, satisfies the axioms of a real algebra and is isomorphic to the dual numbers. We could have written {"real_part": x, "dual_part": y} if we wanted. You can see this viewpoint in some of the links I've posted elsewhere here.^[1]

So given all of that background, there are two answers to your original question. The first is to just simply view it as that "reverse-mode autodiff doesn't use dual numbers." Many people have this view, and I would say that that it really focuses on what I've called the "computer science" view above.

The second view is to note that the relationship between reverse-mode autodiff and dual numbers is the same as the relationship between reverse-mode autodiff and forward-mode autodiff. It would be silly to say that they are totally different, unrelated things: at the end of the day all we are really doing is changing the order in which we perform a bunch of multiplies of Jacobian matrices. I tend to view it as similar to the relationship between the DFT and the FFT: there is this super elegant linear algebra view involving DFT matrices. Do we say that the FFT "doesn't use matrices?" Well, I guess, but are we going to go so far as to say that it also doesn't involve linear algebra, etc? That is my view.

There are a few other differences between reverse-mode and forward-mode autodiff. Each individual operation in the computation graph, for instance, can be thought of as an individual instance of forward-mode autodiff. In reverse-mode, on the other hand, we typically store the (back-)propagated adjoints as additional data on the input node objects, not the output nodes. This is useful if we are thinking of backpropagation on a graph. It's up to you if you view these as involving materially different theories or just differences of implementation for the sake of optimization.

In short, the main thing is that there's less literature on a purely algebraic version of reverse-mode autodiff in general.

[1] There is one important difference: we often think of the dual numbers as an ordered ring with "h" infinitesimal. The first viewpoint doesn't use this part of the mathematical structure - and it's very interesting to note that it isn't even necessary! Although it's cute to think of h as infinitesimal, the autodiff properties we get flow purely from the algebraic properties of having h^2 = 0, regardless of order. Of course, though, we can always just think of the dual numbers as an unordered ring, if we want.

Re:The Elements of Differentiable Programming on Friday March 22, 2024 @11:34PM (#39797181)
Sure, right here: https://github.com/pytorch/pytorch/blob/main/torch/autograd/...

Here's the documentation: https://pytorch.org/tutorials/intermediate/forward_ad_usage....

> When an input, which we call “primal”, is associated with a “direction” tensor, which we call “tangent”, the resultant new tensor object is called a “dual tensor” for its connection to dual numbers[0].

Re:The Elements of Differentiable Programming on Friday March 22, 2024 @09:14PM (#39796537)
It isn't true for all ordered rings, and the dual numbers are in fact a counterexample to the claim that it is true.

Beyond that I'm not sure what to tell you, other than it's fairly easy to see that the dual numbers do satisfy the axioms of an ordered ring that I gave. Here's a large survey of various infinitesimal systems by Philip Ehrlich where he also notes the dual numbers are an ordered ring: https://arxiv.org/pdf/1808.03345.pdf.

Re:The Elements of Differentiable Programming on Friday March 22, 2024 @08:13PM (#39796175)
That isn't what an ordered ring is. Your property of a < b → a² < b² doesn't even hold true in the integers. For instance, let a = -2 and b = -1.

The correct property is that if a ≤ b, a + c ≤ b + c, and if a ≥ 0 and b ≥ 0, then ab ≥ 0. It is fairly easy to see that these properties hold for dual numbers.

Re:The Elements of Differentiable Programming on Friday March 22, 2024 @07:41PM (#39795999)
These things are different and I did mean dual numbers. The dual numbers do form an ordered ring. When you complain about certain elements being non-invertible, I think you are probably complaining that they aren't a field.
Re:The Elements of Differentiable Programming on Friday March 22, 2024 @07:24PM (#39795899)
Thank you for repeating yourself three times. It seems like you think that the dual number algebra involves "magic woo numbers." It seems like you haven't really worked through this stuff too much. I would suggest reading some of the resources above, such as the MIT lecture series. The rest of your points I think I have already addressed, though you ignored in your reply - I've said Pytorch does reverse mode diff several times at this point.
Re:The Elements of Differentiable Programming on Friday March 22, 2024 @07:11PM (#39795813)
At the end of the day, if you are storing inputs and outputs to a function as a pair of numbers - one for the actual value, and one for the derivative - and if addition and multiplication work the way you expect and propagate derivatives correctly - then you are using dual numbers, regardless of if you notate it a + b*h or {"value": a, "derivative": b}.

Pytorch does things slightly differently in that it is mostly focused on reverse-mode autodiff, and so it stores adjoints relative to the overall output rather than partial derivatives relative to the input, but this isn't really an entirely different thing, in the same way that the FFT isn't entirely different from the DFT.

There seems to be some confusion about the relationship between dual numbers and smooth infinitesimal analysis. Both have nilpotent elements, but with dual numbers the background logic is classical, whereas it isn't with smooth infinitesimal analysis.

Re:The Elements of Differentiable Programming on Friday March 22, 2024 @07:05PM (#39795772)
There are a few good resources. Here is a good blog post with some introduction:

https://towardsdatascience.com/forward-mode-automatic-differ...

Some thorough notes from MIT: https://book.sciml.ai/notes/08-Forward-Mode_Automatic_Differ...

Here is a teacher who taught a class using these, calling the dual element dx instead of h:

https://cornellmath.wordpress.com/2007/08/28/non-nonstandard...

Re:The Elements of Differentiable Programming on Friday March 22, 2024 @06:24PM (#39795486)
One very interesting thing about automatic differentiation is that you can think of it as involving a new algebra, similar to the complex numbers, where we adjoin an extra element to the reals to form a plane. This new algebra is called the ring of "dual numbers." The difference is that instead of adding a new element "i" with i² = -1, we add one called "h" with h² = 0!

Every element in the dual numbers is of the form a + bh, and in fact the entire ring can be turned into a totally ordered ring in a very natural way: simply declare h < r for any real r > 0. In essence, we are saying h is an infinitesimal - so small that its square is 0. So we have a non-Archimedean ring with infinitesimals - the smallest such ring extending the real numbers.

Why is this so important? Well, if you have some function f which can be extended to the dual number plane - which many can, similar to the complex plane - we have

f(x+h) = f(x) + f'(x)h

Which is little more than restating the usual definition of the derivative: f'(x) = (f(x+h) - f(x))/h

For instance, suppose we have f(x) = 2x² - 3x + 1, then

f(x+h) = 2(x+h)² - 3(x+h) + 1 = 2(x² + 2xh + h²) - 3(x+h) + 1 = (2x² - 3x + 1) + (4x - 3)h

Where the last step just involves rearranging terms and canceling out the h² = 0 term. Note that the expression for the derivative we get, (4x-3), is correct, and magically computed itself straight from the properties of the algebra.

In short, just like creating i² = -1 revolutionized algebra, setting h² = 0 revolutionizes calculus. Most autodiff packages (such as Pytorch) use something not much more advanced than this, although there are optimizations to speed it up (e.g. reverse mode diff).

Re:How random is xkcd? (2015) on Friday December 29, 2023 @12:09PM (#38807387)
XKCD should solve the problem the same way Tetris randomizers do. In Tetris, they don't use naive memoryless uniform randomizers for pretty much the same reasons that people are complaining about in this article: you tend to get these long droughts and floods of pieces that you want or don't want. Instead, they just do a random permutation of all 7 pieces, spawn those, then do another random permutation, etc. XKCD could easily do this kind of thing (with cookies, I guess).
Re:Decimal to Fraction on Tuesday August 15, 2023 @11:04PM (#37142416)
He points out that the YouTube video "uses mediants" to compute rational approximations to real numbers. He then says that the continued fraction expansion is better. However, the mediant-based method is totally identical to the continued fraction expansion method. The two are related via the Stern-Brocot tree (https://en.m.wikipedia.org/wiki/Stern%E2%80%93Brocot_tree).

The fractions that one gets from iterating the mediant process are exactly the "semiconvergents" one gets from the continued fraction process. Truncating the continued fraction gives the "convergents"; these are special mediants which are right before switching direction as one zig zags on the tree.

Re:Ask HN: Are we morally obligated to give freedom to AGI? on Tuesday February 07, 2023 @02:38PM (#34698153)
We'll know if an AI is conscious same way we know if a cat is consciousness, and it has nothing to do with language.
Re:Cistercian Numerals on Tuesday January 31, 2023 @01:59AM (#34592115)
Unrelated rant: The Unicode people have missed a lot more than that. There are an enormous amount of, for instance, musical accidentals that are missing, including ones that have been in use for at least a hundred years, such as the half flats or half sharps in e.g. Arabic or Turkish music, which are used by probably hundreds of millions of people in the Middle East. (They do have a symbol called "half sharp" and "half flat", but it isn't the same symbol.)

But at least they have the multiocular O, I guess.

Re:Ask HN: Why Is Everything Declining? on Saturday January 28, 2023 @04:34PM (#34562187)
There are some pretty clear indications that the derivative of civilization is strongly negative at the moment, particularly if you live in Europe.

Actually, the fact that people are supposed to pretend things are OK, while everyone over there is possibly a few steps away from being drafted into war, is another sign that things have headed in the wrong direction in exactly the manner OP is suggesting.

For jazz it's also the composer. People like Wayne Shorter, Herbie Hancock, Billy Strayhorn, Thelonious Monk, etc - all incredible composers
Re:Ancient Apocalypse Reviewed on Saturday January 07, 2023 @03:42AM (#34286323)
I'm not sure much of the stuff really needs to be "debunked" at all. Let's look, for instance, at Gobekli Tepe.

Is it really the position of mainstream archaeology that something like Gobekli Tepe was built by nomadic hunter-gatherer tribes who hadn't even invented the wheel? Some of the pillars weigh 22,000 lbs. There are intricate statues carved by people who supposedly didn't have metalworking or any metal tools. The entire thing is part of an even larger complex that has yet to be excavated and it was all planned out and coordinated by people who hadn't even invented writing or math. How plausible is this?

10 years ago, when these discoveries were much newer, mainstream archaeologists were still largely hung up on the idea that these ridiculous massive stone temples must somehow have been built by primitive hunter-gatherers. These days, it seems as though those attitudes have shifted, and that things like Gobekli Tepe call into question if we really have the right picture regarding the timeline of human development at all. It seems increasingly possible - even in mainstream archaeology - that humans 13000 years ago may simply have been further ahead than we thought.

One side effect of this paradigm shift is that people like Graham Hancock get to claim they were right all along. OK! Of course it this doesn't mean everything else he has ever claimed is right, but as far as I care, he can milk the "him vs the establishment" angle all he wants. He has a valid complaint - but more importantly, what institution is supposed to be able "debunk" him at a time when legitimate new discoveries are currently upending everything we thought we knew? You need to figure out what is actually going on first before you can hope to be Real Scientists "debunking" anything. Until you do, the notion that perhaps Gobekli Tepe was really built by people with a comparatively advanced level of civilizational development, rather than primitive hunter-gatherer cavemen, seems as decent a hypothesis to entertain as anything else. And if I were a betting man, I'd bet this really is the right hypothesis, in my view!

This article is bizarre. It reads like they've unearthed some long lost Rosetta Stone artifact from thousands of years ago. In reality, these people have "discovered" that everyone right around them writes using this language and this is just how they write and they all know about it. What is the "discovery" here?

Here's what I think: modern Western civilization - to say nothing of historical colonial societies - has attempted to pulverize these cultures utterly: it has removed their spoken and written language, music and art; altered their general societal structure; created a false narrative that they are "savages"; and so on. Some of these events are very recent, and some people involved are even still alive today.

Then, we like to do this thing where we go ahead and "study" the same people whose culture we just destroyed, pretending all the while as if it were an ancient civilization destroyed thousands of years ago through some natural process.

Tens of millions of people are walking around in Africa today who use this language. Now that we have "discovered" this, maybe some day we will also "discover" that they have music, art, jokes, and an entire culture.

No shade on Ngom, though, as I am sure he is doing his best to bring some of these things to light within the Western academic system.

I can't comment regarding how you think is best to teach your students. This is now a popular blog post that has gone viral on HackerNews to a much wider audience of well-educated people, so you should expect people will clarify these things on here. I'm talking mostly about stuff like this:

> Five hundred years ago, however, it would have made a very big difference. Before the advent of temperament systems, D-sharp and E-flat were two different notes. They weren’t just written differently; they sounded different. You can compare the historical versions of these notes yourself in this track I made... My track is tuned in a system called five-limit just intonation

^ These are not the historical versions of those notes. 5-limit just intonation was not in widespread use in Western Europe 500 years ago. 500 years is not before the advent of temperament systems. And so on. Teach this to your students however you think is best, but people on here may be interested to know that.

You are correct. For instance, traditionally, in barbershop vocal music, singers are trained to deliberately deviate from 12 equal, towards an ever-shifting kind of just intonation, in order to maximize the extent to which the voices blend. Auto tune, on the other hand, just tunes things straight to 12 equal. Melodyne fares a little bit better in that it lets you tune to custom microtonal scales, or fudge things a little bit here and there, etc. Interestingly, Logic Pro X has a "Hermode Tuning algorithm" that will basically do the dynamic adjustment toward just intonation for you, but it only works for MIDI instruments and not auto tune as far as I know.
This is called "adaptive just intonation." Logic Pro X has this feature built in, using a particular algorithm called Hermode Tuning. It sounds great
There is some basic information that is very wrong in this article. For example:

"My track is tuned in a system called five-limit just intonation via the magic of MTS-ESP. It’s the basis for all the tuning systems used in Western Europe between about 1500 and 1900."

No - at no point in the last 500 years was 5-limit just intonation ever the predominant tuning system used anywhere in Western Europe. The real predominant tuning system was called "meantone temperament," to which this article sadly devotes only about 3 words - and those words are only about 12 tone meantone keyboard layouts, not about the bigger, abstract idea of meantone temperament in general as it was understood and taught by practitioners of the day.

There is a very important difference between meantone and just intonation. The goal of meantone was to have four tempered perfect fifths (approximately a 3/2 frequency ratio) add together to approximate the fifth harmonic (or a 5/1 frequency ratio). Thus, the major third from the circle of fifths would approximate a 5/4 ratio with the tonic, and the major chord would approximate a very crunchy sounding 4:5:6 ratio. In order to do this, fifths are all flattened slightly to make the tradeoff - flattening the fifths by 1/4 of a "syntonic comma" was typical, or "quarter-comma meantone". Even though keyboard instruments evolved in a more well-tempered direction, meantone was the way that teachers of the common practice era (such as Leopold Mozart) still taught and thought about this stuff.

Meantone sounds noticeably different from just intonation, where the major third from the circle of fifths is a syntonic comma sharp of a 5/4 ratio (about 22 cents). In just intonation, if you want your major chords to be 4:5:6, you need to bring in this other, different, independent 5/4 major third that is not on the circle of fifths. As a result, certain chord progressions that are common in Western music will tend to exhibit strange sounding "comma drifts" if you play them in just intonation. Adam Neely has a good video on "Benedetti's Puzzle" about this for those who are interested.

Of course, there is nothing wrong with just intonation, and comma shifts can sound interesting if you want to deliberately use them in some kind of modern microtonal setting, but it simply isn't the tuning historically used in common practice Western music.

Anyway, though, if you go through the article with a marker and replace all instances of "just intonation" with "meantone," the general idea is mostly correct.