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

Percentage Accurate: 87.6% → 99.9%
Time: 8.2s
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: 87.6% 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.8× speedup?

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1 - y}{z}} \cdot x + y \]
    5. clear-num96.1%

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{z}{1 - y}}{x}}} + y \]
    7. clear-num96.5%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{1 - y}}} + y \]
    8. div-inv96.5%

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

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

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

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

Alternative 2: 74.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{+209} \lor \neg \left(y \leq -1.65 \cdot 10^{+154}\right) \land \left(y \leq -1.19 \cdot 10^{+82} \lor \neg \left(y \leq 60000000000000\right)\right):\\ \;\;\;\;-\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} + y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -2.5e+209)
         (and (not (<= y -1.65e+154))
              (or (<= y -1.19e+82) (not (<= y 60000000000000.0)))))
   (- (/ y (/ z x)))
   (+ (/ x z) y)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.5e+209) || (!(y <= -1.65e+154) && ((y <= -1.19e+82) || !(y <= 60000000000000.0)))) {
		tmp = -(y / (z / x));
	} else {
		tmp = (x / z) + y;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-2.5d+209)) .or. (.not. (y <= (-1.65d+154))) .and. (y <= (-1.19d+82)) .or. (.not. (y <= 60000000000000.0d0))) then
        tmp = -(y / (z / x))
    else
        tmp = (x / z) + y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -2.5e+209) || (!(y <= -1.65e+154) && ((y <= -1.19e+82) || !(y <= 60000000000000.0)))) {
		tmp = -(y / (z / x));
	} else {
		tmp = (x / z) + y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -2.5e+209) or (not (y <= -1.65e+154) and ((y <= -1.19e+82) or not (y <= 60000000000000.0))):
		tmp = -(y / (z / x))
	else:
		tmp = (x / z) + y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -2.5e+209) || (!(y <= -1.65e+154) && ((y <= -1.19e+82) || !(y <= 60000000000000.0))))
		tmp = Float64(-Float64(y / Float64(z / x)));
	else
		tmp = Float64(Float64(x / z) + y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -2.5e+209) || (~((y <= -1.65e+154)) && ((y <= -1.19e+82) || ~((y <= 60000000000000.0)))))
		tmp = -(y / (z / x));
	else
		tmp = (x / z) + y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e+209], And[N[Not[LessEqual[y, -1.65e+154]], $MachinePrecision], Or[LessEqual[y, -1.19e+82], N[Not[LessEqual[y, 60000000000000.0]], $MachinePrecision]]]], (-N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), N[(N[(x / z), $MachinePrecision] + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+209} \lor \neg \left(y \leq -1.65 \cdot 10^{+154}\right) \land \left(y \leq -1.19 \cdot 10^{+82} \lor \neg \left(y \leq 60000000000000\right)\right):\\
\;\;\;\;-\frac{y}{\frac{z}{x}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.49999999999999982e209 or -1.65e154 < y < -1.1899999999999999e82 or 6e13 < y

    1. Initial program 74.6%

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

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

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{1 + -1 \cdot y}}} \]
      3. mul-1-neg66.2%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-x}{\color{blue}{\frac{-\left(-z\right)}{y}}} \]
      3. remove-double-neg66.2%

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

        \[\leadsto \frac{-x}{\color{blue}{\frac{-z}{-y}}} \]
      5. distribute-frac-neg66.2%

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

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

        \[\leadsto -\color{blue}{\frac{x}{z} \cdot y} \]
      8. clear-num71.0%

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

        \[\leadsto -\color{blue}{\frac{1 \cdot y}{\frac{z}{x}}} \]
      10. *-un-lft-identity71.1%

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

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

    if -2.49999999999999982e209 < y < -1.65e154 or -1.1899999999999999e82 < y < 6e13

    1. Initial program 93.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{+209} \lor \neg \left(y \leq -1.65 \cdot 10^{+154}\right) \land \left(y \leq -1.19 \cdot 10^{+82} \lor \neg \left(y \leq 60000000000000\right)\right):\\ \;\;\;\;-\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} + y\\ \end{array} \]

