# Expressions List

Last updated

Last updated

You can use a variety of functions that can be used when writing an expression to compare or transform data during the processing of a rule.

The following functions are currently supported within an expression:

Comparison functions

Comparing data

These will compare one instance to another and will evaluate to either **True** or **False. **

These operators are not available for all data types. The table below shows what operators can be used with what data. Operators support either a symbol representation (e.g. =) or a natural language equivalent. For comparing dates, see the date functions.

Operator (and aliases) | String (text) | Number | Date | Truth |
---|---|---|---|---|

Comparing lists

These will compare one list of instances against another list and evaluate to either **True** or **False**.

isSubset

The isSubset function enables you to confirm whether items in one list are present in another.

For example, you could check that the skills required for a job role is a subset of the skills listed for a candidate.

To do this, the function needs to be told where to gather this data from. This is done by specifying which two relationships contain this information and which side of the relationship (the subject or object) will be compared. These relationships should be plural. Using the example above, we might have a rule that looks like this:

**Rule:** Candidate (%S) > is suitable for > Job role (%O)

**Expression:** isSubset(%O, has essential skills, *, %S meets, *)

At runtime, if we had a candidate of `Simone`

and the rule was processing a job role of `Retail Financial Advisor`

, the expression would do the following to determine that the 1st list is a subset of the 2nd list and return True from the expression.

Follow our Academy course on comparative expressions for detailed examples and how you can combine multiple comparative expressions.

Mathematical functions

The following mathematical functions are available to use with **number** concepts only.

**Data type of output: **number

Mathematical functions can be combined using brackets.

Mathematical functions can be combined using brackets. Where mathematical calculations are being performed you should observe correct usage of brackets, otherwise the calculation will be read left to right.

Date functions

Use within an expression to compare or transform dates.

These functions allow you to:

Retrieve the current date/time

Get an index for a given date

Add or subtract from a date

Calculate the difference between dates

Compare two dates to determine if one is in the past, present or future from the other

Inputs to these functions must come from a concept set to a

**date**type. An error will be displayed if you try to use these on data that is from a string, number or truth concept.Date/time format: YYYY-MM-DD HH:MM:SS

These functions may output timestamps, dates, numbers or true/false. The output data type will be mentioned for each function.

Retrieve the current date/time

Functions to get the current date or date/time to use within other functions. For example to work out a person's age you can write an expression to calculate the number of years between a persons date-of-birth and today's date.

**Data type of output: **date/time

These functions will output a unix timestamp, which is a machine readable datetime format. Mostly you will not see these timestamps. However, if you do come across them during building and want to see it in a human-friendly format there’s many websites you can use to convert them such as epoch converter.

Get an index for a given date

Functions that take a date and return an index (number) based on the chosen function.

**Data type of output:** number

Add or subtract from a date

Add or remove a number of days, weeks, months or years from a date to create a new date.

This function requires you to pass in a **date** followed by a **number** you want to add. e.g. `addDays(2023-12-22, 3)`

= 2023-12-25.

To subtract from a date you can use a negative number. e.g. `addDays(2023-12-22, -3)`

= 2023-12-19

These examples use static data, but both arguments of this function can be dynamic by using variables, so long as the data used is of the correct type. E.g. addDays(%date, %number).

**Data type of output:** date/time

These functions output a timestamp. If the output of this function is assigned to the object of the rule (%O) then the object should be a **date **type. If the object is a number, the timestamp will be displayed in the result and/or the evidence.

Calculate the difference between dates

Returns the difference between two dates as a number.

This function requires you to pass in two dates. Regardless of the order, it will always output a positive number.

**Data type of output: **number

Comparing dates

Pass two dates into the function to check if one is in the past, present or future from the other.

These functions will check the dates and evaluate to true or false for the expression to either pass or fail.

**Data type of output:** True/false

1. Generate 1st list | 2. Generate 2nd list |
---|---|

Function name | Description | Example |
---|---|---|

Function name | Description | Example |
---|---|---|

Function name | Description | Example |
---|---|---|

Function name | Description | Example |
---|---|---|

Function name | Description | Example |
---|---|---|

Function name | Description | Example |
---|---|---|

**=**

equals

is equal to

!=

does not equal

is not equal to

>

gt

greater than

is greater than

>=

gte

greater than or equal to

is greater than or equal to

<

lt

less than

is less than

<=

lte

less than or equal to

is less than or equal to

isSubset (see below for details)

%O = Retail Financial Advisor

%S = Candidate

Retail Financial Advisor > has essential skills > *

(* denotes *all*)

Simone > meets > *

The engine gathers all facts for Retail Financial Advisor > has essential skills > * and compiles a list from the objects. Shown below.

The engine gathers all facts for Simone > meets > * and compiles a list from the objects. Shown below.

*1st list*

*2nd list*

Banking experience

Banking experience

Degree qualified

Multi-lingual

3 x A-levels

Degree qualified

Driving license

Driving license

3 x A-levels

Knowledge of current finance products

Add

**+**
Add two numbers together

10 + 5 = 15

Subtract

**-**
Subtract one number from another

2 - 1 = 1

Divide

