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

Percentage Accurate: 88.3% → 99.7%
Time: 6.6s
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.3% 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.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(z - x\right)\\ t_1 := \frac{x + t_0}{z}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{+295}\right):\\ \;\;\;\;y + x \cdot \left(\frac{1}{z} - \frac{y}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} + \frac{t_0}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- z x))) (t_1 (/ (+ x t_0) z)))
   (if (or (<= t_1 (- INFINITY)) (not (<= t_1 1e+295)))
     (+ y (* x (- (/ 1.0 z) (/ y z))))
     (+ (/ x z) (/ t_0 z)))))
double code(double x, double y, double z) {
	double t_0 = y * (z - x);
	double t_1 = (x + t_0) / z;
	double tmp;
	if ((t_1 <= -((double) INFINITY)) || !(t_1 <= 1e+295)) {
		tmp = y + (x * ((1.0 / z) - (y / z)));
	} else {
		tmp = (x / z) + (t_0 / z);
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	double t_0 = y * (z - x);
	double t_1 = (x + t_0) / z;
	double tmp;
	if ((t_1 <= -Double.POSITIVE_INFINITY) || !(t_1 <= 1e+295)) {
		tmp = y + (x * ((1.0 / z) - (y / z)));
	} else {
		tmp = (x / z) + (t_0 / z);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y * (z - x)
	t_1 = (x + t_0) / z
	tmp = 0
	if (t_1 <= -math.inf) or not (t_1 <= 1e+295):
		tmp = y + (x * ((1.0 / z) - (y / z)))
	else:
		tmp = (x / z) + (t_0 / z)
	return tmp
function code(x, y, z)
	t_0 = Float64(y * Float64(z - x))
	t_1 = Float64(Float64(x + t_0) / z)
	tmp = 0.0
	if ((t_1 <= Float64(-Inf)) || !(t_1 <= 1e+295))
		tmp = Float64(y + Float64(x * Float64(Float64(1.0 / z) - Float64(y / z))));
	else
		tmp = Float64(Float64(x / z) + Float64(t_0 / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y * (z - x);
	t_1 = (x + t_0) / z;
	tmp = 0.0;
	if ((t_1 <= -Inf) || ~((t_1 <= 1e+295)))
		tmp = y + (x * ((1.0 / z) - (y / z)));
	else
		tmp = (x / z) + (t_0 / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + t$95$0), $MachinePrecision] / z), $MachinePrecision]}, If[Or[LessEqual[t$95$1, (-Infinity)], N[Not[LessEqual[t$95$1, 1e+295]], $MachinePrecision]], N[(y + N[(x * N[(N[(1.0 / z), $MachinePrecision] - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / z), $MachinePrecision] + N[(t$95$0 / z), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < -inf.0 or 9.9999999999999998e294 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z)

    1. Initial program 64.2%

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

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

    if -inf.0 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < 9.9999999999999998e294

    1. Initial program 99.9%

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

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

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

Alternative 2: 95.4% accurate, 0.7× speedup?

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

\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 < -2.49999999999999989e110 or 3.00000000000000023e46 < z

    1. Initial program 71.5%

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

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

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

    if -2.49999999999999989e110 < z < 3.00000000000000023e46

    1. Initial program 99.4%

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

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

Alternative 3: 85.5% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.5999999999999999e143 or 8.19999999999999959e99 < x

    1. Initial program 91.9%

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

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

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

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

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

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

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

    if -3.5999999999999999e143 < x < 8.19999999999999959e99

    1. Initial program 87.1%

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

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

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

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

Alternative 4: 95.5% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 74.3%

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

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

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

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

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

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

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

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

        \[\leadsto y + -1 \cdot \color{blue}{\frac{y \cdot x}{z}} \]
      7. *-commutative91.6%

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

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

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

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

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

    if -1.05e17 < y < 1

    1. Initial program 99.9%

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

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

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

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

Alternative 5: 95.9% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 74.3%

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

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

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

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

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

    if -1.05e17 < y < 1

    1. Initial program 99.9%

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

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

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

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

Alternative 6: 61.1% accurate, 1.3× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.3999999999999998e-22 or 4.1000000000000003e-9 < y

    1. Initial program 75.6%

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

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

    if -3.3999999999999998e-22 < y < 4.1000000000000003e-9

    1. Initial program 99.9%

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

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

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

Alternative 7: 62.3% accurate, 1.3× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.30000000000000006e-19

    1. Initial program 78.6%

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

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

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

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

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

    if -1.30000000000000006e-19 < y < 7.4000000000000003e-10

    1. Initial program 99.9%

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

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

    if 7.4000000000000003e-10 < y

    1. Initial program 72.8%

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

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

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

Alternative 8: 78.0% 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.6%

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

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

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

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

Alternative 9: 40.5% 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.6%

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

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

    \[\leadsto y \]

Developer target: 94.4% 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 2023275 
(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))