tan-example (used to crash)

Percentage Accurate: 79.8% → 99.7%
Time: 33.6s
Alternatives: 8
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 8 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.8% 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.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan y \cdot \tan z\\ x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{{t_0}^{6}}} \cdot \left(1 + t_0\right) - \tan a\right) \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* (tan y) (tan z))))
   (+
    x
    (-
     (* (/ (+ (tan y) (tan z)) (- 1.0 (cbrt (pow t_0 6.0)))) (+ 1.0 t_0))
     (tan a)))))
double code(double x, double y, double z, double a) {
	double t_0 = tan(y) * tan(z);
	return x + ((((tan(y) + tan(z)) / (1.0 - cbrt(pow(t_0, 6.0)))) * (1.0 + t_0)) - tan(a));
}
public static double code(double x, double y, double z, double a) {
	double t_0 = Math.tan(y) * Math.tan(z);
	return x + ((((Math.tan(y) + Math.tan(z)) / (1.0 - Math.cbrt(Math.pow(t_0, 6.0)))) * (1.0 + t_0)) - Math.tan(a));
}
function code(x, y, z, a)
	t_0 = Float64(tan(y) * tan(z))
	return Float64(x + Float64(Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - cbrt((t_0 ^ 6.0)))) * Float64(1.0 + t_0)) - tan(a)))
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[Power[N[Power[t$95$0, 6.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{{t_0}^{6}}} \cdot \left(1 + t_0\right) - \tan a\right)
\end{array}
\end{array}
Derivation
  1. Initial program 80.7%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Step-by-step derivation
    1. add-cube-cbrt80.4%

      \[\leadsto x + \left(\color{blue}{\left(\sqrt[3]{\tan \left(y + z\right)} \cdot \sqrt[3]{\tan \left(y + z\right)}\right) \cdot \sqrt[3]{\tan \left(y + z\right)}} - \tan a\right) \]
    2. pow380.4%

      \[\leadsto x + \left(\color{blue}{{\left(\sqrt[3]{\tan \left(y + z\right)}\right)}^{3}} - \tan a\right) \]
  3. Applied egg-rr80.4%

    \[\leadsto x + \left(\color{blue}{{\left(\sqrt[3]{\tan \left(y + z\right)}\right)}^{3}} - \tan a\right) \]
  4. Step-by-step derivation
    1. rem-cube-cbrt80.7%

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

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

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

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

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

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

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

    \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - {\left(\tan y \cdot \tan z\right)}^{2}} \cdot \left(\tan y \cdot \tan z + 1\right)} - \tan a\right) \]
  6. Step-by-step derivation
    1. add-cbrt-cube99.6%

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\sqrt[3]{\left({\left(\tan y \cdot \tan z\right)}^{2} \cdot {\left(\tan y \cdot \tan z\right)}^{2}\right) \cdot {\left(\tan y \cdot \tan z\right)}^{2}}}} \cdot \left(\tan y \cdot \tan z + 1\right) - \tan a\right) \]
    2. pow399.6%

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{\color{blue}{{\left({\left(\tan y \cdot \tan z\right)}^{2}\right)}^{3}}}} \cdot \left(\tan y \cdot \tan z + 1\right) - \tan a\right) \]
    3. pow-pow99.7%

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{\color{blue}{{\left(\tan y \cdot \tan z\right)}^{\left(2 \cdot 3\right)}}}} \cdot \left(\tan y \cdot \tan z + 1\right) - \tan a\right) \]
    4. metadata-eval99.7%

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

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

    \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \sqrt[3]{{\left(\tan y \cdot \tan z\right)}^{6}}} \cdot \left(1 + \tan y \cdot \tan z\right) - \tan a\right) \]

Alternative 2: 99.7% accurate, 0.3× speedup?

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

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Step-by-step derivation
    1. tan-sum99.6%

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

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

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

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

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

Alternative 3: 99.7% accurate, 0.4× speedup?

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

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

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

      \[\leadsto \color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} + x \]
    2. div-inv56.9%

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

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

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

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

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

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

Alternative 4: 89.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan \left(y + z\right)\\ \mathbf{if}\;a \leq -0.00035:\\ \;\;\;\;\left(x + t_0\right) - \tan a\\ \mathbf{elif}\;a \leq 0.0023:\\ \;\;\;\;\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} + \left(x - a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(t_0 - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (tan (+ y z))))
   (if (<= a -0.00035)
     (- (+ x t_0) (tan a))
     (if (<= a 0.0023)
       (+ (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) (- x a))
       (+ x (- t_0 (tan a)))))))