Alternative 3: 74.6% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;y \leq -4.5 \cdot 10^{+153} \lor \neg \left(y \leq -1.19 \cdot 10^{+82}\right) \land y \leq 55000000000:\\
\;\;\;\;\frac{x}{z} + y\\

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


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

    1. Initial program 62.4%

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

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

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

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

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

        \[\leadsto \frac{x}{\frac{z}{\color{blue}{1 - y}}} \]
    4. Simplified68.8%

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

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

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

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

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

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

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{\frac{-\left(-z\right)}{y}}} \]
      4. remove-double-neg68.6%

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

        \[\leadsto \left(-x\right) \cdot \frac{1}{\color{blue}{\frac{-z}{-y}}} \]
      6. clear-num68.8%

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

        \[\leadsto \left(-x\right) \cdot \color{blue}{\frac{y}{z}} \]
    9. Applied egg-rr68.8%

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

    if -4.2e209 < y < -4.5000000000000001e153 or -1.1899999999999999e82 < y < 5.5e10

    1. Initial program 93.9%

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

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

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

    if -4.5000000000000001e153 < y < -1.1899999999999999e82 or 5.5e10 < y

    1. Initial program 78.0%

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

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

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

        \[\leadsto \color{blue}{\frac{x}{\frac{z}{1 + -1 \cdot y}}} \]
      3. mul-1-neg65.5%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{-x}{-\frac{-z}{y}}} \]
      2. distribute-frac-neg65.5%

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

        \[\leadsto \frac{-x}{\frac{\color{blue}{z}}{y}} \]
      4. frac-2neg65.5%

        \[\leadsto \frac{-x}{\color{blue}{\frac{-z}{-y}}} \]
      5. distribute-frac-neg65.5%

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

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

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

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

        \[\leadsto -\color{blue}{\frac{1 \cdot y}{\frac{z}{x}}} \]
      10. *-un-lft-identity71.8%

        \[\leadsto -\frac{\color{blue}{y}}{\frac{z}{x}} \]
    9. Applied egg-rr71.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.2 \cdot 10^{+209}:\\ \;\;\;\;\frac{y}{z} \cdot \left(-x\right)\\ \mathbf{elif}\;y \leq -4.5 \cdot 10^{+153} \lor \neg \left(y \leq -1.19 \cdot 10^{+82}\right) \land y \leq 55000000000:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;-\frac{y}{\frac{z}{x}}\\ \end{array} \]

Alternative 4: 99.8% accurate, 0.7× speedup?

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

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

\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 < -2e27 or 9e7 < y

    1. Initial program 73.4%

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

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

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

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

    if -2e27 < y < 9e7

    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}\;y \leq -2 \cdot 10^{+27} \lor \neg \left(y \leq 90000000\right):\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \end{array} \]

Alternative 5: 94.9% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 73.6%

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

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

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

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

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

    if -4e17 < 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}{\left(-1 \cdot \frac{y}{z} + \frac{1}{z}\right) \cdot x + y} \]
    3. Taylor expanded in y around 0 99.1%

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

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

Alternative 6: 98.9% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 73.6%

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

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

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

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

    if -4e17 < 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}{\left(-1 \cdot \frac{y}{z} + \frac{1}{z}\right) \cdot x + y} \]
    3. Taylor expanded in y around 0 99.1%

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

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

Alternative 7: 61.0% accurate, 1.3× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.2000000000000005e-57 or 2.6e-24 < y

    1. Initial program 77.6%

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

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

    if -7.2000000000000005e-57 < y < 2.6e-24

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7.2 \cdot 10^{-57}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-24}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

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

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

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

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

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

Alternative 9: 40.7% 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 86.4%

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

    \[\leadsto \color{blue}{y} \]
  3. Final simplification35.2%

    \[\leadsto y \]

Developer target: 93.9% 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 2023199 
(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))