Go a step back after a bad manipulation

119 views
Skip to first unread message

Mario Lemelin

unread,
Dec 4, 2023, 12:24:51 PM12/4/23
to sympy
Hello,
This is my first time. Just wondering if there is a command that I can do when, in a jupyter notebook, when I want to go back one step (If I did a bad algebraic manipulation for example). Thank you in advance for your help. Mario

gu...@uwosh.edu

unread,
Dec 4, 2023, 1:19:30 PM12/4/23
to sympy
If you are having sympy do the math for you using `solve`, `factor`, `simplify` and things like that it is often difficult. One option is to restart your notebook kernel and run all the steps except for the one you made a mistake at.

If you are doing algebraic steps by hand, you can just reverse the the last step. If you are doing this you may also want to look at algebra_with_sympy, which has some convenience features for doing step-by-step algebra. Full disclosure: I am the primary contributor to algebra_with_sympy.

Mario Lemelin

unread,
Dec 5, 2023, 1:18:19 PM12/5/23
to sympy
Thank you very much for the information and the link to the website.

Aaron Meurer

unread,
Dec 6, 2023, 4:09:16 PM12/6/23
to sy...@googlegroups.com
It really depends on how you structure your code. SymPy expressions
are immutable, so if you just assign each step to a different
variable, you can easily refer back to previous variables.

You should also be careful with Jupyter notebooks that if you delete
cells, or insert cells before other cells, you may end up with a
notebook that doesn't actually execute again if you open it again
later, because when you start a notebook from scratch the cells are
always executed from top to bottom, which may not be the original
execution order. It can sometimes be a good idea to "restart and run
all" in your notebook to reset the state and ensure everything runs
again.

Aaron Meurer

On Mon, Dec 4, 2023 at 10:24 AM Mario Lemelin <math0...@gmail.com> wrote:
>
> Hello,
> This is my first time. Just wondering if there is a command that I can do when, in a jupyter notebook, when I want to go back one step (If I did a bad algebraic manipulation for example). Thank you in advance for your help. Mario
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/82c3aedb-215b-4083-a462-42bbc5684632n%40googlegroups.com.

gu...@uwosh.edu

unread,
Dec 6, 2023, 5:20:16 PM12/6/23
to sympy
Aaron's comments are really important. These are pitfalls that can easily lead to inconsistent outcomes and notebooks that do not work.

Sangyub Lee

unread,
Dec 7, 2023, 9:49:36 AM12/7/23
to sympy
Jupyter notebook is already a good framework to write code like literature,
and unfortunately, I don't think that we need a different tooling from SymPy to do that.

I just advice to make multiple cells, structure your notebooks well,
and print the intermediate results of your computation often in your cell
(use print or display)

I don't think that it is easy for any computer algebra, or related tools to support 'step-back' functionality.
I haven't seen that in other competitors, like Mathematica, too.
The problem can be generalized to time-travel debugging (Time travel debugging - Wikipedia), 
and it is an area of research, if it matters how to do it correctly, or efficiently.

Mario Lemelin

unread,
Dec 7, 2023, 12:16:56 PM12/7/23
to sympy
If I had one functionality to have in Sympy, it would be the possibility to get access to a list of symbols that I am using in my notebook. A function called, let's say LstSymbols(), which give the name of the symbols that are in use in the notebook in addition to their values . This way, I can see if, by manipulations, I change some values of the symbols. Or maybe that function already exists? That would be a good thing to have when you are trying to get back some steps. Just as suggestion!

Aaron Meurer

unread,
Dec 7, 2023, 5:00:57 PM12/7/23
to sy...@googlegroups.com
This is more a question of the notebook frontend, not SymPy (SymPy is
just doing the symbolic math). The debugger in Jupyter might offer
what you are looking for. Or there might be other notebook extensions
that do it.I don't personally use the notebook very often so I don't
have any specific solutions for you.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/b8bf74c3-511c-49d6-b5e4-cd8ee5681e6en%40googlegroups.com.

Oscar Benjamin

unread,
Dec 7, 2023, 5:20:52 PM12/7/23
to sy...@googlegroups.com
I think what you mean here is more like "variables" rather than
"symbols". You might want to try using Spyder which can show you the
values of all of the Python variables you have defined.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/b8bf74c3-511c-49d6-b5e4-cd8ee5681e6en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages