tan-example (used to crash)

Percentage Accurate: 79.6% → 99.7%
Time: 31.8s
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.6% 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.2× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \tan y \cdot \tan z\\ \mathsf{fma}\left(\cos a \cdot \tan y + \mathsf{fma}\left(\cos a, \tan z, \sin a \cdot \left(t\_0 + -1\right)\right), \frac{1}{\cos a \cdot \left(1 - t\_0\right)}, x\right) \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* (tan y) (tan z))))
   (fma
    (+ (* (cos a) (tan y)) (fma (cos a) (tan z) (* (sin a) (+ t_0 -1.0))))
    (/ 1.0 (* (cos a) (- 1.0 t_0)))
    x)))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = tan(y) * tan(z);
	return fma(((cos(a) * tan(y)) + fma(cos(a), tan(z), (sin(a) * (t_0 + -1.0)))), (1.0 / (cos(a) * (1.0 - t_0))), x);
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = Float64(tan(y) * tan(z))
	return fma(Float64(Float64(cos(a) * tan(y)) + fma(cos(a), tan(z), Float64(sin(a) * Float64(t_0 + -1.0)))), Float64(1.0 / Float64(cos(a) * Float64(1.0 - t_0))), x)
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[Cos[a], $MachinePrecision] * N[Tan[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[a], $MachinePrecision] * N[Tan[z], $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Cos[a], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
\mathsf{fma}\left(\cos a \cdot \tan y + \mathsf{fma}\left(\cos a, \tan z, \sin a \cdot \left(t\_0 + -1\right)\right), \frac{1}{\cos a \cdot \left(1 - t\_0\right)}, x\right)
\end{array}
\end{array}
Derivation
  1. Initial program 82.7%

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

      \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \tan a\right) + x} \]
    3. lift--.f64N/A

      \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} + x \]
    4. lift-tan.f64N/A

      \[\leadsto \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) + x \]
    5. lift-+.f64N/A

      \[\leadsto \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) + x \]
    6. tan-sumN/A

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

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

      \[\leadsto \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \color{blue}{\frac{\sin a}{\cos a}}\right) + x \]
    9. frac-subN/A

      \[\leadsto \color{blue}{\frac{\left(\tan y + \tan z\right) \cdot \cos a - \left(1 - \tan y \cdot \tan z\right) \cdot \sin a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a}} + x \]
    10. div-invN/A

      \[\leadsto \color{blue}{\left(\left(\tan y + \tan z\right) \cdot \cos a - \left(1 - \tan y \cdot \tan z\right) \cdot \sin a\right) \cdot \frac{1}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a}} + x \]
    11. lower-fma.f64N/A

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos a \cdot \left(\tan y + \tan z\right) - \sin a \cdot \left(1 - \tan y \cdot \tan z\right)}, \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    2. sub-negN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos a \cdot \left(\tan y + \tan z\right) + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right)}, \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    3. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos a \cdot \left(\tan y + \tan z\right)} + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right), \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    4. lift-+.f64N/A

      \[\leadsto \mathsf{fma}\left(\cos a \cdot \color{blue}{\left(\tan y + \tan z\right)} + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right), \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    5. distribute-lft-inN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\cos a \cdot \tan y + \cos a \cdot \tan z\right)} + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right), \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    6. associate-+l+N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos a \cdot \tan y + \left(\cos a \cdot \tan z + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right)\right)}, \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    7. lower-+.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos a \cdot \tan y + \left(\cos a \cdot \tan z + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right)\right)}, \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    8. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\cos a \cdot \tan y} + \left(\cos a \cdot \tan z + \left(\mathsf{neg}\left(\sin a \cdot \left(1 - \tan y \cdot \tan z\right)\right)\right)\right), \frac{1}{\cos a \cdot \left(1 - \tan y \cdot \tan z\right)}, x\right) \]
    9. lower-fma.f64N/A

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

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

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

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

Alternative 2: 99.7% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \tan y \cdot \tan z\\ \mathsf{fma}\left(\sin a \cdot \left(t\_0 + -1\right) + \cos a \cdot \left(\tan y + \tan z\right), \frac{1}{\cos a \cdot \left(1 - t\_0\right)}, x\right) \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* (tan y) (tan z))))
   (fma
    (+ (* (sin a) (+ t_0 -1.0)) (* (cos a) (+ (tan y) (tan z))))
    (/ 1.0 (* (cos a) (- 1.0 t_0)))
    x)))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = tan(y) * tan(z);
	return fma(((sin(a) * (t_0 + -1.0)) + (cos(a) * (tan(y) + tan(z)))), (1.0 / (cos(a) * (1.0 - t_0))), x);
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = Float64(tan(y) * tan(z))
	return fma(Float64(Float64(sin(a) * Float64(t_0 + -1.0)) + Float64(cos(a) * Float64(tan(y) + tan(z)))), Float64(1.0 / Float64(cos(a) * Float64(1.0 - t_0))), x)
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[Sin[a], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision] + N[(N[Cos[a], $MachinePrecision] * N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Cos[a], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
\mathsf{fma}\left(\sin a \cdot \left(t\_0 + -1\right) + \cos a \cdot \left(\tan y + \tan z\right), \frac{1}{\cos a \cdot \left(1 - t\_0\right)}, x\right)
\end{array}
\end{array}
Derivation
  1. Initial program 82.7%

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

      \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
    2. +-commutativeN/A

      \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \tan a\right) + x} \]
    3. lift--.f64N/A

      \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} + x \]
    4. lift-tan.f64N/A

      \[\leadsto \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) + x \]
    5. lift-+.f64N/A

      \[\leadsto \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) + x \]
    6. tan-sumN/A

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

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

      \[\leadsto \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \color{blue}{\frac{\sin a}{\cos a}}\right) + x \]
    9. frac-subN/A

      \[\leadsto \color{blue}{\frac{\left(\tan y + \tan z\right) \cdot \cos a - \left(1 - \tan y \cdot \tan z\right) \cdot \sin a}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a}} + x \]
    10. div-invN/A

      \[\leadsto \color{blue}{\left(\left(\tan y + \tan z\right) \cdot \cos a - \left(1 - \tan y \cdot \tan z\right) \cdot \sin a\right) \cdot \frac{1}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a}} + x \]
    11. lower-fma.f64N/A

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

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

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

