[genius] Thu Jun 09 16:56:00 2016 Jiri (George) Lebl <jirka 5z com>



commit eca66bc74a5a42609156e5a7993849dc1491dec1
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date:   Thu Jun 9 16:59:53 2016 -0500

    Thu Jun 09 16:56:00 2016  Jiri (George) Lebl <jirka 5z com>
    
        * help/C/genius.xml, lib/combinatorics/factorial.gel:
          Apply patch from Anders Jonsson to fix Subfactorial (definition
          wrong).  Also, let Subfactorial, Factorial, DoubleFactorial
          take a matrix and apply function on matrix.
    
        * lib/functions/elementary.gel: fix acos
    
        * src/geniustests.txt, src/longtest.gel: Add a few tests including
          test for some inverse trig functions
    
        * src/eval.c, src/funclib.c, src/gnome-genius.c, src/mpwrap.c,
          help/C/genius.xml, lib/equation_solving/newton.gel,
          lib/misc/misc.gel, lib/combinatorics/recursive_sequences.gel:
          Some string fixes also from Anders Jonsson

 ChangeLog                                 |   17 +++++++++++++++++
 help/C/genius.xml                         |    6 +++---
 lib/combinatorics/factorial.gel           |   18 ++++++++++++------
 lib/combinatorics/recursive_sequences.gel |    2 +-
 lib/equation_solving/newton.gel           |    4 ++--
 lib/functions/elementary.gel              |    4 +++-
 lib/library-strings.c                     |   10 +++++-----
 lib/misc/misc.gel                         |    2 +-
 src/eval.c                                |    9 ++++++---
 src/funclib.c                             |    2 +-
 src/geniustests.txt                       |    5 +++++
 src/gnome-genius.c                        |    6 +++---
 src/longtest.gel                          |   25 ++++++++++++++++++++++---
 src/mpwrap.c                              |    2 +-
 14 files changed, 82 insertions(+), 30 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 88fadfb..d248ee9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Thu Jun 09 16:56:00 2016  Jiri (George) Lebl <jirka 5z com>
+
+       * help/C/genius.xml, lib/combinatorics/factorial.gel:
+         Apply patch from Anders Jonsson to fix Subfactorial (definition
+         wrong).  Also, let Subfactorial, Factorial, DoubleFactorial
+         take a matrix and apply function on matrix.
+
+       * lib/functions/elementary.gel: fix acos
+       
+       * src/geniustests.txt, src/longtest.gel: Add a few tests including
+         test for some inverse trig functions
+
+       * src/eval.c, src/funclib.c, src/gnome-genius.c, src/mpwrap.c,
+         help/C/genius.xml, lib/equation_solving/newton.gel,
+         lib/misc/misc.gel, lib/combinatorics/recursive_sequences.gel:
+         Some string fixes also from Anders Jonsson
+
 Mon May 23 16:20:17 2016  Jiri (George) Lebl <jirka 5z com>
 
        * src/graphing.c: fix segfault when rotate animation is running and a
diff --git a/help/C/genius.xml b/help/C/genius.xml
index d70f7c3..4535c29 100644
--- a/help/C/genius.xml
+++ b/help/C/genius.xml
@@ -6874,7 +6874,7 @@ divided to make all pivots 1.</para>
          <term><anchor id="gel-function-GaloisMatrix"/>GaloisMatrix</term>
          <listitem>
           <synopsis>GaloisMatrix (combining_rule)</synopsis>
-          <para>Galois matrix given a linear combining rule (a_1*x_+...+a_n*x_n=x_(n+1)).</para>
+          <para>Galois matrix given a linear combining rule (a_1*x_1+...+a_n*x_n=x_(n+1)).</para>
          </listitem>
         </varlistentry>
 
