Skip to content

Commit

Permalink
Merge pull request #26723 from haru-44/if_bool
Browse files Browse the repository at this point in the history
Fix if statement returning bool
  • Loading branch information
smichr committed Jun 18, 2024
2 parents 7fc4652 + 2535502 commit 023378b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 67 deletions.
5 changes: 1 addition & 4 deletions sympy/combinatorics/free_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,7 @@ def copy(self):

@property
def is_identity(self):
if self.array_form == ():
return True
else:
return False
return not self.array_form

@property
def array_form(self):
Expand Down
10 changes: 3 additions & 7 deletions sympy/combinatorics/perm_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1916,16 +1916,12 @@ def _eval_is_alt_sym_naive(self, only_sym=False, only_alt=False):
if order == sym_order:
self._is_sym = True
self._is_alt = False
if only_alt:
return False
return True
return not only_alt

elif 2*order == sym_order:
if 2*order == sym_order:
self._is_sym = False
self._is_alt = True
if only_sym:
return False
return True
return not only_sym

return False

Expand Down
13 changes: 3 additions & 10 deletions sympy/geometry/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,11 @@ def is_parallel(self, l):
if isinstance(l, LinearEntity3D):
a = l.direction_ratio
b = self.normal_vector
c = sum(i*j for i, j in zip(a, b))
if c == 0:
return True
else:
return False
elif isinstance(l, Plane):
return sum(i*j for i, j in zip(a, b)) == 0
if isinstance(l, Plane):
a = Matrix(l.normal_vector)
b = Matrix(self.normal_vector)
if a.cross(b).is_zero_matrix:
return True
else:
return False
return bool(a.cross(b).is_zero_matrix)


def is_perpendicular(self, l):
Expand Down
16 changes: 4 additions & 12 deletions sympy/holonomic/recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,8 @@ def __repr__(self):
__str__ = __repr__

def __eq__(self, other):
if self.recurrence == other.recurrence:
if self.n == other.n:
if self._have_init_cond and other._have_init_cond:
if self.u0 == other.u0:
return True
else:
return False
else:
return True
else:
return False
else:
if self.recurrence != other.recurrence or self.n != other.n:
return False
if self._have_init_cond and other._have_init_cond:
return self.u0 == other.u0
return True
31 changes: 10 additions & 21 deletions sympy/solvers/ode/nonhomogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ def _undetermined_coefficients_match(expr, x, func=None, eq_homogeneous=S.Zero):
expr = powsimp(expr, combine='exp') # exp(x)*exp(2*x + 1) => exp(3*x + 1)
retdict = {}

def _test_term(expr, x):
def _test_term(expr, x) -> bool:
r"""
Test if ``expr`` fits the proper form for undetermined coefficients.
"""
if not expr.has(x):
return True
elif expr.is_Add:
if expr.is_Add:
return all(_test_term(i, x) for i in expr.args)
elif expr.is_Mul:
if expr.is_Mul:
if expr.has(sin, cos):
foundtrig = False
# Make sure that there is only one trig function in the args.
Expand All @@ -336,26 +336,15 @@ def _test_term(expr, x):
else:
foundtrig = True
return all(_test_term(i, x) for i in expr.args)
elif expr.is_Function:
if expr.func in (sin, cos, exp, sinh, cosh):
if expr.args[0].match(a*x + b):
return True
else:
return False
else:
return False
elif expr.is_Pow and expr.base.is_Symbol and expr.exp.is_Integer and \
if expr.is_Function:
return expr.func in (sin, cos, exp, sinh, cosh) and \
bool(expr.args[0].match(a*x + b))
if expr.is_Pow and expr.base.is_Symbol and expr.exp.is_Integer and \
expr.exp >= 0:
return True
elif expr.is_Pow and expr.base.is_number:
if expr.exp.match(a*x + b):
return True
else:
return False
elif expr.is_Symbol or expr.is_number:
return True
else:
return False
if expr.is_Pow and expr.base.is_number:
return bool(expr.exp.match(a*x + b))
return expr.is_Symbol or bool(expr.is_number)

def _get_trial_set(expr, x, exprs=set()):
r"""
Expand Down
9 changes: 3 additions & 6 deletions sympy/solvers/ode/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,7 @@ def _verify(self, fx):
# m1[coeff]*m1[x]*m1[y] + m2[coeff]*m2[x]*m2[y]*y'
self.m1 = separatevars(d, dict=True, symbols=(x, self.y))
self.m2 = separatevars(e, dict=True, symbols=(x, self.y))
if self.m1 and self.m2:
return True
return False
return bool(self.m1 and self.m2)

def _get_match_object(self):
fx = self.ode_problem.func
Expand Down Expand Up @@ -1730,9 +1728,8 @@ class HomogeneousCoeffBest(HomogeneousCoeffSubsIndepDivDep, HomogeneousCoeffSubs
order = [1]

def _verify(self, fx):
if HomogeneousCoeffSubsIndepDivDep._verify(self, fx) and HomogeneousCoeffSubsDepDivIndep._verify(self, fx):
return True
return False
return HomogeneousCoeffSubsIndepDivDep._verify(self, fx) and \
HomogeneousCoeffSubsDepDivIndep._verify(self, fx)

def _get_general_solution(self, *, simplify_flag: bool = True):
# There are two substitutions that solve the equation, u1=y/x and u2=x/y
Expand Down
9 changes: 2 additions & 7 deletions sympy/solvers/simplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,13 +1128,8 @@ def show_linprog(c, A=None, b=None, A_eq=None, b_eq=None, bounds=None):
x = Matrix(symbols('x1:%s' % (A.cols+1)))
f,c = (C*x)[0], [i<=j for i,j in zip(A*x, b)] + [Eq(i,j) for i,j in zip(A_eq*x,b_eq)]
for i, (lo, hi) in enumerate(bounds):
if lo is None and hi is None:
continue
if lo is None:
c.append(x[i]<=hi)
elif hi is None:
c.append(x[i]>=lo)
else:
if lo is not None:
c.append(x[i]>=lo)
if hi is not None:
c.append(x[i]<=hi)
return f,c

0 comments on commit 023378b

Please sign in to comment.