Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B

Percentage Accurate: 99.9% → 99.9%
Time: 5.3s
Alternatives: 15
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x + \cos y\right) - z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x + cos(y)) - (z * sin(y));
}
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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z):
	return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x + cos(y)) - Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x + cos(y)) - (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + \cos y\right) - z \cdot \sin y
\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 15 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: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + \cos y\right) - z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x + cos(y)) - (z * sin(y));
}
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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z):
	return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x + cos(y)) - Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x + cos(y)) - (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}

Alternative 1: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x + \cos y\right) - z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x + cos(y)) - (z * sin(y));
}
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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z):
	return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x + cos(y)) - Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x + cos(y)) - (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[\left(x + \cos y\right) - z \cdot \sin y \]
  2. Add Preprocessing

Alternative 2: 99.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x + 1\right) - z \cdot \sin y\\ \mathbf{if}\;z \leq -0.81:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-17}:\\ \;\;\;\;x \cdot \left(1 + \frac{\cos y}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (+ x 1.0) (* z (sin y)))))
   (if (<= z -0.81) t_0 (if (<= z 5e-17) (* x (+ 1.0 (/ (cos y) x))) t_0))))
double code(double x, double y, double z) {
	double t_0 = (x + 1.0) - (z * sin(y));
	double tmp;
	if (z <= -0.81) {
		tmp = t_0;
	} else if (z <= 5e-17) {
		tmp = x * (1.0 + (cos(y) / x));
	} 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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x + 1.0d0) - (z * sin(y))
    if (z <= (-0.81d0)) then
        tmp = t_0
    else if (z <= 5d-17) then
        tmp = x * (1.0d0 + (cos(y) / x))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x + 1.0) - (z * Math.sin(y));
	double tmp;
	if (z <= -0.81) {
		tmp = t_0;
	} else if (z <= 5e-17) {
		tmp = x * (1.0 + (Math.cos(y) / x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x + 1.0) - (z * math.sin(y))
	tmp = 0
	if z <= -0.81:
		tmp = t_0
	elif z <= 5e-17:
		tmp = x * (1.0 + (math.cos(y) / x))
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x + 1.0) - Float64(z * sin(y)))
	tmp = 0.0
	if (z <= -0.81)
		tmp = t_0;
	elseif (z <= 5e-17)
		tmp = Float64(x * Float64(1.0 + Float64(cos(y) / x)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x + 1.0) - (z * sin(y));
	tmp = 0.0;
	if (z <= -0.81)
		tmp = t_0;
	elseif (z <= 5e-17)
		tmp = x * (1.0 + (cos(y) / x));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -0.81], t$95$0, If[LessEqual[z, 5e-17], N[(x * N[(1.0 + N[(N[Cos[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x + 1\right) - z \cdot \sin y\\
\mathbf{if}\;z \leq -0.81:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 5 \cdot 10^{-17}:\\
\;\;\;\;x \cdot \left(1 + \frac{\cos y}{x}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.81000000000000005 or 4.9999999999999999e-17 < z

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]
    3. Applied rewrites88.3%

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]

    if -0.81000000000000005 < z < 4.9999999999999999e-17

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in x around inf

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

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

      \[\leadsto x \cdot \left(1 + \color{blue}{\frac{1}{x}}\right) \]
    5. Applied rewrites62.3%

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

      \[\leadsto x \cdot \left(1 + \color{blue}{\frac{\cos y}{x}}\right) \]
    7. Applied rewrites73.2%

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

Alternative 3: 98.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \sin y\\ t_1 := \left(x + \cos y\right) - t\_0\\ t_2 := \left(x + 1\right) - t\_0\\ \mathbf{if}\;t\_1 \leq -100:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 0.98:\\ \;\;\;\;\cos y - 1 \cdot z\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (sin y)))
        (t_1 (- (+ x (cos y)) t_0))
        (t_2 (- (+ x 1.0) t_0)))
   (if (<= t_1 -100.0) t_2 (if (<= t_1 0.98) (- (cos y) (* 1.0 z)) t_2))))
double code(double x, double y, double z) {
	double t_0 = z * sin(y);
	double t_1 = (x + cos(y)) - t_0;
	double t_2 = (x + 1.0) - t_0;
	double tmp;
	if (t_1 <= -100.0) {
		tmp = t_2;
	} else if (t_1 <= 0.98) {
		tmp = cos(y) - (1.0 * z);
	} else {
		tmp = t_2;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = z * sin(y)
    t_1 = (x + cos(y)) - t_0
    t_2 = (x + 1.0d0) - t_0
    if (t_1 <= (-100.0d0)) then
        tmp = t_2
    else if (t_1 <= 0.98d0) then
        tmp = cos(y) - (1.0d0 * z)
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z * Math.sin(y);
	double t_1 = (x + Math.cos(y)) - t_0;
	double t_2 = (x + 1.0) - t_0;
	double tmp;
	if (t_1 <= -100.0) {
		tmp = t_2;
	} else if (t_1 <= 0.98) {
		tmp = Math.cos(y) - (1.0 * z);
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.sin(y)
	t_1 = (x + math.cos(y)) - t_0
	t_2 = (x + 1.0) - t_0
	tmp = 0
	if t_1 <= -100.0:
		tmp = t_2
	elif t_1 <= 0.98:
		tmp = math.cos(y) - (1.0 * z)
	else:
		tmp = t_2
	return tmp
function code(x, y, z)
	t_0 = Float64(z * sin(y))
	t_1 = Float64(Float64(x + cos(y)) - t_0)
	t_2 = Float64(Float64(x + 1.0) - t_0)
	tmp = 0.0
	if (t_1 <= -100.0)
		tmp = t_2;
	elseif (t_1 <= 0.98)
		tmp = Float64(cos(y) - Float64(1.0 * z));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * sin(y);
	t_1 = (x + cos(y)) - t_0;
	t_2 = (x + 1.0) - t_0;
	tmp = 0.0;
	if (t_1 <= -100.0)
		tmp = t_2;
	elseif (t_1 <= 0.98)
		tmp = cos(y) - (1.0 * z);
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -100.0], t$95$2, If[LessEqual[t$95$1, 0.98], N[(N[Cos[y], $MachinePrecision] - N[(1.0 * z), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := \left(x + \cos y\right) - t\_0\\
t_2 := \left(x + 1\right) - t\_0\\
\mathbf{if}\;t\_1 \leq -100:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 0.98:\\
\;\;\;\;\cos y - 1 \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < -100 or 0.97999999999999998 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y)))

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]
    3. Applied rewrites88.3%

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]

    if -100 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 0.97999999999999998

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

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

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

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    5. Applied rewrites35.2%

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    6. Applied rewrites27.8%

      \[\leadsto \cos y - \color{blue}{1 \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 97.1% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \sin y\\ t_1 := \left(x + \cos y\right) - t\_0\\ t_2 := \left(x + 0\right) - t\_0\\ \mathbf{if}\;t\_1 \leq -100:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 0.98:\\ \;\;\;\;\cos y - 1 \cdot z\\ \mathbf{elif}\;t\_1 \leq 5:\\ \;\;\;\;1 + x\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (sin y)))
        (t_1 (- (+ x (cos y)) t_0))
        (t_2 (- (+ x 0.0) t_0)))
   (if (<= t_1 -100.0)
     t_2
     (if (<= t_1 0.98)
       (- (cos y) (* 1.0 z))
       (if (<= t_1 5.0) (+ 1.0 x) t_2)))))
