コード例 #1
0
ファイル: sequences_invplus.py プロジェクト: AndreaCensi/mcdp
def Nat_mult_antichain_Max(m):
    """ 
        Returns the set of elements of Nat so that their product is at most m:
    
        Max { (a, b) | a * b <= m }
    
    """
    # top -> [(top, top)]
    P = Nat()
    P.belongs(m)
    top = P.get_top()
    if is_top(P, m):
        s = set([(top, top)])
        return s

    assert isinstance(m, int)
    
    if m < 1:
        return set([(0, 0)])
    
    s = set()
    for o1 in range(1, m + 1):
        assert o1 >= 1
        # We want the minimum x such that o1 * x >= f
        # x >= f / o1
        # x* = ceil(f / o1)
        x =  int(np.floor(m * 1.0 / o1))
        assert x * o1 <= m # feasible
        assert (x+1) * o1 > m, (x+1, o1, m) # and minimum
        s.add((o1, x))
    return s
コード例 #2
0
ファイル: sequences_invplus.py プロジェクト: AndreaCensi/mcdp
def Nat_mult_antichain_Min(m):
    """ 
        Returns the Minimal set of elements of Nat so that their product is at least m:
    
        Min { (a, b) | a * b >= m }
    
    """
    # (top, 1) or (1, top)
    P = Nat()
    P.belongs(m)
    top = P.get_top()
    if is_top(P, m):
        s = set([(top, 1), (1, top)]) # XXX:
        return s

    assert isinstance(m, int)
    
    if m == 0:
        # any (r1,r2) is such that r1*r2 >= 0
        return set([(0, 0)])
    
    s = set()
    for o1 in range(1, m + 1):
        assert o1 >= 1
        # We want the minimum x such that o1 * x >= f
        # x >= f / o1
        # x* = ceil(f / o1)
        x =  int(np.ceil(m * 1.0 / o1))
        assert x * o1 >= m
        assert (x-1) * o1 < m
        assert x >= 1
        s.add((o1, x))
    return s