Discussion:
A question about numerical-integration.lisp
Alasdair McAndrew
2015-11-01 10:10:38 UTC
Permalink
Hello,

I am using the excellent gsll package (in the first instance), to provide
an interface to quadpack for the mathematics system FriCAS. I'm slowly
going through calculus/numerical-integration.lisp one function at a time
and writing each one into FriCAS as I go. This means writing functions in
FriCAS's own language SPAD which interface with gsll.

This is made harder by me being a lisp newbie.

However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.

I'm using SBCL in emacs-slime, and I have installed gsll with quicklisp, so
that I can call an integration routine with

* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)

But the commands

* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))

* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)

just produces a long list of errors. Is "grid" a standard library, or does
it need to be loaded first? (Told you I was a newbie...)

Thanks
Alasdair
--
[image: http://www.facebook.com/alasdair.mcandrew]
<http://www.facebook.com/alasdair.mcandrew> [image:
https://plus.google.com/+AlasdairMcAndrew/posts]
<https://plus.google.com/+AlasdairMcAndrew/posts> [image:
https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108]
<https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108> [image:
https://twitter.com/amca01] <https://twitter.com/amca01> [image:
http://numbersandshapes.net] <http://numbersandshapes.net>
David Catteeuw
2015-11-01 13:15:36 UTC
Permalink
Hi Alasdair,

I guess grid refers to Antik's grids, a data type for matrices:
https://www.common-lisp.net/project/antik/
<https://www.common-lisp.net/project/antik/#documentation>

Regards,
david.
<https://www.common-lisp.net/project/antik/#documentation>
Post by Alasdair McAndrew
Hello,
I am using the excellent gsll package (in the first instance), to provide
an interface to quadpack for the mathematics system FriCAS. I'm slowly
going through calculus/numerical-integration.lisp one function at a time
and writing each one into FriCAS as I go. This means writing functions in
FriCAS's own language SPAD which interface with gsll.
This is made harder by me being a lisp newbie.
However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.
I'm using SBCL in emacs-slime, and I have installed gsll with quicklisp,
so that I can call an integration routine with
* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
But the commands
* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)
just produces a long list of errors. Is "grid" a standard library, or does
it need to be loaded first? (Told you I was a newbie...)
Thanks
Alasdair
--
[image: http://www.facebook.com/alasdair.mcandrew]
https://plus.google.com/+AlasdairMcAndrew/posts]
https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108]
http://numbersandshapes.net] <http://numbersandshapes.net>
Alasdair McAndrew
2015-11-01 22:31:45 UTC
Permalink
Thank you very much! It seems that grid (antik) is automatically loaded
with gsll by quicklisp. But that doesn't seem to be the problem: both

(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))

and

(vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0)

seem to give the same result - which should be the endpoints and
singularities for computation of a numerical integral by use of the GSL
QUADPACK routine QAGP, implemented in gsll as integration-qagp. But the
command

(gsll:integration-QAGp 'integration-test-f454 (grid:copy-to (vector 0.0d0
1.0d0 (sqrt 2.0d0) 3.0d0)) 0.0d0 1.0d-3 1000))

fails with a slew of errors. The debugger's first backtrace is

