Define a variable in sympy to be a CONSTANT
<pre><code>from sympy import *
from sympy.stats import *
mu, Y = symbols('mu Y', real = True, constant = True)
sigma = symbols('sigma', real = True, positive=True)
X = Normal('X', mu, sigma)
</code></pre>

<p>When asking for:</p>

<pre><code>E(X, evaluate=False)
</code></pre>

<p>I get:</p>

<pre><code>â                     
â                      
â®                2    
â®        -(X - Î¼)     
â®        ââââââââââ   
â®              2      
â®           2âÏ       
â®  â2âXââ¯             
â®  ââââââââââââââââ dX
â®       2ââÏâÏ        
â¡                     
-â 
</code></pre>

<p>Which is what I expect. When asking for:</p>

<pre><code>E(X, X&gt;0, evaluate=False)
E(X, X&gt;pi, evaluate=False)
E(X, X &gt;-3, evaluate=False)
</code></pre>

<p>Using any constant, the result is as expected from the Normal Definition of conditional expectation. However, when trying to solve for:</p>

<pre><code>E(X, X&gt;Y)
</code></pre>

<p>I'm getting an error that has to do with roots. Is there a way to define a Y, such that sympy acknowledges that it is a constant, just like a 0 or a -3 or even pi, and shows the integration as expected? I'm assuming the problem with the request I have from sympy is that somehow the Y isn't acknowledges as a constant and therefore, when trying to solve this request, sympy is faced with a roots problem.</p>

<p>Your problem appears to be a limitation in the current inequality solver: the algorithm that transforms a system of inequalities to a union of sets apparently needs to sort the boundary points determined by those inequalities (even if there's only one such point). Reduction of inequalities with symbolic limits has not been implemented yet.</p>

<p>I suggest a <strong>dirty trick</strong> to get around this limitation. Define:</p>

<pre><code>class SymbolTrick(NumberSymbol):
    def __new__(self, name):
        obj = NumberSymbol.__new__(self)
        obj._name = name
        return obj

    _as_mpf_val = pi._as_mpf_val
    approximation_interval = pi.approximation_interval
    __str__ = lambda self: str(self._name)
</code></pre>

<p>This defines a subclass of <em>NumberSymbol</em> having the same numeric value of <em>pi</em> (it is necessary to specify one, as the inequality reduction algorithm needs to sort the list boundaries otherwise it will fail).</p>

<p>At this point:</p>

<pre><code>In [7]: Y = SymbolTrick("Y")

In [8]: E(X, X &gt; Y, evaluate=False)
Out[8]: 
â                              
â                               
â®                    2         
â®            -(X - Î¼)          
â®            ââââââââââ        
â®                  2           
â®               2âÏ            
â®      â2âXââ¯                  
â® ââââââââââââââââââââââââââ dX
â®        â                     
â®        â                      
â®        â®             2       
â®        â®     -(X - Î¼)        
â®        â®     ââââââââââ      
â®        â®           2         
â®        â®        2âÏ          
â®        â® â2ââ¯                
â® 2ââÏâÏââ® ââââââââââââââ dX   
â®        â®     2ââÏâÏ          
â®        â¡                     
â®        Y                     
â¡      
Y
</code></pre>

python symbols sympy