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

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

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


\end{array}

Error

Target

Original10.3
Target0.5
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Derivation

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

    1. Initial program 64.0

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

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

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    5. Simplified0.0

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

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

    if -inf.0 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 4.9999999999999997e303

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x} \]
    3. Applied egg-rr0.2

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

      \[\leadsto \color{blue}{\frac{y \cdot x + x}{z}} - x \]
    5. Simplified0.1

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

    if 4.9999999999999997e303 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z)

    1. Initial program 62.0

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

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

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

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

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

Reproduce

herbie shell --seed 2022186 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

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