Commit 46727ef7 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl

Fri Jul 24 16:32:32 2009 Jiri (George) Lebl <jirka@5z.com>

	* lib/calculus/fourier.gel: add NumericalFourierCosineSeriesFunction
	  and NumericalFourierSineSeriesFunction and fixup some doc stringss

	* src/eval.c, src/dict.c: build the subst_dict on first function
	  evaluate.  This avoids subst lists for simple functions, plus
	  it makes the global identifier no-substitution behaviour slightly
	  more easy to see.
parent e5427170
Fri Jul 24 16:32:32 2009 Jiri (George) Lebl <jirka@5z.com>
* lib/calculus/fourier.gel: add NumericalFourierCosineSeriesFunction
and NumericalFourierSineSeriesFunction and fixup some doc stringss
* src/eval.c, src/dict.c: build the subst_dict on first function
evaluate. This avoids subst lists for simple functions, plus
it makes the global identifier no-substitution behaviour slightly
more easy to see.
Fri Jul 24 16:01:28 2009 Jiri (George) Lebl <jirka@5z.com>
* src/calc.c, src/compil.c: Correctly compile/decompile all the new
......
......@@ -15,7 +15,41 @@ function NumericalFourierSeriesFunction(f,L,N) =
FourierSeriesFunction(c@(1),c@(2),L)
)
SetHelp("NumericalFourierSeriesFunction","calculus","Return a function which is the fourier series of f with half-period L with coefficients up to N computed numerically");
SetHelp("NumericalFourierSeriesFunction","calculus","Return a function which is the Fourier series of f with half-period L with coefficients up to N computed numerically");
function NumericalFourierSineSeriesFunction(f,L,N) =
(
local *;
# check arguments
if not IsFunctionOrIdentifier(f) then
(error("NumericalFourierSineSeriesFunction: argument f must be a function");bailout)
else if not (IsReal(L) and L > 0) then
(error("NumericalFourierSineSeriesFunction: argument L must be a positive real value");bailout)
else if not IsPositiveInteger(N) then
(error("NumericalFourierSineSeriesFunction: argument N must be a positive integer");bailout);
b = NumericalFourierSineSeriesCoefficients(f,L,N);
FourierSeriesFunction(null,b,L)
)
SetHelp("NumericalFourierSineSeriesFunction","calculus","Return a function which is the Fourier sine series of f on [0,L] with coefficients up to N computed numerically");
function NumericalFourierCosineSeriesFunction(f,L,N) =
(
local *;
# check arguments
if not IsFunctionOrIdentifier(f) then
(error("NumericalFourierCosineSeriesFunction: argument f must be a function");bailout)
else if not (IsReal(L) and L > 0) then
(error("NumericalFourierCosineSeriesFunction: argument L must be a positive real value");bailout)
else if not IsPositiveInteger(N) then
(error("NumericalFourierCosineSeriesFunction: argument N must be a positive integer");bailout);
a = NumericalFourierCosineSeriesCoefficients(f,L,N);
FourierSeriesFunction(a,null,L)
)
SetHelp("NumericalFourierCosineSeriesFunction","calculus","Return a function which is the Fourier cosine series of f on [0,L] with coefficients up to N computed numerically");
function FourierSeriesFunction(a,b,L) =
(
......
......@@ -193,9 +193,11 @@ char *fake = N_("Calculate the limit of a real-valued function at x0. Tries to
char *fake = N_("Integration by midpoint rule");
char *fake = N_("Attempt to calculate numerical derivative");
char *fake = N_("Numerically compute the coefficients for a cosine Fourier series for a function on [0,L] up to the Nth coefficient.");
char *fake = N_("Return a function which is the Fourier cosine series of f on [0,L] with coefficients up to N computed numerically");
char *fake = N_("Numerically compute the coefficients for a Fourier series with half-period L up to the Nth coefficient.");
char *fake = N_("Return a function which is the fourier series of f with half-period L with coefficients up to N computed numerically");
char *fake = N_("Return a function which is the Fourier series of f with half-period L with coefficients up to N computed numerically");
char *fake = N_("Numerically compute the coefficients for a sine Fourier series for a function on [0,L] up to the Nth coefficient.");
char *fake = N_("Return a function which is the Fourier sine series of f on [0,L] with coefficients up to N computed numerically");
char *fake = N_("Integration by rule set in NumericalIntegralFunction of f from a to b using NumericalIntegralSteps steps");
char *fake = N_("Attempt to calculate numerical left derivative");
char *fake = N_("Attempt to calculate the limit of f(step_fun(i)) as i goes from 1 to N");
......
......@@ -822,14 +822,7 @@ d_popcontext (void)
if ((func->type == GEL_USER_FUNC ||
func->type == GEL_VARIABLE_FUNC) &&
func->context >= context.top) {
D_ENSURE_USER_BODY (func);
if ( ! func->built_subst_dict) {
func->subst_dict = gel_get_ids_for_extradict (NULL,
func->named_args,
func->local_idents,
func->data.user);
func->built_subst_dict = 1;
}
D_ENSURE_SUBST_DICT (func);
func->extra_dict =
gel_subst_local_vars (func->extra_dict, &(func->subst_dict));
/* With substitution, context of the function is
......
......@@ -136,15 +136,25 @@ void d_protect_all(void);
void d_add_named_args (GelEFunc *f, const char *args);
#define D_ENSURE_USER_BODY(f) \
if G_UNLIKELY (f->data.user == NULL) { \
g_assert (f->id->uncompiled != NULL); \
f->data.user = \
gel_decompile_tree (f->id->uncompiled); \
f->id->uncompiled = NULL; \
if G_UNLIKELY ((f)->data.user == NULL) { \
g_assert ((f)->id->uncompiled != NULL); \
(f)->data.user = \
gel_decompile_tree ((f)->id->uncompiled); \
(f)->id->uncompiled = NULL; \
/* On error give null tree */ \
if (f->data.user == NULL) \
f->data.user = gel_makenum_null (); \
if ((f)->data.user == NULL) \
(f)->data.user = gel_makenum_null (); \
} \
#define D_ENSURE_SUBST_DICT(f) \
D_ENSURE_USER_BODY (f); \
if ( ! (f)->built_subst_dict) { \
(f)->subst_dict = gel_get_ids_for_extradict (NULL, \
(f)->named_args, \
(f)->local_idents, \
(f)->data.user); \
(f)->built_subst_dict = 1; \
}
#endif
......@@ -6907,7 +6907,10 @@ iter_eval_etree(GelCtx *ctx)
(n->func.func->type == GEL_USER_FUNC ||
n->func.func->type == GEL_VARIABLE_FUNC) &&
d_curcontext () != 0) {
d_put_on_subst_list (n->func.func);
D_ENSURE_SUBST_DICT (n->func.func);
if (n->func.func->subst_dict != NULL) {
d_put_on_subst_list (n->func.func);
}
}
WHACK_SAVEDN_POP;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment