NOT

Logical negation operator. Inverts a boolean value.

Syntax

NOT expression

Purpose

NOT turns TRUE into FALSE and vice versa. In legal rules it typically encodes negative requirements ("has no criminal record", "is not disqualified") and pairs with AND/OR to express exceptions.

Truth Table

A NOT A
TRUE FALSE
FALSE TRUE

Examples

Example file:

-- NOT keyword examples

-- Basic NOT Operations

#EVAL NOT TRUE
#EVAL NOT FALSE

-- Double Negation

#EVAL NOT NOT TRUE
#EVAL NOT NOT FALSE

-- In Conditional Logic

ASSUME hasCriminalRecord IS A BOOLEAN

DECIDE isClean IS NOT hasCriminalRecord

#CHECK isClean

-- With AND

ASSUME personAge IS A NUMBER
ASSUME isBlocked IS A BOOLEAN

DECIDE canAccess IS personAge >= 18 AND NOT isBlocked

#CHECK canAccess

-- With OR

GIVEN isAdmin IS A BOOLEAN, isRestricted IS A BOOLEAN
hasAccess isAdmin isRestricted MEANS isAdmin OR NOT isRestricted

#EVAL hasAccess FALSE FALSE
#EVAL hasAccess FALSE TRUE

-- Negating Compound Expressions

GIVEN a IS A BOOLEAN, b IS A BOOLEAN

-- NOT binds tighter than AND
notAThenB a b MEANS NOT a AND b

-- Use parentheses to negate compound expression
notBoth a b MEANS NOT (a AND b)

#EVAL notAThenB TRUE TRUE
#EVAL notAThenB FALSE TRUE
#EVAL notBoth TRUE TRUE
#EVAL notBoth FALSE TRUE

-- NOT with Comparisons

GIVEN n IS A NUMBER
isNotZero n MEANS NOT (n EQUALS 0)
isNotPositive n MEANS NOT (n > 0)

#EVAL isNotZero 5
#EVAL isNotZero 0
#EVAL isNotPositive 5
#EVAL isNotPositive (-3)

-- In IF Expressions

GIVEN flag IS A BOOLEAN
invertedMessage flag MEANS
  IF NOT flag
  THEN "flag is off"
  ELSE "flag is on"

#EVAL invertedMessage TRUE
#EVAL invertedMessage FALSE

Basic Negation

ASSUME hasCriminalRecord IS A BOOLEAN

DECIDE isClean IS NOT hasCriminalRecord

Combined with AND

ASSUME personAge IS A NUMBER
ASSUME isBlocked IS A BOOLEAN

DECIDE canAccess IS personAge >= 18 AND NOT isBlocked

Negating Compound Expressions

NOT binds tighter than AND and OR, so parenthesize compound expressions to negate them as a whole:

GIVEN a IS A BOOLEAN, b IS A BOOLEAN

-- NOT applies only to a
notAThenB a b MEANS NOT a AND b

-- NOT applies to the whole conjunction
notBoth a b MEANS NOT (a AND b)

Negating Comparisons

GIVEN n IS A NUMBER
isNotZero n MEANS NOT (n EQUALS 0)

Pitfalls

  • Precedence. NOT a AND b means (NOT a) AND b, not NOT (a AND b). Use parentheses when negating a compound expression.
  • Comparisons need parentheses. Write NOT (n EQUALS 0); without parentheses the NOT tries to apply to n alone.
  • Prefer UNLESS for exceptions. p AND NOT q can be written p UNLESS q, which often reads closer to the legal source text.
  • AND - Logical conjunction
  • OR - Logical disjunction
  • IMPLIES - Logical implication
  • UNLESS - Exception clause (AND NOT)

See Also