如何使用 not 和 or 简化布尔表达式



我有以下布尔表达式:

not (start_date > b or s > end_date)

如何简化它?

def is_date_in_items(end_date, start_date, items):
    b, s = _get_biggest_and_smallest_date(items)
    return not (start_date > b or s > end_date)
not (start_date > b or s > end_date)
// is equivalent to 
not(start_date > b) and not(s > end_date)
// which is equivalent to 
start_data <= b and s <= end_date

这来自德摩根定律,其中指出:

¬(P OR Q) <=> (¬P) AND (¬Q) 
你可以

把它缩短一点:

start_date <= b and s <=end_date

最新更新