|\^/| Maple 7 (IBM INTEL LINUX) ._|\| |/|_. Copyright (c) 2001 by Waterloo Maple Inc. \ MAPLE / All rights reserved. Maple is a registered trademark of <____ ____> Waterloo Maple Inc. | Type ? for help. # util.maple -- misc utility routines # $Id: util.maple,v 1.1 2001/06/29 09:36:22 jthorn Exp $ > # # C_str - codegen[C](), but returning its result as a Maple string # fix_rationals - convert numbers to RATIONAL() calls # nonmatching_names - find names in a list which *don't* have a specified prefix # sprint_numeric_list - convert a numeric list to a valid C identifier suffix # print_name_list_dcl - print a C declaration for a list of names # # hypercube_points - compute all (integer) points in an N-dimensional hypercube # # ftruncate - truncate a file to zero length # > ################################################################################ ################################################################################ ################################################################################ > # # This function is a wrapper around codegen[C]() which returns the # genenerated code explictly as a Maple string. # # Arguments: # expr = (in) The expression for which code is to be generated. # ... = (in) Any further arguments are taken as options to be passed # to codegen[C]() # # Results: # The function returns a maple string of C code. # > C_str := > proc(expr::algebraic) > local tempname, str, temp; > # name of temp file # FIXME: should use process number to ensure uniqueness > tempname := "/tmp/C_str.tmp.c"; > # truncate temp file to zero length > fopen(tempname, WRITE); > fclose(tempname); > # generate the code > codegen[C](args, filename=tempname); > # read the code back in > str := ""; > while true > do > temp := readline(tempname); > if (temp = 0) > then break; > end if; > str := cat(str, temp); > end do; > fclose(tempname); > # strip off the leading " t0 = " > return op(2,sscanf(str, "%s = %[^;];")); > end proc; C_str := proc(expr::algebraic) local tempname, str, temp; tempname := "/tmp/C_str.tmp.c"; fopen(tempname, WRITE); fclose(tempname); codegen[C](args, filename = tempname); str := ""; do temp := readline(tempname); if temp = 0 then break end if; str := cat(str, temp) end do; fclose(tempname); return op(2, sscanf(str, "%s = %[^;];")) end proc > ################################################################################ > # # This function converts all {integer, rational} subexpressions of its # input except integer exponents and -1 factors in products, into function # calls # RATIONAL(num,den) # This is useful in conjunction with the C() library function, since # # C( (1/3) * foo * bar ) # t0 = foo*bar/3; # # generates a (slow) division (and runs the risk of mixed-mode-arithmetic # problems), while # # C((1.0/3.0) * foo * bar); # t0 = 0.3333333333*foo*bar; # # suffers from roundoff error. With this function, # # fix_rationals((1/3) * foo * bar); # RATIONAL(1,3) foo bar # C(%); # t0 = RATIONAL(1.0,3.0)*foo*bar; # # which a C preprocessor macro can easily convert to the desired # # t0 = (1.0/3.0)*foo*bar; # # Additionally, this function can be told to leave certain types of # subexpressions unconverged. For example, # fix_rationals(expr, type, specfunc(integer, DATA)); # will leave all subexpressions of the form DATA(integer arguments) # unconverted. # # Arguments: # expr = (in) The expression to be converted. # inert_fn = (optional in) # If specified, this argument should be a Boolean procedure # or the name of a Boolean procedure. This procedure should # take one or more argument, and return true if and only if # the first argument should *not* be converted, i.e. if we # should leave this expression unchanged. See the last # example above. # ... = (optional in) # Any further arguments are passed as additional arguments to # the inert_fn procedure. # > fix_rationals := > proc( > expr::{ > algebraic, name = algebraic, > list({algebraic, name = algebraic}), > set ({algebraic, name = algebraic}) > }, > inert_fn::{name, procedure} > ) > local nn, k, > base, power, fbase, fpower, > fn, fn_args_list, > num, den, mult; > # do we want to convert this expression? > if ((nargs >= 2) and inert_fn(expr, args[3..nargs])) > then return expr; > end if; > # recurse over lists and sets > if (type(expr, {list,set})) > then return map(fix_rationals, expr, args[2..nargs]); > end if; > # recurse over equation right hand sides > if (type(expr, name = algebraic)) > then return ( lhs(expr) = fix_rationals(rhs(expr), args[2..nargs]) ); > end if; > # recurse over functions other than RATIONAL() > if (type(expr, function)) > then > fn := op(0, expr); > if (fn <> 'RATIONAL') > then > fn_args_list := [op(expr)]; > fn_args_list := map(fix_rationals, fn_args_list, args[2..nargs]); > fn; return '%'( op(fn_args_list) ); > end if; > end if; > > nn := nops(expr); > # recurse over sums > if (type(expr, `+`)) > then return sum('fix_rationals(op(k,expr), args[2..nargs])', 'k'=1..nn); > end if; > # recurse over products # ... leaving leading -1 factors intact, i.e. not converted to RATIONAL(-1,1) > if (type(expr, `*`)) > then > if (op(1, expr) = -1) > then return -1*fix_rationals(remove(type, expr, 'identical(-1)'), > args[2..nargs]); > else return product('fix_rationals(op(k,expr), args[2..nargs])', > 'k'=1..nn); > end if; > end if; > # recurse over powers # ... leaving integer exponents intact > if (type(expr, `^`)) > then > base := op(1, expr); > power := op(2, expr); > > fbase := fix_rationals(base, args[2..nargs]); > if (type(power, integer)) > then fpower := power; > else fpower := fix_rationals(power, args[2..nargs]); > end if; > return fbase ^ fpower; > end if; > # fix integers and fractions > if (type(expr, integer)) > then return 'RATIONAL'(expr, 1); > end if; > if (type(expr, fraction)) > then > num := op(1, expr); > den := op(2, expr); > > return 'RATIONAL'(num, den); > end if; > # turn Maple floating-point into integer fraction, then recursively fix that > if (type(expr, float)) > then > mult := op(1, expr); > power := op(2, expr); > return fix_rationals(mult * 10^power, args[2..nargs]); > end if; > # identity op on names > if (type(expr, name)) > then return expr; > end if; > # unknown type > error "%0", > "unknown type for expr!", > " whattype(expr) = ", whattype(expr), > " expr = ", expr; > end proc; fix_rationals := proc(expr::{algebraic, name = algebraic, list({algebraic, name = algebraic}), set({algebraic, name = algebraic})}, inert_fn::{procedure, name}) local nn, k, base, power, fbase, fpower, fn, fn_args_list, num, den, mult; if 2 <= nargs and inert_fn(expr, args[3 .. nargs]) then return expr end if; if type(expr, {set, list}) then return map(fix_rationals, expr, args[2 .. nargs]) end if; if type(expr, name = algebraic) then return lhs(expr) = fix_rationals(rhs(expr), args[2 .. nargs]) end if; if type(expr, function) then fn := op(0, expr); if fn <> 'RATIONAL' then fn_args_list := [op(expr)]; fn_args_list := map(fix_rationals, fn_args_list, args[2 .. nargs]); fn; return '%'(op(fn_args_list)) end if end if; nn := nops(expr); if type(expr, `+`) then return sum('fix_rationals(op(k, expr), args[2 .. nargs])', 'k' = 1 .. nn) end if; if type(expr, `*`) then if op(1, expr) = -1 then return -fix_rationals( remove(type, expr, 'identical(-1)'), args[2 .. nargs]) else return product('fix_rationals(op(k, expr), args[2 .. nargs])', 'k' = 1 .. nn) end if end if; if type(expr, `^`) then base := op(1, expr); power := op(2, expr); fbase := fix_rationals(base, args[2 .. nargs]); if type(power, integer) then fpower := power else fpower := fix_rationals(power, args[2 .. nargs]) end if; return fbase^fpower end if; if type(expr, integer) then return 'RATIONAL'(expr, 1) end if; if type(expr, fraction) then num := op(1, expr); den := op(2, expr); return 'RATIONAL'(num, den) end if; if type(expr, float) then mult := op(1, expr); power := op(2, expr); return fix_rationals(mult*10^power, args[2 .. nargs]) end if; if type(expr, name) then return expr end if; error "%0", "unknown type for expr!", " whattype(expr) = ", whattype(expr), " expr = ", expr end proc > ################################################################################ > # # This function finds names in a list which *don't* have a specified prefix. # # Arguments: # name_list = A list of the names. # prefix = The prefix we want to filter out. # # Results: # This function returns the subset list of names which don't have the # specified prefix. # > nonmatching_names := > proc( name_list::list({name,string}), prefix::{name,string} ) > > select( proc(n) > evalb(not StringTools[IsPrefix](prefix,n)); > end proc > , > name_list > ); > end proc; nonmatching_names := proc( name_list::list({name, string}), prefix::{name, string}) select(proc(n) evalb(not StringTools[IsPrefix](prefix, n)) end proc, name_list) end proc > ################################################################################ > # # This function converts a numeric list to a string which is a valid # C identifier suffix: elements are separated by "_", decimal points are # replaced by "x", and all nonzero values have explicit +/- signs, which # are replaced by "p"/"m". # # For example, [0,-3.5,+4] --> "0_m3x5_p4". # > sprint_numeric_list := > proc(nlist::list(numeric)) > # generate preliminary string, eg "+0_-3.5_+4" > map2(sprintf, "%+a", nlist); > ListTools[Join](%, "_"); > cat(op(%)); > # fixup bad characters > StringTools[SubstituteAll](%, "+0", "0"); > StringTools[CharacterMap](".+-", "xpm", %); > > return %; > end proc; sprint_numeric_list := proc(nlist::list(numeric)) map2(sprintf, "%+a", nlist); ListTools[Join](%, "_"); cat(op(%)); StringTools[SubstituteAll](%, "+0", "0"); StringTools[CharacterMap](".+-", "xpm", %); return % end proc > ################################################################################ > # # This function prints a C declaration for a list of names. # # Argument: # name_list = A list of the names. # name_type = The C type of the names, eg. "double". # file_name = The file name to write the declaration to. This is # truncated before writing. # > print_name_list_dcl := > proc( name_list::list({name,string}), > name_type::string, > file_name::string ) > local blanks, separator_string; > > ftruncate(file_name); > # a sequence of blanks with the same length as name_type > seq(" ", i=1..length(name_type)); > # string to separate names > separator_string := cat(",\n", %, " "); > > map(convert, name_list, string); > ListTools[Join](%, separator_string); > cat(op(%)); > > fprintf(file_name, > "%s %s;\n", > name_type, %); > NULL; > end proc; print_name_list_dcl := proc( name_list::list({name, string}), name_type::string, file_name::string) local blanks, separator_string; ftruncate(file_name); seq(" ", i = 1 .. length(name_type)); separator_string := cat(",\n", %, " "); map(convert, name_list, string); ListTools[Join](%, separator_string); cat(op(%)); fprintf(file_name, "%s %s;\n", name_type, %); NULL end proc > ################################################################################ ################################################################################ ################################################################################ > # # This function computes a list of all the (integer) points in an # N-dimensional hypercube, in lexicographic order. The present # implementation requires N <= 4. # # Arguments: # cmin,cmax = N-element lists of cube minimum/maximum coordinates. # # Results: # The function returns a set of d-element lists giving the coordinates. # For example, # hypercube([0,0], [2,1] # returns # { [0,0], [0,1], [1,0], [1,1], [2,0], [2,1] } > hypercube_points := > proc(cmin::list(integer), cmax::list(integer)) > local N, i,j,k,l; > > N := nops(cmin); > if (nops(cmax) <> N) > then error > "must have same number of dimensions for min and max coordinates!"; > fi; > > if (N = 1) > then return [seq([i], i=cmin[1]..cmax[1])]; > elif (N = 2) > then return [ > seq( > seq([i,j], j=cmin[2]..cmax[2]), > i=cmin[1]..cmax[1]) > ]; > elif (N = 3) > then return [ > seq( > seq( > seq([i,j,k], k=cmin[3]..cmax[3]), > j=cmin[2]..cmax[2] ), > i=cmin[1]..cmax[1]) > ]; > elif (N = 4) > then return [ > seq( > seq( > seq( > seq([i,j,k,l], l=cmin[4]..cmax[4]), > k=cmin[3]..cmax[3] ), > j=cmin[2]..cmax[2]), > i=cmin[1]..cmax[1]) > ]; > else > error "implementation restriction: must have N <= 4, got %1!", N; > fi; > end proc; hypercube_points := proc(cmin::list(integer), cmax::list(integer)) local N, i, j, k, l; N := nops(cmin); if nops(cmax) <> N then error "must have same number of dimensions for min and max coordinates!" end if; if N = 1 then return [seq([i], i = cmin[1] .. cmax[1])] elif N = 2 then return [seq(seq([i, j], j = cmin[2] .. cmax[2]), i = cmin[1] .. cmax[1])] elif N = 3 then return [seq( seq(seq([i, j, k], k = cmin[3] .. cmax[3]), j = cmin[2] .. cmax[2]) , i = cmin[1] .. cmax[1])] elif N = 4 then return [seq(seq(seq( seq([i, j, k, l], l = cmin[4] .. cmax[4]), k = cmin[3] .. cmax[3]), j = cmin[2] .. cmax[2]), i = cmin[1] .. cmax[1])] else error "implementation restriction: must have N <= 4, got %1!", N end if end proc > ################################################################################ ################################################################################ ################################################################################ > # # This function truncates a file to 0 length if it exists, or creates # it at that length if it doesn't exist. # # Arguments: # file_name = (in) The name of the file. # > ftruncate := > proc(file_name::string) > fopen(file_name, 'WRITE'); > fclose(%); > NULL; > end proc; ftruncate := proc(file_name::string) fopen(file_name, 'WRITE'); fclose(%); NULL end proc # GInterpolate.maple -- compute generalized interpolation formulas/coefficients # $Id$ > # # <<>> # polynomial_interpolant - compute polynomial interpolant # coeff_as_lc_of_data - coefficients of ... (linear combination of data) # # print_coeff__lc_of_data - print C code to compute coefficients # print_data_var_assign - print C code to assign data-value variables # print_interp_cmpt__lc_of_data - print C code for computation of interpolant # # coeff_name - name of coefficient of data at a given [m] coordinate # data_var_name - name of variable storing data value at a given [m] coordinate # > ################################################################################ > # # ***** representation of numbers, data values, etc ***** # # We use RATIONAL(p.0,q.0) to denote the rational number p/q. # # We use DATA(...) to represent the data values being interpolated at a # specified [m] coordinate, where the arguments are the [m] coordinates. # # We use COEFF(...) to represent the molecule coefficient at a specified # [m] coordinate, where the arguments are the [m] coordinates. # # For example, the usual 1-D centered 2nd order 1st derivative molecule # would be written # RATIONAL(-1.0,2.0)*DATA(-1) + RATIONA(1.0,2.0)*DATA(1) # and its coefficients as # COEFF(-1) = RATIONAL(-1.0,2.0) # COEFF(1) = RATIONAL(1.0,2.0) # > ################################################################################ ################################################################################ ################################################################################ > # # This function computes a polynomial interpolant in any number of dimensions. # # Arguments: # fn = The interpolation function. This should be a procedure in the # coordinates, having the coefficients as global variables. For # example, # proc(x,y) c00 + c10*x + c01*y end proc # coeff_list = A set of the interpolation coefficients (coefficients in # the interpolation function), for example [c00, c10, c01]. # coord_list = A list of the coordinates (independent variables in the # interpolation function), for example [x,y]. # posn_list = A list of positions (each a list of numeric values) where the # interpolant is to use data, for example hypercube([0,0], [1,1]). # Any positions may be used; if they're redundant (as in the # example) the least-squares interpolant is computed. # # Results: # This function returns the interpolating polynomial, in the form of # an algebraic expression in the coordinates and the data values. # > polynomial_interpolant := > proc( > fn::procedure, coeff_list::list(name), > coord_list::list(name), posn_list::list(list(numeric)) > ) > local posn, data_eqns, coeff_eqns; > # coefficients of interpolating polynomial > data_eqns := { seq( fn(op(posn))='DATA'(op(posn)) , posn=posn_list ) }; > coeff_eqns := linalg[leastsqrs](data_eqns, {op(coeff_list)}); > if (has(coeff_eqns, '_t')) > then error "interpolation coefficients aren't uniquely determined!"; > end if; > # interpolant as a polynomial in the coordinates > return subs(coeff_eqns, eval(fn))(op(coord_list)); > end proc; polynomial_interpolant := proc(fn::procedure, coeff_list::list(name), coord_list::list(name), posn_list::list(list(numeric))) local posn, data_eqns, coeff_eqns; data_eqns := {seq(fn(op(posn)) = 'DATA'(op(posn)), posn = posn_list)}; coeff_eqns := linalg[leastsqrs](data_eqns, {op(coeff_list)}); if has(coeff_eqns, '_t') then error "interpolation coefficients aren't uniquely determined!" end if; return subs(coeff_eqns, eval(fn))(op(coord_list)) end proc > ################################################################################ > # # This function takes as input an interpolating polynomial, expresses # it as a linear combination of the data values, and returns the coefficeints # of that form. # # Arguments: # interpolant = The interpolating polynomial (an algebraic expression # in the coordinates and the data values). # posn_list = The same list of positions as was used to compute the # interpolating polynomial. # # Results: # This function returns the coefficients, as a list of equations of the # form COEFF(...) = value , where each value is a polynomial in the # coordinates. The order of the list matches that of posn_list. # > coeff_as_lc_of_data := > proc( > interpolant::algebraic, > posn_list::list(list(numeric)) > ) > local data_list, interpolant_as_lc_of_data; > # interpolant as a linear combination of the data values > data_list := [ seq( 'DATA'(op(posn)) , posn=posn_list ) ]; > interpolant_as_lc_of_data := collect(interpolant, data_list); > # coefficients of the data values in the linear combination > return map( > proc(posn::list(numeric)) > coeff(interpolant_as_lc_of_data, DATA(op(posn))); > 'COEFF'(op(posn)) = %; > end proc > , > posn_list > ); > end proc; coeff_as_lc_of_data := proc( interpolant::algebraic, posn_list::list(list(numeric))) local data_list, interpolant_as_lc_of_data; data_list := [seq('DATA'(op(posn)), posn = posn_list)]; interpolant_as_lc_of_data := collect(interpolant, data_list); return map(proc(posn::list(numeric)) coeff(interpolant_as_lc_of_data, DATA(op(posn))); 'COEFF'(op(posn)) = % end proc, posn_list) end proc > ################################################################################ ################################################################################ ################################################################################ > # # This function prints C expressions for the coefficients of an # interpolating polynomial. (The polynomial is expressed as linear # combinations of the data values with coefficients which are # RATIONAL(p,q) calls.) # # Arguments: # coeff_list = A list of the coefficients, as returned from # coeff_as_lc_of_data() . # coeff_name_prefix = A prefix string for the coefficient names. # temp_name_type = The C type to be used for Maple-introduced temporary # names, eg. "double". # file_name = The file name to write the coefficients to. This is # truncated before writing. # > print_coeff__lc_of_data := > proc( coeff_list::list(specfunc(numeric,COEFF) = algebraic), > coeff_name_prefix::string, > temp_name_type::string, > file_name::string ) > global `codegen/C/function/informed`; > local coeff_list2, cmpt_list, temp_name_list; > # convert LHS of each equation from a COEFF() call (eg COEFF(-1,+1)) # to a Maple/C variable name (eg coeff_I_m1_p1) > coeff_list2 := map( > proc(coeff_eqn::specfunc(numeric,COEFF) = algebraic) > local posn; > posn := [op(lhs(coeff_eqn))]; > coeff_name(posn,coeff_name_prefix); > convert(%, name); # codegen[C] wants LHS > # to be an actual Maple *name* > % = fix_rationals(rhs(coeff_eqn)); > end proc > , > coeff_list > ); > # # generate the C code # > # tell codegen[C] not to warn about unknown RATIONAL() and DATA() "fn calls" # via undocumented :( global table > `codegen/C/function/informed`['RATIONAL'] := true; > `codegen/C/function/informed`['DATA'] := true; > > ftruncate(file_name); > # optimized computation sequence for all the coefficients # (may use local variables t0,t1,t2,...) > cmpt_list := [codegen[optimize](coeff_list2, tryhard)]; > # list of the t0,t1,t2,... local variables > temp_name_list := nonmatching_names(map(lhs,cmpt_list), coeff_name_prefix); > # declare the t0,t1,t2,... local variables (if there are any) > if (nops(temp_name_list) > 0) > then print_name_list_dcl(%, temp_name_type, file_name); > fi; > # now print the optimized computation sequence > codegen[C](cmpt_list, filename=file_name); > > NULL; > end proc; print_coeff__lc_of_data := proc( coeff_list::list(specfunc(numeric, COEFF) = algebraic), coeff_name_prefix::string, temp_name_type::string, file_name::string) local coeff_list2, cmpt_list, temp_name_list; global `codegen/C/function/informed`; coeff_list2 := map(proc( coeff_eqn::(specfunc(numeric, COEFF) = algebraic)) local posn; posn := [op(lhs(coeff_eqn))]; coeff_name(posn, coeff_name_prefix); convert(%, name); % = fix_rationals(rhs(coeff_eqn)) end proc, coeff_list); `codegen/C/function/informed`['RATIONAL'] := true; `codegen/C/function/informed`['DATA'] := true; ftruncate(file_name); cmpt_list := [codegen[optimize](coeff_list2, tryhard)]; temp_name_list := nonmatching_names(map(lhs, cmpt_list), coeff_name_prefix); if 0 < nops(temp_name_list) then print_name_list_dcl(%, temp_name_type, file_name) end if; codegen[C](cmpt_list, filename = file_name); NULL end proc > ################################################################################ > # # This function prints a sequence of C expression to assign the data-value # variables. # # Arguments: # posn_list = The same list of positions as was used to compute the # interpolating polynomial. # data_var_name_prefix = A prefix string for the data variable names. # file_name = The file name to write the coefficients to. This is # truncated before writing. # > print_data_var_assign := > proc( > posn_list::list(list(numeric)), > data_var_name_prefix::string, > file_name::string > ) > > ftruncate(file_name); > > map( > proc(posn::list(numeric)) > fprintf(file_name, > "%s = %a;\n", > data_var_name(posn,data_var_name_prefix), > DATA(op(posn))); > end proc > , > posn_list > ); > > NULL; > end proc; print_data_var_assign := proc(posn_list::list(list(numeric)), data_var_name_prefix::string, file_name::string) ftruncate(file_name); map(proc(posn::list(numeric)) fprintf(file_name, "%s = %a;\n", data_var_name(posn, data_var_name_prefix), DATA(op(posn))) end proc, posn_list); NULL end proc > ################################################################################ > # # This function prints a C expression to compute the interpolant, # using the coefficients computed by print_coeff__lc_of_data() # (i.e. expressing the interpolant as a linear combination of the # data values). # # Arguments: # posn_list = The same list of positions as was used to compute the # interpolating polynomial. # result_var_name = The (string) name of the variable to which the # result is to be assigned. # coeff_name_prefix = A prefix string for the coefficient names. # data_var_name_prefix = A prefix string for the data variable names. # file_name = The file name to write the coefficients to. This is # truncated before writing. # > print_interp_cmpt__lc_of_data := > proc( > posn_list::list(list(numeric)), > result_var_name::string, > coeff_name_prefix::string, > data_var_name_prefix::string, > file_name::string > ) > > ftruncate(file_name); > fprintf(file_name, "%s =\n", result_var_name); > # list of "coeff*data_var" terms > map( > proc(posn::list(numeric)) > sprintf("%s*%s", > coeff_name(posn,coeff_name_prefix), > data_var_name(posn,data_var_name_prefix)); > end proc > , > posn_list > ); > > ListTools[Join](%, "\n\t+ "); > cat(op(%)); > > fprintf(file_name, "\t%s;\n", %); > NULL; > end proc; print_interp_cmpt__lc_of_data := proc(posn_list::list(list(numeric)), result_var_name::string, coeff_name_prefix::string, data_var_name_prefix::string, file_name::string) ftruncate(file_name); fprintf(file_name, "%s =\n", result_var_name); map(proc(posn::list(numeric)) sprintf("%s*%s", coeff_name(posn, coeff_name_prefix), data_var_name(posn, data_var_name_prefix)) end proc, posn_list); ListTools[Join](%, "\n\t+ "); cat(op(%)); fprintf(file_name, "\t%s;\n", %); NULL end proc > ################################################################################ ################################################################################ ################################################################################ > # # This function computes the name of the coefficient of the data at a # given [m] position, i.e. it encapsulates our naming convention for this. # # Arguments: # posn = (in) The [m] coordinates. # name_prefix = A prefix string for the coefficient name. # # Results: # The function returns the coefficient, as a Maple string. # > coeff_name := > proc(posn::list(numeric), name_prefix::string) > cat(name_prefix, sprint_numeric_list(posn)); > end proc; coeff_name := proc(posn::list(numeric), name_prefix::string) cat(name_prefix, sprint_numeric_list(posn)) end proc > ################################################################################ > # # This function computes the name of the variable in which the C code # will store the input data at a given [m] position, i.e. it encapsulates # our naming convention for this. # # Arguments: # posn = (in) The [m] coordinates. # name_prefix = A prefix string for the variable name. # # Results: # The function returns the variable name, as a Maple string. # > data_var_name := > proc(posn::list(numeric), name_prefix::string) > cat(name_prefix, sprint_numeric_list(posn)); > end proc; data_var_name := proc(posn::list(numeric), name_prefix::string) cat(name_prefix, sprint_numeric_list(posn)) end proc # Maple code to compute 1-D Lagrange interpolation coefficients (orders 1-4) # $Id$ > ################################################################################ > # # interpolating functions # > > fn_1d_order1 := > proc(x) > + c0 + c1*x > end proc; fn_1d_order1 := proc(x) c0 + c1*x end proc > > fn_1d_order2 := > proc(x) > + c0 + c1*x + c2*x^2 > end proc; fn_1d_order2 := proc(x) c0 + c1*x + c2*x^2 end proc > > fn_1d_order3 := > proc(x) > + c0 + c1*x + c2*x^2 + c3*x^3 > end proc; fn_1d_order3 := proc(x) c0 + c1*x + c2*x^2 + c3*x^3 end proc > > fn_1d_order4 := > proc(x) > + c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 > end; fn_1d_order4 := proc(x) c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 end proc > > fn_1d_order5 := > proc(x) > + c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 > end; fn_1d_order5 := proc(x) c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 end proc > > fn_1d_order6 := > proc(x) > + c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 + c6*x^6 > end; fn_1d_order6 := proc(x) c0 + c1*x + c2*x^2 + c3*x^3 + c4*x^4 + c5*x^5 + c6*x^6 end proc > ######################################## > # # coefficients in interpolating functions # > > coeff_list_1d_order1 := [c0, c1]; coeff_list_1d_order1 := [c0, c1] > coeff_list_1d_order2 := [c0, c1, c2]; coeff_list_1d_order2 := [c0, c1, c2] > coeff_list_1d_order3 := [c0, c1, c2, c3]; coeff_list_1d_order3 := [c0, c1, c2, c3] > coeff_list_1d_order4 := [c0, c1, c2, c3, c4]; coeff_list_1d_order4 := [c0, c1, c2, c3, c4] > coeff_list_1d_order5 := [c0, c1, c2, c3, c4, c5]; coeff_list_1d_order5 := [c0, c1, c2, c3, c4, c5] > coeff_list_1d_order6 := [c0, c1, c2, c3, c4, c5, c6]; coeff_list_1d_order6 := [c0, c1, c2, c3, c4, c5, c6] > ######################################## > # # coordinates and interpolation points # > > coord_list_1d := [x]; coord_list_1d := [x] > # generate points in Fortran ordering > posn_list_1d_size2 := map(ListTools[Reverse], hypercube_points([ 0], [+1])); posn_list_1d_size2 := [[0], [1]] > posn_list_1d_size3 := map(ListTools[Reverse], hypercube_points([-1], [+1])); posn_list_1d_size3 := [[-1], [0], [1]] > posn_list_1d_size4 := map(ListTools[Reverse], hypercube_points([-1], [+2])); posn_list_1d_size4 := [[-1], [0], [1], [2]] > posn_list_1d_size5 := map(ListTools[Reverse], hypercube_points([-2], [+2])); posn_list_1d_size5 := [[-2], [-1], [0], [1], [2]] > posn_list_1d_size6 := map(ListTools[Reverse], hypercube_points([-2], [+3])); posn_list_1d_size6 := [[-2], [-1], [0], [1], [2], [3]] > posn_list_1d_size7 := map(ListTools[Reverse], hypercube_points([-3], [+3])); posn_list_1d_size7 := [[-3], [-2], [-1], [0], [1], [2], [3]] > ################################################################################ > # # generic stuff for 1d, cube, size=2 # > > data_var_list_1d_size2 := map(data_var_name, posn_list_1d_size2, "data_"); data_var_list_1d_size2 := ["data_0", "data_p1"] > > print_name_list_dcl(data_var_list_1d_size2, > "fp", "1d.coeffs/1d.cube.size2/data-var.dcl.c"); > print_data_var_assign(posn_list_1d_size2, > "data_", "1d.coeffs/1d.cube.size2/data-var.assign.c"); > > print_name_list_dcl(map(coeff_name, posn_list_1d_size2, "coeff_I_"), > "fp", "1d.coeffs/1d.cube.size2/coeff-I.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size2, "coeff_dx_"), > "fp", "1d.coeffs/1d.cube.size2/coeff-dx.dcl.c"); > > print_interp_cmpt__lc_of_data(posn_list_1d_size2, > "result", "coeff_I_", "data_", > "1d.coeffs/1d.cube.size2/interp-I.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size2, > "result", "coeff_dx_", "data_", > "1d.coeffs/1d.cube.size2/interp-dx.compute.c"); > ######################################## > # # generic stuff for 1d, cube, size=3 # > > data_var_list_1d_size3 := map(data_var_name, posn_list_1d_size3, "data_"); data_var_list_1d_size3 := ["data_m1", "data_0", "data_p1"] > > print_name_list_dcl(data_var_list_1d_size3, > "fp", "1d.coeffs/1d.cube.size3/data-var.dcl.c"); > print_data_var_assign(posn_list_1d_size3, > "data_", "1d.coeffs/1d.cube.size3/data-var.assign.c"); > > print_name_list_dcl(map(coeff_name, posn_list_1d_size3, "coeff_I_"), > "fp", "1d.coeffs/1d.cube.size3/coeff-I.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size3, "coeff_dx_"), > "fp", "1d.coeffs/1d.cube.size3/coeff-dx.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size3, "coeff_dxx_"), > "fp", "1d.coeffs/1d.cube.size3/coeff-dxx.dcl.c"); > > print_interp_cmpt__lc_of_data(posn_list_1d_size3, > "result", "coeff_I_", "data_", > "1d.coeffs/1d.cube.size3/interp-I.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size3, > "result", "coeff_dx_", "data_", > "1d.coeffs/1d.cube.size3/interp-dx.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size3, > "result", "coeff_dxx_", "data_", > "1d.coeffs/1d.cube.size3/interp-dxx.compute.c"); > ######################################## > # # generic stuff for 1d, cube, size=4 # > > data_var_list_1d_size4 := map(data_var_name, posn_list_1d_size4, "data_"); data_var_list_1d_size4 := ["data_m1", "data_0", "data_p1", "data_p2"] > > print_name_list_dcl(data_var_list_1d_size4, > "fp", "1d.coeffs/1d.cube.size4/data-var.dcl.c"); > print_data_var_assign(posn_list_1d_size4, > "data_", "1d.coeffs/1d.cube.size4/data-var.assign.c"); > > print_name_list_dcl(map(coeff_name, posn_list_1d_size4, "coeff_I_"), > "fp", "1d.coeffs/1d.cube.size4/coeff-I.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size4, "coeff_dx_"), > "fp", "1d.coeffs/1d.cube.size4/coeff-dx.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size4, "coeff_dxx_"), > "fp", "1d.coeffs/1d.cube.size4/coeff-dxx.dcl.c"); > > print_interp_cmpt__lc_of_data(posn_list_1d_size4, > "result", "coeff_I_", "data_", > "1d.coeffs/1d.cube.size4/interp-I.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size4, > "result", "coeff_dx_", "data_", > "1d.coeffs/1d.cube.size4/interp-dx.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size4, > "result", "coeff_dxx_", "data_", > "1d.coeffs/1d.cube.size4/interp-dxx.compute.c"); > ######################################## > # # generic stuff for 1d, cube, size=5 # > > data_var_list_1d_size5 := map(data_var_name, posn_list_1d_size5, "data_"); data_var_list_1d_size5 := ["data_m2", "data_m1", "data_0", "data_p1", "data_p2"] > > print_name_list_dcl(data_var_list_1d_size5, > "fp", "1d.coeffs/1d.cube.size5/data-var.dcl.c"); > print_data_var_assign(posn_list_1d_size5, > "data_", "1d.coeffs/1d.cube.size5/data-var.assign.c"); > > print_name_list_dcl(map(coeff_name, posn_list_1d_size5, "coeff_I_"), > "fp", "1d.coeffs/1d.cube.size5/coeff-I.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size5, "coeff_dx_"), > "fp", "1d.coeffs/1d.cube.size5/coeff-dx.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size5, "coeff_dxx_"), > "fp", "1d.coeffs/1d.cube.size5/coeff-dxx.dcl.c"); > > print_interp_cmpt__lc_of_data(posn_list_1d_size5, > "result", "coeff_I_", "data_", > "1d.coeffs/1d.cube.size5/interp-I.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size5, > "result", "coeff_dx_", "data_", > "1d.coeffs/1d.cube.size5/interp-dx.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size5, > "result", "coeff_dxx_", "data_", > "1d.coeffs/1d.cube.size5/interp-dxx.compute.c"); > ######################################## > # # generic stuff for 1d, cube, size=6 # > > data_var_list_1d_size6 := map(data_var_name, posn_list_1d_size6, "data_"); data_var_list_1d_size6 := ["data_m2", "data_m1", "data_0", "data_p1", "data_p2", "data_p3"] > > print_name_list_dcl(data_var_list_1d_size6, > "fp", "1d.coeffs/1d.cube.size6/data-var.dcl.c"); > print_data_var_assign(posn_list_1d_size6, > "data_", "1d.coeffs/1d.cube.size6/data-var.assign.c"); > > print_name_list_dcl(map(coeff_name, posn_list_1d_size6, "coeff_I_"), > "fp", "1d.coeffs/1d.cube.size6/coeff-I.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size6, "coeff_dx_"), > "fp", "1d.coeffs/1d.cube.size6/coeff-dx.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size6, "coeff_dxx_"), > "fp", "1d.coeffs/1d.cube.size6/coeff-dxx.dcl.c"); > > print_interp_cmpt__lc_of_data(posn_list_1d_size6, > "result", "coeff_I_", "data_", > "1d.coeffs/1d.cube.size6/interp-I.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size6, > "result", "coeff_dx_", "data_", > "1d.coeffs/1d.cube.size6/interp-dx.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size6, > "result", "coeff_dxx_", "data_", > "1d.coeffs/1d.cube.size6/interp-dxx.compute.c"); > ######################################## > # # generic stuff for 1d, cube, size=7 # > > data_var_list_1d_size7 := map(data_var_name, posn_list_1d_size7, "data_"); data_var_list_1d_size7 := [ "data_m3", "data_m2", "data_m1", "data_0", "data_p1", "data_p2", "data_p3"] > > print_name_list_dcl(data_var_list_1d_size7, > "fp", "1d.coeffs/1d.cube.size7/data-var.dcl.c"); > print_data_var_assign(posn_list_1d_size7, > "data_", "1d.coeffs/1d.cube.size7/data-var.assign.c"); > > print_name_list_dcl(map(coeff_name, posn_list_1d_size7, "coeff_I_"), > "fp", "1d.coeffs/1d.cube.size7/coeff-I.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size7, "coeff_dx_"), > "fp", "1d.coeffs/1d.cube.size7/coeff-dx.dcl.c"); > print_name_list_dcl(map(coeff_name, posn_list_1d_size7, "coeff_dxx_"), > "fp", "1d.coeffs/1d.cube.size7/coeff-dxx.dcl.c"); > > print_interp_cmpt__lc_of_data(posn_list_1d_size7, > "result", "coeff_I_", "data_", > "1d.coeffs/1d.cube.size7/interp-I.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size7, > "result", "coeff_dx_", "data_", > "1d.coeffs/1d.cube.size7/interp-dx.compute.c"); > print_interp_cmpt__lc_of_data(posn_list_1d_size7, > "result", "coeff_dxx_", "data_", > "1d.coeffs/1d.cube.size7/interp-dxx.compute.c"); > ################################################################################ > # # 1d, cube, order=1, smoothing=0 (size=2) # > # interpolating polynomial > interp_1d_cube_order1_smooth0 > := polynomial_interpolant(fn_1d_order1, coeff_list_1d_order1, > coord_list_1d, posn_list_1d_size2); interp_1d_cube_order1_smooth0 := DATA(0) + (DATA(1) - DATA(0)) x > # I > coeff_as_lc_of_data(%, posn_list_1d_size2); [COEFF(0) = 1 - x, COEFF(1) = x] > print_coeff__lc_of_data(%, "coeff_I_", "fp", > "1d.coeffs/1d.cube.order1.smooth0/coeff-I.compute.c"); bytes used=1000308, alloc=917336, time=0.08 > # d/dx > simplify( diff(interp_1d_cube_order1_smooth0,x) ); DATA(1) - DATA(0) > coeff_as_lc_of_data(%, posn_list_1d_size2); [COEFF(0) = -1, COEFF(1) = 1] > print_coeff__lc_of_data(%, "coeff_dx_", "fp", > "1d.coeffs/1d.cube.order1.smooth0/coeff-dx.compute.c"); > ######################################## > # # 1d, cube, order=2, smoothing=0 (size=3) # > # interpolating polynomial > interp_1d_cube_order2_smooth0 > := polynomial_interpolant(fn_1d_order2, coeff_list_1d_order2, > coord_list_1d, posn_list_1d_size3); interp_1d_cube_order2_smooth0 := DATA(0) + (- 1/2 DATA(-1) + 1/2 DATA(1)) x 2 + (1/2 DATA(-1) + 1/2 DATA(1) - DATA(0)) x > # I > coeff_as_lc_of_data(%, posn_list_1d_size3); 2 2 2 [COEFF(-1) = - 1/2 x + 1/2 x , COEFF(0) = 1 - x , COEFF(1) = 1/2 x + 1/2 x ] > print_coeff__lc_of_data(%, "coeff_I_", "fp", > "1d.coeffs/1d.cube.order2.smooth0/coeff-I.compute.c"); > # d/dx > simplify( diff(interp_1d_cube_order2_smooth0,x) ); - 1/2 DATA(-1) + 1/2 DATA(1) + x DATA(-1) + DATA(1) x - 2 x DATA(0) > coeff_as_lc_of_data(%, posn_list_1d_size3); [COEFF(-1) = x - 1/2, COEFF(0) = -2 x, COEFF(1) = 1/2 + x] > print_coeff__lc_of_data(%, "coeff_dx_", "fp", > "1d.coeffs/1d.cube.order2.smooth0/coeff-dx.compute.c"); bytes used=2000620, alloc=1376004, time=0.11 > # d^2/dx^2 > simplify( diff(interp_1d_cube_order2_smooth0,x,x) ); DATA(-1) + DATA(1) - 2 DATA(0) > coeff_as_lc_of_data(%, posn_list_1d_size3); [COEFF(-1) = 1, COEFF(0) = -2, COEFF(1) = 1] > print_coeff__lc_of_data(%, "coeff_dxx_", "fp", > "1d.coeffs/1d.cube.order2.smooth0/coeff-dxx.compute.c"); > ######################################## > # # 1d, cube, order=3, smoothing=0 (size=4) # > # interpolating polynomial > interp_1d_cube_order3_smooth0 > := polynomial_interpolant(fn_1d_order3, coeff_list_1d_order3, > coord_list_1d, posn_list_1d_size4); interp_1d_cube_order3_smooth0 := DATA(0) + (- 1/2 DATA(0) - 1/3 DATA(-1) + DATA(1) - 1/6 DATA(2)) x 2 + (1/2 DATA(-1) + 1/2 DATA(1) - DATA(0)) x 3 + (1/2 DATA(0) - 1/6 DATA(-1) - 1/2 DATA(1) + 1/6 DATA(2)) x > # I > coeff_as_lc_of_data(%, posn_list_1d_size4); 2 3 2 3 [COEFF(-1) = - 1/3 x + 1/2 x - 1/6 x , COEFF(0) = 1 - 1/2 x - x + 1/2 x , 2 3 3 COEFF(1) = x + 1/2 x - 1/2 x , COEFF(2) = - 1/6 x + 1/6 x ] > print_coeff__lc_of_data(%, "coeff_I_", "fp", > "1d.coeffs/1d.cube.order3.smooth0/coeff-I.compute.c"); bytes used=3000928, alloc=1703624, time=0.18 > # d/dx > simplify( diff(interp_1d_cube_order3_smooth0,x) ); - 1/2 DATA(0) - 1/3 DATA(-1) + DATA(1) - 1/6 DATA(2) + x DATA(-1) + x DATA(1) 2 2 2 - 2 x DATA(0) + 3/2 x DATA(0) - 1/2 x DATA(-1) - 3/2 x DATA(1) 2 + 1/2 x DATA(2) > coeff_as_lc_of_data(%, posn_list_1d_size4); 2 2 [COEFF(-1) = x - 1/2 x - 1/3, COEFF(0) = - 1/2 - 2 x + 3/2 x , 2 2 COEFF(1) = x + 1 - 3/2 x , COEFF(2) = 1/2 x - 1/6] > print_coeff__lc_of_data(%, "coeff_dx_", "fp", > "1d.coeffs/1d.cube.order3.smooth0/coeff-dx.compute.c"); > # d^2/dx^2 > simplify( diff(interp_1d_cube_order3_smooth0,x,x) ); DATA(-1) + DATA(1) - 2 DATA(0) + 3 x DATA(0) - x DATA(-1) - 3 x DATA(1) + x DATA(2) > coeff_as_lc_of_data(%, posn_list_1d_size4); [COEFF(-1) = 1 - x, COEFF(0) = -2 + 3 x, COEFF(1) = 1 - 3 x, COEFF(2) = x] > print_coeff__lc_of_data(%, "coeff_dxx_", "fp", > "1d.coeffs/1d.cube.order3.smooth0/coeff-dxx.compute.c"); > ######################################## > # # 1d, cube, order=4, smoothing=0 (size=5) # > # interpolating polynomial > interp_1d_cube_order4_smooth0 > := polynomial_interpolant(fn_1d_order4, coeff_list_1d_order4, > coord_list_1d, posn_list_1d_size5); bytes used=4001224, alloc=1769148, time=0.25 interp_1d_cube_order4_smooth0 := DATA(0) + (- 1/12 DATA(2) + 1/12 DATA(-2) - 2/3 DATA(-1) + 2/3 DATA(1)) x + (- 5/4 DATA(0) - 1/24 DATA(2) - 1/24 DATA(-2) + 2/3 DATA(-1) + 2/3 DATA(1)) 2 3 x + (1/12 DATA(2) - 1/12 DATA(-2) + 1/6 DATA(-1) - 1/6 DATA(1)) x + (1/24 DATA(2) + 1/24 DATA(-2) - 1/6 DATA(-1) - 1/6 DATA(1) + 1/4 DATA(0)) 4 x > # I > coeff_as_lc_of_data(%, posn_list_1d_size5); 2 3 4 [COEFF(-2) = 1/12 x - 1/24 x - 1/12 x + 1/24 x , 2 3 4 COEFF(-1) = - 2/3 x + 2/3 x + 1/6 x - 1/6 x , 2 4 COEFF(0) = - 5/4 x + 1 + 1/4 x , 3 2 4 COEFF(1) = - 1/6 x + 2/3 x + 2/3 x - 1/6 x , 3 2 4 COEFF(2) = 1/12 x - 1/12 x - 1/24 x + 1/24 x ] > print_coeff__lc_of_data(%, "coeff_I_", "fp", > "1d.coeffs/1d.cube.order4.smooth0/coeff-I.compute.c"); bytes used=5001468, alloc=1834672, time=0.33 > # d/dx > simplify( diff(interp_1d_cube_order4_smooth0,x) ); - 1/12 DATA(2) + 1/12 DATA(-2) - 2/3 DATA(-1) + 2/3 DATA(1) - 5/2 x DATA(0) - 1/12 x DATA(2) - 1/12 x DATA(-2) + 4/3 x DATA(-1) + 4/3 x DATA(1) 2 2 2 2 + 1/4 x DATA(2) - 1/4 x DATA(-2) + 1/2 x DATA(-1) - 1/2 x DATA(1) 3 3 3 3 + 1/6 x DATA(2) + 1/6 x DATA(-2) - 2/3 x DATA(-1) - 2/3 x DATA(1) 3 + x DATA(0) > coeff_as_lc_of_data(%, posn_list_1d_size5); 2 3 [COEFF(-2) = - 1/12 x - 1/4 x + 1/6 x + 1/12, 3 2 3 COEFF(-1) = - 2/3 + 4/3 x - 2/3 x + 1/2 x , COEFF(0) = - 5/2 x + x , 2 3 COEFF(1) = - 1/2 x - 2/3 x + 4/3 x + 2/3, 3 2 COEFF(2) = - 1/12 - 1/12 x + 1/6 x + 1/4 x ] > print_coeff__lc_of_data(%, "coeff_dx_", "fp", > "1d.coeffs/1d.cube.order4.smooth0/coeff-dx.compute.c"); bytes used=6001700, alloc=1900196, time=0.40 > # d^2/dx^2 > simplify( diff(interp_1d_cube_order4_smooth0,x,x) ); - 5/2 DATA(0) - 1/12 DATA(2) - 1/12 DATA(-2) + 4/3 DATA(-1) + 4/3 DATA(1) 2 + 1/2 x DATA(2) - 1/2 x DATA(-2) + x DATA(-1) - x DATA(1) + 1/2 x DATA(2) 2 2 2 2 + 1/2 x DATA(-2) - 2 x DATA(-1) - 2 x DATA(1) + 3 x DATA(0) > coeff_as_lc_of_data(%, posn_list_1d_size5); 2 2 [COEFF(-2) = - 1/12 - 1/2 x + 1/2 x , COEFF(-1) = -2 x + x + 4/3, 2 2 COEFF(0) = - 5/2 + 3 x , COEFF(1) = -x + 4/3 - 2 x , 2 COEFF(2) = 1/2 x - 1/12 + 1/2 x ] > print_coeff__lc_of_data(%, "coeff_dxx_", "fp", > "1d.coeffs/1d.cube.order4.smooth0/coeff-dxx.compute.c"); bytes used=7001904, alloc=1900196, time=0.47 > ######################################## > # # 1d, cube, order=5, smoothing=0 (size=6) # > # interpolating polynomial > interp_1d_cube_order5_smooth0 > := polynomial_interpolant(fn_1d_order5, coeff_list_1d_order5, > coord_list_1d, posn_list_1d_size6); bytes used=8002732, alloc=1900196, time=0.54 interp_1d_cube_order5_smooth0 := DATA(0) + (- 1/2 DATA(-1) - 1/4 DATA(2) - 1/3 DATA(0) + 1/20 DATA(-2) + DATA(1) + 1/30 DATA(3)) x + (- 5/4 DATA(0) - 1/24 DATA(2) - 1/24 DATA(-2) + 2/3 DATA(-1) + 2/3 DATA(1)) 2 x + (- 1/24 DATA(-1) + 7/24 DATA(2) + 5/12 DATA(0) - 1/24 DATA(-2) 3 - 7/12 DATA(1) - 1/24 DATA(3)) x + (1/24 DATA(2) + 1/24 DATA(-2) - 1/6 DATA(-1) - 1/6 DATA(1) + 1/4 DATA(0)) 4 x + (1/24 DATA(-1) - 1/24 DATA(2) - 1/12 DATA(0) - 1/120 DATA(-2) 5 + 1/12 DATA(1) + 1/120 DATA(3)) x > # I > coeff_as_lc_of_data(%, posn_list_1d_size6); 2 3 4 5 [COEFF(-2) = 1/20 x - 1/24 x - 1/24 x + 1/24 x - 1/120 x , 2 3 4 5 COEFF(-1) = - 1/2 x + 2/3 x - 1/24 x - 1/6 x + 1/24 x , 2 3 4 5 COEFF(0) = 1 - 1/3 x - 5/4 x + 5/12 x + 1/4 x - 1/12 x , 2 3 4 5 COEFF(1) = x + 2/3 x - 7/12 x - 1/6 x + 1/12 x , 3 4 2 5 COEFF(2) = - 1/4 x + 7/24 x + 1/24 x - 1/24 x - 1/24 x , 5 3 COEFF(3) = 1/30 x + 1/120 x - 1/24 x ] > print_coeff__lc_of_data(%, "coeff_I_", "fp", > "1d.coeffs/1d.cube.order5.smooth0/coeff-I.compute.c"); bytes used=9002940, alloc=1965720, time=0.63 > # d/dx > simplify( diff(interp_1d_cube_order5_smooth0,x) ); - 1/3 DATA(0) + DATA(1) - 1/2 DATA(-1) - 1/4 DATA(2) + 1/30 DATA(3) 2 2 3 3 - 7/4 x DATA(1) - 1/8 x DATA(3) + 1/6 x DATA(2) + 1/6 x DATA(-2) 3 3 3 4 - 2/3 x DATA(-1) - 2/3 x DATA(1) + x DATA(0) + 5/24 x DATA(-1) 4 4 - 5/24 x DATA(2) - 5/12 x DATA(0) - 5/2 x DATA(0) - 1/12 x DATA(2) 2 - 1/12 x DATA(-2) + 4/3 x DATA(-1) + 4/3 x DATA(1) - 1/8 x DATA(-1) 2 2 2 4 + 7/8 x DATA(2) + 5/4 x DATA(0) - 1/8 x DATA(-2) - 1/24 x DATA(-2) 4 4 + 5/12 x DATA(1) + 1/24 x DATA(3) + 1/20 DATA(-2) > coeff_as_lc_of_data(%, posn_list_1d_size6); bytes used=10003740, alloc=1965720, time=0.71 2 3 4 [COEFF(-2) = - 1/8 x - 1/12 x + 1/6 x + 1/20 - 1/24 x , 4 3 2 COEFF(-1) = 5/24 x - 2/3 x + 4/3 x - 1/2 - 1/8 x , 2 4 3 COEFF(0) = 5/4 x - 5/12 x + x - 1/3 - 5/2 x, 4 2 3 COEFF(1) = 5/12 x + 4/3 x - 7/4 x + 1 - 2/3 x , 4 2 3 COEFF(2) = - 1/4 - 5/24 x - 1/12 x + 7/8 x + 1/6 x , 4 2 COEFF(3) = 1/24 x + 1/30 - 1/8 x ] > print_coeff__lc_of_data(%, "coeff_dx_", "fp", > "1d.coeffs/1d.cube.order5.smooth0/coeff-dx.compute.c"); bytes used=11004108, alloc=1965720, time=0.78 > # d^2/dx^2 > simplify( diff(interp_1d_cube_order5_smooth0,x,x) ); - 5/2 DATA(0) - 1/12 DATA(2) - 1/12 DATA(-2) + 4/3 DATA(-1) + 4/3 DATA(1) - 1/4 x DATA(-1) + 7/4 x DATA(2) + 5/2 x DATA(0) - 1/4 x DATA(-2) 2 2 - 7/2 x DATA(1) - 1/4 x DATA(3) + 1/2 x DATA(2) + 1/2 x DATA(-2) 2 2 2 3 - 2 x DATA(-1) - 2 x DATA(1) + 3 x DATA(0) + 5/6 x DATA(-1) 3 3 3 3 - 5/6 x DATA(2) - 5/3 x DATA(0) - 1/6 x DATA(-2) + 5/3 x DATA(1) 3 + 1/6 x DATA(3) > coeff_as_lc_of_data(%, posn_list_1d_size6); 3 2 [COEFF(-2) = - 1/12 - 1/6 x + 1/2 x - 1/4 x, 3 2 COEFF(-1) = 5/6 x - 1/4 x + 4/3 - 2 x , 3 2 COEFF(0) = - 5/3 x + 3 x + 5/2 x - 5/2, 3 2 COEFF(1) = 5/3 x - 7/2 x + 4/3 - 2 x , 3 2 3 COEFF(2) = - 1/12 + 7/4 x - 5/6 x + 1/2 x , COEFF(3) = 1/6 x - 1/4 x] > print_coeff__lc_of_data(%, "coeff_dxx_", "fp", > "1d.coeffs/1d.cube.order5.smooth0/coeff-dxx.compute.c"); bytes used=12004376, alloc=1965720, time=0.86 > ######################################## > # # 1d, cube, order=6, smoothing=0 (size=7) # > # interpolating polynomial > interp_1d_cube_order6_smooth0 > := polynomial_interpolant(fn_1d_order6, coeff_list_1d_order6, > coord_list_1d, posn_list_1d_size7); bytes used=13004532, alloc=1965720, time=0.95 interp_1d_cube_order6_smooth0 := DATA(0) + (- 3/4 DATA(-1) - 3/20 DATA(2) / - 1/60 DATA(-3) + 3/20 DATA(-2) + 3/4 DATA(1) + 1/60 DATA(3)) x + | \ 3/4 DATA(-1) + 1/180 DATA(3) - 3/40 DATA(-2) + 1/180 DATA(-3) + 3/4 DATA(1) 49 \ 2 /13 - -- DATA(0) - 3/40 DATA(2)| x + |-- DATA(-1) + 1/6 DATA(2) 36 / \48 13 \ 3 / + 1/48 DATA(-3) - 1/6 DATA(-2) - -- DATA(1) - 1/48 DATA(3)| x + | 48 / \ 13 13 - -- DATA(-1) - 1/144 DATA(3) + 1/12 DATA(-2) - 1/144 DATA(-3) - -- DATA(1) 48 48 \ 4 + 7/18 DATA(0) + 1/12 DATA(2)| x + (- 1/48 DATA(-1) - 1/60 DATA(2) / 5 - 1/240 DATA(-3) + 1/60 DATA(-2) + 1/48 DATA(1) + 1/240 DATA(3)) x + ( 1/48 DATA(-1) + 1/720 DATA(3) - 1/120 DATA(-2) + 1/720 DATA(-3) 6 + 1/48 DATA(1) - 1/36 DATA(0) - 1/120 DATA(2)) x > # I > coeff_as_lc_of_data(%, posn_list_1d_size7); 2 3 4 5 6 [COEFF(-3) = - 1/60 x + 1/180 x + 1/48 x - 1/144 x - 1/240 x + 1/720 x , 2 3 4 5 6 COEFF(-2) = 3/20 x - 3/40 x - 1/6 x + 1/12 x + 1/60 x - 1/120 x , 2 13 3 13 4 5 6 COEFF(-1) = - 3/4 x + 3/4 x + -- x - -- x - 1/48 x + 1/48 x , 48 48 4 49 2 6 COEFF(0) = 7/18 x - -- x + 1 - 1/36 x , 36 13 3 2 5 6 13 4 COEFF(1) = - -- x + 3/4 x + 3/4 x + 1/48 x + 1/48 x - -- x , 48 48 3 2 5 6 4 COEFF(2) = 1/6 x - 3/20 x - 3/40 x - 1/60 x - 1/120 x + 1/12 x , 3 2 5 6 4 COEFF(3) = - 1/48 x + 1/60 x + 1/180 x + 1/240 x + 1/720 x - 1/144 x ] > print_coeff__lc_of_data(%, "coeff_I_", "fp", > "1d.coeffs/1d.cube.order6.smooth0/coeff-I.compute.c"); bytes used=14004752, alloc=1965720, time=1.02 bytes used=15005080, alloc=1965720, time=1.11 > # d/dx > simplify( diff(interp_1d_cube_order6_smooth0,x) ); bytes used=16005600, alloc=1965720, time=1.19 2 3/4 DATA(1) - 3/4 DATA(-1) - 3/20 DATA(2) - 1/60 DATA(-3) + 1/16 x DATA(-3) 13 2 2 13 3 3 - -- x DATA(1) - 1/16 x DATA(3) - -- x DATA(-1) - 1/36 x DATA(3) 16 12 3 3 13 3 3 + 1/3 x DATA(-2) - 1/36 x DATA(-3) - -- x DATA(1) + 14/9 x DATA(0) 12 3 4 4 4 + 1/3 x DATA(2) - 5/48 x DATA(-1) - 1/12 x DATA(2) - 1/48 x DATA(-3) 4 4 4 5 + 1/12 x DATA(-2) + 5/48 x DATA(1) + 1/48 x DATA(3) + 1/8 x DATA(-1) 5 5 5 5 + 1/120 x DATA(3) - 1/20 x DATA(-2) + 1/120 x DATA(-3) + 1/8 x DATA(1) 5 5 2 - 1/6 x DATA(0) - 1/20 x DATA(2) - 1/2 x DATA(-2) + 3/2 x DATA(-1) + 1/90 x DATA(3) - 3/20 x DATA(-2) + 1/90 x DATA(-3) + 3/2 x DATA(1) 49 13 2 2 - -- x DATA(0) - 3/20 x DATA(2) + -- x DATA(-1) + 1/2 x DATA(2) 18 16 + 1/60 DATA(3) + 3/20 DATA(-2) > coeff_as_lc_of_data(%, posn_list_1d_size7); 2 5 3 4 [COEFF(-3) = 1/16 x + 1/120 x - 1/60 + 1/90 x - 1/36 x - 1/48 x , 4 5 2 3 COEFF(-2) = 1/12 x - 1/20 x - 3/20 x - 1/2 x + 3/20 + 1/3 x , 5 13 2 4 13 3 COEFF(-1) = 1/8 x + -- x - 3/4 - 5/48 x - -- x + 3/2 x, 16 12 5 3 49 COEFF(0) = - 1/6 x + 14/9 x - -- x, 18 4 13 3 5 13 2 COEFF(1) = 3/4 + 5/48 x - -- x + 1/8 x + 3/2 x - -- x , 12 16 5 3 4 2 COEFF(2) = - 3/20 - 1/20 x + 1/3 x - 1/12 x + 1/2 x - 3/20 x, 5 3 2 4 COEFF(3) = 1/90 x + 1/120 x - 1/36 x - 1/16 x + 1/60 + 1/48 x ] > print_coeff__lc_of_data(%, "coeff_dx_", "fp", > "1d.coeffs/1d.cube.order6.smooth0/coeff-dx.compute.c"); bytes used=17005760, alloc=1965720, time=1.28 > # d^2/dx^2 > simplify( diff(interp_1d_cube_order6_smooth0,x,x) ); bytes used=18008016, alloc=1965720, time=1.37 49 - -- DATA(0) + 3/2 DATA(1) + 3/2 DATA(-1) - 3/20 DATA(2) + 1/90 DATA(-3) 18 2 2 2 3 - 1/12 x DATA(-3) - 13/4 x DATA(1) - 1/12 x DATA(3) - 5/12 x DATA(-1) 3 3 3 3 + 1/12 x DATA(3) + 1/3 x DATA(-2) - 1/12 x DATA(-3) + 5/12 x DATA(1) 3 4 4 4 - 1/3 x DATA(2) + 5/8 x DATA(-1) - 1/4 x DATA(2) + 1/24 x DATA(-3) 4 4 4 2 - 1/4 x DATA(-2) + 5/8 x DATA(1) + 1/24 x DATA(3) + x DATA(-2) + 13/8 x DATA(-1) - 1/8 x DATA(3) - x DATA(-2) + 1/8 x DATA(-3) 2 2 - 13/8 x DATA(1) + x DATA(2) - 13/4 x DATA(-1) + x DATA(2) 2 4 + 1/90 DATA(3) - 3/20 DATA(-2) + 14/3 x DATA(0) - 5/6 x DATA(0) > coeff_as_lc_of_data(%, posn_list_1d_size7); 2 3 4 [COEFF(-3) = - 1/12 x + 1/8 x - 1/12 x + 1/90 + 1/24 x , 3 2 4 COEFF(-2) = 1/3 x + x - x - 1/4 x - 3/20, 4 2 3 COEFF(-1) = 5/8 x + 13/8 x - 13/4 x - 5/12 x + 3/2, 4 49 2 COEFF(0) = - 5/6 x - -- + 14/3 x , 18 3 2 4 COEFF(1) = - 13/8 x + 5/12 x - 13/4 x + 3/2 + 5/8 x , 2 3 4 COEFF(2) = x + x - 1/3 x - 3/20 - 1/4 x , 3 2 4 COEFF(3) = 1/12 x - 1/12 x + 1/90 + 1/24 x - 1/8 x] > print_coeff__lc_of_data(%, "coeff_dxx_", "fp", > "1d.coeffs/1d.cube.order6.smooth0/coeff-dxx.compute.c"); bytes used=19008232, alloc=1965720, time=1.45 > ######################################## > quit bytes used=19846220, alloc=1965720, time=1.53