返回资讯中心
外部精选
软件工程
#开发者实时流

All Logic, No Bite

Today, I’d like to talk about logic — and before I do, I should probably explain why. But before we get to that, a definition may be in order: in a nutshell, logic is a system for drawing conclusions from premises (“fac…

Hacker News 最新weinzierl2026/10/16 · 2026/10/1630 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

29

4

7

Share

Today, I’d like to talk about logic — and before I do, I should probably explain why. But before we get to that, a definition may be in order: in a nutshell, logic is a system for drawing conclusions from premises (“facts”).

Formal logic usually isn’t taught in high school; as far as I know, a rigorous treatment of it isn’t even required for most computer science degrees. The concept is familiar to most mathematicians and to a handful of software engineers who dabble in esoteric programming languages. As for everyone else, we might know about “digital logic”, a simple algebra of binary numbers that involves operators such as AND, NOT, and OR. What’s less clear is how we get from zeroes and ones to some semblance of human reasoning.

For mathematicians, the most common role of formal logic is to provide a more precise vocabulary for proofs. To illustrate some of the ambiguities of everyday speech, consider the following statement in the form of “if A then B”:

It’s something a parent could say to a child. In that use, the phrasing clearly implies its own inverse, “if not A then not B”:

The statement also seems to imply the “if B then A” — although this form, called the converse, needs a small edit for clarity:

As for “if not B then not A” (contraposition), it ought to be true under the most pedantic interpretation of the original sentence. That said, in real life, it would be tacitly understood that other factors — say, a power outage — can get in the way of a gaming session even if the chores are taken care of. That’s to say, the truth of the contraposition is debatable:

Do all other “if A then B” statements play by the same rules? Nope:

This time around, the phrasing doesn’t imply the inverse (“if not A then not B”). The speaker isn’t suggesting that Mr. Mittens meows only when it wants to eat. Therefore, we can’t infer the following:

On the flip side, if the original assertion is true — if the cat is always vocal when hungry — the contraposition (“if not B then not A”) follows in a straightforward way:

Our problems with cat logic don’t end here. Let’s consider the following:

Both A and B are true, but most people would peg the statement as false — or at least wrong. The truths coincide, but we reject the argument because the antecedent (A) and the consequent (B) are not connected in any obvious way.

But what if I told you that every Sunday morning, Bob wakes up with a headache? This idea, expressed using the if-then connective, would read:

As before, we don’t know what’s the connection. Maybe there isn’t one; maybe the timing of Bob’s migraines is just a cosmic coincidence. Yet, in this context, a coincidence is good enough to accept the claim.

Another subjective issue crops up with the following statement:

It feels wrong, but there’s nothing we can disprove: the consequent is false, but so is the antecedent it’s gated on. We just don’t like that the sentence limits our imagination: perhaps if pigs could fly, all pumpkins would be donut-shaped? But if the task at hand is to work from true premises toward logical conclusions, and A is not a true premise, why the heck are we trying to form opinions about B? It’s a universe that doesn’t exist; we’re not given the axioms that govern it.

Let’s twist that knife a bit more: what do we make of the following sentences presented together?

An intuitive interpretation is that they can’t be both true at the same time. A more analytical view is that only the consequents can’t. In other words, maybe this is just telling us that pigs can’t possibly fly?…

It’s not just the if-then connective that’s cursed; the A and B atoms can cause problems too. In our examples, they appear to be declarations of facts — but can we proclaim anything we want? If I say “this statement is false”, is that a truth or a falsehood? Neither? Both?…

These semantic gotchas are great if you’re devising brain-teasers for nerds; they’re not helpful if you’re writing down a mathematical argument. This is why mathematicians rely on formal logic to define some predictable ground rules. The classic approach is pretty close to common sense, but it resolves the ambiguities by making several ad hoc calls. In particular:

A statement in the form “if A then B” (“A ⇒ B”):

…does not imply its inverse (“not A ⇒ not B”). A cat that always meows when hungry isn’t required to stay quiet once fed.

…doesn’t imply the converse (“B ⇒ A”). By extension, if you hear Mr. Mittens meowing, it’s not a given that he wants a meal.

…implies its contraposition (“not B ⇒ not A”). No meows is proof positive that the cat isn’t looking for food.

Lack of relevance is not fatal. A true proposition implies any other true proposition. In “if A then B”, it’s enough that A is true in tandem with B, so there’s nothing false about “if grass is green then kittens are cute”.

Counter-to-fact conditionals are true. A false antecedent can imply whatever it wants: “if pigs can fly then pumpkins are square”. The sentence is true, with no actual consequences for pumpkin shape.

You gotta take sides. The system only deals with statements that can bear a single, binary truth value. If it can’t, it’s not a valid statement.

Logic arguments expressed with words are easy to grasp, so to keep the riff-raff out, mathematicians often resort to symbolic notation. For example, the idea that sets A and B are equal to each other if and only if they contain the same elements can be more enigmatically spelled out as:

My initial plan for this article was to dive into this symbology next. But before we do, it may be useful to show how formal logic acts not only as a convenient language for proofs, but also as the source of math.

A real pain

Arithmetic is the oldest branch of mathematics; it’s also notable for having resisted attempts at formalization for a pretty long time. As it turns out, it’s tricky to explain numbers and basic arithmetic operations as anything other than “the things you know”. I don’t know why an apple plus an apple gives me two apples; I guess it’s just how apples are. It seems to work with fingers too.

Regular readers may recall two earlier articles about some of the successful efforts to construct the arithmetic of natural numbers and reals from scratch. In the end, we took the existence of an empty set as a given and then defined numbers and operations through the repeated application of several fairly intuitive rules:

How has mathematics gotten so abstract?

lcamtuf

·

September 27, 2025

Read full story

Unreal numbers

lcamtuf

·

Feb 15

Read full story

The beauty of this method is that it gave us more than what we already knew. For example, it seamlessly generalized to operations on infinite numbers, with mildly surprising results.

Unfortunately, in math textbooks, intuitive explanations aren’t the rule. Many of the discipline’s foundational axioms stem from investigations of the natural world, but we prefer to teach the craft as if it owed nothing to reality. In the modern academic practice, the question of where a particular idea came from, or whether an axiom is ontologically correct, is considered vacuous and out of scope. For the most part, you’re just handed a rulebook to play someone else’s game.

In the remainder of the section, I’ll try to kill two birds with one stone. First, we’ll look at yet another method of constructing the reals to develop intuition that will pay off once we get to digital logic (i.e., Boolean algebra). Second, on the topic of my mini-rant about mathematical education, we’ll note that the use of logic doesn’t necessarily make one’s arguments logical.

The usual axiomatic approach to defining reals is to give students a collection of roughly fourteen ad-hoc rules for manipulating the elements of an otherwise opaque set we call “ℝ”. The axiomatic method doesn’t care what the set contains or what it means; the method doesn’t even posit the existence of any canonical version of ℝ. We simply assert the existence of some structures — i.e., collections of objects and object relations — that, by the will of the gods of mathematical abstraction, obey the prescribed rules.

The rules are usually divided into three parts: field axioms, order axioms, and the axiom of completeness. Field axioms are easy; they pretend to be abstract, but tacitly capture natural laws. They assert the existence of a mystery operation called “addition” (symbol: “+”). The operation takes two operands in the reals and produces a result that’s also in ℝ. Further, the operation is associative and commutative; that is, for any a, b, and c in ℝ, it obeys the following equivalencies:

The same ruleset is given for multiplication (“·”):

So far, we’ve said nothing about what these two operators actually do. Turns out that we don’t have to say much; first, to distinguish between them, the axioms assert the existence of additive and multiplicative identities. By that, we mean a pair of elements in ℝ, conventionally labeled “0” and “1”, such that for any a chosen from the set of real numbers (for short: any a ∈ ℝ), the following equalities always hold true:

Again, the approach doesn’t concern itself with the “why” or the “how”; all we’re saying is that in a system that obeys our axioms, there must be a pair of elements for which the equalities hold. And if these elements exist, we might as well label them in a familiar way.

Next, we posit that for any a taken from ℝ, there exists an additive inverse (“-a”); and that for any a ≠ 0, we can also find a multiplicative inverse (“1/a”). Because we don’t have subtraction or division defined just yet, we treat these inverses as atomic symbols that obey the following rules:

The final field axiom is the distributive property that ties the two operators together: a · (b + c) = a · b + a · c.

The neat surprise is that these rules are already good enough to perform calculations in ℝ. By combining the axioms, we can easily prove that there can be only one additive identity (“0”), one multiplicative identity (“1”), and that “0” and “1” can’t be the same. Next, because addition always produces a result in ℝ, we conclude that there is a real associated with the value of 1 + 1. If we label this real “2”, we can for example show the following:

Alas, field axioms do not provide complete “driving directions” to the reals. There are many different algebraic fields; for instance, the exact same axioms are also satisfied by complex numbers. Heck, we can even make the rules work for certain types of finite sets, giving us modulo arithmetic systems that have applications in cryptography, but that would be frowned upon on a tax return. The smallest possible finite field needs just two elements: “0” and “1”, with the result of 1 + 1 simply wrapping around, computer-style.

To get closer to where we want to be, we continue with order axioms. We begin by proposing that for any a and b chosen from ℝ, exactly one of three possibilities must hold: a < b, a = b, or b < a. Further, to tie the behavior of the less-than operator to existing algebraic rules, we give the following axioms for any a, b, c ∈ ℝ:

If a < b and 0 < c (i.e., if c is positive), then a · c < b · c.

The structures that obey this criteria are infinite fields that do not wrap around and in which all elements are ordered in the usual arithmetic sense.

If you made this far, you might be wondering why I grumbled about how we teach math. Sure, we had a lot of axioms dumped at our doorstep with little justification, but in the end, they’re all saying reasonable things?…

The answer is that we’re not done yet: the rules we have in place are also valid for rational numbers (ℚ), a subset of real numbers that consists only of simple fractions and doesn’t include values such as π or √2. To get to a ruleset that unambiguously describes reals, we need to toss in the axiom of completeness.

To explain the usual phrasing of the axiom, we must first talk about subsets and their bounds. If

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →