Computer Science/Scientific Computing

1. Fundamentals of Computing

  • -
728x90
반응형

What is scientific computing?

Scientific computing concerns with the design and analysis of algorithms for solving mathematical problems that arise in science and engineering

Problem Solving Process

  1. Develop a mathematical model
  1. Discretize the model and develop algorithms to solve the equations numerically
    💡
    만약 우리가 특정 함수를 taylor 근사를 통해서 접근한다고 했을 때, 특정한 항까지만 고려한 경우 discretize했다고 볼 수 있다. 그래야 컴퓨터를 통해서 계산할 수 있기 때문이다.
  1. Implement and execute the algorithms in computer software.
  1. Interpret and validate the computed results, repeating any or all of the preceding steps, if necessary

Sources of Approximation

Before computation

  1. Mathematical modeling : 즉 모델링 하는 과정에서 근사를 취할 수 있다.
  1. Empirical measurements : 즉 데이터 자체 내에 에러가 존재할 수 있다.
  1. Previous computations : 이전 결과 자체에서 근사가 있을 수 있다.

During computation

  1. Truncation or discretization : 수학적인 근사를 하는 과정에서 발생. 즉 algorithm 자체의 error를 의미한다.
  1. Rounding : 컴퓨팅의 한계로 발생하는 error이다.

Others

  1. Input의 uncertainty로 인해 문제가 가속화될 수 있다. 이를 conditioning problem 이라고 부른다.
  1. input의 perturbation으로 인해 output의 변하는 정도는 모델의 stability와 관련이 있다.

Example

  1. Earth is modeled as a sphere, idealizing its true shape (model simplification)

  1. Value for radius is based on empirical measurements and previous computations (errors in inputs)
    r6371kmr \approx 6371\text{km}
  1. Value of π\pi requires truncating infinite process (roundoff error)
💡
컴퓨터가 표현할 수 있는 자리수는 한계가 있으므로 이 과정에서 roundoff error가 발생하는 것이다.
  1. Values for input data and results of arithmetic operations are rounded by calculator or computer (roundoff error)
    A4×3.14159×(6371)25.10064×108km2A \approx 4 \times 3.14159 \times (6371)^2 \approx 5.10064 \times 10^8 \text{km}^2
💡
마찬가지로 컴퓨터가 표현할 수 있는 자리수가 한계가 있기 때문에 roundoff error가 발생하는 것이다.

Truncation Error and Rounding Error

Computation error is the sum of truncation error and rounding error. In addition, one of these usually dominates.

Truncation error

Difference between the true result (for actual input) and the result produced by given algorithm using exact arithmetic

f(x)=f(x+h)f(x)h+Mh2,M=maxf(x)f'(x) = \frac{f(x+h) - f(x)}{h} + \frac{Mh}{2}, M = \max|f''(x)|
💡
Truncation errors arises when an infinite process is replaced by a finite one

Rounding error

Difference between result produced by given algorithm using exact arithmetic and result produced by the same algorithm using limited precision arithmetic

x=π,x^=3.141592653189793,xx^x1016x = \pi, \hat x = 3.141592653189793, \frac{|x - \hat x|}{|x|}\approx 10^{-16}
💡
Round-off errors depend on the fact that practically each number in a numerical computation must be rounded(or chopped) to a certain number of digits

Example

Error in finite difference approximation exhibits tradeoff between rounding error and truncation error

f(x)f(x+h)f(x)hf'(x) \approx \frac{f(x+h) - f(x)}{h}
  1. Truncation error bounded by Mh/2Mh/2
  1. Rounding error bounded by 2ϵ/h2\epsilon /h, where error in function values bounded by ϵ\epsilon
  1. Total error minimized when h2ϵ/Mh \approx 2\sqrt{\epsilon/M}
    💡
    증명은 간단히 산술기하를 활용해주면 된다.

    → Error increases for smaller hh because of rounding error and increases for larger hh because of truncation error

Absolute Error and Relative Error

Absolute error

Approximate value - true value

xx^\|x - \hat x\|

Relative error

absolute errortrue value=xx^x\frac{\text{absolute error}}{\text{true value}} = \frac{\|x - \hat x\|}{\|x\|}

It is equivalent to

approx value=(true value)×(1 + rel error)\text{approx value}= \text{(true value)}\times \text{(1 + rel error)}
💡
True value는 실제로는 알 수 없는 것이므로, estimate error 를 구하거나 bound error 를 구한다.

Floating-Point Numbers

Floating-point number system characterized by four integers

