5.4.22 · D1 · HinglishScientific Computing (Python)

FoundationsFloating point gotchas — catastrophic cancellation, associativity failure

1,576 words7 min read↑ Read in English

5.4.22 · D1 · Coding › Scientific Computing (Python) › Floating point gotchas — catastrophic cancellation, associat

Yeh page kuch bhi assume nahi karta. Parent note Floating Point Gotchas ko touch karne se pehle, hum har woh symbol build karte hain jo woh use karta hai, ek ek brick karke, har brick pichli wali ke upar.


0. Computer ke liye "number" hota kya hai?

Ek calculator screen ki fixed width hoti hai. Agar woh 4 digits dikha sakti hai, toh fit hota hai ( ke roop mein) lekin add karne se kuch nahi badlta — woh right edge se gir jaata hai. Ek real computer bhi yahi idea hai, bas zyaada digits ke saath. Neeche sab kuch "digits edge se gir jaati hain" ka precise version hai.

Figure — Floating point gotchas — catastrophic cancellation, associativity failure

1. Bits, base-2, aur mantissa

Ek bit ek single 0 ya 1 hota hai. Computers numbers ko base 2 (binary) mein likhte hain, bilkul waise hi jaise hum base 10 mein likhte hain — lekin place-values ki nahi, ki powers hoti hain.

Base 10 mein, . Base 2 mein, .

Aise kyun split karte hain? Kyunki yeh binary mein scientific notation hai. "Digits" aur "scale" ko alag store karna memory ke ek chhote hisse ko aur dono represent karne deta hai. Topic ke liye yeh zaroori hai kyunki exponent gap ka size decide karta hai — aur gap size hi poori kahani hai.


2. Gap, aur machine epsilon

Kyunki mantissa mein sirf 52 bits hain, number ke paas sabse chhoti change jo tum kar sakte ho woh last bit ko flip karna hai, jo worth hai. ke baad gap ka size yahi hai.

Figure — Floating point gotchas — catastrophic cancellation, associativity failure

Yeh picture ek crucial fact dikhati hai: gap number ki magnitude ke saath badhti hai. ke paas gap hai; ke paas gap lagbhag hai; ke paas number ek gap se bhi chhota hai aur add karne par simply gaayab ho jaata hai. Yeh akela visual parent ka "" absorption explain karta hai.


3. Relative vs absolute error — do rulers

Dono kyun? ke liye se galat hona disastrous hai (50%) lekin ke liye negligible (billionth part). Computer ki guarantee relative ruler mein batayi jaati hai kyunki woh saari magnitudes mein constant rehti hai.

Figure — Floating point gotchas — catastrophic cancellation, associativity failure

Symbols kaise padhein:

  • ::: " ka float" — ke sabse kareeb representable double.
  • (delta) ::: woh tiny relative fudge, mein kahin bhi.
  • ::: kyunki rounding kareeb wala neighbour choose karta hai, tum kabhi bhi aadhi gap se zyaada galat nahi ho sakte.

Parent note jo bhi derive karta hai — cancellation amplifier, summation bound — sab is ek line par lagaya gaya algebra hai.


4. Symbols jo parent note mein milenge


5. Yeh bricks topic kaise banate hain

Bits and base-2

Mantissa and exponent

The gap grows with magnitude

Machine epsilon

Relative vs absolute error

Rounding model fl x = x times 1 plus delta

Cancellation amplifier

Associativity failure and absorption

Quadratic and 1 minus cos x fixes

Kahan summation

Numerical stability

Ise top-down padhte hain: raw bits format dete hain, format gap deta hai, gap deta hai, aur relative/absolute distinction ke saath milke rounding model milta hai — woh single equation jisse Catastrophic cancellation, Round-off error propagation, Kahan compensated summation aur Quadratic formula numerical issues sab follow karte hain. Poori chain Numerical stability and conditioning mein land hoti hai.


Equipment checklist

Tum parent note ke liye ready ho jab bina deekhe har sawaal ka jawaab de sako:

ko decimal mein convert karo.
.
IEEE-754 double kitne mantissa bits store karta hai?
52 (plus ek hidden leading 1 = 53 bits of precision).
kya hai aur yeh kya measure karta hai?
, aur next double ke beech ka relative gap.
Stored of true ke liye absolute vs relative error — dono define karo.
absolute ; relative .
Rounding model batao aur har symbol ka matlab batao.
, ; = round to nearest double, = relative slip, = half-gap max.
Bade numbers ke liye representable numbers ke beech ki gap kyun badhti hai?
exponent poori mantissa ko scale karta hai, toh last-bit step ke saath badhta hai.
Computer ki guarantee relative error mein kyun batayi jaati hai?
kyunki yeh saari magnitudes mein constant rehti hai, absolute error ke unlike.