Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SATySFi:サイン・コサインを使って平方根を求める
@require: stdja
@require: list
% sqrt r = sin(acos(1 - 2r)/2) (for 0 < r < 1)
let sqrt-b r =
sin (acos (1. -. r *. 2.) /. 2.)
% NOTE: behavior undefined
let get-invalid-value () = 0. /. 0.
let sqrt r =
let rd = 1pt *' r in
if rd >' 0pt then
if rd >' 1pt then 1. /. sqrt-b (1. /. r)
else sqrt-b r
else if rd <' 0pt then get-invalid-value ()
else 0.
%===========================================================
let my-iota n =
let-rec iter | 0 rs = rs
| k rs = iter (k - 1) ((k - 1) :: rs) in
iter n []
let my-sqrt-eqn n =
let rn = sqrt (float n) in
let mthn = math-char MathOrd (arabic n) in
let mthrn = math-char MathOrd (show-float rn) in
${| \sqrt{#mthn} |= #mthrn |}
let my-sqrt-eqns n =
List.map (fun k -> my-sqrt-eqn (k + 1)) (my-iota n)
in
document (|
title = {平方根の値}; author = {某ZR(アレ)};
show-title = true; show-toc = false;
|) '<
+p {
サイン・コサインは\SATySFi;で平方根を求めるのに非常に役に立つ。
\align(my-sqrt-eqns 25);
}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.