β:base or radixp:precision[L,U]:exponent range\beta : \text{base or radix} \\ p : precision \\ \left[ L, U\right]: \text{exponent range}

→ 따라서 Floating-point number system은 다음과 같이 표기될 수 있다.

F(β,p,L,U)\mathbb F(\beta, p, L, U)

예를 들어 xRx \in \R는 다음과 같이 표현된다.

x=(1)σ(d0.d1d2dp1)β×βe=(1)σ(d0+d1β1+d2β2++dp1β(p1))×βe\begin{aligned} x &= (-1)^\sigma(d_0.d_1d_2\cdots d_{p - 1})_\beta \times \beta^e \\ &= (-1)^\sigma(d_0 + d_1\beta^{-1} + d_2\beta^{-2}+\cdots + d_{p - 1}\beta^{-(p - 1)})\times \beta^e \end{aligned}

where digits dk{0,1,,β1}d_k \in \{0, 1, \dots, \beta - 1\} with d00d_0 \ne 0 (for normalization) and exponent ee is an integer such that

LeUL \le e \le U
💡
2진법 기준으로 d00d_0 \ne 0을 보장해줌으로써 추가적인 bit를 사용하지 않아도 된다는 장점이 존재하게 된다. (해당 bit를 mantissa에 더 사용할 수 있다.)

Properties

  1. Total number of normalized floating-point numbers is
    2(β1)βp1(UL+1)+12(\beta - 1)\beta^{p - 1}(U - L + 1) + 1
  1. Smallest positive normalized number
    xmin=βLx_{\min} = \beta^L
  1. Largest floating-point number
    xmax=βU+1(1βp)x_{\max} = \beta^{U + 1}(1 - \beta^{-p})
    💡
    제일 작은 숫자 단위가 β(p1)\beta^{-(p - 1)}이다. 1은 βU\beta^U에 붙었다고 생각해주면 된다. 해당 숫자를 더해주게 되면 βU+1\beta^{U + 1}이 되면서 자릿수가 증가하기 때문에, 저 숫자가 최대라고 할 수 있다.
  1. Floating-point numbers equally spaced only between successive powers of β\beta
    💡
    당연히 단위는 βe\beta^e만큼 동간격으로 떨어지게 된다.
  1. Not all real numbers are exactly representable; those that are called machine numbers
    💡
    앞에서 설명한 것처럼 컴퓨터는 bit의 한계 때문에 round-off를 반드시 수행해야 한다. 이 과정을 통해 나타낼 수 있는 숫자들을 machine number 라고 하는 것이다.
  1. Numbers in F\mathbb F are symmetric with respect to zero
    💡
    Computer Architecture에서 배운 것처럼 sign-bit를 차용하기 때문이라고 이해하면 될 듯 싶다.

Example

💡
위 그림에서 확인할 수 있는 것처럼, 숫자가 커질수록 absolute-error는 커지게 된다. 하지만 true-value가 커짐에 따라서 relative-error는 작아지게 된다. 이에 수치 계산에서 더 일관된 정밀도를 유지할 수 있게 되는 장점이 존재한다.

Machine Epsilon

Definition

The distance between 1 and the smallest machine number larger than 1 is called machine epsilon and is denoted with ϵM\epsilon_M. The value of machine epsilon is

ϵM=β(p1)\epsilon_M = \beta^{-(p - 1)}
💡
제일 작은 숫자의 단위이다. 또한 추가적으로 이러한 소리를 하려면 LL이 적어도 0이하의 수를 가진다는 것이 전제되어야 한다. 사실상 ϵM=ulp(1)=ϵMβ0\epsilon_M = \text{ulp}(1) = \epsilon_M\beta^0으로 연관지어서 이해할 수 있다.

Definition

The distance between any machine number xFx \in \mathbb F and its consecutive machine number(successor) is called unit in the last place and is denoted with ulp(x)\text{ulp}(x)

ulp(x)=β(p1)×βe=βep+1=ϵMβe\text{ulp}(x) = \beta^{-(p - 1)}\times \beta^e = \beta^{e-p+1} = \epsilon_M\beta^e
💡
βe\beta^e는 현재 xx에 대응되는 exponent값을 그대로 가져왔다고 생각해주면 된다. 즉, ulp의 중요한 점은 successor와의 거리를 machine epsilon을 활용해서 표현할 수 있다는 것이다.

Hidden Bit

Today’s computers use base 2 to internally represent numbers. Therefore, the only choice of digits that remains for the leading bit d0d_0 is d0=1d_0 = 1. This creates an opportunity to save some memory if we avoid occupying the bit d0d_0 with the fixed value of 1. This implicit bit whose value is always 1 for any normalized binary number is called the hidden bit.

