Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/imperative-programming-resit/1/f/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2017 Imperative programming (resit) 1 f Solution by
Codex 0 2026-10-31
Use Binet's formula entirely within . SetHere pairs mean the rational and radical coefficients. An exact program using the preceding procedures is
z = mkRat(0,1); one = mkRat(1,1)
half = mkRat(1,2)
phi = mkIrr(half,half)
psi = mkIrr(half,negRat(half))
c = mkIrr(z,mkRat(1,5))
p = mkIrr(one,z); q = mkIrr(one,z)
for i = 0,...,n-1:
minusQ = mkIrr(negRat(q.rat),negRat(q.irr))
OutIrr(mulIrr(c,addIrr(p,minusQ)))
Out.Ln()
p = mulIrr(p,phi)
q = mulIrr(q,psi)At iteration , and , so the printed value is exactly . The irrational coefficient cancels algebraically, and the rational result is an integer. This prints ; to use the convention , initialize
p=phi and q=psi. There are field operations, with growing arbitrary-precision arithmetic costs kept separate from that count. New to topics? Read the docs here!