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

Percentage Accurate: 99.7% → 100.0%
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);
}
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.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}

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.7% 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);
}
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.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: 100.0% accurate, 1.4× speedup?

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

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

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

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

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

Alternative 2: 79.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -5.3 \cdot 10^{+178}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+59} \lor \neg \left(y \leq 2.9 \cdot 10^{+93}\right) \land y \leq 1.9 \cdot 10^{+140}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -5.3e+178)
   4.0
   (if (or (<= y 9.2e+59) (and (not (<= y 2.9e+93)) (<= y 1.9e+140)))
     (* 4.0 (/ (- x z) y))
     4.0)))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -5.3e+178) {
		tmp = 4.0;
	} else if ((y <= 9.2e+59) || (!(y <= 2.9e+93) && (y <= 1.9e+140))) {
		tmp = 4.0 * ((x - z) / y);
	} else {
		tmp = 4.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 (y <= (-5.3d+178)) then
        tmp = 4.0d0
    else if ((y <= 9.2d+59) .or. (.not. (y <= 2.9d+93)) .and. (y <= 1.9d+140)) then
        tmp = 4.0d0 * ((x - z) / y)
    else
        tmp = 4.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -5.3e+178) {
		tmp = 4.0;
	} else if ((y <= 9.2e+59) || (!(y <= 2.9e+93) && (y <= 1.9e+140))) {
		tmp = 4.0 * ((x - z) / y);
	} else {
		tmp = 4.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -5.3e+178:
		tmp = 4.0
	elif (y <= 9.2e+59) or (not (y <= 2.9e+93) and (y <= 1.9e+140)):
		tmp = 4.0 * ((x - z) / y)
	else:
		tmp = 4.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -5.3e+178)
		tmp = 4.0;
	elseif ((y <= 9.2e+59) || (!(y <= 2.9e+93) && (y <= 1.9e+140)))
		tmp = Float64(4.0 * Float64(Float64(x - z) / y));
	else
		tmp = 4.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -5.3e+178)
		tmp = 4.0;
	elseif ((y <= 9.2e+59) || (~((y <= 2.9e+93)) && (y <= 1.9e+140)))
		tmp = 4.0 * ((x - z) / y);
	else
		tmp = 4.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -5.3e+178], 4.0, If[Or[LessEqual[y, 9.2e+59], And[N[Not[LessEqual[y, 2.9e+93]], $MachinePrecision], LessEqual[y, 1.9e+140]]], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], 4.0]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.3 \cdot 10^{+178}:\\
\;\;\;\;4\\

\mathbf{elif}\;y \leq 9.2 \cdot 10^{+59} \lor \neg \left(y \leq 2.9 \cdot 10^{+93}\right) \land y \leq 1.9 \cdot 10^{+140}:\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\

\mathbf{else}:\\
\;\;\;\;4\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.29999999999999988e178 or 9.20000000000000032e59 < y < 2.8999999999999998e93 or 1.9e140 < y

    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 84.9%

      \[\leadsto \color{blue}{4} \]

    if -5.29999999999999988e178 < y < 9.20000000000000032e59 or 2.8999999999999998e93 < y < 1.9e140

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+47.5%

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

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in y around 0 80.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.3 \cdot 10^{+178}:\\ \;\;\;\;4\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+59} \lor \neg \left(y \leq 2.9 \cdot 10^{+93}\right) \land y \leq 1.9 \cdot 10^{+140}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \mathbf{else}:\\ \;\;\;\;4\\ \end{array} \]

Alternative 3: 52.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2600:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+66}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))))
   (if (<= x -9.5e-29)
     t_0
     (if (<= x 2600.0) 4.0 (if (<= x 1.9e+66) (* (/ z y) -4.0) t_0)))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double tmp;
	if (x <= -9.5e-29) {
		tmp = t_0;
	} else if (x <= 2600.0) {
		tmp = 4.0;
	} else if (x <= 1.9e+66) {
		tmp = (z / y) * -4.0;
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = 4.0d0 * (x / y)
    if (x <= (-9.5d-29)) then
        tmp = t_0
    else if (x <= 2600.0d0) then
        tmp = 4.0d0
    else if (x <= 1.9d+66) then
        tmp = (z / y) * (-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 * (x / y);
	double tmp;
	if (x <= -9.5e-29) {
		tmp = t_0;
	} else if (x <= 2600.0) {
		tmp = 4.0;
	} else if (x <= 1.9e+66) {
		tmp = (z / y) * -4.0;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	tmp = 0
	if x <= -9.5e-29:
		tmp = t_0
	elif x <= 2600.0:
		tmp = 4.0
	elif x <= 1.9e+66:
		tmp = (z / y) * -4.0
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / y))
	tmp = 0.0
	if (x <= -9.5e-29)
		tmp = t_0;
	elseif (x <= 2600.0)
		tmp = 4.0;
	elseif (x <= 1.9e+66)
		tmp = Float64(Float64(z / y) * -4.0);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / y);
	tmp = 0.0;
	if (x <= -9.5e-29)
		tmp = t_0;
	elseif (x <= 2600.0)
		tmp = 4.0;
	elseif (x <= 1.9e+66)
		tmp = (z / y) * -4.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9.5e-29], t$95$0, If[LessEqual[x, 2600.0], 4.0, If[LessEqual[x, 1.9e+66], N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y}\\
\mathbf{if}\;x \leq -9.5 \cdot 10^{-29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 2600:\\
\;\;\;\;4\\

\mathbf{elif}\;x \leq 1.9 \cdot 10^{+66}:\\
\;\;\;\;\frac{z}{y} \cdot -4\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -9.50000000000000023e-29 or 1.9000000000000001e66 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+47.4%

        \[\leadsto \color{blue}{\frac{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \cdot \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1 \cdot 1}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1}} \]
    3. Applied egg-rr47.0%

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in z around inf 75.7%

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

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

    if -9.50000000000000023e-29 < x < 2600

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{4} \]

    if 2600 < x < 1.9000000000000001e66

    1. Initial program 99.9%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+46.6%

        \[\leadsto \color{blue}{\frac{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \cdot \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1 \cdot 1}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1}} \]
    3. Applied egg-rr46.5%

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in z around inf 99.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{-29}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 2600:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{+66}:\\ \;\;\;\;\frac{z}{y} \cdot -4\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \end{array} \]

Alternative 4: 52.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ \mathbf{if}\;x \leq -3.1 \cdot 10^{-29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 420:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 7.4 \cdot 10^{+68}:\\ \;\;\;\;z \cdot \frac{-4}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))))
   (if (<= x -3.1e-29)
     t_0
     (if (<= x 420.0) 4.0 (if (<= x 7.4e+68) (* z (/ -4.0 y)) t_0)))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double tmp;
	if (x <= -3.1e-29) {
		tmp = t_0;
	} else if (x <= 420.0) {
		tmp = 4.0;
	} else if (x <= 7.4e+68) {
		tmp = z * (-4.0 / y);
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = 4.0d0 * (x / y)
    if (x <= (-3.1d-29)) then
        tmp = t_0
    else if (x <= 420.0d0) then
        tmp = 4.0d0
    else if (x <= 7.4d+68) then
        tmp = z * ((-4.0d0) / y)
    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 * (x / y);
	double tmp;
	if (x <= -3.1e-29) {
		tmp = t_0;
	} else if (x <= 420.0) {
		tmp = 4.0;
	} else if (x <= 7.4e+68) {
		tmp = z * (-4.0 / y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	tmp = 0
	if x <= -3.1e-29:
		tmp = t_0
	elif x <= 420.0:
		tmp = 4.0
	elif x <= 7.4e+68:
		tmp = z * (-4.0 / y)
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / y))
	tmp = 0.0
	if (x <= -3.1e-29)
		tmp = t_0;
	elseif (x <= 420.0)
		tmp = 4.0;
	elseif (x <= 7.4e+68)
		tmp = Float64(z * Float64(-4.0 / y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / y);
	tmp = 0.0;
	if (x <= -3.1e-29)
		tmp = t_0;
	elseif (x <= 420.0)
		tmp = 4.0;
	elseif (x <= 7.4e+68)
		tmp = z * (-4.0 / y);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(4.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3.1e-29], t$95$0, If[LessEqual[x, 420.0], 4.0, If[LessEqual[x, 7.4e+68], N[(z * N[(-4.0 / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y}\\
\mathbf{if}\;x \leq -3.1 \cdot 10^{-29}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 420:\\
\;\;\;\;4\\

\mathbf{elif}\;x \leq 7.4 \cdot 10^{+68}:\\
\;\;\;\;z \cdot \frac{-4}{y}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.10000000000000026e-29 or 7.39999999999999996e68 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+47.4%

        \[\leadsto \color{blue}{\frac{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \cdot \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1 \cdot 1}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1}} \]
    3. Applied egg-rr47.0%

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in z around inf 75.7%

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

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

    if -3.10000000000000026e-29 < x < 420

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{4} \]

    if 420 < x < 7.39999999999999996e68

    1. Initial program 99.9%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+46.6%

        \[\leadsto \color{blue}{\frac{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \cdot \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1 \cdot 1}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} - 1}} \]
    3. Applied egg-rr46.5%

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in z around inf 99.6%

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

      \[\leadsto \color{blue}{-4 \cdot \frac{z}{y}} \]
    6. Step-by-step derivation
      1. associate-*r/68.8%

        \[\leadsto \color{blue}{\frac{-4 \cdot z}{y}} \]
      2. associate-/l*68.8%

        \[\leadsto \color{blue}{\frac{-4}{\frac{y}{z}}} \]
      3. associate-/r/68.9%

        \[\leadsto \color{blue}{\frac{-4}{y} \cdot z} \]
    7. Simplified68.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{-29}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 420:\\ \;\;\;\;4\\ \mathbf{elif}\;x \leq 7.4 \cdot 10^{+68}:\\ \;\;\;\;z \cdot \frac{-4}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x}{y}\\ \end{array} \]

Alternative 5: 85.4% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-30} \lor \neg \left(x \leq 2 \cdot 10^{+64}\right):\\
\;\;\;\;4 \cdot \frac{x - z}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -6.5000000000000005e-30 or 2.00000000000000004e64 < x

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+47.9%

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

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in y around 0 81.9%

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

    if -6.5000000000000005e-30 < x < 2.00000000000000004e64

    1. Initial program 99.9%

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

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \color{blue}{\left(y \cdot 0.75 + \left(x - z\right)\right)} \]
      4. distribute-lft-in99.8%

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

        \[\leadsto \color{blue}{\left(1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right) + \frac{4}{y} \cdot \left(x - z\right)} \]
      6. *-commutative99.8%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right)} \]
      9. associate-*r*99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\left(\frac{4}{y} \cdot y\right) \cdot 0.75}\right) \]
      10. associate-*l/99.9%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\frac{4 \cdot y}{y}} \cdot 0.75\right) \]
      11. associate-/l*99.9%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\frac{4}{\frac{y}{y}}} \cdot 0.75\right) \]
      12. *-inverses99.9%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \frac{4}{\color{blue}{1}} \cdot 0.75\right) \]
      13. metadata-eval99.9%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{4} \cdot 0.75\right) \]
      14. metadata-eval99.9%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{3}\right) \]
      15. metadata-eval99.9%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, \color{blue}{4}\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - z, \frac{4}{y}, 4\right)} \]
    4. Taylor expanded in x around 0 92.4%

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

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

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

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

