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

Percentage Accurate: 88.3% → 99.9%
Time: 5.2s
Alternatives: 9
Speedup: 1.0×

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: 88.3% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

\\
y - \frac{x}{z} \cdot \left(y + -1\right)
\end{array}
Derivation
  1. Initial program 85.2%

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

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

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

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

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

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

      \[\leadsto y - \frac{x}{z} \cdot \color{blue}{\left(y + \left(-1\right)\right)} \]
    6. metadata-eval99.9%

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

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

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

Alternative 2: 75.3% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{-x}{\frac{z}{y}}\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{+69}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;y \leq 1.9 \cdot 10^{+140}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.5000000000000002e69 or 1.2e15 < y < 1.9e140

    1. Initial program 76.5%

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

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

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

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

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

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

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

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

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

    if -8.5000000000000002e69 < y < 1.2e15

    1. Initial program 99.9%

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

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

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

    if 1.9e140 < y

    1. Initial program 51.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot z} \]
    6. Step-by-step derivation
      1. *-commutative65.3%

        \[\leadsto \color{blue}{z \cdot \frac{y}{z}} \]
      2. clear-num65.1%

        \[\leadsto z \cdot \color{blue}{\frac{1}{\frac{z}{y}}} \]
      3. un-div-inv66.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+69}:\\ \;\;\;\;\frac{-x}{\frac{z}{y}}\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+15}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+140}:\\ \;\;\;\;\frac{-x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{z}{y}}\\ \end{array} \]

Alternative 3: 75.8% accurate, 0.7× speedup?

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

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

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

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

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


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

    1. Initial program 73.6%

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

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

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

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

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

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

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

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

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

    if -3.19999999999999985e69 < y < 8e14

    1. Initial program 99.9%

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

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

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

    if 8e14 < y < 3.6000000000000001e141

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000001e141 < y

    1. Initial program 51.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{y}{z} \cdot z} \]
    6. Step-by-step derivation
      1. *-commutative65.3%

        \[\leadsto \color{blue}{z \cdot \frac{y}{z}} \]
      2. clear-num65.1%

        \[\leadsto z \cdot \color{blue}{\frac{1}{\frac{z}{y}}} \]
      3. un-div-inv66.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+69}:\\ \;\;\;\;\frac{-x}{\frac{z}{y}}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+14}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{+141}:\\ \;\;\;\;y \cdot \frac{-x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{z}{y}}\\ \end{array} \]

Alternative 4: 95.2% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 70.9%

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

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

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

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

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

    if -14.199999999999999 < y < 1

    1. Initial program 99.9%

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

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

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

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

Alternative 5: 99.2% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 70.9%

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

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

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

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

    if -14.199999999999999 < y < 1

    1. Initial program 99.9%

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

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

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

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

Alternative 6: 57.1% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{+77}:\\
\;\;\;\;y\\

\mathbf{elif}\;z \leq 1.6:\\
\;\;\;\;\frac{x}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.4e77 or 1.6000000000000001 < z

    1. Initial program 65.2%

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

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

    if -1.4e77 < z < 1.6000000000000001

    1. Initial program 99.3%

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

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

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

Alternative 7: 79.1% accurate, 1.3× 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.8%

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

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

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

    if 1 < y

    1. Initial program 65.4%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{y}{z}\\ \end{array} \]

Alternative 8: 79.1% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{z}{y}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y 1.0) (+ y (/ x z)) (/ z (/ z y))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= 1.0) {
		tmp = y + (x / z);
	} else {
		tmp = z / (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 <= 1.0d0) then
        tmp = y + (x / z)
    else
        tmp = z / (z / y)
    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 / (z / y);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= 1.0:
		tmp = y + (x / z)
	else:
		tmp = z / (z / y)
	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(z / y));
	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 / (z / y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, 1.0], N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision], N[(z / N[(z / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 92.8%

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

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

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

    if 1 < y

    1. Initial program 65.4%

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

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

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

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

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

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

        \[\leadsto \color{blue}{z \cdot \frac{y}{z}} \]
      2. clear-num54.9%

        \[\leadsto z \cdot \color{blue}{\frac{1}{\frac{z}{y}}} \]
      3. un-div-inv55.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq 1:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{z}{y}}\\ \end{array} \]

Alternative 9: 41.1% accurate, 9.0× speedup?

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

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

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

    \[\leadsto \color{blue}{y} \]
  3. Final simplification38.1%

    \[\leadsto y \]

Developer target: 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 2023293 
(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))