tan-example (used to crash)

Percentage Accurate: 79.7% → 99.7%
Time: 34.1s
Alternatives: 10
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 10 alternatives:

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.7% accurate, 0.4× speedup?

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

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

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

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

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

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

Alternative 3: 99.7% accurate, 0.4× speedup?

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

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

    \[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 4: 89.4% accurate, 0.5× speedup?

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

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

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

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


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

    1. Initial program 77.9%

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

    if -3.4e-4 < a < 0.17499999999999999

    1. Initial program 80.9%

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

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

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

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

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

    if 0.17499999999999999 < a

    1. Initial program 76.7%

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

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

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

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

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

Alternative 5: 89.4% accurate, 0.5× speedup?

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

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

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

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


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

    1. Initial program 77.9%

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

    if -1.65e-4 < a < 0.17499999999999999

    1. Initial program 80.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.17499999999999999 < a

    1. Initial program 76.7%

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

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

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

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

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

Alternative 6: 51.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.6 \lor \neg \left(a \leq 4.7\right):\\
\;\;\;\;x + \frac{\sin y}{\cos y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -1.6000000000000001 or 4.70000000000000018 < a

    1. Initial program 77.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + \left(\color{blue}{\left(-\tan a\right)} + x\right) \]
      8. rem-square-sqrt44.7%

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + \left(\color{blue}{\sqrt{-\tan a} \cdot \sqrt{-\tan a}} + x\right) \]
      9. fabs-sqr44.7%

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + \left(\color{blue}{\left|\sqrt{-\tan a} \cdot \sqrt{-\tan a}\right|} + x\right) \]
      10. rem-square-sqrt54.5%

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

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + \left(\color{blue}{\left|\tan a\right|} + x\right) \]
      12. rem-square-sqrt9.7%

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + \left(\left|\color{blue}{\sqrt{\tan a} \cdot \sqrt{\tan a}}\right| + x\right) \]
      13. fabs-sqr9.7%

        \[\leadsto \frac{\sin \left(z + y\right)}{\cos \left(z + y\right)} + \left(\color{blue}{\sqrt{\tan a} \cdot \sqrt{\tan a}} + x\right) \]
      14. rem-square-sqrt21.7%

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

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

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

      \[\leadsto \color{blue}{x + \left(\frac{\sin a}{\cos a} + \frac{\sin y}{\cos y}\right)} \]
    8. Step-by-step derivation
      1. associate-+r+21.6%

        \[\leadsto \color{blue}{\left(x + \frac{\sin a}{\cos a}\right) + \frac{\sin y}{\cos y}} \]
    9. Simplified21.6%

      \[\leadsto \color{blue}{\left(x + \frac{\sin a}{\cos a}\right) + \frac{\sin y}{\cos y}} \]
    10. Taylor expanded in a around 0 23.2%

      \[\leadsto \color{blue}{x + \frac{\sin y}{\cos y}} \]
    11. Step-by-step derivation
      1. +-commutative23.2%

        \[\leadsto \color{blue}{\frac{\sin y}{\cos y} + x} \]
    12. Simplified23.2%

      \[\leadsto \color{blue}{\frac{\sin y}{\cos y} + x} \]

    if -1.6000000000000001 < a < 4.70000000000000018

    1. Initial program 81.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.6 \lor \neg \left(a \leq 4.7\right):\\ \;\;\;\;x + \frac{\sin y}{\cos y}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tan \left(z + y\right) - a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 49.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

      \[\leadsto x + \left(\tan \left(z + y\right) + \color{blue}{\left|\sqrt{-\tan a} \cdot \sqrt{-\tan a}\right|}\right) \]
    4. rem-square-sqrt68.6%

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

      \[\leadsto x + \left(\tan \left(z + y\right) + \color{blue}{\left|\tan a\right|}\right) \]
    6. rem-square-sqrt26.8%

      \[\leadsto x + \left(\tan \left(z + y\right) + \left|\color{blue}{\sqrt{\tan a} \cdot \sqrt{\tan a}}\right|\right) \]
    7. fabs-sqr26.8%

      \[\leadsto x + \left(\tan \left(z + y\right) + \color{blue}{\sqrt{\tan a} \cdot \sqrt{\tan a}}\right) \]
    8. rem-square-sqrt52.6%

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

    \[\leadsto x + \color{blue}{\left(\tan \left(z + y\right) + \tan a\right)} \]
  7. Final simplification52.6%

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

Alternative 8: 79.7% accurate, 1.0× speedup?

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

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

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

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

Alternative 9: 50.9% accurate, 1.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -7.79999999999999982 or 0.170000000000000012 < a

    1. Initial program 76.5%

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

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

    if -7.79999999999999982 < a < 0.170000000000000012

    1. Initial program 81.6%

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

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

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

Alternative 10: 31.8% 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.3%

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

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

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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