Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A

Percentage Accurate: 99.8% → 99.9%
Time: 6.5s
Alternatives: 9
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / 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 = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z):
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z)
	return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
end
function tmp = code(x, y, z)
	tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{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 9 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.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / 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 = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
}
def code(x, y, z):
	return 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
function code(x, y, z)
	return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
end
function tmp = code(x, y, z)
	tmp = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}
\end{array}

Alternative 1: 99.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{-4 \cdot \left(z - x\right)}{y} + 4 \end{array} \]
(FPCore (x y z) :precision binary64 (+ (/ (* -4.0 (- z x)) y) 4.0))
double code(double x, double y, double z) {
	return ((-4.0 * (z - x)) / y) + 4.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 = (((-4.0d0) * (z - x)) / y) + 4.0d0
end function
public static double code(double x, double y, double z) {
	return ((-4.0 * (z - x)) / y) + 4.0;
}
def code(x, y, z):
	return ((-4.0 * (z - x)) / y) + 4.0
function code(x, y, z)
	return Float64(Float64(Float64(-4.0 * Float64(z - x)) / y) + 4.0)
end
function tmp = code(x, y, z)
	tmp = ((-4.0 * (z - x)) / y) + 4.0;
end
code[x_, y_, z_] := N[(N[(N[(-4.0 * N[(z - x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + 4.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{-4 \cdot \left(z - x\right)}{y} + 4
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
  2. Applied rewrites99.9%

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

Alternative 2: 98.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x - z\right) \cdot \frac{4}{y}\\ t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\ \mathbf{if}\;t\_1 \leq -5000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 100:\\ \;\;\;\;\mathsf{fma}\left(\frac{z}{y}, -4, 4\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (- x z) (/ 4.0 y)))
        (t_1 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y))))
   (if (<= t_1 -5000.0) t_0 (if (<= t_1 100.0) (fma (/ z y) -4.0 4.0) t_0))))
double code(double x, double y, double z) {
	double t_0 = (x - z) * (4.0 / y);
	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
	double tmp;
	if (t_1 <= -5000.0) {
		tmp = t_0;
	} else if (t_1 <= 100.0) {
		tmp = fma((z / y), -4.0, 4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(x - z) * Float64(4.0 / y))
	t_1 = Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
	tmp = 0.0
	if (t_1 <= -5000.0)
		tmp = t_0;
	elseif (t_1 <= 100.0)
		tmp = fma(Float64(z / y), -4.0, 4.0);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - z), $MachinePrecision] * N[(4.0 / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5000.0], t$95$0, If[LessEqual[t$95$1, 100.0], N[(N[(z / y), $MachinePrecision] * -4.0 + 4.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 100:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{y}, -4, 4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < -5e3 or 100 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y))

    1. Initial program 99.7%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y}} \]
    3. Step-by-step derivation
      1. associate-*r/N/A

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

        \[\leadsto \frac{\left(x - z\right) \cdot 4}{y} \]
      3. associate-/l*N/A

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

        \[\leadsto \left(1 \cdot \left(x - z\right)\right) \cdot \frac{\color{blue}{4}}{y} \]
      5. metadata-evalN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x - z\right)\right) \cdot \frac{4}{y} \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \left(\mathsf{neg}\left(-1 \cdot \left(x - z\right)\right)\right) \cdot \frac{\color{blue}{4}}{y} \]
      7. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(x - z\right)\right)\right)\right)\right) \cdot \frac{4}{y} \]
      8. metadata-evalN/A

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(x - z\right)\right)\right)\right)\right) \cdot \frac{4 \cdot 1}{y} \]
      9. associate-*r/N/A

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

        \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\left(x - z\right)\right)\right)\right)\right) \cdot \color{blue}{\left(4 \cdot \frac{1}{y}\right)} \]
      11. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(-1 \cdot \left(x - z\right)\right)\right) \cdot \left(4 \cdot \frac{1}{y}\right) \]
      12. distribute-lft-neg-inN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x - z\right)\right) \cdot \left(\color{blue}{4} \cdot \frac{1}{y}\right) \]
      13. metadata-evalN/A

        \[\leadsto \left(1 \cdot \left(x - z\right)\right) \cdot \left(4 \cdot \frac{1}{y}\right) \]
      14. *-lft-identityN/A

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

        \[\leadsto \left(x - z\right) \cdot \left(\color{blue}{4} \cdot \frac{1}{y}\right) \]
      16. associate-*r/N/A

        \[\leadsto \left(x - z\right) \cdot \frac{4 \cdot 1}{\color{blue}{y}} \]
      17. metadata-evalN/A

        \[\leadsto \left(x - z\right) \cdot \frac{4}{y} \]
      18. frac-2negN/A

        \[\leadsto \left(x - z\right) \cdot \frac{\mathsf{neg}\left(4\right)}{\color{blue}{\mathsf{neg}\left(y\right)}} \]
      19. metadata-evalN/A

        \[\leadsto \left(x - z\right) \cdot \frac{-4}{\mathsf{neg}\left(\color{blue}{y}\right)} \]
      20. frac-2negN/A

        \[\leadsto \left(x - z\right) \cdot \frac{\mathsf{neg}\left(-4\right)}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      21. metadata-evalN/A

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

        \[\leadsto \left(x - z\right) \cdot \frac{4}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      23. /-rgt-identityN/A

        \[\leadsto \left(x - z\right) \cdot \frac{4}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\color{blue}{1}}} \]
      24. metadata-evalN/A

        \[\leadsto \left(x - z\right) \cdot \frac{4}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \]
      25. frac-2negN/A

        \[\leadsto \left(x - z\right) \cdot \frac{4}{\frac{\mathsf{neg}\left(y\right)}{\color{blue}{-1}}} \]
      26. metadata-evalN/A

        \[\leadsto \left(x - z\right) \cdot \frac{4}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \]
      27. frac-2neg-revN/A

        \[\leadsto \left(x - z\right) \cdot \frac{4}{\frac{y}{\color{blue}{1}}} \]
      28. /-rgt-identity98.5

        \[\leadsto \left(x - z\right) \cdot \frac{4}{y} \]
    4. Applied rewrites98.5%

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

    if -5e3 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < 100

    1. Initial program 99.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Applied rewrites100.0%

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

      \[\leadsto \color{blue}{4 + -4 \cdot \frac{z}{y}} \]
    4. Step-by-step derivation
      1. fp-cancel-sign-sub-invN/A

        \[\leadsto 4 - \color{blue}{\left(\mathsf{neg}\left(-4\right)\right) \cdot \frac{z}{y}} \]
      2. metadata-evalN/A

        \[\leadsto 4 \cdot 1 - \color{blue}{\left(\mathsf{neg}\left(-4\right)\right)} \cdot \frac{z}{y} \]
      3. metadata-evalN/A

        \[\leadsto 4 \cdot 1 - 4 \cdot \frac{\color{blue}{z}}{y} \]
      4. distribute-lft-out--N/A

        \[\leadsto 4 \cdot \color{blue}{\left(1 - \frac{z}{y}\right)} \]
      5. *-inversesN/A

        \[\leadsto 4 \cdot \left(\frac{y}{y} - \frac{\color{blue}{z}}{y}\right) \]
      6. distribute-lft-out--N/A

        \[\leadsto 4 \cdot \frac{y}{y} - \color{blue}{4 \cdot \frac{z}{y}} \]
      7. associate-/l*N/A

        \[\leadsto \frac{4 \cdot y}{y} - \color{blue}{4} \cdot \frac{z}{y} \]
      8. associate-*r/N/A

        \[\leadsto \frac{4 \cdot y}{y} - \frac{4 \cdot z}{\color{blue}{y}} \]
      9. div-subN/A

        \[\leadsto \frac{4 \cdot y - 4 \cdot z}{\color{blue}{y}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{4 \cdot y - \left(\mathsf{neg}\left(-4\right)\right) \cdot z}{y} \]
      11. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{4 \cdot y + -4 \cdot z}{y} \]
      12. +-commutativeN/A

        \[\leadsto \frac{-4 \cdot z + 4 \cdot y}{y} \]
      13. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{-4 \cdot z - \left(\mathsf{neg}\left(4\right)\right) \cdot y}{y} \]
      14. metadata-evalN/A

        \[\leadsto \frac{-4 \cdot z - -4 \cdot y}{y} \]
      15. *-commutativeN/A

        \[\leadsto \frac{-4 \cdot z - y \cdot -4}{y} \]
      16. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{-4 \cdot z + \left(\mathsf{neg}\left(y\right)\right) \cdot -4}{y} \]
      17. div-addN/A

        \[\leadsto \frac{-4 \cdot z}{y} + \color{blue}{\frac{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}{y}} \]
      18. associate-*r/N/A

        \[\leadsto -4 \cdot \frac{z}{y} + \frac{\color{blue}{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}}{y} \]
      19. *-commutativeN/A

        \[\leadsto \frac{z}{y} \cdot -4 + \frac{\color{blue}{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}}{y} \]
      20. remove-double-negN/A

        \[\leadsto \frac{z}{y} \cdot -4 + \frac{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)} \]
    5. Applied rewrites97.8%

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