**/**
Divide one number by another

6 / 2 = 3

Multiply

* Multiple one number by another

4 * 2 = 8

Round

**round(%X,** %Y**)**
Round X to the nearest integer.
You can specify Y to round to Y number of places.
If Y is not specified, 0 is assumed.

round(123.4) = 123 or round(123.4567,2) = 123.46

Ceiling

**ceil(%X)**
Round X towards plus infinity

ceil(4.2) = 5 ceil(-4.2) = -4

Floor

**floor(%X)**
Round X towards minus infinity

floor(4.2) = 4 floor(-4.2) = 4

Absolute

**abs(%X)**
Calculate the absolute value of X

abs(4.2) = 4 abs(-4.2) = 4

Minimum

**min(%A,%B,%C...)**
Calculate the minimum value in a set of values

min(6,4,2,15,11) = 2

Maximum

**max(%A,%B,%C...)**
Calculate the maximum value in a set of values

max(6,4,2,15,11) = 15

Modulus

**mod(%X,%Y)**
Calculate the modulus (the remainder of an integer division) of X/Y

mod(5,2) = 1

Power

**pow(%X,%Y)**
Calculate the power of X to Y (X^Y)

pow(10,3) = 1000

Square root

**sqrt(%X)**
Calculate the square root of X

sqrt(64) = 8

Factorial

**factorial(%X)**
Calculate the factorial of X

factorial(4) = 24

Tangent

**tan(%X)**
Calculate the tangent of X

tan(45) = 1.61978

Cosecant

**csc(%X)**
Calculate the cosecant of X

csc(30) = 1.01211

Cotangent

**cot(%X)**
Calculate the cotangent of X

cot(80) = 0.11107

Secant

**sec(%X)**
Calculate the secant of X

sec(60) = -1.04996

Inverse tangent

**atan2(%X,%Y)**
Calculate the inverse tangent of X and Y

atan2(0.45,0.23) = 1.0983

Today

**today()**
Current date at the point the function is executed during a query.
*The time will default to midnight.*

today() = 1703203200000 (translates to 2023-12-22 00:00:00)

Now

**now()**
Current date **and time** at the point the function is executed during a query.

now() = 1703249564941 (translates to 2023-12-22 12:52:44)

Day of week

**dayOfWeek(%date)**
Returns the nth day of the week for a given date (a number from 1 to 7 where Monday = 1 and Sunday -= 7)

dayOfWeek(2023-12-22) = 5 (it's a Friday)

Day of month

**dayOfMonth(%date)**
Returns the nth day of the month for a given date

dayOfMonth(2023-12-22) = 22

Day of year

**dayOfYear(%date)**
Returns the nth day of the year for a given date

dayOfYear(2023-12-22) = 356

Month of year

**monthOfYear(%date)**
Returns the nth month of the year for a given date (a number between 1-12)

monthOfYear(2023-12-22) = 12

Year

**year(%date)**
Returns the year of a given date

year(2023-12-22) = 2023

Add days

**addDays(%date, n)**
Add n number of days to a given date.

addDays(2023-12-22, 3) =

1703462400000 (converts to 2023-12-25)

Add weeks

**addWeeks(%date, n)**
Add n number of weeks to a given date.

addWeeks(2023-12-22, 3) = 1705017600000 (converts to 2024-01-12)

Add months

**addMonths(%date, n)**
Add n number of months to a given date.

addMonths(2023-12-22), 3) = 1711065600000 (converts to 2024-03-22)

Add years

**addYears(%date, n)**
Add n number of years

addYears(2023-12-222, 3) = 1797897600000 (converts to 2026-12-22)

Seconds between

secondsBetween(%date1, %date2) The number of seconds between two date/times.

secondsBetween(2023-12-22 12:30:**10**, 2023-12-22 12:30:**12**) = **2**

Minutes between

minutesBetween(%date1, %date2) The number of minutes between two date/times.

minutesBetween(2023-12-22 12:**30**:10, 2023-12-22 12:**40**:12) = **10**

Hours between

hoursBetween(%date1, %date2) The number of hours between two dates/times.

hoursBetween(2023-12-22 **12**:30:10, 2023-12-22 **14**:30:12) = **2**

Days between

daysBetween(%date1, %date2) The number of days between two date/times.

daysBetween(2023-12-**18** 12:30:10, 2023-12-**22** 12:30:12) = **4**

Weeks between

weeksBetween(%date1, %date2) The number of weeksonds between two date/times.

weeksBetween(2023-11-20 12:30:10, 2023-12-22 12:30:12) = **4**

Months between

monthsBetween(%date1, %date2) The number of months between two date/times.

monthsBetween(2023-**10**-22 12:30:10, 2023-**12**-22 12:30:12) = **2**

Years between

yearsBetween(%date1, %date2) The number of years between two date/times.

yearsBetween(2023-12-22 12:30:10, 2025-07-18 12:30:12) = **1**

Is before date

**isBeforeDate(%date1, %date2)**
Checks if date 1 is before date 2 and returns true or false

isBeforeDate(2023-12-21, 2023-12-22) = true

Is same date

**isSameDate(%date1, %date2)**
Checks if date 1 is the same as date 2 and returns true or false

isSameDate(2023-12-21, 2023-12-22) = false

Is after date

**isAfterDate(%date1, %date2)**
Checks if date 1 is after date 2 and returns true or false

isAfterDate(2023-12-21, 2023-12-22) = false