Opened 3 years ago

# Step by step integration for educational use

Reported by: Owned by: mmarco major sage-9.7 symbolics integration, education, sd110 nthiery, kcrisman, slelievre Miguel Marco N/A u/mmarco/manualintegrate ff07f9ad8e3ae9f668cfd99ac75026a913915f23

This branch implements a system to compute symbolic integrals step by step, trying to follow the rules that are taught to students to compute integrals by hand.

To compute the appropriate rules, it uses the sympy module `manualintegrate`.

It is exposed to the user through a `ManualIntegral` class, that can either be iterated to get hints on steps to follow:

```sage: from sage.symbolic.integration.manual import ManualIntegral
sage: M = ManualIntegral(exp(x)*sin(x), x)
sage: M.hint()
(u == sin(x),
dv == e^x,
du == cos(x),
v == integrate(e^x, x),
integrate(e^x*sin(x), x) == v*sin(x) - integrate(v*cos(x), x))
sage: M.hint()
(integrate(e^x, x) == e^x,)
sage: M.hint()
(u == cos(x),
dv == e^x,
du == -sin(x),
v == integrate(e^x, x),
integrate(cos(x)*e^x, x) == v*cos(x) - integrate(-v*sin(x), x))
sage: M.hint()
(integrate(e^x, x) == e^x,)
sage: M.hint()
(integrate(e^x*sin(x), x) == -cos(x)*e^x + e^x*sin(x) - integrate(e^x*sin(x), x),
2*integrate(e^x*sin(x), x) == -cos(x)*e^x + e^x*sin(x))
```

Also, all hints can be listed at once:

```sage: M.all_hints()
[(u == sin(x),
dv == e^x,
du == cos(x),
v == integrate(e^x, x),
integrate(e^x*sin(x), x) == v*sin(x) - integrate(v*cos(x), x)),
(integrate(e^x, x) == e^x,),
(u == cos(x),
dv == e^x,
du == -sin(x),
v == integrate(e^x, x),
integrate(cos(x)*e^x, x) == v*cos(x) - integrate(-v*sin(x), x)),
(integrate(e^x, x) == e^x,),
(integrate(e^x*sin(x), x) == -cos(x)*e^x + e^x*sin(x) - integrate(e^x*sin(x), x),
2*integrate(e^x*sin(x), x) == -cos(x)*e^x + e^x*sin(x))]
```

### comment:1 Changed 3 years ago by mmarco

• Branch set to u/mmarco/manualintegrate

### comment:2 Changed 3 years ago by mmarco

• Authors set to Miguel Marco
• Commit set to 9824f80aee60f09d2e6faeaf30b3a7640c77107a
• Component changed from PLEASE CHANGE to symbolics
• Description modified (diff)
• Type changed from PLEASE CHANGE to enhancement

The user interface is maybe not very natural, but I couldn't figure out anything that was clearly better (right now the hints are just tuples of symbolic equations, I considered creating specific classes for this, but I am not sure it is a better solution).

Also, I am also not sure if the ManualIntegral? class should be imported by default (the name space is already bloated, but mostly, I am not sure if this is the kind of thing that you want to offer by default to students, or if it is preferable to offer it as some kind of 'optional' feature).

I would appreciate any comments obout these questions.

New commits:

 ​6cd0e60 `First implementation` ​9824f80 `Complete docstrings and tests.`

### comment:4 Changed 3 years ago by mmarco

• Status changed from new to needs_review

### comment:5 Changed 2 years ago by embray

• Milestone changed from sage-8.9 to sage-9.1

Ticket retargeted after milestone closed

### comment:6 Changed 2 years ago by gh-Shlokatadistance

I dont think this should be a default, because after all Sagemath should be like an aid to your calculations, and I dont think that giving the steps right away would help anyone learn. Moreover I think the modifications which can be made to this, of course at the higher levels can be stages of the steps, meaning that different stages reveal different levels of step, which eases the burden of understanding the exact calculation.

Moreover, I think instead of explicit details being given, we can reveal the steps to be of the format

