ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:73986] [Ruby trunk Feature#12110] Can create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
@ 2016-02-25 16:30 ` waldyr.ar
  2016-02-25 16:31 ` [ruby-core:73987] " waldyr.ar
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: waldyr.ar @ 2016-02-25 16:30 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been reported by Waldyr de Souza.

----------------------------------------
Feature #12110: Can create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method like the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:73987] [Ruby trunk Feature#12110] Can create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
  2016-02-25 16:30 ` [ruby-core:73986] [Ruby trunk Feature#12110] Can create a method to avoid vacuous truth? waldyr.ar
@ 2016-02-25 16:31 ` waldyr.ar
  2016-02-25 18:47 ` [ruby-core:73989] [Ruby trunk Feature#12110] Create " waldyr.ar
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: waldyr.ar @ 2016-02-25 16:31 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Waldyr de Souza.

Description updated

----------------------------------------
Feature #12110: Can create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57140

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:73989] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
  2016-02-25 16:30 ` [ruby-core:73986] [Ruby trunk Feature#12110] Can create a method to avoid vacuous truth? waldyr.ar
  2016-02-25 16:31 ` [ruby-core:73987] " waldyr.ar
@ 2016-02-25 18:47 ` waldyr.ar
  2016-02-25 21:29 ` [ruby-core:73991] " shevegen
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: waldyr.ar @ 2016-02-25 18:47 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Waldyr de Souza.

Subject changed from Can create a method to avoid vacuous truth? to Create a method to avoid vacuous truth?

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57142

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:73991] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2016-02-25 18:47 ` [ruby-core:73989] [Ruby trunk Feature#12110] Create " waldyr.ar
@ 2016-02-25 21:29 ` shevegen
  2016-02-25 22:39 ` [ruby-core:73993] " matthew
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: shevegen @ 2016-02-25 21:29 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Robert A. Heiler.


Here is the biggest problem:

- What name would you give it? :)

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57143

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:73993] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2016-02-25 21:29 ` [ruby-core:73991] " shevegen
@ 2016-02-25 22:39 ` matthew
  2016-02-27 13:59 ` [ruby-core:74023] " andrew
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: matthew @ 2016-02-25 22:39 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Matthew Kerwin.


Robert A. Heiler wrote:
> Here is the biggest problem:
> 
> - What name would you give it? :)

​I seem to recall someone suggesting 'any_and_all?' in the past. Can't remember if I just made that up, though.

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57145

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74023] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2016-02-25 22:39 ` [ruby-core:73993] " matthew
@ 2016-02-27 13:59 ` andrew
  2016-02-28  0:51 ` [ruby-core:74027] " duerst
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: andrew @ 2016-02-27 13:59 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Andrew Vit.


Waldyr de Souza wrote:
> I often find myself running into unexpected results when using #all? for example
> 
> `[].all? { |e| false } # => true`

If you expect all false, then why not use `none?`, is it not sufficient?

> Even though it's logically correct could we have a method that express the following?
> 
> `foo.any? && foo.all?(&:bar)`

This also has edge cases, try: `foo = [nil]`

Matthew Kerwin wrote:
> I seem to recall someone suggesting 'any_and_all?' in the past.

This makes sense and it's consistent with `foo.any?(&block) && foo.all?(&block)`

This is still surprising to me, it looks like a contradiction:

```
[].any? #=> false
[].all? #=> true
```

I would expect "all" to be a superset of "any": both should mean "at least one".
Is there a reason for the existing behaviour, or is it just history now?


----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57174

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74027] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2016-02-27 13:59 ` [ruby-core:74023] " andrew
@ 2016-02-28  0:51 ` duerst
  2016-02-28  1:32 ` [ruby-core:74028] " sawadatsuyoshi
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: duerst @ 2016-02-28  0:51 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Martin Dürst.


Andrew Vit wrote:

> This is still surprising to me, it looks like a contradiction:
> 
> ```
> [].any? #=> false
> [].all? #=> true
> ```
> 
> I would expect "all" to be a superset of "any": both should mean "at least one".
> Is there a reason for the existing behavior, or is it just history now?

It's the way it works in Mathematics. But I'll try to explain it without using too much Mathematical terminology.

all? doesn't ask "at least one"?, but really "are all of those that are in the array true?". If there's no element in the array, then the condition is indeed true for all elements in the array.

Another way to try to understand this is to look at how these operations can be expressed by using reduce:

def any? (&block)
  reduce(q1) { |memo, e| memo or block.call(e) }
end

def all? (&block)
  reduce(q2) { |memo, e| memo and block.call(e) }
end

So both of these operations are map-reduce operations. The mapping is done with the block, converting array elements to true/false booleans. The reduction is 'or' for any? and 'and' for all?. Now the question for you is to figure out what we should put instead of q1 and q2. Hint: First make sure you get q1 and q2 right for arrays with actual elements. Then see what you get from the above definitions with empty arrays.

[In Mathematical terms, false is the neutral element of logical OR, and true is the neutral element of logical AND, the same way 0 is the neutral element of addition, and 1 is the neutral element of multiplication. Therefore, the sum of zero elements is 0, but the product of zero elements is 1.]

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57178

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74028] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2016-02-28  0:51 ` [ruby-core:74027] " duerst
@ 2016-02-28  1:32 ` sawadatsuyoshi
  2016-03-10  7:24 ` [ruby-core:74261] " andrew
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: sawadatsuyoshi @ 2016-02-28  1:32 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Tsuyoshi Sawada.


