Transforming a continued fraction representation into a real: dfc2f

### 6.7.8 Transforming a continued fraction representation into a real: dfc2f

The dfc2f command transforms a continued fraction into a real number.

- dfc2f takes one argument:
  L, a list representing a continued fraction, which can be:
  - a list of integers for a rational number.
  - a list whose last element is a list for an ultimately periodic representation, i.e. a quadratic number, that is a root of a second order equation with integer coefficients.
  - a list with a remainder r as last element (a=a0+1/…+1/an+1/r).
- dfc2f(L) returns the rational number or the quadratic number whose continued fraction representation is L.

Examples.

- Input:
  dfc2f([1,2,[2]])
  Output:

  1
  1
  √ |
  2
  | +1
  | +2
  | +1

  After simplification with normal:

  | √ |
  2

- Input:
  dfc2f([1,2,3])
  Output:

  10
  7

- Input:
  normal(dfc2f([3,3,6,[3,6]]))
  Output:

  | √ |
  11

- Input:
  dfc2f([1,2,3,4,5,6,7])
  Output:

  9976
  6961

  Input (to verify):
  1+1/(2+1/(3+1/(4+1/(5+1/(6+1/7)))))
  Output:

  9976
  6961

- Input:
  dfc2f([1,2,3,4,5,43/7])
  Output:

  9976
  6961

  Input (to verify):
  1+1/(2+1/(3+1/(4+1/(5+7/43))))
  Output:

  9976
  6961