polars_plan/dsl/
arithmetic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use std::ops::{Add, Div, Mul, Neg, Rem, Sub};

use super::*;

// Arithmetic ops
impl Add for Expr {
    type Output = Expr;

    fn add(self, rhs: Self) -> Self::Output {
        binary_expr(self, Operator::Plus, rhs)
    }
}

impl Sub for Expr {
    type Output = Expr;

    fn sub(self, rhs: Self) -> Self::Output {
        binary_expr(self, Operator::Minus, rhs)
    }
}

impl Div for Expr {
    type Output = Expr;

    fn div(self, rhs: Self) -> Self::Output {
        binary_expr(self, Operator::Divide, rhs)
    }
}

impl Mul for Expr {
    type Output = Expr;

    fn mul(self, rhs: Self) -> Self::Output {
        binary_expr(self, Operator::Multiply, rhs)
    }
}

impl Rem for Expr {
    type Output = Expr;

    fn rem(self, rhs: Self) -> Self::Output {
        binary_expr(self, Operator::Modulus, rhs)
    }
}

impl Neg for Expr {
    type Output = Expr;

    fn neg(self) -> Self::Output {
        self.map_private(FunctionExpr::Negate)
    }
}

impl Expr {
    /// Floor divide `self` by `rhs`.
    pub fn floor_div(self, rhs: Self) -> Self {
        binary_expr(self, Operator::FloorDivide, rhs)
    }

    /// Raise expression to the power `exponent`
    pub fn pow<E: Into<Expr>>(self, exponent: E) -> Self {
        self.map_many_private(
            FunctionExpr::Pow(PowFunction::Generic),
            &[exponent.into()],
            false,
            None,
        )
    }

    /// Compute the square root of the given expression
    pub fn sqrt(self) -> Self {
        self.map_private(FunctionExpr::Pow(PowFunction::Sqrt))
    }

    /// Compute the cube root of the given expression
    pub fn cbrt(self) -> Self {
        self.map_private(FunctionExpr::Pow(PowFunction::Cbrt))
    }

    /// Compute the cosine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn cos(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Cos))
    }

    /// Compute the cotangent of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn cot(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Cot))
    }

    /// Compute the sine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn sin(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Sin))
    }

    /// Compute the tangent of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn tan(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Tan))
    }

    /// Compute the inverse cosine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn arccos(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::ArcCos))
    }

    /// Compute the inverse sine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn arcsin(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::ArcSin))
    }

    /// Compute the inverse tangent of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn arctan(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::ArcTan))
    }

    /// Compute the inverse tangent of the given expression, with the angle expressed as the argument of a complex number
    #[cfg(feature = "trigonometry")]
    pub fn arctan2(self, x: Self) -> Self {
        self.map_many_private(FunctionExpr::Atan2, &[x], false, None)
    }

    /// Compute the hyperbolic cosine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn cosh(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Cosh))
    }

    /// Compute the hyperbolic sine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn sinh(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Sinh))
    }

    /// Compute the hyperbolic tangent of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn tanh(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Tanh))
    }

    /// Compute the inverse hyperbolic cosine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn arccosh(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::ArcCosh))
    }

    /// Compute the inverse hyperbolic sine of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn arcsinh(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::ArcSinh))
    }

    /// Compute the inverse hyperbolic tangent of the given expression
    #[cfg(feature = "trigonometry")]
    pub fn arctanh(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::ArcTanh))
    }

    /// Convert from radians to degrees
    #[cfg(feature = "trigonometry")]
    pub fn degrees(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Degrees))
    }

    /// Convert from degrees to radians
    #[cfg(feature = "trigonometry")]
    pub fn radians(self) -> Self {
        self.map_private(FunctionExpr::Trigonometry(TrigonometricFunction::Radians))
    }

    /// Compute the sign of the given expression
    #[cfg(feature = "sign")]
    pub fn sign(self) -> Self {
        self.map_private(FunctionExpr::Sign)
    }
}