Alternative 3: 85.4% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;z \leq 3.4 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, 4, 4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -9.9999999999999999e45 or 3.4000000000000003e-30 < z

    1. Initial program 99.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Applied rewrites99.8%

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

      \[\leadsto \color{blue}{4 + -4 \cdot \frac{z}{y}} \]
    4. Step-by-step derivation
      1. fp-cancel-sign-sub-invN/A

        \[\leadsto 4 - \color{blue}{\left(\mathsf{neg}\left(-4\right)\right) \cdot \frac{z}{y}} \]
      2. metadata-evalN/A

        \[\leadsto 4 \cdot 1 - \color{blue}{\left(\mathsf{neg}\left(-4\right)\right)} \cdot \frac{z}{y} \]
      3. metadata-evalN/A

        \[\leadsto 4 \cdot 1 - 4 \cdot \frac{\color{blue}{z}}{y} \]
      4. distribute-lft-out--N/A

        \[\leadsto 4 \cdot \color{blue}{\left(1 - \frac{z}{y}\right)} \]
      5. *-inversesN/A

        \[\leadsto 4 \cdot \left(\frac{y}{y} - \frac{\color{blue}{z}}{y}\right) \]
      6. distribute-lft-out--N/A

        \[\leadsto 4 \cdot \frac{y}{y} - \color{blue}{4 \cdot \frac{z}{y}} \]
      7. associate-/l*N/A

        \[\leadsto \frac{4 \cdot y}{y} - \color{blue}{4} \cdot \frac{z}{y} \]
      8. associate-*r/N/A

        \[\leadsto \frac{4 \cdot y}{y} - \frac{4 \cdot z}{\color{blue}{y}} \]
      9. div-subN/A

        \[\leadsto \frac{4 \cdot y - 4 \cdot z}{\color{blue}{y}} \]
      10. metadata-evalN/A

        \[\leadsto \frac{4 \cdot y - \left(\mathsf{neg}\left(-4\right)\right) \cdot z}{y} \]
      11. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{4 \cdot y + -4 \cdot z}{y} \]
      12. +-commutativeN/A

        \[\leadsto \frac{-4 \cdot z + 4 \cdot y}{y} \]
      13. fp-cancel-sign-sub-invN/A

        \[\leadsto \frac{-4 \cdot z - \left(\mathsf{neg}\left(4\right)\right) \cdot y}{y} \]
      14. metadata-evalN/A

        \[\leadsto \frac{-4 \cdot z - -4 \cdot y}{y} \]
      15. *-commutativeN/A

        \[\leadsto \frac{-4 \cdot z - y \cdot -4}{y} \]
      16. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{-4 \cdot z + \left(\mathsf{neg}\left(y\right)\right) \cdot -4}{y} \]
      17. div-addN/A

        \[\leadsto \frac{-4 \cdot z}{y} + \color{blue}{\frac{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}{y}} \]
      18. associate-*r/N/A

        \[\leadsto -4 \cdot \frac{z}{y} + \frac{\color{blue}{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}}{y} \]
      19. *-commutativeN/A

        \[\leadsto \frac{z}{y} \cdot -4 + \frac{\color{blue}{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}}{y} \]
      20. remove-double-negN/A

        \[\leadsto \frac{z}{y} \cdot -4 + \frac{\left(\mathsf{neg}\left(y\right)\right) \cdot -4}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)} \]
    5. Applied rewrites81.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{z}{y}, -4, 4\right)} \]

    if -9.9999999999999999e45 < z < 3.4000000000000003e-30

    1. Initial program 99.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Applied rewrites99.9%

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x}{y}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto 4 \cdot \frac{x}{y} + \color{blue}{4} \]
      2. associate-*r/N/A

        \[\leadsto \frac{4 \cdot x}{y} + 4 \]
      3. associate-*l/N/A

        \[\leadsto \frac{4}{y} \cdot x + 4 \]
      4. metadata-evalN/A

        \[\leadsto \frac{4 \cdot 1}{y} \cdot x + 4 \]
      5. associate-*r/N/A

        \[\leadsto \left(4 \cdot \frac{1}{y}\right) \cdot x + 4 \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot \frac{1}{y}, \color{blue}{x}, 4\right) \]
      7. associate-*r/N/A

        \[\leadsto \mathsf{fma}\left(\frac{4 \cdot 1}{y}, x, 4\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{4}{y}, x, 4\right) \]
      9. lift-/.f6489.4

        \[\leadsto \mathsf{fma}\left(\frac{4}{y}, x, 4\right) \]
    5. Applied rewrites89.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{4}{y}, x, 4\right)} \]
    6. Applied rewrites89.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, 4, 4\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 79.1% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 2.1 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, 4, 4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.8000000000000004e53 or 2.0999999999999999e179 < z

    1. Initial program 99.7%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -4 \cdot \color{blue}{\frac{z}{y}} \]
      2. frac-2negN/A

        \[\leadsto -4 \cdot \frac{\mathsf{neg}\left(z\right)}{\color{blue}{\mathsf{neg}\left(y\right)}} \]
      3. distribute-frac-negN/A

        \[\leadsto -4 \cdot \left(\mathsf{neg}\left(\frac{z}{\mathsf{neg}\left(y\right)}\right)\right) \]
      4. distribute-frac-neg2N/A

        \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      6. /-rgt-identityN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\color{blue}{1}}} \]
      7. metadata-evalN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \]
      8. frac-2negN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\color{blue}{-1}}} \]
      9. metadata-evalN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \]
      10. frac-2neg-revN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{y}{\color{blue}{1}}} \]
      11. /-rgt-identity71.6

        \[\leadsto -4 \cdot \frac{z}{y} \]
    4. Applied rewrites71.6%

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]

    if -5.8000000000000004e53 < z < 2.0999999999999999e179

    1. Initial program 99.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Applied rewrites99.9%

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

      \[\leadsto \color{blue}{4 + 4 \cdot \frac{x}{y}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto 4 \cdot \frac{x}{y} + \color{blue}{4} \]
      2. associate-*r/N/A

        \[\leadsto \frac{4 \cdot x}{y} + 4 \]
      3. associate-*l/N/A

        \[\leadsto \frac{4}{y} \cdot x + 4 \]
      4. metadata-evalN/A

        \[\leadsto \frac{4 \cdot 1}{y} \cdot x + 4 \]
      5. associate-*r/N/A

        \[\leadsto \left(4 \cdot \frac{1}{y}\right) \cdot x + 4 \]
      6. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot \frac{1}{y}, \color{blue}{x}, 4\right) \]
      7. associate-*r/N/A

        \[\leadsto \mathsf{fma}\left(\frac{4 \cdot 1}{y}, x, 4\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{4}{y}, x, 4\right) \]
      9. lift-/.f6482.3

        \[\leadsto \mathsf{fma}\left(\frac{4}{y}, x, 4\right) \]
    5. Applied rewrites82.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{4}{y}, x, 4\right)} \]
    6. Applied rewrites82.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, 4, 4\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 79.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_0 := -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -5.8 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 2.1 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(\frac{4}{y}, x, 4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5.8000000000000004e53 or 2.0999999999999999e179 < z

    1. Initial program 99.7%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -4 \cdot \color{blue}{\frac{z}{y}} \]
      2. frac-2negN/A

        \[\leadsto -4 \cdot \frac{\mathsf{neg}\left(z\right)}{\color{blue}{\mathsf{neg}\left(y\right)}} \]
      3. distribute-frac-negN/A

        \[\leadsto -4 \cdot \left(\mathsf{neg}\left(\frac{z}{\mathsf{neg}\left(y\right)}\right)\right) \]
      4. distribute-frac-neg2N/A

        \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      6. /-rgt-identityN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\color{blue}{1}}} \]
      7. metadata-evalN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \]
      8. frac-2negN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\color{blue}{-1}}} \]
      9. metadata-evalN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \]
      10. frac-2neg-revN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{y}{\color{blue}{1}}} \]
      11. /-rgt-identity71.6

        \[\leadsto -4 \cdot \frac{z}{y} \]
    4. Applied rewrites71.6%

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]

    if -5.8000000000000004e53 < z < 2.0999999999999999e179

    1. Initial program 99.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in z around 0

      \[\leadsto \color{blue}{1 + 4 \cdot \frac{x + \frac{3}{4} \cdot y}{y}} \]
    3. Applied rewrites82.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{4}{y}, x, 4\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 66.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\ t_2 := \frac{x}{y} \cdot 4\\ \mathbf{if}\;t\_1 \leq -3 \cdot 10^{+160}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq -1000:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 100:\\ \;\;\;\;4\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+213}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* -4.0 (/ z y)))
        (t_1 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
        (t_2 (* (/ x y) 4.0)))
   (if (<= t_1 -3e+160)
     t_0
     (if (<= t_1 -1000.0)
       t_2
       (if (<= t_1 100.0) 4.0 (if (<= t_1 5e+213) t_2 t_0))))))
