Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Bugs
* ``N`` now handles arbitrary precision numbers when the number of digits is not specified.
* ``Set*``: fixed issue #128.
* ``SameQ``: comparison with MachinePrecision only needs to be exact within the last bit Issue #148.

* Fix a bug in `Simplify` that produced expressions of the form ``ConditionalExpression[_,{True}]``.

4.0.1
-----
Expand Down
14 changes: 9 additions & 5 deletions mathics/builtin/numbers/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ class Simplify(Builtin):
"Simplify[rule_Rule]": "Simplify /@ rule",
"Simplify[list_List, assum_]": "Simplify[#1, assum]& /@ list",
"Simplify[rule_Rule, assum_]": "Simplify[#1, assum]& /@ rule",
"Simplify[0^a_, assum_]": "ConditionalExpression[0,Simplify[a>0]]",
"Simplify[b_^a_, assum_]": "ConditionalExpression[b,Simplify[{Or[a>0, b!=0]}]]",
"Simplify[0^a_, assum_]": "ConditionalExpression[0,Simplify[a>0, assum]]",
"Simplify[b_^a_, assum_]": "ConditionalExpression[b^a,Simplify[Or[a>0, b!=0],assum]]",
}

def apply_assuming(self, expr, assumptions, evaluation):
Expand All @@ -435,19 +435,23 @@ def apply_assuming(self, expr, assumptions, evaluation):
def apply(self, expr, evaluation):
"%(name)s[expr_]"
# Check first if we are dealing with a logic expression...
if expr in (SymbolTrue, SymbolFalse, SymbolList):
return expr
expr = evaluate_predicate(expr, evaluation)
if expr.is_atom():
return expr
# else, use sympy:
elements = [self.apply(element, evaluation) for element in expr._elements]
head = self.apply(expr.get_head(), evaluation)
expr = Expression(head, *elements)

sympy_expr = expr.to_sympy()
# If the expression cannot be handled by Sympy, just return it.
if sympy_expr is None:
return
return expr
# Tries to apply the rules
sympy_result = sympy.simplify(sympy_expr)
return from_sympy(sympy_result)
result = from_sympy(sympy_result).evaluate(evaluation)
return result


class FullSimplify(Simplify):
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/numbers/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,6 @@ def apply(self, f, xs, evaluation, options):
if default.has_form("Integrate", None):
if default._elements[0] == f:
default = SymbolUndefined

simplified_cases = []
for case in cases:
# TODO: if something like 0^n or 1/expr appears,
Expand Down Expand Up @@ -742,6 +741,7 @@ def apply(self, f, xs, evaluation, options):
# Sympy returned the same expression, so it can't be evaluated.
return
result = Expression("Simplify", result, assuming)
result = result.evaluate(evaluation)
return result

def apply_D(self, func, domain, var, evaluation, options):
Expand Down
1 change: 1 addition & 0 deletions test/test_calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ def test_calculus():
"{x->1.51213}",
"Issue #1235",
),
("Integrate[Integrate[1,{y,0,E^x}],{x,0,Log[13]}]", "12", "Issue #153"),
):
check_evaluation(str_expr, str_expected, message)