Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3

Percentage Accurate: 88.5% → 99.9%
Time: 8.4s
Alternatives: 9
Speedup: 0.8×

Specification

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

\\
\frac{x + y \cdot \left(z - x\right)}{z}
\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: 88.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.6× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -9.9999999999999995e32 or 1.00000000000000004e-10 < z

    1. Initial program 70.5%

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

      \[\leadsto \color{blue}{\left(1 - \frac{x}{z}\right) \cdot y + \frac{x}{z}} \]

    if -9.9999999999999995e32 < z < 1.00000000000000004e-10

    1. Initial program 99.9%

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

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

Alternative 2: 78.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{z} + y\\ t_1 := \frac{x}{z} \cdot \left(-y\right)\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+181}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{+95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (/ x z) y)) (t_1 (* (/ x z) (- y))))
   (if (<= y -8.5e+181)
     t_0
     (if (<= y -3.8e+95)
       t_1
       (if (<= y 2.5e+37) t_0 (if (<= y 2.25e+136) t_1 (* z (/ y z))))))))
double code(double x, double y, double z) {
	double t_0 = (x / z) + y;
	double t_1 = (x / z) * -y;
	double tmp;
	if (y <= -8.5e+181) {
		tmp = t_0;
	} else if (y <= -3.8e+95) {
		tmp = t_1;
	} else if (y <= 2.5e+37) {
		tmp = t_0;
	} else if (y <= 2.25e+136) {
		tmp = t_1;
	} else {
		tmp = z * (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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (x / z) + y
    t_1 = (x / z) * -y
    if (y <= (-8.5d+181)) then
        tmp = t_0
    else if (y <= (-3.8d+95)) then
        tmp = t_1
    else if (y <= 2.5d+37) then
        tmp = t_0
    else if (y <= 2.25d+136) then
        tmp = t_1
    else
        tmp = z * (y / z)
    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 = (x / z) * -y;
	double tmp;
	if (y <= -8.5e+181) {
		tmp = t_0;
	} else if (y <= -3.8e+95) {
		tmp = t_1;
	} else if (y <= 2.5e+37) {
		tmp = t_0;
	} else if (y <= 2.25e+136) {
		tmp = t_1;
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x / z) + y
	t_1 = (x / z) * -y
	tmp = 0
	if y <= -8.5e+181:
		tmp = t_0
	elif y <= -3.8e+95:
		tmp = t_1
	elif y <= 2.5e+37:
		tmp = t_0
	elif y <= 2.25e+136:
		tmp = t_1
	else:
		tmp = z * (y / z)
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x / z) + y)
	t_1 = Float64(Float64(x / z) * Float64(-y))
	tmp = 0.0
	if (y <= -8.5e+181)
		tmp = t_0;
	elseif (y <= -3.8e+95)
		tmp = t_1;
	elseif (y <= 2.5e+37)
		tmp = t_0;
	elseif (y <= 2.25e+136)
		tmp = t_1;
	else
		tmp = Float64(z * Float64(y / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x / z) + y;
	t_1 = (x / z) * -y;
	tmp = 0.0;
	if (y <= -8.5e+181)
		tmp = t_0;
	elseif (y <= -3.8e+95)
		tmp = t_1;
	elseif (y <= 2.5e+37)
		tmp = t_0;
	elseif (y <= 2.25e+136)
		tmp = t_1;
	else
		tmp = z * (y / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x / z), $MachinePrecision] * (-y)), $MachinePrecision]}, If[LessEqual[y, -8.5e+181], t$95$0, If[LessEqual[y, -3.8e+95], t$95$1, If[LessEqual[y, 2.5e+37], t$95$0, If[LessEqual[y, 2.25e+136], t$95$1, N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{z} + y\\
t_1 := \frac{x}{z} \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+181}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq -3.8 \cdot 10^{+95}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 2.5 \cdot 10^{+37}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 2.25 \cdot 10^{+136}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.49999999999999966e181 or -3.7999999999999999e95 < y < 2.49999999999999994e37

    1. Initial program 91.5%

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

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

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

    if -8.49999999999999966e181 < y < -3.7999999999999999e95 or 2.49999999999999994e37 < y < 2.25e136

    1. Initial program 73.3%

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot \frac{x}{z}\right)} \cdot y \]
    5. Step-by-step derivation
      1. mul-1-neg72.5%

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

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

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

    if 2.25e136 < y

    1. Initial program 62.0%

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - x\right)}{z}} \]
    3. Taylor expanded in z around inf 27.5%

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

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{z}}} \]
      2. associate-/r/59.9%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot z} \]
    5. Applied egg-rr59.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+181}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{+95}:\\ \;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{+37}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{+136}:\\ \;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \]

