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

Percentage Accurate: 99.8% → 100.0%
Time: 5.6s
Alternatives: 9
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ 1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (+ 1.0 (/ (* 4.0 (- (+ x (* y 0.25)) z)) y)))
double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 1.0d0 + ((4.0d0 * ((x + (y * 0.25d0)) - z)) / y)
end function
public static double code(double x, double y, double z) {
	return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
}
def code(x, y, z):
	return 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y)
function code(x, y, z)
	return Float64(1.0 + Float64(Float64(4.0 * Float64(Float64(x + Float64(y * 0.25)) - z)) / y))
end
function tmp = code(x, y, z)
	tmp = 1.0 + ((4.0 * ((x + (y * 0.25)) - z)) / y);
end
code[x_, y_, z_] := N[(1.0 + N[(N[(4.0 * N[(N[(x + N[(y * 0.25), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

Alternative 1: 100.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ 4 \cdot \frac{x - z}{y} + 2 \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* 4.0 (/ (- x z) y)) 2.0))
double code(double x, double y, double z) {
	return (4.0 * ((x - z) / y)) + 2.0;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (4.0d0 * ((x - z) / y)) + 2.0d0
end function
public static double code(double x, double y, double z) {
	return (4.0 * ((x - z) / y)) + 2.0;
}
def code(x, y, z):
	return (4.0 * ((x - z) / y)) + 2.0
function code(x, y, z)
	return Float64(Float64(4.0 * Float64(Float64(x - z) / y)) + 2.0)
end
function tmp = code(x, y, z)
	tmp = (4.0 * ((x - z) / y)) + 2.0;
end
code[x_, y_, z_] := N[(N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}

\\
4 \cdot \frac{x - z}{y} + 2
\end{array}
Derivation
  1. Initial program 100.0%

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Step-by-step derivation
    1. associate-/l*99.7%

      \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
    2. associate--l+99.7%

      \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
  3. Simplified99.7%

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

    \[\leadsto \color{blue}{2 + 4 \cdot \frac{x - z}{y}} \]
  5. Step-by-step derivation
    1. +-commutative100.0%

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
  6. Simplified100.0%

    \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
  7. Final simplification100.0%

    \[\leadsto 4 \cdot \frac{x - z}{y} + 2 \]

Alternative 2: 57.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{4}{\frac{y}{x}}\\ t_1 := 1 + -4 \cdot \frac{z}{y}\\ \mathbf{if}\;z \leq -640:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{-249}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-278}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-179}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 950000:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (/ 4.0 (/ y x)))) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
   (if (<= z -640.0)
     t_1
     (if (<= z -4.6e-249)
       t_0
       (if (<= z 6.2e-278)
         2.0
         (if (<= z 7.2e-179) t_0 (if (<= z 950000.0) 2.0 t_1)))))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + (4.0 / (y / x));
	double t_1 = 1.0 + (-4.0 * (z / y));
	double tmp;
	if (z <= -640.0) {
		tmp = t_1;
	} else if (z <= -4.6e-249) {
		tmp = t_0;
	} else if (z <= 6.2e-278) {
		tmp = 2.0;
	} else if (z <= 7.2e-179) {
		tmp = t_0;
	} else if (z <= 950000.0) {
		tmp = 2.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    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 = 1.0d0 + (4.0d0 / (y / x))
    t_1 = 1.0d0 + ((-4.0d0) * (z / y))
    if (z <= (-640.0d0)) then
        tmp = t_1
    else if (z <= (-4.6d-249)) then
        tmp = t_0
    else if (z <= 6.2d-278) then
        tmp = 2.0d0
    else if (z <= 7.2d-179) then
        tmp = t_0
    else if (z <= 950000.0d0) then
        tmp = 2.0d0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 1.0 + (4.0 / (y / x));
	double t_1 = 1.0 + (-4.0 * (z / y));
	double tmp;
	if (z <= -640.0) {
		tmp = t_1;
	} else if (z <= -4.6e-249) {
		tmp = t_0;
	} else if (z <= 6.2e-278) {
		tmp = 2.0;
	} else if (z <= 7.2e-179) {
		tmp = t_0;
	} else if (z <= 950000.0) {
		tmp = 2.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + (4.0 / (y / x))
	t_1 = 1.0 + (-4.0 * (z / y))
	tmp = 0
	if z <= -640.0:
		tmp = t_1
	elif z <= -4.6e-249:
		tmp = t_0
	elif z <= 6.2e-278:
		tmp = 2.0
	elif z <= 7.2e-179:
		tmp = t_0
	elif z <= 950000.0:
		tmp = 2.0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(4.0 / Float64(y / x)))
	t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y)))
	tmp = 0.0
	if (z <= -640.0)
		tmp = t_1;
	elseif (z <= -4.6e-249)
		tmp = t_0;
	elseif (z <= 6.2e-278)
		tmp = 2.0;
	elseif (z <= 7.2e-179)
		tmp = t_0;
	elseif (z <= 950000.0)
		tmp = 2.0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + (4.0 / (y / x));
	t_1 = 1.0 + (-4.0 * (z / y));
	tmp = 0.0;
	if (z <= -640.0)
		tmp = t_1;
	elseif (z <= -4.6e-249)
		tmp = t_0;
	elseif (z <= 6.2e-278)
		tmp = 2.0;
	elseif (z <= 7.2e-179)
		tmp = t_0;
	elseif (z <= 950000.0)
		tmp = 2.0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(4.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -640.0], t$95$1, If[LessEqual[z, -4.6e-249], t$95$0, If[LessEqual[z, 6.2e-278], 2.0, If[LessEqual[z, 7.2e-179], t$95$0, If[LessEqual[z, 950000.0], 2.0, t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \frac{4}{\frac{y}{x}}\\
t_1 := 1 + -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -640:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -4.6 \cdot 10^{-249}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 6.2 \cdot 10^{-278}:\\
\;\;\;\;2\\

\mathbf{elif}\;z \leq 7.2 \cdot 10^{-179}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 950000:\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -640 or 9.5e5 < z

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto 1 + \color{blue}{-4 \cdot \frac{z}{y}} \]
    5. Step-by-step derivation
      1. *-commutative68.3%

        \[\leadsto 1 + \color{blue}{\frac{z}{y} \cdot -4} \]
    6. Simplified68.3%

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

    if -640 < z < -4.5999999999999996e-249 or 6.19999999999999983e-278 < z < 7.20000000000000015e-179

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]
    5. Step-by-step derivation
      1. associate-*r/65.4%

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. associate-/l*65.2%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{x}}} \]
    6. Simplified65.2%

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

    if -4.5999999999999996e-249 < z < 6.19999999999999983e-278 or 7.20000000000000015e-179 < z < 9.5e5

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.8%

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

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

      \[\leadsto \color{blue}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -640:\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq -4.6 \cdot 10^{-249}:\\ \;\;\;\;1 + \frac{4}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-278}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 7.2 \cdot 10^{-179}:\\ \;\;\;\;1 + \frac{4}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 950000:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \end{array} \]

Alternative 3: 57.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + \frac{4 \cdot x}{y}\\ t_1 := 1 + -4 \cdot \frac{z}{y}\\ \mathbf{if}\;z \leq -1600:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-250}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{-276}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-181}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 245000:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ 1.0 (/ (* 4.0 x) y))) (t_1 (+ 1.0 (* -4.0 (/ z y)))))
   (if (<= z -1600.0)
     t_1
     (if (<= z -8.8e-250)
       t_0
       (if (<= z 1.45e-276)
         2.0
         (if (<= z 7.6e-181) t_0 (if (<= z 245000.0) 2.0 t_1)))))))
