tan-example (used to crash)

Percentage Accurate: 79.4% → 99.7%
Time: 40.1s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\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)\]
\[\begin{array}{l} \\ x + \left(\tan \left(y + z\right) - \tan a\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
	return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a):
	return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a)
	return Float64(x + Float64(tan(Float64(y + z)) - tan(a)))
end
function tmp = code(x, y, z, a)
	tmp = x + (tan((y + z)) - tan(a));
end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 79.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \left(\tan \left(y + z\right) - \tan a\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
	return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a):
	return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a)
	return Float64(x + Float64(tan(Float64(y + z)) - tan(a)))
end
function tmp = code(x, y, z, a)
	tmp = x + (tan((y + z)) - tan(a));
end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right) + x \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (+ (- (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) (tan a)) x))
double code(double x, double y, double z, double a) {
	return (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - tan(a)) + x;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = (((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z)))) - tan(a)) + x
end function
public static double code(double x, double y, double z, double a) {
	return (((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z)))) - Math.tan(a)) + x;
}
def code(x, y, z, a):
	return (((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) - math.tan(a)) + x
function code(x, y, z, a)
	return Float64(Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) - tan(a)) + x)
end
function tmp = code(x, y, z, a)
	tmp = (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - tan(a)) + x;
end
code[x_, y_, z_, a_] := N[(N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}

\\
\left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right) + x
\end{array}
Derivation
  1. Initial program 80.9%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutative80.9%

      \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \tan a\right) + x} \]
    2. sub-neg80.9%

      \[\leadsto \color{blue}{\left(\tan \left(y + z\right) + \left(-\tan a\right)\right)} + x \]
    3. associate-+l+80.9%

      \[\leadsto \color{blue}{\tan \left(y + z\right) + \left(\left(-\tan a\right) + x\right)} \]
    4. tan-sum99.6%

      \[\leadsto \color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} + \left(\left(-\tan a\right) + x\right) \]
    5. div-inv99.6%

      \[\leadsto \color{blue}{\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z}} + \left(\left(-\tan a\right) + x\right) \]
    6. fma-define99.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, \left(-\tan a\right) + x\right)} \]
    7. neg-mul-199.6%

      \[\leadsto \mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, \color{blue}{-1 \cdot \tan a} + x\right) \]
    8. fma-define99.6%

      \[\leadsto \mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, \color{blue}{\mathsf{fma}\left(-1, \tan a, x\right)}\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, \mathsf{fma}\left(-1, \tan a, x\right)\right)} \]
  5. Step-by-step derivation
    1. fma-undefine99.6%

      \[\leadsto \color{blue}{\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z} + \mathsf{fma}\left(-1, \tan a, x\right)} \]
    2. fma-undefine99.6%

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

      \[\leadsto \left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z} + \left(\color{blue}{\left(-\tan a\right)} + x\right) \]
    4. associate-+r+99.8%

      \[\leadsto \color{blue}{\left(\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z} + \left(-\tan a\right)\right) + x} \]
    5. unsub-neg99.8%

      \[\leadsto \color{blue}{\left(\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z} - \tan a\right)} + x \]
    6. associate-*r/99.8%

      \[\leadsto \left(\color{blue}{\frac{\left(\tan y + \tan z\right) \cdot 1}{1 - \tan y \cdot \tan z}} - \tan a\right) + x \]
    7. *-rgt-identity99.8%

      \[\leadsto \left(\frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} - \tan a\right) + x \]
  6. Simplified99.8%

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

Alternative 2: 89.1% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\cos \left(y + z\right)}\\ t_1 := \sin \left(y + z\right)\\ \mathbf{if}\;\tan a \leq -0.01:\\ \;\;\;\;x + \mathsf{fma}\left(t\_1, t\_0, -\tan a\right)\\ \mathbf{elif}\;\tan a \leq 0.0001:\\ \;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(t\_1 \cdot t\_0 - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (/ 1.0 (cos (+ y z)))) (t_1 (sin (+ y z))))
   (if (<= (tan a) -0.01)
     (+ x (fma t_1 t_0 (- (tan a))))
     (if (<= (tan a) 0.0001)
       (+ x (- (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) a))
       (+ x (- (* t_1 t_0) (tan a)))))))
