연분수 계산기
소수나 분수를 연분수 표기와 수렴분수로 변환.
이 도구 소개
연분수는 임의의 실수를 중첩된 나눗셈의 수열로 표현하는 수학적 표기법입니다. 표준 소수 표기와 달리, 연분수는 수의 기본 산술 구조를 드러내며 점진적으로 더 나은 유리수 근사값을 제공합니다. 이 도구는 3.14159와 같은 소수든 355/113과 같은 분수든 입력을 연분수 형태로 변환하여, 수학자들이 무리수 상수에 대한 놀랍도록 정확한 유리수 근사값을 역사적으로 어떻게 발견했는지 이해하기 쉽게 만듭니다.
이 계산기 사용법은 간단합니다. 소수를 입력하거나 분자/분모 형식의 분수를 입력한 후 계산하려는 항의 개수를 지정하세요. 도구는 연분수 표기를 [a₀; a₁, a₂, ...] 형태로 표시하고 수렴분수 표를 생성합니다. 각 수렴분수는 분모 크기 대비 최고의 유리수 근사값을 제공하는데, 이 성질은 항해 시스템, 천문 계산, 음악 조율에서 활용됩니다.
연분수는 특히 정수론과 암호학에서 가치가 있으며, 무리수의 효율적 근사는 미묘한 수학적 성질을 노출할 수 있습니다. 2의 제곱근과 같은 특정 무리수에 나타나는 주기적 패턴은 대수학과 기하학으로의 깊은 연결을 드러냅니다. 순수 수학을 탐구하든, 공학 근사값을 검증하든, 혹은 355/113이 π를 그렇게 정확하게 근사하는 이유를 알고 싶든, 이 도구는 추상적 연분수 이론을 시각적이고 상호작용적인 계산으로 변환합니다.
자주 묻는 질문
코드 구현
import math
def continued_fraction(x: float, max_terms: int = 20) -> list[int]:
"""Compute continued fraction representation of x"""
terms = []
remaining = x
for _ in range(max_terms):
a = int(math.floor(remaining))
terms.append(a)
frac = remaining - a
if abs(frac) < 1e-10:
break
remaining = 1 / frac
if not math.isfinite(remaining):
break
return terms
def convergents(terms: list[int]) -> list[tuple[int, int]]:
"""Compute convergents (rational approximations) from continued fraction terms"""
conv = []
h_prev, h_curr = 1, terms[0]
k_prev, k_curr = 0, 1
conv.append((h_curr, k_curr))
for i in range(1, len(terms)):
a = terms[i]
h_next = a * h_curr + h_prev
k_next = a * k_curr + k_prev
h_prev, h_curr = h_curr, h_next
k_prev, k_curr = k_curr, k_next
conv.append((h_curr, k_curr))
return conv
# Example: pi
pi_terms = continued_fraction(math.pi, 10)
print(f"pi = [{pi_terms[0]}; {', '.join(map(str, pi_terms[1:]))}]")
for num, den in convergents(pi_terms):
approx = num / den
error = abs(approx - math.pi)
print(f" {num}/{den} = {approx:.10f} (error: {error:.2e})")
# Golden ratio
phi = (1 + math.sqrt(5)) / 2
print(f"phi terms: {continued_fraction(phi, 8)}") # All ones!
# sqrt(2)
sqrt2_terms = continued_fraction(math.sqrt(2), 8)
print(f"sqrt(2) terms: {sqrt2_terms}") # [1; 2, 2, 2, ...]
Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.