def pt_double(lbiX, lbiY, sgnX, sgnY): """See also: K. Kajiwara et al., http://arxiv.org/abs/0803.4062 and http://arxiv.org/pdf/0903.0331.pdf 8 ADDSUBs + 10 CMPs """ (lbi3X, c3X), sgn3X = lbi.lbi_add(lbiX, lbiX, sgnX, sgnX) (lbi3X, c3X), sgn3X = lbi.lbi_add(lbi3X, lbiX, sgn3X, sgnX) (lbi3Y, c3Y), sgn3Y = lbi.lbi_add(lbiY, lbiY, sgnY, sgnY) (lbi3Y, c3Y), sgn3Y = lbi.lbi_add(lbi3Y, lbiY, sgn3Y, sgnY) # Get [2]P x-coordinate if 1 == sgnX: (lbi2X, c2X), sgn2X = lbi.lbi_add(lbiY, lbi3X, sgnY, sgn3X) else: (lbi2X, c2X), sgn2X = (lbiY, 0), sgnY if 1 == lbi.lbi_cmp(lbiX, lbiY, sgnX, sgnY): (lbi2X, c2X), sgn2X = lbi.lbi_sub(lbi2X, lbi3X, sgn2X, sgn3X) else: (lbi2X, c2X), sgn2X = lbi.lbi_sub(lbi2X, lbi3Y, sgn2X, sgn3Y) # Get [2]P y-coordinate if 1 == sgnY: (lbi2Y, c2Y), sgn2Y = lbi.lbi_add(lbiX, lbi3Y, sgnX, sgn3Y) else: (lbi2Y, c2Y), sgn2Y = (lbiX, 0), sgnX if 1 == lbi.lbi_cmp(lbiX, lbiY, sgnX, sgnY): (lbi2Y, c2Y), sgn2Y = lbi.lbi_sub(lbi2Y, lbi3X, sgn2Y, sgn3X) else: (lbi2Y, c2Y), sgn2Y = lbi.lbi_sub(lbi2Y, lbi3Y, sgn2Y, sgn3Y) return lbi2X, lbi2Y, sgn2X, sgn2Y
def pt_coord(vectors, vlbi, vsgn): (v1, v2, v3, v4) = vectors lbi1, sgn1 = pt_sp(v1, vlbi, vsgn) lbi2, sgn2 = pt_sp(v2, vlbi, vsgn) if 1 == lbi.lbi_cmp(lbi1, lbi2, sgn1, sgn2): lbipos, sgnpos = lbi1, sgn1 else: lbipos, sgnpos = lbi2, sgn2 lbi3, sgn3 = pt_sp(v3, vlbi, vsgn) lbi4, sgn4 = pt_sp(v4, vlbi, vsgn) if 1 == lbi.lbi_cmp(lbi3, lbi4, sgn3, sgn4): lbineg, sgnneg = lbi3, sgn3 else: lbineg, sgnneg = lbi4, sgn4 (lbiR, cR), sgnR = lbi.lbi_sub(lbipos, lbineg, sgnpos, sgnneg) return lbiR, lbineg, sgnR, sgnneg
def pt_double_alt(lbiX, lbiY, sgnX, sgnY): """See also: K. Kajiwara et al., http://arxiv.org/abs/0803.4062 and http://arxiv.org/pdf/0903.0331.pdf 5 ADDSUBs + 6 CMPs """ (lbi2X, c2X), sgn2X = lbi.lbi_add(lbiX, lbiX, sgnX, sgnX) (lbi3X, c3X), sgn3X = lbi.lbi_add(lbi2X, lbiX, sgn2X, sgnX) (lbi2Y, c2Y), sgn2Y = lbi.lbi_add(lbiY, lbiY, sgnY, sgnY) (lbi3Y, c3Y), sgn3Y = lbi.lbi_add(lbi2Y, lbiY, sgn2Y, sgnY) cmp = lbi.lbi_cmp(lbiX, lbiY, sgnX, sgnY) if 1 == cmp: if 1 == sgnX: lbiXX, sgnXX = lbiY, sgnY else: (lbiXX, cXX), sgnXX = lbi.lbi_sub(lbiY, lbi3X, sgnY, sgn3X) if 1 == sgnY: (lbiYY, cYY), sgnYY = lbi.lbi_sub(lbi3Y, lbi2X, sgn3Y, sgn2X) else: lbiYY, sgnYY = lbiX, sgnX else: if 1 == sgnX: (lbiXX, cXX), sgnXX = lbi.lbi_sub(lbi3X, lbi2Y, sgn3X, sgn2Y) else: lbiXX, sgnXX = lbi2Y, -sgn2Y if 1 == sgnY: lbiYY, sgnYY = lbi2X, -sgn2X else: (lbiXX, cXX), sgnXX = lbi.lbi_sub(lbiX, lbi3Y, sgnX, sgn3Y) return lbiXX, lbiYY, sgnXX, sgnYY
def pt_coord_pre(vectors, vlbi, vsgn, lbineg, sgnneg): (v1, v2, v3, v4) = vectors lbi1, sgn1 = pt_sp(v1, vlbi, vsgn) lbi2, sgn2 = pt_sp(v2, vlbi, vsgn) if 1 == lbi.lbi_cmp(lbi1, lbi2, sgn1, sgn2): lbipos, sgnpos = lbi1, sgn1 else: lbipos, sgnpos = lbi2, sgn2 (lbiR, cR), sgnR = lbi.lbi_sub(lbipos, lbineg, sgnpos, sgnneg) return lbiR, sgnR
def point_face(xr, sxr, yr, syr): if (1, -1) == (sxr, syr): return 5 if (-1, 1) == (sxr, syr): return 2 cmpyx = lbi.lbi_cmp(xr, yr, sxr, syr) if (1, 1) == (sxr, syr): if 1 == cmpyx: return 6 else: return 1 elif (-1, -1) == (sxr, syr): if 1 == cmpyx: return 4 else: return 3 else: return 0
def line_center(xp, sxp, yp, syp, xq, sxq, yq, syq): xcmp = lbi.lbi_cmp(xp, xq, sxp, sxq) ycmp = lbi.lbi_cmp(yp, yq, syp, syq) # P, Q are on edges 2 and 3 if -1 == xcmp * ycmp: if xcmp == 1: (xb, sxb, yb, syb) = (xq, sxq, yq, syq) (xc, sxc, yc, syc) = (xp, sxp, yp, syp) conf = 'CB' else: (xb, sxb, yb, syb) = (xp, sxp, yp, syp) (xc, sxc, yc, syc) = (xq, sxq, yq, syq) conf = 'BC' return (xc, sxc, yb, syb, conf) # One of P or Q in on edge 2 or 3 else: if 1 == xcmp: (subyxinf, cyxinf), sgnyxinf = lbi.lbi_sub(yq, xq, syq, sxq) (subyx, cyx), sgnyx = lbi.lbi_sub(yp, xp, syp, sxp) cmpyx = lbi.lbi_cmp(subyx, subyxinf, sgnyx, sgnyxinf) if 1 == cmpyx: (add, cadd), sadd = lbi.lbi_add(xq, subyx, sxq, sgnyx) return (xq, sxq, add, sadd, 'AC') else: (sub, csub), ssub = lbi.lbi_sub(yq, subyx, syq, sgnyx) return (sub, ssub, yq, syq, 'AB') else: (subyxinf, cyxinf), sgnyxinf = lbi.lbi_sub(yp, xp, syp, sxp) (subyx, cyx), sgnyx = lbi.lbi_sub(yq, xq, syq, sxq) cmpyx = lbi.lbi_cmp(subyx, subyxinf, sgnyx, sgnyxinf) if 1 == cmpyx: (add, cadd), sadd = lbi.lbi_add(xp, subyx, sxp, sgnyx) return (xp, sxp, add, sadd, 'CA') else: (sub, csub), ssub = lbi.lbi_sub(yp, subyx, syp, sgnyx) return (sub, ssub, yp, syp, 'BA') return (0, 0, 0, 0, '')
def pt_K(lbiX, lbiY, sgnX, sgnY, verbose=False): (lbi3X, c3X), sgn3X = lbi.lbi_add(lbiX, lbiX, sgnX, sgnX) (lbi3X, c3X), sgn3X = lbi.lbi_add(lbi3X, lbiX, sgn3X, sgnX) (lbi3Y, c3Y), sgn3Y = lbi.lbi_add(lbiY, lbiY, sgnY, sgnY) (lbi3Y, c3Y), sgn3Y = lbi.lbi_add(lbi3Y, lbiY, sgn3Y, sgnY) (lbisum, csum), sgnsum = lbi.lbi_add(lbiX, lbiY, sgnX, sgnY) if verbose: print "In K: 3X, 3Y", lbi.lbi_lbi2dec(lbi3X, sgn3X), lbi.lbi_lbi2dec( lbi3Y, sgn3Y) print "In K: X+Y ", lbi.lbi_lbi2dec(lbisum, sgnsum) if 1 == lbi.lbi_cmp(lbiX, lbiY, sgnX, sgnY): lbimax, sgnmax = lbi3X, sgn3X else: lbimax, sgnmax = lbi3Y, sgn3Y if 1 == sgnmax: (lbiR, cR), sgnR = lbi.lbi_sub(lbimax, lbisum, sgnmax, sgnsum) else: (lbiR, cR), sgnR = (lbisum, csum), -sgnsum return lbiR, sgnR
def pt_K_alt(lbiX, lbiY, sgnX, sgnY, verbose=False): """Hessian Pencil parameter from a cyce point. 4 ADDSUBs + 5 CMPs """ (lbisum, csum), sgnsum = lbi.lbi_add(lbiX, lbiY, sgnX, sgnY) (lbi2X, c2X), sgn2X = lbi.lbi_add(lbiX, lbiX, sgnX, sgnX) (lbi2Y, c2Y), sgn2Y = lbi.lbi_add(lbiY, lbiY, sgnY, sgnY) cmp = lbi.lbi_cmp(lbiX, lbiY, sgnX, sgnY) if 1 == cmp: if 1 == sgnX: (lbiR, cR), sgnR = lbi.lbi_sub(lbi2X, lbiY, sgn2X, sgnY) return lbiR, sgnR else: return lbisum, -sgnsum else: if 1 == sgnY: (lbiR, cR), sgnR = lbi.lbi_sub(lbi2Y, lbiX, sgn2Y, sgnX) return lbiR, sgnR else: return lbisum, -sgnsum