Debian Codegraph @

src/examples/compiler/README

raw
1 This is a demo of compiling a very high-level, Latex-like langauge
2 into C++/MADNESS. The objectives are
3
4 - lower the entry barrier for doing practical calculations with
5 MADNESS, even to the point of being useful in the classroom.
6
7 - automate mapping basic math constructs into C++ to facilitate
8 understanding of how to compose MADNESS applications in C++.
9
10 The compiler is a quick and dirty hack using flex and bison. It is
11 far from production quality, but most problems can be easily fixed
12 by looking at "mra.ll", "mra.yy", or "mra-driver.hh". It's
13 actually pretty simple.
14
15
16 To build:
17
18 - you will need a recent version of bison, flex, and g++
19
20 - type "make"
21
22 - you now have the executable "mra"
23
24
25 To run the compiler:
26
27 - "./mra inputfilename"
28
29 This produces output to the terminal and
30 three output files
31
32 * The terminal output informs you about errors
33 and type inferences.
34
35 * "prog.cc" holds the generated C++ file.
36
37 * "prog.tex" holds the generated Latex equation.
38
39 * "prog.tree" holds the syntax tree that is
40 useful for debugging the compiler
41
42 To view the latex:
43
44 - you will need the AMS tex and font packages installed
45
46 - "pdflatex eqn.tex" will generate eqn.pdf
47 ("eqn.tex" is just boiler plate that includes "prog.tex")
48
49
50 To compile and run the generated program:
51
52 - "make -f Makefile-prog prog"
53
54 - "./prog"
55
56
57 Examples
58
59 - hatom - calculates the energy of the hydrogen atom ground state
60
61 - hehf - solves the HF equations for the helium atom
62
63 - hehf2 - solves the HF equations for the helium atom
64
65 - hatompolar - solves for the polarizability of the hydrogen atom
66
67 - he2el - calculates the energy of the two-term Hylleraars
68 wavefunction for helium (this will require 40+ GB of memory)
69
70 - qa - a pathetic attempt at quality assurance testing
71
72
73 The language
74
75 - Variables can be either names of Greek letters (no backslash
76 needed) or the usual alpha-numeric string. Capilize the
77 first letter to get uppercase Greek.
78
79 - There are lots of reserved names, mostly math functions
80 and greek names - these are not actually checked for.
81
82 - For prettiest latex output use single character variable names
83
84 - Types are inferred, though if this breaks you can declare
85 the type.
86
87 - x is implicitly typed as a coordinate of the appropriate
88 dimension
89
90 - pi (lowercase) is the real value 3.141...
91
92 - the boolean values true and false are recognized
93
94 - subscripts become array references in the C++ (x_1 --> x[1])
95
96 - comments - characters from # to EOL are ignored
97
98 - Each program has to have this form
99
100 Let
101 domain specification
102 optional declarations and other definitions
103 In
104 program source
105 End
106
107 - The Let block provides global defintions and parameters for the
108 main body of the code -- they will become global defintions in
109 the C++ file.
110
111 * domain specification is
112
113 Omega = [lo,hi]^D
114
115 which specifies a cube in D dimensions. The values of lo and
116 hi are available as box_lo and box_hi in the C++, and D as D.
117
118 * k = integer value
119
120 specifies the order of the wavelet, default is 6
121
122 * epsilon = real value
123
124 specifies the truncation threshold, default is 1e-4
125
126 * You can define other global constants
127
128 * Type declarations of the form (not usually needed)
129
130 comma-separated-list in field
131
132 e.g.,
133
134 a, b in R
135
136 where field is one of R (real), C (Complex), Z (Integer) (still
137 need to add RT, CT, RF, CF, Rd for tensors, functions, and
138 d-dimension vector/coordinate).
139
140 * One-line function definitions
141
142 name = paramlist -> expression
143
144 Have a look at the examples for usage.
145
146 - The In block provides the executable statements that will appear
147 in your C++ main program.
148
149 * Arithmetic (+,-,*,/), comparison (<,>,>=,<=,==,!=), boolean
150 (and, or, not), subscript/array (x_i), and power (x^y)
151 operations should work as expected.
152
153 * for variable in [lo,hi]
154 statements
155 end
156
157 specifies iteration over an inclusive range that is assumed integer
158
159 * while exp
160 statements
161 end
162
163 * break jumps out of a loop
164
165 * if exp
166 statements
167 elif exp
168 statements
169 else
170 statements
171 end
172
173 * sum_var=lo^hi exp
174
175 computes the sum of exp with variable var varied over the
176 inclusive range [lo,hi]. Should nest correctly and work
177 inside expressions.
178
179 Presently assumes result is a number so cannot yet sum up a
180 function result ... to fix this need to modify the
181 initialization of the accumulation variable by peeling off the
182 first term.
183
184 * print comma-separated-expression-list
185
186 does the obvious thing
187
188 * plot function
189
190 plots the madness function to file "plot" using opendx format.
191 You can also use the form
192
193 plot function, filename
194
195 where file name is a string valued expression (e.g., "fred")
196
197 * vec(x) in 1D
198 * vec(x,y) in 2D
199 * etc.
200
201 converts Cartesian coordinates into a vector coordinate
202
203 * f(x) in 1D
204 * f(x,y) in 2D
205 * etc.
206
207 where f is a MADNESS function evaluates the function at a point
208
209
210 * function(r)
211
212 where f is a MADNESS function and r is a vector coordinate
213 evaluates the function at a point
214
215
216 * |x| is abs(x)
217
218 * ||x|| is norm(x)
219
220 * ||x||_F is normf(x)
221
222 * < f | g > is bra-ket notation for inner(f,g)
223
224 To get < f | Q | g > write <f | Q g>
225
226 * < f > is bra-ket notation for f.trace() = int(f(x),x in Omega)
227
228 * del_i is partial derivative in i'th direction
229 (i=0 is x, i=1 is y, etc.). E.g.,
230
231 dfdz = del_2 f
232
233 is the derivative in the z direction of the madness function f.
234
235 * del^2 applies the laplacian (is this working?)
236
237 * del^-2 applies the Coulomb GF
238
239 * (expression - del^2)^-1 applies the BSH with mu^2 = expression
240
241 The recognition of this pattern is very crude and it must be
242 typed in exactly the above ordering and form.
243
244 Application of the GFs truncates the input and the output
245 for efficiency.
246
247 * F is the operator that projects a C++ function into the
248 multiwavelet basis. E.g., if in the Let block you had
249
250 g = x -> exp(-sqrt(x_0^2 + x_1^2 + x_2^2))
251
252 Then in the In block you could have
253
254 f = F g
255
256 You can use the result of "F g" in expressions (since it
257 compiles to real_function(function_factory(g))).
258
259 Feel free to extend and fix.
260
261
262