I have a large number of variables/functions with subscripts and use definitions with memoization to avoid recomputing them within a kernel session, but I cannot figure out how to export them all for long-term storage. (Ideally human-readable and in a way that also works when running the code from the command line without the Notebook interface).
I have symbolized the subscripted variables so I can use functions that only operate on symbols (in particular Save, Clear). Below is a minimum working example.
Creating and saving the variables as symbols works fine:
Get["Notation`"]
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]
a⎵Subscript⎵1 = 2
a⎵Subscript⎵test = 3
Names[StringJoin[$Context, "*"]]
Information[a⎵Subscript⎵1, LongForm -> False]
Information[a⎵Subscript⎵test, LongForm -> False]
Information["a⎵Subscript⎵1",
LongForm -> False]
Information["a⎵Subscript⎵test",
LongForm -> False]
Save[ NotebookDirectory[] <> "test_symbolize_save.m", "`*"]
But when I open a new notebook and load the saved file it loads neither the original variables with subscript (only the internal representation) nor the associated values (even though they are contained in the exported file):
Get["Notation`"]
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]
Get[StringJoin[NotebookDirectory[], "test_symbolize_save.m"]];
Names[StringJoin[$Context, "*"]]
Information[2, LongForm -> False]
Information[3, LongForm -> False]
Information["a⎵Subscript⎵1", LongForm -> False]
Information["a⎵Subscript⎵test", LongForm -> False]
I entered the subscript via "Ctrl+_" for the first ? calls before exporting and after importing. The RawInputForm of those calls after importing probably points to the underlying issue, as the intended reference to the subscripted variable points to its stored value instead.
Content of the file exported with Save:
a⎵Subscript⎵1 = 2
a⎵Subscript⎵test = 3
(I also tried DumpSave, and while that saved the variable/function name, it did not save the subscripts and associated values.)
My question: How can I easily and consistently create, export, and import variables/functions with subscripts, so the definitions and computed values are fully restored after import?
I don't have to use symbolize (in fact i never did before), but when I tried Save without symbolizing it did not actually export my variables/functions with subscripts.
Notation
and just stick to one dimensional symbols. There are so fewer headaches... $\endgroup$Notation
rules weren't saved viaSave
. How you get that to work I'm not entirely sure, but try exporting theOwnValues
,DownValues
, andFormatValues
explicitly. That will work at minimum. $\endgroup$