如何用 not and or 简化布尔表达式?

How to simplify boolean expression with not and 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)

你可以把它缩短一点:

start_date <= b and 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

这来自 De Morgan's Laws 其中指出:

¬(P OR Q) <=> (¬P) AND (¬Q)