double code(double x, double y, double z) {
	double t_0 = 1.0 + ((4.0 * x) / y);
	double t_1 = 1.0 + (-4.0 * (z / y));
	double tmp;
	if (z <= -1600.0) {
		tmp = t_1;
	} else if (z <= -8.8e-250) {
		tmp = t_0;
	} else if (z <= 1.45e-276) {
		tmp = 2.0;
	} else if (z <= 7.6e-181) {
		tmp = t_0;
	} else if (z <= 245000.0) {
		tmp = 2.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z)
    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 = 1.0d0 + ((4.0d0 * x) / y)
    t_1 = 1.0d0 + ((-4.0d0) * (z / y))
    if (z <= (-1600.0d0)) then
        tmp = t_1
    else if (z <= (-8.8d-250)) then
        tmp = t_0
    else if (z <= 1.45d-276) then
        tmp = 2.0d0
    else if (z <= 7.6d-181) then
        tmp = t_0
    else if (z <= 245000.0d0) then
        tmp = 2.0d0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = 1.0 + ((4.0 * x) / y);
	double t_1 = 1.0 + (-4.0 * (z / y));
	double tmp;
	if (z <= -1600.0) {
		tmp = t_1;
	} else if (z <= -8.8e-250) {
		tmp = t_0;
	} else if (z <= 1.45e-276) {
		tmp = 2.0;
	} else if (z <= 7.6e-181) {
		tmp = t_0;
	} else if (z <= 245000.0) {
		tmp = 2.0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 1.0 + ((4.0 * x) / y)
	t_1 = 1.0 + (-4.0 * (z / y))
	tmp = 0
	if z <= -1600.0:
		tmp = t_1
	elif z <= -8.8e-250:
		tmp = t_0
	elif z <= 1.45e-276:
		tmp = 2.0
	elif z <= 7.6e-181:
		tmp = t_0
	elif z <= 245000.0:
		tmp = 2.0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	t_0 = Float64(1.0 + Float64(Float64(4.0 * x) / y))
	t_1 = Float64(1.0 + Float64(-4.0 * Float64(z / y)))
	tmp = 0.0
	if (z <= -1600.0)
		tmp = t_1;
	elseif (z <= -8.8e-250)
		tmp = t_0;
	elseif (z <= 1.45e-276)
		tmp = 2.0;
	elseif (z <= 7.6e-181)
		tmp = t_0;
	elseif (z <= 245000.0)
		tmp = 2.0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 1.0 + ((4.0 * x) / y);
	t_1 = 1.0 + (-4.0 * (z / y));
	tmp = 0.0;
	if (z <= -1600.0)
		tmp = t_1;
	elseif (z <= -8.8e-250)
		tmp = t_0;
	elseif (z <= 1.45e-276)
		tmp = 2.0;
	elseif (z <= 7.6e-181)
		tmp = t_0;
	elseif (z <= 245000.0)
		tmp = 2.0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1600.0], t$95$1, If[LessEqual[z, -8.8e-250], t$95$0, If[LessEqual[z, 1.45e-276], 2.0, If[LessEqual[z, 7.6e-181], t$95$0, If[LessEqual[z, 245000.0], 2.0, t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + \frac{4 \cdot x}{y}\\
t_1 := 1 + -4 \cdot \frac{z}{y}\\
\mathbf{if}\;z \leq -1600:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq -8.8 \cdot 10^{-250}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.45 \cdot 10^{-276}:\\
\;\;\;\;2\\

\mathbf{elif}\;z \leq 7.6 \cdot 10^{-181}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 245000:\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -1600 or 245000 < z

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto 1 + \color{blue}{-4 \cdot \frac{z}{y}} \]
    5. Step-by-step derivation
      1. *-commutative68.3%

        \[\leadsto 1 + \color{blue}{\frac{z}{y} \cdot -4} \]
    6. Simplified68.3%

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

    if -1600 < z < -8.8e-250 or 1.44999999999999994e-276 < z < 7.5999999999999996e-181

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]
    5. Step-by-step derivation
      1. associate-*r/65.4%

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative65.4%

        \[\leadsto 1 + \frac{\color{blue}{x \cdot 4}}{y} \]
    6. Simplified65.4%

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

    if -8.8e-250 < z < 1.44999999999999994e-276 or 7.5999999999999996e-181 < z < 245000

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.8%

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

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

      \[\leadsto \color{blue}{2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification67.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1600:\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq -8.8 \cdot 10^{-250}:\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{-276}:\\ \;\;\;\;2\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{-181}:\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{elif}\;z \leq 245000:\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \end{array} \]

Alternative 4: 85.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{-31} \lor \neg \left(y \leq 1.75 \cdot 10^{+136}\right):\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{4}{\frac{y}{x - z}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -7.2e-31) (not (<= y 1.75e+136)))
   (+ 2.0 (* -4.0 (/ z y)))
   (+ 1.0 (/ 4.0 (/ y (- x z))))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -7.2e-31) || !(y <= 1.75e+136)) {
		tmp = 2.0 + (-4.0 * (z / y));
	} else {
		tmp = 1.0 + (4.0 / (y / (x - z)));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-7.2d-31)) .or. (.not. (y <= 1.75d+136))) then
        tmp = 2.0d0 + ((-4.0d0) * (z / y))
    else
        tmp = 1.0d0 + (4.0d0 / (y / (x - z)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -7.2e-31) || !(y <= 1.75e+136)) {
		tmp = 2.0 + (-4.0 * (z / y));
	} else {
		tmp = 1.0 + (4.0 / (y / (x - z)));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -7.2e-31) or not (y <= 1.75e+136):
		tmp = 2.0 + (-4.0 * (z / y))
	else:
		tmp = 1.0 + (4.0 / (y / (x - z)))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -7.2e-31) || !(y <= 1.75e+136))
		tmp = Float64(2.0 + Float64(-4.0 * Float64(z / y)));
	else
		tmp = Float64(1.0 + Float64(4.0 / Float64(y / Float64(x - z))));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -7.2e-31) || ~((y <= 1.75e+136)))
		tmp = 2.0 + (-4.0 * (z / y));
	else
		tmp = 1.0 + (4.0 / (y / (x - z)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.2e-31], N[Not[LessEqual[y, 1.75e+136]], $MachinePrecision]], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(4.0 / N[(y / N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-31} \lor \neg \left(y \leq 1.75 \cdot 10^{+136}\right):\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\

\mathbf{else}:\\
\;\;\;\;1 + \frac{4}{\frac{y}{x - z}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.20000000000000007e-31 or 1.75000000000000001e136 < y

    1. Initial program 99.9%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto \color{blue}{2 + 4 \cdot \frac{x - z}{y}} \]
    5. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    7. Taylor expanded in x around 0 89.4%

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

    if -7.20000000000000007e-31 < y < 1.75000000000000001e136

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.8%

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

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

      \[\leadsto 1 + \frac{4}{\color{blue}{\frac{y}{x - z}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{-31} \lor \neg \left(y \leq 1.75 \cdot 10^{+136}\right):\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{4}{\frac{y}{x - z}}\\ \end{array} \]

Alternative 5: 55.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{+31} \lor \neg \left(z \leq 450000\right):\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.95e+31) (not (<= z 450000.0))) (+ 1.0 (* -4.0 (/ z y))) 2.0))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.95e+31) || !(z <= 450000.0)) {
		tmp = 1.0 + (-4.0 * (z / y));
	} else {
		tmp = 2.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z <= (-1.95d+31)) .or. (.not. (z <= 450000.0d0))) then
        tmp = 1.0d0 + ((-4.0d0) * (z / y))
    else
        tmp = 2.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.95e+31) || !(z <= 450000.0)) {
		tmp = 1.0 + (-4.0 * (z / y));
	} else {
		tmp = 2.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.95e+31) or not (z <= 450000.0):
		tmp = 1.0 + (-4.0 * (z / y))
	else:
		tmp = 2.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.95e+31) || !(z <= 450000.0))
		tmp = Float64(1.0 + Float64(-4.0 * Float64(z / y)));
	else
		tmp = 2.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.95e+31) || ~((z <= 450000.0)))
		tmp = 1.0 + (-4.0 * (z / y));
	else
		tmp = 2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.95e+31], N[Not[LessEqual[z, 450000.0]], $MachinePrecision]], N[(1.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{+31} \lor \neg \left(z \leq 450000\right):\\
\;\;\;\;1 + -4 \cdot \frac{z}{y}\\

\mathbf{else}:\\
\;\;\;\;2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.95e31 or 4.5e5 < z

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto 1 + \color{blue}{-4 \cdot \frac{z}{y}} \]
    5. Step-by-step derivation
      1. *-commutative70.7%

        \[\leadsto 1 + \color{blue}{\frac{z}{y} \cdot -4} \]
    6. Simplified70.7%

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

    if -1.95e31 < z < 4.5e5

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.8%

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

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

      \[\leadsto \color{blue}{2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.95 \cdot 10^{+31} \lor \neg \left(z \leq 450000\right):\\ \;\;\;\;1 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]

Alternative 6: 81.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.62 \cdot 10^{+112} \lor \neg \left(x \leq 5 \cdot 10^{+140}\right):\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.62e+112) (not (<= x 5e+140)))
   (+ 1.0 (/ (* 4.0 x) y))
   (+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.62e+112) || !(x <= 5e+140)) {
		tmp = 1.0 + ((4.0 * x) / y);
	} else {
		tmp = 2.0 + (-4.0 * (z / y));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-1.62d+112)) .or. (.not. (x <= 5d+140))) then
        tmp = 1.0d0 + ((4.0d0 * x) / y)
    else
        tmp = 2.0d0 + ((-4.0d0) * (z / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.62e+112) || !(x <= 5e+140)) {
		tmp = 1.0 + ((4.0 * x) / y);
	} else {
		tmp = 2.0 + (-4.0 * (z / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -1.62e+112) or not (x <= 5e+140):
		tmp = 1.0 + ((4.0 * x) / y)
	else:
		tmp = 2.0 + (-4.0 * (z / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -1.62e+112) || !(x <= 5e+140))
		tmp = Float64(1.0 + Float64(Float64(4.0 * x) / y));
	else
		tmp = Float64(2.0 + Float64(-4.0 * Float64(z / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -1.62e+112) || ~((x <= 5e+140)))
		tmp = 1.0 + ((4.0 * x) / y);
	else
		tmp = 2.0 + (-4.0 * (z / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.62e+112], N[Not[LessEqual[x, 5e+140]], $MachinePrecision]], N[(1.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.62 \cdot 10^{+112} \lor \neg \left(x \leq 5 \cdot 10^{+140}\right):\\
\;\;\;\;1 + \frac{4 \cdot x}{y}\\

\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.61999999999999994e112 or 5.00000000000000008e140 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto 1 + \color{blue}{4 \cdot \frac{x}{y}} \]
    5. Step-by-step derivation
      1. associate-*r/77.8%

        \[\leadsto 1 + \color{blue}{\frac{4 \cdot x}{y}} \]
      2. *-commutative77.8%

        \[\leadsto 1 + \frac{\color{blue}{x \cdot 4}}{y} \]
    6. Simplified77.8%

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

    if -1.61999999999999994e112 < x < 5.00000000000000008e140

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.8%

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

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

      \[\leadsto \color{blue}{2 + 4 \cdot \frac{x - z}{y}} \]
    5. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    7. Taylor expanded in x around 0 85.5%

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} + 2 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.62 \cdot 10^{+112} \lor \neg \left(x \leq 5 \cdot 10^{+140}\right):\\ \;\;\;\;1 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \end{array} \]

Alternative 7: 85.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{+107} \lor \neg \left(x \leq 1.25 \cdot 10^{+107}\right):\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -4.1e+107) (not (<= x 1.25e+107)))
   (+ 2.0 (* 4.0 (/ x y)))
   (+ 2.0 (* -4.0 (/ z y)))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -4.1e+107) || !(x <= 1.25e+107)) {
		tmp = 2.0 + (4.0 * (x / y));
	} else {
		tmp = 2.0 + (-4.0 * (z / y));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((x <= (-4.1d+107)) .or. (.not. (x <= 1.25d+107))) then
        tmp = 2.0d0 + (4.0d0 * (x / y))
    else
        tmp = 2.0d0 + ((-4.0d0) * (z / y))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -4.1e+107) || !(x <= 1.25e+107)) {
		tmp = 2.0 + (4.0 * (x / y));
	} else {
		tmp = 2.0 + (-4.0 * (z / y));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -4.1e+107) or not (x <= 1.25e+107):
		tmp = 2.0 + (4.0 * (x / y))
	else:
		tmp = 2.0 + (-4.0 * (z / y))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -4.1e+107) || !(x <= 1.25e+107))
		tmp = Float64(2.0 + Float64(4.0 * Float64(x / y)));
	else
		tmp = Float64(2.0 + Float64(-4.0 * Float64(z / y)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -4.1e+107) || ~((x <= 1.25e+107)))
		tmp = 2.0 + (4.0 * (x / y));
	else
		tmp = 2.0 + (-4.0 * (z / y));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e+107], N[Not[LessEqual[x, 1.25e+107]], $MachinePrecision]], N[(2.0 + N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 + N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+107} \lor \neg \left(x \leq 1.25 \cdot 10^{+107}\right):\\
\;\;\;\;2 + 4 \cdot \frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.0999999999999999e107 or 1.25e107 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto \color{blue}{2 + 4 \cdot \frac{x - z}{y}} \]
    5. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    7. Taylor expanded in x around inf 86.7%

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

    if -4.0999999999999999e107 < x < 1.25e107

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. associate-/l*99.7%

        \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
      2. associate--l+99.7%

        \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
    3. Simplified99.7%

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

      \[\leadsto \color{blue}{2 + 4 \cdot \frac{x - z}{y}} \]
    5. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{4 \cdot \frac{x - z}{y} + 2} \]
    7. Taylor expanded in x around 0 87.2%

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} + 2 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification87.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{+107} \lor \neg \left(x \leq 1.25 \cdot 10^{+107}\right):\\ \;\;\;\;2 + 4 \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \end{array} \]

