Average Error: 12.5 → 0.7
Time: 5.7s
Precision: binary64
Cost: 2512
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{+74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+293}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* x (- y z)) y)) (t_1 (* x (/ (- y z) y))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -5e+74)
       t_0
       (if (<= t_0 5e+98) t_1 (if (<= t_0 5e+293) t_0 t_1))))))
double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
	double t_0 = (x * (y - z)) / y;
	double t_1 = x * ((y - z) / y);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -5e+74) {
		tmp = t_0;
	} else if (t_0 <= 5e+98) {
		tmp = t_1;
	} else if (t_0 <= 5e+293) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	return (x * (y - z)) / y;
}
public static double code(double x, double y, double z) {
	double t_0 = (x * (y - z)) / y;
	double t_1 = x * ((y - z) / y);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -5e+74) {
		tmp = t_0;
	} else if (t_0 <= 5e+98) {
		tmp = t_1;
	} else if (t_0 <= 5e+293) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y - z)) / y
def code(x, y, z):
	t_0 = (x * (y - z)) / y
	t_1 = x * ((y - z) / y)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -5e+74:
		tmp = t_0
	elif t_0 <= 5e+98:
		tmp = t_1
	elif t_0 <= 5e+293:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = Float64(Float64(x * Float64(y - z)) / y)
	t_1 = Float64(x * Float64(Float64(y - z) / y))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -5e+74)
		tmp = t_0;
	elseif (t_0 <= 5e+98)
		tmp = t_1;
	elseif (t_0 <= 5e+293)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * (y - z)) / y;
end
function tmp_2 = code(x, y, z)
	t_0 = (x * (y - z)) / y;
	t_1 = x * ((y - z) / y);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -5e+74)
		tmp = t_0;
	elseif (t_0 <= 5e+98)
		tmp = t_1;
	elseif (t_0 <= 5e+293)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(N[(y - z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -5e+74], t$95$0, If[LessEqual[t$95$0, 5e+98], t$95$1, If[LessEqual[t$95$0, 5e+293], t$95$0, t$95$1]]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
t_1 := x \cdot \frac{y - z}{y}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -5 \cdot 10^{+74}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+98}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+293}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.5
Target3.2
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;z < -2.060202331921739 \cdot 10^{+104}:\\ \;\;\;\;x - \frac{z \cdot x}{y}\\ \mathbf{elif}\;z < 1.6939766013828526 \cdot 10^{+213}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0 or -4.99999999999999963e74 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.9999999999999998e98 or 5.00000000000000033e293 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 17.3

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

      \[\leadsto \color{blue}{x \cdot \frac{y - z}{y}} \]
      Proof
      (*.f64 x (/.f64 (-.f64 y z) y)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 76 points increase in error, 26 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -4.99999999999999963e74 or 4.9999999999999998e98 < (/.f64 (*.f64 x (-.f64 y z)) y) < 5.00000000000000033e293

    1. Initial program 0.2

      \[\frac{x \cdot \left(y - z\right)}{y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error21.2
Cost1176
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{-38}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.65 \cdot 10^{-81}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3600:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.32 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.7 \cdot 10^{+170}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error21.0
Cost1176
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -5.5 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.5 \cdot 10^{-81}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 150:\\ \;\;\;\;\left(-x\right) \cdot \frac{z}{y}\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{+114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 7.6 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error3.9
Cost712
\[\begin{array}{l} t_0 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;y \leq -2 \cdot 10^{-195}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4 \cdot 10^{-286}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error2.2
Cost712
\[\begin{array}{l} t_0 := x \cdot \frac{y - z}{y}\\ \mathbf{if}\;x \leq -8 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-76}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error2.1
Cost712
\[\begin{array}{l} t_0 := \frac{x}{\frac{y}{y - z}}\\ \mathbf{if}\;x \leq -1.36 \cdot 10^{-117}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-73}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error19.0
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -17500000000:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.6 \cdot 10^{-119}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error25.9
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022325 
(FPCore (x y z)
  :name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))

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