Average Error: 12.1 → 0.3
Time: 3.9s
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 := \frac{x}{\frac{y}{y - z}}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-134}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;t_0 \leq 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 (- y z)))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -1e-78)
       t_0
       (if (<= t_0 2e-134)
         (* x (- 1.0 (/ z y)))
         (if (<= t_0 1e+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 / (y - z));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -1e-78) {
		tmp = t_0;
	} else if (t_0 <= 2e-134) {
		tmp = x * (1.0 - (z / y));
	} else if (t_0 <= 1e+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 / (y - z));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -1e-78) {
		tmp = t_0;
	} else if (t_0 <= 2e-134) {
		tmp = x * (1.0 - (z / y));
	} else if (t_0 <= 1e+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 / (y - z))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -1e-78:
		tmp = t_0
	elif t_0 <= 2e-134:
		tmp = x * (1.0 - (z / y))
	elif t_0 <= 1e+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(y / Float64(y - z)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -1e-78)
		tmp = t_0;
	elseif (t_0 <= 2e-134)
		tmp = Float64(x * Float64(1.0 - Float64(z / y)));
	elseif (t_0 <= 1e+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 / (y - z));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -1e-78)
		tmp = t_0;
	elseif (t_0 <= 2e-134)
		tmp = x * (1.0 - (z / y));
	elseif (t_0 <= 1e+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[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -1e-78], t$95$0, If[LessEqual[t$95$0, 2e-134], N[(x * N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+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 := \frac{x}{\frac{y}{y - z}}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-78}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-134}:\\
\;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\

\mathbf{elif}\;t_0 \leq 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.1
Target2.8
Herbie0.3
\[\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 3 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0 or 9.9999999999999992e292 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 61.1

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

      \[\leadsto \color{blue}{\frac{x}{\frac{y}{y - z}}} \]
      Proof
      (/.f64 x (/.f64 y (-.f64 y z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 65 points increase in error, 38 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -9.99999999999999999e-79 or 2.00000000000000008e-134 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.9999999999999992e292

    1. Initial program 0.3

      \[\frac{x \cdot \left(y - z\right)}{y} \]

    if -9.99999999999999999e-79 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2.00000000000000008e-134

    1. Initial program 10.2

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

      \[\leadsto \color{blue}{x \cdot \left(1 - \frac{z}{y}\right)} \]
      Proof
      (*.f64 x (-.f64 1 (/.f64 z y))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (-.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) (/.f64 z y))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= div-sub_binary64 (/.f64 (-.f64 y z) y))): 3 points increase in error, 1 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 73 points increase in error, 38 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

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

Alternatives

Alternative 1
Error1.8
Cost1996
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{+60}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{1}{y - z}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-134}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;t_0 \leq 10^{+293}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{y}{y - z}}\\ \end{array} \]
Alternative 2
Error3.8
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{-179}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{-232}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error3.6
Cost712
\[\begin{array}{l} t_0 := \frac{x}{\frac{y}{y - z}}\\ \mathbf{if}\;y \leq -6.2 \cdot 10^{-179}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{-233}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.2
Cost648
\[\begin{array}{l} t_0 := \frac{z \cdot \left(-x\right)}{y}\\ \mathbf{if}\;z \leq -4.1 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+50}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error18.9
Cost648
\[\begin{array}{l} t_0 := \frac{-z}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -2.05 \cdot 10^{-53}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 8.8 \cdot 10^{+49}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error25.9
Cost64
\[x \]

Error

Reproduce

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