Beispiel #1
0
def polyroots(q, p, pol):
    '''
    Finds all of the roots of polynomial @pol, with the constant of highest 
    degree @q and the constant of x**0 @p. Returns a set of all the roots.
    
    >>> polyroots(1, 2, 'x**3 - 2*x**2 - x + 2')
    set([1, 2, -1])
    
    TODO: Add ability to find @q and @p from @pol
    
    AUTHORS:
    v0.5.1+         --> pydsigner
    '''
    s = set((x for x in set(iter_utils.flatten((((frac(up, uq) for uq, up in [
                    (-qv, -pv), (-qv, pv), (qv, -pv), (qv, pv)]) 
                for qv in factors(abs(q))) for pv in factors(abs(p))))) 
            if eval(pol.replace('x', 'frac("%s")' % x)) == 0))
    
    nset = set()
    for n in s:
        if n.denominator == 1:
            nset.add(n.numerator)
        elif frac(float(n)) == n:
            nset.add(float(n))
        else:
            nset.add(n)
    return nset
Beispiel #2
0
 def get_rel_tb_tree_list(cls, root=None) :
     if type(root) is str :
         if root == "function" :
             a = [os.path.join(root,arch) for arch in cls.get_rel_archis_tree()]
         elif not (root in  cls.Required_tree) :
             return []
         else :
             a = [os.path.join(root,arch) for arch in cls.Required_tree[root] ]
         return [root]+a
     else :
         if root is None : root = Nt2_tb_struct.Required_tree
         z = [ cls.get_rel_tb_tree_list(r) for r in root]
         return list(flatten(z))
Beispiel #3
0
 def get_rel_tb_tree_list(cls, tb_name,root=None) :
     if isinstance(root,str ) :
         if root == "function" :
             a = [os.path.join(cls.__get_tb_from_md_path(tb_name),root,arch) for arch in cls.get_rel_archis_tree()]
         elif not (root in  cls.Required_tree) :
             return []
         else :
             a = [os.path.join(root,arch) for arch in cls.Required_tree[root] ]
         return ([root] if root != 'function' else [os.path.join(cls.__get_tb_from_md_path(tb_name),root)] )+a
     else :
         if root is None : root = Nt2_tb_struct.Required_tree
         z = [ cls.get_rel_tb_tree_list(tb_name,root=r) for r in root]
         return list(flatten(z))
Beispiel #4
0
 def get_rel_tb_tree_list(cls, tb_name, root=None):
     if isinstance(root, str):
         if root == "function":
             a = [
                 os.path.join(cls.__get_tb_from_md_path(tb_name), root,
                              arch) for arch in cls.get_rel_archis_tree()
             ]
         elif not (root in cls.Required_tree):
             return []
         else:
             a = [
                 os.path.join(root, arch)
                 for arch in cls.Required_tree[root]
             ]
         return ([root] if root != 'function' else [
             os.path.join(cls.__get_tb_from_md_path(tb_name), root)
         ]) + a
     else:
         if root is None: root = Nt2_tb_struct.Required_tree
         z = [cls.get_rel_tb_tree_list(tb_name, root=r) for r in root]
         return list(flatten(z))