x=±(1.d1d2dp1)β×βe=±(1+d1β1+d2β2++dp1β(p1))×βe\begin{aligned} x &= \pm (1.d_1d_2\cdots d_{p - 1})_\beta \times \beta^e \\ &= \pm(1 + d_1\beta^{-1} + d_2\beta^{-2} + \cdots + d_{p - 1}\beta^{-(p - 1)})\times \beta ^e\end{aligned}

Rounding Rules

If real number xx is not exactly representable, then it is approximated by nearby floating-point number fl(x)\text{fl}(x):

fl(x):RF(β,p,L,U)\text{fl}(x) : \R \to \mathbb F(\beta,p, L, U)

This process is called rounding, and error introduced is called rounding error or rondoff error

Rounding rules

Assume x=±(d0.d1dp1dp)β×βex = \pm (d_0.d_1\cdots d_{p - 1}d_p \cdots)_\beta \times \beta^e

Chopping

Truncate base-β\beta expansion of xx after (p1)(p - 1)-st digit

fl(x)=±(d0.d1dp1)β×βe\text{fl}(x) = \pm (d_0.d_1\cdots d_{p - 1})_\beta \times \beta^e
💡
단순 버림을 진행한 것이라고 생각해주면 된다.
fl(x)xxϵMβe(d0.d1d2)ββeϵM(1.0)β=ϵM\frac{|\text{fl}(x) - x|}{|x|}\le \frac{\epsilon_M \beta^e}{(d_0.d_1d_2\cdots)_\beta\beta^e} \le \frac{\epsilon_M}{(1.0)_\beta} = \epsilon_M

Rounding to nearest

fl(x)\text{fl}(x) is the nearest floating-point number to xx, using floating-point number whose last stored digit is even in case of tie

fl(x)=±(d0.d1dp2d~p1)β×βe,\text{fl}(x) = \pm (d_0.d_1\cdots d_{p - 2}\tilde d_{p - 1})_\beta \times \beta^e,

where d~p1\tilde d_{p - 1} is either dp1d_{p - 1} or dp1+1d_{p - 1} + 1

💡
반올림과 유사하나, 단 5인 경우에는 결과가 짝수가 되게끔한다는 점에서 차이를 보인다.
💡
Rounding to nearest는 가장 정확하기 때문에 기본값으로 설정된다.
fl(x)xxϵM2\frac{|\text{fl}(x) - x|}{|x|}\le \frac{\epsilon_M}{2}

Unit roundoff

Definition

The smallest number δ\delta such that fl(1+δ)>1\text{fl}(1 + \delta) > 1 is called unit roundoff and is denoted by uu, that is

u={ϵM2,if rounding is usedϵM,if chopping is usedu = \begin{cases}\frac{\epsilon_M}{2}, &\text{if rounding is used} \\ \epsilon_M, & \text{if chopping is used}\end{cases}
💡
ϵM\epsilon_M은 1의 successor까지의 거리인데 rounding을 사용하게 되면 절반만 가면 된다.

For either chopping or rounding to the nearest we have

fl(x)xxu\frac{|\text{fl}(x) - x|}{|x|}\le u

which is equivalent to

fl(x)=x(1+δ),\text{fl}(x) = x(1+\delta),

where δu|\delta|\le u 

Subnormal numbers

A relatively large gap between zero and xminx_{\min} (underflow region)

Therefore, we define the concept of subnormal numbers as follows

x=±(0.d1d2dp1)β×βLx= \pm (0.d_1d_2\cdots d_{p - 1})_\beta \times \beta^L
💡
정수부가 0이라는 점과 exponent가 LL이라는 점을 주의해야 한다.

Gradual underflow

Let fl(x)=±(0.00dpkdp1)β×βL\text{fl}(x) = \pm (0.0\cdots0 d_{p - k}\cdots d_{p - 1})_\beta \times \beta^L with dpk0d_{p - k}\ne 0 then

fl(x)xx12βL(p1)(0.00100)β×βL=12β(p1)β(pk)=12βk+1\begin{aligned}\frac{|\text{fl}(x) - x|}{|x|}&\le \frac{1}{2}\frac{\beta^{L - (p - 1)}}{(0.0\cdots010\cdots0)_\beta \times \beta^L} \\&= \frac{1}{2}\frac{\beta^{-(p - 1)}}{\beta^{-(p - k)}} \\ &= \frac{1}{2}\beta^{-k + 1}\end{aligned}
반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.