double code(double x, double y, double z) {
	double t_0 = z * sin(y);
	double t_1 = (x + cos(y)) - t_0;
	double t_2 = (x + 0.0) - t_0;
	double tmp;
	if (t_1 <= -100.0) {
		tmp = t_2;
	} else if (t_1 <= 0.98) {
		tmp = cos(y) - (1.0 * z);
	} else if (t_1 <= 5.0) {
		tmp = 1.0 + x;
	} else {
		tmp = t_2;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = z * sin(y)
    t_1 = (x + cos(y)) - t_0
    t_2 = (x + 0.0d0) - t_0
    if (t_1 <= (-100.0d0)) then
        tmp = t_2
    else if (t_1 <= 0.98d0) then
        tmp = cos(y) - (1.0d0 * z)
    else if (t_1 <= 5.0d0) then
        tmp = 1.0d0 + x
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = z * Math.sin(y);
	double t_1 = (x + Math.cos(y)) - t_0;
	double t_2 = (x + 0.0) - t_0;
	double tmp;
	if (t_1 <= -100.0) {
		tmp = t_2;
	} else if (t_1 <= 0.98) {
		tmp = Math.cos(y) - (1.0 * z);
	} else if (t_1 <= 5.0) {
		tmp = 1.0 + x;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = z * math.sin(y)
	t_1 = (x + math.cos(y)) - t_0
	t_2 = (x + 0.0) - t_0
	tmp = 0
	if t_1 <= -100.0:
		tmp = t_2
	elif t_1 <= 0.98:
		tmp = math.cos(y) - (1.0 * z)
	elif t_1 <= 5.0:
		tmp = 1.0 + x
	else:
		tmp = t_2
	return tmp
function code(x, y, z)
	t_0 = Float64(z * sin(y))
	t_1 = Float64(Float64(x + cos(y)) - t_0)
	t_2 = Float64(Float64(x + 0.0) - t_0)
	tmp = 0.0
	if (t_1 <= -100.0)
		tmp = t_2;
	elseif (t_1 <= 0.98)
		tmp = Float64(cos(y) - Float64(1.0 * z));
	elseif (t_1 <= 5.0)
		tmp = Float64(1.0 + x);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = z * sin(y);
	t_1 = (x + cos(y)) - t_0;
	t_2 = (x + 0.0) - t_0;
	tmp = 0.0;
	if (t_1 <= -100.0)
		tmp = t_2;
	elseif (t_1 <= 0.98)
		tmp = cos(y) - (1.0 * z);
	elseif (t_1 <= 5.0)
		tmp = 1.0 + x;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + 0.0), $MachinePrecision] - t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -100.0], t$95$2, If[LessEqual[t$95$1, 0.98], N[(N[Cos[y], $MachinePrecision] - N[(1.0 * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5.0], N[(1.0 + x), $MachinePrecision], t$95$2]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := \left(x + \cos y\right) - t\_0\\
t_2 := \left(x + 0\right) - t\_0\\
\mathbf{if}\;t\_1 \leq -100:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 0.98:\\
\;\;\;\;\cos y - 1 \cdot z\\

\mathbf{elif}\;t\_1 \leq 5:\\
\;\;\;\;1 + x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < -100 or 5 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y)))

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]
    3. Applied rewrites88.3%

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]
    4. Applied rewrites68.3%

      \[\leadsto \left(x + 0\right) - z \cdot \sin y \]

    if -100 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 0.97999999999999998

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

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

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

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    5. Applied rewrites35.2%

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    6. Applied rewrites27.8%

      \[\leadsto \cos y - \color{blue}{1 \cdot z} \]

    if 0.97999999999999998 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 5

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + x} \]
    3. Applied rewrites62.3%

      \[\leadsto \color{blue}{1 + x} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 74.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x + \cos y\right) - z \cdot \sin y\\ t_1 := \left(x + 1\right) - z \cdot y\\ \mathbf{if}\;t\_0 \leq -100:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 0.98:\\ \;\;\;\;\cos y - 1 \cdot z\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+149}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;1 + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (+ x (cos y)) (* z (sin y)))) (t_1 (- (+ x 1.0) (* z y))))
   (if (<= t_0 -100.0)
     t_1
     (if (<= t_0 0.98)
       (- (cos y) (* 1.0 z))
       (if (<= t_0 5e+149) t_1 (+ 1.0 x))))))
