Difference between revisions of "Not"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "<c>not</c> is a keyword unary operator that returns the logical negation of its operand. Category:Language Category:Keywords {{stub}}")
 
(removed {{stub}} tag)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<c>not</c> is a [[:Category:Keywords|keyword]] unary operator that returns the logical negation of its operand.
+
<c>not</c> is a [[:Category:Keywords|keyword]] unary operator that returns the logical negation of its operand. In its simplest usage, <c>not true</c> is equal to <c>false</c>, and <c>not false</c> is equal to <c>true</c>.
 +
 
 +
== Numeric Operands ==
 +
In detail, for any numeric operand <c>x</c>, the result of <c>not x</c> depends on the absolute value of <c>x</c>.  The full truth table for <c>not</c> with numeric operands is shown below.
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Range of <c>abs(x)</c> !! <c>not x</c>
 +
|-
 +
| <c>abs(x) <= 0</c> || <c>1</c>
 +
|-
 +
| <c>0 < abs(x) < 1</c> || <c>1 - x</c>
 +
|-
 +
| <c>abs(x) >= 1</c> || <c>0</c>
 +
|}
 +
 
 +
This is consistent with MiniScript’s support for [[Fuzzy Logic|fuzzy logic]].  If interpreted as probability, then if <c>p</c> is the probability of an event happening, <c>not p</c> is the probability of that event ''not'' happening.
 +
 
 +
== Non-Numeric Operands ==
 +
 
 +
When used with types other than numbers, <c>not</c> returns 1 (<c>true</c>) if the given value is “empty”, and 0 (<c>false</c>) if the operand is “not empty”, as shown below.
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Type of <c>x</c> || Characteristic of <c>x</c> || <c>not x</c>
 +
|-
 +
| [[string]] || empty, i.e. <c>x.len == 0</c> || 1
 +
|-
 +
| [[string]] || non-empty, i.e. <c>x.len > 0</c> || 0
 +
|-
 +
| [[list]] || empty, i.e. <c>x.len == 0</c> || 1
 +
|-
 +
| [[list]] || non-empty, i.e. <c>x.len > 0</c> || 0
 +
|-
 +
| [[map]] || empty, i.e. <c>x.len == 0</c> || 1
 +
|-
 +
| [[map]] || non-empty, i.e. <c>x.len > 0</c> || 0
 +
|-
 +
| [[function]] || any || 0
 +
|-
 +
| [[null]] || (N/A) || 1
 +
|}
 +
 
  
 
[[Category:Language]]
 
[[Category:Language]]
 
[[Category:Keywords]]
 
[[Category:Keywords]]
 
{{stub}}
 

Latest revision as of 22:21, 29 March 2023

not is a keyword unary operator that returns the logical negation of its operand. In its simplest usage, not true is equal to false, and not false is equal to true.

Numeric Operands

In detail, for any numeric operand x, the result of not x depends on the absolute value of x. The full truth table for not with numeric operands is shown below.

Range of abs(x) not x
abs(x) <= 0 1
0 < abs(x) < 1 1 - x
abs(x) >= 1 0

This is consistent with MiniScript’s support for fuzzy logic. If interpreted as probability, then if p is the probability of an event happening, not p is the probability of that event not happening.

Non-Numeric Operands

When used with types other than numbers, not returns 1 (true) if the given value is “empty”, and 0 (false) if the operand is “not empty”, as shown below.

Type of x Characteristic of x not x
string empty, i.e. x.len == 0 1
string non-empty, i.e. x.len > 0 0
list empty, i.e. x.len == 0 1
list non-empty, i.e. x.len > 0 0
map empty, i.e. x.len == 0 1
map non-empty, i.e. x.len > 0 0
function any 0
null (N/A) 1