[genius] Fri Jul 24 16:32:32 2009 Jiri (George) Lebl <jirka 5z com>



commit 46727ef708e1620c36e2a5f43f0af60da1bd9485
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Fri Jul 24 16:32:35 2009 -0500

    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.

 ChangeLog                |   10 ++++++++++
 lib/calculus/fourier.gel |   36 +++++++++++++++++++++++++++++++++++-
 lib/library-strings.c    |    4 +++-
 src/dict.c               |    9 +--------
 src/dict.h               |   24 +++++++++++++++++-------
 src/eval.c               |    5 ++++-
 6 files changed, 70 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5ad09a2..9390398 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+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
diff --git a/lib/calculus/fourier.gel b/lib/calculus/fourier.gel
index c15a3aa..bde51c1 100644
--- a/lib/calculus/fourier.gel
+++ b/lib/calculus/fourier.gel
@@ -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) =
 	(
diff --git a/lib/library-strings.c b/lib/library-strings.c
index f28b39b..c3570f1 100644
--- a/lib/library-strings.c
+++ b/lib/library-strings.c
@@ -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");
diff --git a/src/dict.c b/src/dict.c
index 617a90d..3600ef7 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -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
diff --git a/src/dict.h b/src/dict.h
index 7c2a7ae..3278fb9 100644
--- a/src/dict.h
+++ b/src/dict.h
@@ -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
diff --git a/src/eval.c b/src/eval.c
index 22f7711..d364989 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]