def verify_1(self,AT, BT, CT, HT, p_n_a, p_n_b, p_n_c, p_n_h): self.AT = AT self.BT = BT self.CT = CT self.HT = HT x = symbols('x') AP = Poly(np.flip(AT, 0), x) BP = Poly(np.flip(BT, 0), x) CP = Poly(np.flip(CT, 0), x) HP = Poly(np.flip(HT, 0), x) print(HP) # A(t_0) A_t_0 = AP.eval(self.t_0) B_t_0 = BP.eval(self.t_0) C_t_0 = CP.eval(self.t_0) H_t_0 = HP.eval(self.t_0) # verifier self.v_n_a = cv.mul_point(cv.order + int(A_t_0), G) self.v_n_b = cv.mul_point(cv.order + int(B_t_0), G) self.v_n_c = cv.mul_point(cv.order + int(C_t_0), G) self.v_n_h = cv.mul_point(cv.order + int(H_t_0), G) print(p_n_a == self.v_n_a, p_n_b == self.v_n_b , p_n_c == self.v_n_c , p_n_h == self.v_n_h ) return (p_n_a == self.v_n_a and p_n_b == self.v_n_b and p_n_c == self.v_n_c and p_n_h == self.v_n_h)
def first_alpha_power_root(poly, irr_poly, p, elements_to_check=None): poly = Poly([(Poly(coeff, alpha) % irr_poly).trunc(p).as_expr() for coeff in poly.all_coeffs()], x) test_poly = Poly(1, alpha) log.debug(f"testing f:{poly}") for i in range(1, p**irr_poly.degree()): test_poly = (Poly(Poly(alpha, alpha) * test_poly, alpha) % irr_poly).set_domain(GF(p)) if elements_to_check is not None and i not in elements_to_check: continue value = Poly((Poly(poly.eval(test_poly.as_expr()), alpha) % irr_poly), alpha).trunc(p) log.debug(f"testing alpha^{i} f({test_poly})={value}") if value.is_zero: return i return -1
0 >>> residue(2/sin(x), x, 0) 2 This function is essential for the Residue Theorem [1]. ''' f = x * (x * x + 1) p = Poly(f, x) A = -2 + 2 * I B = 2 + 2 * I C = 2 - 2 * I D = -2 - 2 * I ABCD = [A, B, C, D] path = list(zip([D] + ABCD, ABCD)) print([p.eval(x, z) for z in ABCD]) logf = log(f) print([logf.subs(x, z).evalf() for z in ABCD]) ip = [((b - a) / f.subs(x, b)).evalf() for a, b in path] print(ip, sum(ip)) ress = [residue(1 / f, x, z0) for z0 in [0, I, -I]] print(sum(ress), ress) '''A->B : sum(f*dz) = sum(f*dx) = F|(-2->2) ''' def residue(f, circle, N): '''residue(f, A->B->.., N) == integrate(f, A->..->A, N)/2pi/1j '''
def piecewise_symbolic_integral(self, integrand, x, y=None): """ Computes the symbolic integral of 'x' of a piecewise polynomial 'integrand'. The result might be a sympy expression or a numerical value. Parameters ---------- integrand : list A list of (lower bound, upper bound, polynomial) x : object A string/sympy expression representing the integration variable """ res = 0 #logger.debug(f"\t\t\t\tpiecewise_symbolic_integral") #logger.debug(f"\t\t\t\tlen(integrand): {len(integrand)} --- y: {y}") for l, u, p in integrand: symx = symvar(x) symy = symvar(y) if y else symvar("aux_y") syml = Poly(to_sympy(l), symy, domain="QQ") symu = Poly(to_sympy(u), symy, domain="QQ") #logger.debug(f"\t\t\t\t\tl: {l} --- u: {u} --- p: {p}") if type(p) != Poly: symp = Poly(to_sympy(p), symx, domain="QQ") else: symp = Poly(p.as_expr(), symx, domain=f"QQ[{symy}]") if y else p if self.cache is not None: # for cache = True """ hierarchical cache, where we cache: - the anti-derivatives for integrands, retrieved by the same integrand key - the partial integration term, retrieved by the same (integrand key, lower / upper bound key) pair - the whole integration, retrieved by the same (integrand key, lower bound key, upper bound key) pair """ bds_ks = [MPWMI.cache_key(syml)[0], MPWMI.cache_key(symu)[0]] # cache keys for bounds bds = [syml.as_expr(), symu.as_expr()] p_ks = MPWMI.cache_key(symp) # cache key for integrand polynomial trm_ks = [(bds_ks[0], p_ks[0]), (bds_ks[1], p_ks[0])] if (bds_ks[0], bds_ks[1], p_ks[0]) in self.cache: # retrieve the whole integration self.cache_hit[True] += 1 symintegral = self.cache[(bds_ks[0], bds_ks[1], p_ks[0])] symintegral = symintegral.subs(symintegral.gens[0], symy) else: terms = [] for tk in trm_ks: # retrieve partial integration terms if tk in self.cache: trm = self.cache[tk] trm = trm.subs(trm.gens[0], symy) terms.append(trm) else: terms.append(None) if None not in terms: self.cache_hit[True] += 1 else: if p_ks[0] in self.cache: # retrieve anti-derivative self.cache_hit[True] += 1 antidrv = self.cache[p_ks[0]] antidrv_expr = antidrv.as_expr().subs(antidrv.gens[0], symx) antidrv = Poly(antidrv_expr, symx, domain=f"QQ[{symy}]") if y \ else Poly(antidrv_expr, symx, domain="QQ") else: self.cache_hit[False] += 1 antidrv = symp.integrate(symx) for k in p_ks: # cache anti-derivative self.cache[k] = antidrv for i in range(len(terms)): if terms[i] is not None: continue terms[i] = antidrv.eval({symx: bds[i]}) terms[i] = Poly(terms[i].as_expr(), symy, domain="QQ") for k in p_ks: # cache partial integration terms self.cache[(bds_ks[i], k)] = terms[i] symintegral = terms[1] - terms[0] for k in p_ks: # cache the whole integration self.cache[(bds_ks[0], bds_ks[1], k)] = symintegral else: # for cache = False antidrv = symp.integrate(symx) symintegral = antidrv.eval({symx: symu.as_expr()}) - \ antidrv.eval({symx: syml.as_expr()}) res += symintegral #logger.debug(f"\t\t\t\t\tsymintegral: {symintegral}") return res
Gs = G.subs(x, -x) Gs = Poly(Gs + pp, x, modulus=p) A, R = reduction(F, Gs) res = res * pow(R.coeffs()[0], G.degree(), p) % p res = -res if R.degree() % 2 else res R = tru_mod(invs(R.coeffs()[0]) * R) R = -R if R.degree() % 2 else R return resultant(G, R, res) anss = 1 for gs in g_zeros: anss *= f_pol.eval(x, -gs) anss = 1 for fs in f_zeros: anss *= g_pol.eval(x, -fs) # 나눠: _, r_pol = reduction(f_pol, Poly(g_pol.subs(x, -x), x)) anss = 1 print(r_pol) for gs in g_zeros: anss *= r_pol.eval(-gs) print(anss)