tan-example (used to crash)

Percentage Accurate: 79.7% → 99.7%
Time: 33.8s
Alternatives: 11
Speedup: 1.0×

Specification

?
\[\left(\left(\left(x = 0 \lor 0.5884142 \leq x \land x \leq 505.5909\right) \land \left(-1.796658 \cdot 10^{+308} \leq y \land y \leq -9.425585 \cdot 10^{-310} \lor 1.284938 \cdot 10^{-309} \leq y \land y \leq 1.751224 \cdot 10^{+308}\right)\right) \land \left(-1.776707 \cdot 10^{+308} \leq z \land z \leq -8.599796 \cdot 10^{-310} \lor 3.293145 \cdot 10^{-311} \leq z \land z \leq 1.725154 \cdot 10^{+308}\right)\right) \land \left(-1.796658 \cdot 10^{+308} \leq a \land a \leq -9.425585 \cdot 10^{-310} \lor 1.284938 \cdot 10^{-309} \leq a \land a \leq 1.751224 \cdot 10^{+308}\right)\]
\[\begin{array}{l} \\ x + \left(\tan \left(y + z\right) - \tan a\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
double code(double x, double y, double z, double a) {
	return x + (tan((y + z)) - tan(a));
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + (tan((y + z)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	return x + (Math.tan((y + z)) - Math.tan(a));
}
def code(x, y, z, a):
	return x + (math.tan((y + z)) - math.tan(a))
function code(x, y, z, a)
	return Float64(x + Float64(tan(Float64(y + z)) - tan(a)))
end
function tmp = code(x, y, z, a)
	tmp = x + (tan((y + z)) - tan(a));
end
code[x_, y_, z_, a_] := N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x + \left(\frac{\left(\tan y + \tan z\right) \cdot \cos a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a} - \color{blue}{1} \cdot \frac{\sin a}{\cos a}\right) \]
    4. cancel-sign-sub-inv99.7%

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

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

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

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

Alternative 2: 99.7% accurate, 0.3× speedup?

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

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

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

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

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

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

      \[\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.7%

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

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

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

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

Alternative 3: 88.2% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -2 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(\sin \left(y + z\right), \frac{1}{\cos \left(y + z\right)}, x - \tan a\right)\\

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

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


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

    1. Initial program 78.0%

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

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

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

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

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

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

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

    if -1.9999999999999999e-7 < (tan.f64 a) < 4.9999999999999998e-82

    1. Initial program 79.0%

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

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

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

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

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

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

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

        \[\leadsto x + \left(\frac{\left(\tan y + \tan z\right) \cdot \cos a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a} - \color{blue}{1} \cdot \frac{\sin a}{\cos a}\right) \]
      4. cancel-sign-sub-inv99.7%

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

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

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

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

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

    if 4.9999999999999998e-82 < (tan.f64 a)

    1. Initial program 81.9%

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

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

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

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

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

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

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

        \[\leadsto x + \left(\frac{\left(\tan y + \tan z\right) \cdot \cos a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a} - \color{blue}{1} \cdot \frac{\sin a}{\cos a}\right) \]
      4. cancel-sign-sub-inv99.7%

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

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

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

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

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

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

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

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

Alternative 4: 99.7% accurate, 0.3× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto x + \left(\frac{\left(\tan y + \tan z\right) \cdot \cos a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a} - \color{blue}{1} \cdot \frac{\sin a}{\cos a}\right) \]
    4. cancel-sign-sub-inv99.7%

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

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

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

Alternative 5: 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. Add Preprocessing
  3. Step-by-step derivation
    1. tan-sum99.7%

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

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

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

      \[\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.7%

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

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

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

Alternative 6: 79.7% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto x + \left(\frac{\left(\tan y + \tan z\right) \cdot \cos a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a} - \color{blue}{1} \cdot \frac{\sin a}{\cos a}\right) \]
    4. cancel-sign-sub-inv99.7%

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

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

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

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

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

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

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

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

Alternative 7: 60.2% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 85.1%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin y}{\cos y} + \left(x - \frac{\sin a}{\cos a}\right)} \]
    5. Simplified72.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{x + \left(\tan y - \tan a\right)} \]
    9. Simplified72.0%

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

    if 1.99999999999999991e-6 < (+.f64 y z)

    1. Initial program 69.3%

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

      \[\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+69.0%

        \[\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. +-commutative69.0%

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

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

        \[\leadsto x \cdot \left(1 + \left(\frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)} \cdot x} - \frac{\sin a}{x \cdot \cos a}\right)\right) \]
      5. associate-/r*69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x \cdot \left(1 + \color{blue}{1 \cdot \frac{\sin \left(y + z\right)}{\cos \left(y + z\right) \cdot x}}\right) \]
      2. associate-/r*45.0%

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

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

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

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

        \[\leadsto x \cdot \left(1 + \frac{\tan \color{blue}{\left(z + y\right)}}{x}\right) \]
    12. Simplified45.1%

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

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

