[genius] Wed Apr 11 16:56:15 2012 Jiri (George) Lebl <jirka 5z com>



commit 4996c6ea11769b5e8ffe8784db9c936e51038a7d
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Wed Apr 11 16:56:22 2012 -0500

    Wed Apr 11 16:56:15 2012  Jiri (George) Lebl <jirka 5z com>
    
    	* src/symbolic.c: fix derivatives of Im and Re to be the z
    	  derivatives.
    
    	* src/funclib.c, src/symbolic.c, help/C/gel-function-list.xml:
    	  add the sinc function and its derivative.

 ChangeLog                    |    8 ++++++++
 NEWS                         |    2 ++
 help/C/gel-function-list.xml |   14 ++++++++++++++
 src/funclib.c                |   35 ++++++++++++++++++++++++++++++++++-
 src/geniustests.txt          |    2 ++
 src/symbolic.c               |   12 +++++++-----
 6 files changed, 67 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2bf2858..2ae5903 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Apr 11 16:56:15 2012  Jiri (George) Lebl <jirka 5z com>
+
+	* src/symbolic.c: fix derivatives of Im and Re to be the z
+	  derivatives.
+
+	* src/funclib.c, src/symbolic.c, help/C/gel-function-list.xml:
+	  add the sinc function and its derivative.
+
 Mon Apr 09 21:12:40 2012  Jiri (George) Lebl <jirka 5z com>
 
 	* src/matop.c: forgotten nargs setting led to a crash when
diff --git a/NEWS b/NEWS
index 368e3ca..dc4fb2c 100644
--- a/NEWS
+++ b/NEWS
@@ -2,10 +2,12 @@ Changes to 1.0.16
 
 * Simpler output when typing "help foo" when foo is neither defined nor
   documented.
+* Add sinc function
 * Fix possible uninitialized crash when reading badly formed standard library
   (should never happen but ...)
 * Fix LinearRecursiveSequence and allow it to take vector for n
 * Fix crash on uninitialized variables in conjugate transpose
+* Fix derivatives of Im and Re
 * Avoid double error about uninitialized variables
 * Spelling fixes and documentation fixes (me, LucPionchon)
 
diff --git a/help/C/gel-function-list.xml b/help/C/gel-function-list.xml
index e2ae973..9ed54e1 100644
--- a/help/C/gel-function-list.xml
+++ b/help/C/gel-function-list.xml
@@ -4615,6 +4615,20 @@ and has period <userinput>b-a</userinput>.</para>
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-sinc">
+         <term>sinc</term>
+         <listitem>
+          <synopsis>sinc (x)</synopsis>
+	  <para>Calculates the unnormalized sinc function, that is
+		  <userinput>sin(x)/x</userinput>.
+		  If you want the normalized function call <userinput>sinc(pi*x)</userinput>.</para>
+          <para>
+	    See
+	    <ulink url="http://en.wikipedia.org/wiki/Sinc";>Wikipedia</ulink> for more information.
+	  </para>
+         </listitem>
+        </varlistentry>
+
       </variablelist>
     </sect1>
 
diff --git a/src/funclib.c b/src/funclib.c
index 131f3ac..0b7d3d6 100644
--- a/src/funclib.c
+++ b/src/funclib.c
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2011 Jiri (George) Lebl
+ * Copyright (C) 1997-2012 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -45,6 +45,7 @@ static GelEFunc *_internal_exp_function = NULL;
 
 static GelEFunc *conj_function = NULL;
 static GelEFunc *sin_function = NULL;
+static GelEFunc *sinc_function = NULL;
 static GelEFunc *cos_function = NULL;
 static GelEFunc *sinh_function = NULL;
 static GelEFunc *cosh_function = NULL;
@@ -1172,6 +1173,34 @@ sin_op(GelCtx *ctx, GelETree * * a, gboolean *exception)
 	return gel_makenum_use(fr);
 }
 
