簡體   English   中英

如何用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)
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的法律 ,該法律指出:

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

您可以將其縮短:

start_date <= b and s <=end_date

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM