Tristate - wanna?

Alex Parrill via Digitalmars-d digitalmars-d at puremagic.com
Sat Mar 26 19:36:47 PDT 2016


On Sunday, 27 March 2016 at 02:19:56 UTC, crimaniak wrote:
> On Saturday, 26 March 2016 at 22:39:58 UTC, Alex Parrill wrote:
>
> ...
>> If we're going down that route, might as well use state tables.
> ...
>
> For Boolean, Ternary, and N-state logic:
>
> a && b == min(a, b)
> a || b == max(a, b)
> ~a == N-1-a
>
> why to optimize it more?

That's incorrect for the `unknown` value.

Lets say you represented true as 1f, false as 0f, and unknown as 
NaN...

std.algorithm.max(0, 0f/0f) = 0, but should be NaN
std.math.fmax(1, 0f/0f) = NaN, but should be 1

N-state logic isn't just about probabilities either. According to 
Wikipedia, Bochvar's three-valued logic has an "internal" state, 
where any operation with `internal` results in `internal` 
(similar to NaN). More broadly, the values and operations between 
them could be whatever the mathematician or developer wants, so a 
truth table is one of the ways to generally specify an operator.


More information about the Digitalmars-d mailing list