Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to intsteps.py #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 30 additions & 2 deletions app/logic/intsteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
_manualintegrate, integral_steps, evaluates,
ConstantRule, ConstantTimesRule, PowerRule, AddRule, URule,
PartsRule, CyclicPartsRule, TrigRule, ExpRule, ReciprocalRule, ArctanRule,
AlternativeRule, DontKnowRule, RewriteRule
AlternativeRule, DontKnowRule, RewriteRule, PiecewiseRule
)

# Need this to break loops
Expand Down Expand Up @@ -81,6 +81,8 @@ def print_rule(self, rule):
self.print_DontKnow(rule)
elif isinstance(rule, RewriteRule):
self.print_Rewrite(rule)
elif isinstance(rule, PiecewiseRule):
self.print_Piecewise(rule)
else:
self.append(repr(rule))

Expand Down Expand Up @@ -145,7 +147,21 @@ def print_U(self, rule):
sympy.Integral(integrand, u)))

with self.new_level():
self.print_rule(replace_u_var(rule.substep, rule.symbol.name, u))

if isinstance(rule.substep, PiecewiseRule):
substep = None
cond = False
for s, c in rule.substep.subfunctions:
if c:
if cond and c:
raise ValueError("Multiple conditions in piecewise rule is not handled yet.")
substep = s
cond = True

self.print_rule(replace_u_var(substep, rule.symbol.name, u))

else:
self.print_rule(replace_u_var(rule.substep, rule.symbol.name, u))

self.append("Now substitute {} back in:".format(
self.format_math(u)))
Expand Down Expand Up @@ -282,6 +298,18 @@ def print_DontKnow(self, rule):
self.append("But the integral is")
self.append(self.format_math_display(sympy.integrate(rule.context, rule.symbol)))

def print_Piecewise(self, rule):

substep = None
cond = False
for s, c in rule.subfunctions:
if c:
if cond and c:
raise ValueError("Multiple conditions in piecewise rule is not handled yet.")
substep = s
cond = True

self.print_rule(substep)

class HTMLPrinter(IntegralPrinter, stepprinter.HTMLPrinter):
def __init__(self, rule):
Expand Down