tan-example (used to crash)

Percentage Accurate: 79.3% → 99.7%
Time: 33.8s
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.3% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ x + \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 81.8%

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

      \[\leadsto x + \color{blue}{\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, -\tan a\right)} \]
  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 2: 88.5% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\tan a \leq -0.005 \lor \neg \left(\tan a \leq 2 \cdot 10^{-11}\right):\\
\;\;\;\;x + \log \left(e^{\tan \left(y + z\right) - \tan a}\right)\\

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


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

    1. Initial program 82.0%

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

        \[\leadsto x + \color{blue}{\log \left(e^{\tan \left(y + z\right) - \tan a}\right)} \]
    4. Applied egg-rr82.0%

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

    if -0.0050000000000000001 < (tan.f64 a) < 1.99999999999999988e-11

    1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\tan a \leq -0.005 \lor \neg \left(\tan a \leq 2 \cdot 10^{-11}\right):\\ \;\;\;\;x + \log \left(e^{\tan \left(y + z\right) - \tan a}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}\\ \end{array} \]
  5. 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 81.8%

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

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

      \[\leadsto \color{blue}{\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z}} + x \]
  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/61.2%

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

      \[\leadsto \frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} + x \]
  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(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right) \]
  8. Add Preprocessing

Alternative 4: 59.0% accurate, 0.5× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\left|t_1\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (tan.f64 (+.f64 y z)) < -0.0200000000000000004

    1. Initial program 73.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (tan.f64 (+.f64 y z)) < 0.014999999999999999

    1. Initial program 99.8%

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

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

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

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

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

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

    if 0.014999999999999999 < (tan.f64 (+.f64 y z))

    1. Initial program 77.1%

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

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

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

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

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

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

      \[\leadsto \tan \left(y + z\right) - \color{blue}{\left(-x\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt51.5%

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\tan \left(y + z\right) - \left(-x\right)\right)}^{2}}} \]
      4. sub-neg51.7%

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

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

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

        \[\leadsto \sqrt{{\left(\tan \left(y + z\right) + \left(-\sqrt{\color{blue}{x \cdot x}}\right)\right)}^{2}} \]
      8. sqrt-unprod21.6%

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

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

        \[\leadsto \sqrt{{\left(\tan \left(y + z\right) + \color{blue}{\sqrt{-x} \cdot \sqrt{-x}}\right)}^{2}} \]
      11. sqrt-unprod51.7%

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

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

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

        \[\leadsto \sqrt{{\left(\tan \left(y + z\right) + \color{blue}{x}\right)}^{2}} \]
    9. Applied egg-rr51.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\tan \left(y + z\right) + x\right)}^{2}}} \]
    10. Step-by-step derivation
      1. unpow251.7%

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

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

        \[\leadsto \left|\color{blue}{x + \tan \left(y + z\right)}\right| \]
    11. Simplified51.7%

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

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

Alternative 5: 79.2% accurate, 0.5× speedup?

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

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

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

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

    \[\leadsto x + \color{blue}{\log \left(e^{\tan \left(y + z\right) - \tan a}\right)} \]
  5. Final simplification81.8%

    \[\leadsto x + \log \left(e^{\tan \left(y + z\right) - \tan a}\right) \]
  6. Add Preprocessing

Alternative 6: 59.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;t_0 \leq -0.02 \lor \neg \left(t_0 \leq 0.015\right):\\
\;\;\;\;x + t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (tan.f64 (+.f64 y z)) < -0.0200000000000000004 or 0.014999999999999999 < (tan.f64 (+.f64 y z))

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (tan.f64 (+.f64 y z)) < 0.014999999999999999

    1. Initial program 99.8%

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

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

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

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

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

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

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

Alternative 7: 59.7% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

    if 2e-3 < (+.f64 y z)

    1. Initial program 71.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 79.3% accurate, 1.0× speedup?

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

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

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

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

Alternative 9: 50.2% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 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 81.8%

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

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

    \[\leadsto x \]
  5. Add Preprocessing

Reproduce

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