Average Error: 9.9 → 2.0
Time: 5.9s
Precision: binary64
Cost: 840
\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}} - x\\ \mathbf{if}\;z \leq -1.3712974317740827 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 39557020297.2278:\\ \;\;\;\;\frac{x + x \cdot \left(y - z\right)}{z}\\ \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 (/ z x)) x)))
   (if (<= z -1.3712974317740827e+50)
     t_0
     (if (<= z 39557020297.2278) (/ (+ x (* x (- y z))) z) 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 / (z / x)) - x;
	double tmp;
	if (z <= -1.3712974317740827e+50) {
		tmp = t_0;
	} else if (z <= 39557020297.2278) {
		tmp = (x + (x * (y - z))) / z;
	} 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 / (z / x)) - x
    if (z <= (-1.3712974317740827d+50)) then
        tmp = t_0
    else if (z <= 39557020297.2278d0) then
        tmp = (x + (x * (y - z))) / z
    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 / (z / x)) - x;
	double tmp;
	if (z <= -1.3712974317740827e+50) {
		tmp = t_0;
	} else if (z <= 39557020297.2278) {
		tmp = (x + (x * (y - z))) / z;
	} 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 / (z / x)) - x
	tmp = 0
	if z <= -1.3712974317740827e+50:
		tmp = t_0
	elif z <= 39557020297.2278:
		tmp = (x + (x * (y - z))) / z
	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(y / Float64(z / x)) - x)
	tmp = 0.0
	if (z <= -1.3712974317740827e+50)
		tmp = t_0;
	elseif (z <= 39557020297.2278)
		tmp = Float64(Float64(x + Float64(x * Float64(y - z))) / z);
	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 / (z / x)) - x;
	tmp = 0.0;
	if (z <= -1.3712974317740827e+50)
		tmp = t_0;
	elseif (z <= 39557020297.2278)
		tmp = (x + (x * (y - z))) / z;
	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[(y / N[(z / x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]}, If[LessEqual[z, -1.3712974317740827e+50], t$95$0, If[LessEqual[z, 39557020297.2278], N[(N[(x + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \frac{y}{\frac{z}{x}} - x\\
\mathbf{if}\;z \leq -1.3712974317740827 \cdot 10^{+50}:\\
\;\;\;\;t_0\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.9
Target0.4
Herbie2.0
\[\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 z < -1.3712974317740827e50 or 39557020297.227798 < z

    1. Initial program 17.8

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

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

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

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

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

    if -1.3712974317740827e50 < z < 39557020297.227798

    1. Initial program 0.5

      \[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
    2. Applied egg-rr0.5

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

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

Alternatives

Alternative 1
Error21.9
Cost984
\[\begin{array}{l} t_0 := \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-47}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq -1.56 \cdot 10^{-145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-260}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-57}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 0.00031:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 2
Error2.5
Cost712
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}} - x\\ \mathbf{if}\;y \leq -27.340922656872998:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.0008738801419590957:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error2.8
Cost712
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}} - x\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x + y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error2.8
Cost712
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}} - x\\ \mathbf{if}\;z \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error11.3
Cost584
\[\begin{array}{l} t_0 := \frac{y \cdot x}{z}\\ \mathbf{if}\;y \leq -3.374842221325893 \cdot 10^{+58}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+80}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error11.5
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.374842221325893 \cdot 10^{+58}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+80}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]
Alternative 7
Error11.4
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -3.374842221325893 \cdot 10^{+58}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+80}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]
Alternative 8
Error18.9
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 0.00031:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 9
Error33.3
Cost128
\[-x \]

Error

Reproduce

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