Alternative 6: 86.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.6 \cdot 10^{+44}:\\ \;\;\;\;4 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+78}:\\ \;\;\;\;4 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.6e+44)
   (+ 4.0 (* (/ z y) -4.0))
   (if (<= z 1.9e+78) (+ 4.0 (/ (* 4.0 x) y)) (* 4.0 (/ (- x z) y)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.6e+44) {
		tmp = 4.0 + ((z / y) * -4.0);
	} else if (z <= 1.9e+78) {
		tmp = 4.0 + ((4.0 * x) / y);
	} else {
		tmp = 4.0 * ((x - 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 (z <= (-2.6d+44)) then
        tmp = 4.0d0 + ((z / y) * (-4.0d0))
    else if (z <= 1.9d+78) then
        tmp = 4.0d0 + ((4.0d0 * x) / y)
    else
        tmp = 4.0d0 * ((x - z) / y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.6e+44) {
		tmp = 4.0 + ((z / y) * -4.0);
	} else if (z <= 1.9e+78) {
		tmp = 4.0 + ((4.0 * x) / y);
	} else {
		tmp = 4.0 * ((x - z) / y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -2.6e+44:
		tmp = 4.0 + ((z / y) * -4.0)
	elif z <= 1.9e+78:
		tmp = 4.0 + ((4.0 * x) / y)
	else:
		tmp = 4.0 * ((x - z) / y)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -2.6e+44)
		tmp = Float64(4.0 + Float64(Float64(z / y) * -4.0));
	elseif (z <= 1.9e+78)
		tmp = Float64(4.0 + Float64(Float64(4.0 * x) / y));
	else
		tmp = Float64(4.0 * Float64(Float64(x - z) / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -2.6e+44)
		tmp = 4.0 + ((z / y) * -4.0);
	elseif (z <= 1.9e+78)
		tmp = 4.0 + ((4.0 * x) / y);
	else
		tmp = 4.0 * ((x - z) / y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -2.6e+44], N[(4.0 + N[(N[(z / y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.9e+78], N[(4.0 + N[(N[(4.0 * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[(N[(x - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+44}:\\
\;\;\;\;4 + \frac{z}{y} \cdot -4\\

\mathbf{elif}\;z \leq 1.9 \cdot 10^{+78}:\\
\;\;\;\;4 + \frac{4 \cdot x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -2.5999999999999999e44

    1. Initial program 100.0%

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

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \color{blue}{\left(y \cdot 0.75 + \left(x - z\right)\right)} \]
      4. distribute-lft-in99.7%

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

        \[\leadsto \color{blue}{\left(1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right) + \frac{4}{y} \cdot \left(x - z\right)} \]
      6. *-commutative99.7%

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

        \[\leadsto \color{blue}{\left(x - z\right) \cdot \frac{4}{y} + \left(1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right)} \]
      8. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right)} \]
      9. associate-*r*99.7%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\left(\frac{4}{y} \cdot y\right) \cdot 0.75}\right) \]
      10. associate-*l/99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\frac{4 \cdot y}{y}} \cdot 0.75\right) \]
      11. associate-/l*99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\frac{4}{\frac{y}{y}}} \cdot 0.75\right) \]
      12. *-inverses99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \frac{4}{\color{blue}{1}} \cdot 0.75\right) \]
      13. metadata-eval99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{4} \cdot 0.75\right) \]
      14. metadata-eval99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{3}\right) \]
      15. metadata-eval99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, \color{blue}{4}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - z, \frac{4}{y}, 4\right)} \]
    4. Taylor expanded in x around 0 88.0%

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

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

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

    if -2.5999999999999999e44 < z < 1.9e78

    1. Initial program 99.9%

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

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

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

        \[\leadsto 1 + \frac{4}{y} \cdot \color{blue}{\left(y \cdot 0.75 + \left(x - z\right)\right)} \]
      4. distribute-lft-in99.7%

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

        \[\leadsto \color{blue}{\left(1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right) + \frac{4}{y} \cdot \left(x - z\right)} \]
      6. *-commutative99.7%

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

        \[\leadsto \color{blue}{\left(x - z\right) \cdot \frac{4}{y} + \left(1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right)} \]
      8. fma-def99.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \frac{4}{y} \cdot \left(y \cdot 0.75\right)\right)} \]
      9. associate-*r*99.7%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\left(\frac{4}{y} \cdot y\right) \cdot 0.75}\right) \]
      10. associate-*l/99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\frac{4 \cdot y}{y}} \cdot 0.75\right) \]
      11. associate-/l*99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{\frac{4}{\frac{y}{y}}} \cdot 0.75\right) \]
      12. *-inverses99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \frac{4}{\color{blue}{1}} \cdot 0.75\right) \]
      13. metadata-eval99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{4} \cdot 0.75\right) \]
      14. metadata-eval99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, 1 + \color{blue}{3}\right) \]
      15. metadata-eval99.8%

        \[\leadsto \mathsf{fma}\left(x - z, \frac{4}{y}, \color{blue}{4}\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x - z, \frac{4}{y}, 4\right)} \]
    4. Taylor expanded in z around 0 92.3%

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

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

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

    if 1.9e78 < z

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+30.6%

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

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in y around 0 90.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.6 \cdot 10^{+44}:\\ \;\;\;\;4 + \frac{z}{y} \cdot -4\\ \mathbf{elif}\;z \leq 1.9 \cdot 10^{+78}:\\ \;\;\;\;4 + \frac{4 \cdot x}{y}\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \frac{x - z}{y}\\ \end{array} \]

