Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1

Percentage Accurate: 100.0% → 100.0%
Time: 7.0s
Alternatives: 8
Speedup: 1.0×

Specification

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

\\
\frac{x - y}{z - 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 8 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: 100.0% accurate, 1.0× speedup?

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

\\
\frac{x - y}{z - y}
\end{array}

Alternative 1: 100.0% accurate, 0.6× speedup?

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

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

    \[\frac{x - y}{z - y} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. div-sub100.0%

      \[\leadsto \color{blue}{\frac{x}{z - y} - \frac{y}{z - y}} \]
  4. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{x}{z - y} - \frac{y}{z - y}} \]
  5. Add Preprocessing

Alternative 2: 75.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{z - y}\\ t_1 := \frac{y}{y - z}\\ \mathbf{if}\;x \leq -9.5 \cdot 10^{+45}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-127}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \leq 8.4 \cdot 10^{-88}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;x \leq 9.2 \cdot 10^{+34}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ x (- z y))) (t_1 (/ y (- y z))))
   (if (<= x -9.5e+45)
     t_0
     (if (<= x 2.8e-127)
       t_1
       (if (<= x 8.4e-88) (/ x z) (if (<= x 9.2e+34) t_1 t_0))))))
double code(double x, double y, double z) {
	double t_0 = x / (z - y);
	double t_1 = y / (y - z);
	double tmp;
	if (x <= -9.5e+45) {
		tmp = t_0;
	} else if (x <= 2.8e-127) {
		tmp = t_1;
	} else if (x <= 8.4e-88) {
		tmp = x / z;
	} else if (x <= 9.2e+34) {
		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 = x / (z - y)
    t_1 = y / (y - z)
    if (x <= (-9.5d+45)) then
        tmp = t_0
    else if (x <= 2.8d-127) then
        tmp = t_1
    else if (x <= 8.4d-88) then
        tmp = x / z
    else if (x <= 9.2d+34) 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 = x / (z - y);
	double t_1 = y / (y - z);
	double tmp;
	if (x <= -9.5e+45) {
		tmp = t_0;
	} else if (x <= 2.8e-127) {
		tmp = t_1;
	} else if (x <= 8.4e-88) {
		tmp = x / z;
	} else if (x <= 9.2e+34) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = x / (z - y)
	t_1 = y / (y - z)
	tmp = 0
	if x <= -9.5e+45:
		tmp = t_0
	elif x <= 2.8e-127:
		tmp = t_1
	elif x <= 8.4e-88:
		tmp = x / z
	elif x <= 9.2e+34:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(x / Float64(z - y))
	t_1 = Float64(y / Float64(y - z))
	tmp = 0.0
	if (x <= -9.5e+45)
		tmp = t_0;
	elseif (x <= 2.8e-127)
		tmp = t_1;
	elseif (x <= 8.4e-88)
		tmp = Float64(x / z);
	elseif (x <= 9.2e+34)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = x / (z - y);
	t_1 = y / (y - z);
	tmp = 0.0;
	if (x <= -9.5e+45)
		tmp = t_0;
	elseif (x <= 2.8e-127)
		tmp = t_1;
	elseif (x <= 8.4e-88)
		tmp = x / z;
	elseif (x <= 9.2e+34)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9.5e+45], t$95$0, If[LessEqual[x, 2.8e-127], t$95$1, If[LessEqual[x, 8.4e-88], N[(x / z), $MachinePrecision], If[LessEqual[x, 9.2e+34], t$95$1, t$95$0]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq 2.8 \cdot 10^{-127}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \leq 8.4 \cdot 10^{-88}:\\
\;\;\;\;\frac{x}{z}\\

\mathbf{elif}\;x \leq 9.2 \cdot 10^{+34}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -9.4999999999999998e45 or 9.1999999999999993e34 < x

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 85.4%

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

    if -9.4999999999999998e45 < x < 2.8e-127 or 8.3999999999999998e-88 < x < 9.1999999999999993e34

    1. Initial program 99.9%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 81.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{y}{z - y}} \]
    4. Step-by-step derivation
      1. neg-mul-181.9%

        \[\leadsto \color{blue}{-\frac{y}{z - y}} \]
      2. distribute-neg-frac81.9%

        \[\leadsto \color{blue}{\frac{-y}{z - y}} \]
    5. Simplified81.9%

      \[\leadsto \color{blue}{\frac{-y}{z - y}} \]
    6. Step-by-step derivation
      1. frac-2neg81.9%

        \[\leadsto \color{blue}{\frac{-\left(-y\right)}{-\left(z - y\right)}} \]
      2. div-inv81.7%

        \[\leadsto \color{blue}{\left(-\left(-y\right)\right) \cdot \frac{1}{-\left(z - y\right)}} \]
      3. remove-double-neg81.7%

        \[\leadsto \color{blue}{y} \cdot \frac{1}{-\left(z - y\right)} \]
      4. sub-neg81.7%

        \[\leadsto y \cdot \frac{1}{-\color{blue}{\left(z + \left(-y\right)\right)}} \]
      5. distribute-neg-in81.7%

        \[\leadsto y \cdot \frac{1}{\color{blue}{\left(-z\right) + \left(-\left(-y\right)\right)}} \]
      6. remove-double-neg81.7%

        \[\leadsto y \cdot \frac{1}{\left(-z\right) + \color{blue}{y}} \]
    7. Applied egg-rr81.7%

      \[\leadsto \color{blue}{y \cdot \frac{1}{\left(-z\right) + y}} \]
    8. Step-by-step derivation
      1. associate-*r/81.9%

        \[\leadsto \color{blue}{\frac{y \cdot 1}{\left(-z\right) + y}} \]
      2. *-rgt-identity81.9%

        \[\leadsto \frac{\color{blue}{y}}{\left(-z\right) + y} \]
      3. +-commutative81.9%

        \[\leadsto \frac{y}{\color{blue}{y + \left(-z\right)}} \]
      4. sub-neg81.9%

        \[\leadsto \frac{y}{\color{blue}{y - z}} \]
    9. Simplified81.9%

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

    if 2.8e-127 < x < 8.3999999999999998e-88

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 100.0%

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

Alternative 3: 76.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+36} \lor \neg \left(y \leq 8.5 \cdot 10^{-23}\right):\\
\;\;\;\;1 - \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.39999999999999992e36 or 8.4999999999999996e-23 < y

    1. Initial program 99.9%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0 72.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{x - y}{y}} \]
    4. Step-by-step derivation
      1. div-sub72.1%

        \[\leadsto -1 \cdot \color{blue}{\left(\frac{x}{y} - \frac{y}{y}\right)} \]
      2. sub-neg72.1%

        \[\leadsto -1 \cdot \color{blue}{\left(\frac{x}{y} + \left(-\frac{y}{y}\right)\right)} \]
      3. *-inverses72.1%

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

        \[\leadsto -1 \cdot \left(\frac{x}{y} + \color{blue}{-1}\right) \]
      5. distribute-lft-in72.1%

        \[\leadsto \color{blue}{-1 \cdot \frac{x}{y} + -1 \cdot -1} \]
      6. metadata-eval72.1%

        \[\leadsto -1 \cdot \frac{x}{y} + \color{blue}{1} \]
      7. +-commutative72.1%

        \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
      8. mul-1-neg72.1%

        \[\leadsto 1 + \color{blue}{\left(-\frac{x}{y}\right)} \]
      9. unsub-neg72.1%

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    5. Simplified72.1%

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

    if -2.39999999999999992e36 < y < 8.4999999999999996e-23

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 79.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{+36} \lor \neg \left(y \leq 8.5 \cdot 10^{-23}\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z - y}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 70.7% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-56} \lor \neg \left(y \leq 4.8 \cdot 10^{-109}\right):\\
\;\;\;\;1 - \frac{x}{y}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.99999999999999997e-56 or 4.79999999999999977e-109 < y

    1. Initial program 99.9%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0 66.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{x - y}{y}} \]
    4. Step-by-step derivation
      1. div-sub67.0%

        \[\leadsto -1 \cdot \color{blue}{\left(\frac{x}{y} - \frac{y}{y}\right)} \]
      2. sub-neg67.0%

        \[\leadsto -1 \cdot \color{blue}{\left(\frac{x}{y} + \left(-\frac{y}{y}\right)\right)} \]
      3. *-inverses67.0%

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

        \[\leadsto -1 \cdot \left(\frac{x}{y} + \color{blue}{-1}\right) \]
      5. distribute-lft-in67.0%

        \[\leadsto \color{blue}{-1 \cdot \frac{x}{y} + -1 \cdot -1} \]
      6. metadata-eval67.0%

        \[\leadsto -1 \cdot \frac{x}{y} + \color{blue}{1} \]
      7. +-commutative67.0%

        \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
      8. mul-1-neg67.0%

        \[\leadsto 1 + \color{blue}{\left(-\frac{x}{y}\right)} \]
      9. unsub-neg67.0%

        \[\leadsto \color{blue}{1 - \frac{x}{y}} \]
    5. Simplified67.0%

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

    if -4.99999999999999997e-56 < y < 4.79999999999999977e-109

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 77.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-56} \lor \neg \left(y \leq 4.8 \cdot 10^{-109}\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 61.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{+39}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{-24}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{z}{y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.6e+39) 1.0 (if (<= y 5.8e-24) (/ x z) (+ 1.0 (/ z y)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.6e+39) {
		tmp = 1.0;
	} else if (y <= 5.8e-24) {
		tmp = x / z;
	} else {
		tmp = 1.0 + (z / y);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.6d+39)) then
        tmp = 1.0d0
    else if (y <= 5.8d-24) then
        tmp = x / z
    else
        tmp = 1.0d0 + (z / y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.6e+39) {
		tmp = 1.0;
	} else if (y <= 5.8e-24) {
		tmp = x / z;
	} else {
		tmp = 1.0 + (z / y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.6e+39:
		tmp = 1.0
	elif y <= 5.8e-24:
		tmp = x / z
	else:
		tmp = 1.0 + (z / y)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.6e+39)
		tmp = 1.0;
	elseif (y <= 5.8e-24)
		tmp = Float64(x / z);
	else
		tmp = Float64(1.0 + Float64(z / y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.6e+39)
		tmp = 1.0;
	elseif (y <= 5.8e-24)
		tmp = x / z;
	else
		tmp = 1.0 + (z / y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.6e+39], 1.0, If[LessEqual[y, 5.8e-24], N[(x / z), $MachinePrecision], N[(1.0 + N[(z / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+39}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 5.8 \cdot 10^{-24}:\\
\;\;\;\;\frac{x}{z}\\

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


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

    1. Initial program 99.9%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 61.3%

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

    if -1.59999999999999996e39 < y < 5.7999999999999997e-24

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 64.2%

      \[\leadsto \color{blue}{\frac{x}{z}} \]

    if 5.7999999999999997e-24 < y

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 69.9%

      \[\leadsto \color{blue}{\left(1 + -1 \cdot \frac{x}{y}\right) - -1 \cdot \frac{z}{y}} \]
    4. Step-by-step derivation
      1. associate-+r-69.9%

        \[\leadsto \color{blue}{1 + \left(-1 \cdot \frac{x}{y} - -1 \cdot \frac{z}{y}\right)} \]
      2. distribute-lft-out--69.9%

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

        \[\leadsto 1 + -1 \cdot \color{blue}{\frac{x - z}{y}} \]
      4. mul-1-neg69.9%

        \[\leadsto 1 + \color{blue}{\left(-\frac{x - z}{y}\right)} \]
      5. unsub-neg69.9%

        \[\leadsto \color{blue}{1 - \frac{x - z}{y}} \]
    5. Simplified69.9%

      \[\leadsto \color{blue}{1 - \frac{x - z}{y}} \]
    6. Taylor expanded in x around 0 49.1%

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

Alternative 6: 61.6% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+37}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 2.8 \cdot 10^{-28}:\\
\;\;\;\;\frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.1999999999999998e37 or 2.7999999999999998e-28 < y

    1. Initial program 99.9%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 54.0%

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

    if -5.1999999999999998e37 < y < 2.7999999999999998e-28

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 64.2%

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

Alternative 7: 100.0% accurate, 1.0× speedup?

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

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

    \[\frac{x - y}{z - y} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 8: 35.5% accurate, 7.0× speedup?

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

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

    \[\frac{x - y}{z - y} \]
  2. Add Preprocessing
  3. Taylor expanded in y around inf 33.7%

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

Developer target: 100.0% accurate, 0.6× speedup?

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

\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}

Reproduce

?
herbie shell --seed 2024085 
(FPCore (x y z)
  :name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
  :precision binary64

  :alt
  (- (/ x (- z y)) (/ y (- z y)))

  (/ (- x y) (- z y)))