- # Even though we know a,b are real we use the symbolic ring. This
- # lets us return pretty expressions where possible.
- a = SR(a)
- b = SR(b)
- n = ZZ(n) # Ensure that 1/(2**n) is not integer division.
- dn = 1/(2**n)
+ # Even though we know a,b are real we use a different ring. We
+ # prefer ZZ so that we can support division of finite field
+ # elements by (a-b). Eventually this should be supported for QQ as
+ # well, although it does not work at the moment. The preference of
+ # SR over RR is to return something attractive when e.g. a=pi.
+ if a in ZZ:
+ a = ZZ(a)
+ else:
+ a = SR(a)
+
+ if b in ZZ:
+ b = ZZ(b)
+ else:
+ b = SR(b)
+
+ # Ensure that (2**n) is an element of ZZ. This is used later --
+ # we can divide finite field elements by integers but we can't
+ # multiply them by rationals at the moment.
+ n = ZZ(n)