require "localized-ring"
require "polynomial"
require "residue-class-ring"
require "rational"

case n = Integer(ARGV.shift)
when 0
  K = Rational
when -1
  K = Integer
  require "mathn"
  raise "not implement this case"
when -2
  K = Integer
else
  K = ResidueClassRing(Integer, n)
end

G = Polynomial(K, "x")
x = G.var
F = LocalizedRing(G)
x0 = F[x]

if false
PF = Polynomial(F, "a0")
a0 = PF.var
AF = ResidueClassRing(PF, a0**2 - 2*x - 1)
a = AF[a0]

else
#AF = AlgebraicExtentionField(F, "a") {|a0| a0**2 - 2*x - 1}
AF = AlgebraicExtentionField(F, "a") {|a0| a0**2 - 2}
a = AF.var
end

p( AF.unity/(x**2 + a*x + 1) + a/(x**2 - a*x + 1) )