double code(double x, double y, double z, double a) {
	double t_0 = 1.0 / cos((y + z));
	double t_1 = sin((y + z));
	double tmp;
	if (tan(a) <= -0.01) {
		tmp = x + fma(t_1, t_0, -tan(a));
	} else if (tan(a) <= 0.0001) {
		tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - a);
	} else {
		tmp = x + ((t_1 * t_0) - tan(a));
	}
	return tmp;
}
function code(x, y, z, a)
	t_0 = Float64(1.0 / cos(Float64(y + z)))
	t_1 = sin(Float64(y + z))
	tmp = 0.0
	if (tan(a) <= -0.01)
		tmp = Float64(x + fma(t_1, t_0, Float64(-tan(a))));
	elseif (tan(a) <= 0.0001)
		tmp = Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) - a));
	else
		tmp = Float64(x + Float64(Float64(t_1 * t_0) - tan(a)));
	end
	return tmp
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(1.0 / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.01], N[(x + N[(t$95$1 * t$95$0 + (-N[Tan[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 0.0001], N[(x + N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(t$95$1 * t$95$0), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\cos \left(y + z\right)}\\
t_1 := \sin \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.01:\\
\;\;\;\;x + \mathsf{fma}\left(t\_1, t\_0, -\tan a\right)\\

\mathbf{elif}\;\tan a \leq 0.0001:\\
\;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - a\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(t\_1 \cdot t\_0 - \tan a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (tan.f64 a) < -0.0100000000000000002

    1. Initial program 79.8%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot79.8%

        \[\leadsto x + \left(\color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} - \tan a\right) \]
      2. div-inv79.8%

        \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
      3. fma-neg79.8%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, -\tan a\right)} \]
    4. Applied egg-rr79.8%

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, -\tan a\right)} \]

    if -0.0100000000000000002 < (tan.f64 a) < 1.00000000000000005e-4

    1. Initial program 83.9%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 83.9%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a}\right) \]
    4. Step-by-step derivation
      1. tan-sum99.8%

        \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - a\right) \]
      2. tan-quot99.8%

        \[\leadsto x + \left(\frac{\color{blue}{\frac{\sin y}{\cos y}} + \tan z}{1 - \tan y \cdot \tan z} - a\right) \]
      3. div-inv99.8%

        \[\leadsto x + \left(\color{blue}{\left(\frac{\sin y}{\cos y} + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z}} - a\right) \]
      4. tan-quot99.8%

        \[\leadsto x + \left(\left(\color{blue}{\tan y} + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z} - a\right) \]
      5. fma-neg99.8%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, -a\right)} \]
      6. +-commutative99.8%

        \[\leadsto x + \mathsf{fma}\left(\color{blue}{\tan z + \tan y}, \frac{1}{1 - \tan y \cdot \tan z}, -a\right) \]
      7. *-commutative99.8%

        \[\leadsto x + \mathsf{fma}\left(\tan z + \tan y, \frac{1}{1 - \color{blue}{\tan z \cdot \tan y}}, -a\right) \]
    5. Applied egg-rr99.8%

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(\tan z + \tan y, \frac{1}{1 - \tan z \cdot \tan y}, -a\right)} \]
    6. Step-by-step derivation
      1. fma-undefine99.8%

        \[\leadsto x + \color{blue}{\left(\left(\tan z + \tan y\right) \cdot \frac{1}{1 - \tan z \cdot \tan y} + \left(-a\right)\right)} \]
      2. unsub-neg99.8%

        \[\leadsto x + \color{blue}{\left(\left(\tan z + \tan y\right) \cdot \frac{1}{1 - \tan z \cdot \tan y} - a\right)} \]
      3. associate-*r/99.8%

        \[\leadsto x + \left(\color{blue}{\frac{\left(\tan z + \tan y\right) \cdot 1}{1 - \tan z \cdot \tan y}} - a\right) \]
      4. *-rgt-identity99.8%

        \[\leadsto x + \left(\frac{\color{blue}{\tan z + \tan y}}{1 - \tan z \cdot \tan y} - a\right) \]
    7. Simplified99.8%

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

    if 1.00000000000000005e-4 < (tan.f64 a)

    1. Initial program 76.1%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot76.1%

        \[\leadsto x + \left(\color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} - \tan a\right) \]
      2. div-inv76.1%

        \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
    4. Applied egg-rr76.1%

      \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.01:\\ \;\;\;\;x + \mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, -\tan a\right)\\ \mathbf{elif}\;\tan a \leq 0.0001:\\ \;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)} - \tan a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 88.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\cos \left(y + z\right)}\\ t_1 := \sin \left(y + z\right)\\ \mathbf{if}\;\tan a \leq -0.01:\\ \;\;\;\;x + \mathsf{fma}\left(t\_1, t\_0, -\tan a\right)\\ \mathbf{elif}\;\tan a \leq 2 \cdot 10^{-19}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(t\_1 \cdot t\_0 - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (/ 1.0 (cos (+ y z)))) (t_1 (sin (+ y z))))
   (if (<= (tan a) -0.01)
     (+ x (fma t_1 t_0 (- (tan a))))
     (if (<= (tan a) 2e-19)
       (+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))))
       (+ x (- (* t_1 t_0) (tan a)))))))
