How to serialize?

Jun 24, 2014 at 10:41 AM
Edited Jun 24, 2014 at 10:56 AM

I am trying to serialize this function:
 var func = TermBuilder.Power(2 * -x, TermBuilder.Exp(-x * -2)) * TermBuilder.Exp(-x * y * (-2)) - x * y * y * (-y);
with this code:
            // serialize the func
            IFormatter formatter = new BinaryFormatter();
            Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
            formatter.Serialize(stream, func);

            func = null;

            // deserialize the func
            stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
            func = (Term)formatter.Deserialize(stream);

and i can not because TermPower is not Serializable.
After adding the Serializable attribute it serializes and deserializes, but the rest of execution fails at compilation.

Is there anything i am doing wrong?

P.S. My serialization/deserialoization code is from here:

Jun 30, 2014 at 11:43 AM
Well, this is obviously a bug.
You can download the library's source code, fix it and build it.

I will fix it in a later release, when I make more time to develop the library. If you wish to do it, please say so. I will give you permissions to develop.
Jun 30, 2014 at 11:49 AM
I have figured that out.

The problem actually is that the Variables created after deserialization are not the ones that were used when the term was created.

eg.: if X is the variable before the serialization, then Variable deserialized_X != X.

If i remember correctly, this happens during compilation of the term, when a dict is used. I can't remember the exact piece of code right now.