Martin Dürst wrote:
> Andrew Vit wrote:
> 
> > This is still surprising to me, it looks like a contradiction:
> > 
> > ```
> > [].any? #=> false
> > [].all? #=> true
> > ```
> > 
> > I would expect "all" to be a superset of "any": both should mean "at least one".
> > Is there a reason for the existing behavior, or is it just history now?
> 
> It's the way it works in Mathematics.

In natural language, universal quantification carries a presupposition that the domain is non empty; the meaning of "for all x in A, p(x)" is undefined when A is empty, just like "the king of the United States" is undefined. And whenever universal quantification is defined, the entailment holds: "for all x in A, p(x) → for some x in A, p(x)". That is probably what Andrew Vit was mentioning. And that is where natural language and formal systems differ, which makes the latter a bit counter-intuitive.

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57179

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74261] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2016-02-28  1:32 ` [ruby-core:74028] " sawadatsuyoshi
@ 2016-03-10  7:24 ` andrew
  2016-03-10  9:06 ` [ruby-core:74263] " duerst
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: andrew @ 2016-03-10  7:24 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Andrew Vit.


Thanks Martin and Tsuyoshi, 

Yes, all of this makes sense when you just look at it the right way. 
Otherwise this basic equality wouldn't work either:

```
[].all? { true } == [].none? { false }
```

I'm not sure a new core method is justified anyway. It's easy to add ourselves
or even create a special implementation of enumerable:

```
# naive hack (!)
module Enumerable
  def nonempty
    dup.extend NonemptyIterators
  end
  
  module NonemptyIterators
    def all?
      !empty? && super
    end
    # ...
  end
end

[].all? { true }  # == true
[].nonempty.all? { true } # == false
```

I'm not sure I would like it to assume the natural language interpretation for me.
It might be enough that ruby core just provides the logic primitives.

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57393

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74263] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2016-03-10  7:24 ` [ruby-core:74261] " andrew
@ 2016-03-10  9:06 ` duerst
  2016-03-10  9:41 ` [ruby-core:74264] " sawadatsuyoshi
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: duerst @ 2016-03-10  9:06 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Martin Dürst.


Tsuyoshi Sawada wrote:

> In natural language, universal quantification carries a presupposition that the domain is non empty; the meaning of "for all x in A, p(x)" is undefined when A is empty, just like "the king of the United States" is undefined. And whenever universal quantification is defined, the entailment holds: "for all x in A, p(x) → for some x in A, p(x)" (And the word "any" in a question is the same as "some" here). That is probably what Andrew Vit was mentioning. And that is where natural language and formal systems differ, which makes the latter a bit counter-intuitive.

I agree that in natural language, expressions that are similar to universal quantification usually assume that the underlying set is not empty. But this isn't so much because that's how natural language works. It is more because natural language is used in context, and it's usually clear from context already that the underlying set is not empty. If it's known that the underlying set is empty, then statements with universal quantifications are simply not made, because they are not needed. This is different from Mathematics and programming, where we as much as possible don't want to treat the empty set as special.

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57395

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74264] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2016-03-10  9:06 ` [ruby-core:74263] " duerst
@ 2016-03-10  9:41 ` sawadatsuyoshi
  2016-03-12  7:06 ` [ruby-core:74281] " nobu
  2016-03-12  8:01 ` [ruby-core:74282] " sawadatsuyoshi
  12 siblings, 0 replies; 13+ messages in thread