double code(double x, double y, double z) {
	double t_0 = (x + cos(y)) - (z * sin(y));
	double t_1 = (x + 1.0) - (z * y);
	double tmp;
	if (t_0 <= -100.0) {
		tmp = t_1;
	} else if (t_0 <= 0.98) {
		tmp = cos(y) - (1.0 * z);
	} else if (t_0 <= 5e+149) {
		tmp = t_1;
	} else {
		tmp = 1.0 + x;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (x + cos(y)) - (z * sin(y))
    t_1 = (x + 1.0d0) - (z * y)
    if (t_0 <= (-100.0d0)) then
        tmp = t_1
    else if (t_0 <= 0.98d0) then
        tmp = cos(y) - (1.0d0 * z)
    else if (t_0 <= 5d+149) then
        tmp = t_1
    else
        tmp = 1.0d0 + x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x + Math.cos(y)) - (z * Math.sin(y));
	double t_1 = (x + 1.0) - (z * y);
	double tmp;
	if (t_0 <= -100.0) {
		tmp = t_1;
	} else if (t_0 <= 0.98) {
		tmp = Math.cos(y) - (1.0 * z);
	} else if (t_0 <= 5e+149) {
		tmp = t_1;
	} else {
		tmp = 1.0 + x;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x + math.cos(y)) - (z * math.sin(y))
	t_1 = (x + 1.0) - (z * y)
	tmp = 0
	if t_0 <= -100.0:
		tmp = t_1
	elif t_0 <= 0.98:
		tmp = math.cos(y) - (1.0 * z)
	elif t_0 <= 5e+149:
		tmp = t_1
	else:
		tmp = 1.0 + x
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x + cos(y)) - Float64(z * sin(y)))
	t_1 = Float64(Float64(x + 1.0) - Float64(z * y))
	tmp = 0.0
	if (t_0 <= -100.0)
		tmp = t_1;
	elseif (t_0 <= 0.98)
		tmp = Float64(cos(y) - Float64(1.0 * z));
	elseif (t_0 <= 5e+149)
		tmp = t_1;
	else
		tmp = Float64(1.0 + x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x + cos(y)) - (z * sin(y));
	t_1 = (x + 1.0) - (z * y);
	tmp = 0.0;
	if (t_0 <= -100.0)
		tmp = t_1;
	elseif (t_0 <= 0.98)
		tmp = cos(y) - (1.0 * z);
	elseif (t_0 <= 5e+149)
		tmp = t_1;
	else
		tmp = 1.0 + x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + 1.0), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100.0], t$95$1, If[LessEqual[t$95$0, 0.98], N[(N[Cos[y], $MachinePrecision] - N[(1.0 * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+149], t$95$1, N[(1.0 + x), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x + \cos y\right) - z \cdot \sin y\\
t_1 := \left(x + 1\right) - z \cdot y\\
\mathbf{if}\;t\_0 \leq -100:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 0.98:\\
\;\;\;\;\cos y - 1 \cdot z\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+149}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < -100 or 0.97999999999999998 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 4.9999999999999999e149

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]
    3. Applied rewrites88.3%

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

      \[\leadsto \left(x + 1\right) - z \cdot \color{blue}{y} \]
    5. Applied rewrites64.2%

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

    if -100 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 0.97999999999999998

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

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

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

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    5. Applied rewrites35.2%

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    6. Applied rewrites27.8%

      \[\leadsto \cos y - \color{blue}{1 \cdot z} \]

    if 4.9999999999999999e149 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y)))

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + x} \]
    3. Applied rewrites62.3%

      \[\leadsto \color{blue}{1 + x} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 73.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.00112:\\ \;\;\;\;1 + x\\ \mathbf{elif}\;x \leq 7.6 \cdot 10^{-13}:\\ \;\;\;\;\cos y - y \cdot z\\ \mathbf{else}:\\ \;\;\;\;1 + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -0.00112)
   (+ 1.0 x)
   (if (<= x 7.6e-13) (- (cos y) (* y z)) (+ 1.0 x))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -0.00112) {
		tmp = 1.0 + x;
	} else if (x <= 7.6e-13) {
		tmp = cos(y) - (y * z);
	} else {
		tmp = 1.0 + x;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (x <= (-0.00112d0)) then
        tmp = 1.0d0 + x
    else if (x <= 7.6d-13) then
        tmp = cos(y) - (y * z)
    else
        tmp = 1.0d0 + x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -0.00112) {
		tmp = 1.0 + x;
	} else if (x <= 7.6e-13) {
		tmp = Math.cos(y) - (y * z);
	} else {
		tmp = 1.0 + x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -0.00112:
		tmp = 1.0 + x
	elif x <= 7.6e-13:
		tmp = math.cos(y) - (y * z)
	else:
		tmp = 1.0 + x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -0.00112)
		tmp = Float64(1.0 + x);
	elseif (x <= 7.6e-13)
		tmp = Float64(cos(y) - Float64(y * z));
	else
		tmp = Float64(1.0 + x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -0.00112)
		tmp = 1.0 + x;
	elseif (x <= 7.6e-13)
		tmp = cos(y) - (y * z);
	else
		tmp = 1.0 + x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -0.00112], N[(1.0 + x), $MachinePrecision], If[LessEqual[x, 7.6e-13], N[(N[Cos[y], $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.00112:\\
\;\;\;\;1 + x\\

\mathbf{elif}\;x \leq 7.6 \cdot 10^{-13}:\\
\;\;\;\;\cos y - y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -0.0011199999999999999 or 7.5999999999999999e-13 < x

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + x} \]
    3. Applied rewrites62.3%

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

    if -0.0011199999999999999 < x < 7.5999999999999999e-13

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

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

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

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
    5. Applied rewrites35.2%

      \[\leadsto \color{blue}{\cos y} - y \cdot z \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 71.5% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{+19}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\

\mathbf{elif}\;y \leq 3.6:\\
\;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1 + \mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)\\


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

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
    3. Applied rewrites28.0%

      \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
    4. Applied rewrites28.0%

      \[\leadsto \color{blue}{\left(-z\right) \cdot \sin y} \]

    if -7.4e19 < y < 3.60000000000000009

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]

    if 3.60000000000000009 < y

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]
    4. Taylor expanded in x around inf

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

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

      \[\leadsto 1 + \color{blue}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 71.4% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+19}:\\ \;\;\;\;1 + x \cdot \left(1 + \frac{1 \cdot \left(-0.5 \cdot 1 - z\right)}{x}\right)\\ \mathbf{elif}\;y \leq 3.6:\\ \;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.65e+19)
   (+ 1.0 (* x (+ 1.0 (/ (* 1.0 (- (* -0.5 1.0) z)) x))))
   (if (<= y 3.6)
     (+ 1.0 (+ x (* y (- (* -0.5 y) z))))
     (+ 1.0 (fma (/ (fma 1.0 -0.5 z) x) x x)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.65e+19) {
		tmp = 1.0 + (x * (1.0 + ((1.0 * ((-0.5 * 1.0) - z)) / x)));
	} else if (y <= 3.6) {
		tmp = 1.0 + (x + (y * ((-0.5 * y) - z)));
	} else {
		tmp = 1.0 + fma((fma(1.0, -0.5, z) / x), x, x);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.65e+19)
		tmp = Float64(1.0 + Float64(x * Float64(1.0 + Float64(Float64(1.0 * Float64(Float64(-0.5 * 1.0) - z)) / x))));
	elseif (y <= 3.6)
		tmp = Float64(1.0 + Float64(x + Float64(y * Float64(Float64(-0.5 * y) - z))));
	else
		tmp = Float64(1.0 + fma(Float64(fma(1.0, -0.5, z) / x), x, x));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, -1.65e+19], N[(1.0 + N[(x * N[(1.0 + N[(N[(1.0 * N[(N[(-0.5 * 1.0), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.6], N[(1.0 + N[(x + N[(y * N[(N[(-0.5 * y), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(N[(1.0 * -0.5 + z), $MachinePrecision] / x), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+19}:\\
\;\;\;\;1 + x \cdot \left(1 + \frac{1 \cdot \left(-0.5 \cdot 1 - z\right)}{x}\right)\\

\mathbf{elif}\;y \leq 3.6:\\
\;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1 + \mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)\\


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

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]
    4. Taylor expanded in x around inf

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

      \[\leadsto 1 + x \cdot \color{blue}{\left(1 + \frac{y \cdot \left(-0.5 \cdot y - z\right)}{x}\right)} \]
    6. Applied rewrites42.3%

      \[\leadsto 1 + x \cdot \left(1 + \frac{1 \cdot \left(-0.5 \cdot 1 - z\right)}{x}\right) \]

    if -1.65e19 < y < 3.60000000000000009

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]

    if 3.60000000000000009 < y

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]
    4. Taylor expanded in x around inf

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

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

      \[\leadsto 1 + \color{blue}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 70.6% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)\\ \mathbf{if}\;y \leq -9.2 \cdot 10^{+14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 3.6:\\ \;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (fma (/ (fma 1.0 -0.5 z) x) x x))))
   (if (<= y -9.2e+14)
     t_0
     (if (<= y 3.6) (+ 1.0 (+ x (* y (- (* -0.5 y) z)))) t_0))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + fma((fma(1.0, -0.5, z) / x), x, x);
	double tmp;
	if (y <= -9.2e+14) {
		tmp = t_0;
	} else if (y <= 3.6) {
		tmp = 1.0 + (x + (y * ((-0.5 * y) - z)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(1.0 + fma(Float64(fma(1.0, -0.5, z) / x), x, x))
	tmp = 0.0
	if (y <= -9.2e+14)
		tmp = t_0;
	elseif (y <= 3.6)
		tmp = Float64(1.0 + Float64(x + Float64(y * Float64(Float64(-0.5 * y) - z))));
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(N[(1.0 * -0.5 + z), $MachinePrecision] / x), $MachinePrecision] * x + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.2e+14], t$95$0, If[LessEqual[y, 3.6], N[(1.0 + N[(x + N[(y * N[(N[(-0.5 * y), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \mathsf{fma}\left(\frac{\mathsf{fma}\left(1, -0.5, z\right)}{x}, x, x\right)\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 3.6:\\
\;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -9.2e14 or 3.60000000000000009 < y

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]
    4. Taylor expanded in x around inf

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

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

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

    if -9.2e14 < y < 3.60000000000000009

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

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

Alternative 10: 70.3% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+19}:\\ \;\;\;\;1 + x\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-16}:\\ \;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.65e+19)
   (+ 1.0 x)
   (if (<= y 1.15e-16) (+ 1.0 (+ x (* y (- (* -0.5 y) z)))) (+ 1.0 x))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.65e+19) {
		tmp = 1.0 + x;
	} else if (y <= 1.15e-16) {
		tmp = 1.0 + (x + (y * ((-0.5 * y) - z)));
	} else {
		tmp = 1.0 + x;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.65d+19)) then
        tmp = 1.0d0 + x
    else if (y <= 1.15d-16) then
        tmp = 1.0d0 + (x + (y * (((-0.5d0) * y) - z)))
    else
        tmp = 1.0d0 + x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.65e+19) {
		tmp = 1.0 + x;
	} else if (y <= 1.15e-16) {
		tmp = 1.0 + (x + (y * ((-0.5 * y) - z)));
	} else {
		tmp = 1.0 + x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.65e+19:
		tmp = 1.0 + x
	elif y <= 1.15e-16:
		tmp = 1.0 + (x + (y * ((-0.5 * y) - z)))
	else:
		tmp = 1.0 + x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.65e+19)
		tmp = Float64(1.0 + x);
	elseif (y <= 1.15e-16)
		tmp = Float64(1.0 + Float64(x + Float64(y * Float64(Float64(-0.5 * y) - z))));
	else
		tmp = Float64(1.0 + x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.65e+19)
		tmp = 1.0 + x;
	elseif (y <= 1.15e-16)
		tmp = 1.0 + (x + (y * ((-0.5 * y) - z)));
	else
		tmp = 1.0 + x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.65e+19], N[(1.0 + x), $MachinePrecision], If[LessEqual[y, 1.15e-16], N[(1.0 + N[(x + N[(y * N[(N[(-0.5 * y), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+19}:\\
\;\;\;\;1 + x\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{-16}:\\
\;\;\;\;1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.65e19 or 1.15e-16 < y

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + x} \]
    3. Applied rewrites62.3%

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

    if -1.65e19 < y < 1.15e-16

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

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

Alternative 11: 69.9% accurate, 4.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{+19}:\\ \;\;\;\;1 + x\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+58}:\\ \;\;\;\;\left(x + 1\right) - z \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 + x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.95e+19)
   (+ 1.0 x)
   (if (<= y 8.5e+58) (- (+ x 1.0) (* z y)) (+ 1.0 x))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.95e+19) {
		tmp = 1.0 + x;
	} else if (y <= 8.5e+58) {
		tmp = (x + 1.0) - (z * y);
	} else {
		tmp = 1.0 + x;
	}
	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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.95d+19)) then
        tmp = 1.0d0 + x
    else if (y <= 8.5d+58) then
        tmp = (x + 1.0d0) - (z * y)
    else
        tmp = 1.0d0 + x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.95e+19) {
		tmp = 1.0 + x;
	} else if (y <= 8.5e+58) {
		tmp = (x + 1.0) - (z * y);
	} else {
		tmp = 1.0 + x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.95e+19:
		tmp = 1.0 + x
	elif y <= 8.5e+58:
		tmp = (x + 1.0) - (z * y)
	else:
		tmp = 1.0 + x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.95e+19)
		tmp = Float64(1.0 + x);
	elseif (y <= 8.5e+58)
		tmp = Float64(Float64(x + 1.0) - Float64(z * y));
	else
		tmp = Float64(1.0 + x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.95e+19)
		tmp = 1.0 + x;
	elseif (y <= 8.5e+58)
		tmp = (x + 1.0) - (z * y);
	else
		tmp = 1.0 + x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.95e+19], N[(1.0 + x), $MachinePrecision], If[LessEqual[y, 8.5e+58], N[(N[(x + 1.0), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+19}:\\
\;\;\;\;1 + x\\

\mathbf{elif}\;y \leq 8.5 \cdot 10^{+58}:\\
\;\;\;\;\left(x + 1\right) - z \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.95e19 or 8.50000000000000015e58 < y

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + x} \]
    3. Applied rewrites62.3%

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

    if -1.95e19 < y < 8.50000000000000015e58

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \left(x + \color{blue}{1}\right) - z \cdot \sin y \]
    3. Applied rewrites88.3%

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

      \[\leadsto \left(x + 1\right) - z \cdot \color{blue}{y} \]
    5. Applied rewrites64.2%

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

Alternative 12: 62.3% accurate, 19.5× speedup?

\[\begin{array}{l} \\ 1 + x \end{array} \]
(FPCore (x y z) :precision binary64 (+ 1.0 x))
double code(double x, double y, double z) {
	return 1.0 + x;
}
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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 1.0d0 + x
end function
public static double code(double x, double y, double z) {
	return 1.0 + x;
}
def code(x, y, z):
	return 1.0 + x
function code(x, y, z)
	return Float64(1.0 + x)
end
function tmp = code(x, y, z)
	tmp = 1.0 + x;
end
code[x_, y_, z_] := N[(1.0 + x), $MachinePrecision]
\begin{array}{l}

\\
1 + x
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x + \cos y\right) - z \cdot \sin y \]
  2. Taylor expanded in y around 0

    \[\leadsto \color{blue}{1 + x} \]
  3. Applied rewrites62.3%

    \[\leadsto \color{blue}{1 + x} \]
  4. Add Preprocessing

Alternative 13: 24.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x + \cos y\right) - z \cdot \sin y \leq -0.04:\\ \;\;\;\;-0.5\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (- (+ x (cos y)) (* z (sin y))) -0.04) -0.5 1.0))
double code(double x, double y, double z) {
	double tmp;
	if (((x + cos(y)) - (z * sin(y))) <= -0.04) {
		tmp = -0.5;
	} else {
		tmp = 1.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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (((x + cos(y)) - (z * sin(y))) <= (-0.04d0)) then
        tmp = -0.5d0
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (((x + Math.cos(y)) - (z * Math.sin(y))) <= -0.04) {
		tmp = -0.5;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if ((x + math.cos(y)) - (z * math.sin(y))) <= -0.04:
		tmp = -0.5
	else:
		tmp = 1.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(Float64(x + cos(y)) - Float64(z * sin(y))) <= -0.04)
		tmp = -0.5;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (((x + cos(y)) - (z * sin(y))) <= -0.04)
		tmp = -0.5;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.04], -0.5, 1.0]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < -0.0400000000000000008

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(\frac{-1}{2} \cdot y - z\right)\right)} \]
    3. Applied rewrites55.8%

      \[\leadsto \color{blue}{1 + \left(x + y \cdot \left(-0.5 \cdot y - z\right)\right)} \]
    4. Taylor expanded in y around inf

      \[\leadsto {y}^{2} \cdot \color{blue}{\left(-1 \cdot \frac{z}{y} - \frac{1}{2}\right)} \]
    5. Applied rewrites6.4%

      \[\leadsto {y}^{2} \cdot \color{blue}{\left(-1 \cdot \frac{z}{y} - 0.5\right)} \]
    6. Applied rewrites4.6%

      \[\leadsto \left(\frac{z \cdot z}{1} - 0.5 \cdot 0.5\right) \cdot \frac{1}{\color{blue}{0.5 - \frac{z}{1}}} \]
    7. Taylor expanded in z around 0

      \[\leadsto \frac{-1}{2} \]
    8. Applied rewrites3.8%

      \[\leadsto -0.5 \]

    if -0.0400000000000000008 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y)))

    1. Initial program 99.9%

      \[\left(x + \cos y\right) - z \cdot \sin y \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{1 + x} \]
    3. Applied rewrites62.3%

      \[\leadsto \color{blue}{1 + x} \]
    4. Taylor expanded in x around 0

      \[\leadsto 1 \]
    5. Applied rewrites22.1%

      \[\leadsto 1 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 22.1% accurate, 72.9× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
	return 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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 1.0d0
end function
public static double code(double x, double y, double z) {
	return 1.0;
}
def code(x, y, z):
	return 1.0
function code(x, y, z)
	return 1.0
end
function tmp = code(x, y, z)
	tmp = 1.0;
end
code[x_, y_, z_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x + \cos y\right) - z \cdot \sin y \]
  2. Taylor expanded in y around 0

    \[\leadsto \color{blue}{1 + x} \]
  3. Applied rewrites62.3%

    \[\leadsto \color{blue}{1 + x} \]
  4. Taylor expanded in x around 0

    \[\leadsto 1 \]
  5. Applied rewrites22.1%

    \[\leadsto 1 \]
  6. Add Preprocessing

Alternative 15: 2.5% accurate, 72.9× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
	return 0.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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 0.0d0
end function
public static double code(double x, double y, double z) {
	return 0.0;
}
def code(x, y, z):
	return 0.0
function code(x, y, z)
	return 0.0
end
function tmp = code(x, y, z)
	tmp = 0.0;
end
code[x_, y_, z_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x + \cos y\right) - z \cdot \sin y \]
  2. Taylor expanded in y around 0

    \[\leadsto \color{blue}{1 + x} \]
  3. Applied rewrites62.3%

    \[\leadsto \color{blue}{1 + x} \]
  4. Taylor expanded in x around 0

    \[\leadsto 1 \]
  5. Applied rewrites22.1%

    \[\leadsto 1 \]
  6. Applied rewrites2.5%

    \[\leadsto 0 \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2025159 
(FPCore (x y z)
  :name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
  :precision binary64
  (- (+ x (cos y)) (* z (sin y))))