@@ -7049,7 +7049,7 @@ do (
          <term><anchor id="gel-function-Subfactorial"/>Subfactorial</term>
          <listitem>
           <synopsis>Subfactorial (n)</synopsis>
-          <para>Subfactorial: n! times sum_{k=1}^n (-1)^k/k!.</para>
+          <para>Subfactorial: n! times sum_{k=0}^n (-1)^k/k!.</para>
          </listitem>
         </varlistentry>
 
@@ -8004,7 +8004,7 @@ and has period <userinput>b-a</userinput>.</para>
          <term><anchor id="gel-function-HalleysMethod"/>HalleysMethod</term>
          <listitem>
           <synopsis>HalleysMethod (f,df,ddf,guess,epsilon,maxn)</synopsis>
-         <para>Find zeros using Halleys's method.  <varname>f</varname> is
+         <para>Find zeros using Halley's method.  <varname>f</varname> is
                  the function, <varname>df</varname> is the derivative of
                  <varname>f</varname>, and <varname>ddf</varname> is the second derivative of
                  <varname>f</varname>.  <varname>guess</varname> is the initial
diff --git a/lib/combinatorics/factorial.gel b/lib/combinatorics/factorial.gel
index d08319e..7c0f59d 100644
--- a/lib/combinatorics/factorial.gel
+++ b/lib/combinatorics/factorial.gel
@@ -1,14 +1,16 @@
 ## Some combinatorial functions
 
 # Subfactorial
-# Subfactorial(n)=n! times \sum_{k=1}^n (-1)^k/k!
+# Subfactorial(n)=n! times \sum_{k=0}^n (-1)^k/k!
 # This is the number of permutations of n objects that leaves none of the
 # objects unchanged.
-SetHelp("Subfactorial","combinatorics","Subfactorial: n! times sum_{k=1}^n (-1)^k/k!");
+SetHelp("Subfactorial","combinatorics","Subfactorial: n! times sum_{k=0}^n (-1)^k/k!");
 function Subfactorial(n) = (
-       if not IsNonNegativeInteger(n) then
+       if(IsMatrix(n)) then
+               return ApplyOverMatrix(n,Subfactorial)
+       else if not IsNonNegativeInteger(n) then
                (error("Subfactorial: argument not an integer >= 0");bailout);
-       (n!) * sum k=1 to n do ((-1)^k)/(k!)
+       (n!) * sum k=0 to n do ((-1)^k)/(k!)
 )
 
 SetHelp("Catalan","combinatorics","Get nth Catalan number");
@@ -24,7 +26,9 @@ function Catalan(n) = (
 ## Defined by n! = n(n-1)(n-2)...
 SetHelp("Factorial","combinatorics","Factorial: n(n-1)(n-2)...");
 function Factorial(n) = (
-       if not IsNonNegativeInteger(n) then
+       if(IsMatrix(n)) then
+               return ApplyOverMatrix(n,Factorial)
+       else if not IsNonNegativeInteger(n) then
                (error("Factorial: argument not an integer >= 0");bailout);
        n!
 )
@@ -33,7 +37,9 @@ function Factorial(n) = (
 ## Defined by n!! = n(n-2)(n-4)...
 SetHelp("DoubleFactorial","combinatorics","Double factorial: n(n-2)(n-4)...");
 function DoubleFactorial(n) = (
-       if not IsNonNegativeInteger(n) then
+       if(IsMatrix(n)) then
+               return ApplyOverMatrix(n,DoubleFactorial)
+       else if not IsNonNegativeInteger(n) then
                (error("DoubleFactorial: argument not an integer >= 0");bailout);
        n!!
 )
diff --git a/lib/combinatorics/recursive_sequences.gel b/lib/combinatorics/recursive_sequences.gel
index 2c9f79c..b2fd304 100644
--- a/lib/combinatorics/recursive_sequences.gel
+++ b/lib/combinatorics/recursive_sequences.gel
@@ -5,7 +5,7 @@
 # Galois Matrix
 # Given a linear combining rule (a_1*x_+...+a_n*x_n=x_(n+1)),
 # gives the Galois stepping matrix
-SetHelp ("GaloisMatrix", "combinatorics", "Galois matrix given a linear combining rule 
(a_1*x_+...+a_n*x_n=x_(n+1))")
+SetHelp ("GaloisMatrix", "combinatorics", "Galois matrix given a linear combining rule 
(a_1*x_1+...+a_n*x_n=x_(n+1))")
 function GaloisMatrix(combining_rule) = (
  [[0;I(columns(combining_rule)-1)],combining_rule.']
 )
diff --git a/lib/equation_solving/newton.gel b/lib/equation_solving/newton.gel
index 51f9d88..630b0f3 100644
--- a/lib/equation_solving/newton.gel
+++ b/lib/equation_solving/newton.gel
@@ -1,6 +1,6 @@
 # Newton's method and related
 
-SetHelp("NewtonsMethod","equation_solving","Attempt to find a zero of a functionf with derivative df using 
Newton's method, returning after two successive values are within epsilon or after maxn tries (then returns 
null)")
+SetHelp("NewtonsMethod","equation_solving","Attempt to find a zero of a function f with derivative df using 
Newton's method, returning after two successive values are within epsilon or after maxn tries (then returns 
null)")
 function NewtonsMethod(f,df,guess,epsilon,maxn) = (
        guess := float(guess);
        for n=1 to maxn do (
@@ -17,7 +17,7 @@ function NewtonsMethod(f,df,guess,epsilon,maxn) = (
        null
 )
 
-SetHelp("HalleysMethod","equation_solving","Attempt to find a zero of a functionf with derivative df and 
second derivative ddf using Halleys's method, returning after two successive values are within epsilon or 
after maxn tries (then returns null)")
+SetHelp("HalleysMethod","equation_solving","Attempt to find a zero of a functionf with derivative df and 
second derivative ddf using Halley's method, returning after two successive values are within epsilon or 
after maxn tries (then returns null)")
 function HalleysMethod(f,df,ddf,guess,epsilon,maxn) = (
        guess := float(guess);
        for n=1 to maxn do (
diff --git a/lib/functions/elementary.gel b/lib/functions/elementary.gel
index c0e4198..b144512 100644
--- a/lib/functions/elementary.gel
+++ b/lib/functions/elementary.gel
@@ -70,10 +70,12 @@ function acos(x) = (
                0
        else if x==-1 then
                pi
+       else if x==0 then
+               pi/2
        else if IsReal(x) and -1 < x < 1 then
                atan(sqrt(1-x^2)/x)+(if x>0 then 0 else pi)
        else
-               (-1i)*ln(1i*x+1i*sqrt(abs(1-x^2))*exp((1i/2)*Arg(1-x^2)))
+               (-1i)*ln(x+1i*sqrt(abs(1-x^2))*exp((1i/2)*Arg(1-x^2)))
 );
 arccos = acos
 SetHelpAlias ("acos", "arccos");
diff --git a/lib/library-strings.c b/lib/library-strings.c
index d2addcb..01d4763 100644
--- a/lib/library-strings.c
+++ b/lib/library-strings.c
@@ -1,6 +1,6 @@
 char *fake = N_("Compose two functions");
 char *fake = N_("Compose a function with itself n times, passing x as argument, and returning x if n == 0");
-char *fake = N_("Print a table of values for f(n) for numbers from from vector v, or if v is a number for 
integers from 1 to v");
+char *fake = N_("Print a table of values for f(n) for numbers from vector v, or if v is a number for 
integers from 1 to v");
 char *fake = N_("Make a string");
 char *fake = N_("Tolerance of the Chop function");
 char *fake = N_("How many iterations to try to find the limit for continuity and limits");
@@ -167,7 +167,7 @@ char *fake = N_("Factorial: n(n-1)(n-2)...");
 char *fake = N_("Falling factorial: (n)_k = n(n-1)...(n-(k-1))");
 char *fake = N_("Calculate nth Fibonacci number");
 char *fake = N_("Calculate the Frobenius number for a coin problem");
-char *fake = N_("Galois matrix given a linear combining rule (a_1*x_+...+a_n*x_n=x_(n+1))");
+char *fake = N_("Galois matrix given a linear combining rule (a_1*x_1+...+a_n*x_n=x_(n+1))");
 char *fake = N_("Use greedy algorithm to find c, for c . v = n.  (v must be sorted)");
 char *fake = N_("Harmonic Number, the nth harmonic number of order r");
 char *fake = N_("Hofstadter's function q(n) defined by q(1)=1, q(2)=1, q(n)=q(n-q(n-1))+q(n-q(n-2))");
@@ -177,7 +177,7 @@ char *fake = N_("Get the Pascal's triangle as a matrix");
 char *fake = N_("(Pochhammer) Rising factorial: (n)_k = n(n+1)...(n+(k-1))");
 char *fake = N_("Stirling number of the first kind");
 char *fake = N_("Stirling number of the second kind");
-char *fake = N_("Subfactorial: n! times sum_{k=1}^n (-1)^k/k!");
+char *fake = N_("Subfactorial: n! times sum_{k=0}^n (-1)^k/k!");
 char *fake = N_("Calculate the nth triangular number");
 char *fake = N_("Calculate permutations");
 char *fake = N_("Integration of f by Composite Simpson's Rule on the interval [a,b] with the number of steps 
calculated by the fourth derivative bound and the desired tolerance");
@@ -237,8 +237,8 @@ char *fake = N_("Find root of a function using the bisection method to within TO
 char *fake = N_("Find root of a function using the method of false position to within TOL tolerance in up to 
N iterations.  f(a) and f(b) must have opposite signs.");
 char *fake = N_("Find root of a function using the Muller's method");
 char *fake = N_("Find root of a function using the secant method to within TOL tolerance in up to N 
iterations.  f(a) and f(b) must have opposite signs.");
-char *fake = N_("Attempt to find a zero of a functionf with derivative df and second derivative ddf using 
Halleys's method, returning after two successive values are within epsilon or after maxn tries (then returns 
null)");
-char *fake = N_("Attempt to find a zero of a functionf with derivative df using Newton's method, returning 
after two successive values are within epsilon or after maxn tries (then returns null)");
+char *fake = N_("Attempt to find a zero of a functionf with derivative df and second derivative ddf using 
Halley's method, returning after two successive values are within epsilon or after maxn tries (then returns 
null)");
+char *fake = N_("Attempt to find a zero of a function f with derivative df using Newton's method, returning 
after two successive values are within epsilon or after maxn tries (then returns null)");
 char *fake = N_("Find roots of a polynomial (given as vector of coefficients)");
 char *fake = N_("Find roots of a quartic polynomial (given as vector of coefficients)");
 char *fake = N_("Use classical non-adaptive Runge-Kutta of fourth order method to numerically solve 
y'=f(x,y) for initial x0,y0 going to x1 with n increments, returns y at x1");
diff --git a/lib/misc/misc.gel b/lib/misc/misc.gel
index b64d91f..3fb1647 100644
--- a/lib/misc/misc.gel
+++ b/lib/misc/misc.gel
@@ -15,7 +15,7 @@ function ComposePower(f,n,x) = (
        x
 )
 
-SetHelp("PrintTable","basic","Print a table of values for f(n) for numbers from from vector v, or if v is a 
number for integers from 1 to v")
+SetHelp("PrintTable","basic","Print a table of values for f(n) for numbers from vector v, or if v is a 
number for integers from 1 to v")
 function PrintTable(f,v) = (
        local *;
        # Note we can't check the 2 arguments, FIXME
diff --git a/src/eval.c b/src/eval.c
index c13c899..ce8522c 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3501,10 +3501,13 @@ gel_similar_possible_ids (const char *id)
                const char *id = li->data;
 
                if (li->next == NULL &&
-                   li != similar)
-                       g_string_append (sim, _("' or '"));
-               else if (li != similar)
+                   li != similar) {
+                       g_string_append (sim, "' ");
+                       g_string_append (sim, _("or"));
+                       g_string_append (sim, " '");
+               } else if (li != similar) {
                        g_string_append (sim, "', '");
+               }
 
                g_string_append (sim, id);
 
diff --git a/src/funclib.c b/src/funclib.c
index 6176d5a..abf1c18 100644
--- a/src/funclib.c
+++ b/src/funclib.c
@@ -3191,7 +3191,7 @@ min_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
                         */
                        return gel_stealnode (a[0]);
                } else {
-                       gel_errorout (_("%s: Input not a number of matrix of numbers."),
+                       gel_errorout (_("%s: Input not a number or matrix of numbers."),
                                      "min");
                        return NULL;
                }
diff --git a/src/geniustests.txt b/src/geniustests.txt
index 83e8579..c968e71 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -1220,6 +1220,11 @@ Im(4)                                                            0
 1+0.000000000000000000000000000000000000000000000001i          1+0.0i
 0.00000000000000000000000000000000000001+1.1i                  0.0+1.1i
 -0.00000000000000000000000000000000000001+1.1i                 -0.0+1.1i
+Subfactorial([1,2,3,4,5,6])                                    [0,1,2,9,44,265]
+Subfactorial(0)                                                        1
+Subfactorial(-1)                                               Subfactorial(-1)
+Factorial([0,1,2,3,4,5,6])                                     [1,1,2,6,24,120,720]
+DoubleFactorial([0,1,2,3,4,5,6])                               [1,1,2,3,8,15,48]
 load "nullspacetest.gel"                                       true
 load "longtest.gel"                                            true
 load "testprec.gel"                                            true
diff --git a/src/gnome-genius.c b/src/gnome-genius.c
index 9ced528..da2bf98 100644
--- a/src/gnome-genius.c
+++ b/src/gnome-genius.c
@@ -2000,7 +2000,7 @@ aboutcb(GtkWidget * widget, gpointer data)
                              "version", VERSION,
                              "copyright", _(GENIUS_COPYRIGHT_STRING),
                              "comments",
-                             _("The Gnome calculator style edition of "
+                             _("The GNOME calculator style edition of "
                                "the Genius Mathematical Tool."),
                              "authors", authors,
                              "documenters", documenters,
@@ -3960,13 +3960,13 @@ save_all_cb (GtkWidget *w)
 
        if (there_are_unsaved) {
                genius_display_error (NULL, _("Save new programs by "
-                                             "\"Save As..\" first!"));
+                                             "\"Save As...\" first!"));
        }
 
        if (there_are_readonly_modified) {
                genius_display_error (NULL,
                                      _("Some read-only programs are "
-                                       "modified.  Use \"Save As..\" "
+                                       "modified.  Use \"Save As...\" "
                                        "to save them to "
                                        "a new location."));
        }
diff --git a/src/longtest.gel b/src/longtest.gel
index 44708a1..382508b 100644
--- a/src/longtest.gel
+++ b/src/longtest.gel
@@ -41,7 +41,23 @@ function randtest2() = (
     true
 );
 
+function invtest() = (
+       retval = true;
+       epsilon = 0.0001;
+       for n in 
`[[`sin,`asin],[`sec,`asec],[`cos,`acos],[`csc,`acsc],[`sinh,`asinh],[`sech,`asech],[`cosh,`acosh],[`csch,`acsch]]
 do (
+               for x in [0.1,0.2,0.4,10,-10,3i,1+1i] do (
+                       y = n@(1) call ( n@(2) call (x) );
+                       if (not IsValue (y)) or abs(x-y) > epsilon then (
+                               error ("Bad inverse on " + n + " at " + x + "!");
+                               retval = false
+                       )
+               )
+       );
+       retval
+);
+
 function derivtest() = (
+       retval = true;
        epsilon = 0.0001;
        for n in 
[`asin,`asinh,`acos,`acosh,`acsc,`acsch,`asec,`asech,`atan,`atanh,`acot,`acoth,`sin,`sinh,`cos,`cosh,`csc,`csch,`sec,`sech,`tan,`tanh,`cot,`coth,`sqrt,`ln,`log2,`log10,`exp,`cis]
 do (
                d = SymbolicDerivative(n);
@@ -49,7 +65,7 @@ function derivtest() = (
                        y = (d call (x)) - NDerivative (n,x);
                        if (not IsValue (y)) or abs(y) > epsilon then (
                                error ("Bad derivative on " + n + " at " + x + "!");
-                               return false
+                               retval = false
                        )
                )
        );
@@ -59,10 +75,10 @@ function derivtest() = (
                y = (d call (x)) - NDerivative (f,x);
                if (not IsValue (y)) or abs(y) > epsilon then (
                        error ("Bad derivative on 5th atan deriv at " + x + "!");
-                       return false
+                       retval = false
                )
        );
-       true
+       retval
 );
 
 function roottestcube() = (
@@ -197,6 +213,9 @@ function LongTest() = (
        #random test 2
        if not randtest2() then (error("error on random test 2");errors = errors + 1);
 
+       #inverses test
+       if not invtest() then (error("error on inv test");errors = errors + 1);
+
        #derivative test
        if not derivtest() then (error("error on deriv test");errors = errors + 1);
 
diff --git a/src/mpwrap.c b/src/mpwrap.c
index d407232..e2ac0a7 100644
--- a/src/mpwrap.c
+++ b/src/mpwrap.c
@@ -4085,7 +4085,7 @@ mpw_legendre(mpw_ptr rop,mpw_ptr op1, mpw_ptr op2)
                mpwl_legendre(rop->r,op1->r,op2->r);
        } else {
                gel_error_num=GEL_NUMERICAL_MPW_ERROR;
-               gel_errorout (_("Can't get Legendre symbols complex numbers"));
+               gel_errorout (_("Can't get Legendre symbols of complex numbers"));
        }
 }
 void


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