yt.units.unit_object.Unit.match — The yt Project 3.2-dev documentation

# yt.units.unit_object.Unit.match

`Unit.` `match`(pattern, old=False)

  Pattern matching.

  Wild symbols match all.

  Return `None` when expression (self) does not match with pattern. Otherwise return a dictionary such that:

      pattern.xreplace(self.match(pattern)) == self

  Examples

      >>> from sympy import Wild
      >>> from sympy.abc import x, y
      >>> p = Wild("p")
      >>> q = Wild("q")
      >>> r = Wild("r")
      >>> e = (x+y)**(x+y)
      >>> e.match(p**p)
      {p_: x + y}
      >>> e.match(p**q)
      {p_: x + y, q_: x + y}
      >>> e = (2*x)**2
      >>> e.match(p*q**r)
      {p_: 4, q_: x, r_: 2}
      >>> (p*q**r).xreplace(e.match(p*q**r))
      4*x**2

  The `old` flag will give the old-style pattern matching where expressions and patterns are essentially solved to give the match. Both of the following give None unless `old=True`:

      >>> (x - 2).match(p - x, old=True)
      {p_: 2*x - 2}
      >>> (2/x).match(p*x, old=True)
      {p_: 2/x**2}