You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2008/04/15 15:20:54 UTC

svn commit: r648239 [3/4] - in /commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic: ./ analysis/ arithmetic/ functions/ instructions/ trimming/

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Atan2Transformer2.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Atan2Transformer2.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Atan2Transformer2.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Atan2Transformer2.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the atan2 function invocation instructions.
+ */
+public class Atan2Transformer2 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        final int tmp1 = methodDifferentiator.getTmp(1);
+        final int tmp2 = methodDifferentiator.getTmp(2);
+        final int tmp3 = methodDifferentiator.getTmp(3);
+
+        // generate differential code
+        // ... y, x0, x1  --> ...  atan2(y, x0), -x1*y/(x0^2+y^2)
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp3)); // => y, x0
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp2)); // => y
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1)); // =>
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1)); // => y
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp2)); // => y, x0
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "atan2", DD_RETURN_D_DESCRIPTOR)); // => atan2(y,x0)
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp3)); // => atan2(y,x0), x1
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1)); // => atan2(y,x0), x1, y
+        list.add(new InsnNode(Opcodes.DMUL));            // => atan2(y,x0), x1*y
+        list.add(new InsnNode(Opcodes.DNEG));            // => atan2(y,x0), -x1*y
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp2)); // => atan2(y,x0), -x1*y, x0
+        list.add(new InsnNode(Opcodes.DUP2));            // => atan2(y,x0), -x1*y, x0, x0
+        list.add(new InsnNode(Opcodes.DMUL));            // => atan2(y,x0), -x1*y, x0^2
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1)); // => atan2(y,x0), -x1*y, x0^2, y
+        list.add(new InsnNode(Opcodes.DUP2));            // => atan2(y,x0), -x1*y, x0^2, y, y
+        list.add(new InsnNode(Opcodes.DMUL));            // => atan2(y,x0), -x1*y, x0^2, y^2
+        list.add(new InsnNode(Opcodes.DADD));            // => atan2(y,x0), -x1*y, x0^2+y^2
+        list.add(new InsnNode(Opcodes.DDIV));            // => atan2(y,x0), -x1*y/(x0^2+y^2)
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Atan2Transformer2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the atan function invocation instructions.
+ */
+public class AtanTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ...  atan(u0), u1 / (1 + u0 * u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DCONST_1));
+        list.add(new InsnNode(Opcodes.DADD));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "atan", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanhTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanhTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanhTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanhTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the atanh function invocation instructions.
+ * <p>As of java 6, the JVM does not supply an inverse hyperbolic
+ * tangent function (see <a
+ * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4919337">bug
+ * 4919337</a>), so this generator will not be triggered for java 6 and below.</p>
+ */
+public class AtanhTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ...  atanh(u0), u1 / (1 - u0 * u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DCONST_1));
+        list.add(new InsnNode(Opcodes.DSUB));
+        list.add(new InsnNode(Opcodes.DNEG));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "atanh", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/AtanhTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CbrtTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CbrtTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CbrtTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CbrtTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.LdcInsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the cbrt function invocation instructions.
+ */
+public class CbrtTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... cbrt(u0), u1 / (3 * cbrt(u0) * cbrt(u0))
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "cbrt", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new LdcInsnNode(Double.valueOf(3)));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DDIV));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CbrtTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CosTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CosTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CosTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CosTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the cos function invocation instructions.
+ */
+public class CosTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... cos(u0), -u1 * sin(u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "sin", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DNEG));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "cos", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CosTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CoshTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CoshTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CoshTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CoshTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the cosh function invocation instructions.
+ */
+public class CoshTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... cosh(u0), u1 * sinh(u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "sinh", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "cosh", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/CoshTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/ExpTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/ExpTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/ExpTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/ExpTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the exp function invocation instructions.
+ */
+public class ExpTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... exp(u0), u1 * exp(u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "exp", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/ExpTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Expm1Transformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Expm1Transformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Expm1Transformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Expm1Transformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the expm1 function invocation instructions.
+ */
+public class Expm1Transformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... expm1(u0), u1 * (1 + expm1(u0))
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "expm1", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DCONST_1));
+        list.add(new InsnNode(Opcodes.DADD));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Expm1Transformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer1.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer1.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer1.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer1.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the hypot function invocation instructions.
+ */
+public class HypotTransformer1 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        final int tmp1 = methodDifferentiator.getTmp(1);
+        final int tmp2 = methodDifferentiator.getTmp(2);
+
+        // generate differential code
+        // ... x0, x1, y  --> ...  hypot(x0,y), x0*x1/hypot(x0,y)
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1)); // => x0, x1
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp2)); // => x0
+        list.add(new InsnNode(Opcodes.DUP2));            // => x0, x0
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1)); // => x0, x0, y
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "hypot", DD_RETURN_D_DESCRIPTOR)); // => x0, hypot(x0,y)
+        list.add(new InsnNode(Opcodes.DUP2_X2));         // => hypot(x0,y), x0, hypot(x0,y)
+        list.add(new InsnNode(Opcodes.DDIV));            // => hypot(x0,y), x0/hypot(x0,y)
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp2)); // => hypot(x0,y), x0/hypot(x0,y), x1
+        list.add(new InsnNode(Opcodes.DMUL));            // => hypot(x0,y), x0*x1/hypot(x0,y)
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer12.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer12.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer12.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer12.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the hypot function invocation instructions.
+ */
+public class HypotTransformer12 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        final int tmp1 = methodDifferentiator.getTmp(1);
+        final int tmp2 = methodDifferentiator.getTmp(2);
+        final int tmp3 = methodDifferentiator.getTmp(3);
+        final int tmp4 = methodDifferentiator.getTmp(4);
+
+        // generate differential code
+        // ... x0, x1, y0, y1  --> ...  hypot(x0,y0), (x0*x1+y0*y1)/hypot(x0,y0)
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1)); // => x0, x1, y0
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp2)); // => x0, x1
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp3)); // => x0
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp4)); // =>
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp4)); // => x0
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp2)); // => x0, y0
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "hypot", DD_RETURN_D_DESCRIPTOR)); // => hypot(x0,y0)
+        list.add(new InsnNode(Opcodes.DUP2));            // => hypot(x0,y), hypot(x0,y)
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp4)); // => hypot(x0,y), hypot(x0,y), x0
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp3)); // => hypot(x0,y), hypot(x0,y), x0, x1
+        list.add(new InsnNode(Opcodes.DMUL));            // => hypot(x0,y), hypot(x0,y), x0*x1
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp2)); // => hypot(x0,y), hypot(x0,y), x0*x1, y0
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1)); // => hypot(x0,y), hypot(x0,y), x0*x1, y0, y1
+        list.add(new InsnNode(Opcodes.DMUL));            // => hypot(x0,y), hypot(x0,y), x0*x1, y0*y1
+        list.add(new InsnNode(Opcodes.DADD));            // => hypot(x0,y), hypot(x0,y), x0*x1+y0*y1
+        list.add(new InsnNode(Opcodes.DUP2_X2));         // => hypot(x0,y), x0*x1+y0*y1, hypot(x0,y), x0*x1+y0*y1
+        list.add(new InsnNode(Opcodes.POP2));            // => hypot(x0,y), x0*x1+y0*y1, hypot(x0,y)
+        list.add(new InsnNode(Opcodes.DDIV));            // => hypot(x0,y), (x0*x1+y0*y1)/hypot(x0,y)
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer12.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer2.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer2.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer2.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer2.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the hypot function invocation instructions.
+ */
+public class HypotTransformer2 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        final int tmp1 = methodDifferentiator.getTmp(1);
+
+        // generate differential code
+        // ... x, y0, y1  --> ...  hypot(x,y0), y0*y1/hypot(x,y0)
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1)); // => x, y0
+        list.add(new InsnNode(Opcodes.DUP2_X2));         // => y0, x, y0
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "hypot", DD_RETURN_D_DESCRIPTOR)); // => y0, hypot(x,y0)
+        list.add(new InsnNode(Opcodes.DUP2_X2));         // => hypot(x,y0), y0, hypot(x,y0)
+        list.add(new InsnNode(Opcodes.DDIV));            // => hypot(x,y0), y0/hypot(x,y0)
+        list.add(new VarInsnNode(Opcodes.DLOAD,  tmp1)); // => hypot(x,y0), y0/hypot(x,y0), y1
+        list.add(new InsnNode(Opcodes.DMUL));            // => hypot(x,y0), y0*y1/hypot(x,y0)
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/HypotTransformer2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log10Transformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log10Transformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log10Transformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log10Transformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.LdcInsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the log10 function invocation instructions.
+ */
+public class Log10Transformer implements MathInvocationTransformer {
+
+    /** Log(10). */
+    private static final Double LOG_10 = Double.valueOf(Math.log(10.0));
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner,
+                                       final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... log10(u0), u1 / (u0 * log(10))
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new LdcInsnNode(LOG_10));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner,
+                                    "log10", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log10Transformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log1pTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log1pTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log1pTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log1pTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the log1p function invocation instructions.
+ */
+public class Log1pTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... log1p(u0), u1 / (1 + u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DCONST_1));
+        list.add(new InsnNode(Opcodes.DADD));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "log1p", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/Log1pTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/LogTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/LogTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/LogTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/LogTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the log function invocation instructions.
+ */
+public class LogTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... log(u0), u1 / u0;
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "log", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/LogTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/MathInvocationTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/MathInvocationTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/MathInvocationTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/MathInvocationTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.tree.InsnList;
+
+/** Interface for replacing single math method invocations.
+ */
+public interface MathInvocationTransformer {
+
+    /** Descriptor for <code>double m(double)</code> methods. */
+    String D_RETURN_D_DESCRIPTOR = "(D)D";
+
+    /** Descriptor for <code>double m(double, double)</code> methods. */
+    String DD_RETURN_D_DESCRIPTOR = "(DD)D";
+
+    /** Get the replacement list for an invocation instruction.
+     * @param owner owner of the method (typically Math or StrictMath)
+     * @param methodDifferentiator method differentiator driving this transformer
+     * @return replacement list
+     * @exception DifferentiationException if the method differentiator cannot provide
+     * a temporary variable
+     */
+    InsnList getReplacementList(String owner, MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException;
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/MathInvocationTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer1.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer1.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer1.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer1.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the pow function invocation instructions.
+ */
+public class PowTransformer1 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        // generate diferential code
+        // ... a0, a1, b  --> ... pow(a0, b), a1 * b * pow(a0, b) / a0
+        final int tmp1 = methodDifferentiator.getTmp(1);
+        final int tmp2 = methodDifferentiator.getTmp(2);
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp1));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "pow", DD_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer12.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer12.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer12.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer12.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the pow function invocation instructions.
+ */
+public class PowTransformer12 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        // generate differential code
+        // ... a0, a1, b0, b1  --> ... pow(a0,b0), (a1*b0/a0 + b1*log(a0)) * pow(a0,b0)
+        final int tmp1 = methodDifferentiator.getTmp(1);
+        final int tmp2 = methodDifferentiator.getTmp(2);
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "log", D_RETURN_D_DESCRIPTOR));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp1));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DDIV));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp1));
+        list.add(new InsnNode(Opcodes.DADD));
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "pow", DD_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp1));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer12.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer2.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer2.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer2.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer2.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for the pow function invocation instructions.
+ */
+public class PowTransformer2 implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        // generate differential code
+        // ... a, b0, b1  --> ... pow(a, b0), b1 * log(a) * pow(a, b0)
+        final int tmp1 = methodDifferentiator.getTmp(1);
+        final int tmp2 = methodDifferentiator.getTmp(2);
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp1));
+        list.add(new VarInsnNode(Opcodes.DSTORE, tmp2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "pow", DD_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "log", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new VarInsnNode(Opcodes.DLOAD, tmp1));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/PowTransformer2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the sin function invocation instructions.
+ */
+public class SinTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... sin(u0), u1 * cos(u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "cos", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "sin", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinhTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinhTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinhTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinhTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the sinh function invocation instructions.
+ */
+public class SinhTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... sinh(u0), u1 * cosh(u0)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "cosh", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "sinh", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SinhTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SqrtTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SqrtTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SqrtTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SqrtTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the sqrt function invocation instructions.
+ */
+public class SqrtTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ... sqrt(u0), u1 / (2 * sqrt(u0))
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "sqrt", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DADD));
+        list.add(new InsnNode(Opcodes.DDIV));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/SqrtTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the tan function invocation instructions.
+ */
+public class TanTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ...  tan(u0), u1 * (1 + tan(u0) * tan(u0))
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "tan", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DCONST_1));
+        list.add(new InsnNode(Opcodes.DADD));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanhTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanhTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanhTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanhTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.functions;
+
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+
+/** Differentiation transformer for the tanh function invocation instructions.
+ */
+public class TanhTransformer implements MathInvocationTransformer {
+
+    /** {@inheritDoc} */
+    public InsnList getReplacementList(final String owner, final MethodDifferentiator methodDifferentiator) {
+
+        // generate differential code
+        // ... u0, u1  --> ...  tanh, u1 * (1 - tanh * tanh)
+        final InsnList list = new InsnList();
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.POP2));
+        list.add(new MethodInsnNode(Opcodes.INVOKESTATIC, owner, "tanh", D_RETURN_D_DESCRIPTOR));
+        list.add(new InsnNode(Opcodes.DUP2_X2));
+        list.add(new InsnNode(Opcodes.DUP2));
+        list.add(new InsnNode(Opcodes.DMUL));
+        list.add(new InsnNode(Opcodes.DCONST_1));
+        list.add(new InsnNode(Opcodes.DSUB));
+        list.add(new InsnNode(Opcodes.DNEG));
+        list.add(new InsnNode(Opcodes.DMUL));
+        return list;
+
+    }
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/functions/TanhTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DLoadTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DLoadTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DLoadTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DLoadTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.instructions;
+
+import org.apache.commons.nabla.automatic.analysis.InstructionsTransformer;
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for DLOAD instructions.
+ * <p>Each DLOAD instruction for double variable <i>k</i>
+ * is replaced by two DLOAD instructions for double variables
+ * <i>k</i> and <i>k+2</i> representing an expanded differential pair.
+ */
+public class DLoadTransformer implements InstructionsTransformer {
+
+    /** Holder for the singleton instance.*/
+    private static class LazyHolder  {
+        /** The singleton instance. */
+        private static final InstructionsTransformer INSTANCE = new DLoadTransformer();
+    }
+
+    /** Hidden constructor.
+     */
+    private DLoadTransformer() {
+    }
+
+    /** Get the singleton instance.
+     * <p>We use here the Initialization on Demand Holder idiom.</p>
+     * @return the singleton instance
+     */
+    public static InstructionsTransformer getInstance() {
+        return LazyHolder.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
+    public InsnList getReplacement(final AbstractInsnNode insn,
+                                   final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+        final int var = ((VarInsnNode) insn).var;
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DLOAD, var));
+        list.add(new VarInsnNode(Opcodes.DLOAD, var + 2));
+        return list;
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DLoadTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DReturnTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DReturnTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DReturnTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DReturnTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.instructions;
+
+import org.apache.commons.nabla.automatic.analysis.AutomaticDifferentiator;
+import org.apache.commons.nabla.automatic.analysis.InstructionsTransformer;
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.TypeInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for DRETURN instructions.
+ * <p>DRETURN instructions are replaced by instructions
+ * that build a {@link org.apache.commons.nabla.core.DifferentialPair
+ * DifferentialPair} instance from the expanded differential pair
+ * on operand stack head and an ARETURN instruction returning this
+ * instance.</p>
+ */
+public class DReturnTransformer implements InstructionsTransformer {
+
+    /** Holder for the singleton instance.*/
+    private static class LazyHolder  {
+        /** The singleton instance. */
+        private static final InstructionsTransformer INSTANCE = new DReturnTransformer();
+    }
+
+    /** Hidden constructor.
+     */
+    private DReturnTransformer() {
+    }
+
+    /** Get the singleton instance.
+     * <p>We use here the Initialization on Demand Holder idiom.</p>
+     * @return the singleton instance
+     */
+    public static InstructionsTransformer getInstance() {
+        return LazyHolder.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
+    public InsnList getReplacement(final AbstractInsnNode insn,
+                                   final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+
+        // reuse local variables slots 1, 2, 3 and 4 for temporary storage
+        // (this may reduce the number of needed local variables)
+        methodDifferentiator.useLocal(1, 4);
+
+        final InsnList list = new InsnList();
+        // operand stack initial state: a0, a1
+        list.add(new VarInsnNode(Opcodes.DSTORE, 3));           // => a0
+        list.add(new VarInsnNode(Opcodes.DSTORE, 1));           // =>
+        list.add(new TypeInsnNode(Opcodes.NEW,
+                                  AutomaticDifferentiator.DP_NAME)); // => o,
+        list.add(new InsnNode(Opcodes.DUP));                    // => o, o
+        list.add(new VarInsnNode(Opcodes.DLOAD, 1));            // => o, o, a0
+        list.add(new VarInsnNode(Opcodes.DLOAD, 3));            // => o, o, a0, a1
+        list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
+                                    AutomaticDifferentiator.DP_NAME,
+                                    "<init>", "(DD)V"));        // => dp
+        list.add(new InsnNode(Opcodes.ARETURN));                // =>
+        return list;
+
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DReturnTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DStoreTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DStoreTransformer.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DStoreTransformer.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DStoreTransformer.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.instructions;
+
+import org.apache.commons.nabla.automatic.analysis.InstructionsTransformer;
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.VarInsnNode;
+
+/** Differentiation transformer for DSTORE instructions.
+ * <p>Each DSTORE instruction for double variable <i>k</i>
+ * is replaced by two DSTORE instructions for double variables
+ * <i>k+2</i> and <i>k</i> representing an expanded differential pair.
+ */
+public class DStoreTransformer implements InstructionsTransformer {
+
+    /** Holder for the singleton instance.*/
+    private static class LazyHolder  {
+        /** The singleton instance. */
+        private static final InstructionsTransformer INSTANCE = new DStoreTransformer();
+    }
+
+    /** Hidden constructor.
+     */
+    private DStoreTransformer() {
+    }
+
+    /** Get the singleton instance.
+     * <p>We use here the Initialization on Demand Holder idiom.</p>
+     * @return the singleton instance
+     */
+    public static InstructionsTransformer getInstance() {
+        return LazyHolder.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
+    public InsnList getReplacement(final AbstractInsnNode insn,
+                                   final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+        final int var = ((VarInsnNode) insn).var;
+        final InsnList list = new InsnList();
+        list.add(new VarInsnNode(Opcodes.DSTORE, var + 2));
+        list.add(new VarInsnNode(Opcodes.DSTORE, var));
+        return list;
+    }
+
+}

Propchange: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DStoreTransformer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DcmpTransformer1.java
URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DcmpTransformer1.java?rev=648239&view=auto
==============================================================================
--- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DcmpTransformer1.java (added)
+++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/automatic/instructions/DcmpTransformer1.java Tue Apr 15 06:20:36 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.nabla.automatic.instructions;
+
+import org.apache.commons.nabla.automatic.analysis.InstructionsTransformer;
+import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator;
+import org.apache.commons.nabla.core.DifferentiationException;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+
+/** Differentiation transformer for DCMPx instructions.
+ * <p>Each DCMPx instruction is replaced by a sequence that
+ * first remove the differential parts from the top stack cells
+ * followed by the comparison instruction.
+ */
+public class DcmpTransformer1 implements InstructionsTransformer {
+
+    /** Holder for the singleton instance.*/
+    private static class LazyHolder  {
+        /** The singleton instance. */
+        private static final InstructionsTransformer INSTANCE = new DcmpTransformer1();
+    }
+
+    /** Hidden constructor.
+     */
+    private DcmpTransformer1() {
+    }
+
+    /** Get the singleton instance.
+     * <p>We use here the Initialization on Demand Holder idiom.</p>
+     * @return the singleton instance
+     */
+    public static InstructionsTransformer getInstance() {
+        return LazyHolder.INSTANCE;
+    }
+
+    /** {@inheritDoc} */
+    public InsnList getReplacement(final AbstractInsnNode insn,
+                                   final MethodDifferentiator methodDifferentiator)
+        throws DifferentiationException {
+        final InsnList list = new InsnList();
+        // operand stack initial state: a0, a1, b
+        list.add(new InsnNode(Opcodes.DUP2_X2)); // => a0, b, a1, b
+        list.add(new InsnNode(Opcodes.POP2));    // => a0, b, a1
+        list.add(new InsnNode(Opcodes.POP2));    // => a0, b
+        list.add(methodDifferentiator.clone(insn));
+        return list;
+    }
+
+}