Topic: C++ types std::boolean, std::true, std::false


Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Wed, 26 Jun 2013 18:11:12 +0200
Raw View
On Mon, Jun 24, 2013 at 7:40 PM, Greg Marr <gregmmarr@gmail.com> wrote:
>
> On Monday, June 24, 2013 4:37:47 AM UTC-4, Jim Smith wrote:
>>
>> std::bool_intermediate for states that are not true or false.  ... Also, std::bool_intermediate take into account the superposition of the two boolean states.
>
>
> This sounds exactly like std::optional<bool>.


I think `optional<bool>` has confusing semantics to be used for
tri-value logic. I'll call the third value "third", just for
exposition. Consider:

// I would normally not use == true, but I think it is worth for clarity here
optional<bool> a = true;
assert(bool(a) == true);
assert(bool(!a) == false);
assert(*a == true);

optional<bool> b = false;
assert(bool(a) == true);
assert(bool(!a) == false);
assert(*a == false);

auto third = none;
optional<bool> c = third;
assert(bool(c) == false);
assert(bool(!c) == true);
// *c is UB

With this `bool(a)` or any contextual conversion to bool, like
`if(a)`, means "Is `a` not the third value?"/
`bool(!a)` means "Is `a` the third value?"
And `*a` means "assuming `a` is not the third value, is it true?"
The question "Is `a` false?" would have to be `!*a`, which is actually
"assuming `a` is not the third value, is it true?"

So a three-way if with optional<bool> would look like:

if(!a) {
    // third value
} else if(*a) {
    // true
} else {
    // false
}

I prefer something like boost::tribool.

tribool a = true;
assert(bool(a) == true);
assert(bool(!a) == false);

tribool b = false;
assert(bool(a) == false);
assert(bool(!a) == true);

tribool c = third;
assert(bool(c) == false);
assert(bool(!c) == false);

With this `bool(a)` means "Is `a` true?", and `bool(!a)` means "Is `a`
false?". The third value, not being true nor false yields "no" for
both queries.

So a three-way if looks like:

if(a) {
    // true
} else if(!a) {
    // false
} else {
    // third value
}

Another thing to notice is that `operator!` works as expected with
tribool: the negation of true is false, and the negation of false is
true. The negation of an indeterminate value is indeterminate (it acts
a bit like NaN in floating point arithmetic; call it not-a-boolean ;).
With optional<bool> the negation of false is false.

I prefer to restrict my usage of optional<bool> for incidental
occurrences in generic code, and not as a tri-valued boolean. I don't
need it often, but I wouldn't mind having a tribool type in the
standard library, as long as it is not some "object-oriented"
nonsense.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.


Author: Fernando Cacciola <fernando.cacciola@gmail.com>
Date: Wed, 26 Jun 2013 23:30:23 -0300
Raw View
--001a11c31598bc937d04e0198dae
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Jun 26, 2013 at 1:11 PM, Martinho Fernandes <
martinho.fernandes@gmail.com> wrote:

> On Mon, Jun 24, 2013 at 7:40 PM, Greg Marr <gregmmarr@gmail.com> wrote:
> >
> > On Monday, June 24, 2013 4:37:47 AM UTC-4, Jim Smith wrote:
> >>
> >> std::bool_intermediate for states that are not true or false.  ...
> Also, std::bool_intermediate take into account the superposition of the two
> boolean states.
> >
> >
> > This sounds exactly like std::optional<bool>.
>
>
> I think `optional<bool>` has confusing semantics to be used for
> tri-value logic.


FWIW, I totally agree with you here, and in fact, we have boost::tribool
precisely because boost::optional<bool> didn't quite cut it.

I thought about having core support for tribool but it's quite tricky to
get right, and pure library support is actually enough, even if not as
convenient.

I use triboolean logic all over the place when I work on a very specific
(and specialized) domain, for which I write code like:

if ( certainly(b) )
{
 // b == true
}
else if ( certainly_not(b) )
{
  // b == false
}
else
{
 // b is indeterminate (or neither true nor false if we consider a more
general lattice type)
}

I'm not fond of the extra verbosity or the fact that the triboolean
expression b must be evaluated twice (unless is set aside before the
statement), but I can live with that.

So, is there any proposal for tribool already?

Best

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



--001a11c31598bc937d04e0198dae
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On W=
ed, Jun 26, 2013 at 1:11 PM, Martinho Fernandes <span dir=3D"ltr">&lt;<a hr=
ef=3D"mailto:martinho.fernandes@gmail.com" target=3D"_blank">martinho.ferna=
ndes@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div>On Mon, Jun 24, 2013=
 at 7:40 PM, Greg Marr &lt;<a href=3D"mailto:gregmmarr@gmail.com" target=3D=
"_blank">gregmmarr@gmail.com</a>&gt; wrote:<br>



&gt;<br>
&gt; On Monday, June 24, 2013 4:37:47 AM UTC-4, Jim Smith wrote:<br>
&gt;&gt;<br>
&gt;&gt; std::bool_intermediate for states that are not true or false. =A0.=
... Also, std::bool_intermediate take into account the superposition of the =
two boolean states.<br>
&gt;<br>
&gt;<br>
&gt; This sounds exactly like std::optional&lt;bool&gt;.<br>
<br>
<br>
</div>I think `optional&lt;bool&gt;` has confusing semantics to be used for=
<br>
tri-value logic.</blockquote><div><br></div><div>FWIW, I totally agree with=
 you here, and in fact, we have boost::tribool precisely because boost::opt=
ional&lt;bool&gt; didn&#39;t quite cut it.<br><br></div><div>I thought abou=
t having core support for tribool but it&#39;s quite tricky to get right, a=
nd pure library support is actually enough, even if not as convenient.<br>

</div><div><br>I use triboolean logic all over the place when I work on a v=
ery specific (and specialized) domain, for which I write code like:<br><br>=
</div><div>if ( certainly(b) )<br>{<br></div><div>=A0// b =3D=3D true<br></=
div>

<div>}<br>else if ( certainly_not(b) ) <br>{<br></div><div>=A0 // b =3D=3D =
false<br></div><div>}<br></div><div>else<br>{<br></div><div>=A0// b is inde=
terminate (or neither true nor false if we consider a more general lattice =
type)<br>

</div><div>}<br><br></div><div>I&#39;m not fond of the extra verbosity or t=
he fact that the triboolean expression b must be evaluated twice (unless is=
 set aside before the statement), but I can live with that.<br></div><div>

<br></div><div>So, is there any proposal for tribool already?<br></div><div=
><br></div><div>Best</div></div><br>-- <br>Fernando Cacciola<br>SciSoft Con=
sulting, Founder<br><a href=3D"http://www.scisoft-consulting.com" target=3D=
"_blank">http://www.scisoft-consulting.com</a>
</div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

--001a11c31598bc937d04e0198dae--

.


Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Thu, 27 Jun 2013 10:56:20 +0200
Raw View
On 06/27/2013 04:30 AM, Fernando Cacciola wrote:

> I thought about having core support for tribool but it's quite tricky to
> get right, and pure library support is actually enough, even if not as
> convenient.

You should also consider the behavior of the logical operators. I have
had use cases where I could not use boost::tribool because it truth
table did not match my needs. Instead I needed operators that always
yielded determinate values (true/false) unless both operands were
indeterminate. I am going to call this boolean type for neutral bool
below.

I have listed the truth tables of the two below. I use F = false, T =
true, and N = none/indeterminate.

The truth tables for boost::tribool:

   NOT |
   ----+---
     F | T
     T | F
     N | N

   AND | F T N
   ----+-------
     F | F F F
     T | F T N
     N | F N N

   OR  | F T N
   ----+-------
     F | F T N
     T | T T T
     N | N T N

The truth tables for neutral bool:

   NOT |
   ----+---
     F | T
     T | F
     N | N

   AND | F T N
   ----+-------
     F | F F F
     T | F T T
     N | F T N

   OR  | F T N
   ----+-------
     F | F T F
     T | T T T
     N | F T N

There may also be a valid use case for a NaN-like tribool that always
yields indeterminate if either operand is indeterminate, but I am not
going to elaborate on that here.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.


Author: Fernando Cacciola <fernando.cacciola@gmail.com>
Date: Thu, 27 Jun 2013 09:23:08 -0300
Raw View
--001a11c3aa2a94a4ef04e021d57a
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Jun 27, 2013 at 5:56 AM, Bjorn Reese <breese@mail1.stofanet.dk>wrote:

> On 06/27/2013 04:30 AM, Fernando Cacciola wrote:
>
>  I thought about having core support for tribool but it's quite tricky to
>> get right, and pure library support is actually enough, even if not as
>> convenient.
>>
>
> You should also consider the behavior of the logical operators. I have
> had use cases where I could not use boost::tribool because it truth
> table did not match my needs. Instead I needed operators that always
> yielded determinate values (true/false) unless both operands were
> indeterminate. I am going to call this boolean type for neutral bool
> below.
>

Interesting.

Following your truth table below, I would say that, ultimately, you need:

a & b -> possibly ( a & b ) // if using tribool

a | b -> certainly( a | b ) // if using tribool

everything else seems to match tribool.

Would you be able to use the equivalence above and stick to tribool?


Regarding core support, here is where I am at the moment, FWIW:

The difficulty boils down to the fact that there are two paths to reduce
from tribool to bool.

We have:

certainly(b)        == true IFF b = true
certainly_not(b) == true IFF b = false
possibly(b)        == true IFF b != false
possibly_not(b) == true IFF b != true

thus, given

tribool tb ;

foo ( bool ) ; foo(tb);
if ( tb )
tb ?
while(tb)

all of them coluld be equivalent to reducing via certainly or possibly, but
arbitraryly picking one doesn't seem right.

For example, I normally write

if ( certainly(tb) )
else if ( certainly_not(tb) )
else // only indeterminate falls here

but it's also quite reasonable to do

if ( certainly(tb) )
else // both false and indeterminate falls here

so it would not be at all evident what:

if ( tb )
else

actually means, NOT even if we guessed that if ( tb ) means if (
certainly(tb) )

my current preference  goes to disallow entirely conversion to bool, not
even explicit, and add the following new keywords:

certainly_if
possibly_if
certainly_else
possibly_else

so that I can write:

certianly_if ( tb )
{
  // tb == true for sure
}
certainly_else
{
 // tb == false for sure
}
else
{
  // can't tel
}

Granted, certainly_if ( tb ) is so much the same as if ( certainly(tb) )
that a new keyword seems totally unnecesary, but the real thing is the
_else keywords:

certainly_else
{
}

is much much better (IMHO) than

else if ( certainly_not(tb) )
{
}

so I like that one to be in core, but then the _if versions make sense just
for completeness

Best

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



--001a11c3aa2a94a4ef04e021d57a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 27, 2013 at 5:56 AM, Bjorn Reese <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:breese@mail1.stofanet.dk" target=3D"_blank">breese@mail1.stofanet.dk<=
/a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div class=3D"im">On 06/2=
7/2013 04:30 AM, Fernando Cacciola wrote:<br>
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex">
I thought about having core support for tribool but it&#39;s quite tricky t=
o<br>
get right, and pure library support is actually enough, even if not as<br>
convenient.<br>
</blockquote>
<br></div>
You should also consider the behavior of the logical operators. I have<br>
had use cases where I could not use boost::tribool because it truth<br>
table did not match my needs. Instead I needed operators that always<br>
yielded determinate values (true/false) unless both operands were<br>
indeterminate. I am going to call this boolean type for neutral bool<br>
below.<br></blockquote><div><br></div><div>Interesting.<br><br></div><div>F=
ollowing your truth table below, I would say that, ultimately, you need:<br=
><br></div><div>a &amp; b -&gt; possibly ( a &amp; b ) // if using tribool<=
br>

<br></div><div>a | b -&gt; certainly( a | b ) // if using tribool<br><br></=
div><div>everything else seems to match tribool.<br><br></div><div class=3D=
"h5">Would you be able to use the equivalence above and stick to tribool?<b=
r>

<br>
<br></div><div class=3D"h5">Regarding core support, here is where I am at t=
he moment, FWIW:<br><br></div><div class=3D"h5">The difficulty boils down t=
o the fact that there are two paths to reduce from tribool to bool. <br><br=
>

