logoalt Hacker News

ColinWright12/10/20241 replyview on HN

But you have specifically initialized your AND and OR results to be True and then False, respectively, thus specifying the resulting value for their processing of the empty set.

I've read through your reply several times, and I think you've missed the point.

The code here is the code that produces the right result for non-empty collections. It's the shortest, cleanest, clearest code that does so. These aren't random initial values, chosen arbitrarily. They are the unique values that make the code give the right answer.

Then we ask: What result does it give for the empty collection?

The answer is that for "sum" it gives "0", for "product" it gives "1", for "AND" it gives "True", for "OR" it gives "False".

In particular, in each case it gives the identity element of the algebraic structure. This isn't a coincidence, it's a part of how algebraic operations work.

That's why for any operator, the result of applying it to an empty collection is the identity element. It's algebraically consistent.


Replies

MrMcCall12/17/2024

Sure, but as a programmer, my job is to specify and code out the semantics of the system. ANDing and ORing a set of bools may very well be different for one list's semantics than another's.

So, the initial value that forms the basis for those computations -- to my mind and experience -- is as related to the value computed for the empty set as the programmer decides it should be. I don't think that function's default will necessarily be the proper semantic result when applied to the empty set.

As an example, why should "Are all hats green?" have the same result as "Are all hats NOT green?"? If the logical computation's initial value is the automatic result, then you have merely answered the mathematical-logic answer to a question about sets, not about the list of real-world things being modeled.

If one is writing pure math software, then the answer will be the pure math logical result. When one is modeling a real-world system, the semantics require another level of specification, in my experience and opinion.

(Good morning. I've never replied to such an old comment before. I do not yet have software to monitor my active conversations around here, and am only just beginning to entertain undertaking such a project, so it is merely luck of the universe that I found your interesting comment this morning. Thanks. It's like a mental warm-up as I begin my day.)