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

Percentage Accurate: 88.0% → 99.8%
Time: 8.5s
Alternatives: 10
Speedup: 0.5×

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 10 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.0% 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.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -45000000 \lor \neg \left(y \leq 6000000000\right):\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -45000000.0) (not (<= y 6000000000.0)))
   (/ y (/ z (- z x)))
   (/ (fma y (- z x) x) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -45000000.0) || !(y <= 6000000000.0)) {
		tmp = y / (z / (z - x));
	} else {
		tmp = fma(y, (z - x), x) / z;
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((y <= -45000000.0) || !(y <= 6000000000.0))
		tmp = Float64(y / Float64(z / Float64(z - x)));
	else
		tmp = Float64(fma(y, Float64(z - x), x) / z);
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[y, -45000000.0], N[Not[LessEqual[y, 6000000000.0]], $MachinePrecision]], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\


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

    1. Initial program 72.8%

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

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

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

      \[\leadsto \color{blue}{y \cdot \frac{z - x}{z}} \]
    6. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto y \cdot \color{blue}{\frac{1}{\frac{z}{z - x}}} \]
      2. un-div-inv100.0%

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

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

    if -4.5e7 < y < 6e9

    1. Initial program 99.9%

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
    2. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \frac{\color{blue}{y \cdot \left(z - x\right) + x}}{z} \]
      2. fma-define99.9%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y, z - x, x\right)}}{z} \]
    3. Simplified99.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -45000000 \lor \neg \left(y \leq 6000000000\right):\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -45000000 \lor \neg \left(y \leq 3500000000\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 -45000000.0) (not (<= y 3500000000.0)))
   (/ y (/ z (- z x)))
   (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -45000000.0) || !(y <= 3500000000.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 <= (-45000000.0d0)) .or. (.not. (y <= 3500000000.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 <= -45000000.0) || !(y <= 3500000000.0)) {
		tmp = y / (z / (z - x));
	} else {
		tmp = (x + (y * (z - x))) / z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -45000000.0) or not (y <= 3500000000.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 <= -45000000.0) || !(y <= 3500000000.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 <= -45000000.0) || ~((y <= 3500000000.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, -45000000.0], N[Not[LessEqual[y, 3500000000.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 -45000000 \lor \neg \left(y \leq 3500000000\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 < -4.5e7 or 3.5e9 < y

    1. Initial program 72.8%

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

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

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

      \[\leadsto \color{blue}{y \cdot \frac{z - x}{z}} \]
    6. Step-by-step derivation
      1. clear-num99.9%

        \[\leadsto y \cdot \color{blue}{\frac{1}{\frac{z}{z - x}}} \]
      2. un-div-inv100.0%

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

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

    if -4.5e7 < y < 3.5e9

    1. Initial program 99.9%

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

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

Alternative 3: 99.1% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 73.4%

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

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

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

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

        \[\leadsto y \cdot \color{blue}{\frac{1}{\frac{z}{z - x}}} \]
      2. un-div-inv99.7%

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

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

    if -9.5e11 < y < 1

    1. Initial program 99.2%

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

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

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

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

Alternative 4: 99.1% accurate, 0.5× speedup?

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

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

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


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

    1. Initial program 73.4%

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

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

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

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

    if -9.5e11 < y < 1

    1. Initial program 99.2%

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

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

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

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

Alternative 5: 83.5% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.50000000000000011e-85 or 1.27999999999999995e-101 < z

    1. Initial program 78.8%

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

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

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

    if -1.50000000000000011e-85 < z < 1.27999999999999995e-101

    1. Initial program 99.9%

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

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

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

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

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

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

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

Alternative 6: 77.9% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{+179}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+253}:\\ \;\;\;\;x \cdot \frac{y}{-z}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 6.5e+179)
   (+ y (/ x z))
   (if (<= y 4.3e+253) (* x (/ y (- z))) (* z (/ y z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 6.5e+179) {
		tmp = y + (x / z);
	} else if (y <= 4.3e+253) {
		tmp = x * (y / -z);
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= 6.5d+179) then
        tmp = y + (x / z)
    else if (y <= 4.3d+253) then
        tmp = x * (y / -z)
    else
        tmp = z * (y / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 6.5e+179) {
		tmp = y + (x / z);
	} else if (y <= 4.3e+253) {
		tmp = x * (y / -z);
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 6.5e+179:
		tmp = y + (x / z)
	elif y <= 4.3e+253:
		tmp = x * (y / -z)
	else:
		tmp = z * (y / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 6.5e+179)
		tmp = Float64(y + Float64(x / z));
	elseif (y <= 4.3e+253)
		tmp = Float64(x * Float64(y / Float64(-z)));
	else
		tmp = Float64(z * Float64(y / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 6.5e+179)
		tmp = y + (x / z);
	elseif (y <= 4.3e+253)
		tmp = x * (y / -z);
	else
		tmp = z * (y / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 6.5e+179], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.3e+253], N[(x * N[(y / (-z)), $MachinePrecision]), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{+179}:\\
\;\;\;\;y + \frac{x}{z}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < 6.50000000000000052e179

    1. Initial program 88.8%

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

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

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

    if 6.50000000000000052e179 < y < 4.2999999999999999e253

    1. Initial program 87.7%

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

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

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

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

        \[\leadsto x \cdot \frac{\color{blue}{1 - y}}{z} \]
    5. Simplified86.8%

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

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

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

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

    if 4.2999999999999999e253 < y

    1. Initial program 59.9%

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

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

      \[\leadsto \frac{\color{blue}{y \cdot z}}{z} \]
    5. Step-by-step derivation
      1. *-commutative22.8%

        \[\leadsto \frac{\color{blue}{z \cdot y}}{z} \]
      2. associate-/l*73.3%

        \[\leadsto \color{blue}{z \cdot \frac{y}{z}} \]
    6. Applied egg-rr73.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 6.5 \cdot 10^{+179}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 4.3 \cdot 10^{+253}:\\ \;\;\;\;x \cdot \frac{y}{-z}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 61.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.1 \cdot 10^{-86}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-11}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.1e-86) y (if (<= y 1.1e-11) (/ x z) (* z (/ y z)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.1e-86) {
		tmp = y;
	} else if (y <= 1.1e-11) {
		tmp = x / z;
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.1d-86)) then
        tmp = y
    else if (y <= 1.1d-11) then
        tmp = x / z
    else
        tmp = z * (y / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.1e-86) {
		tmp = y;
	} else if (y <= 1.1e-11) {
		tmp = x / z;
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.1e-86:
		tmp = y
	elif y <= 1.1e-11:
		tmp = x / z
	else:
		tmp = z * (y / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.1e-86)
		tmp = y;
	elseif (y <= 1.1e-11)
		tmp = Float64(x / z);
	else
		tmp = Float64(z * Float64(y / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.1e-86)
		tmp = y;
	elseif (y <= 1.1e-11)
		tmp = x / z;
	else
		tmp = z * (y / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.1e-86], y, If[LessEqual[y, 1.1e-11], N[(x / z), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 78.8%

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

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

    if -1.1000000000000001e-86 < y < 1.1000000000000001e-11

    1. Initial program 99.9%

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

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

    if 1.1000000000000001e-11 < y

    1. Initial program 75.1%

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

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

      \[\leadsto \frac{\color{blue}{y \cdot z}}{z} \]
    5. Step-by-step derivation
      1. *-commutative28.2%

        \[\leadsto \frac{\color{blue}{z \cdot y}}{z} \]
      2. associate-/l*54.4%

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

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

Alternative 8: 60.6% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.60000000000000003e-86 or 5.4999999999999996e-10 < y

    1. Initial program 77.0%

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

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

    if -1.60000000000000003e-86 < y < 5.4999999999999996e-10

    1. Initial program 99.9%

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

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

Alternative 9: 79.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.0) (+ y (/ x z)) (* z (/ y z))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.0) {
		tmp = y + (x / z);
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= 1.0d0) then
        tmp = y + (x / z)
    else
        tmp = z * (y / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.0) {
		tmp = y + (x / z);
	} else {
		tmp = z * (y / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 1.0:
		tmp = y + (x / z)
	else:
		tmp = z * (y / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= 1.0)
		tmp = Float64(y + Float64(x / z));
	else
		tmp = Float64(z * Float64(y / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 1.0)
		tmp = y + (x / z);
	else
		tmp = z * (y / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 1.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(z * N[(y / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;y + \frac{x}{z}\\

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


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

    1. Initial program 91.1%

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

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

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

    if 1 < y

    1. Initial program 75.1%

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

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

      \[\leadsto \frac{\color{blue}{y \cdot z}}{z} \]
    5. Step-by-step derivation
      1. *-commutative28.2%

        \[\leadsto \frac{\color{blue}{z \cdot y}}{z} \]
      2. associate-/l*54.4%

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

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

Alternative 10: 41.1% 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.7%

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

    \[\leadsto \color{blue}{y} \]
  4. Add Preprocessing

Developer Target 1: 93.5% 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 2024116 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

  :alt
  (! :herbie-platform default (- (+ y (/ x z)) (/ y (/ z x))))

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