tan-example (used to crash)

Percentage Accurate: 79.4% → 99.7%
Time: 22.0s
Alternatives: 16
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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    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}

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 16 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.4% 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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    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} \\ \begin{array}{l} t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\ x + \left(\left(\frac{\cos z \cdot \sin y}{t\_0} + \frac{\cos y \cdot \sin z}{t\_0}\right) - \tan a\right) \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (- (* (cos y) (cos z)) (* (sin y) (sin z)))))
   (+
    x
    (- (+ (/ (* (cos z) (sin y)) t_0) (/ (* (cos y) (sin z)) t_0)) (tan a)))))
double code(double x, double y, double z, double a) {
	double t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	return x + ((((cos(z) * sin(y)) / t_0) + ((cos(y) * sin(z)) / t_0)) - tan(a));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    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 = (cos(y) * cos(z)) - (sin(y) * sin(z))
    code = x + ((((cos(z) * sin(y)) / t_0) + ((cos(y) * sin(z)) / t_0)) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = (Math.cos(y) * Math.cos(z)) - (Math.sin(y) * Math.sin(z));
	return x + ((((Math.cos(z) * Math.sin(y)) / t_0) + ((Math.cos(y) * Math.sin(z)) / t_0)) - Math.tan(a));
}
def code(x, y, z, a):
	t_0 = (math.cos(y) * math.cos(z)) - (math.sin(y) * math.sin(z))
	return x + ((((math.cos(z) * math.sin(y)) / t_0) + ((math.cos(y) * math.sin(z)) / t_0)) - math.tan(a))
function code(x, y, z, a)
	t_0 = Float64(Float64(cos(y) * cos(z)) - Float64(sin(y) * sin(z)))
	return Float64(x + Float64(Float64(Float64(Float64(cos(z) * sin(y)) / t_0) + Float64(Float64(cos(y) * sin(z)) / t_0)) - tan(a)))
end
function tmp = code(x, y, z, a)
	t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	tmp = x + ((((cos(z) * sin(y)) / t_0) + ((cos(y) * sin(z)) / t_0)) - tan(a));
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x + N[(N[(N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] + N[(N[(N[Cos[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\
x + \left(\left(\frac{\cos z \cdot \sin y}{t\_0} + \frac{\cos y \cdot \sin z}{t\_0}\right) - \tan a\right)
\end{array}
\end{array}
Derivation
  1. Initial program 79.4%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.8%

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

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

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

Alternative 2: 89.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\ t_1 := \frac{\cos z \cdot \sin y}{t\_0}\\ t_2 := \cos y \cdot \sin z\\ t_3 := x + \left(\left(t\_1 + \frac{t\_2}{\cos \left(y + z\right)}\right) - \tan a\right)\\ \mathbf{if}\;a \leq -0.0225:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;a \leq 0.0076:\\ \;\;\;\;x + \mathsf{fma}\left(a, -0.3333333333333333 \cdot {a}^{2} - 1, \frac{t\_2}{t\_0} + t\_1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (- (* (cos y) (cos z)) (* (sin y) (sin z))))
        (t_1 (/ (* (cos z) (sin y)) t_0))
        (t_2 (* (cos y) (sin z)))
        (t_3 (+ x (- (+ t_1 (/ t_2 (cos (+ y z)))) (tan a)))))
   (if (<= a -0.0225)
     t_3
     (if (<= a 0.0076)
       (+
        x
        (fma
         a
         (- (* -0.3333333333333333 (pow a 2.0)) 1.0)
         (+ (/ t_2 t_0) t_1)))
       t_3))))
double code(double x, double y, double z, double a) {
	double t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	double t_1 = (cos(z) * sin(y)) / t_0;
	double t_2 = cos(y) * sin(z);
	double t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a));
	double tmp;
	if (a <= -0.0225) {
		tmp = t_3;
	} else if (a <= 0.0076) {
		tmp = x + fma(a, ((-0.3333333333333333 * pow(a, 2.0)) - 1.0), ((t_2 / t_0) + t_1));
	} else {
		tmp = t_3;
	}
	return tmp;
}
function code(x, y, z, a)
	t_0 = Float64(Float64(cos(y) * cos(z)) - Float64(sin(y) * sin(z)))
	t_1 = Float64(Float64(cos(z) * sin(y)) / t_0)
	t_2 = Float64(cos(y) * sin(z))
	t_3 = Float64(x + Float64(Float64(t_1 + Float64(t_2 / cos(Float64(y + z)))) - tan(a)))
	tmp = 0.0
	if (a <= -0.0225)
		tmp = t_3;
	elseif (a <= 0.0076)
		tmp = Float64(x + fma(a, Float64(Float64(-0.3333333333333333 * (a ^ 2.0)) - 1.0), Float64(Float64(t_2 / t_0) + t_1)));
	else
		tmp = t_3;
	end
	return tmp
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x + N[(N[(t$95$1 + N[(t$95$2 / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, -0.0225], t$95$3, If[LessEqual[a, 0.0076], N[(x + N[(a * N[(N[(-0.3333333333333333 * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] + N[(N[(t$95$2 / t$95$0), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\
t_1 := \frac{\cos z \cdot \sin y}{t\_0}\\
t_2 := \cos y \cdot \sin z\\
t_3 := x + \left(\left(t\_1 + \frac{t\_2}{\cos \left(y + z\right)}\right) - \tan a\right)\\
\mathbf{if}\;a \leq -0.0225:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;a \leq 0.0076:\\
\;\;\;\;x + \mathsf{fma}\left(a, -0.3333333333333333 \cdot {a}^{2} - 1, \frac{t\_2}{t\_0} + t\_1\right)\\

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


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

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Applied rewrites79.8%

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

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

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

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

    if -0.022499999999999999 < a < 0.00759999999999999998

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Applied rewrites79.8%

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

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

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

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

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

Alternative 3: 89.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\ t_1 := \frac{\cos z \cdot \sin y}{t\_0}\\ t_2 := \cos y \cdot \sin z\\ t_3 := x + \left(\left(t\_1 + \frac{t\_2}{\cos \left(y + z\right)}\right) - \tan a\right)\\ \mathbf{if}\;\tan a \leq -0.02:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;\tan a \leq 0.0002:\\ \;\;\;\;x + \left(\left(t\_1 + \frac{t\_2}{t\_0}\right) - a\right)\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (- (* (cos y) (cos z)) (* (sin y) (sin z))))
        (t_1 (/ (* (cos z) (sin y)) t_0))
        (t_2 (* (cos y) (sin z)))
        (t_3 (+ x (- (+ t_1 (/ t_2 (cos (+ y z)))) (tan a)))))
   (if (<= (tan a) -0.02)
     t_3
     (if (<= (tan a) 0.0002) (+ x (- (+ t_1 (/ t_2 t_0)) a)) t_3))))
double code(double x, double y, double z, double a) {
	double t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	double t_1 = (cos(z) * sin(y)) / t_0;
	double t_2 = cos(y) * sin(z);
	double t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a));
	double tmp;
	if (tan(a) <= -0.02) {
		tmp = t_3;
	} else if (tan(a) <= 0.0002) {
		tmp = x + ((t_1 + (t_2 / t_0)) - a);
	} else {
		tmp = t_3;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z))
    t_1 = (cos(z) * sin(y)) / t_0
    t_2 = cos(y) * sin(z)
    t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a))
    if (tan(a) <= (-0.02d0)) then
        tmp = t_3
    else if (tan(a) <= 0.0002d0) then
        tmp = x + ((t_1 + (t_2 / t_0)) - a)
    else
        tmp = t_3
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = (Math.cos(y) * Math.cos(z)) - (Math.sin(y) * Math.sin(z));
	double t_1 = (Math.cos(z) * Math.sin(y)) / t_0;
	double t_2 = Math.cos(y) * Math.sin(z);
	double t_3 = x + ((t_1 + (t_2 / Math.cos((y + z)))) - Math.tan(a));
	double tmp;
	if (Math.tan(a) <= -0.02) {
		tmp = t_3;
	} else if (Math.tan(a) <= 0.0002) {
		tmp = x + ((t_1 + (t_2 / t_0)) - a);
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = (math.cos(y) * math.cos(z)) - (math.sin(y) * math.sin(z))
	t_1 = (math.cos(z) * math.sin(y)) / t_0
	t_2 = math.cos(y) * math.sin(z)
	t_3 = x + ((t_1 + (t_2 / math.cos((y + z)))) - math.tan(a))
	tmp = 0
	if math.tan(a) <= -0.02:
		tmp = t_3
	elif math.tan(a) <= 0.0002:
		tmp = x + ((t_1 + (t_2 / t_0)) - a)
	else:
		tmp = t_3
	return tmp
function code(x, y, z, a)
	t_0 = Float64(Float64(cos(y) * cos(z)) - Float64(sin(y) * sin(z)))
	t_1 = Float64(Float64(cos(z) * sin(y)) / t_0)
	t_2 = Float64(cos(y) * sin(z))
	t_3 = Float64(x + Float64(Float64(t_1 + Float64(t_2 / cos(Float64(y + z)))) - tan(a)))
	tmp = 0.0
	if (tan(a) <= -0.02)
		tmp = t_3;
	elseif (tan(a) <= 0.0002)
		tmp = Float64(x + Float64(Float64(t_1 + Float64(t_2 / t_0)) - a));
	else
		tmp = t_3;
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	t_1 = (cos(z) * sin(y)) / t_0;
	t_2 = cos(y) * sin(z);
	t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a));
	tmp = 0.0;
	if (tan(a) <= -0.02)
		tmp = t_3;
	elseif (tan(a) <= 0.0002)
		tmp = x + ((t_1 + (t_2 / t_0)) - a);
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x + N[(N[(t$95$1 + N[(t$95$2 / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.02], t$95$3, If[LessEqual[N[Tan[a], $MachinePrecision], 0.0002], N[(x + N[(N[(t$95$1 + N[(t$95$2 / t$95$0), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\
t_1 := \frac{\cos z \cdot \sin y}{t\_0}\\
t_2 := \cos y \cdot \sin z\\
t_3 := x + \left(\left(t\_1 + \frac{t\_2}{\cos \left(y + z\right)}\right) - \tan a\right)\\
\mathbf{if}\;\tan a \leq -0.02:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;\tan a \leq 0.0002:\\
\;\;\;\;x + \left(\left(t\_1 + \frac{t\_2}{t\_0}\right) - a\right)\\

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


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

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Applied rewrites79.8%

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

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

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

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

    if -0.0200000000000000004 < (tan.f64 a) < 2.0000000000000001e-4

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Applied rewrites79.8%

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

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

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

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

      \[\leadsto x + \left(\left(\frac{\cos z \cdot \sin y}{\cos y \cdot \cos z - \sin y \cdot \sin z} + \frac{\cos y \cdot \sin z}{\cos y \cdot \cos z - \sin y \cdot \sin z}\right) - \color{blue}{a}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 89.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\ t_1 := \frac{\cos z \cdot \sin y}{t\_0}\\ t_2 := \cos y \cdot \sin z\\ t_3 := x + \left(\left(t\_1 + \frac{t\_2}{\cos \left(y + z\right)}\right) - \tan a\right)\\ \mathbf{if}\;\tan a \leq -0.02:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;\tan a \leq 10^{-20}:\\ \;\;\;\;x + \left(\frac{t\_2}{t\_0} + t\_1\right)\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (- (* (cos y) (cos z)) (* (sin y) (sin z))))
        (t_1 (/ (* (cos z) (sin y)) t_0))
        (t_2 (* (cos y) (sin z)))
        (t_3 (+ x (- (+ t_1 (/ t_2 (cos (+ y z)))) (tan a)))))
   (if (<= (tan a) -0.02)
     t_3
     (if (<= (tan a) 1e-20) (+ x (+ (/ t_2 t_0) t_1)) t_3))))
double code(double x, double y, double z, double a) {
	double t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	double t_1 = (cos(z) * sin(y)) / t_0;
	double t_2 = cos(y) * sin(z);
	double t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a));
	double tmp;
	if (tan(a) <= -0.02) {
		tmp = t_3;
	} else if (tan(a) <= 1e-20) {
		tmp = x + ((t_2 / t_0) + t_1);
	} else {
		tmp = t_3;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z))
    t_1 = (cos(z) * sin(y)) / t_0
    t_2 = cos(y) * sin(z)
    t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a))
    if (tan(a) <= (-0.02d0)) then
        tmp = t_3
    else if (tan(a) <= 1d-20) then
        tmp = x + ((t_2 / t_0) + t_1)
    else
        tmp = t_3
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = (Math.cos(y) * Math.cos(z)) - (Math.sin(y) * Math.sin(z));
	double t_1 = (Math.cos(z) * Math.sin(y)) / t_0;
	double t_2 = Math.cos(y) * Math.sin(z);
	double t_3 = x + ((t_1 + (t_2 / Math.cos((y + z)))) - Math.tan(a));
	double tmp;
	if (Math.tan(a) <= -0.02) {
		tmp = t_3;
	} else if (Math.tan(a) <= 1e-20) {
		tmp = x + ((t_2 / t_0) + t_1);
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = (math.cos(y) * math.cos(z)) - (math.sin(y) * math.sin(z))
	t_1 = (math.cos(z) * math.sin(y)) / t_0
	t_2 = math.cos(y) * math.sin(z)
	t_3 = x + ((t_1 + (t_2 / math.cos((y + z)))) - math.tan(a))
	tmp = 0
	if math.tan(a) <= -0.02:
		tmp = t_3
	elif math.tan(a) <= 1e-20:
		tmp = x + ((t_2 / t_0) + t_1)
	else:
		tmp = t_3
	return tmp
function code(x, y, z, a)
	t_0 = Float64(Float64(cos(y) * cos(z)) - Float64(sin(y) * sin(z)))
	t_1 = Float64(Float64(cos(z) * sin(y)) / t_0)
	t_2 = Float64(cos(y) * sin(z))
	t_3 = Float64(x + Float64(Float64(t_1 + Float64(t_2 / cos(Float64(y + z)))) - tan(a)))
	tmp = 0.0
	if (tan(a) <= -0.02)
		tmp = t_3;
	elseif (tan(a) <= 1e-20)
		tmp = Float64(x + Float64(Float64(t_2 / t_0) + t_1));
	else
		tmp = t_3;
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = (cos(y) * cos(z)) - (sin(y) * sin(z));
	t_1 = (cos(z) * sin(y)) / t_0;
	t_2 = cos(y) * sin(z);
	t_3 = x + ((t_1 + (t_2 / cos((y + z)))) - tan(a));
	tmp = 0.0;
	if (tan(a) <= -0.02)
		tmp = t_3;
	elseif (tan(a) <= 1e-20)
		tmp = x + ((t_2 / t_0) + t_1);
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Cos[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x + N[(N[(t$95$1 + N[(t$95$2 / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.02], t$95$3, If[LessEqual[N[Tan[a], $MachinePrecision], 1e-20], N[(x + N[(N[(t$95$2 / t$95$0), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos y \cdot \cos z - \sin y \cdot \sin z\\
t_1 := \frac{\cos z \cdot \sin y}{t\_0}\\
t_2 := \cos y \cdot \sin z\\
t_3 := x + \left(\left(t\_1 + \frac{t\_2}{\cos \left(y + z\right)}\right) - \tan a\right)\\
\mathbf{if}\;\tan a \leq -0.02:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;\tan a \leq 10^{-20}:\\
\;\;\;\;x + \left(\frac{t\_2}{t\_0} + t\_1\right)\\

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


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

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Applied rewrites79.8%

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

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

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

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

    if -0.0200000000000000004 < (tan.f64 a) < 9.99999999999999945e-21

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. Applied rewrites79.8%

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

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

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

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

      \[\leadsto \color{blue}{x + \left(\frac{\cos y \cdot \sin z}{\cos y \cdot \cos z - \sin y \cdot \sin z} + \frac{\cos z \cdot \sin y}{\cos y \cdot \cos z - \sin y \cdot \sin z}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 80.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ x + \left(\left(\frac{\cos z \cdot \sin y}{\cos y \cdot \cos z - \sin y \cdot \sin z} + \frac{\cos y \cdot \sin z}{\cos \left(y + z\right)}\right) - \tan a\right) \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (+
  x
  (-
   (+
    (/ (* (cos z) (sin y)) (- (* (cos y) (cos z)) (* (sin y) (sin z))))
    (/ (* (cos y) (sin z)) (cos (+ y z))))
   (tan a))))
double code(double x, double y, double z, double a) {
	return x + ((((cos(z) * sin(y)) / ((cos(y) * cos(z)) - (sin(y) * sin(z)))) + ((cos(y) * sin(z)) / cos((y + z)))) - tan(a));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + ((((cos(z) * sin(y)) / ((cos(y) * cos(z)) - (sin(y) * sin(z)))) + ((cos(y) * sin(z)) / cos((y + z)))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	return x + ((((Math.cos(z) * Math.sin(y)) / ((Math.cos(y) * Math.cos(z)) - (Math.sin(y) * Math.sin(z)))) + ((Math.cos(y) * Math.sin(z)) / Math.cos((y + z)))) - Math.tan(a));
}
def code(x, y, z, a):
	return x + ((((math.cos(z) * math.sin(y)) / ((math.cos(y) * math.cos(z)) - (math.sin(y) * math.sin(z)))) + ((math.cos(y) * math.sin(z)) / math.cos((y + z)))) - math.tan(a))
function code(x, y, z, a)
	return Float64(x + Float64(Float64(Float64(Float64(cos(z) * sin(y)) / Float64(Float64(cos(y) * cos(z)) - Float64(sin(y) * sin(z)))) + Float64(Float64(cos(y) * sin(z)) / cos(Float64(y + z)))) - tan(a)))
end
function tmp = code(x, y, z, a)
	tmp = x + ((((cos(z) * sin(y)) / ((cos(y) * cos(z)) - (sin(y) * sin(z)))) + ((cos(y) * sin(z)) / cos((y + z)))) - tan(a));
end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.8%

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

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

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

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

Alternative 6: 80.6% accurate, 0.2× speedup?

\[\begin{array}{l} \\ x + \left(\left(\frac{\cos z \cdot \sin y}{\cos \left(y + z\right)} + \frac{\cos y \cdot \sin z}{\cos y \cdot \cos z - \sin y \cdot \sin z}\right) - \tan a\right) \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (+
  x
  (-
   (+
    (/ (* (cos z) (sin y)) (cos (+ y z)))
    (/ (* (cos y) (sin z)) (- (* (cos y) (cos z)) (* (sin y) (sin z)))))
   (tan a))))
double code(double x, double y, double z, double a) {
	return x + ((((cos(z) * sin(y)) / cos((y + z))) + ((cos(y) * sin(z)) / ((cos(y) * cos(z)) - (sin(y) * sin(z))))) - tan(a));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + ((((cos(z) * sin(y)) / cos((y + z))) + ((cos(y) * sin(z)) / ((cos(y) * cos(z)) - (sin(y) * sin(z))))) - tan(a))
end function
public static double code(double x, double y, double z, double a) {
	return x + ((((Math.cos(z) * Math.sin(y)) / Math.cos((y + z))) + ((Math.cos(y) * Math.sin(z)) / ((Math.cos(y) * Math.cos(z)) - (Math.sin(y) * Math.sin(z))))) - Math.tan(a));
}
def code(x, y, z, a):
	return x + ((((math.cos(z) * math.sin(y)) / math.cos((y + z))) + ((math.cos(y) * math.sin(z)) / ((math.cos(y) * math.cos(z)) - (math.sin(y) * math.sin(z))))) - math.tan(a))
function code(x, y, z, a)
	return Float64(x + Float64(Float64(Float64(Float64(cos(z) * sin(y)) / cos(Float64(y + z))) + Float64(Float64(cos(y) * sin(z)) / Float64(Float64(cos(y) * cos(z)) - Float64(sin(y) * sin(z))))) - tan(a)))
end
function tmp = code(x, y, z, a)
	tmp = x + ((((cos(z) * sin(y)) / cos((y + z))) + ((cos(y) * sin(z)) / ((cos(y) * cos(z)) - (sin(y) * sin(z))))) - tan(a));
end
code[x_, y_, z_, a_] := N[(x + N[(N[(N[(N[(N[Cos[z], $MachinePrecision] * N[Sin[y], $MachinePrecision]), $MachinePrecision] / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision] / N[(N[(N[Cos[y], $MachinePrecision] * N[Cos[z], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * N[Sin[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.8%

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

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

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

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

Alternative 7: 79.9% accurate, 0.4× speedup?

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

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.3%

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

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

Alternative 8: 79.9% accurate, 0.4× speedup?

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

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.3%

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

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

Alternative 9: 79.8% accurate, 0.4× speedup?

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

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.3%

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

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

Alternative 10: 79.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x - \left(\tan a - \tan \left(y + z\right)\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (- x (- (tan a) (tan (+ y z)))))
double code(double x, double y, double z, double a) {
	return x - (tan(a) - tan((y + z)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

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

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

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. Applied rewrites79.4%

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

Alternative 11: 64.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.0225:\\ \;\;\;\;x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}\\ \mathbf{else}:\\ \;\;\;\;x + \left(\tan z - \tan a\right)\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (if (<= y -0.0225)
   (+ x (/ (sin (+ y z)) (cos (+ y z))))
   (+ x (- (tan z) (tan a)))))
double code(double x, double y, double z, double a) {
	double tmp;
	if (y <= -0.0225) {
		tmp = x + (sin((y + z)) / cos((y + z)));
	} else {
		tmp = x + (tan(z) - tan(a));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: tmp
    if (y <= (-0.0225d0)) then
        tmp = x + (sin((y + z)) / cos((y + z)))
    else
        tmp = x + (tan(z) - tan(a))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double tmp;
	if (y <= -0.0225) {
		tmp = x + (Math.sin((y + z)) / Math.cos((y + z)));
	} else {
		tmp = x + (Math.tan(z) - Math.tan(a));
	}
	return tmp;
}
def code(x, y, z, a):
	tmp = 0
	if y <= -0.0225:
		tmp = x + (math.sin((y + z)) / math.cos((y + z)))
	else:
		tmp = x + (math.tan(z) - math.tan(a))
	return tmp
function code(x, y, z, a)
	tmp = 0.0
	if (y <= -0.0225)
		tmp = Float64(x + Float64(sin(Float64(y + z)) / cos(Float64(y + z))));
	else
		tmp = Float64(x + Float64(tan(z) - tan(a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	tmp = 0.0;
	if (y <= -0.0225)
		tmp = x + (sin((y + z)) / cos((y + z)));
	else
		tmp = x + (tan(z) - tan(a));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := If[LessEqual[y, -0.0225], N[(x + N[(N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision] / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Tan[z], $MachinePrecision] - N[Tan[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0225:\\
\;\;\;\;x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.022499999999999999

    1. Initial program 79.4%

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

      \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
    3. Applied rewrites49.8%

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

    if -0.022499999999999999 < y

    1. Initial program 79.4%

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

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

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

Alternative 12: 49.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)} \end{array} \]
(FPCore (x y z a) :precision binary64 (+ x (/ (sin (+ y z)) (cos (+ y z)))))
double code(double x, double y, double z, double a) {
	return x + (sin((y + z)) / cos((y + z)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = x + (sin((y + z)) / cos((y + z)))
end function
public static double code(double x, double y, double z, double a) {
	return x + (Math.sin((y + z)) / Math.cos((y + z)));
}
def code(x, y, z, a):
	return x + (math.sin((y + z)) / math.cos((y + z)))
function code(x, y, z, a)
	return Float64(x + Float64(sin(Float64(y + z)) / cos(Float64(y + z))))
end
function tmp = code(x, y, z, a)
	tmp = x + (sin((y + z)) / cos((y + z)));
end
code[x_, y_, z_, a_] := N[(x + N[(N[Sin[N[(y + z), $MachinePrecision]], $MachinePrecision] / N[Cos[N[(y + z), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}
\end{array}
Derivation
  1. Initial program 79.4%

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

    \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
  3. Applied rewrites49.8%

    \[\leadsto \color{blue}{x + \frac{\sin \left(y + z\right)}{\cos \left(y + z\right)}} \]
  4. Add Preprocessing

Alternative 13: 49.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 \cdot \left(x \cdot -1\right)\\ \mathbf{if}\;\tan a \leq -0.02:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\tan a \leq 0.05:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - a \cdot \left(1 + 0.3333333333333333 \cdot {a}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* -1.0 (* x -1.0))))
   (if (<= (tan a) -0.02)
     t_0
     (if (<= (tan a) 0.05)
       (+ x (- (tan (+ y z)) (* a (+ 1.0 (* 0.3333333333333333 (pow a 2.0))))))
       t_0))))
double code(double x, double y, double z, double a) {
	double t_0 = -1.0 * (x * -1.0);
	double tmp;
	if (tan(a) <= -0.02) {
		tmp = t_0;
	} else if (tan(a) <= 0.05) {
		tmp = x + (tan((y + z)) - (a * (1.0 + (0.3333333333333333 * pow(a, 2.0)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-1.0d0) * (x * (-1.0d0))
    if (tan(a) <= (-0.02d0)) then
        tmp = t_0
    else if (tan(a) <= 0.05d0) then
        tmp = x + (tan((y + z)) - (a * (1.0d0 + (0.3333333333333333d0 * (a ** 2.0d0)))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = -1.0 * (x * -1.0);
	double tmp;
	if (Math.tan(a) <= -0.02) {
		tmp = t_0;
	} else if (Math.tan(a) <= 0.05) {
		tmp = x + (Math.tan((y + z)) - (a * (1.0 + (0.3333333333333333 * Math.pow(a, 2.0)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = -1.0 * (x * -1.0)
	tmp = 0
	if math.tan(a) <= -0.02:
		tmp = t_0
	elif math.tan(a) <= 0.05:
		tmp = x + (math.tan((y + z)) - (a * (1.0 + (0.3333333333333333 * math.pow(a, 2.0)))))
	else:
		tmp = t_0
	return tmp
function code(x, y, z, a)
	t_0 = Float64(-1.0 * Float64(x * -1.0))
	tmp = 0.0
	if (tan(a) <= -0.02)
		tmp = t_0;
	elseif (tan(a) <= 0.05)
		tmp = Float64(x + Float64(tan(Float64(y + z)) - Float64(a * Float64(1.0 + Float64(0.3333333333333333 * (a ^ 2.0))))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = -1.0 * (x * -1.0);
	tmp = 0.0;
	if (tan(a) <= -0.02)
		tmp = t_0;
	elseif (tan(a) <= 0.05)
		tmp = x + (tan((y + z)) - (a * (1.0 + (0.3333333333333333 * (a ^ 2.0)))));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(-1.0 * N[(x * -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.02], t$95$0, If[LessEqual[N[Tan[a], $MachinePrecision], 0.05], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - N[(a * N[(1.0 + N[(0.3333333333333333 * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 \cdot \left(x \cdot -1\right)\\
\mathbf{if}\;\tan a \leq -0.02:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. 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)} \]
    3. Applied rewrites79.2%

      \[\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. Taylor expanded in x around inf

      \[\leadsto -1 \cdot \left(x \cdot -1\right) \]
    5. Applied rewrites31.7%

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

    if -0.0200000000000000004 < (tan.f64 a) < 0.050000000000000003

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. 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) \]
    3. Applied rewrites39.8%

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

Alternative 14: 49.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 \cdot \left(x \cdot -1\right)\\ \mathbf{if}\;\tan a \leq -0.02:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\tan a \leq 0.05:\\ \;\;\;\;x + \left(\tan \left(y + z\right) - a\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* -1.0 (* x -1.0))))
   (if (<= (tan a) -0.02)
     t_0
     (if (<= (tan a) 0.05) (+ x (- (tan (+ y z)) a)) t_0))))
double code(double x, double y, double z, double a) {
	double t_0 = -1.0 * (x * -1.0);
	double tmp;
	if (tan(a) <= -0.02) {
		tmp = t_0;
	} else if (tan(a) <= 0.05) {
		tmp = x + (tan((y + z)) - a);
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-1.0d0) * (x * (-1.0d0))
    if (tan(a) <= (-0.02d0)) then
        tmp = t_0
    else if (tan(a) <= 0.05d0) then
        tmp = x + (tan((y + z)) - a)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = -1.0 * (x * -1.0);
	double tmp;
	if (Math.tan(a) <= -0.02) {
		tmp = t_0;
	} else if (Math.tan(a) <= 0.05) {
		tmp = x + (Math.tan((y + z)) - a);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = -1.0 * (x * -1.0)
	tmp = 0
	if math.tan(a) <= -0.02:
		tmp = t_0
	elif math.tan(a) <= 0.05:
		tmp = x + (math.tan((y + z)) - a)
	else:
		tmp = t_0
	return tmp
function code(x, y, z, a)
	t_0 = Float64(-1.0 * Float64(x * -1.0))
	tmp = 0.0
	if (tan(a) <= -0.02)
		tmp = t_0;
	elseif (tan(a) <= 0.05)
		tmp = Float64(x + Float64(tan(Float64(y + z)) - a));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = -1.0 * (x * -1.0);
	tmp = 0.0;
	if (tan(a) <= -0.02)
		tmp = t_0;
	elseif (tan(a) <= 0.05)
		tmp = x + (tan((y + z)) - a);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(-1.0 * N[(x * -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.02], t$95$0, If[LessEqual[N[Tan[a], $MachinePrecision], 0.05], N[(x + N[(N[Tan[N[(y + z), $MachinePrecision]], $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 \cdot \left(x \cdot -1\right)\\
\mathbf{if}\;\tan a \leq -0.02:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. 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)} \]
    3. Applied rewrites79.2%

      \[\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. Taylor expanded in x around inf

      \[\leadsto -1 \cdot \left(x \cdot -1\right) \]
    5. Applied rewrites31.7%

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

    if -0.0200000000000000004 < (tan.f64 a) < 0.050000000000000003

    1. Initial program 79.4%

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

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

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

Alternative 15: 40.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 \cdot \left(x \cdot -1\right)\\ \mathbf{if}\;\tan a \leq -0.02:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\tan a \leq 0.05:\\ \;\;\;\;x + \left(\tan z - a\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z a)
 :precision binary64
 (let* ((t_0 (* -1.0 (* x -1.0))))
   (if (<= (tan a) -0.02) t_0 (if (<= (tan a) 0.05) (+ x (- (tan z) a)) t_0))))
double code(double x, double y, double z, double a) {
	double t_0 = -1.0 * (x * -1.0);
	double tmp;
	if (tan(a) <= -0.02) {
		tmp = t_0;
	} else if (tan(a) <= 0.05) {
		tmp = x + (tan(z) - a);
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-1.0d0) * (x * (-1.0d0))
    if (tan(a) <= (-0.02d0)) then
        tmp = t_0
    else if (tan(a) <= 0.05d0) then
        tmp = x + (tan(z) - a)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double a) {
	double t_0 = -1.0 * (x * -1.0);
	double tmp;
	if (Math.tan(a) <= -0.02) {
		tmp = t_0;
	} else if (Math.tan(a) <= 0.05) {
		tmp = x + (Math.tan(z) - a);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z, a):
	t_0 = -1.0 * (x * -1.0)
	tmp = 0
	if math.tan(a) <= -0.02:
		tmp = t_0
	elif math.tan(a) <= 0.05:
		tmp = x + (math.tan(z) - a)
	else:
		tmp = t_0
	return tmp
function code(x, y, z, a)
	t_0 = Float64(-1.0 * Float64(x * -1.0))
	tmp = 0.0
	if (tan(a) <= -0.02)
		tmp = t_0;
	elseif (tan(a) <= 0.05)
		tmp = Float64(x + Float64(tan(z) - a));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z, a)
	t_0 = -1.0 * (x * -1.0);
	tmp = 0.0;
	if (tan(a) <= -0.02)
		tmp = t_0;
	elseif (tan(a) <= 0.05)
		tmp = x + (tan(z) - a);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, a_] := Block[{t$95$0 = N[(-1.0 * N[(x * -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Tan[a], $MachinePrecision], -0.02], t$95$0, If[LessEqual[N[Tan[a], $MachinePrecision], 0.05], N[(x + N[(N[Tan[z], $MachinePrecision] - a), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 \cdot \left(x \cdot -1\right)\\
\mathbf{if}\;\tan a \leq -0.02:\\
\;\;\;\;t\_0\\

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

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


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

    1. Initial program 79.4%

      \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
    2. 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)} \]
    3. Applied rewrites79.2%

      \[\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. Taylor expanded in x around inf

      \[\leadsto -1 \cdot \left(x \cdot -1\right) \]
    5. Applied rewrites31.7%

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

    if -0.0200000000000000004 < (tan.f64 a) < 0.050000000000000003

    1. Initial program 79.4%

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

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

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

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

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

Alternative 16: 31.7% accurate, 11.5× speedup?

\[\begin{array}{l} \\ -1 \cdot \left(x \cdot -1\right) \end{array} \]
(FPCore (x y z a) :precision binary64 (* -1.0 (* x -1.0)))
double code(double x, double y, double z, double a) {
	return -1.0 * (x * -1.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: a
    code = (-1.0d0) * (x * (-1.0d0))
end function
public static double code(double x, double y, double z, double a) {
	return -1.0 * (x * -1.0);
}
def code(x, y, z, a):
	return -1.0 * (x * -1.0)
function code(x, y, z, a)
	return Float64(-1.0 * Float64(x * -1.0))
end
function tmp = code(x, y, z, a)
	tmp = -1.0 * (x * -1.0);
end
code[x_, y_, z_, a_] := N[(-1.0 * N[(x * -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-1 \cdot \left(x \cdot -1\right)
\end{array}
Derivation
  1. Initial program 79.4%

    \[x + \left(\tan \left(y + z\right) - \tan a\right) \]
  2. 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)} \]
  3. Applied rewrites79.2%

    \[\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. Taylor expanded in x around inf

    \[\leadsto -1 \cdot \left(x \cdot -1\right) \]
  5. Applied rewrites31.7%

    \[\leadsto -1 \cdot \left(x \cdot -1\right) \]
  6. Add Preprocessing

Reproduce

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