Created
February 19, 2021 09:55
-
-
Save baioc/75ffa4d9c06c65675c2fa205d789cdbd to your computer and use it in GitHub Desktop.
Polynomial definition and conversion to Horner form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import (scheme base)) | |
(define-syntax hornify | |
(syntax-rules () | |
((_ x an) an) | |
((_ x a pn ...) | |
(+ a (* x (hornify x pn ...)))))) | |
(define-syntax poly | |
(syntax-rules () | |
((_ (x y ...) (pn ...)) | |
(lambda (x y ...) (hornify x pn ...))))) | |
(define (quadratic a b c) | |
(poly (x) (c b a))) | |
((quadratic 1 -1 -1) 1.618) ; => =~ 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment