Giter Site home page Giter Site logo

dieggsy / csl Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 413 KB

CSL: Chicken Scientific Library! - Chicken Scheme bindings to the GNU Scientific Library (GSL)

License: GNU General Public License v3.0

Scheme 99.74% Emacs Lisp 0.20% Makefile 0.07%
scheme scientific-computing linear-algebra chicken-scheme gsl

csl's Introduction

CSL: Chicken Scientific Library

NOTE: This egg is still very much a work in progress.

This is a Chicken Scheme egg for the GNU Scientific Library (GSL), providing both low-level bindings and a more idiomatic API, as well as some generic functions for convenience.

For GSL function/variable reference, see the official gsl documentation. In this document I’ll only point out functions that have been added, omitted, or whose names have changed.

  • If a function or constant is not listed, you can safely assume the name and parameters are the same as in gsl but with the prefix dropped and underscores changed to dashes.
  • Functions prefixed with ! are provided despite there being an equal (or better) built-in alternative (this might be opinionated, and is open to discussion).
  • Because of the way GSL’s representation of complex numbers is wrapped, GSL functions that work on complex numbers in GSL should work on both complex and real numbers in CSL.

Mathematical Functions

(import (csl math double))
;; equivalently: (import csl.math.double)

GSL prefix: gsl_ (except constants, all of which were changed)

Mathematical Constants

CSLGSL
eM_E
log2eM_LOG2E
sqrt2M_SQRT2
sqrt1/2M_SQRT1_2
sqrt3M_SQRT3
piM_PI
pi/2M_PI_2
pi/4M_PI_4
sqrtpiM_SQRTPI
2/sqrtpiM_2_SQRTPI
1/piM_1_PI
2/piM_2_PI
ln10M_LN10
ln2M_LN2
lnpiM_LNPI
eulerM_EULER

Infinities and Not-a-number

Constants

CSLGSL
+infGSL_POSINF
-infGSL_NAN
nanGSL_NAN

Functions

CSL NAMEGSL
!nan?gsl_isnan
!infinite?gsl_isinf
!finite?gsl_finite

Elementary Functions

CSLGSL
log1+gsl_log1p
exp-1gsl_expm1
hypot2gsl_hypot

Modified

[procedure] (frexp x)

Splits the number x into its normalized fraction (double) f and exponent e, such that (= x (* f (expt 2 e))) and (and (<= 0.5 f) (< f 1)). Returns f and e as multiple values.

Modification reason: ‘Out parameters’ are messy in compiled chicken, unavailable in interpreted chicken, and un-idiomatic in both.

Added

[procedure] (hypot a b [c])

Computes the value of (sqrt (expt a 2) (expt b 2)) or (sqrt (expt a 2) (expt b 2) (expt c 2)) as needed, using hypot2 or hypot3, respectively.

Addition reason: In scheme, optional parameters are more convenient than multiple functions.

[procedure] (cosh x)
[procedure] (sinh x)
[procedure] (tanh x)

Compute the hyperbolic sine, cosine, and tangent of x, respectively. These come from math.h.

Addition reason: GSL provides the inverse of these, but does not provide its own versions of these with the assumption that the user will utilize the math.h versions, but Chicken doesn’t provide these either, so it’s convenient to provide provide these as well.

Small integer powers

CSLGSL
expt-intgsl_pow_int
expt2gsl_pow_2
expt3gsl_pow_3
expt4gsl_pow_4
expt5gsl_pow_5
expt6gsl_pow_6
expt7gsl_pow_7
expt8gsl_pow_8
expt9gsl_pow_9

Testing the sign of numbers

CSLGSL
signGSL_SIGN

Testing for odd and even numbers

CSLGSL
!odd?GSL_IS_ODD
!even?GSL_IS_EVEN

Maximum and minimum functions

CSLGSL
!max-dblGSL_MAX_DBL
!min-dblGSL_MIN_DBL
!max-intGSL_MAX_INT
!min-intGSL_MIN_INT
!max-ldblGSL_MAX_LDBL
!min-ldblGSL_MIN_LDBL

Modified

[procedure] (!max . args)
[procedure] (!min . args)

Get the maximum and minimum argument, respectively. Wrap GSL_MAX and GSL_MIN.

Modification reason: accept multiple args.

Complex Numbers

(import (csl math complex))
;; equivalently: (import csl.math.complex)

GSL prefix: gsl_complex_

Representation of complex numbers

