Code Monkey home page Code Monkey logo

cephes.cl's Introduction

Cephes Mathematical Library

A common lisp CFFI wrapper for the SciPy version of Cephes special functions.

For many years Cephes was considered the gold standard in cross-platform mathematical libraries, superior to the libm distributions of the time (early 1990's). Since then C99 and later ANSI C specifications have closed the gap, but there are still certain special and statistical functions available in Cephes that are not in the standard C libraries.

The SciPy version differs from standard Cephes in that it has some additional functions, improvements in accuracy, and is better documented. Only double-float versions are provided.

Installation

The ASDF file will automatically build the shared library as part of the load operation. If you need to build on a system other than MS Windows or UNIX, you will need to modify the make file to account for the linker command to create a shared library.

As delivered, the Makefile is set-up to work on MS Windows or UNIX, and you can build it manually like so:

cd scipy-cephes && make

If you build this on another platform, please drop a note into a Cephes repository issue with the build instructions so we can update the Makefile and system definition.

The init.lisp file, where CFFI loads the library, should work out of the box if libmd on the path somewhere, regardless of platform. If in doubt, place a copy in the same directory as this README.

Documentation

If you know your way around special functions, the table below should suffice to get started. For a more complete description, see the doc strings in cephes.lisp. Finally, the C source code itself, referenced in cephes.lisp, is thorough and complete from a mathematical perspective.

You can also use the scipy.special online documentation.

The API

There is no overlap between the wrapped Cephes functions and the Common Lisp numerical tower. All functions are in the cephes package.

Exported functions are:

function description
airy Airy function
bdtr Binomial distribution
bdtrc Complement of binomial distribution
bdtri Inverse binomial distribution
besselpoly Weighted integral of the Bessel function of the first kind
beta Beta function
lbeta Natural log of beta
btdtr incomplete beta integral
cbrt cube root
chdtr Chi-square distribution
chdtrc Complemented Chi-square distribution
chdtri Inverse of complemented Chi-square distribution
dawsn Dawson's Integral
ellik Incomplete elliptic integral of the first kind
ellie Incomplete elliptic integral of the second kind
ellpk Complete elliptic integral of the first kind
ellpe Complete elliptic integral of the second kind
jacobian-elliptic jacobian Elliptic Functions
exp2 Base 2 exponential function
exp10 Base 10 exponential function (Common antilogarithm)
expn Exponential integral
fdtr F distribution
fdtrc Complemented F distribution
fdtri Inverse of F distribution
fresnl Fresnel integral
gamma Gamma function
log-gamma Natural logarithm of Gamma function
gdtr Gamma distribution function
gdtrc Complemented Gamma distribution function
gdtri Inverse Gamma distribution function (?) - not documented in src
hyp2f1 Gauss hypergeometric function
hyperg Confluent hypergeometric function
i0 Modified Bessel function of order zero
i0e Modified Bessel function of order zero, exponentially scaled
i1 Modified Bessel function of order one
i1e Modified Bessel function of order one, exponentially scaled
igam Regularized lower incomplete gamma function
igamc Regularized upper incomplete gamma function
igami Inverse of the lower incomplete gamma function
igamci Inverse of the upper incomplete gamma function
incbet Incomplete beta integral
incbi Inverse of incomplete beta integral
iv Modified Bessel function of noninteger order
j0 Bessel function of order zero
y0 Bessel function of the second kind, order zero
j1 Bessel function of order one
y1 Bessel function of second kind of order one
jv Bessel function of noninteger order
k0 Modified Bessel function, third kind, order zero
k0e Modified Bessel function, third kind, order zero, exponentially scaled
k1 Modified Bessel function of the third kind of order one
k1e Modified Bessel function of the third kind of order one, exponentially scaled
kn Modified Bessel function, third kind, integer order
nbdtr Negative binomial distribution
nbdtrc Complemented negative binomial distribution
nbdtri Inverse complemented negative binomial distribution
ndtr Normal distribution function
log-ndtr Log of the normal distribution function
erf Error function
erfc Complementary error function
erfinv Inverse of the error function
erfcinv Inverse of the complementary error function
ndtri Inverse of Normal distribution function
pdtr Poisson distribution
pdtrc Complemented poisson distribution
pdtri Inverse Poisson distribution
poch Pochhammer symbol (a)_m = gamma(a + m) / gamma(a)
psi Psi (digamma) function
rgamma Reciprocal Gamma function
shichi Hyperbolic sine and cosine integrals
sici Sine and cosine integrals
sindg Circular sine of angle in degrees
cosdg Circular cosine of angle in degrees
sinpi Compute sin(pi * x)
cospi Compute cos(pi * x)
spence Dilogarithm
stdtr Student's t distribution
stdtri Functional inverse of Student's t distribution
yv Bessel function of noninteger order
tandg Circular tangent of angle in degrees
cotdg Circular cotangent of argument in degrees
log1p log(1 + x)
log1pmx log(1 + x) - x
expm1 exp(x) - 1
cosm1 cos(x) - 1
lgam1p lgam(x + 1)
yn Bessel function of second kind of integer order
zeta Riemann zeta function of two arguments
zetac Riemann zeta function
owens-t Owen's T-Function

Contributing

When contributing to this repository, please first discuss major changes to the existing code you wish to make via a github issue. Minor changes and major additions are welcome. Please write good commit messages.

License

CEPHES.CL is available under the Microsoft Public License.

cephes.cl's People

Contributors

nathanvy avatar snunez1 avatar symbolics avatar tobyworland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cephes.cl's Issues

ecl version of cephes.cl fails

Hi, the ecl version of cephes.cl fails:

starting phase `build'
Invoking ecl: "/gnu/store/cawsqjfnnv7qd0qdjq7jmlqp440jqx8m-ecl-21.2.1/bin/ecl" "--eval" "(require :asdf)" "--eval" "(asdf:initialize-source-registry (list :source-registry (list :tree (uiop:ensure-pathname \"/gnu/store/l3jgs39cqb9dgag97dq586c0xxa60jqf-ecl-cephes-1.2-0.d87146f/share/common-lisp/ecl/cephes\" :truenamize t :ensure-directory t)) :inherit-configuration))" "--eval" "(asdf:load-system \"cephes\")" "--eval" "(quit)"
;;; Loading #P"/gnu/store/cawsqjfnnv7qd0qdjq7jmlqp440jqx8m-ecl-21.2.1/lib/ecl-21.2.1/asdf.fas"
Building #P"/gnu/store/l3jgs39cqb9dgag97dq586c0xxa60jqf-ecl-cephes-1.2-0.d87146f/share/common-lisp/ecl/cephes/scipy-cephes/libmd.so"
An error occurred during initialization:
Subprocess with command "make"
 exited with error code 1.
error: in phase 'build': uncaught exception:
%exception #<&invoke-error program: "/gnu/store/cawsqjfnnv7qd0qdjq7jmlqp440jqx8m-ecl-21.2.1/bin/ecl" arguments:
("--eval" "(require :asdf)" "--eval" "(asdf:initialize-source-registry (list :source-registry (list :tree (uiop:ensure-pathname \"/gnu/store/l3jgs39cqb9dgag97dq586c0xxa60jqf-ecl-cephes-1.2-0.d87146f/share/common-lisp/ecl/cephes\" :truenamize t :ensure-directory t)) :inherit-configuration))" "--eval" "(asdf:load-system \"cephes\")" "--eval" "(quit)") exit-status: 1 term-signal: #f stop-signal: #f>
phase `build' failed after 1.2 seconds

Is this known to be the case?

Has anyone else tried building cephes.cl with ecl?

Quickload install fails on macOS Ventura

This bug report was first place on stack overflow at
https://stackoverflow.com/questions/77182954/i-need-help-getting-lisp-stat-to-load-on-mac-os-x

I am running macOS Ventura 13.4 (22F66) on a Mac mini M1 built in 2020 using SBCL

I tried to load Lisp-Stat with
(ql:quickload :lisp-stat)
which then tried to load 28 ASDF systems and instal 22 Quicklisp releases. Typical Quicklisp goodness followed but ended with

238,213 bytes in 0.08 seconds (3076.55KB/sec)
; Loading "lisp-stat"
..................................
...............operations/generic].
..............-operations/reducing].
...............operations/matrices]
.............y-operations/utilities].
.............y-operations/creating]..
............ay-operations/indexing]...
............ay-operations/displacing].
.........array-operations/transforming]..
.........array-operations/stacking]......
.....................ilities]
[package num-utils.arithmetic]....................
[package num-utils.num=]..........................
[package num-utils.interval]......................
[package num-utils.chebyshev].....................
[package num-utils.polynomial]....................
[package num-utils.elementwise]...................
.................s.extended-real]
[package num-utils.print-matrix]..................
[package num-utils.matrix]........................
[package num-utils.matrix-shorthand]..............
[package num-utils.quadrature]....................
...................rootfinding]
.package num-utils.test-utilities]...............
...................................
Library #P"/Users/sholland/.local/opt/quicklisp/dists/quicklisp/software/cephes.cl-20221106-git/scipy-cephes/libmd.dylib" exists, skipping build
; 
; compilation unit aborted
;   caught 1 fatal ERROR condition
#<CFFI:LOAD-FOREIGN-LIBRARY-ERROR "Unable to load any of the alternatives:~%   ~S" {700A141943}> 
(:LISP-STAT)
*