((:METHOD NO-APPLICABLE-METHOD (T)) #<STANDARD-GENERIC-FUNCTION
GRID:FOREIGN-POINTER (1)> #(0.0 1.0 1.4142135623730951 3.0)) [fast-method]

Given that the grid command above works without any errors, I don't
understand this at all. But then, as I say, I seem to have programmed in
many languages over the years - with the lamentable absence of lisp. So if
my questions seem trivial and naive, my apologies!

Thanks again,
Alasdair
Post by David Catteeuw
Hi Alasdair,
https://www.common-lisp.net/project/antik/
<https://www.common-lisp.net/project/antik/#documentation>
Regards,
david.
<https://www.common-lisp.net/project/antik/#documentation>
Post by Alasdair McAndrew
Hello,
I am using the excellent gsll package (in the first instance), to provide
an interface to quadpack for the mathematics system FriCAS. I'm slowly
going through calculus/numerical-integration.lisp one function at a time
and writing each one into FriCAS as I go. This means writing functions in
FriCAS's own language SPAD which interface with gsll.
This is made harder by me being a lisp newbie.
However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.
I'm using SBCL in emacs-slime, and I have installed gsll with quicklisp,
so that I can call an integration routine with
* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
But the commands
* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)
just produces a long list of errors. Is "grid" a standard library, or
does it need to be loaded first? (Told you I was a newbie...)
Thanks
Alasdair
--
[image: http://www.facebook.com/alasdair.mcandrew]
https://plus.google.com/+AlasdairMcAndrew/posts]
https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108]
http://numbersandshapes.net] <http://numbersandshapes.net>
--
[image: http://www.facebook.com/alasdair.mcandrew]
<http://www.facebook.com/alasdair.mcandrew> [image:
https://plus.google.com/+AlasdairMcAndrew/posts]
<https://plus.google.com/+AlasdairMcAndrew/posts> [image:
https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108]
<https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108> [image:
https://twitter.com/amca01] <https://twitter.com/amca01> [image:
http://numbersandshapes.net] <http://numbersandshapes.net>
Liam Healy
2015-11-02 02:34:55 UTC
Permalink
Post by Alasdair McAndrew
Hello,
I am using the excellent gsll package (in the first instance), to provide
an interface to quadpack for the mathematics system FriCAS. I'm slowly
going through calculus/numerical-integration.lisp one function at a time
and writing each one into FriCAS as I go. This means writing functions in
FriCAS's own language SPAD which interface with gsll.
This is made harder by me being a lisp newbie.
However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.
I'm using SBCL in emacs-slime, and I have installed gsll with quicklisp,
so that I can call an integration routine with
* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
But the commands
* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)
just produces a long list of errors. Is "grid" a standard library, or does
it need to be loaded first? (Told you I was a newbie...)
Thanks
Alasdair
--
Try this

