sin()#

relationalai.std.math
#sin(number: Number|Producer) -> Expression

Calculates the sine of number, where number is specified in radians. If number is a Producer, sin() filters out any non-numeric values from the producer. Must be called in a rule or query context.

Parameters#

NameTypeDescription
numberProducer or Python Number objectThe angle in radians to calculate the sine of.

Returns#

An Expression object.

Example#

Use sin() to calculate the sine of an angle in radians:

#import relationalai as rai
from relationalai.std import math


# =====
# SETUP
# =====

model = rai.Model("MyModel")
Angle = model.Type("Angle")

with model.rule():
    Angle.add(id=1).set(value=0)
    Angle.add(id=2).set(value=3.14159 / 2)  # Approximately π/2
    Angle.add(id=3).set(value="INVALID")    # Non-numeric value


# =======
# EXAMPLE
# =======

# Set a sin_value property to the sine of each angle's value.
with model.rule():
    angle = Angle()
    angle.set(sin_value=math.sin(angle.value))

# Since sin() filters out non-numeric values, the sin_value property
# is not set for the angle with ID 3.
with model.query() as select:
    angle = Angle()
    response = select(angle.id, angle.sin_value)

print(response.results)
#    id  sin_value
# 0   1        0.0
# 1   2        1.0
# 2   3        NaN

See Also#