double code(double x, double y, double z, double a) {
	double t_0 = 1.0 / cos((y + z));
	double t_1 = sin((y + z));
	double tmp;
	if (tan(a) <= -0.01) {
		tmp = x + fma(t_1, t_0, -tan(a));
	} else if (tan(a) <= 2e-19) {
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
	} else {
		tmp = x + ((t_1 * t_0) - tan(a));
	}
	return tmp;
}
function code(x, y, z, a)
	t_0 = Float64(1.0 / cos(Float64(y + z)))
	t_1 = sin(Float64(y + z))
	tmp = 0.0
	if (tan(a) <= -0.01)
		tmp = Float64(x + fma(t_1, t_0, Float64(-tan(a))));
	elseif (tan(a) <= 2e-19)
		tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))));
	else
		tmp = Float64(x + Float64(Float64(t_1 * t_0) - tan(a)));
	end
	return tmp
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(1.0 / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.01], N[(x + N[(t$95$1 * t$95$0 + (-N[Tan[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 2e-19], N[(x + N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(t$95$1 * t$95$0), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\cos \left(y + z\right)}\\
t_1 := \sin \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.01:\\
\;\;\;\;x + \mathsf{fma}\left(t\_1, t\_0, -\tan a\right)\\

\mathbf{elif}\;\tan a \leq 2 \cdot 10^{-19}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\

\mathbf{else}:\\
\;\;\;\;x + \left(t\_1 \cdot t\_0 - \tan a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (tan.f64 a) < -0.0100000000000000002

    1. Initial program 79.8%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot79.8%

        \[\leadsto x + \left(\color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} - \tan a\right) \]
      2. div-inv79.8%

        \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
      3. fma-neg79.8%

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, -\tan a\right)} \]
    4. Applied egg-rr79.8%

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, -\tan a\right)} \]

    if -0.0100000000000000002 < (tan.f64 a) < 2e-19

    1. Initial program 84.1%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot84.1%

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
      2. div-inv84.1%

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
    4. Applied egg-rr84.1%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
    5. Taylor expanded in a around 0 84.1%

      \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
    6. Step-by-step derivation
      1. +-commutative84.1%

        \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
      2. remove-double-neg84.1%

        \[\leadsto \frac{\sin \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)}{\cos \left(y + z\right)} + x \]
      3. mul-1-neg84.1%

        \[\leadsto \frac{\sin \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)}{\cos \left(y + z\right)} + x \]
      4. sub-neg84.1%

        \[\leadsto \frac{\sin \color{blue}{\left(y - -1 \cdot z\right)}}{\cos \left(y + z\right)} + x \]
      5. remove-double-neg84.1%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)} + x \]
      6. mul-1-neg84.1%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)} + x \]
      7. sub-neg84.1%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \color{blue}{\left(y - -1 \cdot z\right)}} + x \]
    7. Simplified84.1%

      \[\leadsto \color{blue}{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + x} \]
    8. Step-by-step derivation
      1. quot-tan84.1%

        \[\leadsto \color{blue}{\tan \left(z + y\right)} + x \]
      2. tan-sum99.8%

        \[\leadsto \color{blue}{\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y}} + x \]
      3. div-inv99.8%

        \[\leadsto \color{blue}{\left(\tan z + \tan y\right) \cdot \frac{1}{1 - \tan z \cdot \tan y}} + x \]
    9. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\left(\tan z + \tan y\right) \cdot \frac{1}{1 - \tan z \cdot \tan y}} + x \]
    10. Step-by-step derivation
      1. associate-*r/99.8%

        \[\leadsto \color{blue}{\frac{\left(\tan z + \tan y\right) \cdot 1}{1 - \tan z \cdot \tan y}} + x \]
      2. *-rgt-identity99.8%

        \[\leadsto \frac{\color{blue}{\tan z + \tan y}}{1 - \tan z \cdot \tan y} + x \]
    11. Simplified99.8%

      \[\leadsto \color{blue}{\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y}} + x \]

    if 2e-19 < (tan.f64 a)

    1. Initial program 76.1%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot76.1%

        \[\leadsto x + \left(\color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} - \tan a\right) \]
      2. div-inv76.1%

        \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
    4. Applied egg-rr76.1%

      \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.01:\\ \;\;\;\;x + \mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, -\tan a\right)\\ \mathbf{elif}\;\tan a \leq 2 \cdot 10^{-19}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)} - \tan a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 88.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\tan a \leq -0.01:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\ \mathbf{elif}\;\tan a \leq 2 \cdot 10^{-19}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)} - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (<= (tan a) -0.01)
   (+ x (- (tan (+ y z)) (tan a)))
   (if (<= (tan a) 2e-19)
     (+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))))
     (+ x (- (* (sin (+ y z)) (/ 1.0 (cos (+ y z)))) (tan a))))))
