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

Percentage Accurate: 100.0% → 100.0%
Time: 6.3s
Alternatives: 9
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 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: 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 99.9%

    \[\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: 59.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -7.5 \cdot 10^{+54}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.42 \cdot 10^{-130}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{-165}:\\ \;\;\;\;\frac{x}{-y}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-11}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq 1.38 \cdot 10^{+141}:\\ \;\;\;\;\frac{y}{-z}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -7.5e+54)
   1.0
   (if (<= y -1.42e-130)
     (/ x z)
     (if (<= y -4.5e-165)
       (/ x (- y))
       (if (<= y 1.1e-11) (/ x z) (if (<= y 1.38e+141) (/ y (- z)) 1.0))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -7.5e+54) {
		tmp = 1.0;
	} else if (y <= -1.42e-130) {
		tmp = x / z;
	} else if (y <= -4.5e-165) {
		tmp = x / -y;
	} else if (y <= 1.1e-11) {
		tmp = x / z;
	} else if (y <= 1.38e+141) {
		tmp = y / -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 <= (-7.5d+54)) then
        tmp = 1.0d0
    else if (y <= (-1.42d-130)) then
        tmp = x / z
    else if (y <= (-4.5d-165)) then
        tmp = x / -y
    else if (y <= 1.1d-11) then
        tmp = x / z
    else if (y <= 1.38d+141) then
        tmp = y / -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 <= -7.5e+54) {
		tmp = 1.0;
	} else if (y <= -1.42e-130) {
		tmp = x / z;
	} else if (y <= -4.5e-165) {
		tmp = x / -y;
	} else if (y <= 1.1e-11) {
		tmp = x / z;
	} else if (y <= 1.38e+141) {
		tmp = y / -z;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -7.5e+54:
		tmp = 1.0
	elif y <= -1.42e-130:
		tmp = x / z
	elif y <= -4.5e-165:
		tmp = x / -y
	elif y <= 1.1e-11:
		tmp = x / z
	elif y <= 1.38e+141:
		tmp = y / -z
	else:
		tmp = 1.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -7.5e+54)
		tmp = 1.0;
	elseif (y <= -1.42e-130)
		tmp = Float64(x / z);
	elseif (y <= -4.5e-165)
		tmp = Float64(x / Float64(-y));
	elseif (y <= 1.1e-11)
		tmp = Float64(x / z);
	elseif (y <= 1.38e+141)
		tmp = Float64(y / Float64(-z));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -7.5e+54)
		tmp = 1.0;
	elseif (y <= -1.42e-130)
		tmp = x / z;
	elseif (y <= -4.5e-165)
		tmp = x / -y;
	elseif (y <= 1.1e-11)
		tmp = x / z;
	elseif (y <= 1.38e+141)
		tmp = y / -z;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -7.5e+54], 1.0, If[LessEqual[y, -1.42e-130], N[(x / z), $MachinePrecision], If[LessEqual[y, -4.5e-165], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, 1.1e-11], N[(x / z), $MachinePrecision], If[LessEqual[y, 1.38e+141], N[(y / (-z)), $MachinePrecision], 1.0]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;y \leq -4.5 \cdot 10^{-165}:\\
\;\;\;\;\frac{x}{-y}\\

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

\mathbf{elif}\;y \leq 1.38 \cdot 10^{+141}:\\
\;\;\;\;\frac{y}{-z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -7.50000000000000042e54 or 1.38e141 < y

    1. Initial program 99.9%

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

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

    if -7.50000000000000042e54 < y < -1.4199999999999999e-130 or -4.49999999999999992e-165 < y < 1.1000000000000001e-11

    1. Initial program 99.9%

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

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

    if -1.4199999999999999e-130 < y < -4.49999999999999992e-165

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{y}} \]
    5. Step-by-step derivation
      1. mul-1-neg79.1%

        \[\leadsto \color{blue}{-\frac{x}{y}} \]
      2. distribute-frac-neg279.1%

        \[\leadsto \color{blue}{\frac{x}{-y}} \]
    6. Simplified79.1%

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

    if 1.1000000000000001e-11 < y < 1.38e141

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto \color{blue}{\frac{y}{-z}} \]
    6. Simplified45.8%

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

