Skip to content

Commit

Permalink
sage.sets: More block tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Oct 1, 2023
1 parent eac6dc3 commit a330894
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 47 deletions.
53 changes: 29 additions & 24 deletions src/sage/sets/condition_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ def _repr_condition(self, predicate):
sage: Evens = ConditionSet(ZZ, is_even)
sage: Evens._repr_condition(is_even)
'<function is_even at 0x...>(x)'
sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x]) # needs sage.symbolic
sage: BigSin._repr_condition(BigSin._predicates[0]) # needs sage.symbolic
sage: # needs sage.symbolic
sage: BigSin = ConditionSet(RR, sin(x) > 0.9, vars=[x])
sage: BigSin._repr_condition(BigSin._predicates[0])
'sin(x) > 0.900000000000000'
sage: var('t') # parameter # needs sage.symbolic
sage: var('t') # parameter
t
sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q")) # needs sage.symbolic
sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) # needs sage.symbolic
sage: ZeroDimButNotNullary = ConditionSet(ZZ^0, t > 0, vars=("q"))
sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0])
't > 0'
"""
if isinstance(predicate, Expression) and predicate.is_callable():
Expand Down Expand Up @@ -342,24 +344,26 @@ def _call_predicate(self, predicate, element):
TESTS::
sage: TripleDigits = ZZ^3 # needs sage.modules
sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # needs sage.symbolic
sage: # needs sage.modules sage.symbolic
sage: TripleDigits = ZZ^3
sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate
(x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12
sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # needs sage.symbolic
sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples
{ (x, y, z) ∈ Ambient free module of rank 3 over the principal
ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 }
sage: predicate = SmallTriples._predicates[0] # needs sage.symbolic
sage: element = TripleDigits((1, 2, 3)) # needs sage.modules
sage: SmallTriples._call_predicate(predicate, element) # needs sage.modules sage.symbolic
sage: predicate = SmallTriples._predicates[0]
sage: element = TripleDigits((1, 2, 3))
sage: SmallTriples._call_predicate(predicate, element)
sqrt(14) < 12
sage: var('t') # needs sage.symbolic
sage: # needs sage.modules sage.symbolic
sage: var('t')
t
sage: TinyUniverse = ZZ^0 # needs sage.modules
sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=()) # needs sage.modules sage.symbolic
sage: predicate = Nullary._predicates[0] # needs sage.modules sage.symbolic
sage: element = TinyUniverse(0) # needs sage.modules
sage: Nullary._call_predicate(predicate, element) # needs sage.modules sage.symbolic
sage: TinyUniverse = ZZ^0
sage: Nullary = ConditionSet(TinyUniverse, t > 0, vars=())
sage: predicate = Nullary._predicates[0]
sage: element = TinyUniverse(0)
sage: Nullary._call_predicate(predicate, element)
t > 0
"""
if isinstance(predicate, Expression) and predicate.is_callable():
Expand All @@ -375,13 +379,14 @@ def _an_element_(self):
TESTS::
sage: TripleDigits = ZZ^3 # needs sage.modules
sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate # needs sage.symbolic
sage: # needs sage.modules sage.symbolic
sage: TripleDigits = ZZ^3
sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate
(x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12
sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples # needs sage.symbolic
sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples
{ (x, y, z) ∈ Ambient free module of rank 3 over the principal
ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 }
sage: SmallTriples.an_element() # indirect doctest # needs sage.symbolic
sage: SmallTriples.an_element() # indirect doctest
(1, 0, 0)
"""
for element in self._universe.some_elements():
Expand Down Expand Up @@ -409,7 +414,7 @@ def _sympy_(self):
EXAMPLES::
sage: # needs sage.symbolic
sage: # needs sage.modules sage.symbolic
sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate
(x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12
sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples
Expand Down Expand Up @@ -468,7 +473,7 @@ def intersection(self, X):
EXAMPLES::
sage: # needs sage.symbolic
sage: # needs sage.modules sage.symbolic
sage: in_small_oblong(x, y) = x^2 + 3 * y^2 <= 42
sage: SmallOblongUniverse = ConditionSet(QQ^2, in_small_oblong)
sage: SmallOblongUniverse
Expand All @@ -487,7 +492,7 @@ def intersection(self, X):
Combining two ``ConditionSet``s with different formal variables works correctly.
The formal variables of the intersection are taken from ``self``::
sage: # needs sage.symbolic
sage: # needs sage.modules sage.symbolic
sage: SmallMirrorUniverse = ConditionSet(QQ^2, in_small_oblong,
....: vars=(y, x))
sage: SmallMirrorUniverse
Expand Down
27 changes: 15 additions & 12 deletions src/sage/sets/image_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ def __init__(self, map, domain_subset, *, category=None, is_injective=None, inve
EXAMPLES::
sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3]) # needs sage.modules
sage: # needs sage.modules
sage: M = CombinatorialFreeModule(ZZ, [0,1,2,3])
sage: R.<x,y> = QQ[]
sage: H = Hom(M, R, category=Sets()) # needs sage.modules
sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2) # needs sage.modules
sage: Im = f.image() # needs sage.modules
sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling', # needs sage.modules
sage: H = Hom(M, R, category=Sets())
sage: f = H(lambda v: v[0]*x + v[1]*(x^2-y) + v[2]^2*(y+2) + v[3] - v[0]^2)
sage: Im = f.image()
sage: TestSuite(Im).run(skip=['_test_an_element', '_test_pickling',
....: '_test_some_elements', '_test_elements'])
"""
if not is_Parent(domain_subset):
Expand Down Expand Up @@ -198,14 +199,15 @@ def lift(self, x):
EXAMPLES::
sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3]) # needs sage.modules
sage: # needs sage.modules
sage: M = CombinatorialFreeModule(QQ, [0, 1, 2, 3])
sage: R.<x,y> = ZZ[]
sage: H = Hom(M, R, category=Sets()) # needs sage.modules
sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2)) # needs sage.modules
sage: Im = f.image() # needs sage.modules
sage: p = Im.lift(Im.an_element()); p # needs sage.modules
sage: H = Hom(M, R, category=Sets())
sage: f = H(lambda v: floor(v[0])*x + ceil(v[3] - v[0]^2))
sage: Im = f.image()
sage: p = Im.lift(Im.an_element()); p
2*x - 4
sage: p.parent() is R # needs sage.modules
sage: p.parent() is R
True
"""
return x
Expand Down Expand Up @@ -278,7 +280,8 @@ def cardinality(self) -> Integer:
sage: Mod2.cardinality()
Traceback (most recent call last):
...
NotImplementedError: cannot determine cardinality of a non-injective image of an infinite set
NotImplementedError: cannot determine cardinality of a
non-injective image of an infinite set
"""
domain_cardinality = self._domain_subset.cardinality()
if self._is_injective and self._is_injective != 'check':
Expand Down
22 changes: 11 additions & 11 deletions src/sage/sets/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,19 +1381,18 @@ def __init__(self, X, Y, category=None):
EXAMPLES::
sage: S = Set(QQ^2) # needs sage.modules
sage: # needs sage.modules
sage: S = Set(QQ^2)
sage: T = Set(ZZ)
sage: X = S.union(T); X # needs sage.modules
sage: X = S.union(T); X
Set-theoretic union of
Set of elements of Vector space of dimension 2 over Rational Field and
Set of elements of Integer Ring
sage: X.category() # needs sage.modules
sage: X.category()
Category of infinite sets
sage: latex(X) # needs sage.modules
sage: latex(X)
\Bold{Q}^{2} \cup \Bold{Z}
sage: TestSuite(X).run() # needs sage.modules
sage: TestSuite(X).run()
"""
if category is None:
category = Sets()
Expand Down Expand Up @@ -1538,15 +1537,16 @@ def __init__(self, X, Y, category=None):
EXAMPLES::
sage: S = Set(QQ^2) # needs sage.modules
sage: # needs sage.modules
sage: S = Set(QQ^2)
sage: T = Set(ZZ)
sage: X = S.intersection(T); X # needs sage.modules
sage: X = S.intersection(T); X
Set-theoretic intersection of
Set of elements of Vector space of dimension 2 over Rational Field and
Set of elements of Integer Ring
sage: X.category() # needs sage.modules
sage: X.category()
Category of enumerated sets
sage: latex(X) # needs sage.modules
sage: latex(X)
\Bold{Q}^{2} \cap \Bold{Z}
sage: X = Set(IntegerRange(100)).intersection(Primes())
Expand Down

0 comments on commit a330894

Please sign in to comment.