and Lisp-Stat was not available. Any recommendations?

The Makefile seems to have an incomplete list of dependencies

After updating my system, CEPHES stopped to load. The probable reason is that the Makefile has an incomplete list of dependencies and will not rebuild when the limbd headers change.

I am not sure how to address that, especially with GNU Make.

System description:

Uname: Darwin
System: macOS 13.4
Architecture: arm64
Date: Tue Jun  6 21:39:49 CEST 2023
SBCL: /opt/local/bin/sbcl (SBCL 2.3.5)
Brew: :NOT-FOUND
MacPorts: /opt/local/bin/port
QuickLisp: T

Please include an arm64 build of libmd

I'm unable to properly load lisp-stat on Apple Silicon because this particular package fails to load, because the packaged version of libmd is compiled for x86_64.

A quick demonstration

Remove the cephes directory from quicklisp:

$ rm -rf cephes.cl-20221106-git/ 

And then:

$ sbcl
This is SBCL 2.3.4, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (ql:quickload :lisp-stat)
To load "lisp-stat":
  Load 1 ASDF system:
    lisp-stat
; Loading "lisp-stat"
To load "cephes":
  Load 2 ASDF systems:
    asdf cffi
  Install 1 Quicklisp release:
    cephes.cl
; Loading "cephes"
.............Library #P"/Users/nathan/quicklisp/dists/quicklisp/software/cephes.cl-20221106-git/scipy-cephes/libmd.dylib" exists, skipping build

