GithubHelp home page GithubHelp logo

simpsons-rule's Introduction

simpsons-rule

CI tests

This system is for numeric integration of functions of one variable. See an example:

CL-USER> ;; Integrate sin(500x)/x from -5 to 5
; No value
CL-USER> (simpsons-rule:integrate
 (serapeum:hook
  (serapeum:flip #'/)
  (alexandria:compose
   #'sin
   (alexandria:curry #'* 500)))
 -5d0 5d0)
3.1409850016443404d0

All numeric arguments to SIMPSONS-RULE:INTEGRATE must be of the same floating point type T and the function must be of the type T -> T.

The compiler produces specialized code when types of arguments are known at compile time and when optimizing for speed:

CL-USER> (defun integrate-in-unit-range (fn)
  (declare (optimize speed))
  (simpsons-rule:integrate fn 0d0 1d0))
INTEGRATE-IN-UNIT-RANGE
CL-USER> (disassemble 'integrate-in-unit-range)
; disassembly for INTEGRATE-IN-UNIT-RANGE
; Size: 46 bytes. Origin: #x224A91BD                          ; INTEGRATE-IN-UNIT-RANGE
; BD:       488B3DC4FFFFFF   MOV RDI, [RIP-60]                ; 0.0d0
; C4:       488B35B5FFFFFF   MOV RSI, [RIP-75]                ; 1.0d0
; CB:       488B05A6FFFFFF   MOV RAX, [RIP-90]                ; 1.0d-6
; D2:       488945F0         MOV [RBP-16], RAX
; D6:       488B5DF0         MOV RBX, [RBP-16]
; DA:       B908000000       MOV ECX, 8
; DF:       FF7508           PUSH QWORD PTR [RBP+8]
; E2:       B882B74520       MOV EAX, #x2045B782              ; #<FDEFN SIMPSONS-RULE:INTEGRATE/DOUBLE-FLOAT>
; E7:       FFE0             JMP RAX
; E9:       CC10             INT3 16                          ; Invalid argument count trap
NIL
CL-USER> 

SIMPSONS-RULE:INTEGRATE expands to one of specialized versions: either SIMPSONS-RULE:INTEGRATE/SINGLE-FLOAT or SIMPSONS-RULE:INTEGRATE/DOUBLE-FLOAT when possible.

simpsons-rule's People

Contributors

shamazmazum avatar

Watchers

 avatar James Cloos 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.