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

Percentage Accurate: 87.8% → 98.5%
Time: 4.9s
Alternatives: 9
Speedup: 0.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 87.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: 98.5% accurate, 0.6× speedup?

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

\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.60000000000000006e-165 or 1e-136 < z

    1. Initial program 85.3%

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

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

    if -1.60000000000000006e-165 < z < 1e-136

    1. Initial program 100.0%

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

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

Alternative 2: 99.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -7000000000:\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\

\mathbf{elif}\;y \leq 27000:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\

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


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

    1. Initial program 79.8%

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

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

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

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

    if -7e9 < y < 27000

    1. Initial program 100.0%

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

    if 27000 < y

    1. Initial program 78.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -7000000000:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{elif}\;y \leq 27000:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \end{array} \]

Alternative 3: 98.7% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.4e11 or 1.55000000000000002e-14 < y

    1. Initial program 79.7%

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

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

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

    if -4.4e11 < y < 1.55000000000000002e-14

    1. Initial program 100.0%

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

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

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

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

Alternative 4: 98.7% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -440000000000:\\
\;\;\;\;\frac{y}{\frac{z}{z - x}}\\

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

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


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

    1. Initial program 79.1%

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

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

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

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

    if -4.4e11 < y < 1.55000000000000002e-14

    1. Initial program 100.0%

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

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

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

    if 1.55000000000000002e-14 < y

    1. Initial program 80.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -440000000000:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{-14}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \end{array} \]

Alternative 5: 60.6% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3:\\
\;\;\;\;y\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3 or 1.7e-16 < y

    1. Initial program 80.0%

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

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

    if -3 < y < 1.7e-16

    1. Initial program 100.0%

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

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

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

Alternative 6: 61.7% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -3:\\
\;\;\;\;z \cdot \frac{y}{z}\\

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

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


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

    1. Initial program 79.8%

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

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

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

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

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

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

    if -3 < y < 1.7500000000000001e-17

    1. Initial program 100.0%

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

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

    if 1.7500000000000001e-17 < y

    1. Initial program 80.1%

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

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

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

Alternative 7: 81.3% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 93.2%

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

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

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

    if 1.55000000000000002e-14 < y

    1. Initial program 80.1%

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

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

      \[\leadsto \color{blue}{y} + \frac{x}{z} \]
    4. Step-by-step derivation
      1. div-inv59.2%

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

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

        \[\leadsto y + \color{blue}{\sqrt{x \cdot x}} \cdot \frac{1}{z} \]
      4. sqr-neg62.2%

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

        \[\leadsto y + \color{blue}{\left(\sqrt{-x} \cdot \sqrt{-x}\right)} \cdot \frac{1}{z} \]
      6. add-sqr-sqrt67.1%

        \[\leadsto y + \color{blue}{\left(-x\right)} \cdot \frac{1}{z} \]
      7. cancel-sign-sub-inv67.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1.55 \cdot 10^{-14}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;y - \frac{x}{z}\\ \end{array} \]

Alternative 8: 78.4% accurate, 1.8× speedup?

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

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

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

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

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

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

Alternative 9: 41.3% 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 89.3%

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

    \[\leadsto \color{blue}{y} \]
  3. Final simplification40.6%

    \[\leadsto y \]

Developer target: 94.4% accurate, 0.8× speedup?

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

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

Reproduce

?
herbie shell --seed 2023268 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

  :herbie-target
  (- (+ y (/ x z)) (/ y (/ z x)))

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