Alternative 8: 79.7% 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. Add Preprocessing
  3. Final simplification79.5%

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

Alternative 9: 51.0% accurate, 1.9× speedup?

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

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

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

    \[\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+79.2%

      \[\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. +-commutative79.2%

      \[\leadsto x \cdot \left(1 + \left(\frac{\sin \color{blue}{\left(z + y\right)}}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right)\right) \]
    3. *-commutative79.2%

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

      \[\leadsto x \cdot \left(1 + \left(\frac{\sin \left(z + y\right)}{\cos \color{blue}{\left(z + y\right)} \cdot x} - \frac{\sin a}{x \cdot \cos a}\right)\right) \]
    5. associate-/r*79.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \left(1 + \color{blue}{1 \cdot \frac{\sin \left(y + z\right)}{\cos \left(y + z\right) \cdot x}}\right) \]
    2. associate-/r*51.2%

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

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

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

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

      \[\leadsto x \cdot \left(1 + \frac{\tan \color{blue}{\left(z + y\right)}}{x}\right) \]
  12. Simplified51.3%

    \[\leadsto x \cdot \left(1 + \color{blue}{\frac{\tan \left(z + y\right)}{x}}\right) \]
  13. Final simplification51.3%

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

Alternative 10: 2.7% accurate, 207.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (x y z a) :precision binary64 -1.0)
double code(double x, double y, double z, double a) {
	return -1.0;
}
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 = -1.0d0
end function
public static double code(double x, double y, double z, double a) {
	return -1.0;
}
def code(x, y, z, a):
	return -1.0
function code(x, y, z, a)
	return -1.0
end
function tmp = code(x, y, z, a)
	tmp = -1.0;
end
code[x_, y_, z_, a_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 79.5%

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

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

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

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\tan \left(y + z\right) - \tan a\right) + x}\right)} - 1 \]
    4. associate-+l-76.2%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\tan \left(y + z\right) - \left(\tan a - x\right)}\right)} - 1 \]
  4. Applied egg-rr76.2%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\tan \left(y + z\right) - \left(\tan a - x\right)\right)} - 1} \]
  5. Step-by-step derivation
    1. expm1-define76.1%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\tan \left(y + z\right) - \left(\tan a - x\right)\right)\right)} \]
    2. associate--r-76.2%

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

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

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(\tan \left(z + y\right) - \tan a\right) + x\right)\right)} \]
  7. Taylor expanded in x around inf 22.1%

    \[\leadsto \mathsf{expm1}\left(\color{blue}{-1 \cdot \log \left(\frac{1}{x}\right)}\right) \]
  8. Step-by-step derivation
    1. mul-1-neg22.1%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{-\log \left(\frac{1}{x}\right)}\right) \]
    2. log-rec22.1%

      \[\leadsto \mathsf{expm1}\left(-\color{blue}{\left(-\log x\right)}\right) \]
    3. remove-double-neg22.1%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\log x}\right) \]
  9. Simplified22.1%

    \[\leadsto \mathsf{expm1}\left(\color{blue}{\log x}\right) \]
  10. Taylor expanded in x around 0 2.7%

    \[\leadsto \color{blue}{-1} \]
  11. Final simplification2.7%

    \[\leadsto -1 \]
  12. Add Preprocessing

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

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification33.2%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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