debugger invoked on a CFFI:LOAD-FOREIGN-LIBRARY-ERROR in thread
#<THREAD "main thread" RUNNING {70087906B3}>:
  Unable to load any of the alternatives:
   ("libmd"
    #P"/Users/nathan/quicklisp/dists/quicklisp/software/cephes.cl-20221106-git/scipy-cephes/libmd.dylib")

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY                        ] Try loading the foreign library again.
  1: [USE-VALUE                    ] Use another library instead.
  2: [TRY-RECOMPILING              ] Recompile init and try loading it again
  3: [RETRY                        ] Retry
                                     loading FASL for #<CL-SOURCE-FILE "cephes" "init">.
  4: [ACCEPT                       ] Continue, treating
                                     loading FASL for #<CL-SOURCE-FILE "cephes" "init">
                                     as having been successful.
  5:                                 Retry ASDF operation.
  6: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the
                                     configuration.
  7:                                 Retry ASDF operation.
  8:                                 Retry ASDF operation after resetting the
                                     configuration.
  9: [ABORT                        ] Give up on "cephes"
 10:                                 Give up on "lisp-stat"
 11: [REGISTER-LOCAL-PROJECTS      ] Register local projects and try again.
 12:                                 Exit debugger, returning to top level.

(CFFI::FL-ERROR "Unable to load any of the alternatives:~%   ~S" ("libmd" #P"/Users/nathan/quicklisp/dists/quicklisp/software/cephes.cl-20221106-git/scipy-cephes/libmd.dylib"))
   source: (ERROR 'LOAD-FOREIGN-LIBRARY-ERROR :FORMAT-CONTROL CONTROL
                  :FORMAT-ARGUMENTS ARGUMENTS)

Furthermore:

$ file libmd.dylib 
libmd.dylib: Mach-O 64-bit dynamically linked shared library x86_64
$ uname -a
Darwin polaris.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020 arm64

Note here in particular the mismatch between the dylib arch and that reported by uname.

Workaround

If I manually replace the included dylib with an arm64 build from homebrew, everything builds correctly.

Discussion

I'm not sure how you want to approach this because you can't very well include two files with identical names. I'm not particularly familiar with ASDF and whether or not it allows us to include a file conditional on the target OS, but I'm able to conduct some tests on my end if you don't have access to an arm64 machine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.