We have:<br><br></div><div class=3D"h5">certainly(b)=A0=A0=A0=A0=A0=A0=A0 =
=3D=3D true IFF b =3D true<br></div><div class=3D"h5"><div class=3D"h5">cer=
tainly_not(b) =3D=3D true IFF b =3D false<br></div>possibly(b) =A0 =A0 =A0=
=A0 =3D=3D true IFF b !=3D false<br></div><div class=3D"h5">

possibly_not(b) =3D=3D true IFF b !=3D true<br><br>
</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left:1px solid rgb(204,204,204);padding-left:1ex"></blockquote></div>=
thus, given<br><br></div><div class=3D"gmail_extra">tribool tb ;<br></div><=
div class=3D"gmail_extra">

<br></div><div class=3D"gmail_extra">foo ( bool ) ; foo(tb);<br></div><div =
class=3D"gmail_extra">if ( tb )<br></div><div class=3D"gmail_extra">tb ? <b=
r></div><div class=3D"gmail_extra">while(tb)<br><br></div><div class=3D"gma=
il_extra">

all of them coluld be equivalent to reducing via certainly or possibly, but=
 arbitraryly picking one doesn&#39;t seem right.<br><br></div><div class=3D=
"gmail_extra">For example, I normally write<br><br></div><div class=3D"gmai=
l_extra">

if ( certainly(tb) )<br>else if ( certainly_not(tb) )<br>else // only indet=
erminate falls here<br><br></div><div class=3D"gmail_extra">but it&#39;s al=
so quite reasonable to do<br><br></div><div class=3D"gmail_extra">if ( cert=
ainly(tb) )<br>

else // both false and indeterminate falls here<br><br></div><div class=3D"=
gmail_extra">so it would not be at all evident what:<br><br></div><div clas=
s=3D"gmail_extra">if ( tb )<br>else <br><br></div><div class=3D"gmail_extra=
">

actually means, NOT even if we guessed that if ( tb ) means if ( certainly(=
tb) )<br><br></div><div class=3D"gmail_extra">my current preference=A0 goes=
 to disallow entirely conversion to bool, not even explicit, and add the fo=
llowing new keywords:<br>

<br></div><div class=3D"gmail_extra">certainly_if<br></div><div class=3D"gm=
ail_extra">possibly_if<br></div><div class=3D"gmail_extra">certainly_else<b=
r></div><div class=3D"gmail_extra">possibly_else<br><br></div><div class=3D=
"gmail_extra">

so that I can write:<br><br></div><div class=3D"gmail_extra">certianly_if (=
 tb )<br>{<br></div><div class=3D"gmail_extra">=A0 // tb =3D=3D true for su=
re<br></div><div class=3D"gmail_extra">}<br>certainly_else<br>{<br></div><d=
iv class=3D"gmail_extra">

=A0// tb =3D=3D false for sure<br></div><div class=3D"gmail_extra">}<br></d=
iv><div class=3D"gmail_extra">else<br>{<br></div><div class=3D"gmail_extra"=
>=A0 // can&#39;t tel<br></div><div class=3D"gmail_extra">}<br></div><div c=
lass=3D"gmail_extra">

<br></div><div class=3D"gmail_extra">Granted, certainly_if ( tb ) is so muc=
h the same as if ( certainly(tb) ) that a new keyword seems totally unneces=
ary, but the real thing is the _else keywords:<br><br>certainly_else<br>
{<br>
}<br><br>is much much better (IMHO) than<br><br>else if ( certainly_not(tb)=
 )<br>{<br>}<br><br></div><div class=3D"gmail_extra">so I like that one to =
be in core, but then the _if versions make sense just for completeness<br>

<br></div><div class=3D"gmail_extra">Best<br></div><div class=3D"gmail_extr=
a"><br>-- <br>Fernando Cacciola<br>SciSoft Consulting, Founder<br><a href=
=3D"http://www.scisoft-consulting.com">http://www.scisoft-consulting.com</a=
>
</div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

--001a11c3aa2a94a4ef04e021d57a--

.


Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Thu, 27 Jun 2013 14:45:34 +0200
Raw View
On Thu, Jun 27, 2013 at 2:23 PM, Fernando Cacciola
<fernando.cacciola@gmail.com> wrote:
> my current preference  goes to disallow entirely conversion to bool, not
> even explicit, and add the following new keywords:

I don't think there's a good chance of getting new keywords for
something that is a bit of a niche and has proven library-only
implementations :(

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.


Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Thu, 27 Jun 2013 16:03:07 +0200
Raw View
On 06/27/2013 02:23 PM, Fernando Cacciola wrote:

> Following your truth table below, I would say that, ultimately, you need:

If I understood your certainly/possibly functions correctly, the take a
tribool and returns a bool.

> a & b -> possibly ( a & b ) // if using tribool

This will give me

   AND | F T N
   ----+-------
     F | F F F
     T | F T T
     N | F T T

but I need N && N == N.

> a | b -> certainly( a | b ) // if using tribool

This will give me

   OR  | F T N
   ----+-------
     F | F T F
     T | T T T
     N | F T F

but I need N || N == N.

Maybe neutral bool could be handled via a policy or trait of tribool?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.


Author: Fernando Cacciola <fernando.cacciola@gmail.com>
Date: Thu, 27 Jun 2013 12:03:36 -0300
Raw View
--089e01493e2e75e76504e02413b9
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Jun 27, 2013 at 11:03 AM, Bjorn Reese <breese@mail1.stofanet.dk>wrote:

> On 06/27/2013 02:23 PM, Fernando Cacciola wrote:
>
>  Following your truth table below, I would say that, ultimately, you need:
>>
>
> If I understood your certainly/possibly functions correctly, the take a
> tribool and returns a bool.
>
>
>  a & b -> possibly ( a & b ) // if using tribool
>>
>
> This will give me
>
>
>   AND | F T N
>   ----+-------
>     F | F F F
>     T | F T T
>     N | F T T
>
> but I need N && N == N.
>
>
>  a | b -> certainly( a | b ) // if using tribool
>>
>
> This will give me
>
>
>   OR  | F T N
>   ----+-------
>     F | F T F
>     T | T T T
>     N | F T F
>
> but I need N || N == N.
>
>
OK.I actually noticed that but didn't pay attention since it matched tribol
behavior.

I went the posibly|cerainly road as an attempt to follow why would you need
such a behavior.
When you ask: "is a AND b", and you cannot tell a or b, then IMO the answer
is 'how should I know". Which is why N/F AND N/F is N in tribool

So, it looked like you are asking more like: "could it be a AND b", hence
my version. But I'm still suspicious, "I don't know" and "yes" are not
"yes" both at the same time.

Now....

AND and OR can be generalized as a count_true function such that:

a AND b AND c AND d means

 count_true( answers )==answers.count

a OR b OR c OR d means

 count_true( answers )==1

From this POV, you seem to need to know whether all of the *actual* answers
are true at the same time (or at least one in the case of |).
That is:

actual_answers=filter_out_indeterminate(answers);

your AND -> count_true(actual_answers)==actual_answers.count with .count !=
0

your OR -> count_true(actual_answers)==1


Thus, it looks to me that your real need are specialized AND/OR as opposed
to a specialized Truth Table.
That is, we could have tribool and you could have you own AND/OR functions
that do what you want, which, like I said, looks to me that as just
filtering out the indeterminate.


> Maybe neutral bool could be handled via a policy or trait of tribool?
>
>
>  For something like this, a policy would be overkill. But this is a
different discussion.

Best



--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



--089e01493e2e75e76504e02413b9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 27, 2013 at 11:03 AM, Bjorn Reese <span dir=3D"ltr">&lt;<a href=3D"=
mailto:breese@mail1.stofanet.dk" target=3D"_blank">breese@mail1.stofanet.dk=
</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div class=3D"im">On 06/2=
7/2013 02:23 PM, Fernando Cacciola wrote:<br>
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex">
Following your truth table below, I would say that, ultimately, you need:<b=
r>
</blockquote>
<br></div>
If I understood your certainly/possibly functions correctly, the take a<br>
tribool and returns a bool.<div class=3D"im"><br>
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex">
a &amp; b -&gt; possibly ( a &amp; b ) // if using tribool<br>
</blockquote>
<br></div>
This will give me<div class=3D"im"><br>
<br>
=A0 AND | F T N<br>
=A0 ----+-------<br>
=A0 =A0 F | F F F<br>
=A0 =A0 T | F T T<br></div>
=A0 =A0 N | F T T<br>
<br>
but I need N &amp;&amp; N =3D=3D N.<div class=3D"im"><br>
<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex">
a | b -&gt; certainly( a | b ) // if using tribool<br>
</blockquote>
<br></div>
This will give me<div class=3D"im"><br>
<br>
=A0 OR =A0| F T N<br>
=A0 ----+-------<br>
=A0 =A0 F | F T F<br>
=A0 =A0 T | T T T<br></div>
=A0 =A0 N | F T F<br>
<br>
but I need N || N =3D=3D N.<br>
<br></blockquote><div><br></div><div>OK.I actually noticed that but didn&#3=
9;t pay attention since it matched tribol behavior.<br><br></div><div>I wen=
t the posibly|cerainly road as an attempt to follow why would you need such=
 a behavior.<br>

</div><div>When you ask: &quot;is a AND b&quot;, and you cannot tell a or b=
, then IMO the answer is &#39;how should I know&quot;. Which is why N/F AND=
 N/F is N in tribool<br><br></div><div>So, it looked like you are asking mo=
re like: &quot;could it be a AND b&quot;, hence my version. But I&#39;m sti=
ll suspicious, &quot;I don&#39;t know&quot; and &quot;yes&quot; are not &qu=
ot;yes&quot; both at the same time.<br>

<br></div><div>Now....<br><br></div><div>AND and OR can be generalized as a=
 count_true function such that:<br>=A0<br></div><div>a AND b AND c AND d me=
ans<br><br>=A0count_true( answers )=3D=3Danswers.count<br><br></div><div>a =
OR b OR c OR d means<br>

</div><div><br>=A0count_true( answers )=3D=3D1<br><br></div>From this POV, =
you seem to need to know whether all of the *actual* answers are true at th=
e same time (or at least one in the case of |).<br></div><div class=3D"gmai=
l_quote">

That is:<br></div><div class=3D"gmail_quote"><br>actual_answers=3Dfilter_ou=
t_indeterminate(answers);=A0 <br><br>your AND -&gt; count_true(actual_answe=
rs)=3D=3Dactual_answers.count with .count !=3D 0<br><br>your OR -&gt; count=
_true(actual_answers)=3D=3D1<br>

<br><br></div><div class=3D"gmail_quote"><div>Thus, it looks to me that you=
r real need are specialized AND/OR as opposed to a specialized Truth Table.=
<br></div><div>That is, we could have tribool and you could have you own AN=
D/OR functions that do what you want, which, like I said, looks to me that =
as just filtering out the indeterminate.<br>

</div><div></div><div>=A0<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">
Maybe neutral bool could be handled via a policy or trait of tribool?<div c=
lass=3D""><div class=3D"h5"><br>
<br></div></div></blockquote><div>=A0For something like this, a policy woul=
d be overkill. But this is a different discussion.<br><br></div><div>Best<b=
r></div></div><br><br clear=3D"all"><br>-- <br>Fernando Cacciola<br>SciSoft=
 Consulting, Founder<br>

<a href=3D"http://www.scisoft-consulting.com">http://www.scisoft-consulting=
..com</a>
</div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

--089e01493e2e75e76504e02413b9--

.


Author: Fernando Cacciola <fernando.cacciola@gmail.com>
Date: Thu, 27 Jun 2013 15:36:51 -0300
Raw View
--047d7b342d482cf32104e0270e19
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Jun 27, 2013 at 12:03 PM, Fernando Cacciola <
fernando.cacciola@gmail.com> wrote:

> On Thu, Jun 27, 2013 at 11:03 AM, Bjorn Reese <breese@mail1.stofanet.dk>wrote:
>


> That is, we could have tribool and you could have you own AND/OR functions
> that do what you want, which, like I said, looks to me that as just
> filtering out the indeterminate.
>
>

Well, here is something interesting.

These days I'm creating a DSL for SQL query construction, and I was just
looking at the following real code I've created with it:

   Schemas.Doc.Id.Is( aDocModel.Id )
|  (     Schemas.Doc.Label.Is( aDocModel.Name)
     & Schemas.DocCategory.Category.IsAnyOf(aDocModel.Tags)
   )

That code there creates an string that can be added to a WHERE SQL clause.

I wanted this to be super easy to use by the "end-user" programmers, so I
made it such that, if any of the "input values" are null, the expression
automatically reduces.
That is,

if aDocMode.Id is null (or empty in this case as it is a string), then the
above is actually equivalent to just:

        Schemas.Doc.Label.Is( aDocModel.Name)
     & Schemas.DocCategory.Category.IsAnyOf(aDocModel.Tags)

Similarly, if, OTOH, aDocModel.Tags, which is a sequence, happens to be
empty, it reduces to:

   Schemas.Doc.Id.Is( aDocModel.Id )
|  Schemas.Doc.Label.Is( aDocModel.Name)


Now, I just realized that, IIUC, this exactly matches the net effect of
your choice of semantic for & and | with your neutral tribool.
In fact, I might even implemented this using your type.

So, FWIW I found real use cases as I wanted.

Best

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



--047d7b342d482cf32104e0270e19
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 27, 2013 at 12:03 PM, Fernando Cacciola <span dir=3D"ltr">&lt;<a hr=
ef=3D"mailto:fernando.cacciola@gmail.com" target=3D"_blank">fernando.caccio=
la@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div cla=
ss=3D"gmail_extra"><div class=3D"gmail_quote"><div class=3D"gmail_quote">On=
 Thu, Jun 27, 2013 at 11:03 AM, Bjorn Reese <span dir=3D"ltr">&lt;<a href=
=3D"mailto:breese@mail1.stofanet.dk" target=3D"_blank">breese@mail1.stofane=
t.dk</a>&gt;</span> wrote:<div>

</div></div></div></div></div></blockquote><div>=A0</div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra=
"><div class=3D"gmail_quote">

<div class=3D"gmail_quote"><div>That is, we could have tribool and you coul=
d have you own AND/OR functions that do what you want, which, like I said, =
looks to me that as just filtering out the indeterminate.<br>
</div><div class=3D"im"><div>=A0<br></div></div></div></div></div></div></b=
lockquote><div><br>Well, here is something interesting.<br><br>These days I=
&#39;m creating a DSL for SQL query construction, and I was just looking at=
 the following real code I&#39;ve created with it:<br>

<br>=A0=A0 <a href=3D"http://Schemas.Doc.Id.Is">Schemas.Doc.Id.Is</a>( aDoc=
Model.Id )<br>|=A0 (=A0=A0=A0=A0 <a href=3D"http://Schemas.Doc.Label.Is">Sc=
hemas.Doc.Label.Is</a>( aDocModel.Name) <br>=A0=A0=A0=A0 &amp; Schemas.DocC=
ategory.Category.IsAnyOf(aDocModel.Tags)<br>

=A0=A0 )<br><br></div><div>That code there creates an string that can be ad=
ded to a WHERE SQL clause.<br><br></div><div>I wanted this to be super easy=
 to use by the &quot;end-user&quot; programmers, so I made it such that, if=
 any of the &quot;input values&quot; are null, the expression automatically=
 reduces.<br>

</div><div>That is,<br><br></div><div>if aDocMode.Id is null (or empty in t=
his case as it is a string), then the above is actually equivalent to just:=
<br><br>=A0 =A0 =A0 =A0 <a href=3D"http://Schemas.Doc.Label.Is">Schemas.Doc=
..Label.Is</a>( aDocModel.Name) <br>

=A0=A0=A0=A0 &amp; Schemas.DocCategory.Category.IsAnyOf(aDocModel.Tags)<br>=
<br></div><div>Similarly, if, OTOH, aDocModel.Tags, which is a sequence, ha=
ppens to be empty, it reduces to:<br><br>=A0=A0 <a href=3D"http://Schemas.D=
oc.Id.Is">Schemas.Doc.Id.Is</a>( aDocModel.Id )<br>

|=A0 <a href=3D"http://Schemas.Doc.Label.Is">Schemas.Doc.Label.Is</a>( aDoc=
Model.Name) <br><br><br></div><div>Now, I just realized that, IIUC, this ex=
actly matches the net effect of your choice of semantic for &amp; and | wit=
h your neutral tribool.<br>

</div><div>In fact, I might even implemented this using your type.<br><br><=
/div><div>So, FWIW I found real use cases as I wanted.<br><br></div><div>Be=
st<br></div><div><br></div></div>-- <br>Fernando Cacciola<br>SciSoft Consul=
ting, Founder<br>

<a href=3D"http://www.scisoft-consulting.com">http://www.scisoft-consulting=
..com</a>
</div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

--047d7b342d482cf32104e0270e19--

.


Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Sat, 29 Jun 2013 12:04:25 +0200
Raw View
On 06/27/2013 08:36 PM, Fernando Cacciola wrote:

> So, FWIW I found real use cases as I wanted.

Intriguingly, my real-world use case also came from an SQL-like setting.
I had to examine if two rows were similar by comparing their entries
pairwise. Each entry could be null, but the result of the pairwise
comparison should only be null if both entries were null. The results
of each pairwise comparison was then aggregated into the final result.
By having the pairwise comparison operator return a neutral bool, the
aggregation simply became:

   neutral_bool has_artist = row1.artist == row2.artist;
   neutral_bool has_album = row1.album == row2.album;
   neutral_bool result = has_artist && has_album;

The actual code did not use the intermediate has_artist and has_album
variables, and there were more entries that the two listed above.

Regarding the use of traits, I put together a simple prototype of
tribool that uses traits to obtain both the  traditional tribool
behavior and the neutral bool behavior. Pretty straigh-forward.

   https://github.com/breese/tribool/blob/master/include/tribool

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sun, 30 Jun 2013 00:48:38 -0700 (PDT)
Raw View
------=_Part_2222_30527753.1372578518761
Content-Type: text/plain; charset=ISO-8859-1

 Multi-value logic (and tribool is part of it) is based on the fact that
you use values 0,...,n (total n+1) :
not(v) = n-v

and(v1,...,vk) = min(v1,...,vk)

or(v1,...,vk) = max(v1,...,vk)

In case of tribool (n=2):
F = 0
N = 1
T = 2
And all the truth tables can be easily derived.
You can further with logic:
F - not true // impossible
N - unknown likelihood
T - true // certain

certain(v) iff v = T
uncertain(v) iff  v < T
possible(v) iff v > F
impossible(v) iff v = F





--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



------=_Part_2222_30527753.1372578518761
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>
Multi-value logic (and tribool is part of it) is based on the fact that you=
 use values 0,...,n (total n+1)&nbsp;:</div><div>not(v) =3D n-v</div><div>&=
nbsp;</div><div>and(v1,...,vk) =3D min(v1,...,vk)</div><div>&nbsp;</div><di=
v>or(v1,...,vk) =3D max(v1,...,vk)</div><div>&nbsp;</div><div>In case of tr=
ibool (n=3D2):</div><div>F =3D 0&nbsp; </div><div>N =3D 1</div><div>T =3D 2=
</div><div>And all the truth tables can be easily derived.</div><div>You ca=
n further with logic:</div><div>F - not true // impossible</div><div>N - un=
known likelihood</div><div>T - true // certain</div><div>&nbsp;</div><div>c=
ertain(v) iff&nbsp;v =3D T</div><div>uncertain(v) iff&nbsp; v &lt; T</div><=
div>possible(v) iff v &gt; F</div><div>impossible(v) iff v =3D F</div><div>=
&nbsp;</div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;</div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2222_30527753.1372578518761--

.


Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Sun, 30 Jun 2013 11:38:04 +0200
Raw View
On 06/30/2013 09:48 AM, Mikhail Semenov wrote:
> Multi-value logic (and tribool is part of it) is based on the fact that
> you use values 0,...,n (total n+1) :

This reminded me of N2136 "Bool_set: multi-valued logic"

   http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2136.pdf

The most recent status of this proposal that I could find is:

   http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3371.html

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.



.