(setf grid:*default-grid-type* 'grid:foreign-array)
(gsll:integration-QAGp 'integration-test-f454 (grid:grid 0.0d0 1.0d0 (sqrt
2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)

and let us know what happens.

Thanks,
Liam
Alasdair McAndrew
2015-11-02 03:59:31 UTC
Permalink
Brilliant! - thank you so much - that works just as it should. Why cannot
the input to integration-qagp be simply a list or a vector? As in

(gsll:integration-QAGp 'integration-test-f454 '(0.0d0 1.0d0 (sqrt 2.0d0)
3.0d0) 0.0d0 1.0d-3 1000)

or

(gsll:integration-QAGp 'integration-test-f454 (vector 0.0d0 1.0d0 (sqrt
2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)

I'm not sure (told you I was a newbie!) what grid provides that a list or
vector can't.

And here's a tiny problem from my tiny brain: suppose the endpoints and
singularities are given as a standard Lisp list, S say. Then (I'm using
SBCL):

(defvar S2)
(setf S2 (grid:make-foreign-array 'double-float :dimensions (length S)
:initial-contents S))

turns the list into a foreign array grid (is there an easier way?). But
then, my attempts to use S2 as input to gaqp produces errors:

(gsll:integration-QAGp 'my-fun 'S2 0.0d0 1.0d-3 1000)

Basically I need a way of turning a numeric list into input for
integration-QAGp. I'll keep fiddling!

Many thanks again,
Alasdair
Post by Liam Healy
Post by Alasdair McAndrew
Hello,
I am using the excellent gsll package (in the first instance), to provide
an interface to quadpack for the mathematics system FriCAS. I'm slowly
going through calculus/numerical-integration.lisp one function at a time
and writing each one into FriCAS as I go. This means writing functions in
FriCAS's own language SPAD which interface with gsll.
This is made harder by me being a lisp newbie.
However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.
I'm using SBCL in emacs-slime, and I have installed gsll with quicklisp,
so that I can call an integration routine with
* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
But the commands
* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)
just produces a long list of errors. Is "grid" a standard library, or
does it need to be loaded first? (Told you I was a newbie...)
Thanks
Alasdair
--
Try this
(setf grid:*default-grid-type* 'grid:foreign-array)
(gsll:integration-QAGp 'integration-test-f454 (grid:grid 0.0d0 1.0d0 (sqrt
2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
and let us know what happens.
Thanks,
Liam
--
[image: http://www.facebook.com/alasdair.mcandrew]
<http://www.facebook.com/alasdair.mcandrew> [image:
https://plus.google.com/+AlasdairMcAndrew/posts]
<https://plus.google.com/+AlasdairMcAndrew/posts> [image:
https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108]
<https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108> [image:
https://twitter.com/amca01] <https://twitter.com/amca01> [image:
http://numbersandshapes.net] <http://numbersandshapes.net>
David Catteeuw
2015-11-02 06:54:45 UTC
Permalink
Post by Alasdair McAndrew
Brilliant! - thank you so much - that works just as it should. Why
cannot the input to integration-qagp be simply a list or a vector? As in
Post by Alasdair McAndrew
(gsll:integration-QAGp 'integration-test-f454 '(0.0d0 1.0d0 (sqrt 2.0d0)
3.0d0) 0.0d0 1.0d-3 1000)
Post by Alasdair McAndrew
or
(gsll:integration-QAGp 'integration-test-f454 (vector 0.0d0 1.0d0 (sqrt
2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
Post by Alasdair McAndrew
I'm not sure (told you I was a newbie!) what grid provides that a list or
vector can't.

They provide speed especially in combination with the C library GSL. And
since you don't want to check the type in every math function, the
convention is that you convert your data to a grid, then call the math
functions.

This is much like Python and numpy. C doesn't have this problem, but then
its data types are much less user-friendly overall.
Post by Alasdair McAndrew
And here's a tiny problem from my tiny brain: suppose the endpoints and
singularities are given as a standard Lisp list, S say. Then (I'm using
Post by Alasdair McAndrew
(defvar S2)
(setf S2 (grid:make-foreign-array 'double-float :dimensions (length S)
:initial-contents S))
Post by Alasdair McAndrew
turns the list into a foreign array grid (is there an easier way?). But
(gsll:integration-QAGp 'my-fun 'S2 0.0d0 1.0d-3 1000)
(Maybe the second quote?)

Hope this helps,
david.
Post by Alasdair McAndrew
Basically I need a way of turning a numeric list into input for
integration-QAGp. I'll keep fiddling!
Post by Alasdair McAndrew
Many thanks again,
Alasdair
Post by Liam Healy
Post by Alasdair McAndrew
Hello,
I am using the excellent gsll package (in the first instance), to
provide an interface to quadpack for the mathematics system FriCAS. I'm
slowly going through calculus/numerical-integration.lisp one function at a
time and writing each one into FriCAS as I go. This means writing
functions in FriCAS's own language SPAD which interface with gsll.
Post by Alasdair McAndrew
Post by Liam Healy
Post by Alasdair McAndrew
This is made harder by me being a lisp newbie.
However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.
Post by Alasdair McAndrew
Post by Liam Healy
Post by Alasdair McAndrew
I'm using SBCL in emacs-slime, and I have installed gsll with
quicklisp, so that I can call an integration routine with
Post by Alasdair McAndrew
Post by Liam Healy
Post by Alasdair McAndrew
* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
But the commands
* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
Post by Alasdair McAndrew
Post by Liam Healy
Post by Alasdair McAndrew
* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)
just produces a long list of errors. Is "grid" a standard library, or
does it need to be loaded first? (Told you I was a newbie...)
Post by Alasdair McAndrew
Post by Liam Healy
Post by Alasdair McAndrew
Thanks
Alasdair
--
Try this
(setf grid:*default-grid-type* 'grid:foreign-array)
(gsll:integration-QAGp 'integration-test-f454 (grid:grid 0.0d0 1.0d0
(sqrt 2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
Post by Alasdair McAndrew
Post by Liam Healy
and let us know what happens.
Thanks,
Liam
--
Liam Healy
2015-11-02 15:40:58 UTC
Permalink
Post by Alasdair McAndrew
Brilliant! - thank you so much - that works just as it should. Why cannot
the input to integration-qagp be simply a list or a vector? As in
(gsll:integration-QAGp 'integration-test-f454 '(0.0d0 1.0d0 (sqrt 2.0d0)
3.0d0) 0.0d0 1.0d-3 1000)
or
(gsll:integration-QAGp 'integration-test-f454 (vector 0.0d0 1.0d0 (sqrt
2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
I'm not sure (told you I was a newbie!) what grid provides that a list or
vector can't.
Grids can be thought of as generalized arrays. Since GSL is a foreign (C)
library, its arrays are incompatible with CL arrays. The grid part of Antik
provides a way to bridge that gap, so you can handle them with
similarly-named functions. However, they are different, and foreign calls
need foreign arrays.
Post by Alasdair McAndrew
And here's a tiny problem from my tiny brain: suppose the endpoints and
singularities are given as a standard Lisp list, S say. Then (I'm using
(defvar S2)
(setf S2 (grid:make-foreign-array 'double-float :dimensions (length S)
:initial-contents S))
turns the list into a foreign array grid (is there an easier way?).
There are multiple ways to convert lists to foreign-arrays. This should
work.
Post by Alasdair McAndrew
(gsll:integration-QAGp 'my-fun 'S2 0.0d0 1.0d-3 1000)
While you didn't provide the error, this will not work as you have quoted
S2, so you are sending the symbol 'S2 where you need to send the foreign
array as the argument. This has nothing to do with arrays and
foreign-arrays, it is just a basic syntax error.
Post by Alasdair McAndrew
Basically I need a way of turning a numeric list into input for
integration-QAGp. I'll keep fiddling!
You have it, you just have a syntax error.
Post by Alasdair McAndrew
Many thanks again,
Alasdair
No problem,
Liam
Post by Alasdair McAndrew
Post by Liam Healy
Post by Alasdair McAndrew
Hello,
I am using the excellent gsll package (in the first instance), to
provide an interface to quadpack for the mathematics system FriCAS. I'm
slowly going through calculus/numerical-integration.lisp one function at a
time and writing each one into FriCAS as I go. This means writing
functions in FriCAS's own language SPAD which interface with gsll.
This is made harder by me being a lisp newbie.
However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls). However, all I get
is errors.
I'm using SBCL in emacs-slime, and I have installed gsll with quicklisp,
so that I can call an integration routine with
* (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
But the commands
* (defun integration-test-f454 (x)
(* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
* (gsll:integration-QAGp
'integration-test-f454
(grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
0.0d0 1.0d-3 1000)
just produces a long list of errors. Is "grid" a standard library, or
does it need to be loaded first? (Told you I was a newbie...)
Thanks
Alasdair
--
Try this
(setf grid:*default-grid-type* 'grid:foreign-array)
(gsll:integration-QAGp 'integration-test-f454 (grid:grid 0.0d0 1.0d0
(sqrt 2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
and let us know what happens.
Thanks,
Liam
--
[image: http://www.facebook.com/alasdair.mcandrew]
https://plus.google.com/+AlasdairMcAndrew/posts]
https://www.linkedin.com/pub/alasdair-mcandrew/a/178/108]
http://numbersandshapes.net] <http://numbersandshapes.net>
Loading...