Specialized Functions

Vadalog provides a comprehensive library of specialized functions for mathematical operations, hashing, date/time manipulation, type casting, and interval checks.

Mathematical Functions

FunctionSignatureDescription
math:mod()(dividend, divisor) → numberModulo operation
math:sqrt()(x) → doubleSquare root
math:abs()(x) → numberAbsolute value
math:round()(x, scale?) → numberRound to nearest integer or decimal places
math:bround()(x, scale?) → numberBanker’s rounding (round to nearest even)
math:min()(v1, v2, …) → same typeMinimum value
math:max()(v1, v2, …) → same typeMaximum value
math:log()(x) → doubleNatural logarithm
math:log10()(x) → doubleBase-10 logarithm
math:pow()(base, exponent) → doublePower (exponentiation)
math:exp()(x) → doubleExponential (e^x)
math:ceil()(x) → numberRound up to nearest integer
math:floor()(x) → numberRound down to nearest integer
math:sin()(x) → doubleSine
math:cos()(x) → doubleCosine
math:tan()(x) → doubleTangent
math:uniform()(upperBound) → numberRandom integer [0, upperBound)
math:rand()() → doubleRandom double [0, 1)
math:PI()() → doublePi constant
math:E()() → doubleEuler’s number
Examples:
% Square root for distance calculation
distance(X, Y, Distance) <- 
    point(X, Y), 
    Distance = math:sqrt(X * X + Y * Y).

% Compound interest
compound_interest(Principal, Rate, Time, Amount) <- 
    investment(Principal, Rate, Time), 
    Amount = Principal * math:pow(1 + Rate, Time).

% Ceiling for packaging
quantity_boxes(Items, Boxes) <- 
    order(Items), 
    Boxes = math:ceil(Items / 24).

% Circle area
circle_area(Radius, Area) <- 
    circle(Radius), 
    Area = math:PI() * math:pow(Radius, 2).

Hash Functions

FunctionSignatureDescription
hash:hash()(v1, v2, …) → int32-bit Spark hash
hash:sha1()(value) → stringSHA-1 hash
hash:md5()(value) → stringMD5 hash
hash:sha2()(v1, …, bitLength) → stringSHA-2 hash (256, 384, 512 bits)
Examples:
% SHA-256 hash
secure_user_sha256(Username, PasswordHash) <- 
    user(Username, Password), 
    PasswordHash = hash:sha2(Password, 256).

% Composite key hash
composite_hash(User, Pass, Hash) <- 
    credentials(User, Pass), 
    Hash = hash:sha2(User, Pass, 256).

Date and Time Functions

FunctionSignatureDescription
date:current_date()() → dateCurrent date
date:current_timestamp()() → timestampCurrent timestamp
date:next_day()(date) → dateAdd one day
date:prev_day()(date) → dateSubtract one day
date:add()(date, days) → dateAdd N days
date:sub()(date, days) → dateSubtract N days
date:diff()(end, start) → intDifference in days
date:spec_day()(text "MMM-yyyy") → stringParse date with format
date:to_timestamp()(text, format) → timestampParse string to timestamp
date:format()(dateOrTs, pattern) → stringFormat to string
Examples:
% Employee tenure
employee_tenure(Name, Years) <- 
    employee(Name, HireDate), 
    Today = date:current_date(), 
    Days = date:diff(Today, HireDate), 
    Years = Days / 365.

% Product expiry
expiry_date(Product, ExpiryDate) <- 
    product(Product, ManufactureDate, ShelfLife), 
    ExpiryDate = date:add(ManufactureDate, ShelfLife).

% Parse timestamp
parsed_timestamp(Raw, Ts) <- 
    raw_date(Raw), 
    Ts = date:to_timestamp(Raw, "yy-M-dd HH:mm:ss,SSS Z").

Type Casting Functions

FunctionSignatureDescription
as_string()(value) → stringCast to string
as_int()(value) → intCast to integer
as_long()(value) → longCast to long
as_double()(value) → doubleCast to double
as_float()(value) → floatCast to float
as_boolean()(value) → booleanCast to boolean
as_date()(value) → dateCast to date
as_timestamp()(value) → timestampCast to timestamp
as_json()(value) → stringCast to JSON string
as_list()(value, elementType) → listCast to list
as_set()(value, elementType) → setCast to set
as_map()(keys, values, types) → mapCast to map
Example:
formatted_id(ID) <- 
    customer(NumericID), 
    ID = concat("CUST-", as_string(NumericID)).

Interval Operators

FunctionBoundsReturns true for
between(v, min, max)Exclusive bothmin < v < max
_between(v, min, max)Left inclusivemin <= v < max
between_(v, min, max)Right inclusivemin < v <= max
_between_(v, min, max)Both inclusivemin <= v <= max
Example:
adult_customers(Name, Age) <- 
    customer(Name, Age), 
    IsAdult = _between_(Age, 18, 65), 
    IsAdult == #T.

Null Handling Functions

is_null() / is_not_null()

b(El, State) <- a(El), State = is_null(El).
b(El, State) <- a(El), State = is_not_null(El).

nullManagement:ifnull()

Return a fallback value when an expression is null:
b(El, Result) <- a(El), Result = nullManagement:ifnull(El, "was_null", "was_not_null").

nullManagement:coalesce()

Return the first non-null value:
b(Result) <- a(El), Result = nullManagement:coalesce(El, "fallback").

Utility Functions

struct() / struct:get()

Create structured data by pairing keys with values:
a(10, 20).
b(S) <- a(X, Y), S = struct("field1", X, "field2", Y).
c(F1, F2) <- b(S), F1 = struct:get("field1", S), F2 = struct:get("field2", S).
@output("c").
% Output: c(10, 20).

uuid()

Generate universally unique identifiers:
% Random UUID
random_id(A, U) <- input(A), U = uuid().

% Deterministic UUID (same inputs always produce same UUID)
patient_id(Clinic, Patient, UniqueID) <- 
    patient_data(Clinic, Patient), 
    UniqueID = uuid(Clinic, Patient).

monotonically_increasing_id()

Generate monotonically increasing IDs:
numbered_records(Name, ID) <- records(Name), ID = monotonically_increasing_id().

utils:phone_number()

Format phone numbers:
% Default region
formatted_phone(Ph, Fmt) <- phone_data(Ph), Fmt = utils:phone_number(Ph).

% Specific region
formatted_phone_uk(Ph, Fmt) <- phone_data(Ph), Fmt = utils:phone_number(Ph, "GB").

Anonymization Functions

mask()

Mask sensitive data for privacy protection. Replaces characters with configurable mask characters (‘X’, ‘x’, ‘n’ by default).
% Basic masking
masked_email(Name, MaskedEmail) <- 
    user(Name, Email), 
    MaskedEmail = mask(Email).
% "John.Doe123@example.com" → "Xxxx.Xxx nnn@xxxxxxx.xxx"

% Custom characters
custom_masked_ssn(Person, MaskedSSN) <- 
    person(Person, SSN), 
    MaskedSSN = mask(SSN, '*', '*', '#', '-').
% "123-45-6789" → "###-##-####"

anonymization:risk() / anonymization:msu()

Calculate privacy risk scores:
privacy_assessment(Dataset, RiskScore) <- 
    sensitive_data(Dataset, Attributes), 
    RiskScore = anonymization:risk(0.1, [1.0, 0.8, 0.6], 1000).

Kalman Filter Functions

Advanced signal processing and fault detection:
kalmanFilter:fault(A, B, C, R, Q, X, U, nu) → string
kalmanFilter:extractor(input1, input2, inputNumber) → int