+/*sinc function*/
+static GelETree *
+sinc_op(GelCtx *ctx, GelETree * * a, gboolean *exception)
+{
+	mpw_t fr;
+
+	if (a[0]->type == GEL_FUNCTION_NODE ||
+	    a[0]->type == GEL_IDENTIFIER_NODE) {
+		return gel_function_from_function (sinc_function, a[0]);
+	}
+
+	if(a[0]->type==GEL_MATRIX_NODE)
+		return gel_apply_func_to_matrix(ctx,a[0],sinc_op,"sinc", exception);
+
+	if G_UNLIKELY ( ! check_argument_number (a, 0, "sinc"))
+		return NULL;
+
+	if (mpw_zero_p (a[0]->val.value))
+		return gel_makenum_ui(1);
+
+	mpw_init(fr);
+
+	mpw_sin(fr,a[0]->val.value);
+	mpw_div(fr,fr,a[0]->val.value);
+
+	return gel_makenum_use(fr);
+}
+
 /*sinh function*/
 static GelETree *
 sinh_op(GelCtx *ctx, GelETree * * a, gboolean *exception)
@@ -6404,6 +6433,10 @@ gel_funclib_addall(void)
 	atan_function = f;
 	ALIAS (arctan, 1, atan);
 
+	FUNC (sinc, 1, "x", "functions", N_("Calculates the sinc function, that is sin(x)/x"));
+	f->no_mod_all_args = 1;
+	sinc_function = f;
+
 	FUNC (atan2, 2, "y,x", "trigonometry", N_("Calculates the arctan2 function (arctan(y/x) if x>0)"));
 	f->no_mod_all_args = 1;
 	ALIAS (arctan2, 1, atan2);
diff --git a/src/geniustests.txt b/src/geniustests.txt
index a28847f..fbbe7a2 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -1107,6 +1107,8 @@ LinearRecursiveSequence ([1,3,5],[1,2,-1],null)+1		((null)+1)
 prod n=1 to 20 do (A=randint(10,7,7)-4*ones(7,7);IsPositiveSemidefinite(A'*A))	true
 prod n=1 to 20 do (A=randint(10,3,7)-4*ones(3,7);IsPositiveSemidefinite(A'*A))	true
 prod n=1 to 20 do (A=randint(10,7,7)-4*ones(7,7);(rank(A'*A) < 7) or IsPositiveDefinite(A'*A))	true
+sinc(0)==1							true
+sinc(5)==sin(5)/5						true
 load "nullspacetest.gel"					true
 load "longtest.gel"						true
 load "testprec.gel"						true
diff --git a/src/symbolic.c b/src/symbolic.c
index 87bb4e9..604b74a 100644
--- a/src/symbolic.c
+++ b/src/symbolic.c
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2009 Jiri (George) Lebl
+ * Copyright (C) 1997-2012 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -99,16 +99,16 @@ gel_differentiate_func1_expr (GelToken *tok)
 	DERIVATIVE_ENTRY ("conj", "0");
 
 	DERIVATIVE_ENTRY ("exp", "exp(x)");
-	/* Better then 1/x, since doing multiple derivatives
+	/* Better than 1/x, since doing multiple derivatives
 	   on that sucks without simplification */
 	DERIVATIVE_ENTRY ("ln", "x^-1");
 	DERIVATIVE_ENTRY ("log", "x^-1");
 	DERIVATIVE_ENTRY ("log2", "log2(e)*x^-1");
 	DERIVATIVE_ENTRY ("log10", "log10(e)*x^-1");
 
-	/* treat z and zbar separately */
-	DERIVATIVE_ENTRY ("Re", "(1/2)*conj(x)");
-	DERIVATIVE_ENTRY ("Im", "(-1/2i)*conj(x)");
+	/* treat z and zbar separately, we are differentiating in z */
+	DERIVATIVE_ENTRY ("Re", "(1/2)");
+	DERIVATIVE_ENTRY ("Im", "(-1/2i)");
 
 	DERIVATIVE_ENTRY ("sin", "cos(x)");
 	DERIVATIVE_ENTRY ("sinh", "cosh(x)");
@@ -123,6 +123,8 @@ gel_differentiate_func1_expr (GelToken *tok)
 	DERIVATIVE_ENTRY ("cot", "-csc(x)^2");
 	DERIVATIVE_ENTRY ("coth", "-csch(x)^2");
 
+	DERIVATIVE_ENTRY ("sinc", "cos(x)*x^(-1)-sinc(x)*x^(-1)");
+
 	/* FIXME: check these, I don't trust the CRC handbook */
 	DERIVATIVE_ENTRY_ALIAS ("asin", "arcsin", "1/sqrt(1-x^2)");
 	DERIVATIVE_ENTRY_ALIAS ("asinh", "arcsinh", "1/sqrt(1+x^2)");



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