C++ code generation: any way of deflating large expressions?
Dr. Vassilis S. Vassiliadis
vsv20 at cheng.cam.ac.uk
Thu Jul 10 11:51:29 CEST 2003
I wonder if someone has run into the following and has
found a easy way out:
In generating C-source code from symbolic expressions it
is always possible to run into trouble with large size expression
output.
For example, if one stores in an ex variable something like:
ex SUM;
`` SUM = \sum_{i=1}^{10000} x[i] ; ''
then printing this out as csrc will generate a huge line.
The best way is to see if there is an easy algorithmic construct
(perhaps within GiNaC, or hints provided for its efficient implementation)
so that at each level of the tree all operation-containing nodes are
assigned a dummy variable (e.g. those of arithmetic operations or
implementing a function).
Then upon exhaustion, to reverse the procedure
from the leaves of the tree to the root and thus generate a C++ code
fragment with all necessary steps & intermediate variables
to finally get the value of the root.
-----------------------------------------------------------------
Dr. Vassilis S. Vassiliadis,
Lecturer,
UNIVERSITY OF CAMBRIDGE,
DEPARTMENT OF CHEMICAL ENGINEERING
Pembroke Street,
Cambridge CB2 3RA, UK.
Tel: (reception): +44 1223 334777
Fax: (departmental): +44 1223 334796
e-mail: vsv20 at cheng.cam.ac.uk
-----------------------------------------------------------------
More information about the GiNaC-list
mailing list