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

Percentage Accurate: 87.8% → 95.2%
Time: 6.9s
Alternatives: 9
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 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.8% 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: 95.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+167} \lor \neg \left(z \leq 1.7 \cdot 10^{+85}\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 -1.35e+167) (not (<= z 1.7e+85)))
   (+ y (/ x z))
   (/ (+ x (* y (- z x))) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.35e+167) || !(z <= 1.7e+85)) {
		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 <= (-1.35d+167)) .or. (.not. (z <= 1.7d+85))) 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 <= -1.35e+167) || !(z <= 1.7e+85)) {
		tmp = y + (x / z);
	} else {
		tmp = (x + (y * (z - x))) / z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.35e+167) or not (z <= 1.7e+85):
		tmp = y + (x / z)
	else:
		tmp = (x + (y * (z - x))) / z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.35e+167) || !(z <= 1.7e+85))
		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 <= -1.35e+167) || ~((z <= 1.7e+85)))
		tmp = y + (x / z);
	else
		tmp = (x + (y * (z - x))) / z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.35e+167], N[Not[LessEqual[z, 1.7e+85]], $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 -1.35 \cdot 10^{+167} \lor \neg \left(z \leq 1.7 \cdot 10^{+85}\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 < -1.35000000000000003e167 or 1.7000000000000002e85 < z

    1. Initial program 64.2%

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

      \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
    4. Taylor expanded in x around 0 93.1%

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

    if -1.35000000000000003e167 < z < 1.7000000000000002e85

    1. Initial program 97.3%

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

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

Alternative 2: 86.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.1 \cdot 10^{+91} \lor \neg \left(x \leq 1.85 \cdot 10^{+94}\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 -4.1e+91) (not (<= x 1.85e+94)))
   (* (/ x z) (- 1.0 y))
   (+ y (/ x z))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -4.1e+91) || !(x <= 1.85e+94)) {
		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 <= (-4.1d+91)) .or. (.not. (x <= 1.85d+94))) 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 <= -4.1e+91) || !(x <= 1.85e+94)) {
		tmp = (x / z) * (1.0 - y);
	} else {
		tmp = y + (x / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -4.1e+91) or not (x <= 1.85e+94):
		tmp = (x / z) * (1.0 - y)
	else:
		tmp = y + (x / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -4.1e+91) || !(x <= 1.85e+94))
		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 <= -4.1e+91) || ~((x <= 1.85e+94)))
		tmp = (x / z) * (1.0 - y);
	else
		tmp = y + (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e+91], N[Not[LessEqual[x, 1.85e+94]], $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 -4.1 \cdot 10^{+91} \lor \neg \left(x \leq 1.85 \cdot 10^{+94}\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 < -4.1000000000000002e91 or 1.8500000000000001e94 < x

    1. Initial program 84.3%

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

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

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

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

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

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

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

    if -4.1000000000000002e91 < x < 1.8500000000000001e94

    1. Initial program 87.5%

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

      \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
    4. Taylor expanded in x around 0 87.7%

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

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

Alternative 3: 86.2% accurate, 0.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -4.5e90 or 1.39999999999999999e94 < x

    1. Initial program 84.3%

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

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

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

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

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

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

    if -4.5e90 < x < 1.39999999999999999e94

    1. Initial program 87.5%

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

      \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
    4. Taylor expanded in x around 0 87.7%

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

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

Alternative 4: 86.2% accurate, 0.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.20000000000000002e92

    1. Initial program 76.6%

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-inv76.5%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, z - x, x\right)} \cdot \frac{1}{z} \]
    4. Applied egg-rr76.5%

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

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

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

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

        \[\leadsto \frac{x + \color{blue}{\left(-y\right) \cdot x}}{z} \]
      4. distribute-rgt1-in76.4%

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

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

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

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

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

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

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

    if -1.20000000000000002e92 < x < 4.80000000000000021e93

    1. Initial program 87.5%

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

      \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
    4. Taylor expanded in x around 0 87.7%

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

    if 4.80000000000000021e93 < x

    1. Initial program 90.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.2 \cdot 10^{+92}:\\ \;\;\;\;\frac{x}{\frac{z}{1 - y}}\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+93}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} \cdot \left(1 - y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 62.5% accurate, 0.6× speedup?

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

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

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

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


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

    1. Initial program 80.8%

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

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

    if -2.09999999999999992e-76 < y < 2.19999999999999991e-20

    1. Initial program 100.0%

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

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

    if 2.19999999999999991e-20 < y

    1. Initial program 71.6%

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

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

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

        \[\leadsto \frac{\color{blue}{z \cdot y}}{z} \]
    6. Simplified34.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{-76}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{-20}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 61.1% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.04e-76 or 3.30000000000000009e-21 < y

    1. Initial program 76.7%

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

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

    if -1.04e-76 < y < 3.30000000000000009e-21

    1. Initial program 100.0%

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

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

Alternative 7: 82.1% accurate, 0.9× speedup?

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

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

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


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

    1. Initial program 91.8%

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

      \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
    4. Taylor expanded in x around 0 87.7%

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

    if 1 < y

    1. Initial program 69.8%

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

      \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
    4. Taylor expanded in x around 0 55.8%

      \[\leadsto \color{blue}{y + \frac{x}{z}} \]
    5. Step-by-step derivation
      1. add-sqr-sqrt35.6%

        \[\leadsto y + \frac{x}{\color{blue}{\sqrt{z} \cdot \sqrt{z}}} \]
      2. sqrt-unprod60.8%

        \[\leadsto y + \frac{x}{\color{blue}{\sqrt{z \cdot z}}} \]
      3. sqr-neg60.8%

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

        \[\leadsto y + \frac{x}{\color{blue}{\sqrt{-z} \cdot \sqrt{-z}}} \]
      5. add-sqr-sqrt66.2%

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

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

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

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

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

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

    \[\leadsto \frac{x + \color{blue}{y \cdot z}}{z} \]
  4. Taylor expanded in x around 0 80.0%

    \[\leadsto \color{blue}{y + \frac{x}{z}} \]
  5. Add Preprocessing

Alternative 9: 40.8% accurate, 9.0× speedup?

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

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

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

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

Developer Target 1: 94.2% 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 2024180 
(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))