Ask Your Question
1

Integer vs ZZ

asked 2013-04-02 10:46:47 +0100

matthew.weippert gravatar image

What's the difference between sage class ZZ (rings/integer_ring.pyx) and Integer (rings/integer.pyx)?

Is one preferred over the other in some cases? Do they provide different functionality?

Maybe instances of Integer are elements of ZZ?!

Example:

a = ZZ(10)
b = Integer(3)
c = a + b
print a, b, c
print "Type of elements:", type(a), "vs", type(b), "vs", type(c)
print "Type of classes: ", ZZ, "vs", Integer
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-04-02 12:42:38 +0100

fidbc gravatar image

updated 2013-04-02 12:44:13 +0100

Yes, Integer is the type of elements in ZZ. ZZ refers to the ring of integers, whereas Integer refers to the type of an element of the ring ZZ. When you execute, say ZZ(int(10)), int(10) is coerced to an Integer. In your example above you can verify this.

sage: print "Type of elements:", type(a), "vs", type(b), "vs", type(c)
Type of elements: <type 'sage.rings.integer.Integer'> vs <type 'sage.rings.integer.Integer'> vs <type 'sage.rings.integer.Integer'>

The elements a, b, and c are of the same type.

edit flag offensive delete link more
1

answered 2013-04-03 08:25:22 +0100

Volker Braun gravatar image

Sage uses the parent/element pattern for most mathematical objects, see the documentation on coercion for details. For integers the parent is IntegerRing (with ZZ as shortcut) and the element are Integer.

sage: i = 1
sage: type(i)
sage.rings.integer.Integer
sage: type(i.parent())
sage.rings.integer_ring.IntegerRing_class
sage: ZZ is IntegerRing() is i.parent()
True
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-02 10:46:47 +0100

Seen: 2,269 times

Last updated: Apr 03 '13