Alternative 3: 99.7% accurate, 0.2× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \tan y \cdot \tan z\\ x + \frac{\mathsf{fma}\left(\cos a, \tan y + \tan z, \sin a \cdot \left(t\_0 + -1\right)\right)}{\cos a \cdot \left(1 - t\_0\right)} \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* (tan y) (tan z))))
   (+
    x
    (/
     (fma (cos a) (+ (tan y) (tan z)) (* (sin a) (+ t_0 -1.0)))
     (* (cos a) (- 1.0 t_0))))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = tan(y) * tan(z);
	return x + (fma(cos(a), (tan(y) + tan(z)), (sin(a) * (t_0 + -1.0))) / (cos(a) * (1.0 - t_0)));
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = Float64(tan(y) * tan(z))
	return Float64(x + Float64(fma(cos(a), Float64(tan(y) + tan(z)), Float64(sin(a) * Float64(t_0 + -1.0))) / Float64(cos(a) * Float64(1.0 - t_0))))
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[Cos[a], $MachinePrecision] * N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[a], $MachinePrecision] * N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Cos[a], $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan y \cdot \tan z\\
x + \frac{\mathsf{fma}\left(\cos a, \tan y + \tan z, \sin a \cdot \left(t\_0 + -1\right)\right)}{\cos a \cdot \left(1 - t\_0\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 82.7%

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

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

      \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) + \left(\mathsf{neg}\left(\tan a\right)\right)\right)} \]
    3. lift-tan.f64N/A

      \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} + \left(\mathsf{neg}\left(\tan a\right)\right)\right) \]
    4. lift-+.f64N/A

      \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} + \left(\mathsf{neg}\left(\tan a\right)\right)\right) \]
    5. tan-sumN/A

      \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} + \left(\mathsf{neg}\left(\tan a\right)\right)\right) \]
    6. lift-tan.f64N/A

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} + \left(\mathsf{neg}\left(\color{blue}{\tan a}\right)\right)\right) \]
    7. tan-quotN/A

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} + \left(\mathsf{neg}\left(\color{blue}{\frac{\sin a}{\cos a}}\right)\right)\right) \]
    8. distribute-neg-fracN/A

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} + \color{blue}{\frac{\mathsf{neg}\left(\sin a\right)}{\cos a}}\right) \]
    9. frac-addN/A

      \[\leadsto x + \color{blue}{\frac{\left(\tan y + \tan z\right) \cdot \cos a + \left(1 - \tan y \cdot \tan z\right) \cdot \left(\mathsf{neg}\left(\sin a\right)\right)}{\left(1 - \tan y \cdot \tan z\right) \cdot \cos a}} \]
    10. lower-/.f64N/A

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

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

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