double code(double x, double y, double z, double a) {
	double t_0 = tan((y + z));
	double tmp;
	if (a <= -0.00035) {
		tmp = (x + t_0) - tan(a);
	} else if (a <= 0.0023) {
		tmp = ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) + (x - a);
	} else {
		tmp = x + (t_0 - 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) :: t_0
    real(8) :: tmp
    t_0 = tan((y + z))
    if (a <= (-0.00035d0)) then
        tmp = (x + t_0) - tan(a)
    else if (a <= 0.0023d0) then
        tmp = ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z)))) + (x - a)
    else
        tmp = x + (t_0 - tan(a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = Math.tan((y + z));
	double tmp;
	if (a <= -0.00035) {
		tmp = (x + t_0) - Math.tan(a);
	} else if (a <= 0.0023) {
		tmp = ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z)))) + (x - a);
	} else {
		tmp = x + (t_0 - Math.tan(a));
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = math.tan((y + z))
	tmp = 0
	if a <= -0.00035:
		tmp = (x + t_0) - math.tan(a)
	elif a <= 0.0023:
		tmp = ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z)))) + (x - a)
	else:
		tmp = x + (t_0 - math.tan(a))
	return tmp
function code(x, y, z, a)
	t_0 = tan(Float64(y + z))
	tmp = 0.0
	if (a <= -0.00035)
		tmp = Float64(Float64(x + t_0) - tan(a));
	elseif (a <= 0.0023)
		tmp = Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) + Float64(x - a));
	else
		tmp = Float64(x + Float64(t_0 - tan(a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = tan((y + z));
	tmp = 0.0;
	if (a <= -0.00035)
		tmp = (x + t_0) - tan(a);
	elseif (a <= 0.0023)
		tmp = ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) + (x - a);
	else
		tmp = x + (t_0 - tan(a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[a, -0.00035], N[(N[(x + t$95$0), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 0.0023], 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[(x - a), $MachinePrecision]), $MachinePrecision], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < -3.49999999999999996e-4

    1. Initial program 83.3%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Step-by-step derivation
      1. associate-+r-83.3%

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

        \[\leadsto \color{blue}{\left(\tan \left(y + z\right) + x\right)} - \tan a \]
    3. Applied egg-rr83.3%

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

    if -3.49999999999999996e-4 < a < 0.0023

    1. Initial program 77.7%

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, -\tan a\right) + x} \]
      2. fma-udef99.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 \]
      3. div-inv99.8%

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

        \[\leadsto \left(\color{blue}{\tan \left(y + z\right)} + \left(-\tan a\right)\right) + x \]
      5. sub-neg77.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \color{blue}{\left(a + -1 \cdot x\right)} \]
    9. Step-by-step derivation
      1. neg-mul-199.8%

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

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

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

    if 0.0023 < a

    1. Initial program 82.8%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification90.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.00035:\\ \;\;\;\;\left(x + \tan \left(y + z\right)\right) - \tan a\\ \mathbf{elif}\;a \leq 0.0023:\\ \;\;\;\;\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} + \left(x - a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\ \end{array} \]

Alternative 5: 89.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan \left(y + z\right)\\ \mathbf{if}\;a \leq -6.8 \cdot 10^{-7}:\\ \;\;\;\;\left(x + t_0\right) - \tan a\\ \mathbf{elif}\;a \leq 1.05 \cdot 10^{-11}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(t_0 - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (tan (+ y z))))
   (if (<= a -6.8e-7)
     (- (+ x t_0) (tan a))
     (if (<= a 1.05e-11)
       (+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))))
       (+ x (- t_0 (tan a)))))))
double code(double x, double y, double z, double a) {
	double t_0 = tan((y + z));
	double tmp;
	if (a <= -6.8e-7) {
		tmp = (x + t_0) - tan(a);
	} else if (a <= 1.05e-11) {
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
	} else {
		tmp = x + (t_0 - 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) :: t_0
    real(8) :: tmp
    t_0 = tan((y + z))
    if (a <= (-6.8d-7)) then
        tmp = (x + t_0) - tan(a)
    else if (a <= 1.05d-11) then
        tmp = x + ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z))))
    else
        tmp = x + (t_0 - tan(a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = Math.tan((y + z));
	double tmp;
	if (a <= -6.8e-7) {
		tmp = (x + t_0) - Math.tan(a);
	} else if (a <= 1.05e-11) {
		tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z))));
	} else {
		tmp = x + (t_0 - Math.tan(a));
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = math.tan((y + z))
	tmp = 0
	if a <= -6.8e-7:
		tmp = (x + t_0) - math.tan(a)
	elif a <= 1.05e-11:
		tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z))))
	else:
		tmp = x + (t_0 - math.tan(a))
	return tmp
