original_docstring: r"""
          Try to return a pair of words with a common parent; raise an
          exception if this is not possible.
  
          This function begins by checking if both words have the same
          parent. If this is the case, then no work is done and both words
          are returned as-is.
  
          Otherwise it will attempt to convert ``other`` to the domain of ``self``.
          If that fails, it will attempt to convert ``self`` to the domain of
          ``other``. If both attempts fail, it raises a ``TypeError`` to signal
          failure.
  
          EXAMPLES::
  
              sage: W1 = Words('abc'); W2 = Words('ab')
              sage: w1 = W1('abc'); w2 = W2('abba'); w3 = W1('baab')
              sage: w1.parent() is w2.parent()
              False
              sage: a, b = w1.coerce(w2)
              sage: a.parent() is b.parent()
              True
              sage: w1.parent() is w2.parent()
              False
          
docstring: r"""
  Try to return a pair of words with a common parent; raise an
  exception if this is not possible.
  
  This function begins by checking if both words have the same
  parent. If this is the case, then no work is done and both words
  are returned as-is.
  
  
  
  
  
  
docstring_tokens: r " " " Try to return a pair of words with a common parent ; raise an exception if this is not possible . This function begins by checking if both words have the same parent . If this is the case then no work is done and both words are returned as - is .
code: def coerce(self, other):
          r"""
          Try to return a pair of words with a common parent; raise an
          exception if this is not possible.
  
          This function begins by checking if both words have the same
          parent. If this is the case, then no work is done and both words
          are returned as-is.
  
          Otherwise it will attempt to convert ``other`` to the domain of ``self``.
          If that fails, it will attempt to convert ``self`` to the domain of
          ``other``. If both attempts fail, it raises a ``TypeError`` to signal
          failure.
  
          EXAMPLES::
  
              sage: W1 = Words('abc'); W2 = Words('ab')
              sage: w1 = W1('abc'); w2 = W2('abba'); w3 = W1('baab')
              sage: w1.parent() is w2.parent()
              False
              sage: a, b = w1.coerce(w2)
              sage: a.parent() is b.parent()
              True
              sage: w1.parent() is w2.parent()
              False
          """
          if self.parent() != other.parent():
              try:
                  other = self.parent()(other)
                  other.parent()._check(other, length=None)
              except Exception:
                  try:
                      self = other.parent()(self)
                      self.parent()._check(self, length=None)
                  except Exception:
                      raise TypeError("no coercion rule between %r and %r" % (self.parent(), other.parent()))
          return self, other
code_tokens: def coerce ( self , other ) : if self . parent ( ) != other . parent ( ) : try : other = self . parent ( ) ( other ) other . parent ( ) . _check ( other , length = None ) except Exception : try : self = other . parent ( ) ( self ) self . parent ( ) . _check ( self , length = None ) except Exception : raise TypeError ( "no coercion rule between %r and %r" % ( self . parent ( ) , other . parent ( ) ) ) return self , other
short_docstring: r"""
  Try to return a pair of words with a common parent; raise an
  exception if this is not possible.
short_docstring_tokens: r " " " Try to return a pair of words with a common parent ; raise an exception if this is not possible .
comment: r"""
          Try to return a pair of words with a common parent; raise an
          exception if this is not possible.
  
          This function begins by checking if both words have the same
          parent. If this is the case, then no work is done and both words
          are returned as-is.
  
          Otherwise it will attempt to convert ``other`` to the domain of ``self``.
          If that fails, it will attempt to convert ``self`` to the domain of
          ``other``. If both attempts fail, it raises a ``TypeError`` to signal
          failure.
  
          EXAMPLES::
  
              sage: W1 = Words('abc'); W2 = Words('ab')
              sage: w1 = W1('abc'); w2 = W2('abba'); w3 = W1('baab')
              sage: w1.parent() is w2.parent()
              False
              sage: a, b = w1.coerce(w2)
              sage: a.parent() is b.parent()
              True
              sage: w1.parent() is w2.parent()
              False
          """