# Ticket #10053: trac_10053_equality_testing_forms.patch

File trac_10053_equality_testing_forms.patch, 6.6 KB (added by jvkersch, 11 years ago)
• ## sage/tensor/coordinate_patch.py

# HG changeset patch
# User Joris Vankerschaver <joris.vankerschaver@gmail.com>
# Date 1286339483 25200
# Node ID d0961d2f45f35b58c99d91d3ae2d796eb37b4284
# Parent  1089f3d46aca6352a4b17654e4f3107573b98a8b
#10053: Equality instead of comparison for differential forms

diff -r 1089f3d46aca -r d0961d2f45f3 sage/tensor/coordinate_patch.py
 a def __cmp__(self, other): def __eq__(self, other): """ Compare self and other.  Return equality if and only if other has the same coordinates as self, in the same order. Return equality if and only if other has the same coordinates as self, in the same order. EXAMPLES:: Open subset of R^2 with coordinates u, v sage: U = CoordinatePatch((x, y, z)); U Open subset of R^3 with coordinates x, y, z sage: cmp(U, S) 0 sage: cmp(U, U) 0 sage: cmp(U, T) 1 sage: U == S True sage: U == U True sage: U == T False Note that the order of the coordinates matters:: Open subset of R^3 with coordinates x, y, z sage: T = CoordinatePatch((x, z, y)); T Open subset of R^3 with coordinates x, z, y sage: cmp(S, T) -1 sage: S == T False """ # Convert tuples of coordinates to strings before comparing # (see Trac 10041) return str(self._coordinates) == str(other._coordinates) return cmp(str(self._coordinates), str(other._coordinates)) def __ne__(self, other): """ Test whether two coordinate patches are not equal. EXAMPLES:: sage: x, y, z = var('x, y, z') sage: S = CoordinatePatch((x, y, z)); S Open subset of R^3 with coordinates x, y, z sage: u, v = var('u, v') sage: T = CoordinatePatch((u, v)); T Open subset of R^2 with coordinates u, v sage: S != T True """ return not self.__eq__(other) def coordinates(self):
• ## sage/tensor/differential_form_element.py

diff -r 1089f3d46aca -r d0961d2f45f3 sage/tensor/differential_form_element.py
 a True """ if type(other) == type(self): return self.__dict__ == other.__dict__ return False if self._degree != other._degree: return False else: # TODO: the following two lines are where most of the # execution time is spent. self._cleanup() other._cleanup() if len(self._components) != len(other._components): return False # We compare the component dictionary of both differential # forms, keeping in mind that the set of keys is # lexicographically ordered, so that we can simply iterate # over both dictionaries in one go and compare (key, value) # pairs as we go along. for (key1, val1), (key2, val2) in \ zip(self._components.iteritems(), \ other._components.iteritems()): if key1 != key2 or str(val1) != str(val2): return False return True else: return False #def __ne__(self, other): #    return not self.__eq__(other) def __ne__(self, other): r""" Test whether two differential forms are not equal. EXAMPLES:: sage: F = DifferentialForms(); F Algebra of differential forms in the variables x, y, z sage: f = DifferentialForm(F, 2) sage: f[1,2] = x; f x*dy/\dz sage: g = DifferentialForm(F, 3) sage: g[0, 1, 2] = 1; g dx/\dy/\dz sage: f != g True """ return not self.__eq__(other) def _neg_(self): zeros = [] for comp in self._components: if self._components[comp] == 0: if self._components[comp].is_zero(): zeros.append(comp) for comp in zeros:
• ## sage/tensor/differential_forms.py

diff -r 1089f3d46aca -r d0961d2f45f3 sage/tensor/differential_forms.py
 a category = GradedAlgebrasWithBasis(SR)) def __cmp__(self, other): def __eq__(self, other): """ Compare self with other. Return True if self is equal to other. EXAMPLES:: Algebra of differential forms in the variables p, q sage: H = DifferentialForms(U); H Algebra of differential forms in the variables x, y, z sage: cmp(F, G) 1 sage: cmp(F, H) 0 sage: F == G False sage: F == H True """ if type(other) == type(self): return cmp(self._patch, other._patch) return self._patch == other._patch else: return -1 return False def __ne__(self, other): """ Return True if self is not equal to other. 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: p, q = var('p, q') sage: V = CoordinatePatch((p, q)); V Open subset of R^2 with coordinates p, q sage: G = DifferentialForms(V); G Algebra of differential forms in the variables p, q sage: F != G True """ return not self.__eq__(other) def ngens(self):