Convergents[(1+Sqrt[5])/2,10]

CF::usage = 
  "CF[a,b,...] represents the continued fraction a + 1/(b + 1/(...))";
ToCF[x_Integer] := CF[x];
ToCF[Rational[p_, q_]] := 
  If[q == 0, CF[], Join[CF[Floor[p/q]], ToCF[q/Mod[p, q]]]];
ToCF[17/6]

Homographic[{{a_Integer, b_Integer}, {c_Integer, d_Integer}}, x_CF] :=
   Which[
    Length[x] == 0,(*x is CF[], which we can think of as infinity*)
    ToCF[a/c],
    a == c == 0, (*does not depend on x*)
    ToCF[b/d],
    c != 0 && d != 0 && Floor[a/c] == Floor[b/d], (*we know the integer part*)
    Join[CF[Floor[a/c]], Homographic[{{c, d}, {Mod[a, c], Mod[b, d]}}, x]],
    True, (*rewrite using a term of x*)
    Homographic[{{a First[x] + b, a }, {c First[x] + d, c }}, Rest[x]]
   ];

Homographic[{{2, 0}, {0,1}}, ToCF[17/6]]
ToCF[17/3]

BiHomographic[{{a_Integer, b_Integer, c_Integer, 
     d_Integer}, {e_Integer, f_Integer, g_Integer, h_Integer}}, x_CF, 
   y_CF] :=
  Which[
   Length[x] == 0,(*x is infinity*)
   Homographic[{{a,b},{e,f}},y],
   Length[y] == 0,(*y is infinity*)
   Homographic[{{a,c},{e,g}},x],
   a == b == e == d == 0,(*does not depend on x*)
   Homographic[{{c, d}, {g, h}}, y],
   a == c == e == f == 0,(*does not depend on y*)
   Homographic[{{b, d}, {f, h}}, x],
   e != 0 && f != 0 && g != 0 && h != 0 && 
    Floor[a/e] == Floor[b/f] == Floor[c/g] == 
     Floor[d/h],(*we know the integer part*)
   Join[CF[Floor[a/e]], 
    BiHomographic[{{e, f, g, h}, Mod[{a, b, c, d}, {e, f, g, h}]}, x, 
     y]],
   f g h == 0 || Abs[b/f - d/h] > Abs[c/g - d/h],(*expand x*)
   BiHomographic[{{a First[x] + c, b First[x] + d, a, 
      b }, {e First[x] + g, f First[x] + h, e, f}}, Rest[x], y],
   True,(*expand y*)
   BiHomographic[{{a First[y] + b, a, c First[y] + d, 
      c }, {e First[y] + f, e, g First[y] + h, g}}, x, Rest[y]]
  ];

Plus[x_CF, y_CF] ^:= BiHomographic[{{0, 1, 1, 0}, {0, 0, 0, 1}}, x, y];
Times[x_CF, y_CF] ^:= 
  BiHomographic[{{1, 0, 0, 0}, {0, 0, 0, 1}}, x, y];

CF /: Times[x_CF, -1] := Homographic[{{-1, 0}, {0, 1}}, x];
CF /: Power[x_CF, -1] := Homographic[{{0, 1}, {1, 0}}, x];

ToCF[1/2]+ToCF[1/5]
ToCF[1/2+1/5]

ToCF[34/3] ToCF[56/5]
ToCF[(34/3)(56/5)]

CF /: Plus[x_CF, y_Integer] := Homographic[{{1, y}, {0, 1}}, x];
CF /: Times[x_CF, y_Integer] := Homographic[{{y, 0}, {0, 1}}, x];

CF /: Plus[x_CF, Rational[p_, q_]] := Homographic[{{q, p}, {0, q}}, x];
CF /: Times[x_CF, Rational[p_, q_]] := Homographic[{{p, 0}, {0, q}}, x];

eighth = ToCF[1/8];
Table[{i eighth, ToCF[i/8]}, {i, 8}]//TableForm

Normal[CF[a_, b__]] ^:= a + 1/Normal[CF[b]];
Normal[CF[a_]] ^:= a;

Normal/@Table[CF[1,Sequence@@ConstantArray[2,i]] CF[1,Sequence@@ConstantArray[2,i]] - 2,{i,10}]

Rest[CF[{a__}]] ^:= CF[RotateLeft[{a}]]
First[CF[{a__}]] ^:= First[{a}];

ClearAll[Homographic];
Homographic[{{a_Integer, b_Integer}, {c_Integer, d_Integer}}, x_CF] :=
   Homographic[{{a, b}, {c, d}}, x, <||>];
Homographic[{{a_Integer, b_Integer}, {c_Integer, d_Integer}}, x_CF, 
   cache_] := Which[
   KeyExistsQ[cache, {{a, b}, {c, d}, x}],
   CF[cache[{{a, b}, {c, d}, x}]],
   Length[x] == 0,
   ToCF[a/c],
   a == 0 && c == 0,
   ToCF[b/d],
   c != 0 && d != 0 && Floor[a/c] == Floor[b/d],
   Join[CF[Floor[a/c]], 
    Homographic[{{c, d}, {Mod[a, c], Mod[b, d]}}, x, 
     Append[ Join[#, {Floor[a/c]}] & /@ 
       cache, {{a, b}, {c, d}, x} -> {Floor[a/c]}]]],
   True,
   Homographic[{{a First[x] + b, a }, {c First[x] + d, c}}, Rest[x], 
    cache]
   ];

phi = CF[{1}];
4 phi

Simplify[CF[a___, b__, {b__}]] ^:= CF[a, {b}];
Simplify[CF[a___, {b__, b__}]] ^:= CF[a, {b}];
4 phi // Simplify

Simplify[4/3+CF[1,{2}]]
ContinuedFraction[4/3+Sqrt[2]]