Learning notes for the publication (2.1.4)

Source: Internet
Author: User

Learning notes for the publication (2.1.4)
Zhou yinhui

1. Practice 2.7

To get the answer, you need to note that in the text, "Alyssa assumes that there is an abstract object called a range, which has two endpoints, one upper bound and one lower bound". Obviously, an interval is defined by the upper and lower bounds. Just as we say that a point on a plane is defined by its X and Y coordinates, the interval definition function can be written as follows:
(Define (make-interval a B) (cons a B ))
Naturally, the functions for finding the upper and lower bounds are as follows:
; Defines the upper bound
(Define (lower-bound X)
(Car X ))
; Define lower bound
(Define (upper-bound X)
(Cdr x ))

 

2. Practice 2.8

; Define interval Subtraction
(Define (sub-interval x y)
(Make-interval (-(lower-bound X) (lower-bound y ))
(-(Upper-bound X) (upper-bound y ))))

 

3. Practice 2.9

Let's first define the double interval width:
(Define (width x)
(/(-(Upper-bound X) (lower-bound X) 2.0 ))

For the range addition and subtraction, we need to prove that "the range and the bandwidth difference are equal to the sum of the bandwidth difference". Below we use the "difference" as a column to briefly prove that, lx indicates the lower bound of range X, UX indicates the upper bound of range X, and wx indicates twice the width of range X (the reason is to double the width of range X for the convenience of writing the following proof, every expression divided by 2 is too tedious to write ):
(Width (sub-interval x y ))
=> (W (make-interval (-lx ly) (-UX uy )))
=> According to the definition of (width x), it is equal to the upper bound minus the lower bound, and in the above expression (make-interval (-lx ly) (-UX uy )) the upper bound of (-UX uy) is (-lx ly), so
=> (-UX uy) (-lx ly )))
=> For ease of understanding, write the above expression as an infix
=> (Ux-uy)-(Lx-ly)
=> Ux-UY-lx + ly
=> (Ux-lx)-(UY-ly)
=> According to the width definition
=> WX-Wy
So "The width of the difference is equal to the width difference", and the sum is the same.
Multiplication and division do not prove. For example, x = (2, 4) y = (4, 6), their product width is 8, and the product of width is 1.

 

4. Practice 2.10

It is very simple. Because the upper and lower bounds of Y are used as denominator, it is determined whether it is 0:
(Define (div-interval x y)
(If (or (= 0 (upper-bound y) (= 0 (lower-bound y )))
(Display "Division by zero ")
(Mul-interval x
(Make-interval (/1.0 (upper-bound y ))
(/1.0 (lower-bound y ))))))

 

5. Practice 2.11

Ben's mysterious words really make Program Became obscure:
(Define (mul-interval x y)
(Let (A (lower-bound X ))
(B (upper-bound X ))
(C (lower-bound y ))
(D (upper-bound y )))
(Cond (<B 0)
(Cond (<D 0)
(Make-interval (* B D) (* A C )))
(<C 0)
(Make-interval (* a d) (* a c )))
(Else
(Make-interval (* a d) (* B c )))))
(<A 0)
(Cond (<D 0)
(Make-interval (* B c) (* A C )))
(<C 0)
(Let (p1 (* a c ))
(P2 (* a d ))
(P3 (* B C ))
(P4 (* B D )))
(Make-interval (Min P1 P2 P3 P4)
(Max P1 P2 P3 P4 ))))
(Else
(Make-interval (* a d) (* B D )))))
(Else
(Cond (<D 0)
(Make-interval (* B c) (* A D )))
(<C 0)
(Make-interval (* B c) (* B D )))
(Else
(Make-interval (* a c) (* B D ))))))))

 

6. Practice 2.12

(Define (percent c p)
(* P (/C 100.0 )))

(Define (make-center-percent c p)
(Let (A (percent C p )))
(Make-interval (-c a) (+ c ))))

 

7. Exercise 2.13

First, assume that the error of X is deltax, and the change range of X value is (x ± deltax). To facilitate the expression, dx is used to represent ± deltax, then the change range of the value of X is (x + dx), and The percentile error value of X should be (dx/x) * 100%

Then we can see two numbers with errors x multiplied by Y:
(X + dx) * (Y + dy)
=> Xy + x * dy + y * dx + dx * DY
Because Dx and Dy are small, DX * dy approaches 0. We can omit it and convert it:
=> Xy + x * dy + y * DX
It is hard to understand that in the above formula (x * dy + y * dx) is the XY error, that is, the change range of xy is xy + (x * dy + y * dx)
So the percentage error of XY (x * dy + y * dx)/XY) * 100%, that is, (dy/Y + dx/x) * 100%

 

8. Practice 2.14

The two methods are equivalent in mathematics, but the actual computing results of the computer are different,CodeAs follows:
(Define (make-interval a B) (cons a B ))

(Define (lower-bound X)
(Car X ))

(Define (upper-bound X)
(Cdr x ))

(Define (add-interval x y)
(Make-interval (+ (lower-bound X) (lower-bound y ))
(+ (Upper-bound X) (upper-bound y ))))

(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 )))
(P4 (* (upper-bound X) (upper-bound y ))))
(Make-interval (Min P1 P2 P3 P4)
(Max P1 P2 P3 P4 ))))

(Define (div-interval x y)
(Mul-interval x
(Make-interval (/1.0 (upper-bound y ))
(/1.0 (lower-bound y )))))

(Define (par1 R1 R2)
(Div-interval (mul-interval R1 R2)
(Add-interval R1 R2 )))
(Define (par2 R1 R2)
(Let (one (make-interval 1 )))
(Div-interval one
(Add-interval (div-interval one R1)
(Div-interval one R2 )))))

(Define (percent c p)
(* P (/C 100.0 )))

(Define (make-center-percent c p)
(Let (A (percent C p )))
(Make-interval (-c a) (+ c ))))

(Define (center I)
(/(+ (Lower-bound I) (upper-bound I) 2 ))

(Define a (make-center-percent 2 5 ))
(Define B (make-center-percent 3 6 ))

(Center (par1 a B ))
(Center (par2 a B ))
 
The two centers are calculated as follows: 1.2148016178736518 and 1.1999711093990755.
There is indeed such a difference. For example, (1/3) * 3 is equal to 1 in mathematics, but in actual calculation, for example, we keep the precision of the two digits after the decimal point, then 1/3 equals 0.33, multiplied by 3, and the final result is 0.99.

9. Practice 2.15

It seems that eva lu ator makes sense. For example, the error of number A between the range (2, 3) is ± 0. 5, while a ^ A is between (), the error value is ± 2. 5

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.