From: sawadatsuyoshi @ 2016-03-10  9:41 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Tsuyoshi Sawada.


Martin Dürst wrote:
> But this isn't so much because that's how natural language works.

That is how natural language works. Presupposition (failure) is an essential part of natural language semantics. It is a matter of semantics, not pragmatics. Presupposition and implicature are different.

> It is more because natural language is used in context

Natural language exists without context. Sentences can be judged to be syntactically correct and can be semantically interpreted irrespective of whether they make sense in context.

> If it's known that the underlying set is empty, then statements with universal quantifications are simply not made, because they are not needed.

Lack of spontaneous data is no obstacle for interpreting them semantically. You can construct a sentence in your mind and judge it by introspection.

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57396

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using #all? for example

[].all? { |e| false } # => true

Even though it's logically correct could we have a method that express the following?

foo.any? && foo.all?(&:bar)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74281] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2016-03-10  9:41 ` [ruby-core:74264] " sawadatsuyoshi
@ 2016-03-12  7:06 ` nobu
  2016-03-12  8:01 ` [ruby-core:74282] " sawadatsuyoshi
  12 siblings, 0 replies; 13+ messages in thread
From: nobu @ 2016-03-12  7:06 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Nobuyoshi Nakada.

Description updated

Anybody proposed an optional parameter for the default value to `#all?` and `#any?` ?



----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57404

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using `#all?` for example

```ruby
[].all? { |e| false } # => true
```

Even though it's logically correct could we have a method that express the following?

```ruby
foo.any? && foo.all?(&:bar)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [ruby-core:74282] [Ruby trunk Feature#12110] Create a method to avoid vacuous truth?
       [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2016-03-12  7:06 ` [ruby-core:74281] " nobu
@ 2016-03-12  8:01 ` sawadatsuyoshi
  12 siblings, 0 replies; 13+ messages in thread
From: sawadatsuyoshi @ 2016-03-12  8:01 UTC (permalink / raw
  To: ruby-core

Issue #12110 has been updated by Tsuyoshi Sawada.


Nobuyoshi Nakada wrote:
> Anybody proposed an optional parameter for the default value to `#all?` and `#any?` ?

I don't think Waldyr de Souza wants to alter the behaviour

~~~RUBY
[].any?{} # => false
~~~

so `any?` is not the issue.

----------------------------------------
Feature #12110: Create a method to avoid vacuous truth?
https://bugs.ruby-lang.org/issues/12110#change-57405

* Author: Waldyr de Souza
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
I often find myself running into unexpected results when using `#all?` for example

```ruby
[].all? { |e| false } # => true
```

Even though it's logically correct could we have a method that express the following?

```ruby
foo.any? && foo.all?(&:bar)
```



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-03-12  7:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-12110.20160225163013@ruby-lang.org>
2016-02-25 16:30 ` [ruby-core:73986] [Ruby trunk Feature#12110] Can create a method to avoid vacuous truth? waldyr.ar
2016-02-25 16:31 ` [ruby-core:73987] " waldyr.ar
2016-02-25 18:47 ` [ruby-core:73989] [Ruby trunk Feature#12110] Create " waldyr.ar
2016-02-25 21:29 ` [ruby-core:73991] " shevegen
2016-02-25 22:39 ` [ruby-core:73993] " matthew
2016-02-27 13:59 ` [ruby-core:74023] " andrew
2016-02-28  0:51 ` [ruby-core:74027] " duerst
2016-02-28  1:32 ` [ruby-core:74028] " sawadatsuyoshi
2016-03-10  7:24 ` [ruby-core:74261] " andrew
2016-03-10  9:06 ` [ruby-core:74263] " duerst
2016-03-10  9:41 ` [ruby-core:74264] " sawadatsuyoshi
2016-03-12  7:06 ` [ruby-core:74281] " nobu
2016-03-12  8:01 ` [ruby-core:74282] " sawadatsuyoshi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).