tan-example (used to crash)

Percentage Accurate: 79.5% → 99.6%
Time: 46.6s
Alternatives: 13
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 13 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.5% 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.6% accurate, 0.3× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 2: 89.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \tan y + \tan z\\ \mathbf{if}\;\tan a \leq -0.005 \lor \neg \left(\tan a \leq 5 \cdot 10^{-24}\right):\\ \;\;\;\;x + \mathsf{fma}\left(t\_0, 1, -\tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x - \left(a + \frac{t\_0}{-1 + \tan y \cdot \tan z}\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (+ (tan y) (tan z))))
   (if (or (<= (tan a) -0.005) (not (<= (tan a) 5e-24)))
     (+ x (fma t_0 1.0 (- (tan a))))
     (- x (+ a (/ t_0 (+ -1.0 (* (tan y) (tan z)))))))))
double code(double x, double y, double z, double a) {
	double t_0 = tan(y) + tan(z);
	double tmp;
	if ((tan(a) <= -0.005) || !(tan(a) <= 5e-24)) {
		tmp = x + fma(t_0, 1.0, -tan(a));
	} else {
		tmp = x - (a + (t_0 / (-1.0 + (tan(y) * tan(z)))));
	}
	return tmp;
}
function code(x, y, z, a)
	t_0 = Float64(tan(y) + tan(z))
	tmp = 0.0
	if ((tan(a) <= -0.005) || !(tan(a) <= 5e-24))
		tmp = Float64(x + fma(t_0, 1.0, Float64(-tan(a))));
	else
		tmp = Float64(x - Float64(a + Float64(t_0 / Float64(-1.0 + Float64(tan(y) * tan(z))))));
	end
	return tmp
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[N[Tan[a], $MachinePrecision], -0.005], N[Not[LessEqual[N[Tan[a], $MachinePrecision], 5e-24]], $MachinePrecision]], N[(x + N[(t$95$0 * 1.0 + (-N[Tan[a], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(x - N[(a + N[(t$95$0 / N[(-1.0 + N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \tan y + \tan z\\
\mathbf{if}\;\tan a \leq -0.005 \lor \neg \left(\tan a \leq 5 \cdot 10^{-24}\right):\\
\;\;\;\;x + \mathsf{fma}\left(t\_0, 1, -\tan a\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (tan.f64 a) < -0.0050000000000000001 or 4.9999999999999998e-24 < (tan.f64 a)

    1. Initial program 80.1%

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

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

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

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

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

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

    if -0.0050000000000000001 < (tan.f64 a) < 4.9999999999999998e-24

    1. Initial program 77.5%

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

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

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

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

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

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

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

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

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

Alternative 3: 99.7% accurate, 0.3× speedup?

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

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

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

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

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

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

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

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

Alternative 4: 99.7% accurate, 0.4× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 5: 69.3% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (tan.f64 a) < -9.99999999999999955e-7 or 2.00000000000000016e-5 < (tan.f64 a)

    1. Initial program 78.7%

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

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

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

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

      \[\leadsto x + \left(\color{blue}{1 \cdot \tan y} - \tan a\right) \]
    6. Step-by-step derivation
      1. *-lft-identity63.2%

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

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

    if -9.99999999999999955e-7 < (tan.f64 a) < 2.00000000000000016e-5

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 69.3% accurate, 0.5× speedup?

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

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

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

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


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

    1. Initial program 77.9%

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

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

        \[\leadsto x + \left(\color{blue}{\tan y} - \tan a\right) \]
      2. *-un-lft-identity60.7%

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

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

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

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

    if -9.99999999999999955e-7 < (tan.f64 a) < 2.00000000000000016e-5

    1. Initial program 79.0%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (tan.f64 a)

    1. Initial program 79.7%

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

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

        \[\leadsto \color{blue}{e^{\log \left(x + \left(\frac{\sin y}{\cos y} - \tan a\right)\right)}} \]
      2. tan-quot57.3%

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

      \[\leadsto \color{blue}{e^{\log \left(x + \left(\tan y - \tan a\right)\right)}} \]
    6. Step-by-step derivation
      1. rem-exp-log66.0%

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

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

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

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

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

Alternative 7: 79.8% accurate, 0.5× speedup?

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

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

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

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

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

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

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

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

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

Alternative 8: 59.5% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 82.8%

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

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

        \[\leadsto x + \left(\color{blue}{\tan y} - \tan a\right) \]
      2. *-un-lft-identity66.8%

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

      \[\leadsto x + \left(\color{blue}{1 \cdot \tan y} - \tan a\right) \]
    6. Step-by-step derivation
      1. *-lft-identity66.8%

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

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

    if 2.00000000000000014e-17 < (+.f64 y z)

    1. Initial program 73.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 55.7% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.65 \lor \neg \left(a \leq 16\right):\\
\;\;\;\;x + \left(y - \tan a\right)\\

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


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

    1. Initial program 78.9%

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

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

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

    if -0.650000000000000022 < a < 16

    1. Initial program 78.9%

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

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

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

Alternative 11: 55.7% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.21 \lor \neg \left(a \leq 16\right):\\ \;\;\;\;x + \left(y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(y + z\right) + \left(x - a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (or (<= a -0.21) (not (<= a 16.0)))
   (+ x (- y (tan a)))
   (+ (tan (+ y z)) (- x a))))
double code(double x, double y, double z, double a) {
	double tmp;
	if ((a <= -0.21) || !(a <= 16.0)) {
		tmp = x + (y - tan(a));
	} else {
		tmp = tan((y + z)) + (x - a);
	}
	return tmp;
}
real(8) function code(x, y, z, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: tmp
    if ((a <= (-0.21d0)) .or. (.not. (a <= 16.0d0))) then
        tmp = x + (y - tan(a))
    else
        tmp = tan((y + z)) + (x - a)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if ((a <= -0.21) || !(a <= 16.0)) {
		tmp = x + (y - Math.tan(a));
	} else {
		tmp = Math.tan((y + z)) + (x - a);
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if (a <= -0.21) or not (a <= 16.0):
		tmp = x + (y - math.tan(a))
	else:
		tmp = math.tan((y + z)) + (x - a)
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if ((a <= -0.21) || !(a <= 16.0))
		tmp = Float64(x + Float64(y - tan(a)));
	else
		tmp = Float64(tan(Float64(y + z)) + Float64(x - a));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if ((a <= -0.21) || ~((a <= 16.0)))
		tmp = x + (y - tan(a));
	else
		tmp = tan((y + z)) + (x - a);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[Or[LessEqual[a, -0.21], N[Not[LessEqual[a, 16.0]], $MachinePrecision]], N[(x + N[(y - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] + N[(x - a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -0.21 \lor \neg \left(a \leq 16\right):\\
\;\;\;\;x + \left(y - \tan a\right)\\

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


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

    1. Initial program 78.9%

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

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

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

    if -0.209999999999999992 < a < 16

    1. Initial program 78.9%

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 41.2% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00075:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 2.8 \cdot 10^{-9}:\\
\;\;\;\;x + \left(y - \tan a\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.5000000000000002e-4 or 2.79999999999999984e-9 < y

    1. Initial program 59.4%

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

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

    if -7.5000000000000002e-4 < y < 2.79999999999999984e-9

    1. Initial program 99.6%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.00075:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.8 \cdot 10^{-9}:\\ \;\;\;\;x + \left(y - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 31.7% 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 78.9%

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

    \[\leadsto \color{blue}{x} \]
  4. Final simplification31.3%

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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