Comparison

More or less

< Less Than > Greater Than
<= Up To >= At Least
& Lesser | Greater
min least, minimum max greatest, maximum
mins running minimums maxs running maximums
mmin moving minimums mmax moving maximums

Six comparison operators

=Equal<>Not Equal
>Greater Than>=At Least
<Less Than<=Up To

Syntax: (e.g.) x = y, =[x;y]

These binary operators work intuitively on numerical values (converting types when necessary), and apply also to lists, dicts, and tables. They are atomic.

Returns 1b where x and y are equal, else 0b.

q)"hello" = "world"
00010b
q)5h>4h
1b
q)0x05<4j
0b
q)0>(1i;-2j;0h;1b;0N;-0W)
010011b
q)5>=(`a`b!4 6)
a| 1
b| 0

Unlike Match, they are not strict about type.

q)1~1h
0b
q)1=1h
1b

Comparison tolerance applies when matching floats.

q)(1 + 1e-13) = 1
1b

Tip

For booleans, <> is the same as exclusive or (XOR).

Non-numerical arguments

The comparison operators also work on non-numerical values (characters, temporal values, symbols) – not always intuitively.

q)"0" < ("4"; "f"; "F"; 4)  / characters are treated as their numeric value
1110b
q)"alpha" > "omega"         / strings are char lists
00110b
q)`alpha > `omega           / but symbols compare atomically
0b

Particularly notice the comparison of ordinal with cardinal datatypes, such as timestamps with minutes.

q)times: 09:15:37 09:29:01 09:29:15 09:29:15 09:30:01 09:35:27
q)spans:`timespan$times  / timespans:  cardinal
q)stamps:.z.D+times      / timestamps: ordinal 
q)t:09:29                / minute:     cardinal

When comparing ordinals with cardinals, ordinal is converted to the cardinal type first: stamps=t is equivalent to (`minute$stamps)=t and thus

q)(stamps<t;stamps=t;stamps>t)
100000b
011100b
000011b
q)(spans<t;spans=t;spans>t)
100000b
000000b
011111b

Knowledge Base: Temporal data

deltas

Keyword deltas is a uniform unary function that returns the differences between items in its numeric list argument.

differ

Keyword differ is a uniform unary function that returns a boolean list indicating where consecutive pairs of items in x differ.

Match

Match (~) compares its arguments and returns a boolean atom to say whether they are the same.

Comparison tolerance