[CppAD] constructing an AD function at runtime

Kipp Martin kipp.martin at chicagogsb.edu
Tue Sep 12 18:54:43 EDT 2006


Hi all,

In all the CppAd examples we could find, function expressions are 
hardcoded in the code (compile time).
Now suppose I want to implement a constructAD function as follows (sort 
of like the Poly function in the "getstarted.cpp" example)

Type constructAD(string[] infixTokens, int sizeOfInfixTokens){
	//an infixToken example of the function 2.1*x1^2) would be: {"2.1", 
"*", "x1", "^", "2") .
	//sizeOfInfixTokens in this example  =  5
	Type y;

	..... //need your help
	... //e.g. you can "logically" do something like: for(int i = 0; i < 
sizeOfInfixTokens; i++){ y+=infixTokens[i] ;}

	return y;
}

How should I do it. The infixTokens is an array of function tokens. Each 
token is a string symbol. Notice you really don't know what the string 
array looks like except that the tokens are in standard infix and each 
token is exactly the same as the corrsponding c++ operator.

As an alternative to passing string array, I can pass an array of 
AD<double> tokens (making it easy to implement the above function).
For example, I know how to create a number AD, which is as simple as 
AD<double> numberToken = 2.1
But how should I create a "+" AD? I don't think I can create it like
AD<double> plusToken = + //compile time error
or
AD<double> plusToken = "+" //operator = not ready to take a string?

All the hard-coded example always construct an AD with a term like 
AD<doulbe> plusTerm = 3 + numberToken;

Hope there is a solution constructing AD function at runtime in CppAD.

Jun and Kipp






More information about the CppAD mailing list