double code(double x, double y, double z) {
	double t_0 = -4.0 * (z / y);
	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
	double t_2 = (x / y) * 4.0;
	double tmp;
	if (t_1 <= -3e+160) {
		tmp = t_0;
	} else if (t_1 <= -1000.0) {
		tmp = t_2;
	} else if (t_1 <= 100.0) {
		tmp = 4.0;
	} else if (t_1 <= 5e+213) {
		tmp = t_2;
	} 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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = (-4.0d0) * (z / y)
    t_1 = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
    t_2 = (x / y) * 4.0d0
    if (t_1 <= (-3d+160)) then
        tmp = t_0
    else if (t_1 <= (-1000.0d0)) then
        tmp = t_2
    else if (t_1 <= 100.0d0) then
        tmp = 4.0d0
    else if (t_1 <= 5d+213) then
        tmp = t_2
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = -4.0 * (z / y);
	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
	double t_2 = (x / y) * 4.0;
	double tmp;
	if (t_1 <= -3e+160) {
		tmp = t_0;
	} else if (t_1 <= -1000.0) {
		tmp = t_2;
	} else if (t_1 <= 100.0) {
		tmp = 4.0;
	} else if (t_1 <= 5e+213) {
		tmp = t_2;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = -4.0 * (z / y)
	t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
	t_2 = (x / y) * 4.0
	tmp = 0
	if t_1 <= -3e+160:
		tmp = t_0
	elif t_1 <= -1000.0:
		tmp = t_2
	elif t_1 <= 100.0:
		tmp = 4.0
	elif t_1 <= 5e+213:
		tmp = t_2
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(-4.0 * Float64(z / y))
	t_1 = Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
	t_2 = Float64(Float64(x / y) * 4.0)
	tmp = 0.0
	if (t_1 <= -3e+160)
		tmp = t_0;
	elseif (t_1 <= -1000.0)
		tmp = t_2;
	elseif (t_1 <= 100.0)
		tmp = 4.0;
	elseif (t_1 <= 5e+213)
		tmp = t_2;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = -4.0 * (z / y);
	t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
	t_2 = (x / y) * 4.0;
	tmp = 0.0;
	if (t_1 <= -3e+160)
		tmp = t_0;
	elseif (t_1 <= -1000.0)
		tmp = t_2;
	elseif (t_1 <= 100.0)
		tmp = 4.0;
	elseif (t_1 <= 5e+213)
		tmp = t_2;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x / y), $MachinePrecision] * 4.0), $MachinePrecision]}, If[LessEqual[t$95$1, -3e+160], t$95$0, If[LessEqual[t$95$1, -1000.0], t$95$2, If[LessEqual[t$95$1, 100.0], 4.0, If[LessEqual[t$95$1, 5e+213], t$95$2, t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -4 \cdot \frac{z}{y}\\
t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\
t_2 := \frac{x}{y} \cdot 4\\
\mathbf{if}\;t\_1 \leq -3 \cdot 10^{+160}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq -1000:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 100:\\
\;\;\;\;4\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+213}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < -2.9999999999999999e160 or 4.9999999999999998e213 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y))

    1. Initial program 99.6%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in z around inf

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto -4 \cdot \color{blue}{\frac{z}{y}} \]
      2. frac-2negN/A

        \[\leadsto -4 \cdot \frac{\mathsf{neg}\left(z\right)}{\color{blue}{\mathsf{neg}\left(y\right)}} \]
      3. distribute-frac-negN/A

        \[\leadsto -4 \cdot \left(\mathsf{neg}\left(\frac{z}{\mathsf{neg}\left(y\right)}\right)\right) \]
      4. distribute-frac-neg2N/A

        \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      5. lower-/.f64N/A

        \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
      6. /-rgt-identityN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\color{blue}{1}}} \]
      7. metadata-evalN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \]
      8. frac-2negN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\color{blue}{-1}}} \]
      9. metadata-evalN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \]
      10. frac-2neg-revN/A

        \[\leadsto -4 \cdot \frac{z}{\frac{y}{\color{blue}{1}}} \]
      11. /-rgt-identity53.3

        \[\leadsto -4 \cdot \frac{z}{y} \]
    4. Applied rewrites53.3%

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]

    if -2.9999999999999999e160 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < -1e3 or 100 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < 4.9999999999999998e213

    1. Initial program 99.9%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \frac{x}{y} \cdot \color{blue}{4} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{x}{y} \cdot \color{blue}{4} \]
      3. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(x\right)}{\mathsf{neg}\left(y\right)} \cdot 4 \]
      4. distribute-frac-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{x}{\mathsf{neg}\left(y\right)}\right)\right) \cdot 4 \]
      5. distribute-frac-neg2N/A

        \[\leadsto \frac{x}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)} \cdot 4 \]
      6. lower-/.f64N/A

        \[\leadsto \frac{x}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)} \cdot 4 \]
      7. /-rgt-identityN/A

        \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{1}} \cdot 4 \]
      8. metadata-evalN/A

        \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \cdot 4 \]
      9. frac-2negN/A

        \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(y\right)}{-1}} \cdot 4 \]
      10. metadata-evalN/A

        \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \cdot 4 \]
      11. frac-2neg-revN/A

        \[\leadsto \frac{x}{\frac{y}{1}} \cdot 4 \]
      12. /-rgt-identity48.7

        \[\leadsto \frac{x}{y} \cdot 4 \]
    4. Applied rewrites48.7%

      \[\leadsto \color{blue}{\frac{x}{y} \cdot 4} \]

    if -1e3 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < 100

    1. Initial program 99.8%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Taylor expanded in y around inf

      \[\leadsto \color{blue}{4} \]
    3. Step-by-step derivation
      1. Applied rewrites96.1%

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

    Alternative 7: 66.2% accurate, 0.2× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\ t_2 := \frac{4}{y} \cdot x\\ \mathbf{if}\;t\_1 \leq -3 \cdot 10^{+160}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq -1000:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 100:\\ \;\;\;\;4\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+213}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (let* ((t_0 (* -4.0 (/ z y)))
            (t_1 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))
            (t_2 (* (/ 4.0 y) x)))
       (if (<= t_1 -3e+160)
         t_0
         (if (<= t_1 -1000.0)
           t_2
           (if (<= t_1 100.0) 4.0 (if (<= t_1 5e+213) t_2 t_0))))))
    double code(double x, double y, double z) {
    	double t_0 = -4.0 * (z / y);
    	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
    	double t_2 = (4.0 / y) * x;
    	double tmp;
    	if (t_1 <= -3e+160) {
    		tmp = t_0;
    	} else if (t_1 <= -1000.0) {
    		tmp = t_2;
    	} else if (t_1 <= 100.0) {
    		tmp = 4.0;
    	} else if (t_1 <= 5e+213) {
    		tmp = t_2;
    	} 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) :: t_1
        real(8) :: t_2
        real(8) :: tmp
        t_0 = (-4.0d0) * (z / y)
        t_1 = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
        t_2 = (4.0d0 / y) * x
        if (t_1 <= (-3d+160)) then
            tmp = t_0
        else if (t_1 <= (-1000.0d0)) then
            tmp = t_2
        else if (t_1 <= 100.0d0) then
            tmp = 4.0d0
        else if (t_1 <= 5d+213) then
            tmp = t_2
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double x, double y, double z) {
    	double t_0 = -4.0 * (z / y);
    	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
    	double t_2 = (4.0 / y) * x;
    	double tmp;
    	if (t_1 <= -3e+160) {
    		tmp = t_0;
    	} else if (t_1 <= -1000.0) {
    		tmp = t_2;
    	} else if (t_1 <= 100.0) {
    		tmp = 4.0;
    	} else if (t_1 <= 5e+213) {
    		tmp = t_2;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	t_0 = -4.0 * (z / y)
    	t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
    	t_2 = (4.0 / y) * x
    	tmp = 0
    	if t_1 <= -3e+160:
    		tmp = t_0
    	elif t_1 <= -1000.0:
    		tmp = t_2
    	elif t_1 <= 100.0:
    		tmp = 4.0
    	elif t_1 <= 5e+213:
    		tmp = t_2
    	else:
    		tmp = t_0
    	return tmp
    
    function code(x, y, z)
    	t_0 = Float64(-4.0 * Float64(z / y))
    	t_1 = Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
    	t_2 = Float64(Float64(4.0 / y) * x)
    	tmp = 0.0
    	if (t_1 <= -3e+160)
    		tmp = t_0;
    	elseif (t_1 <= -1000.0)
    		tmp = t_2;
    	elseif (t_1 <= 100.0)
    		tmp = 4.0;
    	elseif (t_1 <= 5e+213)
    		tmp = t_2;
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z)
    	t_0 = -4.0 * (z / y);
    	t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
    	t_2 = (4.0 / y) * x;
    	tmp = 0.0;
    	if (t_1 <= -3e+160)
    		tmp = t_0;
    	elseif (t_1 <= -1000.0)
    		tmp = t_2;
    	elseif (t_1 <= 100.0)
    		tmp = 4.0;
    	elseif (t_1 <= 5e+213)
    		tmp = t_2;
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(4.0 / y), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$1, -3e+160], t$95$0, If[LessEqual[t$95$1, -1000.0], t$95$2, If[LessEqual[t$95$1, 100.0], 4.0, If[LessEqual[t$95$1, 5e+213], t$95$2, t$95$0]]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := -4 \cdot \frac{z}{y}\\
    t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\
    t_2 := \frac{4}{y} \cdot x\\
    \mathbf{if}\;t\_1 \leq -3 \cdot 10^{+160}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;t\_1 \leq -1000:\\
    \;\;\;\;t\_2\\
    
    \mathbf{elif}\;t\_1 \leq 100:\\
    \;\;\;\;4\\
    
    \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+213}:\\
    \;\;\;\;t\_2\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < -2.9999999999999999e160 or 4.9999999999999998e213 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y))

      1. Initial program 99.6%

        \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
      2. Taylor expanded in z around inf

        \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
      3. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto -4 \cdot \color{blue}{\frac{z}{y}} \]
        2. frac-2negN/A

          \[\leadsto -4 \cdot \frac{\mathsf{neg}\left(z\right)}{\color{blue}{\mathsf{neg}\left(y\right)}} \]
        3. distribute-frac-negN/A

          \[\leadsto -4 \cdot \left(\mathsf{neg}\left(\frac{z}{\mathsf{neg}\left(y\right)}\right)\right) \]
        4. distribute-frac-neg2N/A

          \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
        5. lower-/.f64N/A

          \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
        6. /-rgt-identityN/A

          \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\color{blue}{1}}} \]
        7. metadata-evalN/A

          \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \]
        8. frac-2negN/A

          \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\color{blue}{-1}}} \]
        9. metadata-evalN/A

          \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \]
        10. frac-2neg-revN/A

          \[\leadsto -4 \cdot \frac{z}{\frac{y}{\color{blue}{1}}} \]
        11. /-rgt-identity53.3

          \[\leadsto -4 \cdot \frac{z}{y} \]
      4. Applied rewrites53.3%

        \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]

      if -2.9999999999999999e160 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < -1e3 or 100 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < 4.9999999999999998e213

      1. Initial program 99.9%

        \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
      2. Taylor expanded in x around inf

        \[\leadsto \color{blue}{4 \cdot \frac{x}{y}} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \frac{x}{y} \cdot \color{blue}{4} \]
        2. lower-*.f64N/A

          \[\leadsto \frac{x}{y} \cdot \color{blue}{4} \]
        3. frac-2negN/A

          \[\leadsto \frac{\mathsf{neg}\left(x\right)}{\mathsf{neg}\left(y\right)} \cdot 4 \]
        4. distribute-frac-negN/A

          \[\leadsto \left(\mathsf{neg}\left(\frac{x}{\mathsf{neg}\left(y\right)}\right)\right) \cdot 4 \]
        5. distribute-frac-neg2N/A

          \[\leadsto \frac{x}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)} \cdot 4 \]
        6. lower-/.f64N/A

          \[\leadsto \frac{x}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)} \cdot 4 \]
        7. /-rgt-identityN/A

          \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{1}} \cdot 4 \]
        8. metadata-evalN/A

          \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \cdot 4 \]
        9. frac-2negN/A

          \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(y\right)}{-1}} \cdot 4 \]
        10. metadata-evalN/A

          \[\leadsto \frac{x}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \cdot 4 \]
        11. frac-2neg-revN/A

          \[\leadsto \frac{x}{\frac{y}{1}} \cdot 4 \]
        12. /-rgt-identity48.7

          \[\leadsto \frac{x}{y} \cdot 4 \]
      4. Applied rewrites48.7%

        \[\leadsto \color{blue}{\frac{x}{y} \cdot 4} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \frac{x}{y} \cdot \color{blue}{4} \]
        2. lift-/.f64N/A

          \[\leadsto \frac{x}{y} \cdot 4 \]
        3. *-commutativeN/A

          \[\leadsto 4 \cdot \color{blue}{\frac{x}{y}} \]
        4. associate-*r/N/A

          \[\leadsto \frac{4 \cdot x}{\color{blue}{y}} \]
        5. associate-*l/N/A

          \[\leadsto \frac{4}{y} \cdot \color{blue}{x} \]
        6. metadata-evalN/A

          \[\leadsto \frac{4 \cdot 1}{y} \cdot x \]
        7. associate-*r/N/A

          \[\leadsto \left(4 \cdot \frac{1}{y}\right) \cdot x \]
        8. lower-*.f64N/A

          \[\leadsto \left(4 \cdot \frac{1}{y}\right) \cdot \color{blue}{x} \]
        9. associate-*r/N/A

          \[\leadsto \frac{4 \cdot 1}{y} \cdot x \]
        10. metadata-evalN/A

          \[\leadsto \frac{4}{y} \cdot x \]
        11. lift-/.f6448.5

          \[\leadsto \frac{4}{y} \cdot x \]
      6. Applied rewrites48.5%

        \[\leadsto \frac{4}{y} \cdot \color{blue}{x} \]

      if -1e3 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < 100

      1. Initial program 99.8%

        \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
      2. Taylor expanded in y around inf

        \[\leadsto \color{blue}{4} \]
      3. Step-by-step derivation
        1. Applied rewrites96.1%

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

      Alternative 8: 66.1% accurate, 0.4× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := -4 \cdot \frac{z}{y}\\ t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\ \mathbf{if}\;t\_1 \leq -1000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 400000000:\\ \;\;\;\;4\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (let* ((t_0 (* -4.0 (/ z y)))
              (t_1 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y))))
         (if (<= t_1 -1000.0) t_0 (if (<= t_1 400000000.0) 4.0 t_0))))
      double code(double x, double y, double z) {
      	double t_0 = -4.0 * (z / y);
      	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
      	double tmp;
      	if (t_1 <= -1000.0) {
      		tmp = t_0;
      	} else if (t_1 <= 400000000.0) {
      		tmp = 4.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)
      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 = (-4.0d0) * (z / y)
          t_1 = 1.0d0 + ((4.0d0 * ((x + (y * 0.75d0)) - z)) / y)
          if (t_1 <= (-1000.0d0)) then
              tmp = t_0
          else if (t_1 <= 400000000.0d0) then
              tmp = 4.0d0
          else
              tmp = t_0
          end if
          code = tmp
      end function
      
      public static double code(double x, double y, double z) {
      	double t_0 = -4.0 * (z / y);
      	double t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
      	double tmp;
      	if (t_1 <= -1000.0) {
      		tmp = t_0;
      	} else if (t_1 <= 400000000.0) {
      		tmp = 4.0;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	t_0 = -4.0 * (z / y)
      	t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y)
      	tmp = 0
      	if t_1 <= -1000.0:
      		tmp = t_0
      	elif t_1 <= 400000000.0:
      		tmp = 4.0
      	else:
      		tmp = t_0
      	return tmp
      
      function code(x, y, z)
      	t_0 = Float64(-4.0 * Float64(z / y))
      	t_1 = Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.75)) - z)) / y))
      	tmp = 0.0
      	if (t_1 <= -1000.0)
      		tmp = t_0;
      	elseif (t_1 <= 400000000.0)
      		tmp = 4.0;
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	t_0 = -4.0 * (z / y);
      	t_1 = 1.0 + ((4.0 * ((x + (y * 0.75)) - z)) / y);
      	tmp = 0.0;
      	if (t_1 <= -1000.0)
      		tmp = t_0;
      	elseif (t_1 <= 400000000.0)
      		tmp = 4.0;
      	else
      		tmp = t_0;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := Block[{t$95$0 = N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.75), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1000.0], t$95$0, If[LessEqual[t$95$1, 400000000.0], 4.0, t$95$0]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := -4 \cdot \frac{z}{y}\\
      t_1 := 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y}\\
      \mathbf{if}\;t\_1 \leq -1000:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;t\_1 \leq 400000000:\\
      \;\;\;\;4\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < -1e3 or 4e8 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y))

        1. Initial program 99.7%

          \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
        2. Taylor expanded in z around inf

          \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
        3. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto -4 \cdot \color{blue}{\frac{z}{y}} \]
          2. frac-2negN/A

            \[\leadsto -4 \cdot \frac{\mathsf{neg}\left(z\right)}{\color{blue}{\mathsf{neg}\left(y\right)}} \]
          3. distribute-frac-negN/A

            \[\leadsto -4 \cdot \left(\mathsf{neg}\left(\frac{z}{\mathsf{neg}\left(y\right)}\right)\right) \]
          4. distribute-frac-neg2N/A

            \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
          5. lower-/.f64N/A

            \[\leadsto -4 \cdot \frac{z}{\color{blue}{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}} \]
          6. /-rgt-identityN/A

            \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\color{blue}{1}}} \]
          7. metadata-evalN/A

            \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)}{\mathsf{neg}\left(-1\right)}} \]
          8. frac-2negN/A

            \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\color{blue}{-1}}} \]
          9. metadata-evalN/A

            \[\leadsto -4 \cdot \frac{z}{\frac{\mathsf{neg}\left(y\right)}{\mathsf{neg}\left(1\right)}} \]
          10. frac-2neg-revN/A

            \[\leadsto -4 \cdot \frac{z}{\frac{y}{\color{blue}{1}}} \]
          11. /-rgt-identity52.0

            \[\leadsto -4 \cdot \frac{z}{y} \]
        4. Applied rewrites52.0%

          \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]

        if -1e3 < (+.f64 #s(literal 1 binary64) (/.f64 (*.f64 #s(literal 4 binary64) (-.f64 (+.f64 x (*.f64 y #s(literal 3/4 binary64))) z)) y)) < 4e8

        1. Initial program 99.8%

          \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
        2. Taylor expanded in y around inf

          \[\leadsto \color{blue}{4} \]
        3. Step-by-step derivation
          1. Applied rewrites95.0%

            \[\leadsto \color{blue}{4} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 9: 33.7% accurate, 18.4× speedup?

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

          \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
        2. Taylor expanded in y around inf

          \[\leadsto \color{blue}{4} \]
        3. Step-by-step derivation
          1. Applied rewrites33.7%

            \[\leadsto \color{blue}{4} \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025130 
          (FPCore (x y z)
            :name "Data.Array.Repa.Algorithms.ColorRamp:rampColorHotToCold from repa-algorithms-3.4.0.1, A"
            :precision binary64
            (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.75)) z)) y)))