Alternative 7: 52.7% accurate, 1.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;4\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.95000000000000003e115 or 3.00000000000000014e99 < z

    1. Initial program 100.0%

      \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
    2. Step-by-step derivation
      1. +-commutative100.0%

        \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
      2. flip-+30.5%

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

      \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
    4. Taylor expanded in z around inf 84.4%

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

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

    if -1.95000000000000003e115 < z < 3.00000000000000014e99

    1. Initial program 99.9%

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

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

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

Alternative 8: 2.4% accurate, 13.0× speedup?

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

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

    \[1 + \frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} \]
  2. Step-by-step derivation
    1. +-commutative99.9%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(\left(x + y \cdot 0.75\right) - z\right)}{y} + 1} \]
    2. flip-+60.3%

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

    \[\leadsto \color{blue}{\frac{\frac{16}{{\left(\frac{y}{\mathsf{fma}\left(y, 0.75, x\right) - z}\right)}^{2}} - 1}{\left(\mathsf{fma}\left(y, 0.75, x\right) - z\right) \cdot \frac{4}{y} - 1}} \]
  4. Taylor expanded in z around inf 87.7%

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

    \[\leadsto \color{blue}{\frac{-4 \cdot z + 8 \cdot x}{y}} - 4 \cdot \left(0.75 + \frac{x}{y}\right) \]
  6. Taylor expanded in y around inf 2.5%

    \[\leadsto \color{blue}{-3} \]
  7. Final simplification2.5%

    \[\leadsto -3 \]

Alternative 9: 33.7% accurate, 13.0× 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;
}
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
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.9%

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

    \[\leadsto \color{blue}{4} \]
  3. Final simplification35.7%

    \[\leadsto 4 \]

Reproduce

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