function code(x, y, z, a)
	t_0 = tan(Float64(y + z))
	tmp = 0.0
	if (a <= -6.8e-7)
		tmp = Float64(Float64(x + t_0) - tan(a));
	elseif (a <= 1.05e-11)
		tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))));
	else
		tmp = Float64(x + Float64(t_0 - tan(a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = tan((y + z));
	tmp = 0.0;
	if (a <= -6.8e-7)
		tmp = (x + t_0) - tan(a);
	elseif (a <= 1.05e-11)
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
	else
		tmp = x + (t_0 - tan(a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[a, -6.8e-7], N[(N[(x + t$95$0), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 1.05e-11], 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[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < -6.79999999999999948e-7

    1. Initial program 83.3%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Step-by-step derivation
      1. associate-+r-83.3%

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

        \[\leadsto \color{blue}{\left(\tan \left(y + z\right) + x\right)} - \tan a \]
    3. Applied egg-rr83.3%

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

    if -6.79999999999999948e-7 < a < 1.0499999999999999e-11

    1. Initial program 77.9%

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

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

        \[\leadsto \color{blue}{\tan \left(y + z\right) - \left(\tan a - x\right)} \]
    3. Applied egg-rr77.9%

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

      \[\leadsto \tan \left(y + z\right) - \color{blue}{-1 \cdot x} \]
    5. Step-by-step derivation
      1. neg-mul-177.5%

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

      \[\leadsto \tan \left(y + z\right) - \color{blue}{\left(-x\right)} \]
    7. Step-by-step derivation
      1. sub-neg77.5%

        \[\leadsto \color{blue}{\tan \left(y + z\right) + \left(-\left(-x\right)\right)} \]
      2. add-sqr-sqrt0.0%

        \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}\right) \]
      3. sqrt-unprod2.7%

        \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}\right) \]
      4. sqr-neg2.7%

        \[\leadsto \tan \left(y + z\right) + \left(-\sqrt{\color{blue}{x \cdot x}}\right) \]
      5. sqrt-unprod2.7%

        \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right) \]
      6. add-sqr-sqrt2.7%

        \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{x}\right) \]
      7. add-sqr-sqrt0.0%

        \[\leadsto \tan \left(y + z\right) + \color{blue}{\sqrt{-x} \cdot \sqrt{-x}} \]
      8. sqrt-unprod77.5%

        \[\leadsto \tan \left(y + z\right) + \color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
      9. sqr-neg77.5%

        \[\leadsto \tan \left(y + z\right) + \sqrt{\color{blue}{x \cdot x}} \]
      10. sqrt-unprod77.0%

        \[\leadsto \tan \left(y + z\right) + \color{blue}{\sqrt{x} \cdot \sqrt{x}} \]
      11. add-sqr-sqrt77.5%

        \[\leadsto \tan \left(y + z\right) + \color{blue}{x} \]
    8. Applied egg-rr77.5%

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

        \[\leadsto \color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} + x \]
      2. div-inv98.6%

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

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

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

        \[\leadsto \frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} + x \]
    12. Simplified98.6%

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

    if 1.0499999999999999e-11 < a

    1. Initial program 82.3%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -6.8 \cdot 10^{-7}:\\ \;\;\;\;\left(x + \tan \left(y + z\right)\right) - \tan a\\ \mathbf{elif}\;a \leq 1.05 \cdot 10^{-11}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\ \end{array} \]

Alternative 6: 79.8% 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.7%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Final simplification80.7%

    \[\leadsto x + \left(\tan \left(y + z\right) - \tan a\right) \]

Alternative 7: 51.2% 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.7%

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

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

      \[\leadsto \color{blue}{\tan \left(y + z\right) - \left(\tan a - x\right)} \]
  3. Applied egg-rr80.6%

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

    \[\leadsto \tan \left(y + z\right) - \color{blue}{-1 \cdot x} \]
  5. Step-by-step derivation
    1. neg-mul-147.1%

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

    \[\leadsto \tan \left(y + z\right) - \color{blue}{\left(-x\right)} \]
  7. Step-by-step derivation
    1. sub-neg47.1%

      \[\leadsto \color{blue}{\tan \left(y + z\right) + \left(-\left(-x\right)\right)} \]
    2. add-sqr-sqrt0.0%

      \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{\sqrt{-x} \cdot \sqrt{-x}}\right) \]
    3. sqrt-unprod3.1%

      \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}}\right) \]
    4. sqr-neg3.1%

      \[\leadsto \tan \left(y + z\right) + \left(-\sqrt{\color{blue}{x \cdot x}}\right) \]
    5. sqrt-unprod3.1%

      \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right) \]
    6. add-sqr-sqrt3.1%

      \[\leadsto \tan \left(y + z\right) + \left(-\color{blue}{x}\right) \]
    7. add-sqr-sqrt0.0%

      \[\leadsto \tan \left(y + z\right) + \color{blue}{\sqrt{-x} \cdot \sqrt{-x}} \]
    8. sqrt-unprod47.1%

      \[\leadsto \tan \left(y + z\right) + \color{blue}{\sqrt{\left(-x\right) \cdot \left(-x\right)}} \]
    9. sqr-neg47.1%

      \[\leadsto \tan \left(y + z\right) + \sqrt{\color{blue}{x \cdot x}} \]
    10. sqrt-unprod46.9%

      \[\leadsto \tan \left(y + z\right) + \color{blue}{\sqrt{x} \cdot \sqrt{x}} \]
    11. add-sqr-sqrt47.1%

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

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

    \[\leadsto x + \tan \left(y + z\right) \]

Alternative 8: 31.9% 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.7%

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

    \[\leadsto \color{blue}{x} \]
  3. Final simplification29.5%

    \[\leadsto x \]

Reproduce

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