Example #1
0
    def gen(self, i=0):
        """
        Return the `i^{th}` generator of ``self``.  This is a one-form,
        more precisely the exterior derivative of the i-th coordinate.

        INPUT:

        - ``i`` - integer (optional, default 0)


        EXAMPLES::

            sage: x, y, z = var('x, y, z')
            sage: U = CoordinatePatch((x, y, z)); U
            Open subset of R^3 with coordinates x, y, z
            sage: F = DifferentialForms(U); F
            Algebra of differential forms in the variables x, y, z
            sage: F.gen(0)
            dx
            sage: F.gen(1)
            dy
            sage: F.gen(2)
            dz

        """

        form = DifferentialForm(self, 0, self._patch.coordinate(i))
        return form.diff()
Example #2
0
    def gen(self, i=0):
        """
        Return the `i^{th}` generator of ``self``.  This is a one-form,
        more precisely the exterior derivative of the i-th coordinate.

        INPUT:

        - ``i`` - integer (optional, default 0)


        EXAMPLES::

            sage: x, y, z = var('x, y, z')
            sage: U = CoordinatePatch((x, y, z)); U
            Open subset of R^3 with coordinates x, y, z
            sage: F = DifferentialForms(U); F
            Algebra of differential forms in the variables x, y, z
            sage: F.gen(0)
            dx
            sage: F.gen(1)
            dy
            sage: F.gen(2)
            dz

        """

        form = DifferentialForm(self, 0, self._patch.coordinate(i))
        return form.diff()
    def _element_constructor_(self, fun):
        """
        Coerce a given function (element of the symbolic ring)
        into a differential form of degree zero.

        EXAMPLES::

            sage: x, y, z = var('x, y, z')
            sage: U = CoordinatePatch((x, y, z))
            doctest:...: DeprecationWarning: Use Manifold instead.
            See http://trac.sagemath.org/24444 for details.
            sage: F = DifferentialForms(U); F
            doctest:...:  DeprecationWarning: For the set of differential forms of
             degree p, use U.diff_form_module(p), where U is the base manifold
             (type U.diff_form_module? for details).
            See http://trac.sagemath.org/24444 for details.
            Algebra of differential forms in the variables x, y, z
            sage: F(sin(x*y))    # indirect doctest
            doctest:...: DeprecationWarning: Use U.diff_form(degree) instead,
             where U is the base manifold (type U.diff_form? for details).
            See http://trac.sagemath.org/24444 for details.
            sin(x*y)

        """


        fun = SR(fun)
        if fun not in self:
            raise ValueError("Function not an element of this algebra of differential forms.")

        return DifferentialForm(self, 0, fun)
Example #4
0
 def test_derivative(self):
     x = self.x
     y = self.y
     z = self.z
     logdf = LogarithmicDifferentialForm(1, [y * z, x * z, x * y],
                                         self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     logdf_der = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(logdf_der.equals(logdf.derivative()))
Example #5
0
 def test_creationA(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     logdf = LogarithmicDifferentialForm(2, [self.x, self.y, self.z],
                                         self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     form[0, 1] = 1 / (y * z)
     form[0, 2] = 1 / (x * z)
     form[1, 2] = 1 / (x * y)
     self.assertEqual(form, logdf.form)
Example #6
0
 def test_creation_B(self):
     x = self.whitney_logdf.form_vars[0]
     y = self.whitney_logdf.form_vars[1]
     z = self.whitney_logdf.form_vars[2]
     whitney = x**2 * y - z**2
     logdf = LogarithmicDifferentialForm(2, [self.x, self.y, self.z],
                                         self.whitney_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     form[0, 1] = x / whitney
     form[0, 2] = y / whitney
     form[1, 2] = z / whitney
     self.assertEqual(form, logdf.form)
Example #7
0
 def test_interior_1_form(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     form = DifferentialForm(self.normal_logdf.form_space, 0,
                             (x + y + z) / (x * y * z))
     one = self.poly_ring.one()
     logdf = LogarithmicDifferentialForm(1, [one, one, one],
                                         self.normal_logdf)
     int_product = logdf.interior_product()
     logdf_form = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(int_product.equals(logdf_form))
Example #8
0
 def test_mul(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     logdf = LogarithmicDifferentialForm(2, [self.x, self.y, self.z],
                                         self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     form[0, 1] = -5 / (y * z)
     form[0, 2] = -5 / (x * z)
     form[1, 2] = -5 / (x * y)
     self.assertTrue((logdf * (-5)).equals((-5) * logdf))
     logdf_mul = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue((-5 * logdf).equals(logdf_mul))
Example #9
0
 def test_create_from_0_form(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     xp = self.x
     yp = self.y
     zp = self.z
     logdf = LogarithmicDifferentialForm(0, [xp + yp + zp],
                                         self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 0,
                             (x + y + z) / (x * y * z))
     logdf_form = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(logdf.equals(logdf_form))
Example #10
0
    def gen(self, i=0):
        """
        Return the `i^{th}` generator of ``self``.  This is a one-form,
        more precisely the exterior derivative of the i-th coordinate.

        INPUT:

        - ``i`` - integer (optional, default 0)


        EXAMPLES::

            sage: x, y, z = var('x, y, z')
            sage: U = CoordinatePatch((x, y, z)); U
            doctest:...: DeprecationWarning: Use Manifold instead.
            See http://trac.sagemath.org/24444 for details.
            Open subset of R^3 with coordinates x, y, z
            sage: F = DifferentialForms(U); F
            doctest:...:  DeprecationWarning: For the set of differential forms of
             degree p, use U.diff_form_module(p), where U is the base manifold
             (type U.diff_form_module? for details).
            See http://trac.sagemath.org/24444 for details.
            Algebra of differential forms in the variables x, y, z
            sage: F.gen(0)
            doctest:...: DeprecationWarning: Use U.diff_form(degree) instead,
             where U is the base manifold (type U.diff_form? for details).
            See http://trac.sagemath.org/24444 for details.
            dx
            sage: F.gen(1)
            dy
            sage: F.gen(2)
            dz

        """

        form = DifferentialForm(self, 0, self._patch.coordinate(i))
        return form.diff()
Example #11
0
 def test_sub(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     logdfA = LogarithmicDifferentialForm(2, [self.x, self.y, self.z],
                                          self.normal_logdf)
     logdfB = LogarithmicDifferentialForm(2, [self.z, self.y, self.x],
                                          self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     form[0, 1] = 1 / (y * z) - 1 / (x * y)
     form[0, 2] = 0
     form[1, 2] = 1 / (x * y) - 1 / (y * z)
     logdf_diff = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(logdf_diff.equals(logdfA - logdfB))
Example #12
0
 def interior_product(self):
   if self.degree==0:
     return LogarithmicDifferentialForm.make_zero(0,self.diff_forms)
   prod_form = DifferentialForm(self.diff_forms.form_space,self.degree-1)
   for v in skew_iter(self.diff_forms.poly_ring.ngens(),self.degree):
     for e_i,e in enumerate(v):
       partial_var = self.diff_forms.form_vars[e]
       partial_w = self.diff_forms.wieghts[e]
       partial = ((-1)**(e_i)) * self.form[tuple(v)] * partial_var * partial_w
       if self.degree>1:
         rest = [ e_other for e_other in v if e_other != e]
         prod_form[tuple(rest)] = prod_form[tuple(rest)] + partial
       else:
         prod_form = prod_form + partial
   return LogarithmicDifferentialForm.create_from_form(prod_form,self.diff_forms)
    def weight_integrand(self, simplify_factor=True):
        """
        Weight integrand as a rational function.

        The Jacobian determinant of some coordinate transformation.
        """
        def arg(x, y):
            return arctan(y / x)  # up to a constant, but it doesn't matter

        def phi(x, y, a, b):
            z = (a + I * b - x - I * y) * (a - I * b - x - I * y)
            w = z.real()
            q = z.imag()
            return arg(w, q).full_simplify()

        n = len(self.internal_vertices())
        coordinates = lambda v: SR.var(chr(97+2*(v-1)) + ',' + chr(97+2*(v-1)+1)) \
                                if v in self.internal_vertices() else \
                                [(0,0), (1,0)][self.ground_vertices().index(v)]
        internal_coordinates = sum(
            (list(coordinates(v)) for v in sorted(self.internal_vertices())),
            [])
        U = CoordinatePatch(internal_coordinates)
        F = DifferentialForms(U)
        psi = 0
        two_forms = []
        for v in self.internal_vertices():
            x, y = coordinates(v)
            outgoing_edges = self.outgoing_edges([v])
            left_target = filter(lambda (x, y, z): z == 'L',
                                 outgoing_edges)[0][1]
            right_target = filter(lambda (x, y, z): z == 'R',
                                  outgoing_edges)[0][1]
            one_forms = []
            for target in [left_target, right_target]:
                a, b = coordinates(target)
                one_form = DifferentialForm(F, 1)
                for v in internal_coordinates:
                    index = internal_coordinates.index(v)
                    one_form[index] = phi(x, y, a, b).diff(v)
                    if simplify_factor:
                        one_form[index] = SR(one_form[index]).full_simplify()
                one_forms.append(one_form)
            two_form = one_forms[0] * one_forms[1]
            two_forms.append(two_form)
        import operator
        two_n_form = reduce(operator.mul, two_forms, 1)
        return two_n_form[range(0, 2 * n)]
Example #14
0
 def test_create_from_form(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     xp = self.x
     yp = self.y
     zp = self.z
     logdf = LogarithmicDifferentialForm(
         2, [xp * yp - yp * zp, xp**2 - zp**2, xp * yp - yp * zp],
         self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     form[0, 1] = 1 / z - 1 / x
     form[0, 2] = (x / (y * z)) - (z / (x * y))
     form[1, 2] = 1 / z - 1 / x
     logdf_form = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(logdf.equals(logdf_form))
Example #15
0
 def test_wedge(self):
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     norm = self.x * self.y * self.z
     logdfA = LogarithmicDifferentialForm(
         1, [self.x * norm, self.y * norm, self.z * norm],
         self.normal_logdf)
     logdfB = LogarithmicDifferentialForm(1, [self.z, self.y, self.x],
                                          self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 2)
     form[0, 1] = 1 / z - 1 / x
     form[0, 2] = (x / (y * z)) - (z / (x * y))
     form[1, 2] = 1 / z - 1 / x
     logdf_wedge = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(logdf_wedge.equals(logdfA.wedge(logdfB)))
Example #16
0
 def test_interior(self):
     xp = self.x
     yp = self.y
     zp = self.z
     logdf = LogarithmicDifferentialForm(
         2, [xp**2, xp + 4 * yp + zp, xp**3 * zp**3], self.whitney_logdf)
     int_product = logdf.interior_product()
     x = self.normal_logdf.form_vars[0]
     y = self.normal_logdf.form_vars[1]
     z = self.normal_logdf.form_vars[2]
     whitney = x**2 * y - z**2
     form = DifferentialForm(self.normal_logdf.form_space, 1)
     form[0] = (-2 * x**2 * y - 2 * x * z - 8 * y * z - 2 * z**2) / whitney
     form[1] = (x**3 - 2 * x**3 * z**4) / whitney
     form[2] = (x**2 + 4 * x * y + x * z + 2 * x**3 * y * z**3) / whitney
     logdf_form = LogarithmicDifferentialForm.create_from_form(
         form, self.whitney_logdf)
     self.assertTrue(int_product.equals(logdf_form))
Example #17
0
    def _element_constructor_(self, fun):
        """
        Coerce a given function (element of the symbolic ring)
        into a differential form of degree zero.

        EXAMPLES::

            sage: x, y, z = var('x, y, z')
            sage: U = CoordinatePatch((x, y, z))
            sage: F = DifferentialForms(U); F
            Algebra of differential forms in the variables x, y, z
            sage: F(sin(x*y))    # indirect doctest
            sin(x*y)

        """

        fun = SR(fun)
        if fun not in self:
            raise ValueError, \
                "Function not an element of this algebra of differential forms."

        return DifferentialForm(self, 0, fun)
Example #18
0
 def __init__(self,degree,vec,differential_forms):
   self.vec = vec
   self.degree = degree
   self.diff_forms = differential_forms
   self.divisor = self.diff_forms.divisor
   sym_divisor = convert_polynomial_to_symbolic(self.divisor,self.diff_forms.form_vars)
   #Construct the p_forms version of self
   if degree==0:
     sym_poly = convert_polynomial_to_symbolic(self.vec[0],self.diff_forms.form_vars)
     self.form = DifferentialForm(self.diff_forms.form_space,degree,sym_poly/sym_divisor)
     return
   if degree==self.diff_forms.poly_ring.ngens():
     sym_poly = convert_polynomial_to_symbolic(self.vec[0],self.diff_forms.form_vars)
     self.form = DifferentialForm(self.diff_forms.form_space,degree)
     self.form[tuple(range(degree))] = sym_poly/sym_divisor
   else:
     self.form = DifferentialForm(self.diff_forms.form_space,degree)
     for i,v in enumerate(skew_iter(self.diff_forms.poly_ring.ngens(),degree)):
       sym_poly = convert_polynomial_to_symbolic(self.vec[i],self.diff_forms.form_vars)
       self.form[tuple(v)] = sym_poly/sym_divisor;
Example #19
0
 def test_unit(self):
     one = LogarithmicDifferentialForm.make_unit(self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 0, 1)
     one_form = LogarithmicDifferentialForm.create_from_form(
         form, self.normal_logdf)
     self.assertTrue(one.equals(one_form))
Example #20
0
 def wedge(self,other):
   diff_form = DifferentialForm.wedge(self.form,other.form)
   return LogarithmicDifferentialForm.create_from_form(diff_form,self.diff_forms)
Example #21
0
class LogarithmicDifferentialForm(SageObject):
    
  def __init__(self,degree,vec,differential_forms):
    self.vec = vec
    self.degree = degree
    self.diff_forms = differential_forms
    self.divisor = self.diff_forms.divisor
    sym_divisor = convert_polynomial_to_symbolic(self.divisor,self.diff_forms.form_vars)
    #Construct the p_forms version of self
    if degree==0:
      sym_poly = convert_polynomial_to_symbolic(self.vec[0],self.diff_forms.form_vars)
      self.form = DifferentialForm(self.diff_forms.form_space,degree,sym_poly/sym_divisor)
      return
    if degree==self.diff_forms.poly_ring.ngens():
      sym_poly = convert_polynomial_to_symbolic(self.vec[0],self.diff_forms.form_vars)
      self.form = DifferentialForm(self.diff_forms.form_space,degree)
      self.form[tuple(range(degree))] = sym_poly/sym_divisor
    else:
      self.form = DifferentialForm(self.diff_forms.form_space,degree)
      for i,v in enumerate(skew_iter(self.diff_forms.poly_ring.ngens(),degree)):
        sym_poly = convert_polynomial_to_symbolic(self.vec[i],self.diff_forms.form_vars)
        self.form[tuple(v)] = sym_poly/sym_divisor;

  def equals(self,other):
    if self.diff_forms==other.diff_forms:
      if self.degree==other.degree:
        for self_v,other_v in zip(self.vec,other.vec):
          if not self_v==other_v:
            return False
          return True
    return False


  def wedge(self,other):
    diff_form = DifferentialForm.wedge(self.form,other.form)
    return LogarithmicDifferentialForm.create_from_form(diff_form,self.diff_forms)

  def derivative(self):
    diff_form = self.form.derivative()
    return LogarithmicDifferentialForm.create_from_form(diff_form,self.diff_forms)

  def __add__(self,other):
    diff_form = self.form+other.form
    return LogarithmicDifferentialForm.create_from_form(diff_form,self.diff_forms)

  def __sub__(self,other):
    diff_form = self.form-other.form
    return LogarithmicDifferentialForm.create_from_form(diff_form,self.diff_forms)

  def __mul__(self,scalar):
    vec = []
    for v in self.vec:
      vec.append(v*Rational(scalar))
    return LogarithmicDifferentialForm(self.form.degree(),vec,self.diff_forms)

  def __rmul__(self,scalar):
    vec = []
    for v in self.vec:
      vec.append(v*Rational(scalar))
    return LogarithmicDifferentialForm(self.form.degree(),vec,self.diff_forms)

  def interior_product(self):
    if self.degree==0:
      return LogarithmicDifferentialForm.make_zero(0,self.diff_forms)
    prod_form = DifferentialForm(self.diff_forms.form_space,self.degree-1)
    for v in skew_iter(self.diff_forms.poly_ring.ngens(),self.degree):
      for e_i,e in enumerate(v):
        partial_var = self.diff_forms.form_vars[e]
        partial_w = self.diff_forms.wieghts[e]
        partial = ((-1)**(e_i)) * self.form[tuple(v)] * partial_var * partial_w
        if self.degree>1:
          rest = [ e_other for e_other in v if e_other != e]
          prod_form[tuple(rest)] = prod_form[tuple(rest)] + partial
        else:
          prod_form = prod_form + partial
    return LogarithmicDifferentialForm.create_from_form(prod_form,self.diff_forms)

  def __repr__(self):
    return self.form.__repr__()

  def __latex__(self):
    if self.degree==0:
      return "$"+self.form.__repr__()+"$"
    if self.degree == self.diff_forms.poly_ring.ngens():
      string =  "$"+self.form[tuple(range(self.degree))].__repr__()
      diff = []
      for v in self.diff_forms.form_vars:
        diff.append("d "+v.__repr__())
      return string+("\wedge ".join(diff))+"$"
    parts = []
    for i,v in enumerate(skew_iter(self.diff_forms.poly_ring.ngens(),self.degree)):
      if not self.vec[i].is_zero():
        parts.append("$"+self.form[tuple(v)].__repr__())
        diff = []
        for e_i in v:
          diff.append("d "+self.diff_forms.form_vars[e_i].__repr__())
        parts[-1] = parts[-1]+("\wedge ".join(diff)) + "$"
    return "+".join(parts)

  @classmethod
  def create_from_form(cls,form,diff_forms):
    sym_divisor = convert_polynomial_to_symbolic(diff_forms.divisor,diff_forms.form_vars)
    if form.degree()==0:
      sym_poly = _get_sym_from_0_form(form,diff_forms)*sym_divisor
      poly = convert_symbolic_to_polynomial(sym_poly,diff_forms.poly_ring,diff_forms.form_vars)
      return LogarithmicDifferentialForm(0,[poly],diff_forms)
    n = diff_forms.poly_ring.ngens()
    if form.degree()==n:
      sym_poly = form[tuple(range(n))]*sym_divisor
      poly = convert_symbolic_to_polynomial(sym_poly,diff_forms.poly_ring,diff_forms.form_vars)
      return LogarithmicDifferentialForm(n,[poly],diff_forms)
    #Compute vec
    vec = []
    for _,v in enumerate(skew_iter(diff_forms.poly_ring.ngens(),form.degree())):
      sym_poly = form[tuple(v)] * sym_divisor
      vec.append(convert_symbolic_to_polynomial(sym_poly,diff_forms.poly_ring,diff_forms.form_vars))
    return LogarithmicDifferentialForm(form.degree(),vec,diff_forms)
  @classmethod
  def make_unit(cls,diff_forms):
    unit = LogarithmicDifferentialForm(0,[diff_forms.divisor],diff_forms)
    return unit

  @classmethod
  def make_zero(cls,p,diff_forms):
    zero_form = DifferentialForm(diff_forms.form_space,p)
    return LogarithmicDifferentialForm.create_from_form(zero_form,diff_forms)
Example #22
0
def _get_sym_from_0_form(form,diff_forms):
  dz = DifferentialForm(diff_forms.form_space,1)
  dz[(0,)] = 1
  return form.wedge(dz)[(0,)]
Example #23
0
 def make_zero(cls,p,diff_forms):
   zero_form = DifferentialForm(diff_forms.form_space,p)
   return LogarithmicDifferentialForm.create_from_form(zero_form,diff_forms)
Example #24
0
 def test_creation_0_form(self):
     z = self.normal_logdf.form_vars[2]
     logdf = LogarithmicDifferentialForm(0, [self.x * self.y],
                                         self.normal_logdf)
     form = DifferentialForm(self.normal_logdf.form_space, 0, 1 / z)
     self.assertEqual(form, logdf.form)