jankapunkt/js-set-extension

Suggested properties

MareoRaft opened this issue · 5 comments

Looking through http://doc.sagemath.org/html/en/reference/sets/sage/sets/set.html, I think we might consider a few additional properties/methods, and maybe a few changes:

  • anElement --> might choose this name over any (my only worry about "any" is that I expect it to be a function that takes in a boolean function and returns true if the boolean function evaluates to true on any of the elements in the set)

  • isEmpty --> tells you if it's an empty set or not (has a size of 0)

  • cardinality --> doesn't really make sense to have this unless we supported infinite sets. (returns the size or "Infinity")

  • isFinite --> doesn't really make sense to have this unless we support infinite sets. (returns true or false)

  • subsets --> we might choose this name over powerSet, if you are leaning towards following Sagemath naming conventions as much as possible

  • randomElement --> returns an element of the set at random. (uses Math.random internally)

I think we could move forward with isEmpty now. We can move forward with randomElement if you agree with the name choice. Change of name for anElement and subsets is really up to your opinion and what convention we agree on for the naming scheme. The final two cardinality and isFinite arguably shouldn't exist since we don't support infinite sets right now.

Once we are in agreement for any one of these, we can open up a separate issue for it.

anElement --> might choose this name over any (my only worry about "any" is that I expect it to be a function that takes in a boolean function and returns true if the boolean function evaluates to true on any of the elements in the set)

Can you please elaborate on this a bit more? In my understanding from the Sagemath documentation this will return the first element of a Set?

isEmpty --> tells you if it's an empty set or not (has a size of 0)

Yes this is good.

() => this.size === 0

cardinality --> doesn't really make sense to have this unless we supported infinite sets. (returns the size or "Infinity")

Agree.

isFinite --> doesn't really make sense to have this unless we support infinite sets. (returns true or false)

Agree.

subsets --> we might choose this name over powerSet, if you are leaning towards following Sagemath naming conventions as much as possible

What is your opinion on this one? I chose powerSet because of the Wikipedia articles which I found because in the German Literature they use the word "Potenzmenge" which translates to Power set.

I would like to support what is commonly used on an international level (which is why I thought the Sagemath to be a good reference), so do you think we will be good with "subsets"?

randomElement --> returns an element of the set at random. (uses Math.random internally)

Yes, I think this is also a good helper.

() => Math.floor(Math.random() *  this.size)

I think we could move forward with isEmpty now. We can move forward with randomElement if you agree with the name choice.

Yes, the names are fine and the implementation should be neither breaking nor introduce unnecessary complexity.

Can you please elaborate on this (anElement) a bit more? In my understanding from the Sagemath documentation this will return the first element of a Set?

Theoretically, sets have no order, so there is no "first" element. In practical implementation, however, Sagemath has some internal ordering of the set. It doesn't matter however, since no specific ordering should be guaranteed. The only purpose of this function is to return an element. It should not matter which one. It is meant to do the same thing that your any function does. I think this function could even be an alias for randomElement, and that would be fine too.

What is your opinion on this one? I chose powerSet because of the Wikipedia articles which I found because in the German Literature they use the word "Potenzmenge" which translates to Power set.

I would like to support what is commonly used on an international level (which is why I thought the Sagemath to be a good reference), so do you think we will be good with "subsets"?

I personally prefer powerSet because this is the term that everyone has used at the universities I attended. All the mathematicians I have encountered say "power set". While Sagemath is a great project, it is unfortunately not perfect. It was written by a very large number of people, all with their own opinions.

For the sake of wrapping up v2 and this ticket, do you have a final opinion on any/anElement and subsets/powerSet?

I would say we keep it powerSet and add to the documentation that is also referred to as subsets. I also think that powerSet is more distinctive to subset than subsets and thus easier to recognize.

Regarding anElement I have another suggestion: firstElement which may defy the concept of a Set having no order but we can overcome this principle implicitly by referring to the first element of the iterator, which is a sole programmatic concept and not related to the underlying mathematical structure of Sets.

In sagemath it is even described as such:

Return the first element of self returned by iter()

So I think we would be good with firstElement here. WDYT?

I would say we keep it powerSet and add to the documentation that is also referred to as subsets. I also think that powerSet is more distinctive to subset than subsets and thus easier to recognize.

That sounds good. I agree. I will open a PR to change the name from power to powerSet. I will also add a note about "subsets" in the docs.

So I think we would be good with firstElement here. WDYT?

I think it is a creative idea, but I'm afraid it will cause confusion. Moreover, you would need to apply a sorting function to guarantee it always returns the same element. But I'm not sure who would even use this function. I think the only usefulness of any/anElement in Sage is when somebody is using an interactive terminal or troubleshooting and just wants to quickly see an element in the set to check that it looks right.