// Farey fractions, illustration how to define functions D := Denominator; N := Numerator; function farey(n) if n eq 1 then return [RationalField() | 0, 1 ]; end if; f := farey(n-1); i := 0; while i lt #f-1 do i +:= 1; if D(f[i]) + D(f[i+1]) eq n then Insert(~f, i+1, (N(f[i]) + N(f[i+1]))/(D(f[i]) + D(f[i+1]))); end if; end while; return f; end function; time f100 := farey(100); farey(10);