Re: [eigen] operator== (and probably others) for 0-sized Eigen-types

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On 11.11.2013 23:59, Gael Guennebaud wrote:
Hi,

I cannot reproduce the compilation issue with both gcc and clang. Here is
what I tested:

#include <Eigen/Core>
#include <iostream>
int main() {
   Eigen::Matrix<double, 1, 0> A, B;
   std::cout << (A == B) << "\n";
};

However, it currently returns false, while returning true seems to be more
appropriate. Actually the problem might be more general because it raises
the question of what should be the result of .all() and .any() on an empty
matrix of bool? Currently both returns false, that is why operator==
returns false too since A==B on Matrices is implemented as:

(A.array()==B.array()).all()

One option could be to make .all() and .any() returns the identity element
of the operators && and || respectively, i.e., true and false. This choice
would even be compatible with the following identities:

Yes, that is also exactly what a mathematician would expect for empty sets.

(A.array()==B.array()).all()  <=> (A==B)

(A.array()!=B.array()).any()  <=> (A!=B)

Yes, again that is basic quantification logic:
( \neg(\forall x: P(x)) ) = (\exist x: \neg P(x)), or in Eigen syntax:
(!(A.all())) == ((!A).any()); assuming A is a boolean array.

However it would break a more fundamental identity that is:

expression.all() => expression.any()

That's called existential fallacy. To make that implication valid something must exist (i.e. the expression must not be empty-sized).

"All flying elephants are pink" is true, but "There exists a pink, flying elephant" is not.

Moreover, it seems to me that an 'ideal' result of all() and any() on
zero-sized objects depend on the context, e.g:

(A.array()==B.array()).all() == (A.array()==B.array()).any() == true

(A.array()!=B.array()).all() == (A.array()!=B.array()).any() == false

That would not make sense for zero sized objects, since (![]) == [] (if [] is an empty boolean array).


Christoph



--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252
----------------------------------------------



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/