Last active
December 24, 2015 12:19
-
-
Save OpenGamma-Blog/6796900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expression expr = sin(mul(sq('x'), sq('y'))); | |
Vector1D g_expr = vector(expr, d(expr, 'x'), d(expr, 'x')); | |
System.out.println(g_expr.describe()); | |
Expression: | |
[(sin (* (sq x) (sq y))) | |
(d (sin (* (sq x) (sq y))) x) | |
(d (sin (* (sq x) (sq y))) x)] | |
gets turned into: | |
(vector | |
(sin (* (sq x) (sq y))) | |
(* (cos (* (sq x) (sq y))) (* (* 2 x) (sq y))) | |
(* (cos (* (sq x) (sq y))) (* (* 2 x) (sq y)))) | |
and into: | |
final double G__1343 = y; // y | |
final double G__1342 = sq( G__1343 ); // (sq y) | |
final double G__1341 = x; // x | |
final double G__1340 = 2; // 2 | |
final double G__1339 = G__1340 * G__1341; // (* 2 x) | |
final double G__1338 = G__1339 * G__1342; // (* (* 2 x) (sq y)) | |
final double G__1334 = sq( G__1341 ); // (sq x) | |
final double G__1333 = G__1334 * G__1342; // (mul (sq x) (sq y)) | |
final double G__1332 = cos( G__1333 ); // (cos (mul (sq x) (sq y))) | |
final double G__1331 = G__1332 * G__1338; // (* (cos (mul (sq x) (sq y))) (* (* 2 x) (sq y))) | |
final double G__1312 = sin( G__1333 ); // (sin (mul (sq x) (sq y))) | |
final double G__1311 = [ G__1312, G__1331, G__1331 ]; // (vector (sin (mul (sq x) (sq y))) (* (cos (mul (sq x) (sq y))) (* (* 2 x) (sq y))) (* (cos (mul (sq x) (sq y))) (* (* 2 x) (sq y)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment