cot()#

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

Calculates the cotangent of number, where number is specified in radians. If number is a Producer, cot() 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 cotangent of.

Returns#

An Expression object.

Example#

Use cot() to calculate the cotangent 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=3.14159 / 4)    # Approximately π/4
    Angle.add(id=2).set(value=3.14159 / 2)    # Approximately π/2
    Angle.add(id=3).set(value="INVALID")      # Non-numeric value


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

# Set a cot_value property to the cotangent of each angle's value.
with model.rule():
    angle = Angle()
    angle.set(cot_value=math.cot(angle.value))

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

print(response.results)
#    id  cot_value
# 0   1   1.000001
# 1   2   0.000001
# 2   3        NaN

See Also#