Opened 5 years ago
Closed 18 months ago
#24171 closed enhancement (fixed)
Formal set membership function
Reported by:  Ralf Stephan  Owned by:  

Priority:  major  Milestone:  sage9.4 
Component:  symbolics  Keywords:  
Cc:  Vincent Delecroix  Merged in:  
Authors:  Ralf Stephan, Matthias Koeppe  Reviewers:  Travis Scrimshaw, Matthias Koeppe 
Report Upstream:  N/A  Work issues:  
Branch:  a8c94ca (Commits, GitHub, GitLab)  Commit:  a8c94cab974c8983dad63c2c6e989936984de49a 
Dependencies:  #31877  Stopgaps: 
Description (last modified by )
To express solution sets from solvers an expressioniselementofset relation is needed. For ease of implementation this can be made a formal function element_of
.
It depends on sets being made coercible into SR. The present ticket plays safe and only does this for finite sets and a few standard infinite sets: NN
, ZZ
, QQ
, AA
; and RealSet
s.
element_of
converts to SymPy's Contains
. This is useful in combination with #31931, which adds SymPy conversions to some of the above sets.
Change History (50)
comment:1 Changed 5 years ago by
Description:  modified (diff) 

comment:2 Changed 5 years ago by
Branch:  → u/rws/formal_set_membership_function 

comment:3 Changed 5 years ago by
Authors:  → Ralf Stephan 

Commit:  → 669ea22318ab33f23f727626eb30e59fa138d253 
Status:  new → needs_review 
comment:4 Changed 5 years ago by
I can reproduce this error
********************************************************************** File "src/sage/misc/dev_tools.py", line 438, in sage.misc.dev_tools.import_statements Failed example: load_submodules(sage.sets) Expected: load sage.sets.real_set... succeeded load sage.sets.set_from_iterator... succeeded Got: load sage.sets.set_from_iterator... succeeded
I think why this now fails is because real_set
is now loaded on startup.
comment:5 Changed 5 years ago by
Status:  needs_review → needs_work 

I think it would be good if RealSet
answered positive to is_Set
, I'm just not sure how to accomplish it correctly. If done it wouldn't need to be loaded at start.
comment:6 Changed 5 years ago by
Commit:  669ea22318ab33f23f727626eb30e59fa138d253 → af82717b1bfeffbe6fc972686882916b0525b149 

comment:7 Changed 5 years ago by
Status:  needs_work → needs_review 

comment:8 Changed 5 years ago by
Commit:  af82717b1bfeffbe6fc972686882916b0525b149 → 592ce8745028ec0659b952e872dfff0a85ef5a5d 

Branch pushed to git repo; I updated commit sha1. New commits:
592ce87  24171: Py3 fixes

comment:9 Changed 5 years ago by
Reviewers:  → Travis Scrimshaw 

Status:  needs_review → positive_review 
LGTM. Thanks.
comment:12 Changed 5 years ago by
Commit:  592ce8745028ec0659b952e872dfff0a85ef5a5d → aa11a3ee31cb75f5acf2e5cef1db52fd2092893b 

Branch pushed to git repo; I updated commit sha1. New commits:
aa11a3e  Merge branch 'develop' into t/24171/formal_set_membership_function

comment:13 Changed 5 years ago by
Status:  needs_work → positive_review 

comment:15 Changed 5 years ago by
comment:16 Changed 5 years ago by
Branch:  u/rws/formal_set_membership_function → u/rws/24171 

comment:17 Changed 5 years ago by
Commit:  aa11a3ee31cb75f5acf2e5cef1db52fd2092893b → ac6af264cb8beed2c7196691003ff93552a9f5b9 

OK, I added junk to the branch, so what Volker means are the patchbot plugin fails. Also, the rare random fails are now happening frequently so patchbot pass depend on the blockers.
New commits:
ac6af26  24171: Formal set memberhzip function

comment:18 Changed 5 years ago by
Dependencies:  → #24284 #24378 

