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

Percentage Accurate: 87.9% → 99.9%
Time: 5.9s
Alternatives: 8
Speedup: 1.0×

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 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: 87.9% 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, 1.0× speedup?

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

\\
y - \frac{x}{z} \cdot \left(y + -1\right)
\end{array}
Derivation
  1. Initial program 88.9%

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

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

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

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

      \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
    4. associate-/r/100.0%

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

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

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

    \[\leadsto \color{blue}{y - \frac{x}{z} \cdot \left(y + -1\right)} \]
  5. Final simplification100.0%

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

Alternative 2: 75.9% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;x \leq 2.6 \cdot 10^{+296}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.4000000000000003e148 or 4.99999999999999994e203 < x < 2.6000000000000001e296

    1. Initial program 87.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-x \cdot y}}{z} \]
      3. distribute-rgt-neg-in57.5%

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

        \[\leadsto \color{blue}{x \cdot \frac{-y}{z}} \]
    7. Simplified64.8%

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

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

        \[\leadsto \color{blue}{-\frac{x \cdot y}{z}} \]
      2. *-commutative57.5%

        \[\leadsto -\frac{\color{blue}{y \cdot x}}{z} \]
      3. associate-/l*72.1%

        \[\leadsto -\color{blue}{\frac{y}{\frac{z}{x}}} \]
      4. distribute-neg-frac72.1%

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

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

    if -3.4000000000000003e148 < x < 4.99999999999999994e203

    1. Initial program 89.2%

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
      4. associate-/r/100.0%

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

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

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

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

      \[\leadsto y - \color{blue}{-1 \cdot \frac{x}{z}} \]
    6. Step-by-step derivation
      1. mul-1-neg85.8%

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

        \[\leadsto y - \color{blue}{\frac{-x}{z}} \]
    7. Simplified85.8%

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

      \[\leadsto \color{blue}{y + \frac{x}{z}} \]
    9. Step-by-step derivation
      1. +-commutative85.8%

        \[\leadsto \color{blue}{\frac{x}{z} + y} \]
    10. Simplified85.8%

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

    if 2.6000000000000001e296 < x

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{+148}:\\ \;\;\;\;\frac{-y}{\frac{z}{x}}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+203}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{+296}:\\ \;\;\;\;\frac{-y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z}\\ \end{array} \]

Alternative 3: 85.5% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.49999999999999926e146 or 2e6 < x

    1. Initial program 88.8%

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
      4. associate-/r/99.9%

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

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

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

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{z} - \frac{y}{z}\right)} \]
    6. Step-by-step derivation
      1. div-sub87.7%

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

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

    if -9.49999999999999926e146 < x < 2e6

    1. Initial program 88.9%

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
      4. associate-/r/100.0%

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

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

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{-x}{z}} \]
    7. Simplified88.4%

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

      \[\leadsto \color{blue}{y + \frac{x}{z}} \]
    9. Step-by-step derivation
      1. +-commutative88.4%

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

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

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

Alternative 4: 99.2% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 75.6%

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
      4. associate-/r/99.9%

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

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

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

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

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

    if -1 < y < 1

    1. Initial program 99.8%

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
      4. associate-/r/100.0%

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

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

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

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

      \[\leadsto y - \color{blue}{-1 \cdot \frac{x}{z}} \]
    6. Step-by-step derivation
      1. mul-1-neg98.7%

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

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

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

      \[\leadsto \color{blue}{y + \frac{x}{z}} \]
    9. Step-by-step derivation
      1. +-commutative98.7%

        \[\leadsto \color{blue}{\frac{x}{z} + y} \]
    10. Simplified98.7%

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

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

Alternative 5: 76.0% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+148}:\\
\;\;\;\;x \cdot \frac{-y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.4000000000000003e148

    1. Initial program 87.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-x \cdot y}}{z} \]
      3. distribute-rgt-neg-in60.5%

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

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

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

    if -3.4000000000000003e148 < x

    1. Initial program 89.1%

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

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

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

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

        \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
      4. associate-/r/100.0%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{y + \frac{x}{z}} \]
    9. Step-by-step derivation
      1. +-commutative82.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{+148}:\\ \;\;\;\;x \cdot \frac{-y}{z}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]

Alternative 6: 61.6% accurate, 1.3× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.8e-19 or 6.80000000000000008e-45 < y

    1. Initial program 78.2%

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

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

    if -5.8e-19 < y < 6.80000000000000008e-45

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.8 \cdot 10^{-19}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 6.8 \cdot 10^{-45}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Alternative 7: 78.5% accurate, 1.8× speedup?

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

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

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

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

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

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

      \[\leadsto y - \color{blue}{\frac{x}{\frac{z}{y - 1}}} \]
    4. associate-/r/100.0%

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

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

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

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

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

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

      \[\leadsto y - \color{blue}{\frac{-x}{z}} \]
  7. Simplified78.0%

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

    \[\leadsto \color{blue}{y + \frac{x}{z}} \]
  9. Step-by-step derivation
    1. +-commutative78.0%

      \[\leadsto \color{blue}{\frac{x}{z} + y} \]
  10. Simplified78.0%

    \[\leadsto \color{blue}{\frac{x}{z} + y} \]
  11. Final simplification78.0%

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

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

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

    \[\leadsto \color{blue}{y} \]
  3. Final simplification37.0%

    \[\leadsto y \]

Developer target: 94.1% 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 2023340 
(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))