Skip to content

Commit f9cfcf7

Browse files
committed
Expression python name from object to this package.
1 parent d235287 commit f9cfcf7

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Demonstration of equation class.ipynb

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"name": "stdout",
2929
"output_type": "stream",
3030
"text": [
31-
"This notebook is running Algebra_with_Sympy version 1.1.1.\n"
31+
"This notebook is running Algebra_with_Sympy version 1.1.2.\n"
3232
]
3333
}
3434
],
@@ -1306,7 +1306,7 @@
13061306
{
13071307
"data": {
13081308
"text/latex": [
1309-
"$c^{2} - c + x^{4} \\left(a^{2} + 2 a + 1\\right) + x^{3} \\cdot \\left(2 a^{2} + 2 a b + 2 a + 2 b\\right) + x^{2} \\left(a^{2} + 2 a b + 2 a c - a + b^{2} + 2 c - 1\\right) + x \\left(2 a c - a + 2 b c - b\\right)=a^{2} x^{4} + 4 c^{2} + 2 c + x^{3} \\cdot \\left(2 a^{2} + 2 a b\\right) + x^{2} \\left(a^{2} + 2 a b + 4 a c + a + b^{2}\\right) + x \\left(4 a c + a + 4 b c + b\\right)$"
1309+
"$c^{2} - c + x^{4} \\left(a^{2} + 2 a + 1\\right) + x^{3} \\left(2 a^{2} + 2 a b + 2 a + 2 b\\right) + x^{2} \\left(a^{2} + 2 a b + 2 a c - a + b^{2} + 2 c - 1\\right) + x \\left(2 a c - a + 2 b c - b\\right)=a^{2} x^{4} + 4 c^{2} + 2 c + x^{3} \\left(2 a^{2} + 2 a b\\right) + x^{2} \\left(a^{2} + 2 a b + 4 a c + a + b^{2}\\right) + x \\left(4 a c + a + 4 b c + b\\right)$"
13101310
],
13111311
"text/plain": [
13121312
"Equation(c**2 - c + x**4*(a**2 + 2*a + 1) + x**3*(2*a**2 + 2*a*b + 2*a + 2*b) + x**2*(a**2 + 2*a*b + 2*a*c - a + b**2 + 2*c - 1) + x*(2*a*c - a + 2*b*c - b), a**2*x**4 + 4*c**2 + 2*c + x**3*(2*a**2 + 2*a*b) + x**2*(a**2 + 2*a*b + 4*a*c + a + b**2) + x*(4*a*c + a + 4*b*c + b))"
@@ -1330,7 +1330,7 @@
13301330
{
13311331
"data": {
13321332
"text/latex": [
1333-
"$c^{2} - c + x^{4} \\left(a^{2} + 2 a + 1\\right) + x^{3} \\cdot \\left(2 a^{2} + 2 a b + 2 a + 2 b\\right) + x^{2} \\left(a^{2} + 2 a b + 2 a c - a + b^{2} + 2 c - 1\\right) + x \\left(2 a c - a + 2 b c - b\\right)=a^{2} x^{4} + 4 c^{2} + 2 c + x^{3} \\cdot \\left(2 a^{2} + 2 a b\\right) + x^{2} \\left(a^{2} + 2 a b + 4 a c + a + b^{2}\\right) + x \\left(4 a c + a + 4 b c + b\\right)$"
1333+
"$c^{2} - c + x^{4} \\left(a^{2} + 2 a + 1\\right) + x^{3} \\left(2 a^{2} + 2 a b + 2 a + 2 b\\right) + x^{2} \\left(a^{2} + 2 a b + 2 a c - a + b^{2} + 2 c - 1\\right) + x \\left(2 a c - a + 2 b c - b\\right)=a^{2} x^{4} + 4 c^{2} + 2 c + x^{3} \\left(2 a^{2} + 2 a b\\right) + x^{2} \\left(a^{2} + 2 a b + 4 a c + a + b^{2}\\right) + x \\left(4 a c + a + 4 b c + b\\right)$"
13341334
],
13351335
"text/plain": [
13361336
"Equation(c**2 - c + x**4*(a**2 + 2*a + 1) + x**3*(2*a**2 + 2*a*b + 2*a + 2*b) + x**2*(a**2 + 2*a*b + 2*a*c - a + b**2 + 2*c - 1) + x*(2*a*c - a + 2*b*c - b), a**2*x**4 + 4*c**2 + 2*c + x**3*(2*a**2 + 2*a*b) + x**2*(a**2 + 2*a*b + 4*a*c + a + b**2) + x*(4*a*c + a + 4*b*c + b))"
@@ -4184,7 +4184,7 @@
41844184
{
41854185
"data": {
41864186
"text/plain": [
4187-
"'1.1.1'"
4187+
"'1.1.2'"
41884188
]
41894189
},
41904190
"execution_count": 168,
@@ -4204,7 +4204,7 @@
42044204
{
42054205
"data": {
42064206
"text/plain": [
4207-
"'1.1.1'"
4207+
"'1.1.2'"
42084208
]
42094209
},
42104210
"execution_count": 169,

algebra_with_sympy/algebraic_equation.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ def integers_as_exact(self):
388388
"""
389389
return self.integers_as_exact
390390

391+
def __get_sympy_expr_name__(expr):
392+
"""
393+
Tries to find the python string name that refers to a sympy object. In
394+
IPython environments (IPython, Jupyter, etc...) looks in the user_ns.
395+
If not in an IPython environment looks in __main__.
396+
:return: string value if found or empty string.
397+
"""
398+
import __main__ as shell
399+
for k in dir(shell):
400+
item = getattr(shell, k)
401+
if isinstance(item, Basic):
402+
if item == expr and not k.startswith('_'):
403+
return k
404+
return ''
405+
391406
def __latex_override__(expr, *arg):
392407
algwsym_config = False
393408
ip = False
@@ -420,7 +435,7 @@ def __latex_override__(expr, *arg):
420435
tempstr = ''
421436
namestr = ''
422437
if isinstance(expr, Equation):
423-
namestr = expr._get_eqn_name()
438+
namestr = __get_sympy_expr_name__(expr)
424439
if namestr != '' and algwsym_config and algwsym_config.output.label:
425440
tempstr += r'$'+latex(expr)
426441
# work around for colab's inconsistent handling of mixed latex and
@@ -450,7 +465,7 @@ def __command_line_printing__(expr, *arg):
450465
labelstr = ''
451466
namestr = ''
452467
if isinstance(expr, Equation):
453-
namestr = expr._get_eqn_name()
468+
namestr = __get_sympy_expr_name__(expr)
454469
if namestr != '' and algwsym_config.output.label:
455470
labelstr += ' (' + namestr + ')'
456471
return print(tempstr + str(expr) + labelstr)

version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.1.2'
1+
__version__ = '1.1.3dev0'

0 commit comments

Comments
 (0)