Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions

m
Line 3,902:
 
procedure main ()
initial {initialize_global_CF ()
initialize_global_CF ()
}
 
show ("golden ratio", golden_ratio, "(1 + sqrt(5))/2")
Line 3,933 ⟶ 3,931:
 
procedure initialize_global_CF ()
/golden_ratio := CF (create generate_constant (1))
/silver_ratio := CF (create generate_constant (2))
/frac_13_11 := r2cf (13, 11)
/frac_22_7 := r2cf (22, 7)
/one := i2cf (1)
/two := i2cf (2)
/three := i2cf (3)
/four := i2cf (4)
/sqrt2 := cf_sub (silver_ratio, one)
return
end
Line 3,972 ⟶ 3,970:
local j, term
 
if *memo <= i then {
}{
if \terminated then
fail
else
{
every j := *memo to i do {
initial {
if \ (term := @term_gen) then
put (memo, term)
Line 4,008:
public to_string (max_terms) # Make a human-readable string.
local s, i, done, term
static separators
 
initial separators := ["", ";", ","]
 
/max_terms := (\default_max_terms | 20)
Line 4,028 ⟶ 4,031:
else
{
s ||:= sep_strseparators[min (i + 1, 3)] || term
i +:= 1
}
}
return s
end
 
private sep_str (i) # A helper procedure for to_string.
return (if i = 0 then "" else if i = 1 then ";" else ",")
end
 
Line 4,050 ⟶ 4,049:
 
public new (a12, a1, a2, a, b12, b1, b2, b)
initial {
practically_infinite_number := 2^64
much_too_big_number := 2^512
}
na12 := a12
na1 := a1
Line 4,119 ⟶ 4,114:
}
 
if \absorb_term_from === 'x' then {
{
term := @xsource
new_a2 := a12; new_a := a1
Line 4,171 ⟶ 4,167:
 
if /cf then
# Generate only "infinityinfinite" terms.
source := create generate_constant (&null)
else if type(cf) == "co-expression" then
Line 4,183 ⟶ 4,179:
 
private infinitized (term)
initial /practically_infinite_number := 2^64
if abs (term) >= abs (practically_infinite_number) then
term := &null
Line 4,189 ⟶ 4,186:
 
private too_big (num)
initial /much_too_big_number := 2^512
if abs (num) < abs (much_too_big_number) then fail
return num
1,448

edits