;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "gsl/gsl-config")



#? *** poly

;; dummy function that adds GSL C header files in C file
(eval `(de dummy_poly () ,gsl-cpheader-cmd ()))

#? * (dummy_poly)
#? * (gsl_poly_eval <c> <len> <x>)
#? * (gsl_poly_dd_init <dd> <x> <y> <size>)
#? * (gsl_poly_dd_eval <dd> <xa> <size> <x>)
#? * (gsl_poly_dd_taylor <c> <xp> <dd> <x> <size> <w>)
#? * (gsl_poly_solve_quadratic <a> <b> <c> <x0> <x1>)
#? * (gsl_poly_complex_solve_quadratic <a> <b> <c> <z0> <z1>)
#? * (gsl_poly_solve_cubic <a> <b> <c> <x0> <x1> <x2>)
#? * (gsl_poly_complex_solve_cubic <a> <b> <c> <z0> <z1> <z2>)
#? * (gsl_poly_complex_workspace_alloc <n>)
#? * (gsl_poly_complex_workspace_free <w>)
#? * (gsl_poly_complex_solve <a> <n> <w> <z>)

;; ********************************************************



(de gsl_poly_eval (    c  len  x )
    ((-gptr- "const double *") c) 
    ((-int-) len) 
    ((-double-) x) 
    (double #{ gsl_poly_eval(  $c ,$len ,$x) #} )
)





(if (> gsl-libversion 1.0)
    (progn
      (de gsl_poly_dd_init (    dd  x  y  size )
	((-gptr- "double *") dd) 
	((-gptr- "const double *") x) 
	((-gptr- "const double *") y) 
	((-int-) size) ;; size_t -> int
	(int #{ gsl_poly_dd_init (  $dd ,$x ,$y ,$size) #} )
	)
      (de gsl_poly_dd_eval (    dd  xa  size  x )
	((-gptr- "const double *") dd) 
	((-gptr- "const double *") xa) 
	((-int-) size) ;; size_t -> int
	((-double-) x) 
	(double #{ gsl_poly_dd_eval (  $dd ,$xa ,$size ,$x) #} )
	)
      (de gsl_poly_dd_taylor (    c  xp  dd  x  size  w )
	((-gptr- "double *") c) 
	((-double-) xp) 
	((-gptr- "const double *") dd) 
	((-gptr- "const double *") x) 
	((-int-) size) ;; size_t -> int
	((-gptr- "double *") w) 
	(int #{ gsl_poly_dd_taylor (  $c ,$xp ,$dd ,$x ,$size ,$w) #} )
	))
  (de gsl_poly_dd_init (    dd  x  y  size )
    ((-gptr- "double *") dd) 
    ((-gptr- "const double *") x) 
    ((-gptr- "const double *") y) 
    ((-int-) size) ;; size_t -> int
    (error "not available in this version of GSL") ())
  (de gsl_poly_dd_eval (    dd  xa  size  x )
    ((-gptr- "const double *") dd) 
    ((-gptr- "const double *") xa) 
    ((-int-) size) ;; size_t -> int
    ((-double-) x) 
    (error "not available in this version of GSL") ())
  (de gsl_poly_dd_taylor (    c  xp  dd  x  size  w )
    ((-gptr- "double *") c) 
    ((-double-) xp) 
    ((-gptr- "const double *") dd) 
    ((-gptr- "const double *") x) 
    ((-int-) size) ;; size_t -> int
    ((-gptr- "double *") w) 
    (error "not available in this version of GSL") ()))


(de gsl_poly_solve_quadratic (    a  b  c  x0  x1 )
    ((-double-) a) 
    ((-double-) b) 
    ((-double-) c) 
    ((-gptr- "double *") x0) 
    ((-gptr- "double *") x1) 
    (int #{ gsl_poly_solve_quadratic (  $a ,$b ,$c ,$x0 ,$x1) #} )
)


(de gsl_poly_complex_solve_quadratic (    a  b  c  z0  z1 )
    ((-double-) a) 
    ((-double-) b) 
    ((-double-) c) 
    ((-gptr- "gsl_complex *") z0) 
    ((-gptr- "gsl_complex *") z1) 
    (int #{ gsl_poly_complex_solve_quadratic (  $a ,$b ,$c ,$z0 ,$z1) #} )
)




(de gsl_poly_solve_cubic (    a  b  c  x0  x1  x2 )
    ((-double-) a) 
    ((-double-) b) 
    ((-double-) c) 
    ((-gptr- "double *") x0) 
    ((-gptr- "double *") x1) 
    ((-gptr- "double *") x2) 
    (int #{ gsl_poly_solve_cubic (  $a ,$b ,$c ,$x0 ,$x1 ,$x2) #} )
)


(de gsl_poly_complex_solve_cubic (    a  b  c  z0  z1  z2 )
    ((-double-) a) 
    ((-double-) b) 
    ((-double-) c) 
    ((-gptr- "gsl_complex *") z0) 
    ((-gptr- "gsl_complex *") z1) 
    ((-gptr- "gsl_complex *") z2) 
    (int #{ gsl_poly_complex_solve_cubic (  $a ,$b ,$c ,$z0 ,$z1 ,$z2) #} )
)





(de gsl_poly_complex_workspace_alloc (    n )
    ((-int-) n)                     ;; size_t -> int
    (gptr #{ gsl_poly_complex_workspace_alloc (  $n) #} )          ;; gsl_poly_complex_workspace * -> gptr
)

(de gsl_poly_complex_workspace_free (    w )
    ((-gptr- "gsl_poly_complex_workspace *") w) 
    #{ gsl_poly_complex_workspace_free (  $w) #} 
    ()
)


(de gsl_poly_complex_solve (    a  n  w  z )
    ((-gptr- "const double *") a) 
    ((-int-) n)                     ;; size_t -> int
    ((-gptr- "gsl_poly_complex_workspace *") w) 
    ((-gptr- "double *") z) 
    (int #{ gsl_poly_complex_solve (  $a ,$n ,$w ,$z) #} )
)


;; ********************************************************

(dhc-make ()
  dummy_poly
  gsl_poly_eval
  gsl_poly_dd_init
  gsl_poly_dd_eval
  gsl_poly_dd_taylor
  gsl_poly_solve_quadratic
  gsl_poly_complex_solve_quadratic
  gsl_poly_solve_cubic
  gsl_poly_complex_solve_cubic
  gsl_poly_complex_workspace_alloc
  gsl_poly_complex_workspace_free
  gsl_poly_complex_solve
)
