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

Percentage Accurate: 99.8% → 99.9%
Time: 5.2s
Alternatives: 7
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 7 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: 99.9% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{4 \cdot \left(x - z\right)}{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(Float64(4.0 * 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[(N[(4.0 * N[(x - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] + 2.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{4 \cdot \left(x - z\right)}{y} + 2
\end{array}
Derivation
  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. +-commutative99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
    10. *-commutative100.0%

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

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
    12. metadata-eval100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
    13. *-rgt-identity100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
    14. *-inverses100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
    15. metadata-eval100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
  3. Simplified100.0%

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

Alternative 2: 53.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 4 \cdot \frac{x}{y}\\ t_1 := -4 \cdot \frac{z}{y}\\ \mathbf{if}\;x \leq -5 \cdot 10^{-8}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq -5.7 \cdot 10^{-160}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-200}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-244}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{-170}:\\ \;\;\;\;2\\ \mathbf{elif}\;x \leq 5.6 \cdot 10^{-17}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* 4.0 (/ x y))) (t_1 (* -4.0 (/ z y))))
   (if (<= x -5e-8)
     t_0
     (if (<= x -5.7e-160)
       t_1
       (if (<= x -4.5e-200)
         2.0
         (if (<= x 2.7e-244)
           t_1
           (if (<= x 1.4e-170) 2.0 (if (<= x 5.6e-17) t_1 t_0))))))))
double code(double x, double y, double z) {
	double t_0 = 4.0 * (x / y);
	double t_1 = -4.0 * (z / y);
	double tmp;
	if (x <= -5e-8) {
		tmp = t_0;
	} else if (x <= -5.7e-160) {
		tmp = t_1;
	} else if (x <= -4.5e-200) {
		tmp = 2.0;
	} else if (x <= 2.7e-244) {
		tmp = t_1;
	} else if (x <= 1.4e-170) {
		tmp = 2.0;
	} else if (x <= 5.6e-17) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = 4.0d0 * (x / y)
    t_1 = (-4.0d0) * (z / y)
    if (x <= (-5d-8)) then
        tmp = t_0
    else if (x <= (-5.7d-160)) then
        tmp = t_1
    else if (x <= (-4.5d-200)) then
        tmp = 2.0d0
    else if (x <= 2.7d-244) then
        tmp = t_1
    else if (x <= 1.4d-170) then
        tmp = 2.0d0
    else if (x <= 5.6d-17) then
        tmp = t_1
    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 t_1 = -4.0 * (z / y);
	double tmp;
	if (x <= -5e-8) {
		tmp = t_0;
	} else if (x <= -5.7e-160) {
		tmp = t_1;
	} else if (x <= -4.5e-200) {
		tmp = 2.0;
	} else if (x <= 2.7e-244) {
		tmp = t_1;
	} else if (x <= 1.4e-170) {
		tmp = 2.0;
	} else if (x <= 5.6e-17) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = 4.0 * (x / y)
	t_1 = -4.0 * (z / y)
	tmp = 0
	if x <= -5e-8:
		tmp = t_0
	elif x <= -5.7e-160:
		tmp = t_1
	elif x <= -4.5e-200:
		tmp = 2.0
	elif x <= 2.7e-244:
		tmp = t_1
	elif x <= 1.4e-170:
		tmp = 2.0
	elif x <= 5.6e-17:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(4.0 * Float64(x / y))
	t_1 = Float64(-4.0 * Float64(z / y))
	tmp = 0.0
	if (x <= -5e-8)
		tmp = t_0;
	elseif (x <= -5.7e-160)
		tmp = t_1;
	elseif (x <= -4.5e-200)
		tmp = 2.0;
	elseif (x <= 2.7e-244)
		tmp = t_1;
	elseif (x <= 1.4e-170)
		tmp = 2.0;
	elseif (x <= 5.6e-17)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = 4.0 * (x / y);
	t_1 = -4.0 * (z / y);
	tmp = 0.0;
	if (x <= -5e-8)
		tmp = t_0;
	elseif (x <= -5.7e-160)
		tmp = t_1;
	elseif (x <= -4.5e-200)
		tmp = 2.0;
	elseif (x <= 2.7e-244)
		tmp = t_1;
	elseif (x <= 1.4e-170)
		tmp = 2.0;
	elseif (x <= 5.6e-17)
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(-4.0 * N[(z / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5e-8], t$95$0, If[LessEqual[x, -5.7e-160], t$95$1, If[LessEqual[x, -4.5e-200], 2.0, If[LessEqual[x, 2.7e-244], t$95$1, If[LessEqual[x, 1.4e-170], 2.0, If[LessEqual[x, 5.6e-17], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 4 \cdot \frac{x}{y}\\
t_1 := -4 \cdot \frac{z}{y}\\
\mathbf{if}\;x \leq -5 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq -5.7 \cdot 10^{-160}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq -4.5 \cdot 10^{-200}:\\
\;\;\;\;2\\

\mathbf{elif}\;x \leq 2.7 \cdot 10^{-244}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 1.4 \cdot 10^{-170}:\\
\;\;\;\;2\\

\mathbf{elif}\;x \leq 5.6 \cdot 10^{-17}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -4.9999999999999998e-8 or 5.5999999999999998e-17 < x

    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. +-commutative99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 99.9%

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

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

    if -4.9999999999999998e-8 < x < -5.70000000000000038e-160 or -4.5000000000000002e-200 < x < 2.7e-244 or 1.39999999999999998e-170 < x < 5.5999999999999998e-17

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

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

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

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

    if -5.70000000000000038e-160 < x < -4.5000000000000002e-200 or 2.7e-244 < x < 1.39999999999999998e-170

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 82.2%

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

Alternative 3: 84.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{-32} \lor \neg \left(y \leq 30500\right):\\
\;\;\;\;2 + -4 \cdot \frac{z}{y}\\

\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{4}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.10000000000000011e-32 or 30500 < 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. +-commutative99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 83.5%

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

    if -3.10000000000000011e-32 < y < 30500

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

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

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

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

        \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y}} \]
      2. associate-*l/94.2%

        \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right)} \]
      3. *-commutative94.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.1 \cdot 10^{-32} \lor \neg \left(y \leq 30500\right):\\ \;\;\;\;2 + -4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \frac{4}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.1% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+93} \lor \neg \left(y \leq 1.8 \cdot 10^{+180}\right):\\
\;\;\;\;2\\

\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \frac{4}{y}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.10000000000000011e93 or 1.8000000000000001e180 < 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. +-commutative99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 73.3%

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

    if -1.10000000000000011e93 < y < 1.8000000000000001e180

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

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

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

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

        \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y}} \]
      2. associate-*l/83.7%

        \[\leadsto \color{blue}{\frac{4}{y} \cdot \left(x - z\right)} \]
      3. *-commutative83.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{+93} \lor \neg \left(y \leq 1.8 \cdot 10^{+180}\right):\\ \;\;\;\;2\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \frac{4}{y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 53.2% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{+54} \lor \neg \left(z \leq 5.5 \cdot 10^{+47}\right):\\
\;\;\;\;-4 \cdot \frac{z}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.19999999999999999e54 or 5.4999999999999998e47 < z

    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. +-commutative99.9%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in y around 0 99.9%

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

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

    if -1.19999999999999999e54 < z < 5.4999999999999998e47

    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. +-commutative100.0%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
      10. *-commutative100.0%

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

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
      12. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
      13. *-rgt-identity100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
      14. *-inverses100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
      15. metadata-eval100.0%

        \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
    4. Add Preprocessing
    5. Taylor expanded in y around inf 43.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+54} \lor \neg \left(z \leq 5.5 \cdot 10^{+47}\right):\\ \;\;\;\;-4 \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;2\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.8% accurate, 1.4× speedup?

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