Alternative 8: 8.1% accurate, 13.0× 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;
}
real(8) function code(x, y, z)
    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 100.0%

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Step-by-step derivation
    1. associate-/l*99.7%

      \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
    2. associate--l+99.7%

      \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
  3. Simplified99.7%

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

    \[\leadsto 1 + \color{blue}{-4 \cdot \frac{z}{y}} \]
  5. Step-by-step derivation
    1. *-commutative45.9%

      \[\leadsto 1 + \color{blue}{\frac{z}{y} \cdot -4} \]
  6. Simplified45.9%

    \[\leadsto 1 + \color{blue}{\frac{z}{y} \cdot -4} \]
  7. Taylor expanded in z around 0 8.3%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification8.3%

    \[\leadsto 1 \]

Alternative 9: 33.9% accurate, 13.0× speedup?

\[\begin{array}{l} \\ 2 \end{array} \]
(FPCore (x y z) :precision binary64 2.0)
double code(double x, double y, double z) {
	return 2.0;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = 2.0d0
end function
public static double code(double x, double y, double z) {
	return 2.0;
}
def code(x, y, z):
	return 2.0
function code(x, y, z)
	return 2.0
end
function tmp = code(x, y, z)
	tmp = 2.0;
end
code[x_, y_, z_] := 2.0
\begin{array}{l}

\\
2
\end{array}
Derivation
  1. Initial program 100.0%

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.25\right) - z\right)}{y} \]
  2. Step-by-step derivation
    1. associate-/l*99.7%

      \[\leadsto 1 + \color{blue}{\frac{4}{\frac{y}{\left(x + y \cdot 0.25\right) - z}}} \]
    2. associate--l+99.7%

      \[\leadsto 1 + \frac{4}{\frac{y}{\color{blue}{x + \left(y \cdot 0.25 - z\right)}}} \]
  3. Simplified99.7%

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

    \[\leadsto \color{blue}{2} \]
  5. Final simplification34.5%

    \[\leadsto 2 \]

Reproduce

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