Operators and Global Functions
Global Function Icons
List of Operators
Symbol | Description |
---|---|
+ | Addition (Unary Plus) |
- | Subtraction (Unary Minus) |
* | Multiplication |
/ | Division |
** | Exponentiation |
% | Modulo/Modulus |
// | Integer Division |
== | Equals |
!= | Not Equals |
< | Less Than |
> | Greater Than |
>= | Greater Than or Equal to |
<= | Less Than or Equal to |
and | Logical AND |
or | Logical OR |
not | Logical NOT |
& | Bitwise AND |
| | Bitwise OR |
~ | Bitwise NOT |
^ | Bitwise XOR |
<< | Bitwise Left Shift |
>> | Bitwise Right Shift |
in | Check for Membership |
-> | Specify a range of numbers or letters, only when constructing dictionary keys in batches |
List of Global Functions
Type | Global Function | Parameter 1 | Parameter 2 | Parameter 3 | Description | Detailed Usage |
---|---|---|---|---|---|---|
General | len | value: List, Set, Str, Dict | Return the length of a complex type data | |||
General | range | start: Number/DateTime | end: Number/DateTime | step=1 | Generate a list within a specified range | |
General | copy | value: Any | Copy an object | |||
General | map | function: Function/lambda | object: List/Number, List/Number,... | Apply a function to each element of a list and return a new list | 1 | |
General | filter | function: Function/lambda | object: List/Dict | Apply a function to each element of a List or each Key in a Dict, creating a new List or Dict containing elements where the function returns True | 2 | |
General | rgb | red: Int | green: Int | blue: Int | Generate an RGB hexadecimal color code string from three [0, 255] values | |
General | hsl | h: Number | s: Number | l: Number | Generate an HSL hexadecimal color code string from three values | |
Conversion | string | value: Value | Convert any simple type to String | |||
Conversion | number | value: String | Convert a string to Number | |||
Conversion | int | value: Number | Convert a Number to an integer (round down) | |||
Conversion | bool | value: Value | Convert a simple type to Bool, "" and 0 are False | |||
Conversion | list | empty/value: List /value: Set/ value: Dict | Convert to List | 3 | ||
Conversion | set | empty/value: List /value: Set/ value: Dict | Convert to Set | Similar to 3 | ||
Conversion | dict | Generate an empty dict, same as | Similar to 3 | |||
Random | random | a: Number | b: Number | Return a random number following a uniform distribution within range [a, b) | ||
Random | randint | a: Number | b: Number | Return a random integer following a uniform distribution within range [a, b] | ||
Random | normal | u: Number | v: Number | Return a random number following a normal distribution with mean u and standard deviation v | ||
Random | possion | u: Number | Return a random number following a Poisson distribution with a specified mean (u) | |||
Random | bernoulli | p: Number | Return a random number (0 or 1) following a Bernoulli distribution with probability p | |||
Random | random_exp | lambda: Number >0 | Return random values following an exponential distribution according to a specified arrival rate | |||
Mathematical | abs | value: Number | Return the absolute value | |||
Mathematical | sqrt | value: Number | Return the square root | |||
Mathematical | cbrt | value: Number | Return the cube root | |||
Mathematical | exp | value: Number | Return the exponential function with base e → e^x | |||
Mathematical | exp2 | value: Number | Return the power function with base 2 → 2^x | |||
Mathematical | log | value: Number | Return the natural logarithm of a specified value | |||
Mathematical | log2 | value: Number | Return the base-2 logarithm | |||
Mathematical | log10 | value: Number | Return the base-10 logarithm | |||
Mathematical | sin | radian: Number | Sine function, parameter in radians | |||
Mathematical | cos | radian: Number | Cosine function | |||
Mathematical | tan | radian: Number | Tangent function | |||
Mathematical | asin | value: Number | Arcsine function | |||
Mathematical | acos | value: Number | Arccosine function | |||
Mathematical | atan | value: Number | Arctangent function, range (-PI/2, PI/2) | |||
Mathematical | atan2 | y-coordinate: Number | x-coordinate: Number | Return the angle with the positive X-axis, range (-PI, PI) | ||
Mathematical | sinh | value: Number | Hyperbolic sine function | |||
Mathematical | cosh | value: Number | Hyperbolic cosine function | |||
Mathematical | tanh | value: Number | Hyperbolic tangent function | |||
Mathematical | asinh | value: Number | Inverse Hyperbolic sine function | |||
Mathematical | acosh | value: Number | Inverse Hyperbolic cosine function | |||
Mathematical | atanh | value: Number | Inverse Hyperbolic tangent function | |||
Mathematical | factorial | n: Int | Return the factorial of a non-negative integer n! | |||
Mathematical | trunc | value: Number | Truncates a number to an integer by removing the decimal part | |||
Mathematical | ceil | value: Number | Round a number up to the smallest integer greater than or equal to the original value | |||
Mathematical | floor | value: Number | Round a number down to the largest integer less than or equal to the original value | |||
Mathematical | round | value: Number | p=0 | Round to the nearest p decimal places | ||
Mathematical | isnan | value: Number | Check if a numeric value is NaN (Not a Number) | |||
Mathematical | isinf | value: Number | Check if a numeric value is infinite (returns True for both positive and negative infinity) | |||
Statistical | max | value list: [Number]/value set: {Number} | Return the maximum value from multiple numbers or a list | |||
Statistical | min | value list: [Number]/value set: {Number} | Return the minimum value | |||
Statistical | mean | value list: [Number]/value set: {Number} | Return the average value | |||
Statistical | median | value list: [Number]/value set: {Number} | Return the median value | |||
Statistical | sum | value list: [Number]/value set: {Number} | Return the sum | |||
Statistical | prod | value list: [Number]/value set: {Number} | Return the product | |||
Statistical | var | value list: [Number]/value set: {Number} | Return the variance | |||
Statistical | std | value list: [Number]/value set: {Number} | Return the standard deviation | |||
Built-in | NearestDistance | entity1: Agent/Cell/coordinate1: [Number, Number] | entity2: Agent/Cell/coordinate2: [Number, Number] | (space: Cell) | Calculate the shortest distance between a specific object and other objects, taking into account whether the cell space is set to wraparound or not. | 4 |
Built-in | AngleTowards | entity1: Agent/Cell/coordinate1: [Number, Number] | entity2: Agent/Cell/coordinate2: [Number, Number] | (space: Cell) | Compute the angle of a certain object relative to another, based on the shortest distance path. | Similar to 4 |
Local Construction | ProductJoin | lists: List, List, ... | sep = "-" | Calculate the Cartesian product of multiple lists and join each element with a delimiter, only used for constructing dictionary keys in bulk | ||
Construction | defaultdict | value: Any | Generate a dict with default values set to value | |||
Construction | datetime | year, month, day, hour=0, minute=0, second=0 | Generate a date value from specified year, month, day, hour, minute, and second | |||
Construction | datetime | value: String(yyyy-mm-ddTHH:MM:SS) | Generate a date in ISO 8601 format | |||
Construction | fromtimestamp | ts: Number | Generate a date from a timestamp |
Supplementary Explanation of Detailed Usage
map
-
map
applies a function to each element in a List sequentially, returning a new List. -
The first parameter is a function—either a named function or an anonymous function defined by the
lambda
keyword. The function's required parameter count determines how many targets will be processed. -
All subsequent parameters serve as processing targets and can be either List type or other data types:
-
If multiple processing targets are Lists, the system processes them using the length of the shortest List.
-
If a processing target contains a Value, the system uses broadcast processing - applying that value consistently while following the shortest List length.
-
If a processing target contains a Dict, the system creates a List from all its keys for processing, without maintaining any specific key order.
-
-
map(abs, [1, -2, 3])
returns[1, 2, 3]
. -
map(lambda x,y: 2*x + y, [1,2,3], 4)
returns[6, 8, 10]
.
filter
filter
applies a function to each element in a List or each Key in a Dict, creating a new List or Dict containing elements where the function returnsTrue
.- The first parameter is a function — either a function name or an anonymous function defined by the lambda keyword. This function should return a Boolean value.
- The second parameter is the target to be processed. If it's a List type, the final return value will be a List; if it's a Dict type, the final return value will be a Dict.
filter(lambda x: x>0, [1,-2,3])
returns[1,3]
.filter(lambda s: s.contains("x"), {"x1":20, "x2":30,"y1":40})
returns{"x1":20, "x2":30}
.
list
- If the parameter is a list, a copy is made.
- If the parameter is a set, all elements are used to generate a list.
- If the parameter is a dict, all keys are used to generate a list.
- If no parameters are provided, an empty list is generated.
NearestDistance
- The
NearestDistance
function calculates the shortest distance between two entities(Agents or Cells) or coordinate points in a wraparound setting. It can calculate distances between entities, between coordinates and entities, or between coordinates. - If the first two parameters are both coordinates, the third parameter should be passed as a Cell entity to specify the Cell space.
- About
inf
- The expression
1/0
returnsinf
instead of throwing an error. - Both expressions
isinf(number("-inf"))
andisinf(number("inf"))
returnTrue
. - The expressions
number("inf") > 0
ornumber("inf") > number("-inf")
will returnTrue
.