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

Percentage Accurate: 87.9% → 99.5%
Time: 7.4s
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.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x + y \cdot \left(z - x\right)}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
function code(x, y, z)
	return Float64(Float64(x + Float64(y * Float64(z - x))) / z)
end
function tmp = code(x, y, z)
	tmp = (x + (y * (z - x))) / z;
end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}

Alternative 1: 99.5% accurate, 0.5× speedup?

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

    1. Initial program 70.8%

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 70.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}} \]

    if -7.1e56 < y < 9e8

    1. Initial program 100.0%

      \[\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 -7.1 \cdot 10^{+56} \lor \neg \left(y \leq 900000000\right):\\ \;\;\;\;y \cdot \frac{z - x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 79.9% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := y + \frac{x}{z}\\
\mathbf{if}\;y \leq -1.25 \cdot 10^{+228}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y \leq 1:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.25e228 or -8e129 < y < 1

    1. Initial program 94.5%

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

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

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

    if -1.25e228 < y < -8e129

    1. Initial program 76.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{y \cdot x}}{-z} \]
      4. associate-*r/85.6%

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

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

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

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

        \[\leadsto -y \cdot \color{blue}{\frac{1}{\frac{z}{x}}} \]
      4. un-div-inv85.9%

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

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

    if 1 < y

    1. Initial program 72.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.25 \cdot 10^{+228}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq -8 \cdot 10^{+129}:\\ \;\;\;\;\frac{y}{\frac{-z}{x}}\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y - \frac{x}{z}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9000000000000 \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 -9000000000000.0) (not (<= y 1.0)))
   (* y (/ (- z x) z))
   (+ y (/ x z))))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -9000000000000.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 <= (-9000000000000.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 <= -9000000000000.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 <= -9000000000000.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 <= -9000000000000.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 <= -9000000000000.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, -9000000000000.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 -9000000000000 \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 < -9e12 or 1 < y

    1. Initial program 72.3%

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

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

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

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

    if -9e12 < y < 1

    1. Initial program 100.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9000000000000 \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 4: 85.1% accurate, 0.5× speedup?

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

    1. Initial program 85.4%

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

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

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

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

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

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

    if -1.35e193 < x < 3.3999999999999999e63

    1. Initial program 87.9%

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

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

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

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

Alternative 5: 62.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-5} \lor \neg \left(y \leq 9.5 \cdot 10^{-26}\right):\\
\;\;\;\;z \cdot \frac{y}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.5000000000000002e-5 or 9.4999999999999995e-26 < y

    1. Initial program 74.3%

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

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

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

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

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

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

    if -5.5000000000000002e-5 < y < 9.4999999999999995e-26

    1. Initial program 100.0%

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

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

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

Alternative 6: 57.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.6 \cdot 10^{-58}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 3.3 \cdot 10^{+49}:\\
\;\;\;\;\frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -9.6000000000000002e-58 or 3.2999999999999998e49 < z

    1. Initial program 77.7%

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

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

    if -9.6000000000000002e-58 < z < 3.2999999999999998e49

    1. Initial program 97.7%

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

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

Alternative 7: 81.3% 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 92.6%

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

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

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

    if 1 < y

    1. Initial program 72.1%

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 79.3% 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 92.6%

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

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

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

    if 1 < y

    1. Initial program 72.1%

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

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

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

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

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

      \[\leadsto \color{blue}{z \cdot \frac{y}{z}} \]
  3. Recombined 2 regimes into one program.
  4. 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 87.2%

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

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

Developer Target 1: 94.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \end{array} \]
(FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
double code(double x, double y, double z) {
	return (y + (x / z)) - (y / (z / x));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (y + (x / z)) - (y / (z / x))
end function
public static double code(double x, double y, double z) {
	return (y + (x / z)) - (y / (z / x));
}
def code(x, y, z):
	return (y + (x / z)) - (y / (z / x))
function code(x, y, z)
	return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x)))
end
function tmp = code(x, y, z)
	tmp = (y + (x / z)) - (y / (z / x));
end
code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}

Reproduce

?
herbie shell --seed 2024139 
(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))