Alternative 3: 68.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.05 \cdot 10^{+43} \lor \neg \left(y \leq -4.3 \cdot 10^{-63}\right) \land \left(y \leq -4.5 \cdot 10^{-165} \lor \neg \left(y \leq 1.55 \cdot 10^{-43}\right)\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -3.05e+43)
         (and (not (<= y -4.3e-63))
              (or (<= y -4.5e-165) (not (<= y 1.55e-43)))))
   (- 1.0 (/ x y))
   (/ x z)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -3.05e+43) || (!(y <= -4.3e-63) && ((y <= -4.5e-165) || !(y <= 1.55e-43)))) {
		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 <= (-3.05d+43)) .or. (.not. (y <= (-4.3d-63))) .and. (y <= (-4.5d-165)) .or. (.not. (y <= 1.55d-43))) 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 <= -3.05e+43) || (!(y <= -4.3e-63) && ((y <= -4.5e-165) || !(y <= 1.55e-43)))) {
		tmp = 1.0 - (x / y);
	} else {
		tmp = x / z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -3.05e+43) or (not (y <= -4.3e-63) and ((y <= -4.5e-165) or not (y <= 1.55e-43))):
		tmp = 1.0 - (x / y)
	else:
		tmp = x / z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -3.05e+43) || (!(y <= -4.3e-63) && ((y <= -4.5e-165) || !(y <= 1.55e-43))))
		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 <= -3.05e+43) || (~((y <= -4.3e-63)) && ((y <= -4.5e-165) || ~((y <= 1.55e-43)))))
		tmp = 1.0 - (x / y);
	else
		tmp = x / z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.05e+43], And[N[Not[LessEqual[y, -4.3e-63]], $MachinePrecision], Or[LessEqual[y, -4.5e-165], N[Not[LessEqual[y, 1.55e-43]], $MachinePrecision]]]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.05 \cdot 10^{+43} \lor \neg \left(y \leq -4.3 \cdot 10^{-63}\right) \land \left(y \leq -4.5 \cdot 10^{-165} \lor \neg \left(y \leq 1.55 \cdot 10^{-43}\right)\right):\\
\;\;\;\;1 - \frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.0499999999999999e43 or -4.2999999999999999e-63 < y < -4.49999999999999992e-165 or 1.55e-43 < y

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-\frac{x - y}{y}} \]
      2. div-sub76.2%

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

        \[\leadsto -\color{blue}{\left(\frac{x}{y} + \left(-\frac{y}{y}\right)\right)} \]
      4. *-inverses76.2%

        \[\leadsto -\left(\frac{x}{y} + \left(-\color{blue}{1}\right)\right) \]
      5. metadata-eval76.2%

        \[\leadsto -\left(\frac{x}{y} + \color{blue}{-1}\right) \]
      6. distribute-neg-in76.2%

        \[\leadsto \color{blue}{\left(-\frac{x}{y}\right) + \left(--1\right)} \]
      7. mul-1-neg76.2%

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

        \[\leadsto -1 \cdot \frac{x}{y} + \color{blue}{1} \]
      9. +-commutative76.2%

        \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
      10. mul-1-neg76.2%

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

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

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

    if -3.0499999999999999e43 < y < -4.2999999999999999e-63 or -4.49999999999999992e-165 < y < 1.55e-43

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.05 \cdot 10^{+43} \lor \neg \left(y \leq -4.3 \cdot 10^{-63}\right) \land \left(y \leq -4.5 \cdot 10^{-165} \lor \neg \left(y \leq 1.55 \cdot 10^{-43}\right)\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 60.7% accurate, 0.3× speedup?

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

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

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

\mathbf{elif}\;y \leq -4.5 \cdot 10^{-165}:\\
\;\;\;\;\frac{x}{-y}\\

\mathbf{elif}\;y \leq 1.55 \cdot 10^{+67}:\\
\;\;\;\;\frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -7.50000000000000042e54 or 1.54999999999999998e67 < y

    1. Initial program 99.9%

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

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

    if -7.50000000000000042e54 < y < -2.80000000000000016e-130 or -4.49999999999999992e-165 < y < 1.54999999999999998e67

    1. Initial program 99.9%

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

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

    if -2.80000000000000016e-130 < y < -4.49999999999999992e-165

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{x}{y}} \]
    5. Step-by-step derivation
      1. mul-1-neg79.1%

        \[\leadsto \color{blue}{-\frac{x}{y}} \]
      2. distribute-frac-neg279.1%

        \[\leadsto \color{blue}{\frac{x}{-y}} \]
    6. Simplified79.1%

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

