from sage.rings.ring import CommutativeRing
class ScalarFieldRing(CommutativeRing):
def __init__(self, domain):
CommutativeRing.__init__(self, base_ring)
self.domain = domain
from sage.rings.ring import Ring
from sage.categories.commutative_rings import CommutativeRings
class ScalarFieldRing(Ring):
def __init__(self, domain):
Ring.__init__(self, None, category=CommutativeRings())
self.domain = domain
from sage.structure.parent import Parent
from sage.categories.commutative_rings import CommutativeRings
class ScalarFieldRing(Parent):
def __init__(self, domain):
Parent.__init__(self, category=CommutativeRings())
self.domain = domain
On Wed, Mar 12, 2014 at 06:41:07AM -0700, Eric Gourgoulhon wrote:
> In order to treat tensor fields on a parallelizable domain N of some
> smooth manifold as elements of a free module (cf. #15916 and this post),
> one has first to introduce the commutative ring C^oo(N) of smooth
> functions N --> R, as a new class, ScalarFieldRing say. Browsing through
> Sage reference manual, a natural guess would be to make it a subclass of
> CommutativeRing:
You don't necessarily need too. You could also just inherit from
Parent; the important thing is to set the category to
CommutativeRings().
CommutativeRing is a bit of a legacy stuff: it's still there because
some features have not yet been moved to categories, and also because
some parents where pure arithmetic speed on elements is vital
(e.g. small finite fields), need it to by Cython.
The issue here is that CommutativeRing.__init__ requires the argument "base_ring" and in the present context, I don't know what to put here: the ring C^oo(N) does not depend upon any other ring. Shall I put self, i.e. write CommutativeRing.__init__(self, self) ?
- create RSF (for "real symbolic field") to isolate pi and sqrt(2) from
cos(x) in the symbolic ring.
- re-create RR as an "overlay field" over the different representations
This is not about floating-point arithmetic nor evaluation, but about a
common parent with some semantics in it.
I would advocate that RLF is a very good approximation of what should
be RR. Perhaps one good direction to take is to try to make RLF
smarter and contains all constants from pi to cos(42^e).
This is half good, I am happy that RLF wraps symbolic constants. But,
first of all there can not be any reasonable coercion from SR to RLF
as SR is much bigger. Secondly, SR is not consistent with evaluation
sage: cos(1.).parent()
Real Field with 53 bits of precision
sage: cos(1).parent()
Symbolic Ring
I would prefer the second parent to be something like
RealSymbolicField or RealNumbers or whatever but not symbolic ring.
Thirdly, I would like to be able to compare real numbers built from
different sources :
- algebraic numbers (built from QQbar and NumberField)
- symbolic constants
- continued fractions
- binary expansions
- ...
But currently:
sage: R.<X> = QQ[]
sage: K.<a> = NumberField(X^4 - 5*X^2 + 5, embedding=1.17)
sage: RLF(a)
1.75570504584947?
sage: expr = 2 * cos(3*pi/10)
sage: RLF(expr)
1.17557050458946?
sage: RLF(a) == RLF(expr) # does not work in RLF
False
sage: bool(SR(a) == SR(expr)) # does not work in SR
False
Even if they are equal as real numbers. So what is broken : comparison
in SR? comparison in RLF?
Any number cos(rational x pi) is algebraic and equality of algebraic
numbers is decidable. Moreover, it is not because something is
undecidable that Sage should return a wrong answer. In that case, it
would be good to have a third party in comparison (either returning
Unknown or raising exception).