double code(double x, double y, double z, double a) {
	double tmp;
	if (tan(a) <= -0.01) {
		tmp = x + (tan((y + z)) - tan(a));
	} else if (tan(a) <= 2e-19) {
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
	} else {
		tmp = x + ((sin((y + z)) * (1.0 / cos((y + z)))) - tan(a));
	}
	return tmp;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: tmp
    if (tan(a) <= (-0.01d0)) then
        tmp = x + (tan((y + z)) - tan(a))
    else if (tan(a) <= 2d-19) then
        tmp = x + ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z))))
    else
        tmp = x + ((sin((y + z)) * (1.0d0 / cos((y + z)))) - tan(a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if (Math.tan(a) <= -0.01) {
		tmp = x + (Math.tan((y + z)) - Math.tan(a));
	} else if (Math.tan(a) <= 2e-19) {
		tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z))));
	} else {
		tmp = x + ((Math.sin((y + z)) * (1.0 / Math.cos((y + z)))) - Math.tan(a));
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if math.tan(a) <= -0.01:
		tmp = x + (math.tan((y + z)) - math.tan(a))
	elif math.tan(a) <= 2e-19:
		tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z))))
	else:
		tmp = x + ((math.sin((y + z)) * (1.0 / math.cos((y + z)))) - math.tan(a))
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if (tan(a) <= -0.01)
		tmp = Float64(x + Float64(tan(Float64(y + z)) - tan(a)));
	elseif (tan(a) <= 2e-19)
		tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))));
	else
		tmp = Float64(x + Float64(Float64(sin(Float64(y + z)) * Float64(1.0 / cos(Float64(y + z)))) - tan(a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if (tan(a) <= -0.01)
		tmp = x + (tan((y + z)) - tan(a));
	elseif (tan(a) <= 2e-19)
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
	else
		tmp = x + ((sin((y + z)) * (1.0 / cos((y + z)))) - tan(a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[LessEqual[N[Tan[a], $MachinePrecision], -0.01], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 2e-19], N[(x + N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision] * N[(1.0 / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.01:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\

\mathbf{elif}\;\tan a \leq 2 \cdot 10^{-19}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\

\mathbf{else}:\\
\;\;\;\;x + \left(\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)} - \tan a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (tan.f64 a) < -0.0100000000000000002

    1. Initial program 79.8%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing

    if -0.0100000000000000002 < (tan.f64 a) < 2e-19

    1. Initial program 84.1%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot84.1%

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
      2. div-inv84.1%

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
    4. Applied egg-rr84.1%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
    5. Taylor expanded in a around 0 84.1%

      \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
    6. Step-by-step derivation
      1. +-commutative84.1%

        \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
      2. remove-double-neg84.1%

        \[\leadsto \frac{\sin \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)}{\cos \left(y + z\right)} + x \]
      3. mul-1-neg84.1%

        \[\leadsto \frac{\sin \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)}{\cos \left(y + z\right)} + x \]
      4. sub-neg84.1%

        \[\leadsto \frac{\sin \color{blue}{\left(y - -1 \cdot z\right)}}{\cos \left(y + z\right)} + x \]
      5. remove-double-neg84.1%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)} + x \]
      6. mul-1-neg84.1%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)} + x \]
      7. sub-neg84.1%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \color{blue}{\left(y - -1 \cdot z\right)}} + x \]
    7. Simplified84.1%

      \[\leadsto \color{blue}{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + x} \]
    8. Step-by-step derivation
      1. quot-tan84.1%

        \[\leadsto \color{blue}{\tan \left(z + y\right)} + x \]
      2. tan-sum99.8%

        \[\leadsto \color{blue}{\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y}} + x \]
      3. div-inv99.8%

        \[\leadsto \color{blue}{\left(\tan z + \tan y\right) \cdot \frac{1}{1 - \tan z \cdot \tan y}} + x \]
    9. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\left(\tan z + \tan y\right) \cdot \frac{1}{1 - \tan z \cdot \tan y}} + x \]
    10. Step-by-step derivation
      1. associate-*r/99.8%

        \[\leadsto \color{blue}{\frac{\left(\tan z + \tan y\right) \cdot 1}{1 - \tan z \cdot \tan y}} + x \]
      2. *-rgt-identity99.8%

        \[\leadsto \frac{\color{blue}{\tan z + \tan y}}{1 - \tan z \cdot \tan y} + x \]
    11. Simplified99.8%

      \[\leadsto \color{blue}{\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y}} + x \]

    if 2e-19 < (tan.f64 a)

    1. Initial program 76.1%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot76.1%

        \[\leadsto x + \left(\color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} - \tan a\right) \]
      2. div-inv76.1%

        \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
    4. Applied egg-rr76.1%

      \[\leadsto x + \left(\color{blue}{\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)}} - \tan a\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification88.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.01:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\ \mathbf{elif}\;\tan a \leq 2 \cdot 10^{-19}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\sin \left(y + z\right) \cdot \frac{1}{\cos \left(y + z\right)} - \tan a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 60.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y + z \leq 10^{-27}:\\ \;\;\;\;x + \left(\tan y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \tan \left(y + z\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (<= (+ y z) 1e-27) (+ x (- (tan y) (tan a))) (+ x (tan (+ y z)))))
