kpeeters / cadabra2

A field-theory motivated approach to computer algebra.
https://cadabra.science/
GNU General Public License v3.0
215 stars 37 forks source link

missing collect_terms when using notebook import #170

Closed leo-brewin closed 4 years ago

leo-brewin commented 4 years ago

Hi Kasper, I'm bumped into a small problem with importing Cadabra notebooks. I'm running this notebook

from shared import *

{a,b,c,d}::Indices.

foo := g^{a b}.
bah := g^{a b}.

diff = check (foo,bah)
print (diff)

which imports the shared notebook containing

{a,b,c,d}::Indices.

def check (foo,bah):
    tmp := @(foo) - @(bah).
    return tmp

The output should be zero but is in fact

g^{a b}-g^{a b}

It seems that a call to collect_terms hasn't been applied (which is normally part of the post_process function). I can fix this in a number of ways

  1. Add an explicit call to collect_terms in the function check.
  2. Add a copy of the post_process function to the shared notebook.
  3. Include from cadabra2_defaults import * in the shared notebook.

I prefer the last choice. But I suppose my question is -- Is this the expected behaviour? Should it not 'just work' without this change?

kpeeters commented 4 years ago

Well spotted! I have just pushed a fix to github which effectively does 3, but automatically. To trigger this with your already existing 'shared' notebook, make a small change and save it, so that the import functionality re-generates the python code from the notebook.

leo-brewin commented 4 years ago

Thanks Kasper for the quick fix.