Average Error: 10.2 → 0.1
Time: 2.5s
Precision: binary64
\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;y - x \cdot \frac{y}{z}\\ \mathbf{elif}\;t_0 \leq -7.589173101786719 \cdot 10^{+48}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\ \mathbf{elif}\;t_0 \leq 1.1372358904094027 \cdot 10^{+307}:\\ \;\;\;\;\left(y + \frac{x}{z}\right) - \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot \frac{x}{z}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x (* y (- z x))) z)))
   (if (<= t_0 (- INFINITY))
     (- y (* x (/ y z)))
     (if (<= t_0 -7.589173101786719e+48)
       (/ (fma y (- z x) x) z)
       (if (<= t_0 1.1372358904094027e+307)
         (- (+ y (/ x z)) (/ (* x y) z))
         (- y (* y (/ x z))))))))
double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
	double t_0 = (x + (y * (z - x))) / z;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = y - (x * (y / z));
	} else if (t_0 <= -7.589173101786719e+48) {
		tmp = fma(y, (z - x), x) / z;
	} else if (t_0 <= 1.1372358904094027e+307) {
		tmp = (y + (x / z)) - ((x * y) / z);
	} else {
		tmp = y - (y * (x / z));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x + Float64(y * Float64(z - x))) / z)
end
function code(x, y, z)
	t_0 = Float64(Float64(x + Float64(y * Float64(z - x))) / z)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(y - Float64(x * Float64(y / z)));
	elseif (t_0 <= -7.589173101786719e+48)
		tmp = Float64(fma(y, Float64(z - x), x) / z);
	elseif (t_0 <= 1.1372358904094027e+307)
		tmp = Float64(Float64(y + Float64(x / z)) - Float64(Float64(x * y) / z));
	else
		tmp = Float64(y - Float64(y * Float64(x / z)));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(y - N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -7.589173101786719e+48], N[(N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$0, 1.1372358904094027e+307], N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
t_0 := \frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;y - x \cdot \frac{y}{z}\\

\mathbf{elif}\;t_0 \leq -7.589173101786719 \cdot 10^{+48}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\

\mathbf{elif}\;t_0 \leq 1.1372358904094027 \cdot 10^{+307}:\\
\;\;\;\;\left(y + \frac{x}{z}\right) - \frac{x \cdot y}{z}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original10.2
Target0.0
Herbie0.1
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
    3. Taylor expanded in y around inf 64.0

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

      \[\leadsto \color{blue}{y - \frac{x}{z} \cdot y} \]
    5. Applied div-inv_binary640.1

      \[\leadsto y - \color{blue}{\left(x \cdot \frac{1}{z}\right)} \cdot y \]
    6. Applied associate-*l*_binary640.1

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

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

    if -inf.0 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < -7.58917310178671929e48

    1. Initial program 0.1

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

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

    if -7.58917310178671929e48 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < 1.1372358904094027e307

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
    3. Taylor expanded in y around 0 0.0

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

    if 1.1372358904094027e307 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z)

    1. Initial program 63.3

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
    3. Taylor expanded in y around inf 63.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + y \cdot \left(z - x\right)}{z} \leq -\infty:\\ \;\;\;\;y - x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{x + y \cdot \left(z - x\right)}{z} \leq -7.589173101786719 \cdot 10^{+48}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}\\ \mathbf{elif}\;\frac{x + y \cdot \left(z - x\right)}{z} \leq 1.1372358904094027 \cdot 10^{+307}:\\ \;\;\;\;\left(y + \frac{x}{z}\right) - \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot \frac{x}{z}\\ \end{array} \]

Reproduce

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