-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhypergeometric_appell.lisp
54 lines (48 loc) · 2.35 KB
/
hypergeometric_appell.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;;; Copyright (c) 2015 Russell Andrew Edson
;;;;
;;;; Permission is hereby granted, free of charge, to any person obtaining a
;;;; copy of this software and associated documentation files (the "Software"),
;;;; to deal in the Software without restriction, including without limitation
;;;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;;;; and/or sell copies of the Software, and to permit persons to whom the
;;;; Software is furnished to do so, subject to the following conditions:
;;;;
;;;; The above copyright notice and this permission notice shall be included
;;;; in all copies or substantial portions of the Software.
;;;;
;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
;;;; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;;;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;;;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;;;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;;; DEALINGS IN THE SOFTWARE.
;;;; Code for approximations of the Appell hypergeometric function.
;;;; TODO
;;;; Date: 27/09/2015
(in-package :cl-mathspecialfunctions)
;;; The Appell Hypergeometric function, F1(a,b,bb,c,x,y). We can compute
;;; this as a truncation of an infinite sum of Gauss hypergeometric
;;; functions -- the given parameter num-terms specifies how many terms
;;; of the summation to use (default is 20).
;;;
;;; Code Usage Examples:
;;;
;;;
(defun hypergeometric-appell (a b bb c x y &optional (num-terms 20))
"Returns Appell's Hypergeometric function, F1(a,b,bb,c,x,y)."
;; As each term in the series contains a ratio of factorials in a, b
;; and c, we can keep track of the previous term each time and update
;; it, instead of computing factorials each time.
(let ((partial-sum (hypergeometric-gauss a bb c y))
(abcx-term 1))
(loop for m from 1 to num-terms do
(setf abcx-term (* abcx-term
(/ (* (+ a m -1) (+ b m -1)) (+ c m -1))
x
(/ 1 m)))
(setf partial-sum
(+ partial-sum
(* abcx-term
(hypergeometric-gauss (+ a m) bb (+ c m) y)))))
partial-sum))