Session Saving

While solving a homework problem, an idea came to me for a feature which would be awesome in almost any interactive environment: A function to record the entire session, using analysis of reaching definitions to keep only commands which entered into the final result.

Here's my entire irb session, including mistakes and just plain weird instructions entered because I wasn't giving what I was doing my full attention:

i3-dhcp-172-16-55-156:~ $ irb
>> 5.11e5/1
=> 511000.0
>> me = 5.1e5
=> 510000.0
>> mx = 1e11
=> 100000000000.0
>> T = 1e9
=> 1000000000.0
>> me/(1-(mx/((mx+me)*sqrt(1-(1/((1+(T/mx))**2))))))
NoMethodError: undefined method `sqrt' for main:Object
    from (irb):5
>> me/(1-(mx/((mx+me)*Math.sqrt(1-(1/((1+(T/mx))**2))))))
=> -83279.5229499069
>> g = 1+T/mx
=> 1.01
>> b = 1/Math.sqrt(1-(1/(g**2)))
=> 7.12399072017183
>> bc = (b*mx)/(mx+me)
=> 7.12395438800445
>> gc = 1/Math.sqrt(1-bc**2)
Errno::EDOM: Numerical argument out of domain - sqrt
    from (irb):10:in `sqrt'
    from (irb):10
>> b = Math.sqrt(1-(1/(g**2)))
=> 0.14037076117582
>> bc = (b*mx)/(mx+me)
=> 0.140370045288589
>> gc = 1/Math.sqrt(1-bc**2)
=> 1.00999989646571
>> 
?> 
?> 
?> 
?> 0
=> 0
>> Ef = me/(1-((mx*Math.sqrt(1-(1/((1+(T/mx))**2))))/(me+mx)))
=> 593278.534798399
>> dE = Ef - me
=> 83278.5347983992
>> #maximum energy transfer in X+e -> X+e
?> 

It would be really awesome to be able to automatically condense this down to only the commands which turned out to be actually relevant, like this:

me = 5.1e5
mx = 1e11
T = 1e9
g = 1+T/mx
b = Math.sqrt(1-(1/(g**2)))
bc = (b*mx)/(mx+me)
gc = 1/Math.sqrt(1-bc**2)
Ef = me/(1-((mx*Math.sqrt(1-(1/((1+(T/mx))**2))))/(me+mx)))
dE = Ef - me

1

Then, the result could be saved for reuse or editing later, which would make it really convenient to revisit calculations that you did earlier, without having to redo them entirely or retype them from your written computations. As mentioned at the start, this would be nice in lots of places besides irb; wxMaxima will save sessions, but it does so by literally recording every command issued2, whether or not they were superseded later. It would be really cool to re-open a session and have all of the old commands that were actually useful without the ones where I made syntax errors or just computed something irrelevant to the problem under consideration, and having realized this, deliberately overwrote that result.


  1. I preserved here several lines (the definitions of g, b, bc, and gc) that I didn't actually care about in this case, but which an automatic analysis would assumedly preserve, as they introduced variables which were still in scope at the end. 

  2. And on such a saved session being re-opened; simply re-issuing and re-executing all of the saved commands. In wxMaxima's case I can see why it would be a good deal of work to do anything more intelligent, since the GUI that knows about the saved session and the actual algebra system in which the state needs to be restored are separate processes; nonetheless it would be really nice to avoid dumb stuff like recomputing the results of expensive operations. 

No Comments

Comment on this post