projects
/
linpy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix symbols() function
[linpy.git]
/
pypol
/
linear.py
diff --git
a/pypol/linear.py
b/pypol/linear.py
index
bd7037b
..
845fac3
100644
(file)
--- a/
pypol/linear.py
+++ b/
pypol/linear.py
@@
-62,7
+62,7
@@
class Expression:
for symbol, coefficient in coefficients if coefficient != 0]
if len(coefficients) == 0:
return Constant(constant)
for symbol, coefficient in coefficients if coefficient != 0]
if len(coefficients) == 0:
return Constant(constant)
- elif len(coefficients) == 1:
+ elif len(coefficients) == 1
and constant == 0
:
symbol, coefficient = coefficients[0]
if coefficient == 1:
return Symbol(symbol)
symbol, coefficient = coefficients[0]
if coefficient == 1:
return Symbol(symbol)
@@
-135,7
+135,7
@@
class Expression:
return False
def __bool__(self):
return False
def __bool__(self):
- True
+
return
True
def __pos__(self):
return self
def __pos__(self):
return self
@@
-271,7
+271,7
@@
class Expression:
self.constant == other.constant
def __hash__(self):
self.constant == other.constant
def __hash__(self):
- return hash((
self._coefficients
, self._constant))
+ return hash((
tuple(sorted(self._coefficients.items()))
, self._constant))
def _toint(self):
lcm = functools.reduce(lambda a, b: a*b // gcd(a, b),
def _toint(self):
lcm = functools.reduce(lambda a, b: a*b // gcd(a, b),
@@
-355,7
+355,7
@@
class Symbol(Expression):
def symbols(names):
if isinstance(names, str):
names = names.replace(',', ' ').split()
def symbols(names):
if isinstance(names, str):
names = names.replace(',', ' ').split()
- return (
s
ymbol(name) for name in names)
+ return (
S
ymbol(name) for name in names)
@_polymorphic_operator
@_polymorphic_operator