tan-example (used to crash)

Percentage Accurate: 79.3% → 99.7%
Time: 26.7s
Alternatives: 12
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 12 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.3% 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.3× speedup?

\[\begin{array}{l} \\ x + \left(\frac{\tan y + \tan z}{1 + \left(-1 - \mathsf{fma}\left(\tan y, \tan z, -1\right)\right)} - \tan a\right) \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (+
  x
  (-
   (/ (+ (tan y) (tan z)) (+ 1.0 (- -1.0 (fma (tan y) (tan z) -1.0))))
   (tan a))))
double code(double x, double y, double z, double a) {
	return x + (((tan(y) + tan(z)) / (1.0 + (-1.0 - fma(tan(y), tan(z), -1.0)))) - tan(a));
}
function code(x, y, z, a)
	return Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 + Float64(-1.0 - fma(tan(y), tan(z), -1.0)))) - 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[(-1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[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. Applied egg-rr99.8%

    \[\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/99.8%

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

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

    \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
  6. Step-by-step derivation
    1. expm1-log1p-u95.1%

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan y \cdot \tan z\right)\right)}} - \tan a\right) \]
    2. expm1-udef95.0%

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan y \cdot \tan z\right)} - 1\right)}} - \tan a\right) \]
    3. log1p-udef95.0%

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \left(e^{\color{blue}{\log \left(1 + \tan y \cdot \tan z\right)}} - 1\right)} - \tan a\right) \]
    4. add-exp-log99.7%

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

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

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

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

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

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

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

Alternative 2: 88.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\tan a \leq -0.02 \lor \neg \left(\tan a \leq 10^{-7}\right):\\ \;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan y + \tan z}{-\mathsf{fma}\left(\tan y, \tan z, -1\right)} + \left(x - a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (or (<= (tan a) -0.02) (not (<= (tan a) 1e-7)))
   (+ x (- (/ 1.0 (/ (cos (+ y z)) (sin (+ y z)))) (tan a)))
   (+ (/ (+ (tan y) (tan z)) (- (fma (tan y) (tan z) -1.0))) (- x a))))
double code(double x, double y, double z, double a) {
	double tmp;
	if ((tan(a) <= -0.02) || !(tan(a) <= 1e-7)) {
		tmp = x + ((1.0 / (cos((y + z)) / sin((y + z)))) - tan(a));
	} else {
		tmp = ((tan(y) + tan(z)) / -fma(tan(y), tan(z), -1.0)) + (x - a);
	}
	return tmp;
}
function code(x, y, z, a)
	tmp = 0.0
	if ((tan(a) <= -0.02) || !(tan(a) <= 1e-7))
		tmp = Float64(x + Float64(Float64(1.0 / Float64(cos(Float64(y + z)) / sin(Float64(y + z)))) - tan(a)));
	else
		tmp = Float64(Float64(Float64(tan(y) + tan(z)) / Float64(-fma(tan(y), tan(z), -1.0))) + Float64(x - a));
	end
	return tmp
end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.02], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 1e-7]], $MachinePrecision]], N[(x + N[(N[(1.0 / N[(N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision] / N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / (-N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision] + -1.0), $MachinePrecision])), $MachinePrecision] + N[(x - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.02 \lor \neg \left(\tan a \leq 10^{-7}\right):\\
\;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (tan.f64 a) < -0.0200000000000000004 or 9.9999999999999995e-8 < (tan.f64 a)

    1. Initial program 81.3%

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

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

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

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

    if -0.0200000000000000004 < (tan.f64 a) < 9.9999999999999995e-8

    1. Initial program 77.8%

      \[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. Applied egg-rr99.8%

      \[\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/99.8%

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

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

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

        \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan y \cdot \tan z\right)\right)}} - \tan a\right) \]
      2. expm1-udef93.5%

        \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\left(e^{\mathsf{log1p}\left(\tan y \cdot \tan z\right)} - 1\right)}} - \tan a\right) \]
      3. log1p-udef93.5%

        \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \left(e^{\color{blue}{\log \left(1 + \tan y \cdot \tan z\right)}} - 1\right)} - \tan a\right) \]
      4. add-exp-log99.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\frac{\tan y + \tan z}{0 - \mathsf{fma}\left(\tan y, \tan z, -1\right)} + x\right)} - \tan a \]
      2. associate--l+99.8%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.02 \lor \neg \left(\tan a \leq 10^{-7}\right):\\ \;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\tan y + \tan z}{-\mathsf{fma}\left(\tan y, \tan z, -1\right)} + \left(x - a\right)\\ \end{array} \]

