tan-example (used to crash)

Percentage Accurate: 80.0% → 99.7%
Time: 17.3s
Alternatives: 10
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 10 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: 80.0% 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.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan z \cdot \tan y\\ t_1 := 1 - t\_0\\ t_2 := \frac{\tan y}{t\_1}\\ t_3 := \frac{\tan z}{t\_1}\\ t_4 := -1 + t\_0\\ x - \left(\frac{\frac{\tan y}{t\_4} \cdot t\_2 - \frac{\tan z}{t\_4} \cdot t\_3}{t\_2 - t\_3} + \tan a\right) \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* (tan z) (tan y)))
        (t_1 (- 1.0 t_0))
        (t_2 (/ (tan y) t_1))
        (t_3 (/ (tan z) t_1))
        (t_4 (+ -1.0 t_0)))
   (-
    x
    (+
     (/ (- (* (/ (tan y) t_4) t_2) (* (/ (tan z) t_4) t_3)) (- t_2 t_3))
     (tan a)))))
double code(double x, double y, double z, double a) {
	double t_0 = tan(z) * tan(y);
	double t_1 = 1.0 - t_0;
	double t_2 = tan(y) / t_1;
	double t_3 = tan(z) / t_1;
	double t_4 = -1.0 + t_0;
	return x - (((((tan(y) / t_4) * t_2) - ((tan(z) / t_4) * t_3)) / (t_2 - t_3)) + 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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    t_0 = tan(z) * tan(y)
    t_1 = 1.0d0 - t_0
    t_2 = tan(y) / t_1
    t_3 = tan(z) / t_1
    t_4 = (-1.0d0) + t_0
    code = x - (((((tan(y) / t_4) * t_2) - ((tan(z) / t_4) * t_3)) / (t_2 - t_3)) + tan(a))
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = Math.tan(z) * Math.tan(y);
	double t_1 = 1.0 - t_0;
	double t_2 = Math.tan(y) / t_1;
	double t_3 = Math.tan(z) / t_1;
	double t_4 = -1.0 + t_0;
	return x - (((((Math.tan(y) / t_4) * t_2) - ((Math.tan(z) / t_4) * t_3)) / (t_2 - t_3)) + Math.tan(a));
}
def code(x, y, z, a):
	t_0 = math.tan(z) * math.tan(y)
	t_1 = 1.0 - t_0
	t_2 = math.tan(y) / t_1
	t_3 = math.tan(z) / t_1
	t_4 = -1.0 + t_0
	return x - (((((math.tan(y) / t_4) * t_2) - ((math.tan(z) / t_4) * t_3)) / (t_2 - t_3)) + math.tan(a))
function code(x, y, z, a)
	t_0 = Float64(tan(z) * tan(y))
	t_1 = Float64(1.0 - t_0)
	t_2 = Float64(tan(y) / t_1)
	t_3 = Float64(tan(z) / t_1)
	t_4 = Float64(-1.0 + t_0)
	return Float64(x - Float64(Float64(Float64(Float64(Float64(tan(y) / t_4) * t_2) - Float64(Float64(tan(z) / t_4) * t_3)) / Float64(t_2 - t_3)) + tan(a)))
end
function tmp = code(x, y, z, a)
	t_0 = tan(z) * tan(y);
	t_1 = 1.0 - t_0;
	t_2 = tan(y) / t_1;
	t_3 = tan(z) / t_1;
	t_4 = -1.0 + t_0;
	tmp = x - (((((tan(y) / t_4) * t_2) - ((tan(z) / t_4) * t_3)) / (t_2 - t_3)) + tan(a));
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Tan[y], $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(N[Tan[z], $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$4 = N[(-1.0 + t$95$0), $MachinePrecision]}, N[(x - N[(N[(N[(N[(N[(N[Tan[y], $MachinePrecision] / t$95$4), $MachinePrecision] * t$95$2), $MachinePrecision] - N[(N[(N[Tan[z], $MachinePrecision] / t$95$4), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision] / N[(t$95$2 - t$95$3), $MachinePrecision]), $MachinePrecision] + N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan z \cdot \tan y\\
t_1 := 1 - t\_0\\
t_2 := \frac{\tan y}{t\_1}\\
t_3 := \frac{\tan z}{t\_1}\\
t_4 := -1 + t\_0\\
x - \left(\frac{\frac{\tan y}{t\_4} \cdot t\_2 - \frac{\tan z}{t\_4} \cdot t\_3}{t\_2 - t\_3} + \tan a\right)
\end{array}
\end{array}
Derivation
  1. Initial program 79.0%

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

      \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
    2. lift-+.f64N/A

      \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
    3. tan-sumN/A

      \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
    4. div-addN/A

      \[\leadsto x + \left(\color{blue}{\left(\frac{\tan y}{1 - \tan y \cdot \tan z} + \frac{\tan z}{1 - \tan y \cdot \tan z}\right)} - \tan a\right) \]
    5. flip-+N/A

      \[\leadsto x + \left(\color{blue}{\frac{\frac{\tan y}{1 - \tan y \cdot \tan z} \cdot \frac{\tan y}{1 - \tan y \cdot \tan z} - \frac{\tan z}{1 - \tan y \cdot \tan z} \cdot \frac{\tan z}{1 - \tan y \cdot \tan z}}{\frac{\tan y}{1 - \tan y \cdot \tan z} - \frac{\tan z}{1 - \tan y \cdot \tan z}}} - \tan a\right) \]
    6. lower-/.f64N/A

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

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

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

Alternative 2: 99.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(-\tan z, \tan y, 1\right)\\ x + \left(\frac{\mathsf{fma}\left(t\_0, \tan z, t\_0 \cdot \tan y\right)}{{t\_0}^{2}} - \tan a\right) \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (fma (- (tan z)) (tan y) 1.0)))
   (+ x (- (/ (fma t_0 (tan z) (* t_0 (tan y))) (pow t_0 2.0)) (tan a)))))
double code(double x, double y, double z, double a) {
	double t_0 = fma(-tan(z), tan(y), 1.0);
	return x + ((fma(t_0, tan(z), (t_0 * tan(y))) / pow(t_0, 2.0)) - tan(a));
}
function code(x, y, z, a)
	t_0 = fma(Float64(-tan(z)), tan(y), 1.0)
	return Float64(x + Float64(Float64(fma(t_0, tan(z), Float64(t_0 * tan(y))) / (t_0 ^ 2.0)) - tan(a)))
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[((-N[Tan[z], $MachinePrecision]) * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision]}, N[(x + N[(N[(N[(t$95$0 * N[Tan[z], $MachinePrecision] + N[(t$95$0 * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-\tan z, \tan y, 1\right)\\
x + \left(\frac{\mathsf{fma}\left(t\_0, \tan z, t\_0 \cdot \tan y\right)}{{t\_0}^{2}} - \tan a\right)
\end{array}
\end{array}
Derivation
  1. Initial program 79.0%

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

      \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
    2. lift-+.f64N/A

      \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
    3. tan-sumN/A

      \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
    4. div-addN/A

      \[\leadsto x + \left(\color{blue}{\left(\frac{\tan y}{1 - \tan y \cdot \tan z} + \frac{\tan z}{1 - \tan y \cdot \tan z}\right)} - \tan a\right) \]
    5. flip-+N/A

      \[\leadsto x + \left(\color{blue}{\frac{\frac{\tan y}{1 - \tan y \cdot \tan z} \cdot \frac{\tan y}{1 - \tan y \cdot \tan z} - \frac{\tan z}{1 - \tan y \cdot \tan z} \cdot \frac{\tan z}{1 - \tan y \cdot \tan z}}{\frac{\tan y}{1 - \tan y \cdot \tan z} - \frac{\tan z}{1 - \tan y \cdot \tan z}}} - \tan a\right) \]
    6. lower-/.f64N/A

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

    \[\leadsto x + \left(\color{blue}{\frac{\frac{\tan y}{1 - \tan z \cdot \tan y} \cdot \frac{\tan y}{1 - \tan z \cdot \tan y} - \frac{\tan z}{1 - \tan z \cdot \tan y} \cdot \frac{\tan z}{1 - \tan z \cdot \tan y}}{\frac{\tan y}{1 - \tan z \cdot \tan y} - \frac{\tan z}{1 - \tan z \cdot \tan y}}} - \tan a\right) \]
  5. Step-by-step derivation
    1. lift-/.f64N/A

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

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

Alternative 3: 88.8% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;\tan a \leq 10^{-12}:\\
\;\;\;\;x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \mathsf{fma}\left(a \cdot a, 0.3333333333333333, 1\right) \cdot a\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} - \frac{\sin a}{\cos a}}{x}, x, x\right)\\


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

    1. Initial program 74.9%

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

    if -0.050000000000000003 < (tan.f64 a) < 9.9999999999999998e-13

    1. Initial program 82.8%

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

        \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
      2. lift-+.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
      3. tan-sumN/A

        \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
      4. lower-/.f64N/A

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

        \[\leadsto x + \left(\frac{\color{blue}{\tan z + \tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
      6. lower-+.f64N/A

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

        \[\leadsto x + \left(\frac{\color{blue}{\tan z} + \tan y}{1 - \tan y \cdot \tan z} - \tan a\right) \]
      8. lower-tan.f64N/A

        \[\leadsto x + \left(\frac{\tan z + \color{blue}{\tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
      9. lower--.f64N/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{\color{blue}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
      10. *-commutativeN/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
      11. lower-*.f64N/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
      12. lower-tan.f64N/A

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

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

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

      \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\left(1 + \frac{1}{3} \cdot {a}^{2}\right) \cdot a}\right) \]
      2. lower-*.f64N/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\left(1 + \frac{1}{3} \cdot {a}^{2}\right) \cdot a}\right) \]
      3. +-commutativeN/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)} \cdot a\right) \]
      4. *-commutativeN/A

        \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \left(\color{blue}{{a}^{2} \cdot \frac{1}{3}} + 1\right) \cdot a\right) \]
      5. lower-fma.f64N/A

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

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

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

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

    if 9.9999999999999998e-13 < (tan.f64 a)

    1. Initial program 76.8%

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

      \[\leadsto \color{blue}{x \cdot \left(\left(1 + \frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)}\right) - \frac{\sin a}{x \cdot \cos a}\right)} \]
    4. Step-by-step derivation
      1. associate--l+N/A

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right)\right)} \]
      2. +-commutativeN/A

        \[\leadsto x \cdot \color{blue}{\left(\left(\frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right) + 1\right)} \]
      3. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\left(\frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right) \cdot x + 1 \cdot x} \]
      4. *-lft-identityN/A

        \[\leadsto \left(\frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right) \cdot x + \color{blue}{x} \]
      5. lower-fma.f64N/A

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

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

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

Alternative 4: 88.9% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.0002:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\

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

\mathbf{else}:\\
\;\;\;\;x + \left(t\_0 - \frac{\sin a}{\cos a}\right)\\


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

    1. Initial program 75.5%

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

    if -2.0000000000000001e-4 < (tan.f64 a) < 0.050000000000000003

    1. Initial program 81.3%

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

      \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
      2. lower-+.f64N/A

        \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} + x \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\color{blue}{\sin \left(y + z\right)}}{\cos \left(y + z\right)} + x \]
      5. +-commutativeN/A

        \[\leadsto \frac{\sin \color{blue}{\left(z + y\right)}}{\cos \left(y + z\right)} + x \]
      6. lower-+.f64N/A

        \[\leadsto \frac{\sin \color{blue}{\left(z + y\right)}}{\cos \left(y + z\right)} + x \]
      7. lower-cos.f64N/A

        \[\leadsto \frac{\sin \left(z + y\right)}{\color{blue}{\cos \left(y + z\right)}} + x \]
      8. +-commutativeN/A

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)}} + x \]
      9. lower-+.f6481.1

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)}} + x \]
    5. Applied rewrites81.1%

      \[\leadsto \color{blue}{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + x} \]
    6. Taylor expanded in x around inf

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

        \[\leadsto \mathsf{fma}\left(\frac{\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x}, \color{blue}{x}, x\right) \]
      2. Step-by-step derivation
        1. Applied rewrites98.0%

          \[\leadsto \mathsf{fma}\left(\frac{\tan y + \tan z}{\mathsf{fma}\left(-\tan z, \tan y, 1\right) \cdot x}, x, x\right) \]

        if 0.050000000000000003 < (tan.f64 a)

        1. Initial program 78.8%

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

            \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\tan a}\right) \]
          2. tan-quotN/A

            \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
          3. lower-/.f64N/A

            \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
          4. lower-sin.f64N/A

            \[\leadsto x + \left(\tan \left(y + z\right) - \frac{\color{blue}{\sin a}}{\cos a}\right) \]
          5. lower-cos.f6478.8

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

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

      Alternative 5: 99.7% accurate, 0.3× speedup?

      \[\begin{array}{l} \\ x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \frac{\sin a}{\cos a}\right) \end{array} \]
      (FPCore (x y z a)
       :precision binary64
       (-
        x
        (+
         (/ (+ (tan z) (tan y)) (+ -1.0 (* (tan z) (tan y))))
         (/ (sin a) (cos a)))))
      double code(double x, double y, double z, double a) {
      	return x - (((tan(z) + tan(y)) / (-1.0 + (tan(z) * tan(y)))) + (sin(a) / cos(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(z) + tan(y)) / ((-1.0d0) + (tan(z) * tan(y)))) + (sin(a) / cos(a)))
      end function
      
      public static double code(double x, double y, double z, double a) {
      	return x - (((Math.tan(z) + Math.tan(y)) / (-1.0 + (Math.tan(z) * Math.tan(y)))) + (Math.sin(a) / Math.cos(a)));
      }
      
      def code(x, y, z, a):
      	return x - (((math.tan(z) + math.tan(y)) / (-1.0 + (math.tan(z) * math.tan(y)))) + (math.sin(a) / math.cos(a)))
      
      function code(x, y, z, a)
      	return Float64(x - Float64(Float64(Float64(tan(z) + tan(y)) / Float64(-1.0 + Float64(tan(z) * tan(y)))) + Float64(sin(a) / cos(a))))
      end
      
      function tmp = code(x, y, z, a)
      	tmp = x - (((tan(z) + tan(y)) / (-1.0 + (tan(z) * tan(y)))) + (sin(a) / cos(a)));
      end
      
      code[x_, y_, z_, a_] := N[(x - N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[(-1.0 + N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] / N[Cos[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \frac{\sin a}{\cos a}\right)
      \end{array}
      
      Derivation
      1. Initial program 79.0%

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

          \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
        2. lift-+.f64N/A

          \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
        3. tan-sumN/A

          \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
        4. lower-/.f64N/A

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

          \[\leadsto x + \left(\frac{\color{blue}{\tan z + \tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
        6. lower-+.f64N/A

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

          \[\leadsto x + \left(\frac{\color{blue}{\tan z} + \tan y}{1 - \tan y \cdot \tan z} - \tan a\right) \]
        8. lower-tan.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \color{blue}{\tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
        9. lower--.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{\color{blue}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
        10. *-commutativeN/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
        11. lower-*.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
        12. lower-tan.f64N/A

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

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

        \[\leadsto x + \left(\color{blue}{\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y}} - \tan a\right) \]
      5. Step-by-step derivation
        1. lift-tan.f64N/A

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

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
        3. lift-cos.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \frac{\sin a}{\color{blue}{\cos a}}\right) \]
        4. lower-/.f64N/A

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

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

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

        \[\leadsto x - \left(\frac{\tan z + \tan y}{-1 + \tan z \cdot \tan y} + \frac{\sin a}{\cos a}\right) \]
      8. Add Preprocessing

      Alternative 6: 99.7% accurate, 0.4× speedup?

      \[\begin{array}{l} \\ x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \tan a\right) \end{array} \]
      (FPCore (x y z a)
       :precision binary64
       (+ x (- (/ (+ (tan z) (tan y)) (- 1.0 (* (tan z) (tan y)))) (tan a))))
      double code(double x, double y, double z, double a) {
      	return x + (((tan(z) + tan(y)) / (1.0 - (tan(z) * tan(y)))) - 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(z) + tan(y)) / (1.0d0 - (tan(z) * tan(y)))) - tan(a))
      end function
      
      public static double code(double x, double y, double z, double a) {
      	return x + (((Math.tan(z) + Math.tan(y)) / (1.0 - (Math.tan(z) * Math.tan(y)))) - Math.tan(a));
      }
      
      def code(x, y, z, a):
      	return x + (((math.tan(z) + math.tan(y)) / (1.0 - (math.tan(z) * math.tan(y)))) - math.tan(a))
      
      function code(x, y, z, a)
      	return Float64(x + Float64(Float64(Float64(tan(z) + tan(y)) / Float64(1.0 - Float64(tan(z) * tan(y)))) - tan(a)))
      end
      
      function tmp = code(x, y, z, a)
      	tmp = x + (((tan(z) + tan(y)) / (1.0 - (tan(z) * tan(y)))) - tan(a));
      end
      
      code[x_, y_, z_, a_] := N[(x + N[(N[(N[(N[Tan[z], $MachinePrecision] + N[Tan[y], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[z], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \tan a\right)
      \end{array}
      
      Derivation
      1. Initial program 79.0%

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

          \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
        2. lift-+.f64N/A

          \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
        3. tan-sumN/A

          \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
        4. lower-/.f64N/A

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

          \[\leadsto x + \left(\frac{\color{blue}{\tan z + \tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
        6. lower-+.f64N/A

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

          \[\leadsto x + \left(\frac{\color{blue}{\tan z} + \tan y}{1 - \tan y \cdot \tan z} - \tan a\right) \]
        8. lower-tan.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \color{blue}{\tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
        9. lower--.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{\color{blue}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
        10. *-commutativeN/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
        11. lower-*.f64N/A

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
        12. lower-tan.f64N/A

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

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

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

      Alternative 7: 89.8% accurate, 0.5× speedup?

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

        1. Initial program 74.5%

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

        if -0.0045999999999999999 < a < 0.0071999999999999998

        1. Initial program 82.8%

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

            \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
          2. lift-+.f64N/A

            \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
          3. tan-sumN/A

            \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
          4. lower-/.f64N/A

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

            \[\leadsto x + \left(\frac{\color{blue}{\tan z + \tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
          6. lower-+.f64N/A

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

            \[\leadsto x + \left(\frac{\color{blue}{\tan z} + \tan y}{1 - \tan y \cdot \tan z} - \tan a\right) \]
          8. lower-tan.f64N/A

            \[\leadsto x + \left(\frac{\tan z + \color{blue}{\tan y}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
          9. lower--.f64N/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{\color{blue}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
          10. *-commutativeN/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
          11. lower-*.f64N/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \color{blue}{\tan z \cdot \tan y}} - \tan a\right) \]
          12. lower-tan.f64N/A

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

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

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

          \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
        6. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\left(1 + \frac{1}{3} \cdot {a}^{2}\right) \cdot a}\right) \]
          2. lower-*.f64N/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\left(1 + \frac{1}{3} \cdot {a}^{2}\right) \cdot a}\right) \]
          3. +-commutativeN/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)} \cdot a\right) \]
          4. *-commutativeN/A

            \[\leadsto x + \left(\frac{\tan z + \tan y}{1 - \tan z \cdot \tan y} - \left(\color{blue}{{a}^{2} \cdot \frac{1}{3}} + 1\right) \cdot a\right) \]
          5. lower-fma.f64N/A

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

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

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

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

        if 0.0071999999999999998 < a

        1. Initial program 76.9%

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

            \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\tan a}\right) \]
          2. tan-quotN/A

            \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
          3. lower-/.f64N/A

            \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\frac{\sin a}{\cos a}}\right) \]
          4. lower-sin.f64N/A

            \[\leadsto x + \left(\tan \left(y + z\right) - \frac{\color{blue}{\sin a}}{\cos a}\right) \]
          5. lower-cos.f6476.9

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

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

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

      Alternative 8: 80.0% 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 79.0%

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

      Alternative 9: 50.7% accurate, 1.7× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(\frac{\tan \left(y + z\right)}{x}, x, x\right) \end{array} \]
      (FPCore (x y z a) :precision binary64 (fma (/ (tan (+ y z)) x) x x))
      double code(double x, double y, double z, double a) {
      	return fma((tan((y + z)) / x), x, x);
      }
      
      function code(x, y, z, a)
      	return fma(Float64(tan(Float64(y + z)) / x), x, x)
      end
      
      code[x_, y_, z_, a_] := N[(N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * x + x), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(\frac{\tan \left(y + z\right)}{x}, x, x\right)
      \end{array}
      
      Derivation
      1. Initial program 79.0%

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

        \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
        2. lower-+.f64N/A

          \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
        3. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} + x \]
        4. lower-sin.f64N/A

          \[\leadsto \frac{\color{blue}{\sin \left(y + z\right)}}{\cos \left(y + z\right)} + x \]
        5. +-commutativeN/A

          \[\leadsto \frac{\sin \color{blue}{\left(z + y\right)}}{\cos \left(y + z\right)} + x \]
        6. lower-+.f64N/A

          \[\leadsto \frac{\sin \color{blue}{\left(z + y\right)}}{\cos \left(y + z\right)} + x \]
        7. lower-cos.f64N/A

          \[\leadsto \frac{\sin \left(z + y\right)}{\color{blue}{\cos \left(y + z\right)}} + x \]
        8. +-commutativeN/A

          \[\leadsto \frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)}} + x \]
        9. lower-+.f6450.6

          \[\leadsto \frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)}} + x \]
      5. Applied rewrites50.6%

        \[\leadsto \color{blue}{\frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + x} \]
      6. Taylor expanded in x around inf

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

          \[\leadsto \mathsf{fma}\left(\frac{\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x}, \color{blue}{x}, x\right) \]
        2. Step-by-step derivation
          1. Applied rewrites50.6%

            \[\leadsto \mathsf{fma}\left(\frac{\tan \left(y + z\right)}{x}, x, x\right) \]
          2. Add Preprocessing

          Alternative 10: 50.7% accurate, 2.0× speedup?

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

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

            \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

              \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
            2. lower-+.f64N/A

              \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} + x} \]
            3. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} + x \]
            4. lower-sin.f64N/A

              \[\leadsto \frac{\color{blue}{\sin \left(y + z\right)}}{\cos \left(y + z\right)} + x \]
            5. +-commutativeN/A

              \[\leadsto \frac{\sin \color{blue}{\left(z + y\right)}}{\cos \left(y + z\right)} + x \]
            6. lower-+.f64N/A

              \[\leadsto \frac{\sin \color{blue}{\left(z + y\right)}}{\cos \left(y + z\right)} + x \]
            7. lower-cos.f64N/A

              \[\leadsto \frac{\sin \left(z + y\right)}{\color{blue}{\cos \left(y + z\right)}} + x \]
            8. +-commutativeN/A

              \[\leadsto \frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)}} + x \]
            9. lower-+.f6450.6

              \[\leadsto \frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)}} + x \]
          5. Applied rewrites50.6%

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

              \[\leadsto \tan \left(z + y\right) + \color{blue}{x} \]
            2. Add Preprocessing

            Reproduce

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