Alternative 4: 89.6% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \tan \left(y + z\right)\\ \mathbf{if}\;\tan a \leq -0.005:\\ \;\;\;\;x + \left(t\_0 - \tan a\right)\\ \mathbf{elif}\;\tan a \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\mathsf{fma}\left(\tan y + \tan z, \frac{1}{1 - \tan y \cdot \tan z}, x - \mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(\sin a, \frac{-1}{\cos a}, t\_0\right)\\ \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (tan (+ y z))))
   (if (<= (tan a) -0.005)
     (+ x (- t_0 (tan a)))
     (if (<= (tan a) 5e-15)
       (fma
        (+ (tan y) (tan z))
        (/ 1.0 (- 1.0 (* (tan y) (tan z))))
        (- x (fma (* a a) (* a 0.3333333333333333) a)))
       (+ x (fma (sin a) (/ -1.0 (cos a)) t_0))))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = tan((y + z));
	double tmp;
	if (tan(a) <= -0.005) {
		tmp = x + (t_0 - tan(a));
	} else if (tan(a) <= 5e-15) {
		tmp = fma((tan(y) + tan(z)), (1.0 / (1.0 - (tan(y) * tan(z)))), (x - fma((a * a), (a * 0.3333333333333333), a)));
	} else {
		tmp = x + fma(sin(a), (-1.0 / cos(a)), t_0);
	}
	return tmp;
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = tan(Float64(y + z))
	tmp = 0.0
	if (tan(a) <= -0.005)
		tmp = Float64(x + Float64(t_0 - tan(a)));
	elseif (tan(a) <= 5e-15)
		tmp = fma(Float64(tan(y) + tan(z)), Float64(1.0 / Float64(1.0 - Float64(tan(y) * tan(z)))), Float64(x - fma(Float64(a * a), Float64(a * 0.3333333333333333), a)));
	else
		tmp = Float64(x + fma(sin(a), Float64(-1.0 / cos(a)), t_0));
	end
	return tmp
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.005], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 5e-15], 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[(x - N[(N[(a * a), $MachinePrecision] * N[(a * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[a], $MachinePrecision] * N[(-1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.005:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\

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

\mathbf{else}:\\
\;\;\;\;x + \mathsf{fma}\left(\sin a, \frac{-1}{\cos a}, t\_0\right)\\


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

    1. Initial program 83.9%

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

    if -0.0050000000000000001 < (tan.f64 a) < 4.99999999999999999e-15

    1. Initial program 83.8%

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + a \cdot 1\right)}\right) \]
      3. associate-*r*N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{\left(a \cdot \frac{1}{3}\right) \cdot {a}^{2}} + a \cdot 1\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{{a}^{2} \cdot \left(a \cdot \frac{1}{3}\right)} + a \cdot 1\right)\right) \]
      5. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left({a}^{2} \cdot \left(a \cdot \frac{1}{3}\right) + \color{blue}{a}\right)\right) \]
      6. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left({a}^{2}, a \cdot \frac{1}{3}, a\right)}\right) \]
      7. unpow2N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      8. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      9. lower-*.f6483.8

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a \cdot a, \color{blue}{a \cdot 0.3333333333333333}, a\right)\right) \]
    5. Applied rewrites83.8%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)}\right) \]
    6. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) + x} \]
      3. lift--.f64N/A

        \[\leadsto \color{blue}{\left(\tan \left(y + z\right) - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)} + x \]
      4. sub-negN/A

        \[\leadsto \color{blue}{\left(\tan \left(y + z\right) + \left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right)\right)} + x \]
      5. associate-+l+N/A

        \[\leadsto \color{blue}{\tan \left(y + z\right) + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right)} \]
      6. lift-tan.f64N/A

        \[\leadsto \color{blue}{\tan \left(y + z\right)} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      7. lift-+.f64N/A

        \[\leadsto \tan \color{blue}{\left(y + z\right)} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      8. tan-sumN/A

        \[\leadsto \color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      9. lift-tan.f64N/A

        \[\leadsto \frac{\color{blue}{\tan y} + \tan z}{1 - \tan y \cdot \tan z} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      10. lift-tan.f64N/A

        \[\leadsto \frac{\tan y + \color{blue}{\tan z}}{1 - \tan y \cdot \tan z} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      11. lift-+.f64N/A

        \[\leadsto \frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      12. lift-tan.f64N/A

        \[\leadsto \frac{\tan y + \tan z}{1 - \color{blue}{\tan y} \cdot \tan z} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      13. lift-tan.f64N/A

        \[\leadsto \frac{\tan y + \tan z}{1 - \tan y \cdot \color{blue}{\tan z}} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      14. lift-*.f64N/A

        \[\leadsto \frac{\tan y + \tan z}{1 - \color{blue}{\tan y \cdot \tan z}} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      15. lift--.f64N/A

        \[\leadsto \frac{\tan y + \tan z}{\color{blue}{1 - \tan y \cdot \tan z}} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
      16. div-invN/A

        \[\leadsto \color{blue}{\left(\tan y + \tan z\right) \cdot \frac{1}{1 - \tan y \cdot \tan z}} + \left(\left(\mathsf{neg}\left(\mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right)\right) + x\right) \]
    7. Applied rewrites99.9%

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

    if 4.99999999999999999e-15 < (tan.f64 a)

    1. Initial program 79.6%

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

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

        \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) + \left(\mathsf{neg}\left(\tan a\right)\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto x + \color{blue}{\left(\left(\mathsf{neg}\left(\tan a\right)\right) + \tan \left(y + z\right)\right)} \]
      4. lift-tan.f64N/A

        \[\leadsto x + \left(\left(\mathsf{neg}\left(\color{blue}{\tan a}\right)\right) + \tan \left(y + z\right)\right) \]
      5. tan-quotN/A

        \[\leadsto x + \left(\left(\mathsf{neg}\left(\color{blue}{\frac{\sin a}{\cos a}}\right)\right) + \tan \left(y + z\right)\right) \]
      6. distribute-neg-frac2N/A

        \[\leadsto x + \left(\color{blue}{\frac{\sin a}{\mathsf{neg}\left(\cos a\right)}} + \tan \left(y + z\right)\right) \]
      7. div-invN/A

        \[\leadsto x + \left(\color{blue}{\sin a \cdot \frac{1}{\mathsf{neg}\left(\cos a\right)}} + \tan \left(y + z\right)\right) \]
      8. lower-fma.f64N/A

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(\sin a, \frac{1}{\mathsf{neg}\left(\cos a\right)}, \tan \left(y + z\right)\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto x + \mathsf{fma}\left(\color{blue}{\sin a}, \frac{1}{\mathsf{neg}\left(\cos a\right)}, \tan \left(y + z\right)\right) \]
      10. lower-/.f64N/A

        \[\leadsto x + \mathsf{fma}\left(\sin a, \color{blue}{\frac{1}{\mathsf{neg}\left(\cos a\right)}}, \tan \left(y + z\right)\right) \]
      11. lower-neg.f64N/A

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

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

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

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

Alternative 5: 89.5% accurate, 0.3× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \tan \left(y + z\right)\\ \mathbf{if}\;\tan a \leq -0.005:\\ \;\;\;\;x + \left(t\_0 - \tan a\right)\\ \mathbf{elif}\;\tan a \leq 10^{-25}:\\ \;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + \mathsf{fma}\left(\sin a, \frac{-1}{\cos a}, t\_0\right)\\ \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (tan (+ y z))))
   (if (<= (tan a) -0.005)
     (+ x (- t_0 (tan a)))
     (if (<= (tan a) 1e-25)
       (+
        x
        (-
         (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z))))
         (fma (* a a) (* a 0.3333333333333333) a)))
       (+ x (fma (sin a) (/ -1.0 (cos a)) t_0))))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = tan((y + z));
	double tmp;
	if (tan(a) <= -0.005) {
		tmp = x + (t_0 - tan(a));
	} else if (tan(a) <= 1e-25) {
		tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - fma((a * a), (a * 0.3333333333333333), a));
	} else {
		tmp = x + fma(sin(a), (-1.0 / cos(a)), t_0);
	}
	return tmp;
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = tan(Float64(y + z))
	tmp = 0.0
	if (tan(a) <= -0.005)
		tmp = Float64(x + Float64(t_0 - tan(a)));
	elseif (tan(a) <= 1e-25)
		tmp = Float64(x + Float64(Float64(Float64(tan(y) + tan(z)) / Float64(1.0 - Float64(tan(y) * tan(z)))) - fma(Float64(a * a), Float64(a * 0.3333333333333333), a)));
	else
		tmp = Float64(x + fma(sin(a), Float64(-1.0 / cos(a)), t_0));
	end
	return tmp
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.005], N[(x + N[(t$95$0 - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Tan[a], $MachinePrecision], 1e-25], N[(x + N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(N[Tan[y], $MachinePrecision] * N[Tan[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(a * a), $MachinePrecision] * N[(a * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[a], $MachinePrecision] * N[(-1.0 / N[Cos[a], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \tan \left(y + z\right)\\
\mathbf{if}\;\tan a \leq -0.005:\\
\;\;\;\;x + \left(t\_0 - \tan a\right)\\

\mathbf{elif}\;\tan a \leq 10^{-25}:\\
\;\;\;\;x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x + \mathsf{fma}\left(\sin a, \frac{-1}{\cos a}, t\_0\right)\\


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

    1. Initial program 83.9%

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

    if -0.0050000000000000001 < (tan.f64 a) < 1.00000000000000004e-25

    1. Initial program 83.0%

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + a \cdot 1\right)}\right) \]
      3. associate-*r*N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{\left(a \cdot \frac{1}{3}\right) \cdot {a}^{2}} + a \cdot 1\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{{a}^{2} \cdot \left(a \cdot \frac{1}{3}\right)} + a \cdot 1\right)\right) \]
      5. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left({a}^{2} \cdot \left(a \cdot \frac{1}{3}\right) + \color{blue}{a}\right)\right) \]
      6. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left({a}^{2}, a \cdot \frac{1}{3}, a\right)}\right) \]
      7. unpow2N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      8. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      9. lower-*.f6483.0

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a \cdot a, \color{blue}{a \cdot 0.3333333333333333}, a\right)\right) \]
    5. Applied rewrites83.0%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(a \cdot a, a \cdot 0.3333333333333333, a\right)}\right) \]
    6. Step-by-step derivation
      1. lift-tan.f64N/A

        \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      2. lift-+.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      3. tan-sumN/A

        \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      4. lift-tan.f64N/A

        \[\leadsto x + \left(\frac{\color{blue}{\tan y} + \tan z}{1 - \tan y \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      5. lift-tan.f64N/A

        \[\leadsto x + \left(\frac{\tan y + \color{blue}{\tan z}}{1 - \tan y \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      6. lift-+.f64N/A

        \[\leadsto x + \left(\frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      7. lift-tan.f64N/A

        \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\tan y} \cdot \tan z} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      8. lift-tan.f64N/A

        \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \color{blue}{\tan z}} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      9. lift-*.f64N/A

        \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\tan y \cdot \tan z}} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      10. lift--.f64N/A

        \[\leadsto x + \left(\frac{\tan y + \tan z}{\color{blue}{1 - \tan y \cdot \tan z}} - \mathsf{fma}\left(a \cdot a, a \cdot \frac{1}{3}, a\right)\right) \]
      11. lower-/.f6499.9

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

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

    if 1.00000000000000004e-25 < (tan.f64 a)

    1. Initial program 81.0%

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

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

        \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) + \left(\mathsf{neg}\left(\tan a\right)\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto x + \color{blue}{\left(\left(\mathsf{neg}\left(\tan a\right)\right) + \tan \left(y + z\right)\right)} \]
      4. lift-tan.f64N/A

        \[\leadsto x + \left(\left(\mathsf{neg}\left(\color{blue}{\tan a}\right)\right) + \tan \left(y + z\right)\right) \]
      5. tan-quotN/A

        \[\leadsto x + \left(\left(\mathsf{neg}\left(\color{blue}{\frac{\sin a}{\cos a}}\right)\right) + \tan \left(y + z\right)\right) \]
      6. distribute-neg-frac2N/A

        \[\leadsto x + \left(\color{blue}{\frac{\sin a}{\mathsf{neg}\left(\cos a\right)}} + \tan \left(y + z\right)\right) \]
      7. div-invN/A

        \[\leadsto x + \left(\color{blue}{\sin a \cdot \frac{1}{\mathsf{neg}\left(\cos a\right)}} + \tan \left(y + z\right)\right) \]
      8. lower-fma.f64N/A

        \[\leadsto x + \color{blue}{\mathsf{fma}\left(\sin a, \frac{1}{\mathsf{neg}\left(\cos a\right)}, \tan \left(y + z\right)\right)} \]
      9. lower-sin.f64N/A

        \[\leadsto x + \mathsf{fma}\left(\color{blue}{\sin a}, \frac{1}{\mathsf{neg}\left(\cos a\right)}, \tan \left(y + z\right)\right) \]
      10. lower-/.f64N/A

        \[\leadsto x + \mathsf{fma}\left(\sin a, \color{blue}{\frac{1}{\mathsf{neg}\left(\cos a\right)}}, \tan \left(y + z\right)\right) \]
      11. lower-neg.f64N/A

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

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

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

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

Alternative 6: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right) \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (+ x (- (/ (+ (tan y) (tan z)) (- 1.0 (* (tan y) (tan z)))) (tan a))))
assert(x < y && y < z && z < 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));
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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
assert x < y && y < z && z < a;
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));
}
[x, y, z, a] = sort([x, y, z, 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))
x, y, z, a = sort([x, y, z, 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
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
	tmp = x + (((tan(y) + tan(z)) / (1.0 - (tan(y) * tan(z)))) - tan(a));
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x + \left(\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z} - \tan a\right)
\end{array}
Derivation
  1. Initial program 82.7%

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

      \[\leadsto x + \left(\color{blue}{\tan \left(y + z\right)} - \tan a\right) \]
    2. lift-+.f64N/A

      \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
    3. tan-sumN/A

      \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
    4. lower-/.f64N/A

      \[\leadsto x + \left(\color{blue}{\frac{\tan y + \tan z}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
    5. lower-+.f64N/A

      \[\leadsto x + \left(\frac{\color{blue}{\tan y + \tan z}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
    6. lower-tan.f64N/A

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

      \[\leadsto x + \left(\frac{\tan y + \color{blue}{\tan z}}{1 - \tan y \cdot \tan z} - \tan a\right) \]
    8. lower--.f64N/A

      \[\leadsto x + \left(\frac{\tan y + \tan z}{\color{blue}{1 - \tan y \cdot \tan z}} - \tan a\right) \]
    9. lower-*.f64N/A

      \[\leadsto x + \left(\frac{\tan y + \tan z}{1 - \color{blue}{\tan y \cdot \tan z}} - \tan a\right) \]
    10. lower-tan.f64N/A

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

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

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

Alternative 7: 70.1% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := x + \left(\tan z - \tan a\right)\\ \mathbf{if}\;a \leq -0.0064:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;a \leq 0.07:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (+ x (- (tan z) (tan a)))))
   (if (<= a -0.0064)
     t_0
     (if (<= a 0.07)
       (+ x (- (tan (+ y z)) (fma a (* (* a a) 0.3333333333333333) a)))
       t_0))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = x + (tan(z) - tan(a));
	double tmp;
	if (a <= -0.0064) {
		tmp = t_0;
	} else if (a <= 0.07) {
		tmp = x + (tan((y + z)) - fma(a, ((a * a) * 0.3333333333333333), a));
	} else {
		tmp = t_0;
	}
	return tmp;
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = Float64(x + Float64(tan(z) - tan(a)))
	tmp = 0.0
	if (a <= -0.0064)
		tmp = t_0;
	elseif (a <= 0.07)
		tmp = Float64(x + Float64(tan(Float64(y + z)) - fma(a, Float64(Float64(a * a) * 0.3333333333333333), a)));
	else
		tmp = t_0;
	end
	return tmp
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.0064], t$95$0, If[LessEqual[a, 0.07], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(a * N[(N[(a * a), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := x + \left(\tan z - \tan a\right)\\
\mathbf{if}\;a \leq -0.0064:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;a \leq 0.07:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 81.2%

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

        \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
      2. flip-+N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{y \cdot y - z \cdot z}{y - z}\right)} - \tan a\right) \]
      3. clear-numN/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{y - z}{y \cdot y - z \cdot z}}\right)} - \tan a\right) \]
      4. lower-/.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{y - z}{y \cdot y - z \cdot z}}\right)} - \tan a\right) \]
      5. clear-numN/A

        \[\leadsto x + \left(\tan \left(\frac{1}{\color{blue}{\frac{1}{\frac{y \cdot y - z \cdot z}{y - z}}}}\right) - \tan a\right) \]
      6. flip-+N/A

        \[\leadsto x + \left(\tan \left(\frac{1}{\frac{1}{\color{blue}{y + z}}}\right) - \tan a\right) \]
      7. lift-+.f64N/A

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

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

      \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{1}{y + z}}\right)} - \tan a\right) \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{1}{y + z}}\right)} - \tan a\right) \]
      2. inv-powN/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left(\frac{1}{y + z}\right)}^{-1}\right)} - \tan a\right) \]
      3. sqr-powN/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)}\right)} - \tan a\right) \]
      4. pow2N/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left({\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right)} - \tan a\right) \]
      5. lower-pow.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left({\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right)} - \tan a\right) \]
      6. lift-/.f64N/A

        \[\leadsto x + \left(\tan \left({\left({\color{blue}{\left(\frac{1}{y + z}\right)}}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right) - \tan a\right) \]
      7. inv-powN/A

        \[\leadsto x + \left(\tan \left({\left({\color{blue}{\left({\left(y + z\right)}^{-1}\right)}}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right) - \tan a\right) \]
      8. pow-powN/A

        \[\leadsto x + \left(\tan \left({\color{blue}{\left({\left(y + z\right)}^{\left(-1 \cdot \frac{-1}{2}\right)}\right)}}^{2}\right) - \tan a\right) \]
      9. metadata-evalN/A

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\left(-1 \cdot \color{blue}{\frac{-1}{2}}\right)}\right)}^{2}\right) - \tan a\right) \]
      10. metadata-evalN/A

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\color{blue}{\frac{1}{2}}}\right)}^{2}\right) - \tan a\right) \]
      11. metadata-evalN/A

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\color{blue}{\left(\frac{1}{2}\right)}}\right)}^{2}\right) - \tan a\right) \]
      12. lower-pow.f64N/A

        \[\leadsto x + \left(\tan \left({\color{blue}{\left({\left(y + z\right)}^{\left(\frac{1}{2}\right)}\right)}}^{2}\right) - \tan a\right) \]
      13. metadata-eval23.6

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\color{blue}{0.5}}\right)}^{2}\right) - \tan a\right) \]
    6. Applied rewrites23.6%

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

      \[\leadsto x + \left(\color{blue}{\frac{\sin z}{\cos z}} - \tan a\right) \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto x + \left(\color{blue}{\frac{\sin z}{\cos z}} - \tan a\right) \]
      2. lower-sin.f64N/A

        \[\leadsto x + \left(\frac{\color{blue}{\sin z}}{\cos z} - \tan a\right) \]
      3. lower-cos.f6461.4

        \[\leadsto x + \left(\frac{\sin z}{\color{blue}{\cos z}} - \tan a\right) \]
    9. Applied rewrites61.4%

      \[\leadsto x + \left(\color{blue}{\frac{\sin z}{\cos z}} - \tan a\right) \]
    10. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x + \left(\frac{\sin z}{\cos z} - \tan a\right)} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\frac{\sin z}{\cos z} - \tan a\right) + x} \]
      3. lower-+.f6461.4

        \[\leadsto \color{blue}{\left(\frac{\sin z}{\cos z} - \tan a\right) + x} \]
    11. Applied rewrites61.4%

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

    if -0.00640000000000000031 < a < 0.070000000000000007

    1. Initial program 84.5%

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + a \cdot 1\right)}\right) \]
      3. associate-*r*N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{\left(a \cdot \frac{1}{3}\right) \cdot {a}^{2}} + a \cdot 1\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{{a}^{2} \cdot \left(a \cdot \frac{1}{3}\right)} + a \cdot 1\right)\right) \]
      5. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left({a}^{2} \cdot \left(a \cdot \frac{1}{3}\right) + \color{blue}{a}\right)\right) \]
      6. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left({a}^{2}, a \cdot \frac{1}{3}, a\right)}\right) \]
      7. unpow2N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      8. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      9. lower-*.f6484.5

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

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + a \cdot 1\right)}\right) \]
      3. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + \color{blue}{a}\right)\right) \]
      4. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(a, \frac{1}{3} \cdot {a}^{2}, a\right)}\right) \]
      5. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \color{blue}{{a}^{2} \cdot \frac{1}{3}}, a\right)\right) \]
      6. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \color{blue}{{a}^{2} \cdot \frac{1}{3}}, a\right)\right) \]
      7. unpow2N/A

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

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \color{blue}{\left(a \cdot a\right)} \cdot 0.3333333333333333, a\right)\right) \]
    8. Applied rewrites84.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -0.0064:\\ \;\;\;\;x + \left(\tan z - \tan a\right)\\ \mathbf{elif}\;a \leq 0.07:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tan z - \tan a\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 79.6% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ x + \left(\tan \left(y + z\right) - \tan a\right) \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a) :precision binary64 (+ x (- (tan (+ y z)) (tan a))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	return x + (tan((y + z)) - tan(a));
}
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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
assert x < y && y < z && z < a;
public static double code(double x, double y, double z, double a) {
	return x + (Math.tan((y + z)) - Math.tan(a));
}
[x, y, z, a] = sort([x, y, z, a])
def code(x, y, z, a):
	return x + (math.tan((y + z)) - math.tan(a))
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	return Float64(x + Float64(tan(Float64(y + z)) - tan(a)))
end
x, y, z, a = num2cell(sort([x, y, z, a])){:}
function tmp = code(x, y, z, a)
	tmp = x + (tan((y + z)) - tan(a));
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
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, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
x + \left(\tan \left(y + z\right) - \tan a\right)
\end{array}
Derivation
  1. Initial program 82.7%

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