Alternative 5: 76.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+43} \lor \neg \left(y \leq 1.55 \cdot 10^{+67}\right):\\ \;\;\;\;1 - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z - y}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -3.2e+43) (not (<= y 1.55e+67))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -3.2e+43) || !(y <= 1.55e+67)) {
		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 <= (-3.2d+43)) .or. (.not. (y <= 1.55d+67))) 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 <= -3.2e+43) || !(y <= 1.55e+67)) {
		tmp = 1.0 - (x / y);
	} else {
		tmp = x / (z - y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -3.2e+43) or not (y <= 1.55e+67):
		tmp = 1.0 - (x / y)
	else:
		tmp = x / (z - y)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -3.2e+43) || !(y <= 1.55e+67))
		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 <= -3.2e+43) || ~((y <= 1.55e+67)))
		tmp = 1.0 - (x / y);
	else
		tmp = x / (z - y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.2e+43], N[Not[LessEqual[y, 1.55e+67]], $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 -3.2 \cdot 10^{+43} \lor \neg \left(y \leq 1.55 \cdot 10^{+67}\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 < -3.20000000000000014e43 or 1.54999999999999998e67 < y

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{-\frac{x - y}{y}} \]
      2. div-sub83.0%

        \[\leadsto -\color{blue}{\left(\frac{x}{y} - \frac{y}{y}\right)} \]
      3. sub-neg83.0%

        \[\leadsto -\color{blue}{\left(\frac{x}{y} + \left(-\frac{y}{y}\right)\right)} \]
      4. *-inverses83.0%

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

        \[\leadsto -\left(\frac{x}{y} + \color{blue}{-1}\right) \]
      6. distribute-neg-in83.0%

        \[\leadsto \color{blue}{\left(-\frac{x}{y}\right) + \left(--1\right)} \]
      7. mul-1-neg83.0%

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

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

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

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

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

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

    if -3.20000000000000014e43 < y < 1.54999999999999998e67

    1. Initial program 99.9%

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

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

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

Alternative 6: 76.8% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+44}:\\
\;\;\;\;1 - \frac{x}{y}\\

\mathbf{elif}\;y \leq 6.6 \cdot 10^{+43}:\\
\;\;\;\;\frac{x}{z - y}\\

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


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

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{-\frac{x - y}{y}} \]
      2. div-sub92.3%

        \[\leadsto -\color{blue}{\left(\frac{x}{y} - \frac{y}{y}\right)} \]
      3. sub-neg92.3%

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

        \[\leadsto -\left(\frac{x}{y} + \left(-\color{blue}{1}\right)\right) \]
      5. metadata-eval92.3%

        \[\leadsto -\left(\frac{x}{y} + \color{blue}{-1}\right) \]
      6. distribute-neg-in92.3%

        \[\leadsto \color{blue}{\left(-\frac{x}{y}\right) + \left(--1\right)} \]
      7. mul-1-neg92.3%

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

        \[\leadsto -1 \cdot \frac{x}{y} + \color{blue}{1} \]
      9. +-commutative92.3%

        \[\leadsto \color{blue}{1 + -1 \cdot \frac{x}{y}} \]
      10. mul-1-neg92.3%

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

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

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

    if -2.30000000000000004e44 < y < 6.6000000000000003e43

    1. Initial program 99.9%

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

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

    if 6.6000000000000003e43 < y

    1. Initial program 100.0%

      \[\frac{x - y}{z - y} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{z - y}{x - y}}} \]
    4. Applied egg-rr99.9%

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot y}{z - y}} \]
      2. neg-mul-182.7%

        \[\leadsto \frac{\color{blue}{-y}}{z - y} \]
    7. Simplified82.7%

      \[\leadsto \color{blue}{\frac{-y}{z - y}} \]
    8. Step-by-step derivation
      1. frac-2neg82.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{y}{\color{blue}{y + \left(-z\right)}} \]
      4. unsub-neg82.7%

        \[\leadsto \frac{y}{\color{blue}{y - z}} \]
    11. Simplified82.7%

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

Alternative 7: 61.9% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+54} \lor \neg \left(y \leq 1.55 \cdot 10^{+67}\right):\\
\;\;\;\;1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -8.0000000000000006e54 or 1.54999999999999998e67 < y

    1. Initial program 99.9%

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

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

    if -8.0000000000000006e54 < y < 1.54999999999999998e67

    1. Initial program 99.9%

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

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

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

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

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

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

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

    \[\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 2024096 
(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)))