CSLGSL
!make-rectangulargsl_complex_rect
!make-polargsl_complex_polar
!anglegsl_complex_arg
!magnitudegsl_complex_abs
magnitude-squaredgsl_complex_abs2
log-magnitudegsl_logabs
!negativegsl_complex_negative
!sqrtgsl_complex_sqrt
!exptgsl_complex_pow
!expgsl_complex_exp
!log10gsl_complex_log10
!loggsl_complex_log
!singsl_complex_sin
!asingsl_complex_asin
!cosgsl_complex_cos
!acosgsl_complex_acos
!tangsl_complex_tan
!atangsl_complex_atan

Modified

[procedure] (!+ . args)
[procedure] (!- . args)
[procedure] (!* . args)
[procedure] (!/ . args)

Add, subtract, multiply, and divide numbers, based on gsl_complex_add, gsl_complex_sub, gsl_complex_mul, and gsl_complex_div, respectively, but accept an arbitrary number of arguments.

Modification reason: accept multiple args.

Polynomials

(import (csl poly))
;; equivalently: (import csl.poly)

GSL prefix: gsl_

Polynomial evaluation

Omitted

FunctionReason
gsl_poly_evalFunctionality is covered by gsl_complex_poly_complex_eval
gsl_poly_complex_evalSee above

Modified

[procedure] (poly-eval c z)

Wraps gsl_complex_poly_complex_eval. Evaluates a polynomial with complex or real coefficients given by list c for the complex or real variable x.

Modification reason: Handles either complex or real doubles. Working with pointers to C arrays isn’t available in interpreted scheme.

[procedure] (poly-eval-derivs c x [num-derivs])

Evaluates a polynomial and its derivatives, returning a list of the results.

Modification reason: Working with pointers to C arrays isn’t available in interpreted scheme.

Added

[procedure] (poly-eval* c z)

Similar to poly-eval, but implemented purely in scheme - should be able to handle all numerical types supported by Chicken Scheme, including exact numbers and bignums.

Addition reason: support more numerical types.

[procedure] (poly-eval-derivs* c z)

Similar to poly-eval-derivs, but implemented purely in scheme - should be able to handle all numerical types supported by Chicken Scheme, including complex numbers, exact numbers, and bignums.

Addition reason: support more numerical types

Divided Difference Representation of Polynomials

Modified

[procedure] (poly-dd-init xa ya)

Computes a divided-difference representation of the interpolating polynomial for the points (x, y) stored in the lists xa and ya of equal size.

Modification reason: Pointers to arrays and out paramaters aren’t easy to work with in interpreted scheme.

[procedure] (poly-dd-eval dd xa x)

Evaluates the polynomial stored in divided-difference form in the lists dd and xa of equal length at point x.

Modification reason: Pointers to arrays aren’t easy to work with in interpreted scheme.

[procedure] (poly-dd-taylor xp dd xa)

Converts the divided-difference representation of a polynomial to a Taylor expansion. The divided-difference representation is supplied in the lists dd and xa of equal size. On output the Taylor coefficients of the polynomial expanded about the point xp are returned as an array.

Quadratic Equations

Omitted

FunctionReason
gsl_poly_solve_quadraticFunctionality is covered by gsl_poly_complex_solve_quadratic

Modified

[procedure] (solve-quadratic a b c)

Wraps gsl_poly_complex_solve_quadratic. Returns two roots, or one root and #f, as multiple values.

Modification reason: Out parameters and C pointers.

Added

[procedure] (solve-quadratic* a b c)

Like solve-quadratic, but implemented purely in scheme - should be able to handle all numerical types supported by Chicken Scheme, including complex numbers, exact numbers, and bignums.

Addition reason: support more numerical types.

Cubic Equations

Omitted

FunctionReason
gsl_poly_solve_cubicFunctionality is covered by gsl_poly_complex_solve_cubic

Modified

[procedure] (solve-cubic a b c)

Wraps gsl_poly_complex_solve_cubic. Returns three roots as multiple values.

Modification reason: Out parameters and C pointers.

Added

example [procedure] (solve-cubic* a b c)

Like solve-cubic, but implemented purely in scheme - should be able to handle all numerical types supported by Chicken Scheme, including complex numbers, exact numbers, and bignums.

Addition reason: support more numerical types.

General Polynomial Equations

Modified

[procedure] (poly-solve a)

Wraps gsl_poly_complex_solve. Computes the roots of the general polynomial whose coefficients are given by the list a. The coefficient of the highest order term must be non-zero.

Modification reason: Out parameters and C pointers.

Special Functions

Vectors and Matrices

csl's People

Contributors

dieggsy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.