Alternative 9: 60.9% accurate, 1.4× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a\\ \mathbf{if}\;a \leq -0.235:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;a \leq 0.21:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot 0.13333333333333333, 0.3333333333333333\right), a \cdot \left(a \cdot a\right), a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (- (* (* x x) (/ 1.0 x)) (tan a))))
   (if (<= a -0.235)
     t_0
     (if (<= a 0.21)
       (+
        x
        (-
         (tan (+ y z))
         (fma
          (fma a (* a 0.13333333333333333) 0.3333333333333333)
          (* a (* a a))
          a)))
       t_0))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = ((x * x) * (1.0 / x)) - tan(a);
	double tmp;
	if (a <= -0.235) {
		tmp = t_0;
	} else if (a <= 0.21) {
		tmp = x + (tan((y + z)) - fma(fma(a, (a * 0.13333333333333333), 0.3333333333333333), (a * (a * a)), a));
	} else {
		tmp = t_0;
	}
	return tmp;
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = Float64(Float64(Float64(x * x) * Float64(1.0 / x)) - tan(a))
	tmp = 0.0
	if (a <= -0.235)
		tmp = t_0;
	elseif (a <= 0.21)
		tmp = Float64(x + Float64(tan(Float64(y + z)) - fma(fma(a, Float64(a * 0.13333333333333333), 0.3333333333333333), Float64(a * Float64(a * a)), a)));
	else
		tmp = t_0;
	end
	return tmp
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.235], t$95$0, If[LessEqual[a, 0.21], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(N[(a * N[(a * 0.13333333333333333), $MachinePrecision] + 0.3333333333333333), $MachinePrecision] * N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a\\
\mathbf{if}\;a \leq -0.235:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;a \leq 0.21:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot 0.13333333333333333, 0.3333333333333333\right), a \cdot \left(a \cdot a\right), a\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 81.1%

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

        \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
      2. lift--.f64N/A

        \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} \]
      3. associate-+r-N/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) - \tan a} \]
      4. sub-negN/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      5. flip-+N/A

        \[\leadsto \color{blue}{\frac{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      6. div-invN/A

        \[\leadsto \color{blue}{\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)\right) \cdot \frac{1}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right)} \]
      8. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x} - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      10. pow2N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      11. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \color{blue}{\frac{1}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      13. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \frac{1}{\color{blue}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      14. lower-neg.f6480.5

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      2. lower-*.f6446.0

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

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

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, \mathsf{neg}\left(\tan a\right)\right) \]
    9. Step-by-step derivation
      1. lower-/.f6443.0

        \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    10. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    11. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      2. lift-neg.f64N/A

        \[\leadsto \left(x \cdot x\right) \cdot \frac{1}{x} + \color{blue}{\left(\mathsf{neg}\left(\tan a\right)\right)} \]
      3. unsub-negN/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
      4. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
      5. lower-*.f6443.1

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x}} - \tan a \]
    12. Applied rewrites43.1%

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

    if -0.23499999999999999 < a < 0.209999999999999992

    1. Initial program 84.6%

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + {a}^{2} \cdot \left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}\right)\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left({a}^{2} \cdot \left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}\right) + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left({a}^{2} \cdot \left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}\right)\right) + a \cdot 1\right)}\right) \]
      3. associate-*r*N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{\left(a \cdot {a}^{2}\right) \cdot \left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}\right)} + a \cdot 1\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{\left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}\right) \cdot \left(a \cdot {a}^{2}\right)} + a \cdot 1\right)\right) \]
      5. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}\right) \cdot \left(a \cdot {a}^{2}\right) + \color{blue}{a}\right)\right) \]
      6. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(\frac{1}{3} + \frac{2}{15} \cdot {a}^{2}, a \cdot {a}^{2}, a\right)}\right) \]
      7. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{\frac{2}{15} \cdot {a}^{2} + \frac{1}{3}}, a \cdot {a}^{2}, a\right)\right) \]
      8. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{{a}^{2} \cdot \frac{2}{15}} + \frac{1}{3}, a \cdot {a}^{2}, a\right)\right) \]
      9. unpow2N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{\left(a \cdot a\right)} \cdot \frac{2}{15} + \frac{1}{3}, a \cdot {a}^{2}, a\right)\right) \]
      10. associate-*l*N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot \left(a \cdot \frac{2}{15}\right)} + \frac{1}{3}, a \cdot {a}^{2}, a\right)\right) \]
      11. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(a, a \cdot \frac{2}{15}, \frac{1}{3}\right)}, a \cdot {a}^{2}, a\right)\right) \]
      12. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, \color{blue}{a \cdot \frac{2}{15}}, \frac{1}{3}\right), a \cdot {a}^{2}, a\right)\right) \]
      13. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot \frac{2}{15}, \frac{1}{3}\right), \color{blue}{a \cdot {a}^{2}}, a\right)\right) \]
      14. unpow2N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot \frac{2}{15}, \frac{1}{3}\right), a \cdot \color{blue}{\left(a \cdot a\right)}, a\right)\right) \]
      15. lower-*.f6484.6

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot 0.13333333333333333, 0.3333333333333333\right), a \cdot \color{blue}{\left(a \cdot a\right)}, a\right)\right) \]
    5. Applied rewrites84.6%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(a, a \cdot 0.13333333333333333, 0.3333333333333333\right), a \cdot \left(a \cdot a\right), a\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 60.8% accurate, 1.5× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a\\ \mathbf{if}\;a \leq -0.19:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;a \leq 0.205:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (- (* (* x x) (/ 1.0 x)) (tan a))))
   (if (<= a -0.19)
     t_0
     (if (<= a 0.205)
       (+ x (- (tan (+ y z)) (fma a (* (* a a) 0.3333333333333333) a)))
       t_0))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double t_0 = ((x * x) * (1.0 / x)) - tan(a);
	double tmp;
	if (a <= -0.19) {
		tmp = t_0;
	} else if (a <= 0.205) {
		tmp = x + (tan((y + z)) - fma(a, ((a * a) * 0.3333333333333333), a));
	} else {
		tmp = t_0;
	}
	return tmp;
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	t_0 = Float64(Float64(Float64(x * x) * Float64(1.0 / x)) - tan(a))
	tmp = 0.0
	if (a <= -0.19)
		tmp = t_0;
	elseif (a <= 0.205)
		tmp = Float64(x + Float64(tan(Float64(y + z)) - fma(a, Float64(Float64(a * a) * 0.3333333333333333), a)));
	else
		tmp = t_0;
	end
	return tmp
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.19], t$95$0, If[LessEqual[a, 0.205], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(a * N[(N[(a * a), $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a\\
\mathbf{if}\;a \leq -0.19:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;a \leq 0.205:\\
\;\;\;\;x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 81.1%

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

        \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
      2. lift--.f64N/A

        \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} \]
      3. associate-+r-N/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) - \tan a} \]
      4. sub-negN/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      5. flip-+N/A

        \[\leadsto \color{blue}{\frac{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      6. div-invN/A

        \[\leadsto \color{blue}{\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)\right) \cdot \frac{1}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right)} \]
      8. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x} - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      10. pow2N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      11. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \color{blue}{\frac{1}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      13. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \frac{1}{\color{blue}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      14. lower-neg.f6480.5

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      2. lower-*.f6446.0

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

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

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, \mathsf{neg}\left(\tan a\right)\right) \]
    9. Step-by-step derivation
      1. lower-/.f6443.0

        \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    10. Applied rewrites43.0%

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    11. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      2. lift-neg.f64N/A

        \[\leadsto \left(x \cdot x\right) \cdot \frac{1}{x} + \color{blue}{\left(\mathsf{neg}\left(\tan a\right)\right)} \]
      3. unsub-negN/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
      4. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
      5. lower-*.f6443.1

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x}} - \tan a \]
    12. Applied rewrites43.1%

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

    if -0.19 < a < 0.204999999999999988

    1. Initial program 84.6%

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + a \cdot 1\right)}\right) \]
      3. associate-*r*N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{\left(a \cdot \frac{1}{3}\right) \cdot {a}^{2}} + a \cdot 1\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(\color{blue}{{a}^{2} \cdot \left(a \cdot \frac{1}{3}\right)} + a \cdot 1\right)\right) \]
      5. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left({a}^{2} \cdot \left(a \cdot \frac{1}{3}\right) + \color{blue}{a}\right)\right) \]
      6. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left({a}^{2}, a \cdot \frac{1}{3}, a\right)}\right) \]
      7. unpow2N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      8. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(\color{blue}{a \cdot a}, a \cdot \frac{1}{3}, a\right)\right) \]
      9. lower-*.f6484.5

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

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

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{a \cdot \left(1 + \frac{1}{3} \cdot {a}^{2}\right)}\right) \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - a \cdot \color{blue}{\left(\frac{1}{3} \cdot {a}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + a \cdot 1\right)}\right) \]
      3. *-rgt-identityN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \left(a \cdot \left(\frac{1}{3} \cdot {a}^{2}\right) + \color{blue}{a}\right)\right) \]
      4. lower-fma.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(a, \frac{1}{3} \cdot {a}^{2}, a\right)}\right) \]
      5. *-commutativeN/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \color{blue}{{a}^{2} \cdot \frac{1}{3}}, a\right)\right) \]
      6. lower-*.f64N/A

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \color{blue}{{a}^{2} \cdot \frac{1}{3}}, a\right)\right) \]
      7. unpow2N/A

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

        \[\leadsto x + \left(\tan \left(y + z\right) - \mathsf{fma}\left(a, \color{blue}{\left(a \cdot a\right)} \cdot 0.3333333333333333, a\right)\right) \]
    8. Applied rewrites84.5%

      \[\leadsto x + \left(\tan \left(y + z\right) - \color{blue}{\mathsf{fma}\left(a, \left(a \cdot a\right) \cdot 0.3333333333333333, a\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 36.3% accurate, 1.6× speedup?

\[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \begin{array}{l} \mathbf{if}\;z \leq 6500000000:\\ \;\;\;\;x + \left(\mathsf{fma}\left(z, 0.3333333333333333 \cdot \left(z \cdot z\right), z\right) - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{1}{x}, -a\right)\\ \end{array} \end{array} \]
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
(FPCore (x y z a)
 :precision binary64
 (if (<= z 6500000000.0)
   (+ x (- (fma z (* 0.3333333333333333 (* z z)) z) (tan a)))
   (fma (* x x) (/ 1.0 x) (- a))))
assert(x < y && y < z && z < a);
double code(double x, double y, double z, double a) {
	double tmp;
	if (z <= 6500000000.0) {
		tmp = x + (fma(z, (0.3333333333333333 * (z * z)), z) - tan(a));
	} else {
		tmp = fma((x * x), (1.0 / x), -a);
	}
	return tmp;
}
x, y, z, a = sort([x, y, z, a])
function code(x, y, z, a)
	tmp = 0.0
	if (z <= 6500000000.0)
		tmp = Float64(x + Float64(fma(z, Float64(0.3333333333333333 * Float64(z * z)), z) - tan(a)));
	else
		tmp = fma(Float64(x * x), Float64(1.0 / x), Float64(-a));
	end
	return tmp
end
NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
code[x_, y_, z_, a_] := If[LessEqual[z, 6500000000.0], N[(x + N[(N[(z * N[(0.3333333333333333 * N[(z * z), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision] + (-a)), $MachinePrecision]]
\begin{array}{l}
[x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6500000000:\\
\;\;\;\;x + \left(\mathsf{fma}\left(z, 0.3333333333333333 \cdot \left(z \cdot z\right), z\right) - \tan a\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{1}{x}, -a\right)\\


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

    1. Initial program 89.9%

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

        \[\leadsto x + \left(\tan \color{blue}{\left(y + z\right)} - \tan a\right) \]
      2. flip-+N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{y \cdot y - z \cdot z}{y - z}\right)} - \tan a\right) \]
      3. clear-numN/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{y - z}{y \cdot y - z \cdot z}}\right)} - \tan a\right) \]
      4. lower-/.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{y - z}{y \cdot y - z \cdot z}}\right)} - \tan a\right) \]
      5. clear-numN/A

        \[\leadsto x + \left(\tan \left(\frac{1}{\color{blue}{\frac{1}{\frac{y \cdot y - z \cdot z}{y - z}}}}\right) - \tan a\right) \]
      6. flip-+N/A

        \[\leadsto x + \left(\tan \left(\frac{1}{\frac{1}{\color{blue}{y + z}}}\right) - \tan a\right) \]
      7. lift-+.f64N/A

        \[\leadsto x + \left(\tan \left(\frac{1}{\frac{1}{\color{blue}{y + z}}}\right) - \tan a\right) \]
      8. lower-/.f6482.3

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

      \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{1}{y + z}}\right)} - \tan a\right) \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left(\frac{1}{\frac{1}{y + z}}\right)} - \tan a\right) \]
      2. inv-powN/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left(\frac{1}{y + z}\right)}^{-1}\right)} - \tan a\right) \]
      3. sqr-powN/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)} \cdot {\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)}\right)} - \tan a\right) \]
      4. pow2N/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left({\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right)} - \tan a\right) \]
      5. lower-pow.f64N/A

        \[\leadsto x + \left(\tan \color{blue}{\left({\left({\left(\frac{1}{y + z}\right)}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right)} - \tan a\right) \]
      6. lift-/.f64N/A

        \[\leadsto x + \left(\tan \left({\left({\color{blue}{\left(\frac{1}{y + z}\right)}}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right) - \tan a\right) \]
      7. inv-powN/A

        \[\leadsto x + \left(\tan \left({\left({\color{blue}{\left({\left(y + z\right)}^{-1}\right)}}^{\left(\frac{-1}{2}\right)}\right)}^{2}\right) - \tan a\right) \]
      8. pow-powN/A

        \[\leadsto x + \left(\tan \left({\color{blue}{\left({\left(y + z\right)}^{\left(-1 \cdot \frac{-1}{2}\right)}\right)}}^{2}\right) - \tan a\right) \]
      9. metadata-evalN/A

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\left(-1 \cdot \color{blue}{\frac{-1}{2}}\right)}\right)}^{2}\right) - \tan a\right) \]
      10. metadata-evalN/A

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\color{blue}{\frac{1}{2}}}\right)}^{2}\right) - \tan a\right) \]
      11. metadata-evalN/A

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\color{blue}{\left(\frac{1}{2}\right)}}\right)}^{2}\right) - \tan a\right) \]
      12. lower-pow.f64N/A

        \[\leadsto x + \left(\tan \left({\color{blue}{\left({\left(y + z\right)}^{\left(\frac{1}{2}\right)}\right)}}^{2}\right) - \tan a\right) \]
      13. metadata-eval23.2

        \[\leadsto x + \left(\tan \left({\left({\left(y + z\right)}^{\color{blue}{0.5}}\right)}^{2}\right) - \tan a\right) \]
    6. Applied rewrites23.2%

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

      \[\leadsto x + \left(\color{blue}{\frac{\sin z}{\cos z}} - \tan a\right) \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto x + \left(\color{blue}{\frac{\sin z}{\cos z}} - \tan a\right) \]
      2. lower-sin.f64N/A

        \[\leadsto x + \left(\frac{\color{blue}{\sin z}}{\cos z} - \tan a\right) \]
      3. lower-cos.f6463.8

        \[\leadsto x + \left(\frac{\sin z}{\color{blue}{\cos z}} - \tan a\right) \]
    9. Applied rewrites63.8%

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

      \[\leadsto x + \left(z \cdot \color{blue}{\left(1 + \frac{1}{3} \cdot {z}^{2}\right)} - \tan a\right) \]
    11. Step-by-step derivation
      1. Applied rewrites44.2%

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

      if 6.5e9 < z

      1. Initial program 61.7%

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

          \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
        2. lift--.f64N/A

          \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} \]
        3. associate-+r-N/A

          \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) - \tan a} \]
        4. sub-negN/A

          \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
        5. flip-+N/A

          \[\leadsto \color{blue}{\frac{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
        6. div-invN/A

          \[\leadsto \color{blue}{\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)\right) \cdot \frac{1}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
        7. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right)} \]
        8. lower--.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
        9. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x} - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
        10. pow2N/A

          \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
        11. lower-pow.f64N/A

          \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
        12. lower-/.f64N/A

          \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \color{blue}{\frac{1}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
        13. lower--.f64N/A

          \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \frac{1}{\color{blue}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
        14. lower-neg.f6461.4

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      6. Step-by-step derivation
        1. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
        2. lower-*.f6428.4

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

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

        \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, \mathsf{neg}\left(\tan a\right)\right) \]
      9. Step-by-step derivation
        1. lower-/.f6425.1

          \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
      10. Applied rewrites25.1%

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

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{-1 \cdot a}\right) \]
      12. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{\mathsf{neg}\left(a\right)}\right) \]
        2. lower-neg.f6414.6

          \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{-a}\right) \]
      13. Applied rewrites14.6%

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{-a}\right) \]
    12. Recombined 2 regimes into one program.
    13. Add Preprocessing

    Alternative 12: 41.8% accurate, 1.7× speedup?

    \[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a \end{array} \]
    NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
    (FPCore (x y z a) :precision binary64 (- (* (* x x) (/ 1.0 x)) (tan a)))
    assert(x < y && y < z && z < a);
    double code(double x, double y, double z, double a) {
    	return ((x * x) * (1.0 / x)) - tan(a);
    }
    
    NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
    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 * x) * (1.0d0 / x)) - tan(a)
    end function
    
    assert x < y && y < z && z < a;
    public static double code(double x, double y, double z, double a) {
    	return ((x * x) * (1.0 / x)) - Math.tan(a);
    }
    
    [x, y, z, a] = sort([x, y, z, a])
    def code(x, y, z, a):
    	return ((x * x) * (1.0 / x)) - math.tan(a)
    
    x, y, z, a = sort([x, y, z, a])
    function code(x, y, z, a)
    	return Float64(Float64(Float64(x * x) * Float64(1.0 / x)) - tan(a))
    end
    
    x, y, z, a = num2cell(sort([x, y, z, a])){:}
    function tmp = code(x, y, z, a)
    	tmp = ((x * x) * (1.0 / x)) - tan(a);
    end
    
    NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
    code[x_, y_, z_, a_] := N[(N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
    \\
    \left(x \cdot x\right) \cdot \frac{1}{x} - \tan a
    \end{array}
    
    Derivation
    1. Initial program 82.7%

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

        \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
      2. lift--.f64N/A

        \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} \]
      3. associate-+r-N/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) - \tan a} \]
      4. sub-negN/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      5. flip-+N/A

        \[\leadsto \color{blue}{\frac{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      6. div-invN/A

        \[\leadsto \color{blue}{\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)\right) \cdot \frac{1}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right)} \]
      8. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x} - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      10. pow2N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      11. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \color{blue}{\frac{1}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      13. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \frac{1}{\color{blue}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      14. lower-neg.f6482.2

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      2. lower-*.f6446.6

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

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

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, \mathsf{neg}\left(\tan a\right)\right) \]
    9. Step-by-step derivation
      1. lower-/.f6443.4

        \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    10. Applied rewrites43.4%

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    11. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      2. lift-neg.f64N/A

        \[\leadsto \left(x \cdot x\right) \cdot \frac{1}{x} + \color{blue}{\left(\mathsf{neg}\left(\tan a\right)\right)} \]
      3. unsub-negN/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
      4. lower--.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
      5. lower-*.f6443.5

        \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x}} - \tan a \]
    12. Applied rewrites43.5%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \frac{1}{x} - \tan a} \]
    13. Add Preprocessing

    Alternative 13: 22.6% accurate, 8.4× speedup?

    \[\begin{array}{l} [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\ \\ \mathsf{fma}\left(x \cdot x, \frac{1}{x}, -a\right) \end{array} \]
    NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
    (FPCore (x y z a) :precision binary64 (fma (* x x) (/ 1.0 x) (- a)))
    assert(x < y && y < z && z < a);
    double code(double x, double y, double z, double a) {
    	return fma((x * x), (1.0 / x), -a);
    }
    
    x, y, z, a = sort([x, y, z, a])
    function code(x, y, z, a)
    	return fma(Float64(x * x), Float64(1.0 / x), Float64(-a))
    end
    
    NOTE: x, y, z, and a should be sorted in increasing order before calling this function.
    code[x_, y_, z_, a_] := N[(N[(x * x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision] + (-a)), $MachinePrecision]
    
    \begin{array}{l}
    [x, y, z, a] = \mathsf{sort}([x, y, z, a])\\
    \\
    \mathsf{fma}\left(x \cdot x, \frac{1}{x}, -a\right)
    \end{array}
    
    Derivation
    1. Initial program 82.7%

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

        \[\leadsto \color{blue}{x + \left(\tan \left(y + z\right) - \tan a\right)} \]
      2. lift--.f64N/A

        \[\leadsto x + \color{blue}{\left(\tan \left(y + z\right) - \tan a\right)} \]
      3. associate-+r-N/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) - \tan a} \]
      4. sub-negN/A

        \[\leadsto \color{blue}{\left(x + \tan \left(y + z\right)\right) + \left(\mathsf{neg}\left(\tan a\right)\right)} \]
      5. flip-+N/A

        \[\leadsto \color{blue}{\frac{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      6. div-invN/A

        \[\leadsto \color{blue}{\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)\right) \cdot \frac{1}{x - \tan \left(y + z\right)}} + \left(\mathsf{neg}\left(\tan a\right)\right) \]
      7. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right)} \]
      8. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x - \tan \left(y + z\right) \cdot \tan \left(y + z\right)}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x} - \tan \left(y + z\right) \cdot \tan \left(y + z\right), \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      10. pow2N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      11. lower-pow.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - \color{blue}{{\tan \left(y + z\right)}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      12. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \color{blue}{\frac{1}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      13. lower--.f64N/A

        \[\leadsto \mathsf{fma}\left(x \cdot x - {\tan \left(y + z\right)}^{2}, \frac{1}{\color{blue}{x - \tan \left(y + z\right)}}, \mathsf{neg}\left(\tan a\right)\right) \]
      14. lower-neg.f6482.2

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{{x}^{2}}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
    6. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x}, \frac{1}{x - \tan \left(y + z\right)}, \mathsf{neg}\left(\tan a\right)\right) \]
      2. lower-*.f6446.6

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

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

      \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, \mathsf{neg}\left(\tan a\right)\right) \]
    9. Step-by-step derivation
      1. lower-/.f6443.4

        \[\leadsto \mathsf{fma}\left(x \cdot x, \color{blue}{\frac{1}{x}}, -\tan a\right) \]
    10. Applied rewrites43.4%

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

      \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{-1 \cdot a}\right) \]
    12. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{\mathsf{neg}\left(a\right)}\right) \]
      2. lower-neg.f6422.3

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{-a}\right) \]
    13. Applied rewrites22.3%

      \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{1}{x}, \color{blue}{-a}\right) \]
    14. Add Preprocessing

    Reproduce

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