| Ok, let's say that it is not JS, but an untyped, closure-based programming language with a strikingly similar array and sort API to JS. Sadly, this comparator is still wrong for any sorting API that expects a general three-way comparison, because it does not handle equality as a separate case. And to tie it down to the mathematics: if a sorting algorithm asks for a full comparison between a and b, and your function returns only a bool, you are conflating the "no" (a is before b) with the "no" (a is the same as b). This fails to represent equality as a separate case, which is exactly the kind of imprecision the author should be trying to teach against. |
| |
| ▲ | mrkeen 2 hours ago | parent | next [-] | | > Sadly, this comparator is still wrong for any sorting API that expects a general three-way comparison, because it does not handle equality as a separate case. Let's scroll up a little bit and read from the section you're finding fault with: the most straightforward type of order that you think of is linear order i.e. one in which every object has its place depending on every other object
Rather than the usual "harrumph! This writer knows NOTHING of mathematics and has no business writing about it," maybe a simple counter-example would do, i.e. present an ordering "in which every object has its place depending on every other object" and "leaves no room for ambiguity in terms of which element comes before which" but also satisfies your requirement of allowing 'equal' ordering. | | |
| ▲ | gobdovan 2 hours ago | parent [-] | | Your reply only works if the article were consistently talking about a strict order. However, it is not. It explicitly introduces linear order using reflexivity and antisymmetry, in other words, a non-strict `<=`-style relation, in which equality IS a real case. If the author wanted to describe a 'no ties' scenario where every object has its own unique place, they should have defined a strict total order. They may know everything about mathematics for all I care. I am critiquing what I am reading, not the author's knowledge. Edit: for anyone wanting a basic example, ["aa", "aa", "ab"] under the usual lexicographic <=. All elements are comparable, so "every object has its place depending on every other object." It also "leaves no room for ambiguity in terms of which element comes before which": aa = aa < ab. Linear order means everything is comparable, not that there are no ties. By claiming "no ties are permitted" while defining the order as a reflexive, antisymmetric relation, the author is mixing a strict-order intuition into a non-strict-order definition. |
| |
| ▲ | layer8 2 hours ago | parent | prev | next [-] | | It could be a typed programming language where the sort function accepts a strict ordering predicate, like for example in C++ (https://en.cppreference.com/cpp/named_req/Compare). | |
| ▲ | gopiandcode 2 hours ago | parent | prev [-] | | > an untyped closure-based programming language with a similar array and sort api to JS Ah! You're talking about Racket or Scheme! ``` > (sort '(3 1 2) (lambda (a b) (< a b))) '(1,2,3) ``` I suppose you ought to go and tell the r6rs standardisation team that a HN user vehemently disagrees with their api: https://www.r6rs.org/document/lib-html-5.96/r6rs-lib-Z-H-5.h... To address your actual pedantry, clearly you have some implicit normative belief about how a book about category theory should be written. That's cool, but this book has clearly chosen another approach, and appears to be clear and well explained enough to give a light introduction to category theory. | | |
| ▲ | gobdovan 2 hours ago | parent [-] | | The syntax in the article is not scheme, you can clearly see it in my comment you're responding to. As for your 'light introduction' comment: even ignoring the code, these are not pedantic complaints but basic mathematical and factual errors. For example, the statement of Birkhoff’s Representation Theorem is wrong. The article says: > Each distributive lattice is isomorphic to an inclusion order of its join-irreducible elements. That is simply not the theorem. The theorem says "Theorem. Any finite distributive lattice L is isomorphic to the lattice of lower sets of the partial order of the join-irreducible elements of L.". You can read the definition on Wikipedia [0] The article is plain wrong. The join-irreducibles themselves form a poset. The theorem is about the lattice of down-sets of that poset, ordered by inclusion. So the article is NOT simplifying, but misstating one of the central results it tries to explain. Call it a 'light introduction' as long as you want. This does not excuse the article from reversing the meaning of the theorem. It's basically like saying 'E=m*c' is a simplification of 'E=m*c^2'. [0] https://en.wikipedia.org/wiki/Birkhoff%27s_representation_th... |
|
|