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