:

## A question on procedures that return procedures

Maple
I'm trying to do symbiolic manipulations to define new procedures but I have trouble figuring out how to achieve my goal. The context is as follows: We have a set of ODEs df/dt = R(f(t)) where f(0) = x. Here f and x are n-dimensional vectors with components f[i], x[i], and R is a vector valued function with components R[i]; t is time. Example: R[1] := proc (x::Vector) x[2] end proc; R[2] := proc (x::Vector) -x[1]*(1+x[3]^2) end proc; R[3] := proc (x::Vector) x[4] end proc; R[4] := proc (x::Vector) -x[3]*(1+x[1]^2) end proc; Now, the Liouville operator is defined as L := proc(F::algebraic,a::list(algebraic)) sum('a[k] * diff(F,x[k])','k'=1..nops(a)); end proc: Here is how it works. If I define a function f as: f := proc (x::Vector) -x[1]*(1+x[3]^2) end proc then after defining a vector x and applying L to f(x) x := Vector(4, [u[1], u[2], u[3], u[4]]) L(f(x), [R[1](x), R[2](x), R[3](x), R[4](x)]); gives u[2] (-1 - u[3]^2 ) - 2 u[4] u[1] u[3] as it should. My problem is this: How to apply L to a function/procedure f(x) and return another function/procedure of a vector x? I do not want to copy this output and use it to define a new function because I want to apply L within a loop to a sequence of functions. To get the picture, think about generating a function basis in the 4 dimensional vector space which is made of products of Hermite polynomials of different orders acting on different coordinates of x. I need to be able to automatically apply L to this function base, like this L(H(p,x[1])*H(q,x[2])*H(r,x[3])*H(s,x[4]),[R[1](x), R[2](x), R[3](x), R[4](x)]); and to extract a function/procedure of x from the output of L. My attempt at using the Maple description of how to generate a procedure that returns another procedure has failed. By the way, if there is a better way to define ODes and implement a Liouville operator, I'll be more than delighted to find out. The ODE example is from "Optimal prediction with memory" by Chorin et al, Physica D, 166, pp 239-257 (2002). If you read this interesting paper, you'll find out exactly what I'm trying to solve.

﻿