Average Error: 10.1 → 0.1
Time: 3.2s
Precision: binary64
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} t_0 := \left(y + 1\right) \cdot \frac{x}{z} - x\\ \mathbf{if}\;x \leq -839233400368095400:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.719777420475578 \cdot 10^{-12}:\\ \;\;\;\;\frac{x + x \cdot y}{z} - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (* (+ y 1.0) (/ x z)) x)))
   (if (<= x -839233400368095400.0)
     t_0
     (if (<= x 4.719777420475578e-12) (- (/ (+ x (* x y)) z) x) t_0))))
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 = ((y + 1.0) * (x / z)) - x;
	double tmp;
	if (x <= -839233400368095400.0) {
		tmp = t_0;
	} else if (x <= 4.719777420475578e-12) {
		tmp = ((x + (x * y)) / z) - x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
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) + 1.0d0)) / z
end function
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 + 1.0d0) * (x / z)) - x
    if (x <= (-839233400368095400.0d0)) then
        tmp = t_0
    else if (x <= 4.719777420475578d-12) then
        tmp = ((x + (x * y)) / z) - x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
public static double code(double x, double y, double z) {
	double t_0 = ((y + 1.0) * (x / z)) - x;
	double tmp;
	if (x <= -839233400368095400.0) {
		tmp = t_0;
	} else if (x <= 4.719777420475578e-12) {
		tmp = ((x + (x * y)) / z) - x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return (x * ((y - z) + 1.0)) / z
def code(x, y, z):
	t_0 = ((y + 1.0) * (x / z)) - x
	tmp = 0
	if x <= -839233400368095400.0:
		tmp = t_0
	elif x <= 4.719777420475578e-12:
		tmp = ((x + (x * y)) / z) - x
	else:
		tmp = t_0
	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(Float64(y + 1.0) * Float64(x / z)) - x)
	tmp = 0.0
	if (x <= -839233400368095400.0)
		tmp = t_0;
	elseif (x <= 4.719777420475578e-12)
		tmp = Float64(Float64(Float64(x + Float64(x * y)) / z) - x);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * ((y - z) + 1.0)) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = ((y + 1.0) * (x / z)) - x;
	tmp = 0.0;
	if (x <= -839233400368095400.0)
		tmp = t_0;
	elseif (x <= 4.719777420475578e-12)
		tmp = ((x + (x * y)) / z) - x;
	else
		tmp = t_0;
	end
	tmp_2 = 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[(N[(y + 1.0), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[x, -839233400368095400.0], t$95$0, If[LessEqual[x, 4.719777420475578e-12], N[(N[(N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] - x), $MachinePrecision], t$95$0]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \left(y + 1\right) \cdot \frac{x}{z} - x\\
\mathbf{if}\;x \leq -839233400368095400:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.1
Target0.4
Herbie0.1
\[\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 2 regimes
  2. if x < -839233400368095360 or 4.7197774204755782e-12 < x

    1. Initial program 26.0

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

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

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

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

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

    if -839233400368095360 < x < 4.7197774204755782e-12

    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. Taylor expanded in z around 0 0.1

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

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

Reproduce

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