-1

Somebody can explain me what does this function do?

class fastfrac:

  def __init__(self,top,bot=1):

    if parent(top) == ZZ or parent(top) == R:
      self.top = R(top)
      self.bot = R(bot)
    elif top.__class__ == fastfrac:
      self.top = top.top
      self.bot = top.bot * bot
    else:
      self.top = R(numerator(top))
      self.bot = R(denominator(top)) * bot

For example, parent() function I don't know what does it do. I search information but I didn't find nothing.

Thank you so much

1 Answers1

2

In Sage, every mathematical object has a parent structure.

For example, an integer's parent would be the ring of integers, a matrix's parents would be a matrix space, a polynomial's parent would be the corresponding polynomial ring, etc.

To know what the object's parent is, one can use the function parent or the method parent of this object.

For example, having defined:

sage: N.<u> = NumberField(x^2 - x - 1)
sage: P.<t> = PolynomialRing(QQ)
sage: R.<y, z> = PolynomialRing(QQ)

and

sage: a = 3
sage: b = 6/2
sage: c = x + 3 - x
sage: d = t + 3 - t
sage: e = y + 3 - y
sage: f = mod(3, 8)

you could see that they all display as 3 but all have different parents.