tan-example (used to crash)

Percentage Accurate: 79.3% → 99.7%
Time: 20.4s
Alternatives: 11
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 79.3% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := 1 - \tan z \cdot \tan y\\
x + \left(\frac{\tan y}{t\_0} + \left(\frac{\tan z}{t\_0} - \tan a\right)\right)
\end{array}
\end{array}
Derivation
  1. Initial program 84.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. lift-tan.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 88.9% accurate, 0.3× speedup?

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

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

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

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


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

    1. Initial program 90.5%

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

      \[\leadsto \color{blue}{x \cdot \left(\left(1 + \frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)}\right) - \frac{\sin a}{x \cdot \cos a}\right)} \]
    4. Step-by-step derivation
      1. associate--l+N/A

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

        \[\leadsto x \cdot \color{blue}{\left(\left(\frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right) + 1\right)} \]
      3. distribute-rgt-inN/A

        \[\leadsto \color{blue}{\left(\frac{\sin \left(y + z\right)}{x \cdot \cos \left(y + z\right)} - \frac{\sin a}{x \cdot \cos a}\right) \cdot x + 1 \cdot x} \]
      4. *-lft-identityN/A

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

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

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

    if -2e-3 < (tan.f64 a) < 3.99999999999999971e-34

    1. Initial program 81.9%

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

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

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

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

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

        \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
      2. Step-by-step derivation
        1. Applied rewrites99.5%

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

        if 3.99999999999999971e-34 < (tan.f64 a)

        1. Initial program 81.0%

          \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
        2. Add Preprocessing
      3. Recombined 3 regimes into one program.
      4. Final simplification92.7%

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

      Alternative 3: 99.7% accurate, 0.4× speedup?

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

        \[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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

      Alternative 4: 89.0% accurate, 0.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -0.00018 \lor \neg \left(a \leq 10^{-31}\right):\\ \;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(-\left(\frac{\tan y + \tan z}{\mathsf{fma}\left(-\tan z, \tan y, 1\right) \cdot x} + 1\right), x, a\right)\\ \end{array} \end{array} \]
      (FPCore (x y z a)
       :precision binary64
       (if (or (<= a -0.00018) (not (<= a 1e-31)))
         (+ x (- (tan (+ y z)) (tan a)))
         (-
          (fma
           (- (+ (/ (+ (tan y) (tan z)) (* (fma (- (tan z)) (tan y) 1.0) x)) 1.0))
           x
           a))))
      double code(double x, double y, double z, double a) {
      	double tmp;
      	if ((a <= -0.00018) || !(a <= 1e-31)) {
      		tmp = x + (tan((y + z)) - tan(a));
      	} else {
      		tmp = -fma(-(((tan(y) + tan(z)) / (fma(-tan(z), tan(y), 1.0) * x)) + 1.0), x, a);
      	}
      	return tmp;
      }
      
      function code(x, y, z, a)
      	tmp = 0.0
      	if ((a <= -0.00018) || !(a <= 1e-31))
      		tmp = Float64(x + Float64(tan(Float64(y + z)) - tan(a)));
      	else
      		tmp = Float64(-fma(Float64(-Float64(Float64(Float64(tan(y) + tan(z)) / Float64(fma(Float64(-tan(z)), tan(y), 1.0) * x)) + 1.0)), x, a));
      	end
      	return tmp
      end
      
      code[x_, y_, z_, a_] := If[Or[LessEqual[a, -0.00018], N[Not[LessEqual[a, 1e-31]], $MachinePrecision]], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[((-N[(N[(N[(N[Tan[y], $MachinePrecision] + N[Tan[z], $MachinePrecision]), $MachinePrecision] / N[(N[((-N[Tan[z], $MachinePrecision]) * N[Tan[y], $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]) * x + a), $MachinePrecision])]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;a \leq -0.00018 \lor \neg \left(a \leq 10^{-31}\right):\\
      \;\;\;\;x + \left(\tan \left(y + z\right) - \tan a\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;-\mathsf{fma}\left(-\left(\frac{\tan y + \tan z}{\mathsf{fma}\left(-\tan z, \tan y, 1\right) \cdot x} + 1\right), x, a\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if a < -1.80000000000000011e-4 or 1e-31 < a

        1. Initial program 86.0%

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

        if -1.80000000000000011e-4 < a < 1e-31

        1. Initial program 81.9%

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

          \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
        4. Step-by-step derivation
          1. mul-1-negN/A

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

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

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

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

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

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

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

            \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
          2. Step-by-step derivation
            1. Applied rewrites99.5%

              \[\leadsto -\mathsf{fma}\left(\frac{\tan y + \tan z}{\mathsf{fma}\left(-\tan z, \tan y, 1\right) \cdot \left(-x\right)} - 1, x, a\right) \]
          3. Recombined 2 regimes into one program.
          4. Final simplification92.7%

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

          Alternative 5: 79.3% accurate, 1.0× speedup?

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

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

          Alternative 6: 50.7% accurate, 1.3× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\ \;\;\;\;-\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, 0.05396825396825397, 0.13333333333333333\right), a \cdot a, 0.3333333333333333\right), a \cdot a, 1\right) \cdot a - x\right)\\ \end{array} \end{array} \]
          (FPCore (x y z a)
           :precision binary64
           (if (or (<= a -1.55) (not (<= a 1.55)))
             (- (- x))
             (-
              (tan (+ z y))
              (-
               (*
                (fma
                 (fma
                  (fma (* a a) 0.05396825396825397 0.13333333333333333)
                  (* a a)
                  0.3333333333333333)
                 (* a a)
                 1.0)
                a)
               x))))
          double code(double x, double y, double z, double a) {
          	double tmp;
          	if ((a <= -1.55) || !(a <= 1.55)) {
          		tmp = -(-x);
          	} else {
          		tmp = tan((z + y)) - ((fma(fma(fma((a * a), 0.05396825396825397, 0.13333333333333333), (a * a), 0.3333333333333333), (a * a), 1.0) * a) - x);
          	}
          	return tmp;
          }
          
          function code(x, y, z, a)
          	tmp = 0.0
          	if ((a <= -1.55) || !(a <= 1.55))
          		tmp = Float64(-Float64(-x));
          	else
          		tmp = Float64(tan(Float64(z + y)) - Float64(Float64(fma(fma(fma(Float64(a * a), 0.05396825396825397, 0.13333333333333333), Float64(a * a), 0.3333333333333333), Float64(a * a), 1.0) * a) - x));
          	end
          	return tmp
          end
          
          code[x_, y_, z_, a_] := If[Or[LessEqual[a, -1.55], N[Not[LessEqual[a, 1.55]], $MachinePrecision]], (-(-x)), N[(N[Tan[N[(z + y), $MachinePrecision]], $MachinePrecision] - N[(N[(N[(N[(N[(N[(a * a), $MachinePrecision] * 0.05396825396825397 + 0.13333333333333333), $MachinePrecision] * N[(a * a), $MachinePrecision] + 0.3333333333333333), $MachinePrecision] * N[(a * a), $MachinePrecision] + 1.0), $MachinePrecision] * a), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\
          \;\;\;\;-\left(-x\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, 0.05396825396825397, 0.13333333333333333\right), a \cdot a, 0.3333333333333333\right), a \cdot a, 1\right) \cdot a - x\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if a < -1.55000000000000004 or 1.55000000000000004 < a

            1. Initial program 84.9%

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

              \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
            4. Step-by-step derivation
              1. mul-1-negN/A

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

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

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

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

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

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

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

                \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
              2. Taylor expanded in y around 0

                \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos z \cdot x} - 1, x, a\right) \]
              3. Step-by-step derivation
                1. Applied rewrites3.5%

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

                  \[\leadsto --1 \cdot x \]
                3. Step-by-step derivation
                  1. Applied rewrites22.8%

                    \[\leadsto -\left(-x\right) \]

                  if -1.55000000000000004 < a < 1.55000000000000004

                  1. Initial program 83.2%

                    \[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. associate-+l-N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\ \;\;\;\;-\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, 0.05396825396825397, 0.13333333333333333\right), a \cdot a, 0.3333333333333333\right), a \cdot a, 1\right) \cdot a - x\right)\\ \end{array} \]
                6. Add Preprocessing

                Alternative 7: 50.7% accurate, 1.4× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\ \;\;\;\;-\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, 0.13333333333333333, 0.3333333333333333\right), a \cdot a, 1\right) \cdot a - x\right)\\ \end{array} \end{array} \]
                (FPCore (x y z a)
                 :precision binary64
                 (if (or (<= a -1.55) (not (<= a 1.55)))
                   (- (- x))
                   (-
                    (tan (+ z y))
                    (-
                     (*
                      (fma (fma (* a a) 0.13333333333333333 0.3333333333333333) (* a a) 1.0)
                      a)
                     x))))
                double code(double x, double y, double z, double a) {
                	double tmp;
                	if ((a <= -1.55) || !(a <= 1.55)) {
                		tmp = -(-x);
                	} else {
                		tmp = tan((z + y)) - ((fma(fma((a * a), 0.13333333333333333, 0.3333333333333333), (a * a), 1.0) * a) - x);
                	}
                	return tmp;
                }
                
                function code(x, y, z, a)
                	tmp = 0.0
                	if ((a <= -1.55) || !(a <= 1.55))
                		tmp = Float64(-Float64(-x));
                	else
                		tmp = Float64(tan(Float64(z + y)) - Float64(Float64(fma(fma(Float64(a * a), 0.13333333333333333, 0.3333333333333333), Float64(a * a), 1.0) * a) - x));
                	end
                	return tmp
                end
                
                code[x_, y_, z_, a_] := If[Or[LessEqual[a, -1.55], N[Not[LessEqual[a, 1.55]], $MachinePrecision]], (-(-x)), N[(N[Tan[N[(z + y), $MachinePrecision]], $MachinePrecision] - N[(N[(N[(N[(N[(a * a), $MachinePrecision] * 0.13333333333333333 + 0.3333333333333333), $MachinePrecision] * N[(a * a), $MachinePrecision] + 1.0), $MachinePrecision] * a), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\
                \;\;\;\;-\left(-x\right)\\
                
                \mathbf{else}:\\
                \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, 0.13333333333333333, 0.3333333333333333\right), a \cdot a, 1\right) \cdot a - x\right)\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if a < -1.55000000000000004 or 1.55000000000000004 < a

                  1. Initial program 84.9%

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

                    \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
                  4. Step-by-step derivation
                    1. mul-1-negN/A

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

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

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

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

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

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

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

                      \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
                    2. Taylor expanded in y around 0

                      \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos z \cdot x} - 1, x, a\right) \]
                    3. Step-by-step derivation
                      1. Applied rewrites3.5%

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

                        \[\leadsto --1 \cdot x \]
                      3. Step-by-step derivation
                        1. Applied rewrites22.8%

                          \[\leadsto -\left(-x\right) \]

                        if -1.55000000000000004 < a < 1.55000000000000004

                        1. Initial program 83.2%

                          \[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. associate-+l-N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\ \;\;\;\;-\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(\mathsf{fma}\left(a \cdot a, 0.13333333333333333, 0.3333333333333333\right), a \cdot a, 1\right) \cdot a - x\right)\\ \end{array} \]
                      6. Add Preprocessing

                      Alternative 8: 50.6% accurate, 1.5× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\ \;\;\;\;-\left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(a \cdot a, 0.3333333333333333, 1\right) \cdot a - x\right)\\ \end{array} \end{array} \]
                      (FPCore (x y z a)
                       :precision binary64
                       (if (or (<= a -1.55) (not (<= a 1.55)))
                         (- (- x))
                         (- (tan (+ z y)) (- (* (fma (* a a) 0.3333333333333333 1.0) a) x))))
                      double code(double x, double y, double z, double a) {
                      	double tmp;
                      	if ((a <= -1.55) || !(a <= 1.55)) {
                      		tmp = -(-x);
                      	} else {
                      		tmp = tan((z + y)) - ((fma((a * a), 0.3333333333333333, 1.0) * a) - x);
                      	}
                      	return tmp;
                      }
                      
                      function code(x, y, z, a)
                      	tmp = 0.0
                      	if ((a <= -1.55) || !(a <= 1.55))
                      		tmp = Float64(-Float64(-x));
                      	else
                      		tmp = Float64(tan(Float64(z + y)) - Float64(Float64(fma(Float64(a * a), 0.3333333333333333, 1.0) * a) - x));
                      	end
                      	return tmp
                      end
                      
                      code[x_, y_, z_, a_] := If[Or[LessEqual[a, -1.55], N[Not[LessEqual[a, 1.55]], $MachinePrecision]], (-(-x)), N[(N[Tan[N[(z + y), $MachinePrecision]], $MachinePrecision] - N[(N[(N[(N[(a * a), $MachinePrecision] * 0.3333333333333333 + 1.0), $MachinePrecision] * a), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;a \leq -1.55 \lor \neg \left(a \leq 1.55\right):\\
                      \;\;\;\;-\left(-x\right)\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\tan \left(z + y\right) - \left(\mathsf{fma}\left(a \cdot a, 0.3333333333333333, 1\right) \cdot a - x\right)\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if a < -1.55000000000000004 or 1.55000000000000004 < a

                        1. Initial program 84.9%

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

                          \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
                        4. Step-by-step derivation
                          1. mul-1-negN/A

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

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

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

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

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

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

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

                            \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
                          2. Taylor expanded in y around 0

                            \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos z \cdot x} - 1, x, a\right) \]
                          3. Step-by-step derivation
                            1. Applied rewrites3.5%

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

                              \[\leadsto --1 \cdot x \]
                            3. Step-by-step derivation
                              1. Applied rewrites22.8%

                                \[\leadsto -\left(-x\right) \]

                              if -1.55000000000000004 < a < 1.55000000000000004

                              1. Initial program 83.2%

                                \[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. associate-+l-N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            Alternative 9: 50.5% accurate, 1.7× speedup?

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

                              1. Initial program 84.9%

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

                                \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
                              4. Step-by-step derivation
                                1. mul-1-negN/A

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

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

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

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

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

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

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

                                  \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
                                2. Taylor expanded in y around 0

                                  \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos z \cdot x} - 1, x, a\right) \]
                                3. Step-by-step derivation
                                  1. Applied rewrites3.5%

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

                                    \[\leadsto --1 \cdot x \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites22.8%

                                      \[\leadsto -\left(-x\right) \]

                                    if -1.55000000000000004 < a < 1.55000000000000004

                                    1. Initial program 83.2%

                                      \[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. associate-+l-N/A

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

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

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

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

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

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

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

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

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

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

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

                                  Alternative 10: 31.8% accurate, 42.0× speedup?

                                  \[\begin{array}{l} \\ -\left(-x\right) \end{array} \]
                                  (FPCore (x y z a) :precision binary64 (- (- x)))
                                  double code(double x, double y, double z, double a) {
                                  	return -(-x);
                                  }
                                  
                                  real(8) function code(x, y, z, a)
                                      real(8), intent (in) :: x
                                      real(8), intent (in) :: y
                                      real(8), intent (in) :: z
                                      real(8), intent (in) :: a
                                      code = -(-x)
                                  end function
                                  
                                  public static double code(double x, double y, double z, double a) {
                                  	return -(-x);
                                  }
                                  
                                  def code(x, y, z, a):
                                  	return -(-x)
                                  
                                  function code(x, y, z, a)
                                  	return Float64(-Float64(-x))
                                  end
                                  
                                  function tmp = code(x, y, z, a)
                                  	tmp = -(-x);
                                  end
                                  
                                  code[x_, y_, z_, a_] := (-(-x))
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  -\left(-x\right)
                                  \end{array}
                                  
                                  Derivation
                                  1. Initial program 84.0%

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

                                    \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
                                  4. Step-by-step derivation
                                    1. mul-1-negN/A

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

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

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

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

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

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

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

                                      \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos \left(z + y\right) \cdot x} - 1, x, a\right) \]
                                    2. Taylor expanded in y around 0

                                      \[\leadsto -\mathsf{fma}\left(\frac{-\sin \left(z + y\right)}{\cos z \cdot x} - 1, x, a\right) \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites35.4%

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

                                        \[\leadsto --1 \cdot x \]
                                      3. Step-by-step derivation
                                        1. Applied rewrites33.0%

                                          \[\leadsto -\left(-x\right) \]
                                        2. Add Preprocessing

                                        Alternative 11: 3.5% accurate, 70.0× speedup?

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

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

                                          \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(-1 \cdot \frac{\frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} - \frac{\sin a}{\cos a}}{x} - 1\right)\right)} \]
                                        4. Step-by-step derivation
                                          1. mul-1-negN/A

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

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

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

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

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

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

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

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

                                            \[\leadsto -1 \cdot a \]
                                          3. Step-by-step derivation
                                            1. Applied rewrites3.7%

                                              \[\leadsto -a \]
                                            2. Add Preprocessing

                                            Reproduce

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