comment:19 Changed 5 years ago by
Actually the reason why #24171 fails the random expression tests is because the here introduced function is yet another function that fails that test.
comment:20 Changed 5 years ago by
Commit:  ac6af264cb8beed2c7196691003ff93552a9f5b9 → 365ea784a37f3a99202ce2f801ce901d29d36cca 

Branch pushed to git repo; I updated commit sha1. New commits:
6559c5e  24282: Exclude some functions with arg restrictions from random testing

5db62d3  Merge branch 'u/rws/exclude_some_functions_with_arg_restrictions_from_random_testing' of git://trac.sagemath.org/sage into tmp17

365ea78  24171: exclude element_of from random testing too

comment:21 Changed 5 years ago by
Dependencies:  #24284 #24378 → #24284 #24378 #24443 

comment:22 Changed 5 years ago by
Cc:  Vincent Delecroix added 

Status:  needs_work → needs_info 
The following problem appeared: to be able to use a symbolic element_of
function its arguments (1. expression, 2. set/domain) must be convertible to the symbolic ring. One doctest in symbolic/ring.pyx
tests that r
(the R interpreter) does not convert to symbolic. But r
is in Sets()
and so we cannot simply test for x in Sets()
and allow conversion of x
because r
would then be allowed.
So we must test for all kinds of sets, e.g. ZZ in InfiniteEnumeratedSets()
, RR in Fields()
, RealSet(0,1) in SetsWithPartialMaps()
, and Set(range(0,5)) in FiniteSets()
, because we need to catch all of these but cannot use the catchall in Sets()
. Is the R interpreter really in the sets category? Is there a better catchall?
comment:23 followup: 24 Changed 5 years ago by
BTW RealSet(oo,oo) in Fields()
is False which looks like a bug, right?
comment:24 followup: 25 Changed 5 years ago by
Replying to rws:
BTW
RealSet(oo,oo) in Fields()
is False which looks like a bug, right?
Not to me. RealSet(oo,oo)
or RealSet(0,1)
act as a facade (like in Sets().Facade()
). That is to say, it does not have any proper elements. Making it a field would be rather artificial because the operation +
and *
that might (or might not) exist on the elements is obtained from other parts of Sage.
comment:25 followup: 26 Changed 5 years ago by
Replying to vdelecroix:
...
RealSet(oo,oo)
orRealSet(0,1)
act as a facade ...
Is there an object that can act as the set of real numbers in Sage?
comment:26 followup: 27 Changed 5 years ago by
Replying to rws:
Replying to vdelecroix:
...
RealSet(oo,oo)
orRealSet(0,1)
act as a facade ...Is there an object that can act as the set of real numbers in Sage?
Very sadly, no!
My dream is:
 rename
RealField(prec)
>RealFloatingPointField_mpfr(prec)
 rename
RealLazyField
>RealComputableField
andRLF > RCF
 create a class
RealField()
to model (abstractly) the set of real numbers  rename
RR
>RFPF
The reason for 2./3. is that we want to distinguish between the field of all real numbers (denoted RR
in math literature) and the field of computable numbers (which is a countable subfield). An element of RCF
would simply be a computer program that gives access to the digit expansion of a number. It should provide access to all mathematical constants like pi
, e
, etc and most transcendental functions. A serious problem about RCF
is that the equality is not decidable... but we can not avoid it.
The set of real numbers (my number 3. in the list) would not implement anything serious. It would only act as an abstract set that can be obtained as the metric completion of QQ
. It could be used as a building block for more advanced structures (like manfiolds).
I put 4. apart as it is a serious backward incompatibility.reasons.
comment:27 Changed 5 years ago by
Dependencies:  #24284 #24378 #24443 → #24284 #24378 #24456 

Status:  needs_info → needs_work 
comment:28 Changed 5 years ago by
Branch:  u/rws/24171 → u/rws/241711 

comment:29 Changed 5 years ago by
Commit:  365ea784a37f3a99202ce2f801ce901d29d36cca → 628f9220672280b526134311efdab819aa3f05c5 

