The implementation works in a similar fashion. The problem here are the Sets with non comparable/ variable arguments.
`set.__contains__` doesn't work for them. In this test we cannot check if the extrema suppose in the set `Interval(-2, 0).intersect(Interval(x, y))`. What are the possible use cases of such functionality?

```python
In [20]: extrema(x, sin(x), Interval(y, z))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/hargup/arbit_sympy_testing/<ipython-input-20-7b4c4d45f1b3> in <module>()
----> 1 extrema(x, sin(x), Interval(y, z))

/home/hargup/arbit_sympy_testing/<ipython-input-14-91832d63c783> in extrema(x, expr, set)
     18     """
     19 
---> 20     locs = (filter(set.__contains__, solve(expr.diff(x), x)) +
     21                 [set.inf, set.sup])
     22     vals = [expr.subs(x, loc) for loc in locs]

/home/hargup/arbit_sympy_testing/sympy/core/sets.py in __contains__(self, other)
    269     def __contains__(self, other):
    270         symb = self.contains(other)
--> 271         result = ask(symb)
    272         if result is None:
    273             raise TypeError('contains did not evaluate to a bool: %r' % symb)

/home/hargup/arbit_sympy_testing/sympy/assumptions/ask.pyc in ask(proposition, assumptions, context)
    134 
    135     # direct resolution method, no logic

--> 136     res = key(expr)._eval_ask(assumptions)
    137     if res is not None:
    138         return res

/home/hargup/arbit_sympy_testing/sympy/assumptions/assume.pyc in _eval_ask(self, assumptions)
    102 
    103     def _eval_ask(self, assumptions):
--> 104         return self.func.eval(self.arg, assumptions)
    105 
    106 

/home/hargup/arbit_sympy_testing/sympy/assumptions/assume.pyc in eval(self, expr, assumptions)
    172                 except AttributeError:
    173                     continue
--> 174                 res = eval(expr, assumptions)
    175                 if _res is None:
    176                     _res = res

/home/hargup/arbit_sympy_testing/sympy/assumptions/handlers/common.pyc in And(expr, assumptions)
     84         result = True
     85         for arg in expr.args:
---> 86             p = ask(arg, assumptions=assumptions)
     87             if p is False:
     88                 return False

/home/hargup/arbit_sympy_testing/sympy/assumptions/ask.pyc in ask(proposition, assumptions, context)
    115     """
    116     if not isinstance(proposition, (BooleanFunction, AppliedPredicate, bool, BooleanAtom)):
--> 117         raise TypeError("proposition must be a valid logical expression")
    118 
    119     if not isinstance(assumptions, (BooleanFunction, AppliedPredicate, bool, BooleanAtom)):

TypeError: proposition must be a valid logical expression
```