I do not use sage very often, and so I am sure I am overlooking something. Here is my problem:

I have very complex formula, and I have to solve that formula for one of variables (get some variable from expression). If I use solve() function is sage, it returns empty list, which is odd, but I found that it could be caused by too complex expression. So I managed to use sympy.solve(), but it returns exception. Here is part of my code:

k, u, v ,w , E, B, S, J, C1, C2 = var('k', 'u', 'v', 'w', 'E', 'B', 'S', 'J', 'C1', 'C2')
assume(B > 0)
assume(S > 0)
assume(J > 0)
assume(k > 0)
assume((u*E^2 + v*E + w) > 0)

f1 = (S == 1/6*(4*E^3*u + 3*E^2*v)/B + 1/6*(2*E^3*u + 3*E^2*v + 6*E*w)/B - k)
f2 = (J == E/B - k/(E^2*u + E*v + w))

#solve f1 and f2 for E

E_S = solve(f1, E)
E_J = solve(f2, E)

#under our assumptions only E_S[2] and A_J[2] are real
#so for that solutions lets find S

f_S1 = (E_S[2].right() == E_J[2].right())


solve(f_S1, S) #returns []

import sympy
sympy.solve(f_S1, S) #returns exception

And here is the returned error

Error in lines 14-14
Traceback (most recent call last):
  File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
  File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sympy/solvers/solvers.py", line 817, in solve
f, symbols = (_sympified_list(w) for w in [f, symbols])
  File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sympy/solvers/solvers.py", line 817, in <genexpr>
f, symbols = (_sympified_list(w) for w in [f, symbols])
  File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sympy/solvers/solvers.py", line 808, in _sympified_list
return list(map(sympify, w if iterable(w) else [w]))
  File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sympy/core/sympify.py", line 265, in sympify
return a._sympy_()
  File "sage/symbolic/expression.pyx", line 1445, in sage.symbolic.expression.Expression._sympy_ (/ext/sage/sage-8.0/src/build/cythonized/sage/symbolic/expression.cpp:11765)
return sympy(self)
  File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 220, in __call__
return self.relation(ex, operator)
  File "/ext/sage/sage-8.0/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 340, in relation
raise NotImplementedError("relation")
NotImplementedError: relation

Could anyone help me solve this problem?

  • $\begingroup$ You don't have a mathematics question. I suggest you use Sagemath questions forum instead. $\endgroup$
    – Somos
    Commented Nov 23, 2017 at 14:24

1 Answer 1


Relations are translated to SymPy in the new Sage-8.1 but the assumptions are not, see https://trac.sagemath.org/ticket/24078

I'm pretty sure that SymPy's solver would, for the most part, not know what to do with assumptions however. Have you tried to solve it in SymPy directly?

  • $\begingroup$ Thanks! My previous answer was not based on the most cutting-edge Sage 8.1 which was just released. $\endgroup$
    – kcrisman
    Commented Dec 8, 2017 at 16:05
  • $\begingroup$ I just tried to recode it into sympy. A run it on two separate machines but calculation didnt finish in two days, so I canceled it. Is it a bug? $\endgroup$
    – Bobesh
    Commented Dec 20, 2017 at 10:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .