5 ms·
It's not just an assemblyism, the near equivalence between 0 and false, and 1 and true is the thing that Boole wrote about for which Boolean values are named. I
by c3534l 7y ago
It's not just an assemblyism, the near equivalence between 0 and false, and 1 and true is the thing that Boole wrote about for which Boolean values are named. I would argue that it's a math thing, not an assembly thing.
- Sharlin 7y agoThat’s true enough, but in programming languages it’s usually zero=false and any non-zero=true, at least in argument position. That’s more difficult to justify mathematically.
- uryga 7y agoi haven't checked it thoroughly, but it looks like all the desired properties of boolean arithmetic are preserved when false = 0 true = [1] (i.e. the equivalence class of all n > 0) && = + || = * spelling it out: || / + (or): 0+0 = 0 0+[1] = [1]+0 = [1] [1]+[1] = [1] && / * (and): 0*0 = 0 0*[1] = [1]*0 = 0 [1]*[1] = [1] where [1] stands for "any nonzero number". (please let me know if i missed anything!) so natural numbers (quotiented by an equivalence relation) seem to work as a model for boolean arithmetic. and idk if we need more mathematical justification than "it works fine" EDIT: changed "integers" to "natural numbers", because 5 + -5 = 0 so the `[1]+[1] = [1]` property doesn't hold
- bhaak 7y ago`[1]+[1] = [1]` also doesn't hold for natural numbers if you are programming in a language with integer overflow. Neither does the multiplication `[1]*[1] = [1]`
- uryga 7y agotrue! i wondered if i should include that but decided to stick with the "mathematical" naturals since we were talking from a math standpoint
- uryga 7y agobtw i came a across a definition of `||` which wouldn't have the `5 + -5` problem, and thus would make it all work with integers: x || y = x + y - xy
- sedachv 7y ago> I would argue that it's a math thing, not an assembly thing. When you have a type system and boolean types, equating 0 and false is not a "math thing," it is more of a "mathematical illiteracy" thing.