Skip to main content

Operators and Global Functions

Global Function Icons

OperatorandGlobalFunction_image1.png

List of Operators

SymbolDescription
+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
andLogical AND
orLogical OR
notLogical NOT
&Bitwise AND
|Bitwise OR
~Bitwise NOT
^Bitwise XOR
<<Bitwise Left Shift
>>Bitwise Right Shift
inCheck for Membership
->Specify a range of numbers or letters, only when constructing dictionary keys in batches

List of Global Functions

TypeGlobal FunctionParameter 1Parameter 2Parameter 3DescriptionDetailed Usage
Generallenvalue: List, Set, Str, DictReturn the length of a complex type data
Generalrangestart: Number/DateTimeend: Number/DateTimestep=1Generate a list within a specified range
Generalcopyvalue: AnyCopy an object
Generalmapfunction: Function/lambdaobject: List/Number, List/Number,...Apply a function to each element of a list and return a new list1
Generalfilterfunction: Function/lambdaobject: List/DictApply 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 True2
Generalrgbred: Intgreen: Intblue: IntGenerate an RGB hexadecimal color code string from three [0, 255] values
Generalhslh: Numbers: Numberl: NumberGenerate an HSL hexadecimal color code string from three values
Conversionstringvalue: ValueConvert any simple type to String
Conversionnumbervalue: StringConvert a string to Number
Conversionintvalue: NumberConvert a Number to an integer (round down)
Conversionboolvalue: ValueConvert a simple type to Bool, "" and 0 are False
Conversionlistempty/value: List /value: Set/ value: DictConvert to List3
Conversionsetempty/value: List /value: Set/ value: DictConvert to SetSimilar to 3
ConversiondictGenerate an empty dict, same as Similar to 3
Randomrandoma: Numberb: NumberReturn a random number following a uniform distribution within range [a, b)
Randomrandinta: Numberb: NumberReturn a random integer following a uniform distribution within range [a, b]
Randomnormalu: Numberv: NumberReturn a random number following a normal distribution with mean u and standard deviation v
Randompossionu: NumberReturn a random number following a Poisson distribution with a specified mean (u)
Randombernoullip: NumberReturn a random number (0 or 1) following a Bernoulli distribution with probability p
Randomrandom_explambda: Number >0Return random values following an exponential distribution according to a specified arrival rate
Mathematicalabsvalue: NumberReturn the absolute value
Mathematicalsqrtvalue: NumberReturn the square root
Mathematicalcbrtvalue: NumberReturn the cube root
Mathematicalexpvalue: NumberReturn the exponential function with base e → e^x
Mathematicalexp2value: NumberReturn the power function with base 2 → 2^x
Mathematicallogvalue: NumberReturn the natural logarithm of a specified value
Mathematicallog2value: NumberReturn the base-2 logarithm
Mathematicallog10value: NumberReturn the base-10 logarithm
Mathematicalsinradian: NumberSine function, parameter in radians
Mathematicalcosradian: NumberCosine function
Mathematicaltanradian: NumberTangent function
Mathematicalasinvalue: NumberArcsine function
Mathematicalacosvalue: NumberArccosine function
Mathematicalatanvalue: NumberArctangent function, range (-PI/2, PI/2)
Mathematicalatan2y-coordinate: Numberx-coordinate: NumberReturn the angle with the positive X-axis, range (-PI, PI)
Mathematicalsinhvalue: NumberHyperbolic sine function
Mathematicalcoshvalue: NumberHyperbolic cosine function
Mathematicaltanhvalue: NumberHyperbolic tangent function
Mathematicalasinhvalue: NumberInverse Hyperbolic sine function
Mathematicalacoshvalue: NumberInverse Hyperbolic cosine function
Mathematicalatanhvalue: NumberInverse Hyperbolic tangent function
Mathematicalfactorialn: IntReturn the factorial of a non-negative integer n!
Mathematicaltruncvalue: NumberTruncates a number to an integer by removing the decimal part
Mathematicalceilvalue: NumberRound a number up to the smallest integer greater than or equal to the original value
Mathematicalfloorvalue: NumberRound a number down to the largest integer less than or equal to the original value
Mathematicalroundvalue: Numberp=0Round to the nearest p decimal places
Mathematicalisnanvalue: NumberCheck if a numeric value is NaN (Not a Number)
Mathematicalisinfvalue: NumberCheck if a numeric value is infinite (returns True for both positive and negative infinity)
Statisticalmaxvalue list: [Number]/value set: {Number}Return the maximum value from multiple numbers or a list
Statisticalminvalue list: [Number]/value set: {Number}Return the minimum value
Statisticalmeanvalue list: [Number]/value set: {Number}Return the average value
Statisticalmedianvalue list: [Number]/value set: {Number}Return the median value
Statisticalsumvalue list: [Number]/value set: {Number}Return the sum
Statisticalprodvalue list: [Number]/value set: {Number}Return the product
Statisticalvarvalue list: [Number]/value set: {Number}Return the variance
Statisticalstdvalue list: [Number]/value set: {Number}Return the standard deviation
Built-inNearestDistanceentity1: 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-inAngleTowardsentity1: 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 ConstructionProductJoinlists: 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
Constructiondefaultdictvalue: AnyGenerate a dict with default values set to value
Constructiondatetimeyear, month, day, hour=0, minute=0, second=0Generate a date value from specified year, month, day, hour, minute, and second
Constructiondatetimevalue: String(yyyy-mm-ddTHH:MM:SS)Generate a date in ISO 8601 format
Constructionfromtimestampts: NumberGenerate a date from a timestamp

Supplementary Explanation of Detailed Usage

  1. 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.

Examples
  • map(abs, [1, -2, 3]) returns [1, 2, 3].

  • map(lambda x,y: 2*x + y, [1,2,3], 4) returns [6, 8, 10].

  1. 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 returns True.
  • 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.
Examples
  • 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}.
  1. 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.
  1. 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.
  1. About inf
  • The expression 1/0 returns inf instead of throwing an error.
  • Both expressions isinf(number("-inf")) and isinf(number("inf")) return True.
  • The expressions number("inf") > 0 or number("inf") > number("-inf") will return True.