Alternative 3: 88.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\tan a \leq -0.06 \lor \neg \left(\tan a \leq 10^{-7}\right):\\ \;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (or (<= (tan a) -0.06) (not (<= (tan a) 1e-7)))
   (+ x (- (/ 1.0 (/ (cos (+ y z)) (sin (+ y z)))) (tan a)))
   (+ x (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))))))
double code(double x, double y, double z, double a) {
	double tmp;
	if ((tan(a) <= -0.06) || !(tan(a) <= 1e-7)) {
		tmp = x + ((1.0 / (cos((y + z)) / sin((y + z)))) - tan(a));
	} else {
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(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 ((tan(a) <= (-0.06d0)) .or. (.not. (tan(a) <= 1d-7))) then
        tmp = x + ((1.0d0 / (cos((y + z)) / sin((y + z)))) - tan(a))
    else
        tmp = x + ((tan(y) + tan(z)) / (1.0d0 - (tan(y) * tan(z))))
    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.06) || !(Math.tan(a) <= 1e-7)) {
		tmp = x + ((1.0 / (Math.cos((y + z)) / Math.sin((y + z)))) - Math.tan(a));
	} else {
		tmp = x + ((Math.tan(y) + Math.tan(z)) / (1.0 - (Math.tan(y) * Math.tan(z))));
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if (math.tan(a) <= -0.06) or not (math.tan(a) <= 1e-7):
		tmp = x + ((1.0 / (math.cos((y + z)) / math.sin((y + z)))) - math.tan(a))
	else:
		tmp = x + ((math.tan(y) + math.tan(z)) / (1.0 - (math.tan(y) * math.tan(z))))
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if ((tan(a) <= -0.06) || !(tan(a) <= 1e-7))
		tmp = Float64(x + Float64(Float64(1.0 / Float64(cos(Float64(y + z)) / sin(Float64(y + z)))) - tan(a)));
	else
		tmp = Float64(x + Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if ((tan(a) <= -0.06) || ~((tan(a) <= 1e-7)))
		tmp = x + ((1.0 / (cos((y + z)) / sin((y + z)))) - tan(a));
	else
		tmp = x + ((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z))));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.06], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 1e-7]], $MachinePrecision]], N[(x + N[(N[(1.0 / N[(N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision] / N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.06 \lor \neg \left(\tan a \leq 10^{-7}\right):\\
\;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\

\mathbf{else}:\\
\;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (tan.f64 a) < -0.059999999999999998 or 9.9999999999999995e-8 < (tan.f64 a)

    1. Initial program 82.8%

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

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

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

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

    if -0.059999999999999998 < (tan.f64 a) < 9.9999999999999995e-8

    1. Initial program 76.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x + \frac{\color{blue}{\tan y + \tan z}}{1 - \tan z \cdot \tan y} \]
    12. Applied egg-rr97.0%

      \[\leadsto x + \color{blue}{\frac{\tan y + \tan z}{1 - \tan z \cdot \tan y}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.06 \lor \neg \left(\tan a \leq 10^{-7}\right):\\ \;\;\;\;x + \left(\frac{1}{\frac{\cos \left(y + z\right)}{\sin \left(y + z\right)}} - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \end{array} \]

Alternative 4: 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 79.5%

    \[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. Applied egg-rr99.8%

    \[\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/99.8%

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

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

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

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

Alternative 5: 60.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\tan a \leq -0.02 \lor \neg \left(\tan a \leq 10^{-12}\right):\\ \;\;\;\;x + \left(\sin z - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(y + z\right) + \left(x - a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (or (<= (tan a) -0.02) (not (<= (tan a) 1e-12)))
   (+ x (- (sin z) (tan a)))
   (+ (tan (+ y z)) (- x a))))
double code(double x, double y, double z, double a) {
	double tmp;
	if ((tan(a) <= -0.02) || !(tan(a) <= 1e-12)) {
		tmp = x + (sin(z) - tan(a));
	} else {
		tmp = tan((y + z)) + (x - 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.02d0)) .or. (.not. (tan(a) <= 1d-12))) then
        tmp = x + (sin(z) - tan(a))
    else
        tmp = tan((y + z)) + (x - 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.02) || !(Math.tan(a) <= 1e-12)) {
		tmp = x + (Math.sin(z) - Math.tan(a));
	} else {
		tmp = Math.tan((y + z)) + (x - a);
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if (math.tan(a) <= -0.02) or not (math.tan(a) <= 1e-12):
		tmp = x + (math.sin(z) - math.tan(a))
	else:
		tmp = math.tan((y + z)) + (x - a)
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if ((tan(a) <= -0.02) || !(tan(a) <= 1e-12))
		tmp = Float64(x + Float64(sin(z) - tan(a)));
	else
		tmp = Float64(tan(Float64(y + z)) + Float64(x - a));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if ((tan(a) <= -0.02) || ~((tan(a) <= 1e-12)))
		tmp = x + (sin(z) - tan(a));
	else
		tmp = tan((y + z)) + (x - a);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.02], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 1e-12]], $MachinePrecision]], N[(x + N[(N[Sin[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] + N[(x - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.02 \lor \neg \left(\tan a \leq 10^{-12}\right):\\
\;\;\;\;x + \left(\sin z - \tan a\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (tan.f64 a) < -0.0200000000000000004 or 9.9999999999999998e-13 < (tan.f64 a)

    1. Initial program 81.0%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 78.1%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.02 \lor \neg \left(\tan a \leq 10^{-12}\right):\\ \;\;\;\;x + \left(\sin z - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(y + z\right) + \left(x - a\right)\\ \end{array} \]

Alternative 6: 79.3% accurate, 0.7× speedup?

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

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

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

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

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

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

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

Alternative 7: 60.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y + z \leq 0.05:\\ \;\;\;\;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) 0.05) (+ x (- (tan y) (tan a))) (+ x (tan (+ y z)))))
double code(double x, double y, double z, double a) {
	double tmp;
	if ((y + z) <= 0.05) {
		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) <= 0.05d0) 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) <= 0.05) {
		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) <= 0.05:
		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) <= 0.05)
		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) <= 0.05)
		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], 0.05], 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 0.05:\\
\;\;\;\;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) < 0.050000000000000003

    1. Initial program 85.3%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin y}{\cos y}} - \left(\tan a - x\right) \]
    5. Step-by-step derivation
      1. tan-quot68.2%

        \[\leadsto \color{blue}{\tan y} - \left(\tan a - x\right) \]
      2. associate--r-68.2%

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

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

    if 0.050000000000000003 < (+.f64 y z)

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x + \tan \color{blue}{\left(z + y\right)} \]
    10. Simplified44.4%

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

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

