{"id":17508142,"url":"https://github.com/iraikov/chicken-sundials","last_synced_at":"2026-03-19T22:18:17.588Z","repository":{"id":148366659,"uuid":"38978199","full_name":"iraikov/chicken-sundials","owner":"iraikov","description":"Chicken Scheme bindings to SUNDIALS (SUite of Nonlinear and DIfferential/ALgebraic equation Solvers)","archived":false,"fork":false,"pushed_at":"2021-05-02T03:57:32.000Z","size":39,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-09T22:05:36.302Z","etag":null,"topics":["chicken-scheme","chicken-scheme-eggs","cvode","cvode-solver","dae","ida-solvers","ode","ode-solver","scheme-language","sundials"],"latest_commit_sha":null,"homepage":null,"language":"Scheme","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iraikov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-07-12T21:11:52.000Z","updated_at":"2022-08-07T10:12:42.000Z","dependencies_parsed_at":"2023-05-19T21:30:35.911Z","dependency_job_id":null,"html_url":"https://github.com/iraikov/chicken-sundials","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/iraikov/chicken-sundials","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-sundials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-sundials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-sundials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-sundials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iraikov","download_url":"https://codeload.github.com/iraikov/chicken-sundials/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-sundials/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28906222,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T04:02:34.702Z","status":"ssl_error","status_checked_at":"2026-01-30T04:02:33.562Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chicken-scheme","chicken-scheme-eggs","cvode","cvode-solver","dae","ida-solvers","ode","ode-solver","scheme-language","sundials"],"created_at":"2024-10-20T04:03:29.678Z","updated_at":"2026-01-30T06:03:59.891Z","avatar_url":"https://github.com/iraikov.png","language":"Scheme","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sundials\n\n## Description\n\nThe Chicken `sundials` library provides bindings to the solvers from\nthe SUNDIALS library (http://computation.llnl.gov/casc/sundials/)\n. SUNDIALS (SUite of Nonlinear and DIfferential/ALgebraic equation\nSolvers) is a collection of solvers for systems of ordinary\ndifferential equations and differential-algebraic equations.\n\nThe Chicken `sundials` library provides interfaces to the CVODE and\nIDA solvers and has been tested with SUNDIALS versions 2.4.0 and 2.5.0.\n\n\n## Library procedures\n\n### IDA solver interface\n\n\n\u003cprocedure\u003e(ida-create-solver TSTART TSTOP VARIABLES DERIVATIVES RESIDUAL-MAIN [RESIDUAL-INIT] [RESIDUAL-EVENT] [EVENTS] [ALG-OR-DIFF]   [SUPPRESS] [IC] [USER-DATA] [RELTOL] [ABSTOL]) =\u003e IDA-SOLVER\u003c/procedure\u003e\n\nCreates and initializes an object representing a problem to be solved\nwith the IDA solver.  \n\nArguments `TSTART` and `TSTOP` must be real numbers that represent\nthe beginning and end of the independent variable range.\n\nArguments `VARIABLES` and `DERIVATIVES` must be SRFI-4\n`f64vector` objects that hold respectively the initial values and\nderivatives of the system variables.\n\nArgument `RESIDUAL-MAIN` is used to compute the residual function\n`F` and must be a procedure of the following form:\n\n (LAMBDA T YY YP DATA)\n\nor\n\n (LAMBDA T YY YP)\n\ndepending on whether the `USER-DATA` optional argument is set, where \n\n; `T`  :  real-valued independent variable\n; `YY` : SRFI-4 `f64vector` with current variable values\n; `YP` : SRFI-4 `f64vector` with current variable derivatives\n; `DATA` : is a user data object (if set)\n\nThis procedure must return a SRFI-4 `f64vector` containing the\nresidual vector.\n\nOptional keyword argument `RESIDUAL-EVENT` must be a procedure of\nthe same form as `RESIDUAL-MAIN`, which computes a rootfinding\nproblem to be solved during the integration of the system. It is set\nonly if argument `EVENTS` is given.\n\nOptional keyword argument `EVENTS` is an SRFI-4 `s32vector` that\nis used for storage of root finding solutions. It must be given if\n`RESIDUAL-EVENT` is given.\n\nOptional keyword argument `ALG-OR-DIFF` must be an SRFI-4\n`s32vector` which indicates the algebraic and differential variables\nin the system. A value of 1 indiciates differential variable, and a\nvalue of 0 indicates an algebraic one. This is required if the\n`SUPPRESS` argument is given and true.\n\nOptional keyword argument `SUPPRESS` is a boolean flag that\nindicates whether algebraic variables must be suppressed in the local\nerror test. If it is true (suppress), then the argument\n`ALG-OR-DIFF` must be given.\n\nOptional keyword argument `IC` is a boolean flag that indicates\nwhether the solver must calculate consistent initial conditions, or\nwhether it must use the initial conditions given by `VARIABLES`.\n\nOptional keyword argument `USER-DATA` is an object that will be\npassed as an additional argument to the residual functions.\n\nOptional keyword arguments `RELTOL` and `ABSTOL` specify relative\nand absolute error tolerance, respectively. These both default to\n1e-4.\n\n\n\u003cprocedure\u003e(ida-reinit-solver IDA-SOLVER T0 Y0 YP0)\u003c/procedure\u003e\n\nRe-initializes IDA for the solution of a problem.\n\n\u003cprocedure\u003e(ida-destroy-solver IDA-SOLVER)\u003c/procedure\u003e\n\nDeallocates the memory associated with the given solver.\n\n\u003cprocedure\u003e(ida-solve IDA-SOLVER T)\u003c/procedure\u003e\n\nIntegrates the system over an interval in the independent\nvariable. This procedure returns either when the given `T` is\nreached, or when a root is found.\n\n\u003cprocedure\u003e(ida-yy IDA-SOLVER)\u003c/procedure\u003e\n\nReturns the vector of current state values of the system.\n\n\u003cprocedure\u003e(ida-yp IDA-SOLVER)\u003c/procedure\u003e\n\nReturns the vector of current state derivative values of the system.\n\n\u003cprocedure\u003e(ida-get-last-order IDA-SOLVER)\u003c/procedure\u003e\n\nReturns the order used during the last solver step.\n\n\u003cprocedure\u003e(ida-get-last-step IDA-SOLVER)\u003c/procedure\u003e\n\nReturns the steps size used during the last solver step.\n\n\u003cprocedure\u003e(ida-get-num-steps IDA-SOLVER)\u003c/procedure\u003e\n\nReturns the cumulative number of steps taken by the solver.\n\n\n### CVODE solver interface\n\n\n\u003cprocedure\u003e(cvode-create-solver TSTART TSTOP VARIABLES RHS-FN [LMM] [ITER] [EWT-FN] [EVENT-FN] [EVENTS] [USER-DATA] [RELTOL] [ABSTOL]) =\u003e CVODE-SOLVER\u003c/procedure\u003e\n\nCreates and initializes an object representing a problem to be solved\nwith the CVODE solver.  \n\nArguments `TSTART` and `TSTOP` must be real numbers that represent\nthe beginning and end of the independent variable range.\n\nArguments `VARIABLES` must be a SRFI-4 `f64vector` object that\nholds the initial values of the system variables.\n\nArgument `RHS-FN` is used to compute the right-hand side of the\nequations, and must be a procedure of the following form:\n\n (LAMBDA T YY DATA)\n\nor\n\n (LAMBDA T YY)\n\ndepending on whether the `USER-DATA` optional argument is set, where \n\n; `T`  :  real-valued independent variable\n; `YY` : SRFI-4 `f64vector` with current variable values\n; `DATA` : is a user data object (if set)\n\nThis procedure must return a SRFI-4 `f64vector` containing the\nresidual vector.\n\nOptional keyword argument `EWT-FN` must be a procedure of the same\nform as `(LAMBDA YY)`, which computes error weights for the system\nvariables, and which can be used in place of relative and absolute\nerror tolerance.\n\nOptional keyword argument `EVENT-FN` must be a procedure of\nthe same form as `RHS-FN`, which computes a rootfinding\nproblem to be solved during the integration of the system. It is set\nonly if argument `EVENTS` is given.\n\nOptional keyword argument `EVENTS` is an SRFI-4 `s32vector` that\nis used for storage of root finding solutions. It must be given if\n`EVENT-FN` is given.\n\nOptional keyword argument `LMM` specifies the linear multistep\nmethod to be used and can be one of `cvode-lmm/adams` (default) or\n`cvode-lmm/bdf`. `cvode-lmm/bdf` is recommended for stiff\nproblems.\n\nOptional keyword argument `ITER` specifies the iteration type to be\nused and can be one of `cvode-iter/functional` (default) or\n`cvode-iter/newton`. `cvode-iter/newton` is recommended for stiff\nproblems.\n\nOptional keyword argument `USER-DATA` is an object that will be\npassed as an additional argument to the residual functions.\n\nOptional keyword arguments `RELTOL` and `ABSTOL` specify relative\nand absolute error tolerance, respectively. These both default to\n1e-4. They are only set of `EWT-FN` is not specified.\n\n\n\u003cprocedure\u003e(cvode-reinit-solver CVODE-SOLVER T0 Y0 YP0)\u003c/procedure\u003e\n\nRe-initializes CVODE for the solution of a problem.\n\n\u003cprocedure\u003e(cvode-destroy-solver CVODE-SOLVER)\u003c/procedure\u003e\n\nDeallocates the memory associated with the given solver.\n\n\u003cprocedure\u003e(cvode-solve CVODE-SOLVER T)\u003c/procedure\u003e\n\nIntegrates the system over an interval in the independent\nvariable. This procedure returns either when the given `T` is\nreached, or when a root is found.\n\n\u003cprocedure\u003e(cvode-yy CVODE-SOLVER)\u003c/procedure\u003e\n\nReturns the vector of current state values of the system.\n\n\n## Example\n\n```scheme\n\n ;;\n ;; Hodgkin-Huxley model\n ;;\n \n (use mathh sundials srfi-4)\n \n (define neg -)\n (define pow expt)\n \n (define TEND  500.0)\n \n   \t                   \n ;; Model parameters\n \n (define (I_stim t) 10)\n (define C_m       1)\n (define E_Na      50)\n (define E_K       -77)\n (define E_L       -54.4)\n  (define gbar_Na   120)\n (define gbar_K    36)\n (define g_L       0.3)\n \n ;; Rate functions\n \n (define (amf v)   (* 0.1    (/ (+ v 40)  (- 1.0 (exp (/ (neg (+ v 40)) 10))))))\n (define (bmf v)   (* 4.0    (exp (/ (neg (+ v 65)) 18))))\n (define (ahf v)   (* 0.07   (exp (/ (neg (+ v 65)) 20))))\n (define (bhf v)   (/ 1.0    (+ 1.0 (exp (/ (neg (+ v 35)) 10)))))\n (define (anf v)   (* 0.01   (/ (+ v 55) (- 1 (exp (/ (neg (+ v 55)) 10))))))\n (define (bnf v)   (* 0.125  (exp (/ (neg (+ v 65)) 80))))\n \n ;; State functions\n \n (define (minf v) (* 0.5 (+ 1 (tanh (/ (- v v1) v2)))))\n (define (winf v) (* 0.5 (+ 1 (tanh (/ (- v v3) v4)))))\n (define (lamw v) (* phi (cosh (/ (- v v3) (* 2 v4)))))\n   \t                   \n ;; Model equations\n \n (define (rhs t yy)\n \n   (let ((v (f64vector-ref yy 0))\n \t(m (f64vector-ref yy 1))\n \t(h (f64vector-ref yy 2))\n \t(n (f64vector-ref yy 3)))\n \n     ;; transition rates at current step\n     (let ((am  (amf v))\n \t  (an  (anf v))\n \t  (ah  (ahf v))\n \t  (bm  (bmf v))\n \t  (bn  (bnf v))\n \t  (bh  (bhf v))\n \n \t  (g_Na (* gbar_Na  (* h (pow m 3))))\n \t  (g_K  (* gbar_K   (pow n 4))))\n       \n       (let (\n \n \t    ;; currents\n \t    (I_Na   (* (- v E_Na) g_Na))\n \t    (I_K    (* (- v E_K)  g_K))\n \t    (I_L    (* g_L  (- v E_L))))\n \t\t  \n \t(let (\n \t      ;; state equations\n \t      (dm (- (* am (- 1 m))  (* bm m)))\n \t      (dh (- (* ah (- 1 h))  (* bh h)))\n \t      (dn (- (* an (- 1 n))  (* bn n)))\n \t      (dv (/ (- (I_stim t) I_L I_Na I_K) C_m))\n \t      )\n    \n \t  (f64vector dv dm dh dn)\n \t  \n \t  )))\n     ))\n   \n  (let ((yy (f64vector -65  0.052 0.596 0.317)) ;; v m h n\n \n \t;; Integration limits \n \t(t0  0.0)\n \t(tf  TEND)\n \t(dt  1e-2))\n    \n     ;; CVODE initialization \n     (let ((solver (cvode-create-solver\n \t\t   t0 yy rhs  \n                   tstop: tf\n \t\t   abstol: 1e-4\n \t\t   reltol: 1e-4)))\n \n       ;; In loop, call CVodeSolve, print results, and test for error. \n       \n       (let recur ((tnext (+ t0 dt)) (iout 1))\n \n \t(let ((flag  (cvode-solve solver tnext)))\n \t  (if (negative? flag) (error 'main \"CVODE solver error\" flag))\n  \n          (print-results solver tnext)\n \n \t  (if (\u003c tnext tf)\n \t      (recur (+ tnext dt) (+ 1 iout)))\n \t  ))\n       \n \n      (cvode-destroy-solver solver)\n       \n (define (print-results solver t)\n   (let ((yy (cvode-yy solver)))\n     (printf \"~A ~A ~A ~A ~A ~A ~A ~A~%\" \n \t    t \n \t     (f64vector-ref yy 0)\n\t     (f64vector-ref yy 1)\n\t     (f64vector-ref yy 2)\n\t     (f64vector-ref yy 3)\n\t     (cvode-get-last-order solver)\n\t     (cvode-get-num-steps solver)\n\t     (cvode-get-last-step solver)\n\t     )))\n```\n\n## License\n\n\n  Copyright 2011-2016 Ivan Raikov.\n  All rights reserved.\n  \n  Redistribution and use in source and binary forms, with or without\n  modification, are permitted provided that the following conditions are\n  met:\n  \n  Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n  \n  Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n  \n  Neither the name of the author nor the names of its contributors may\n  be used to endorse or promote products derived from this software\n  without specific prior written permission.\n  \n  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n  \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\n  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n  COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n  OF THE POSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firaikov%2Fchicken-sundials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firaikov%2Fchicken-sundials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firaikov%2Fchicken-sundials/lists"}