Content-Length: 336332 | pFad | http://github.com/sympy/sympy/pull/27469

88 Lebesgue's measure for discrete sets by grdleo · Pull Request #27469 · sympy/sympy · GitHub
Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

grdleo
Copy link

@grdleo grdleo commented Jan 10, 2025

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 or Rationals. Such sets have a measure of zero.
For sets such as Intersection or Complement that have not been evaluated, and non-obvious sets such as ImageSet, ConditionSet or even PowerSet : measure is not determined and raises a NotImplementedError.

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:

  • When the measure cannot be trivially computed, is it better to raise a NotImplementedError or to return a nan?
  • I am not 100% sure of what a Lebesgue's measure of a power set of an Interval should be equal to. For now it is not implemented.
  • During my implementation, I have figured out that a 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 a FiniteSet has a measure of zero. I feel like this should be addressed in a issue, am I right?

Release Notes

  • sets
    • Fixed missing implementation of Lebesgue's measure for some discrete sets.

@sympy-bot
Copy link

sympy-bot commented Jan 10, 2025

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:

  • sets
    • Fixed missing implementation of Lebesgue's measure for some discrete sets. (#27469 by @grdleo)

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.
#### 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` or `Rationals`. Such sets have a measure of zero.
For sets such as `Intersection` or `Complement` that have not been evaluated, and non-obvious sets such as `ImageSet`, `ConditionSet` or even `PowerSet` : `measure` is not determined and raises a `NotImplementedError`.

#### 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:
- When the measure cannot be trivially computed, is it better to raise a `NotImplementedError` or to return a `nan`?
- I am not 100% sure of what a Lebesgue's measure of a power set of an `Interval` should be equal to. For now it is not implemented.
- During my implementation, I have figured out that a `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 a `FiniteSet` has a measure of zero. I feel like this should be addressed in a issue, am I right?

#### Release Notes

<!-- BEGIN RELEASE NOTES -->
* sets
  * Fixed missing implementation of Lebesgue's measure for some discrete sets.
<!-- END RELEASE NOTES -->

sympy/sets/sets.py Outdated Show resolved Hide resolved
@grdleo grdleo requested a review from oscarbenjamin January 16, 2025 09:37
@@ -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)
Copy link
Collaborator

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.

Copy link
Author

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("...")

Copy link
Collaborator

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sympy/sympy/pull/27469

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy