File: archive1.cpp

package info (click to toggle)
ginac 1.8.9-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 6,640 kB
  • sloc: cpp: 49,195; sh: 5,402; makefile: 448; python: 193
file content (51 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 *  Archiving code example from the tutorial
 */

#include <fstream>

#ifdef IN_GINAC
#include "ginac.h"
#else
#include <ginac/ginac.h>
#endif
using namespace std;
using namespace GiNaC;

int main()
{
	symbol x("x"), y("y"), z("z");

	// do some math
	
	ex foo = sin(x + 2*y) + 3*z + 41;
	ex bar = foo + 1;

	// write the archive
	
	archive a;
	a.archive_ex(foo, "foo");
	a.archive_ex(bar, "the second one");

	ofstream out("foobar.gar");
	out << a;
	out.close();

	// read in the archive
	
	archive a2;
	ifstream in("foobar.gar");
	in >> a2;

	lst syms = {x, y};

	ex ex1 = a2.unarchive_ex(syms, "foo");
	ex ex2 = a2.unarchive_ex(syms, "the second one");

	// do some math again
	
	cout << ex1 << endl;              // prints "41+sin(x+2*y)+3*z"
	cout << ex2 << endl;              // prints "42+sin(x+2*y)+3*z"
	cout << ex1.subs(x == 2) << endl; // prints "41+sin(2+2*y)+3*z"
}