def divide(f, g, prec): ''' Assume g is divisible by f. Returns g/f with precision prec. ''' def key_func(x): return (x[0] + x[2], x[0], x[1], x[2]) ts = sorted(PrecisionDeg2(prec), key=key_func) f_ts = sorted([k for k, v in f.fc_dct.items() if v != 0], key=key_func) res_dct = {} n0, r0, m0 = f_ts[0] a0 = f[(n0, r0, m0)] # Normalize f f = f * a0 ** (-1) for n, r, m in ts: if g[(n + n0, r + r0, m + m0)] == 0: res_dct[(n, r, m)] = 0 else: break ts_res = ts[len(res_dct):] for n, r, m in ts_res: n1, r1, m1 = n + n0, r + r0, m + m0 s = sum((f.fc_dct[(n1 - a, r1 - b, m1 - c)] * res_dct[(a, b, c)] for a, b, c in _spos_def_mats_lt((n1, r1, m1)) if not ((a == n and b == r and c == m) or f.fc_dct[(n1 - a, r1 - b, m1 - c)] == 0))) res_dct[(n, r, m)] = g[(n1, r1, m1)] - s res = QexpLevel1(res_dct, prec) return res * a0
def _inverse(self): a = self[(0, 0, 0)] if a == 0: raise ZeroDivisionError prec = self.prec R = self.base_ring if a != R(1): return (self * a ** (-1))._inverse() * a ** (-1) res_dict = {(0, 0, 0): R(1)} def norm(t): return t[0] + t[2] prec_dict = dict(list_group_by(list(prec), norm)) prec_d_keys = sorted(prec_dict.keys())[1:] for a in prec_d_keys: for t in prec_dict[a]: l = list(_spos_def_mats_lt(t)) l.remove(t) res_dict[t] = - sum([res_dict[u] * self[(t[0] - u[0], t[1] - u[1], t[2] - u[2])] for u in l]) return QexpLevel1(res_dict, prec, base_ring=self.base_ring)
def test_semi_pos_mats(self): self.assertEqual(len(list(semi_pos_def_matarices(10))), 2029) self.assertEqual(len(list(semi_pos_def_matarices(14))), 5357) self.assertEqual(len(list(_spos_def_mats_lt((20, 3, 10)))), 2832) self.assertEqual(len(list(_spos_def_mats_lt((10, 0, 10)))), 1021)