double code(double x, double y, double z, double a) {
	double tmp;
	if ((y + z) <= 1e-27) {
		tmp = x + (tan(y) - tan(a));
	} else {
		tmp = x + tan((y + z));
	}
	return tmp;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: tmp
    if ((y + z) <= 1d-27) then
        tmp = x + (tan(y) - tan(a))
    else
        tmp = x + tan((y + z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if ((y + z) <= 1e-27) {
		tmp = x + (Math.tan(y) - Math.tan(a));
	} else {
		tmp = x + Math.tan((y + z));
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if (y + z) <= 1e-27:
		tmp = x + (math.tan(y) - math.tan(a))
	else:
		tmp = x + math.tan((y + z))
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if (Float64(y + z) <= 1e-27)
		tmp = Float64(x + Float64(tan(y) - tan(a)));
	else
		tmp = Float64(x + tan(Float64(y + z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if ((y + z) <= 1e-27)
		tmp = x + (tan(y) - tan(a));
	else
		tmp = x + tan((y + z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[LessEqual[N[(y + z), $MachinePrecision], 1e-27], N[(x + N[(N[Tan[y], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y + z \leq 10^{-27}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\

\mathbf{else}:\\
\;\;\;\;x + \tan \left(y + z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 y z) < 1e-27

    1. Initial program 86.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 68.0%

      \[\leadsto x + \left(\tan \color{blue}{y} - \tan a\right) \]

    if 1e-27 < (+.f64 y z)

    1. Initial program 69.9%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. tan-quot69.9%

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
      2. div-inv69.9%

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
    4. Applied egg-rr69.9%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
    5. Taylor expanded in a around 0 50.9%

      \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
    6. Step-by-step derivation
      1. +-commutative50.9%

        \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
      2. remove-double-neg50.9%

        \[\leadsto \frac{\sin \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)}{\cos \left(y + z\right)} + x \]
      3. mul-1-neg50.9%

        \[\leadsto \frac{\sin \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)}{\cos \left(y + z\right)} + x \]
      4. sub-neg50.9%

        \[\leadsto \frac{\sin \color{blue}{\left(y - -1 \cdot z\right)}}{\cos \left(y + z\right)} + x \]
      5. remove-double-neg50.9%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)} + x \]
      6. mul-1-neg50.9%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)} + x \]
      7. sub-neg50.9%

        \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \color{blue}{\left(y - -1 \cdot z\right)}} + x \]
    7. Simplified50.9%

      \[\leadsto \color{blue}{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + x} \]
    8. Step-by-step derivation
      1. *-un-lft-identity50.9%

        \[\leadsto \color{blue}{1 \cdot \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)}} + x \]
      2. quot-tan50.9%

        \[\leadsto 1 \cdot \color{blue}{\tan \left(z + y\right)} + x \]
    9. Applied egg-rr50.9%

      \[\leadsto \color{blue}{1 \cdot \tan \left(z + y\right)} + x \]
    10. Step-by-step derivation
      1. *-lft-identity50.9%

        \[\leadsto \color{blue}{\tan \left(z + y\right)} + x \]
    11. Simplified50.9%

      \[\leadsto \color{blue}{\tan \left(z + y\right)} + x \]
  3. Recombined 2 regimes into one program.
  4. Final simplification62.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y + z \leq 10^{-27}:\\ \;\;\;\;x + \left(\tan y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \tan \left(y + z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 69.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.6 \cdot 10^{-7}:\\ \;\;\;\;x + \left(\tan y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tan z - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (<= y -3.6e-7) (+ x (- (tan y) (tan a))) (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
	double tmp;
	if (y <= -3.6e-7) {
		tmp = x + (tan(y) - tan(a));
	} else {
		tmp = x + (tan(z) - tan(a));
	}
	return tmp;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: tmp
    if (y <= (-3.6d-7)) then
        tmp = x + (tan(y) - tan(a))
    else
        tmp = x + (tan(z) - tan(a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if (y <= -3.6e-7) {
		tmp = x + (Math.tan(y) - Math.tan(a));
	} else {
		tmp = x + (Math.tan(z) - Math.tan(a));
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if y <= -3.6e-7:
		tmp = x + (math.tan(y) - math.tan(a))
	else:
		tmp = x + (math.tan(z) - math.tan(a))
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if (y <= -3.6e-7)
		tmp = Float64(x + Float64(tan(y) - tan(a)));
	else
		tmp = Float64(x + Float64(tan(z) - tan(a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if (y <= -3.6e-7)
		tmp = x + (tan(y) - tan(a));
	else
		tmp = x + (tan(z) - tan(a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[LessEqual[y, -3.6e-7], N[(x + N[(N[Tan[y], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-7}:\\
\;\;\;\;x + \left(\tan y - \tan a\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(\tan z - \tan a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.59999999999999994e-7

    1. Initial program 65.1%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 64.3%

      \[\leadsto x + \left(\tan \color{blue}{y} - \tan a\right) \]

    if -3.59999999999999994e-7 < y

    1. Initial program 88.7%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 77.1%

      \[\leadsto x + \left(\tan \color{blue}{z} - \tan a\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 79.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \left(\tan \left(y + z\right) - \tan a\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
	return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a):
	return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a)
	return Float64(x + Float64(tan(Float64(y + z)) - tan(a)))
end
function tmp = code(x, y, z, a)
	tmp = x + (tan((y + z)) - tan(a));
end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}
Derivation
  1. Initial program 80.9%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 8: 41.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -1.55:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq 5.6 \cdot 10^{-5}:\\ \;\;\;\;x + \left(\tan y - a\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (<= a -1.55) x (if (<= a 5.6e-5) (+ x (- (tan y) a)) x)))
double code(double x, double y, double z, double a) {
	double tmp;
	if (a <= -1.55) {
		tmp = x;
	} else if (a <= 5.6e-5) {
		tmp = x + (tan(y) - a);
	} else {
		tmp = x;
	}
	return tmp;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: tmp
    if (a <= (-1.55d0)) then
        tmp = x
    else if (a <= 5.6d-5) then
        tmp = x + (tan(y) - a)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if (a <= -1.55) {
		tmp = x;
	} else if (a <= 5.6e-5) {
		tmp = x + (Math.tan(y) - a);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if a <= -1.55:
		tmp = x
	elif a <= 5.6e-5:
		tmp = x + (math.tan(y) - a)
	else:
		tmp = x
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if (a <= -1.55)
		tmp = x;
	elseif (a <= 5.6e-5)
		tmp = Float64(x + Float64(tan(y) - a));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if (a <= -1.55)
		tmp = x;
	elseif (a <= 5.6e-5)
		tmp = x + (tan(y) - a);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[LessEqual[a, -1.55], x, If[LessEqual[a, 5.6e-5], N[(x + N[(N[Tan[y], $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.55:\\
\;\;\;\;x\\

\mathbf{elif}\;a \leq 5.6 \cdot 10^{-5}:\\
\;\;\;\;x + \left(\tan y - a\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.55000000000000004 or 5.59999999999999992e-5 < a

    1. Initial program 77.2%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 22.6%

      \[\leadsto \color{blue}{x} \]

    if -1.55000000000000004 < a < 5.59999999999999992e-5

    1. Initial program 84.6%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 83.8%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a}\right) \]
    4. Taylor expanded in y around inf 65.4%

      \[\leadsto x + \left(\tan \color{blue}{y} - a\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 50.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ x + \tan \left(y + z\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (+ x (tan (+ y z))))
double code(double x, double y, double z, double a) {
	return x + tan((y + z));
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + tan((y + z))
end function
public static double code(double x, double y, double z, double a) {
	return x + Math.tan((y + z));
}
def code(x, y, z, a):
	return x + math.tan((y + z))
function code(x, y, z, a)
	return Float64(x + tan(Float64(y + z)))
end
function tmp = code(x, y, z, a)
	tmp = x + tan((y + z));
end
code[x_, y_, z_, a_] := N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \tan \left(y + z\right)
\end{array}
Derivation
  1. Initial program 80.9%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. tan-quot80.9%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
    2. div-inv80.9%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
  4. Applied egg-rr80.9%

    \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\sin a \cdot \frac{1}{\cos a}}\right) \]
  5. Taylor expanded in a around 0 53.5%

    \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
  6. Step-by-step derivation
    1. +-commutative53.5%

      \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
    2. remove-double-neg53.5%

      \[\leadsto \frac{\sin \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)}{\cos \left(y + z\right)} + x \]
    3. mul-1-neg53.5%

      \[\leadsto \frac{\sin \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)}{\cos \left(y + z\right)} + x \]
    4. sub-neg53.5%

      \[\leadsto \frac{\sin \color{blue}{\left(y - -1 \cdot z\right)}}{\cos \left(y + z\right)} + x \]
    5. remove-double-neg53.5%

      \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \color{blue}{\left(-\left(-z\right)\right)}\right)} + x \]
    6. mul-1-neg53.5%

      \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \left(y + \left(-\color{blue}{-1 \cdot z}\right)\right)} + x \]
    7. sub-neg53.5%

      \[\leadsto \frac{\sin \left(y - -1 \cdot z\right)}{\cos \color{blue}{\left(y - -1 \cdot z\right)}} + x \]
  7. Simplified53.5%

    \[\leadsto \color{blue}{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + x} \]
  8. Step-by-step derivation
    1. *-un-lft-identity53.5%

      \[\leadsto \color{blue}{1 \cdot \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)}} + x \]
    2. quot-tan53.5%

      \[\leadsto 1 \cdot \color{blue}{\tan \left(z + y\right)} + x \]
  9. Applied egg-rr53.5%

    \[\leadsto \color{blue}{1 \cdot \tan \left(z + y\right)} + x \]
  10. Step-by-step derivation
    1. *-lft-identity53.5%

      \[\leadsto \color{blue}{\tan \left(z + y\right)} + x \]
  11. Simplified53.5%

    \[\leadsto \color{blue}{\tan \left(z + y\right)} + x \]
  12. Final simplification53.5%

    \[\leadsto x + \tan \left(y + z\right) \]
  13. Add Preprocessing

Alternative 10: 32.0% accurate, 207.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z a) :precision binary64 x)
double code(double x, double y, double z, double a) {
	return x;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x
end function
public static double code(double x, double y, double z, double a) {
	return x;
}
def code(x, y, z, a):
	return x
function code(x, y, z, a)
	return x
end
function tmp = code(x, y, z, a)
	tmp = x;
end
code[x_, y_, z_, a_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 80.9%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 31.6%

    \[\leadsto \color{blue}{x} \]
  4. Add Preprocessing

Alternative 11: 3.5% accurate, 207.0× speedup?

\[\begin{array}{l} \\ a \end{array} \]
(FPCore (x y z a) :precision binary64 a)
double code(double x, double y, double z, double a) {
	return a;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = a
end function
public static double code(double x, double y, double z, double a) {
	return a;
}
def code(x, y, z, a):
	return a
function code(x, y, z, a)
	return a
end
function tmp = code(x, y, z, a)
	tmp = a;
end
code[x_, y_, z_, a_] := a
\begin{array}{l}

\\
a
\end{array}
Derivation
  1. Initial program 80.9%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0 44.2%

    \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a}\right) \]
  4. Taylor expanded in a around inf 3.6%

    \[\leadsto \color{blue}{-1 \cdot a} \]
  5. Step-by-step derivation
    1. neg-mul-13.6%

      \[\leadsto \color{blue}{-a} \]
  6. Simplified3.6%

    \[\leadsto \color{blue}{-a} \]
  7. Step-by-step derivation
    1. add-sqr-sqrt2.6%

      \[\leadsto \color{blue}{\sqrt{-a} \cdot \sqrt{-a}} \]
    2. sqrt-unprod5.1%

      \[\leadsto \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}} \]
    3. sqr-neg5.1%

      \[\leadsto \sqrt{\color{blue}{a \cdot a}} \]
    4. sqrt-unprod2.7%

      \[\leadsto \color{blue}{\sqrt{a} \cdot \sqrt{a}} \]
    5. add-sqr-sqrt3.7%

      \[\leadsto \color{blue}{a} \]
    6. *-un-lft-identity3.7%

      \[\leadsto \color{blue}{1 \cdot a} \]
  8. Applied egg-rr3.7%

    \[\leadsto \color{blue}{1 \cdot a} \]
  9. Step-by-step derivation
    1. *-lft-identity3.7%

      \[\leadsto \color{blue}{a} \]
  10. Simplified3.7%

    \[\leadsto \color{blue}{a} \]
  11. Add Preprocessing

Reproduce

?
herbie shell --seed 2024146 
(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))))