This file contains hidden or 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
| (define (make-interval a b) (cons a b)) | |
| (define (upper-bound x) (car x)) | |
| (define (lower-bound x) (cdr x)) | |
| (define (width x) (- (cdr x) (car x))) | |
| (define (mul-interval x y) | |
| (let ((p1 (* (lower-bound x) (lower-bound y))) | |
| (p2 (* (lower-bound x) (upper-bound y))) | |
| (p3 (* (upper-bound x) (lower-bound y))) |
This file contains hidden or 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
| (define (make-interval a b) (cons a b)) | |
| (define (upper-bound x) (car x)) | |
| (define (lower-bound x) (cdr x)) | |
| (define (width x) (- (cdr x) (car x))) | |
| (define (mul-interval x y) | |
| (let ((p1 (* (lower-bound x) (lower-bound y))) | |
| (p2 (* (lower-bound x) (upper-bound y))) | |
| (p3 (* (upper-bound x) (lower-bound y))) |
This file contains hidden or 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
| (define (make-interval a b) (cons a b)) | |
| (define (upper-bound x) (car x)) | |
| (define (lower-bound x) (cdr x)) | |
| (define (width x) (- (cdr x) (car x))) | |
| (define (center i) | |
| (/ (+ (lower-bound i) (upper-bound i)) 2)) | |
| (define (make-center-percent c p) | |
| (let ((w (* c (/ p 100)))) |
This file contains hidden or 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
| (define (par1 r1 r2) | |
| (div-interval (mul-interval r1 r2) | |
| (add-interval r1 r2))) | |
| (define (par2 r1 r2) | |
| (let ((one (make-interval 1 1))) | |
| (div-interval one | |
| (add-interval (div-interval one r1) | |
| (div-interval one r2))))) |
This file contains hidden or 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
| ;Эквивалентные алгебраические выражения могут давать различные результаты потому-что для нашей интервальной арифметики | |
| ;не работает дистрибутивность (и возможно ещё какие-нибудь св-ва обычной арифметики). | |
| ;написание пакета для работы с интервальной арифметикой, не обладающего данным недостатком осложняется | |
| ;сведением всех выражений к какому-то общему виду, либо вычислением погрешностей отдельно от основной арифметики. |
This file contains hidden or 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
| (define (last-pair items) | |
| (define (length-iter a prev) | |
| (if (null? a) | |
| prev | |
| (length-iter (cdr a) (car a)))) | |
| (length-iter items 0)) | |
| (last-pair (list 23 72 149 34)) |
This file contains hidden or 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
| (define (reversel l) | |
| (if (null? l) | |
| l | |
| (append (reversel (cdr l)) (list (car l))) | |
| ) | |
| ) | |
| (reversel (list 1 4 9 16 25)) |
This file contains hidden or 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
| (define (same-parity x . y) | |
| (define (f l) | |
| (cond ((null? l) x) | |
| ((= (remainder x 2) (remainder (car l) 2)) (cons (car l) (f (cdr l)))) | |
| (else (f (cdr l) | |
| ) | |
| ))) | |
| (f y) | |
| ) |
This file contains hidden or 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
| (define (square-list items) | |
| (if (null? items) | |
| () | |
| (cons (* (car items) (car items)) (square-list (cdr items)))) | |
| ) | |
| (define (square-list1 items) | |
| (map (lambda (x)(* x x)) items)) | |
| (square-list (list 1 2 3 4)) |
This file contains hidden or 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
| В первом случае программа Хьюго работает неверно, потому, что он склеивает элементы в обратном порядке, | |
| а во втором потому, что вторым аргументом в cons он передаёт число, а первым - список. |