1. integrate sinx
2. take the solution and judge its value in different equations

3 ....

### comment:7 Changed 2 years ago by mkoeppe

• Milestone changed from sage-9.1 to sage-9.2

Batch modifying tickets that will likely not be ready for 9.1, based on a review of the ticket title, branch/review status, and last modification date.

### comment:8 Changed 21 months ago by mkoeppe

• Milestone changed from sage-9.2 to sage-9.3

### comment:9 Changed 21 months ago by git

• Commit changed from 9824f80aee60f09d2e6faeaf30b3a7640c77107a to 1e6240e6fed4226b8de4b369715060298830ae58

Branch pushed to git repo; I updated commit sha1. New commits:

 ​b47560b `First implementation` ​6109a3b `Complete docstrings and tests.` ​d4dbb8a `Improve ascii_art` ​38cbffb `Fix indentation error` ​1e6240e `Merge branch 'u/mmarco/manualintegrate' of git://trac.sagemath.org/sage into t/28415/manualintegrate`

### comment:11 Changed 19 months ago by slelievre

• Cc kcrisman slelievre added; crisman removed

### comment:13 Changed 19 months ago by gh-rocky

Hi - I was able to watch your your demo in full at https://bbb.imo.universite-paris-saclay.fr/playback/presentation/2.0/playback.html?meetingId=13f0752852b2cf7dc1e08f807f73590c9a3f650d-1604079987388

and have some thoughts that I don't recall othes expressed. The simplest and to me most immediate reaction after looking at the list of namedtuple output from `sympy.integrals.manualintegrate` is to just give the names of the steps,

• integration by parts,
• variable substitution,
• integration under the integral (or Leibniz integration which was a favorite of R. Feynman).

As for your the question of how much to show, that might be handled by some sort of expanded or colapsed view or expanded view that typically exists for (HTML) lists.

But overall it feels like doing this is going to be a lot of work, and it is not clear to me which side this should go on. Probably a bit on the sympy side if it is not there.

Let me give some examples. I see that some of the namedtuples are

• Reciprocal Rule
• Urule
• Piecewise Rule
• Arccoth Rule

and so on. Somewhere there should be a way to get longer verbose descriptions of exactly what there rules mean. Just providing URL link to where the information could be found would be sufficient. Does such a thing currently exist?

As you point out, based on what the rule is there might be further operations or "hints" as you put it that might guide a student. I think the example you gave was substituion by parts and using the system's ability to do factorization to figure out all of the parts which could be tried. Factorization makes sense for only some rules, not all of them. And for other rules other kinds of things to focus on make sense.

So if you want to go down the route of providing only a first step hint and making the student explore from there, it seems like you'd need a mapping from namedtuple name to the kinds of ways to provide hints. And probably this should be done in sympy rather than sage.

### comment:14 Changed 18 months ago by git

• Commit changed from 1e6240e6fed4226b8de4b369715060298830ae58 to ff07f9ad8e3ae9f668cfd99ac75026a913915f23

Branch pushed to git repo; I updated commit sha1. New commits:

 ​33e2667 `First implementation` ​b3f0851 `Complete docstrings and tests.` ​4970411 `Improve ascii_art` ​59dad2b `Fix indentation error` ​d96784e `Make python3 style iterable` ​ff07f9a `Merge branch 'u/mmarco/manualintegrate' of git://trac.sagemath.org/sage into t/28415/manualintegrate`

### comment:15 Changed 14 months ago by mkoeppe

• Milestone changed from sage-9.3 to sage-9.4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

### comment:16 Changed 10 months ago by mkoeppe

• Milestone changed from sage-9.4 to sage-9.5

Setting a new milestone for this ticket based on a cursory review.

### comment:17 Changed 5 months ago by mkoeppe

• Milestone changed from sage-9.5 to sage-9.6

Stalled in `needs_review` or `needs_info`; likely won't make it into Sage 9.5.

### comment:18 Changed 7 weeks ago by mkoeppe

• Milestone changed from sage-9.6 to sage-9.7
Note: See TracTickets for help on using tickets.