\\
2 + \left(x - z\right) \cdot \frac{4}{y}
\end{array}
Derivation
  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. +-commutative99.9%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
    10. *-commutative100.0%

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

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
    12. metadata-eval100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
    13. *-rgt-identity100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
    14. *-inverses100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
    15. metadata-eval100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 98.8%

    \[\leadsto \color{blue}{\left(-4 \cdot \frac{z}{y} + 4 \cdot \frac{x}{y}\right)} + 2 \]
  6. Step-by-step derivation
    1. +-commutative98.8%

      \[\leadsto \color{blue}{\left(4 \cdot \frac{x}{y} + -4 \cdot \frac{z}{y}\right)} + 2 \]
    2. associate-*r/98.8%

      \[\leadsto \left(\color{blue}{\frac{4 \cdot x}{y}} + -4 \cdot \frac{z}{y}\right) + 2 \]
    3. remove-double-neg98.8%

      \[\leadsto \left(\frac{4 \cdot x}{\color{blue}{-\left(-y\right)}} + -4 \cdot \frac{z}{y}\right) + 2 \]
    4. neg-mul-198.8%

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

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

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

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

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

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

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

      \[\leadsto \frac{4}{-1} \cdot \color{blue}{\left(\frac{x}{-y} - \frac{z}{-y}\right)} + 2 \]
    12. div-sub100.0%

      \[\leadsto \frac{4}{-1} \cdot \color{blue}{\frac{x - z}{-y}} + 2 \]
    13. times-frac100.0%

      \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{-1 \cdot \left(-y\right)}} + 2 \]
    14. neg-mul-1100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{\color{blue}{-\left(-y\right)}} + 2 \]
    15. remove-double-neg100.0%

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

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

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

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

Alternative 7: 34.8% 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 99.9%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{\frac{4 \cdot \left(y \cdot 0.25\right)}{y}} + 1\right) \]
    10. *-commutative100.0%

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

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y \cdot \left(0.25 \cdot 4\right)}}{y} + 1\right) \]
    12. metadata-eval100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{y \cdot \color{blue}{1}}{y} + 1\right) \]
    13. *-rgt-identity100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\frac{\color{blue}{y}}{y} + 1\right) \]
    14. *-inverses100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \left(\color{blue}{1} + 1\right) \]
    15. metadata-eval100.0%

      \[\leadsto \frac{4 \cdot \left(x - z\right)}{y} + \color{blue}{2} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{4 \cdot \left(x - z\right)}{y} + 2} \]
  4. Add Preprocessing
  5. Taylor expanded in y around inf 31.4%

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

Reproduce

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