?

Average Error: 20.68% → 0.31%
Time: 32.3s
Precision: binary64
Cost: 78016

?

\[\left(\left(\left(x = 0 \lor 0.5884142 \leq x \land x \leq 505.5909\right) \land \left(-1.796658 \cdot 10^{+308} \leq y \land y \leq -9.425585 \cdot 10^{-310} \lor 1.284938 \cdot 10^{-309} \leq y \land y \leq 1.751224 \cdot 10^{+308}\right)\right) \land \left(-1.776707 \cdot 10^{+308} \leq z \land z \leq -8.599796 \cdot 10^{-310} \lor 3.293145 \cdot 10^{-311} \leq z \land z \leq 1.725154 \cdot 10^{+308}\right)\right) \land \left(-1.796658 \cdot 10^{+308} \leq a \land a \leq -9.425585 \cdot 10^{-310} \lor 1.284938 \cdot 10^{-309} \leq a \land a \leq 1.751224 \cdot 10^{+308}\right)\]
\[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} \]
(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}

Error?

Derivation?

  1. Initial program 20.68

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied egg-rr0.3

    \[\leadsto x + \left(\color{blue}{\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
  3. Simplified0.29

    \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
    Proof

    [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) \]
  4. Applied egg-rr0.33

    \[\leadsto x + \color{blue}{\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}} \]
  5. Simplified0.31

    \[\leadsto x + \color{blue}{\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 \mathsf{fma}\left(\tan y, \tan z, -1\right)}} \]
    Proof

    [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)}} \]
  6. Final simplification0.31

    \[\leadsto 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 \mathsf{fma}\left(\tan y, \tan z, -1\right)} \]

Alternatives

Alternative 1
Error0.3%
Cost59072
\[\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} \]
Alternative 2
Error0.3%
Cost39360
\[x + \left(\frac{\tan y + \tan z}{1 - \frac{\tan z \cdot \sin y}{\cos y}} - \tan a\right) \]
Alternative 3
Error0.29%
Cost32832
\[x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right) \]
Alternative 4
Error11.02%
Cost26568
\[\begin{array}{l} t_0 := \tan \left(y + z\right)\\ \mathbf{if}\;a \leq -9.5 \cdot 10^{-9}:\\ \;\;\;\;\log \left(e^{x + t_0}\right) - \tan a\\ \mathbf{elif}\;a \leq 0.0023:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(t_0 - \tan a\right)\\ \end{array} \]
Alternative 5
Error20.68%
Cost13248
\[x + \left(\tan \left(y + z\right) - \tan a\right) \]
Alternative 6
Error49.88%
Cost6720
\[x + \tan \left(y + z\right) \]
Alternative 7
Error68.08%
Cost64
\[x \]

Error

Reproduce?

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))))