A computer algebra system written in pure Python http://sympy.org/ . To get started to with contributing https://github.com/sympy/sympy/wiki/Introduction-to-contributing
oscarbenjamin on master
Improved type checking - part 2 Merge branch 'master' into bett… Merge pull request #22150 from … (compare)
oscarbenjamin on master
Removed even more Python 2-supp… Merge pull request #22798 from … (compare)
oscarbenjamin on master
Added rewrite from Sum to Produ… Merge pull request #22331 from … (compare)
class Data:
def __init__(self, string,symbol, value):
self.string = string
self.symbol = sm.Symbol(symbol)
self.value = value
def __add__(self, other):
return self.value + other.value if isinstance(other, Data) else other
def __str__(self):
return self.string
def _repr_latex_(self):
return display(Latex(' '.join([self.string, f'({self.symbol})' ,r'\equals', self.value] )))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
c:\users\dell\onedrive\desktop\courses sem8\venv\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
--> 345 return method()
346 return None
347 else:
<ipython-input-49-83e3f780e89d> in _repr_latex_(self)
11 return self.string
12 def _repr_latex_(self):
---> 13 return display(Latex(' '.join([self.string, f'({self.symbol})' ,r'\equals', self.value] )))
14 # area_each_plate = Data("Area of each plate", 15.8*15.8*SI.cm**2)
15 # inlet_pressure = Data("Area of each plate", 15.8*15.8*SI.cm**2)
TypeError: sequence item 3: expected str instance, Quantity found
self.value
. join
requires that every item is converted to a string, so use latex(self.value)
.
_repr_latex
should return a string, not call display().
sympify ("2**5", evaluate=False)
Interesting, simplify("2**5",evaluate=False) didn't work for me, but the Pow function did work with evaluate set to False.
Hi - I'm learning and am looking for a hint for setting up an equation.
The problem is naturally expressed as:
# maximize:
# z = 100*x_1 + 60*x_2 + 70*x_3 + 15*x_4 + 15*x_5
# subject to limits:
# 52*x_1 + 23*x_2 + 35*x_3 + 15*x_4 + 7*x_5 <= 60
# X_1 in {0,1}
# x_2 in {0,1}
# x_3 in {0,1}
# x_4 in {0,1}
# x_5 in {0,1}
But I can't find a way to express "x_1 in the set containing {0,1}
My personal preference is to use the matrix representation
m = Matrix((
[52,23,35,15,7,-60],
[1,0,0,0,0,0],
[0,1,0,0,0,0],
[0,0,1,0,0,0],
[0,0,0,1,0,0],
[0,0,0,0,1,0]
))
...but I'm not sure how to package the variables for the nonlinsolve
function.
decimal(-7/3)
I got -2.333333333333333481363069950020872056484222412109375
I increased the decimal precision. Now I want to convert back to a fraction but each time I got something else that -7/3. Any advice ?
Using x'
as a variable inside parse_expr(...)
(https://docs.sympy.org/latest/modules/parsing.html?highlight=transformations#sympy.parsing.sympy_parser.parse_expr) doesn't seem to work:
>>> from sympy import Symbol
>>> from sympy.parsing.sympy_parser import (parse_expr, standard_transformations, implicit_multiplication_application, convert_xor)
>>>
>>> def parse_plain_text(e, local_dict=None):
... return parse_expr(
... e,
... local_dict=local_dict,
... transformations=(standard_transformations + (implicit_multiplication_application, convert_xor)),
... evaluate=False)
...
>>> parse_plain_text("x_", {"x_": Symbol("x_")})
x_
>>> parse_plain_text("x'", {"x'": Symbol("x'")})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in parse_plain_text
File "REDACTED/sympy/sympy/parsing/sympy_parser.py", line 1005, in parse_expr
code = compile(evaluateFalse(code), '<string>', 'eval')
File "REDACTED/sympy/sympy/parsing/sympy_parser.py", line 1014, in evaluateFalse
node = ast.parse(s)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ast.py", line 47, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
Symbol ('x' )'
^
SyntaxError: EOL while scanning string literal
I could remap this variable to something like x_
(which doesn't throw an error), but is there a way to avoid this workaround?
tokenize
auto_symbol
and modify it so that it allows NAME + '
tokens.