[genius] Thu Jul 14 23:49:51 2011 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Thu Jul 14 23:49:51 2011 Jiri (George) Lebl <jirka 5z com>
- Date: Fri, 15 Jul 2011 06:50:16 +0000 (UTC)
commit eb4cadd1c0a17cd722e29c0e44d732c6f54b96c0
Author: Jiri (George) Lebl <jirka 5z com>
Date: Thu Jul 14 23:49:56 2011 -0700
Thu Jul 14 23:49:51 2011 Jiri (George) Lebl <jirka 5z com>
* lib/*/*.gel, src/funclib.c: Implement IntegerQuotient internally
for speed and use it instead of floor(a/b)
* help/C/genius.xml: fix docbook abstract thingie.
* src/geniustests.txt: some more tests
ChangeLog | 9 +++++++++
help/C/genius.xml | 2 +-
help/genius.txt | 2 +-
lib/combinatorics/misc.gel | 6 +++---
lib/functions/numerical.gel | 3 ---
lib/library-strings.c | 1 -
lib/linear_algebra/misc.gel | 2 +-
src/funclib.c | 33 +++++++++++++++++++++++++++++++++
src/geniustests.txt | 10 ++++++++++
9 files changed, 58 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ad35572..fe3a797 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Jul 14 23:49:51 2011 Jiri (George) Lebl <jirka 5z com>
+
+ * lib/*/*.gel, src/funclib.c: Implement IntegerQuotient internally
+ for speed and use it instead of floor(a/b)
+
+ * help/C/genius.xml: fix docbook abstract thingie.
+
+ * src/geniustests.txt: some more tests
+
Thu Jul 14 17:26:00 2011 Jiri (George) Lebl <jirka 5z com>
* src/eval.c: minor optimizations
diff --git a/help/C/genius.xml b/help/C/genius.xml
index c11a889..b3357c7 100644
--- a/help/C/genius.xml
+++ b/help/C/genius.xml
@@ -33,7 +33,7 @@
<!-- please do not change the id; for translations, change lang to -->
<!-- appropriate code -->
<bookinfo>
- <!--<abstract role="description">Manual for the Genius Math Tool.</abstract>-->
+ <abstract role="description"><para>Manual for the Genius Math Tool.</para></abstract>
<title>&appname; Manual</title>
<copyright>
diff --git a/help/genius.txt b/help/genius.txt
index d16611c..9406695 100644
--- a/help/genius.txt
+++ b/help/genius.txt
@@ -5223,7 +5223,7 @@ NumericalFourierCosineSeriesCoefficients (f,L,N)
Return a vector of coefficients of the the cosine
Fourier series of f with half-period L. That is, we take
f defined on [0,L] take the even periodic extension and
- compute the Fourier series, which only has sine terms.
+ compute the Fourier series, which only has cosine terms.
The series is computed up to the Nth harmonic. The
coefficients are computed by numerical integration using
NumericalIntegral. Note that a@(1) is the constant
diff --git a/lib/combinatorics/misc.gel b/lib/combinatorics/misc.gel
index 0ce24a3..38cc517 100644
--- a/lib/combinatorics/misc.gel
+++ b/lib/combinatorics/misc.gel
@@ -83,7 +83,7 @@ function FrobeniusNumber(v,arg...) = (
# Vitek's inequality for upper bound
# See: Y. Vitek, Bounds for a Linear Diophantine Problem of Frobenius,
# J. London Math. Soc., (2) 10 (1975), 79â85.
- for j = 2 to floor((m@(2)-1)*(m@(elements(m))-1)/2)-1 do (
+ for j = 2 to IntegerQuotient((m@(2)-1)*(m@(elements(m))-1),2)-1 do (
if IsNull(GreedyAlgorithm(j,m)) then
k = j
);
@@ -104,12 +104,12 @@ function GreedyAlgorithm(n,v) = (
if elts == 1 then (
if Divides (v@(1), n) then
- return [floor(n / v@(1))]
+ return [IntegerQuotient(n,v@(1))]
else
return null
);
- k = floor (n / v@(elts));
+ k = IntegerQuotient (n, v@(elts));
for m = k to 0 by -1 do (
c = GreedyAlgorithm (n - m * v@(elts),
v@(1:(elts-1)));
diff --git a/lib/functions/numerical.gel b/lib/functions/numerical.gel
index 6174d92..d983e5b 100644
--- a/lib/functions/numerical.gel
+++ b/lib/functions/numerical.gel
@@ -55,9 +55,6 @@ function Chop(x) =
# Mod (built-in)
# FIXME: Mod with offset (m mod n offset d = something in [d,d+n-1])
-# Division w/o remainder
-SetHelp ("IntegerQuotient", "numeric", "Division w/o remainder")
-function IntegerQuotient(m,n) = floor(m/n)
# IntergerQuotient w/offset (such that d <= m-r*n < d+n
# IntegerDigits = (convert interger to its list of digits, base b, of length len)
# IntegerExponent = (number of trailing zeros in base b expansion = heighest power
diff --git a/lib/library-strings.c b/lib/library-strings.c
index 0bc9d97..4f49913 100644
--- a/lib/library-strings.c
+++ b/lib/library-strings.c
@@ -18,7 +18,6 @@ char *fake = N_("Tolerance for InfiniteSum and InfiniteProduct");
char *fake = N_("Absolute value");
char *fake = N_("Replace very small number with zero");
char *fake = N_("Return the fractional part of a number");
-char *fake = N_("Division w/o remainder");
char *fake = N_("Return the sign (-1,0,1)");
char *fake = N_("Logarithm of any base (calls DiscreteLog if in modulo mode), if base is not given, e is used");
char *fake = N_("The arccos (inverse cos) function");
diff --git a/lib/linear_algebra/misc.gel b/lib/linear_algebra/misc.gel
index cea8eb0..6771f55 100644
--- a/lib/linear_algebra/misc.gel
+++ b/lib/linear_algebra/misc.gel
@@ -252,7 +252,7 @@ function SortVector(v) = (
if elements(v) <= 9 then
bubble(v)
else (
- pe = floor(elements(v)/2);
+ pe = IntegerQuotient(elements(v),2);
piv = v@(pe);
less = more = .;
k = 1;
diff --git a/src/funclib.c b/src/funclib.c
index 2ea347c..cc8ff12 100644
--- a/src/funclib.c
+++ b/src/funclib.c
@@ -2285,6 +2285,37 @@ Jacobi_op(GelCtx *ctx, GelETree * * a, gboolean *exception)
return gel_makenum_use(tmp);
}
+static GelETree *
+IntegerQuotient_op(GelCtx *ctx, GelETree * * a, gboolean *exception)
+{
+ mpz_ptr num1, num2;
+ mpz_t quo;
+ mpw_t numw;
+
+ if (a[0]->type == GEL_MATRIX_NODE ||
+ a[1]->type == GEL_MATRIX_NODE)
+ return gel_apply_func_to_matrixen (ctx, a[0], a[1], IntegerQuotient_op, "IntegerQuotient", exception);
+
+ if G_UNLIKELY ( ! check_argument_integer (a, 0, "IntegerQuotient") ||
+ ! check_argument_integer (a, 1, "IntegerQuotient"))
+ return NULL;
+
+ num1 = mpw_peek_real_mpz (a[0]->val.value);
+ num2 = mpw_peek_real_mpz (a[1]->val.value);
+
+ if (mpz_sgn (num2) == 0) {
+ gel_errorout (_("Division by zero!"));
+
+ return NULL;
+ }
+
+ mpz_init (quo);
+ mpz_fdiv_q (quo, num1, num2);
+ mpw_init (numw);
+ mpw_set_mpz_use (numw, quo);
+ return gel_makenum_use (numw);
+}
+
/*kronecker function*/
static GelETree *
JacobiKronecker_op(GelCtx *ctx, GelETree * * a, gboolean *exception)
@@ -6446,6 +6477,8 @@ gel_funclib_addall(void)
VALIAS (Min, 2, min);
VALIAS (Minimum, 2, min);
+ FUNC (IntegerQuotient, 2, "a,b", "numeric", N_("Division w/o remainder, equivalent to floor(a/b)"));
+
FUNC (Jacobi, 2, "a,b", "number_theory", N_("Calculate the Jacobi symbol (a/b) (b should be odd)"));
ALIAS (JacobiSymbol, 2, Jacobi);
FUNC (JacobiKronecker, 2, "a,b", "number_theory", N_("Calculate the Jacobi symbol (a/b) with the Kronecker extension (a/2)=(2/a) when a odd, or (a/2)=0 when a even"));
diff --git a/src/geniustests.txt b/src/geniustests.txt
index 3e5558f..41b36d9 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -385,6 +385,7 @@ t=0;for k in [1,2,3;4,5,6;7,8,9] do t=t+k;t 45
t=0;for k in 3 do t=t+k;t 3
for k in [1,2,3] do k 3
for n in &d do . (for n in (&d) do (null))
+(for k in . do 1)+2 ((null)+2)
RowMedian([1,2,2,3;1,2,3,4;2,2,2,2;2,2,3,2]) [2;2 1/2;2;2]
Median([1,2,3]) 2
Median([1,4,2,3]) 2 1/2
@@ -969,6 +970,8 @@ Parse("local *;x") Parse("local *;x")
Evaluate("local *;x") Evaluate("local *;x")
NumericalIntegral(`(x)=x^3,0,1) 0.25
NumericalIntegral(`(x)=x^3,-1,1)+1 1.0
+NumericalIntegral(`(x)=GaussFunction(x,10),-100,100) 1.0
+floor(NumericalIntegral(`(x)=GaussFunction(x,10),-10,10)*100) 68
NumericalLimitAtInfinity (atan,`(n)=2^n,10^(-20),10,10000) 1.57079632679
LeftLimit (UnitStep,0) 0
RightLimit (UnitStep,0) 1
@@ -1064,6 +1067,13 @@ ReverseVector(null)+1 ((null)+1)
ShuffleVector([1]) [1]
SortVector(ShuffleVector([6,5,4,3,2,1])) [1,2,3,4,5,6]
ShuffleVector(null)+1 ((null)+1)
+IntegerQuotient(2,3) 0
+IntegerQuotient(3,3) 1
+IntegerQuotient(4,3) 1
+IntegerQuotient(6,3) 2
+IntegerQuotient(-1,3) -1
+IntegerQuotient(1,-3) -1
+IntegerQuotient([1,2,3],[2,2,2]) [0,1,1]
load "nullspacetest.gel" true
load "longtest.gel" true
load "testprec.gel" true
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]