| Alternative 1 | |
|---|---|
| Error | 0.3% |
| Cost | 59072 |
\[\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
x + \left(\frac{\tan y + \tan z}{1 - \tan z \cdot \left(\tan y \cdot t_0\right)} \cdot \left(1 + t_0\right) - \tan a\right)
\end{array}
\]
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
(FPCore (x y z a)
:precision binary64
(let* ((t_0 (fma (tan y) (tan z) -1.0)))
(+
x
(/
(fma (cos a) (- (- (tan y)) (tan z)) (* t_0 (- (sin a))))
(* (cos a) t_0)))))double code(double x, double y, double z, double a) {
return x + (tan((y + z)) - tan(a));
}
double code(double x, double y, double z, double a) {
double t_0 = fma(tan(y), tan(z), -1.0);
return x + (fma(cos(a), (-tan(y) - tan(z)), (t_0 * -sin(a))) / (cos(a) * t_0));
}
function code(x, y, z, a) return Float64(x + Float64(tan(Float64(y + z)) - tan(a))) end
function code(x, y, z, a) t_0 = fma(tan(y), tan(z), -1.0) return Float64(x + Float64(fma(cos(a), Float64(Float64(-tan(y)) - tan(z)), Float64(t_0 * Float64(-sin(a)))) / Float64(cos(a) * t_0))) end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision] + -1.0), $MachinePrecision]}, N[(x + N[(N[(N[Cos[a], $MachinePrecision] * N[((-N[Tan[y], $MachinePrecision]) - N[Tan[z], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * (-N[Sin[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x + \left(\tan \left(y + z\right) - \tan a\right)
\begin{array}{l}
t_0 := \mathsf{fma}\left(\tan y, \tan z, -1\right)\\
x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, t_0 \cdot \left(-\sin a\right)\right)}{\cos a \cdot t_0}
\end{array}
Initial program 20.68
Applied egg-rr0.3
Simplified0.29
[Start]0.3 | \[ x + \left(\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z} - \tan a\right)
\] |
|---|---|
associate-*r/ [=>]0.29 | \[ x + \left(\color{blue}{\frac{\left(\tan y + \tan z\right) \cdot 1}{1 - \tan y \cdot \tan z}} - \tan a\right)
\] |
*-rgt-identity [=>]0.29 | \[ x + \left(\frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} - \tan a\right)
\] |
Applied egg-rr0.33
Simplified0.31
[Start]0.33 | \[ x + \frac{\left(\left(-\tan y\right) - \tan z\right) \cdot \cos a - \left(-1 + \tan y \cdot \tan z\right) \cdot \sin a}{\left(-1 + \tan y \cdot \tan z\right) \cdot \cos a}
\] |
|---|---|
*-commutative [=>]0.33 | \[ x + \frac{\color{blue}{\cos a \cdot \left(\left(-\tan y\right) - \tan z\right)} - \left(-1 + \tan y \cdot \tan z\right) \cdot \sin a}{\left(-1 + \tan y \cdot \tan z\right) \cdot \cos a}
\] |
fma-neg [=>]0.32 | \[ x + \frac{\color{blue}{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, -\left(-1 + \tan y \cdot \tan z\right) \cdot \sin a\right)}}{\left(-1 + \tan y \cdot \tan z\right) \cdot \cos a}
\] |
distribute-rgt-neg-in [=>]0.32 | \[ x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, \color{blue}{\left(-1 + \tan y \cdot \tan z\right) \cdot \left(-\sin a\right)}\right)}{\left(-1 + \tan y \cdot \tan z\right) \cdot \cos a}
\] |
+-commutative [=>]0.32 | \[ x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, \color{blue}{\left(\tan y \cdot \tan z + -1\right)} \cdot \left(-\sin a\right)\right)}{\left(-1 + \tan y \cdot \tan z\right) \cdot \cos a}
\] |
fma-def [=>]0.32 | \[ x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, \color{blue}{\mathsf{fma}\left(\tan y, \tan z, -1\right)} \cdot \left(-\sin a\right)\right)}{\left(-1 + \tan y \cdot \tan z\right) \cdot \cos a}
\] |
*-commutative [=>]0.32 | \[ x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, \mathsf{fma}\left(\tan y, \tan z, -1\right) \cdot \left(-\sin a\right)\right)}{\color{blue}{\cos a \cdot \left(-1 + \tan y \cdot \tan z\right)}}
\] |
+-commutative [=>]0.32 | \[ x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, \mathsf{fma}\left(\tan y, \tan z, -1\right) \cdot \left(-\sin a\right)\right)}{\cos a \cdot \color{blue}{\left(\tan y \cdot \tan z + -1\right)}}
\] |
fma-def [=>]0.31 | \[ x + \frac{\mathsf{fma}\left(\cos a, \left(-\tan y\right) - \tan z, \mathsf{fma}\left(\tan y, \tan z, -1\right) \cdot \left(-\sin a\right)\right)}{\cos a \cdot \color{blue}{\mathsf{fma}\left(\tan y, \tan z, -1\right)}}
\] |
Final simplification0.31
| Alternative 1 | |
|---|---|
| Error | 0.3% |
| Cost | 59072 |
| Alternative 2 | |
|---|---|
| Error | 0.3% |
| Cost | 39360 |
| Alternative 3 | |
|---|---|
| Error | 0.29% |
| Cost | 32832 |
| Alternative 4 | |
|---|---|
| Error | 11.02% |
| Cost | 26568 |
| Alternative 5 | |
|---|---|
| Error | 20.68% |
| Cost | 13248 |
| Alternative 6 | |
|---|---|
| Error | 49.88% |
| Cost | 6720 |
| Alternative 7 | |
|---|---|
| Error | 68.08% |
| Cost | 64 |
herbie shell --seed 2023103
(FPCore (x y z a)
:name "tan-example (used to crash)"
:precision binary64
:pre (and (and (and (or (== x 0.0) (and (<= 0.5884142 x) (<= x 505.5909))) (or (and (<= -1.796658e+308 y) (<= y -9.425585e-310)) (and (<= 1.284938e-309 y) (<= y 1.751224e+308)))) (or (and (<= -1.776707e+308 z) (<= z -8.599796e-310)) (and (<= 3.293145e-311 z) (<= z 1.725154e+308)))) (or (and (<= -1.796658e+308 a) (<= a -9.425585e-310)) (and (<= 1.284938e-309 a) (<= a 1.751224e+308))))
(+ x (- (tan (+ y z)) (tan a))))