3 ms·
i 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 equiv
by uryga 7y ago
i 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