Alternative 3: 78.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{z} + y\\ \mathbf{if}\;y \leq -7.5 \cdot 10^{+182}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -1.95 \cdot 10^{+95}:\\ \;\;\;\;\frac{-y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+135}:\\ \;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (/ x z) y)))
   (if (<= y -7.5e+182)
     t_0
     (if (<= y -1.95e+95)
       (/ (- y) (/ z x))
       (if (<= y 2.3e+38)
         t_0
         (if (<= y 1.75e+135) (* (/ x z) (- y)) (* z (/ y z))))))))
double code(double x, double y, double z) {
	double t_0 = (x / z) + y;
	double tmp;
	if (y <= -7.5e+182) {
		tmp = t_0;
	} else if (y <= -1.95e+95) {
		tmp = -y / (z / x);
	} else if (y <= 2.3e+38) {
		tmp = t_0;
	} else if (y <= 1.75e+135) {
		tmp = (x / z) * -y;
	} else {
		tmp = z * (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) :: t_0
    real(8) :: tmp
    t_0 = (x / z) + y
    if (y <= (-7.5d+182)) then
        tmp = t_0
    else if (y <= (-1.95d+95)) then
        tmp = -y / (z / x)
    else if (y <= 2.3d+38) then
        tmp = t_0
    else if (y <= 1.75d+135) then
        tmp = (x / z) * -y
    else
        tmp = z * (y / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x / z) + y;
	double tmp;
	if (y <= -7.5e+182) {
		tmp = t_0;
	} else if (y <= -1.95e+95) {
		tmp = -y / (z / x);
	} else if (y <= 2.3e+38) {
		tmp = t_0;
	} else if (y <= 1.75e+135) {
		tmp = (x / z) * -y;
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x / z) + y
	tmp = 0
	if y <= -7.5e+182:
		tmp = t_0
	elif y <= -1.95e+95:
		tmp = -y / (z / x)
	elif y <= 2.3e+38:
		tmp = t_0
	elif y <= 1.75e+135:
		tmp = (x / z) * -y
	else:
		tmp = z * (y / z)
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x / z) + y)
	tmp = 0.0
	if (y <= -7.5e+182)
		tmp = t_0;
	elseif (y <= -1.95e+95)
		tmp = Float64(Float64(-y) / Float64(z / x));
	elseif (y <= 2.3e+38)
		tmp = t_0;
	elseif (y <= 1.75e+135)
		tmp = Float64(Float64(x / z) * Float64(-y));
	else
		tmp = Float64(z * Float64(y / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x / z) + y;
	tmp = 0.0;
	if (y <= -7.5e+182)
		tmp = t_0;
	elseif (y <= -1.95e+95)
		tmp = -y / (z / x);
	elseif (y <= 2.3e+38)
		tmp = t_0;
	elseif (y <= 1.75e+135)
		tmp = (x / z) * -y;
	else
		tmp = z * (y / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[y, -7.5e+182], t$95$0, If[LessEqual[y, -1.95e+95], N[((-y) / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.3e+38], t$95$0, If[LessEqual[y, 1.75e+135], N[(N[(x / z), $MachinePrecision] * (-y)), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{z} + y\\
\mathbf{if}\;y \leq -7.5 \cdot 10^{+182}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;y \leq 2.3 \cdot 10^{+38}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 1.75 \cdot 10^{+135}:\\
\;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -7.49999999999999989e182 or -1.9499999999999999e95 < y < 2.3000000000000001e38

    1. Initial program 91.5%

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

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

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

    if -7.49999999999999989e182 < y < -1.9499999999999999e95

    1. Initial program 66.5%

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - x\right)}{z}} \]
    3. Step-by-step derivation
      1. flip--56.0%

        \[\leadsto \frac{y \cdot \color{blue}{\frac{z \cdot z - x \cdot x}{z + x}}}{z} \]
      2. associate-*r/51.3%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{y}{\frac{x + z}{z \cdot z - x \cdot x}}}}{z} \]
      2. difference-of-squares56.6%

        \[\leadsto \frac{\frac{y}{\frac{x + z}{\color{blue}{\left(z + x\right) \cdot \left(z - x\right)}}}}{z} \]
      3. +-commutative56.6%

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

        \[\leadsto \frac{\frac{y}{\color{blue}{\frac{\frac{x + z}{x + z}}{z - x}}}}{z} \]
      5. *-inverses66.5%

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot x}{z}} \]
    8. Step-by-step derivation
      1. associate-/l*72.2%

        \[\leadsto -1 \cdot \color{blue}{\frac{y}{\frac{z}{x}}} \]
      2. associate-*r/72.2%

        \[\leadsto \color{blue}{\frac{-1 \cdot y}{\frac{z}{x}}} \]
      3. neg-mul-172.2%

        \[\leadsto \frac{\color{blue}{-y}}{\frac{z}{x}} \]
    9. Simplified72.2%

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

    if 2.3000000000000001e38 < y < 1.7500000000000001e135

    1. Initial program 79.2%

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

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

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

      \[\leadsto \color{blue}{\left(-1 \cdot \frac{x}{z}\right)} \cdot y \]
    5. Step-by-step derivation
      1. mul-1-neg73.0%

        \[\leadsto \color{blue}{\left(-\frac{x}{z}\right)} \cdot y \]
      2. distribute-frac-neg73.0%

        \[\leadsto \color{blue}{\frac{-x}{z}} \cdot y \]
    6. Simplified73.0%

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

    if 1.7500000000000001e135 < y

    1. Initial program 62.0%

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - x\right)}{z}} \]
    3. Taylor expanded in z around inf 27.5%

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

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{z}}} \]
      2. associate-/r/59.9%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot z} \]
    5. Applied egg-rr59.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.5 \cdot 10^{+182}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{elif}\;y \leq -1.95 \cdot 10^{+95}:\\ \;\;\;\;\frac{-y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 2.3 \cdot 10^{+38}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{elif}\;y \leq 1.75 \cdot 10^{+135}:\\ \;\;\;\;\frac{x}{z} \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \]

