[genius] Thu Apr 23 01:32:06 2009 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: svn-commits-list gnome org
- Subject: [genius] Thu Apr 23 01:32:06 2009 Jiri (George) Lebl <jirka 5z com>
- Date: Thu, 23 Apr 2009 02:32:57 -0400 (EDT)
commit 5cb718ddc8044343c99e89826cb859e74b7056de
Author: Jiri (George) Lebl <jirka 5z com>
Date: Thu Apr 23 01:32:28 2009 -0500
Thu Apr 23 01:32:06 2009 Jiri (George) Lebl <jirka 5z com>
* src/gnome-genius.c: Fix opening new files from the command line.
It just works now.
* lib/calculus/Makefile.am, lib/calculus/fourier.gel: Add some
Fourier series routines. This currently exposes a bug in scoping
rules
---
ChangeLog | 9 +++
lib/calculus/Makefile.am | 2 +-
lib/calculus/fourier.gel | 172 ++++++++++++++++++++++++++++++++++++++++++++++
lib/library-strings.c | 8 ++
src/gnome-genius.c | 25 ++++++-
5 files changed, 213 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0a84d90..52e0c5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Apr 23 01:32:06 2009 Jiri (George) Lebl <jirka 5z com>
+
+ * src/gnome-genius.c: Fix opening new files from the command line.
+ It just works now.
+
+ * lib/calculus/Makefile.am, lib/calculus/fourier.gel: Add some
+ Fourier series routines. This currently exposes a bug in scoping
+ rules
+
Sun Apr 19 19:27:09 2009 Jiri (George) Lebl <jirka 5z com>
* src/geniustests.txt, src/testprec.gel: test the precision stuff
diff --git a/lib/calculus/Makefile.am b/lib/calculus/Makefile.am
index b0360c8..8a9609a 100644
--- a/lib/calculus/Makefile.am
+++ b/lib/calculus/Makefile.am
@@ -1,7 +1,7 @@
Librarydir = $(datadir)/genius/gel/calculus
SUBDIRS =
-GELFILES = differentiation.gel integration.gel limits.gel sums_products.gel
+GELFILES = differentiation.gel integration.gel limits.gel sums_products.gel fourier.gel
EXTRA_DIST = $(GELFILES)
diff --git a/lib/calculus/fourier.gel b/lib/calculus/fourier.gel
new file mode 100644
index 0000000..a8d3fb4
--- /dev/null
+++ b/lib/calculus/fourier.gel
@@ -0,0 +1,172 @@
+# FourierSeries
+#
+function NumericalFourierSeriesFunction(f,L,N) =
+ (
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("NumericalFourierSeriesFunction: argument f must be a function");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("NumericalFourierSeriesFunction: argument L must be a positive real value");bailout)
+ else if not IsPositiveInteger(N) then
+ (error("NumericalFourierSeriesFunction: argument N must be a positive integer");bailout);
+
+ c = NumericalFourierSeriesCoefficients(f,L,N);
+
+ FourierSeriesFunction(c@(1),c@(2),L)
+)
+SetHelp("NumericalFourierSeriesFunction","calculus","FIXME");
+protect("NumericalFourierSeriesFunction");
+
+function FourierSeriesFunction(a,b,L) =
+ (
+# check arguments
+ if not (IsVector(a) and IsVector(b)) then
+ (error("FourierSeriesFunction: arguments a and b must be vectors");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("FourierSeriesFunction: argument L must be a positive real value");bailout);
+
+ `(x) = (
+ if not IsNull(a) then (
+ val = a@(1)/2 + sum n = 2 to elements(a) do
+ a@(n) * cos(x*(n-1)*pi/L)
+ ) else (
+ val = 0
+ );
+
+ if not IsNull(b) then (
+ val = val + sum n = 1 to elements(b) do
+ b@(n) * sin(x*n*pi/L)
+ );
+
+ val
+ )
+)
+SetHelp("FourierSeries","calculus","FIXME");
+protect("FourierSeries");
+
+function NumericalFourierSeriesCoefficients(f,L,N) =
+ (
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("NumericalFourierSeriesCoefficients: argument f must be a function");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("NumericalFourierSeriesCoefficients: argument L must be a positive real value");bailout)
+ else if not IsPositiveInteger(N) then
+ (error("NumericalFourierSeriesCoefficients: argument N must be a positive integer");bailout);
+
+ a = .;
+ b = .;
+
+ a@(1) = (1/L)*NumericalIntegral(f,-L,L);
+ __fs_L = L;
+ __fs_f = f;
+ for __fs_n = 1 to N do (
+ a@(__fs_n+1) = (1/L)*NumericalIntegral(`(x)=((__fs_f call (x))*cos(x*__fs_n*pi/__fs_L)),-L,L);
+ b@(__fs_n) = (1/L)*NumericalIntegral(`(x)=((__fs_f call (x))*sin(x*__fs_n*pi/__fs_L)),-L,L)
+ );
+ `[a,b]
+)
+SetHelp("NumericalFourierSeriesCoefficients","calculus","FIXME");
+protect("NumericalFourierSeriesCoefficients");
+
+function NumericalFourierSineSeriesCoefficients(f,L,N) =
+ (
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("NumericalFourierSineSeriesCoefficients: argument f must be a function");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("NumericalFourierSineSeriesCoefficients: argument L must be a positive real value");bailout)
+ else if not IsPositiveInteger(N) then
+ (error("NumericalFourierSineSeriesCoefficients: argument N must be a positive integer");bailout);
+
+ b = .;
+
+ __fs_L = L;
+ __fs_f = f;
+ for __fs_n = 1 to N do (
+ b@(__fs_n) = (2/L)*NumericalIntegral(`(x)=((__fs_f call (x))*sin(x*__fs_n*pi/__fs_L)),0,L)
+ );
+ b
+)
+SetHelp("NumericalFourierSineSeriesCoefficients","calculus","FIXME");
+protect("NumericalFourierSineSeriesCoefficients");
+
+function NumericalFourierCosineSeriesCoefficients(f,L,N) =
+ (
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("NumericalFourierCosineSeriesCoefficients: argument f must be a function");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("NumericalFourierCosineSeriesCoefficients: argument L must be a positive real value");bailout)
+ else if not IsPositiveInteger(N) then
+ (error("NumericalFourierCosineSeriesCoefficients: argument N must be a positive integer");bailout);
+
+ a = .;
+
+ __fs_L = L;
+ __fs_f = f;
+
+ a@(1) = (1/L)*NumericalIntegral(f,-L,L);
+ for __fs_n = 1 to N do (
+ a@(__fs_n+1) = (1/L)*NumericalIntegral(`(x)=((__fs_f call (x))*cos(x*__fs_n*pi/__fs_L)),-L,L)
+ );
+ a
+)
+SetHelp("NumericalFourierCosineSeriesCoefficients","calculus","FIXME");
+protect("NumericalFourierCosineSeriesCoefficients");
+
+function PeriodicExtension(f,a,b) =
+(
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("PeriodicExtension: argument f must be a function");bailout)
+ else if not (IsReal(a) and IsReal(b) and b > a) then
+ (error("PeriodicExtension: arguments a, b must be a real, b > a");bailout);
+
+ `(x) = (
+ #This is pretty stupid, but simplest way to do this
+ while x > b do x = x-(b-a);
+ while x < a do x = x+(b-a);
+ (f call (x))
+ )
+)
+SetHelp("PeriodicExtension","calculus","FIXME");
+protect("PeriodicExtension");
+
+function EvenPeriodicExtension(f,L) =
+ (
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("EvenPeriodicExtension: argument f must be a function");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("EvenPeriodicExtension: argument L must be a positive real value");bailout);
+
+ `(x) = (
+ #This is pretty stupid, but simplest way to do this
+ while x > L do x = x-2*L;
+ while x < -L do x = x+2*L;
+
+ if x >= 0 then (f call (x)) else (f call (-x))
+ )
+)
+SetHelp("EvenPeriodicExtension","calculus","FIXME");
+protect("EvenPeriodicExtension");
+
+function OddPeriodicExtension(f,L) =
+(
+# check arguments
+ if not IsFunctionOrIdentifier(f) then
+ (error("OddPeriodicExtension: argument f must be a function");bailout)
+ else if not (IsReal(L) and L > 0) then
+ (error("OddPeriodicExtension: argument L must be a positive real value");bailout);
+
+ `(x) = (
+ #This is pretty stupid, but simplest way to do this
+ while x > L do x = x-2*L;
+ while x < -L do x = x+2*L;
+
+ if x >= 0 then (f call (x)) else -(f call (-x))
+ )
+)
+SetHelp("OddPeriodicExtension","calculus","FIXME");
+protect("OddPeriodicExtension");
diff --git a/lib/library-strings.c b/lib/library-strings.c
index 119de23..533eda0 100644
--- a/lib/library-strings.c
+++ b/lib/library-strings.c
@@ -180,6 +180,8 @@ 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");
char *fake = N_("Attempt to calculate derivative by trying first symbolically and then numerically");
+char *fake = N_("FIXME");
+char *fake = N_("FIXME");
char *fake = N_("Try to calculate an infinite product for a single parameter function");
char *fake = N_("Try to calculate an infinite product for a double parameter function with func(arg,n)");
char *fake = N_("Try to calculate an infinite sum for a single parameter function");
@@ -190,12 +192,18 @@ char *fake = N_("Calculate the left limit of a real-valued function at x0");
char *fake = N_("Calculate the limit of a real-valued function at x0. Tries to calculate both left and right limits.");
char *fake = N_("Integration by midpoint rule");
char *fake = N_("Attempt to calculate numerical derivative");
+char *fake = N_("FIXME");
+char *fake = N_("FIXME");
+char *fake = N_("FIXME");
+char *fake = N_("FIXME");
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");
char *fake = N_("Attempt to calculate numerical right derivative");
+char *fake = N_("FIXME");
char *fake = N_("Compute one-sided derivative using five point formula");
char *fake = N_("Compute one-sided derivative using three-point formula");
+char *fake = N_("FIXME");
char *fake = N_("Calculate the right limit of a real-valued function at x0");
char *fake = N_("Compute two-sided derivative using five-point formula");
char *fake = N_("Compute two-sided derivative using three-point formula");
diff --git a/src/gnome-genius.c b/src/gnome-genius.c
index fff60f2..7703397 100644
--- a/src/gnome-genius.c
+++ b/src/gnome-genius.c
@@ -3256,6 +3256,22 @@ get_source_language_manager ()
#endif
static gboolean
+file_exists (const char *fname)
+{
+ GnomeVFSURI *uri;
+ gboolean ret;
+
+ if (ve_string_empty (fname))
+ return FALSE;
+
+ uri = gnome_vfs_uri_new (fname);
+ ret = gnome_vfs_uri_exists (uri);
+ gnome_vfs_uri_unref (uri);
+
+ return ret;
+}
+
+static gboolean
file_is_writable (const char *fname)
{
GnomeVFSFileInfo *info;
@@ -3399,8 +3415,13 @@ new_program (const char *filename)
} else {
char *contents;
p->name = g_strdup (filename);
- p->readonly = ! file_is_writable (filename);
- contents = get_contents_vfs (p->name);
+ if (file_exists (filename)) {
+ p->readonly = ! file_is_writable (filename);
+ contents = get_contents_vfs (p->name);
+ } else {
+ p->readonly = FALSE;
+ contents = g_strdup ("");
+ }
if (contents != NULL &&
g_utf8_validate (contents, -1, NULL)) {
GtkTextIter iter;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]