Skip to content

relationalai.std.math.pow()

pow(base: Number|Producer, exponent: Number|Producer) -> Expression

Calculates the value of base raised to the power of exponent. If base or exponent is a Producer, pow() acts as a filter and removes any non-numeric values from the producer. Must be called in a rule or query context.

NameTypeDescription
baseProducer or Python Number objectThe base number.
exponentProducer or Python Number objectThe exponent to raise the base to.

An Expression object.

Use pow() to calculate the value of a number raised to a power.

import relationalai as rai
from relationalai.std import math
# =====
# SETUP
# =====
model = rai.Model("MyModel4")
Account = model.Type("Account")
with model.rule():
Account.add(id=1).set(balance=100.00)
Account.add(id=2).set(balance=50.00)
Account.add(id=3).set(balance="INVALID") # Non-numeric balance
# =======
# EXAMPLE
# =======
# Set a balance_squared property to the square of each account's balance.
with model.rule():
account = Account()
account.set(balance_squared=math.pow(account.balance, 2))
# Since pow() filters out non-numeric values, the balance_squared property is
# not set for the account with id=3.
with model.query() as select:
account = Account()
response = select(account.id, account.balance_squared)
print(response.results)
# id balance_squared
# 0 1 10000.0
# 1 2 2500.0
# 2 3 NaN