Alternative 4: 99.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -10000000000000 \lor \neg \left(y \leq 135000000000\right):\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1e13 or 1.35e11 < y

    1. Initial program 68.1%

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

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

      \[\leadsto \color{blue}{\left(1 - \frac{x}{z}\right) \cdot y} \]

    if -1e13 < y < 1.35e11

    1. Initial program 100.0%

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -10000000000000 \lor \neg \left(y \leq 135000000000\right):\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \end{array} \]

Alternative 5: 98.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -11000000000000 \lor \neg \left(y \leq 2.9 \cdot 10^{-9}\right):\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.1e13 or 2.89999999999999991e-9 < y

    1. Initial program 69.9%

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

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

      \[\leadsto \color{blue}{\left(1 - \frac{x}{z}\right) \cdot y} \]

    if -1.1e13 < y < 2.89999999999999991e-9

    1. Initial program 99.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -11000000000000 \lor \neg \left(y \leq 2.9 \cdot 10^{-9}\right):\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} + y\\ \end{array} \]

Alternative 6: 62.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-33} \lor \neg \left(y \leq 1.6 \cdot 10^{-41}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.79999999999999994e-33 or 1.60000000000000006e-41 < y

    1. Initial program 72.0%

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - x\right)}{z}} \]
    3. Taylor expanded in z around inf 32.1%

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

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{z}}} \]
      2. associate-/r/53.0%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot z} \]
    5. Applied egg-rr53.0%

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

    if -3.79999999999999994e-33 < y < 1.60000000000000006e-41

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{-33} \lor \neg \left(y \leq 1.6 \cdot 10^{-41}\right):\\ \;\;\;\;z \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]

Alternative 7: 59.7% accurate, 1.3× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.49999999999999972e-36 or 6.2000000000000002e-46 < y

    1. Initial program 72.0%

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

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

    if -7.49999999999999972e-36 < y < 6.2000000000000002e-46

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.5 \cdot 10^{-36}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 6.2 \cdot 10^{-46}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 8: 77.1% accurate, 1.8× speedup?

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

\\
\frac{x}{z} + y
\end{array}
Derivation
  1. Initial program 84.5%

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

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

    \[\leadsto \color{blue}{\frac{x}{z}} + y \]
  4. Final simplification75.4%

    \[\leadsto \frac{x}{z} + y \]

Alternative 9: 39.6% accurate, 9.0× speedup?

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

\\
y
\end{array}
Derivation
  1. Initial program 84.5%

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

    \[\leadsto \color{blue}{y} \]
  3. Final simplification40.7%

    \[\leadsto y \]

Developer target: 93.8% accurate, 0.8× speedup?

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

\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}

Reproduce

?
herbie shell --seed 2023181 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

  :herbie-target
  (- (+ y (/ x z)) (/ y (/ z x)))

  (/ (+ x (* y (- z x))) z))