From: Jens Vollinga Date: Tue, 6 Dec 2005 14:41:13 +0000 (+0000) Subject: New directory for GiNaC examples. X-Git-Tag: release_1-4-0~127 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=8f9f05a96e217067831e4255f0db398305b0130c;ds=sidebyside New directory for GiNaC examples. --- diff --git a/configure.ac b/configure.ac index 1ca64109..7005c946 100644 --- a/configure.ac +++ b/configure.ac @@ -155,6 +155,7 @@ ginsh/ginsh.1 tools/Makefile tools/viewgar.1 doc/Makefile +doc/examples/Makefile doc/tutorial/Makefile doc/reference/Makefile doc/reference/DoxyfileHTML diff --git a/doc/Makefile.am b/doc/Makefile.am index e5de20e3..e6b93210 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,2 +1,2 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = tutorial reference +SUBDIRS = tutorial reference examples diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am new file mode 100644 index 00000000..c88a8212 --- /dev/null +++ b/doc/examples/Makefile.am @@ -0,0 +1,13 @@ +## Process this file with automake to produce Makefile.in + +EXFILES = archive1.cpp + +TEXINFO_TEX = ../tutorial/texinfo.tex + +info_TEXINFOS = ginac-examples.texi + +all: $(EXFILES) + ${MAKEINFO} --no-split --no-headers $(srcdir)/ginac-examples.texi > ginac-examples.txt + ${MAKEINFO} --no-split --html $(srcdir)/ginac-examples.texi + +EXTRA_DIST = $(EXFILES) diff --git a/doc/examples/archive1.cpp b/doc/examples/archive1.cpp new file mode 100644 index 00000000..c20db620 --- /dev/null +++ b/doc/examples/archive1.cpp @@ -0,0 +1,47 @@ +/* + * Archiving code example from the tutorial + */ + +#include +using namespace std; +#include +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; + 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" +} + diff --git a/doc/examples/ginac-examples.texi b/doc/examples/ginac-examples.texi new file mode 100644 index 00000000..200c81e7 --- /dev/null +++ b/doc/examples/ginac-examples.texi @@ -0,0 +1,33 @@ +\input texinfo @c -*-texinfo-*- +@c %**start of header +@setfilename ginac-examples.info +@settitle GiNaC Examples +@afourpaper +@c For `info' only. +@paragraphindent 0 +@c For TeX only. +@iftex +@c I hate putting "@noindent" in front of every paragraph. +@parindent=0pt +@end iftex +@c %**end of header +@ifnottex +@node Top +@end ifnottex + +@finalout +@c finalout prevents ugly black rectangles on overfull hbox lines + +@majorheading GiNaC Examples + +This is a collection of code examples using GiNaC. + +@contents + +@chapter Input / Output + +@section Archiving expressions @uref{archive1.cpp, (source)} + +Two expression are stored in an archive on the disk and are restored again. + +@bye