Alternative 8: 64.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 0.028:\\ \;\;\;\;x + \left(\tan y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\sin z}{\cos z}\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (<= z 0.028) (+ x (- (tan y) (tan a))) (+ x (/ (sin z) (cos z)))))
double code(double x, double y, double z, double a) {
	double tmp;
	if (z <= 0.028) {
		tmp = x + (tan(y) - tan(a));
	} else {
		tmp = x + (sin(z) / cos(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 (z <= 0.028d0) then
        tmp = x + (tan(y) - tan(a))
    else
        tmp = x + (sin(z) / cos(z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if (z <= 0.028) {
		tmp = x + (Math.tan(y) - Math.tan(a));
	} else {
		tmp = x + (Math.sin(z) / Math.cos(z));
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if z <= 0.028:
		tmp = x + (math.tan(y) - math.tan(a))
	else:
		tmp = x + (math.sin(z) / math.cos(z))
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if (z <= 0.028)
		tmp = Float64(x + Float64(tan(y) - tan(a)));
	else
		tmp = Float64(x + Float64(sin(z) / cos(z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if (z <= 0.028)
		tmp = x + (tan(y) - tan(a));
	else
		tmp = x + (sin(z) / cos(z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[LessEqual[z, 0.028], N[(x + N[(N[Tan[y], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[z], $MachinePrecision] / N[Cos[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;x + \frac{\sin z}{\cos z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 0.0280000000000000006

    1. Initial program 88.1%

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin y}{\cos y}} - \left(\tan a - x\right) \]
    5. Step-by-step derivation
      1. tan-quot74.1%

        \[\leadsto \color{blue}{\tan y} - \left(\tan a - x\right) \]
      2. associate--r-74.1%

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

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

    if 0.0280000000000000006 < z

    1. Initial program 49.1%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin z}{\cos z} + x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification64.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 0.028:\\ \;\;\;\;x + \left(\tan y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\sin z}{\cos z}\\ \end{array} \]

Alternative 9: 79.3% 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.5%

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

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

Alternative 10: 60.1% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y + z \leq -4 \cdot 10^{-5} \lor \neg \left(y + z \leq 0.05\right):\\ \;\;\;\;x + \tan \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;y - \left(\tan a - x\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (or (<= (+ y z) -4e-5) (not (<= (+ y z) 0.05)))
   (+ x (tan (+ y z)))
   (- y (- (tan a) x))))
double code(double x, double y, double z, double a) {
	double tmp;
	if (((y + z) <= -4e-5) || !((y + z) <= 0.05)) {
		tmp = x + tan((y + z));
	} else {
		tmp = y - (tan(a) - 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 (((y + z) <= (-4d-5)) .or. (.not. ((y + z) <= 0.05d0))) then
        tmp = x + tan((y + z))
    else
        tmp = y - (tan(a) - x)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if (((y + z) <= -4e-5) || !((y + z) <= 0.05)) {
		tmp = x + Math.tan((y + z));
	} else {
		tmp = y - (Math.tan(a) - x);
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if ((y + z) <= -4e-5) or not ((y + z) <= 0.05):
		tmp = x + math.tan((y + z))
	else:
		tmp = y - (math.tan(a) - x)
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if ((Float64(y + z) <= -4e-5) || !(Float64(y + z) <= 0.05))
		tmp = Float64(x + tan(Float64(y + z)));
	else
		tmp = Float64(y - Float64(tan(a) - x));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if (((y + z) <= -4e-5) || ~(((y + z) <= 0.05)))
		tmp = x + tan((y + z));
	else
		tmp = y - (tan(a) - x);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[Or[LessEqual[N[(y + z), $MachinePrecision], -4e-5], N[Not[LessEqual[N[(y + z), $MachinePrecision], 0.05]], $MachinePrecision]], N[(x + N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(y - N[(N[Tan[a], $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y + z \leq -4 \cdot 10^{-5} \lor \neg \left(y + z \leq 0.05\right):\\
\;\;\;\;x + \tan \left(y + z\right)\\

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


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

    1. Initial program 72.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.00000000000000033e-5 < (+.f64 y z) < 0.050000000000000003

    1. Initial program 99.9%

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

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

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

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

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

      \[\leadsto \color{blue}{y} - \left(\tan a - x\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification61.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y + z \leq -4 \cdot 10^{-5} \lor \neg \left(y + z \leq 0.05\right):\\ \;\;\;\;x + \tan \left(y + z\right)\\ \mathbf{else}:\\ \;\;\;\;y - \left(\tan a - x\right)\\ \end{array} \]

Alternative 11: 50.9% 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 79.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 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 79.5%

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

    \[\leadsto \color{blue}{x} \]
  3. Final simplification32.2%

    \[\leadsto x \]

Reproduce

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