Status:  needs_work → needs_review 
comment:30 Changed 5 years ago by
Note that we have no proper check for if something is a subset of the complexes. I ended up allowing conversion of all finite sets and (NN, ZZ, QQ, RealField, RealSet, AA)
to symbolic.
comment:31 Changed 5 years ago by
Status:  needs_review → needs_work 

comment:32 Changed 18 months ago by
Branch:  u/rws/241711 → u/mkoeppe/241711 

comment:33 Changed 18 months ago by
Commit:  628f9220672280b526134311efdab819aa3f05c5 → 72565f2720115475272c030db26b1144b87377bb 

Dependencies:  #24284 #24378 #24456 
Milestone:  sage8.2 → sage9.4 
comment:34 Changed 18 months ago by
The is_finite
method added here will not be necessary any more with #31877
comment:35 Changed 18 months ago by
Commit:  72565f2720115475272c030db26b1144b87377bb → 5e623bb508d45a0ac79538c93bc115562b6269e0 

Branch pushed to git repo; I updated commit sha1. New commits:
4b09685  RealSet: Put it in a suitable subcategory of TopologicalSpaces()

46eed0e  RealSet.ambient: Change to a normal method

51c8152  Merge branch 't/31877/refine_category_of_realset' into t/24171/setmembershiprebased

5e623bb  RealSet.is_finite: Remove, inherited from category

comment:36 Changed 18 months ago by
Dependencies:  → #31877 

comment:37 Changed 18 months ago by
Commit:  5e623bb508d45a0ac79538c93bc115562b6269e0 → 7d19916c0fbf2bf76054401df372fbedde7cdbb6 

Branch pushed to git repo; I updated commit sha1. New commits:
7d19916  Do not use QQ.completion(oo,oo)  not implemented

comment:38 Changed 18 months ago by
Commit:  7d19916c0fbf2bf76054401df372fbedde7cdbb6 → 5310e04bae60c574eafe491ebcea366e57513822 

comment:39 Changed 18 months ago by
Status:  needs_work → needs_review 

This branch works now as advertised, but a careful review of this design is needed
comment:40 Changed 18 months ago by
We could add more support for other infinite sets later on (e.g., number fields), but this would be good for most (perhaps all?) usecases. I think everything else is good except I don't understand why this line is added (see the diff):
oo = infinity
comment:42 Changed 18 months ago by
Commit:  5310e04bae60c574eafe491ebcea366e57513822 → 43cabe82529c55b1ab3add68304f3b2b73971cba 

Branch pushed to git repo; I updated commit sha1. New commits:
43cabe8  Do not use QQ.completion(oo,oo)  not implemented (fixup)

comment:43 Changed 18 months ago by
Thank you. Green bot => positive review. Please add yourself whether you think you are an author and/or reviewer.
comment:44 Changed 18 months ago by
Commit:  43cabe82529c55b1ab3add68304f3b2b73971cba → c793fcc4f9def7070c36785603958c48cf2710b0 

Branch pushed to git repo; I updated commit sha1. New commits:
c793fcc  Function_elementof: Remove use of is_Set (fixup)

comment:45 Changed 18 months ago by
Reviewers:  Travis Scrimshaw → Travis Scrimshaw, Matthias Koeppe 

comment:46 Changed 18 months ago by
Commit:  c793fcc4f9def7070c36785603958c48cf2710b0 → a8c94cab974c8983dad63c2c6e989936984de49a 

Branch pushed to git repo; I updated commit sha1. New commits:
a8c94ca  Function_elementof: Add conversion to sympy

comment:47 Changed 18 months ago by
Authors:  Ralf Stephan → Ralf Stephan, Matthias Koeppe 

Description:  modified (diff) 
comment:48 Changed 18 months ago by
Status:  needs_review → positive_review 

comment:50 Changed 18 months ago by
Branch:  u/mkoeppe/241711 → a8c94cab974c8983dad63c2c6e989936984de49a 

Resolution:  → fixed 
Status:  positive_review → closed 
New commits:
24171: Formal set membership function