def upper_bound(min_length, max_length, floor, ceiling, min_slope, max_slope): """ Compute a coarse upper bound on the size of a vector satisfying the constraints. TESTS:: sage: import sage.combinat.integer_list as integer_list sage: f = lambda x: lambda i: x sage: integer_list.upper_bound(0,4,f(0), f(1),-infinity,infinity) 4 sage: integer_list.upper_bound(0, infinity, f(0), f(1), -infinity, infinity) inf sage: integer_list.upper_bound(0, infinity, f(0), f(1), -infinity, -1) 1 sage: integer_list.upper_bound(0, infinity, f(0), f(5), -infinity, -1) 15 sage: integer_list.upper_bound(0, infinity, f(0), f(5), -infinity, -2) 9 """ from sage.functions.all import floor as flr if max_length < float('inf'): return sum([ceiling(j) for j in range(max_length)]) elif max_slope < 0 and ceiling(1) < float('inf'): maxl = flr(-ceiling(1) / max_slope) return ceiling(1) * (maxl + 1) + binomial(maxl + 1, 2) * max_slope #FIXME: only checking the first 10000 values, but that should generally #be enough elif [ceiling(j) for j in range(10000)] == [0] * 10000: return 0 else: return float('inf')
def upper_bound(min_length, max_length, floor, ceiling, min_slope, max_slope): """ Compute a coarse upper bound on the size of a vector satisfying the constraints. TESTS:: sage: import sage.combinat.integer_list as integer_list sage: f = lambda x: lambda i: x sage: integer_list.upper_bound(0,4,f(0), f(1),-infinity,infinity) 4 sage: integer_list.upper_bound(0, infinity, f(0), f(1), -infinity, infinity) inf sage: integer_list.upper_bound(0, infinity, f(0), f(1), -infinity, -1) 1 sage: integer_list.upper_bound(0, infinity, f(0), f(5), -infinity, -1) 15 sage: integer_list.upper_bound(0, infinity, f(0), f(5), -infinity, -2) 9 """ from sage.functions.all import floor as flr if max_length < float('inf'): return sum( [ ceiling(j) for j in range(max_length)] ) elif max_slope < 0 and ceiling(1) < float('inf'): maxl = flr(-ceiling(1)/max_slope) return ceiling(1)*(maxl+1) + binomial(maxl+1,2)*max_slope #FIXME: only checking the first 10000 values, but that should generally #be enough elif [ceiling(j) for j in range(10000)] == [0]*10000: return 0 else: return float('inf')