def str_to_CBF(s): # in sage 8.2 or earlier this is equivalent to CBF(s) s = str(s) # to convert from unicode try: return CBF(s) except TypeError: sign = 1 s = s.lstrip('+') if '+' in s: a, b = s.rsplit('+', 1) elif '-' in s: a, b = s.rsplit('-',1) sign = -1 else: a = '' b = s a = a.lstrip(' ') b = b.lstrip(' ') if 'I' in a: b, a = a, b assert 'I' in b or b == '' if b == 'I': b = '1' else: b = b.rstrip(' ').rstrip('I').rstrip('*') res = CBF(0) if a: res += CBF(a) if b: res += sign * CBF(b)* CBF.gens()[0] return res
def _get_alpha(self, m, p, i): theta = CBF(self.cc_data[m]['angles'][p]) unit = (2 * theta).exppii() if i == 0: res = unit else: # it is very likely that the real or imag part are a half integer # as it returns a CDF, we need to convert it to CBF again chival = CBF(round_CBF_to_half_int(CBF(self.character_values[p][(m-1) // self.rel_dim][1]))) res = chival / unit return round_CBF_to_half_int(res)
def str_to_CBF(s): # in sage 8.2 or earlier this is equivalent to CBF(s) s = str(s) # to convert from unicode try: return CBF(s) except TypeError: sign = 1 s = s.lstrip('+') if '+' in s: a, b = s.rsplit('+', 1) elif '-' in s: a, b = s.rsplit('-',1) sign = -1 else: a = '' b = s a = a.lstrip(' ') b = b.lstrip(' ') if 'I' in a: b, a = a, b assert 'I' in b or b == '' if b == 'I': b = '1' else: b = b.rstrip(' ').rstrip('I').rstrip('*') res = CBF(0) if a: res += CBF(a) if b: res += sign * CBF(b)* CBF.gens()[0] return res
def str_to_CBF(s): # in sage 8.2 or earlier this is equivalent to CBF(s) s = str(s) # to convert from unicode try: return CBF(s) except TypeError: # Need to deal with scientific notation # Replace e+ and e- with placeholders so that we can split on + and - s = s.replace("e+", "P").replace("E+", "P").replace("e-", "M").replace("E-", "M") sign = 1 s = s.lstrip('+') if '+' in s: a, b = s.rsplit('+', 1) elif '-' in s: a, b = s.rsplit('-', 1) sign = -1 else: a = '' b = s a = a.lstrip(' ') b = b.lstrip(' ') if 'I' in a: b, a = a, b assert 'I' in b or b == '' if b == 'I': b = '1' else: b = b.rstrip().rstrip('I').rstrip('*') a = a.replace("M", "e-").replace("P", "e+") b = b.replace("M", "e-").replace("P", "e+") res = CBF(0) if a: res += CBF(a) if b: res += sign * CBF(b) * CBF.gens()[0] return res