-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lebesgue's measure for discrete sets #27469
base: master
Are you sure you want to change the base?
Conversation
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like: This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.14. Click here to see the pull request description that was parsed.
|
Corrections after review
@@ -2318,6 +2330,10 @@ def is_iterable(self): | |||
iter_flag = iter_flag and set_i.is_iterable | |||
return iter_flag | |||
|
|||
@property | |||
def _measure(self): | |||
return sum(s._measure for s in self.sets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about DisjointUnion and what measure means in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a mistake indeed. There are three cases:
- if all sets are discrete, their disjoint union is equivalent to another discrete set. So the measure should be zero.
- if all sets are intervals, their disjoint union is equivalent to a Cartesian product. So the measure should be the product of the inner measure.
- if sets are mixed, I agree the measure of such a disjoint union is not trivial and would be wiser to not handle it.
Would you agree to something like this?
def _measure(self):
if all(isinstance(s, Interval | ComplexRegion) for s in self.sets):
# No doubt that in this case, it is well defined
return # product of each of inner measures
# We do not handle any other case, even when all other sets are discrete
raise NotImplementedError("...")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is just best not to implement things like measure when they are not clearly well defined.
The whole concept is inherently ambiguous here e.g. what is the measure of the interval [1, 2]
? The answer would be different if it is measured as a subset of C or R.
I'm not sure that we can really make measure meaningful if going anywhere beyond measuring subsets of R or sets that are clearly subsets of R^N
(i.e. sets of tuples).
References to other Issues or PRs
Discussed in #27465
Brief description of what is fixed or changed
Many discrete sets were missing the implementation of Lebesgue's measure, such as
Naturals
,Range
orRationals
. Such sets have a measure of zero.For sets such as
Intersection
orComplement
that have not been evaluated, and non-obvious sets such asImageSet
,ConditionSet
or evenPowerSet
:measure
is not determined and raises aNotImplementedError
.Other comments
On paper, this was a simple issue to fix. But it has raised some questions that I do not have the answer to yet:
NotImplementedError
or to return anan
?Interval
should be equal to. For now it is not implemented.FiniteSet
can contain singular elements as much as intervals. In this case, to my understanding, the measure of such a set should not be equal to zero. Yet it has been hardcoded that aFiniteSet
has a measure of zero. I feel like this should be addressed in a issue, am I right?Release Notes