Skip to content

relationalai.std.math.exp()

exp(value: Number|Producer) -> Expression

Calculates the exponential of value, or e ** value, where e is the base of the natural logarithm. If value is a Producer, exp() acts as a filter and removes any non-numeric values from the producer. Must be called in a rule or query context.

NameTypeDescription
valueProducer or Python Number objectThe exponent to raise e to.

An Expression object.

Use exp() to calculate the exponential of a number:

import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Account = model.Type("Account")
with model.rule():
Account.add(id=1).set(balance=1.0)
Account.add(id=2).set(balance=2.0)
Account.add(id=3).set(balance="INVALID") # Non-numeric balance
# =======
# EXAMPLE
# =======
# Set a balance_exp property to the exponential of each account's balance.
with model.rule():
account = Account()
account.set(balance_exp=math.exp(account.balance))
# Since exp() filters out non-numeric values, the balance_exp property
# is not set for the account with ID 3.
with model.query() as select:
account = Account()
response = select(account.id, account.balance_exp)
print(response.results)
# id balance_exp
# 0 1 2.718282
# 1 2 7.389056
# 2 3 NaN