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

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

\mathbf{elif}\;t_0 \leq 0.001:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+237}:\\
\;\;\;\;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.6
Target3.3
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 3 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{x - z \cdot \frac{x}{y}} \]
      Proof
      (-.f64 x (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) x) (*.f64 z (/.f64 x y))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 y x) y)) (*.f64 z (/.f64 x y))): 56 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 47 points increase in error, 52 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 (/.f64 x y) (-.f64 y z))): 2 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 75 points increase in error, 75 points decrease in error

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -9.9999999999999999e52 or 1e-3 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.99999999999999988e237

    1. Initial program 0.2

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

    if -9.9999999999999999e52 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1e-3 or 1.99999999999999988e237 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 13.3

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Simplified1.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))): 4 points increase in error, 2 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 79 points increase in error, 28 points decrease in error
  3. Recombined 3 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 - z \cdot \frac{x}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -1 \cdot 10^{+53}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 0.001:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{+237}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error19.4
Cost1176
\[\begin{array}{l} t_0 := z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{if}\;z \leq -3.85 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+125}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.65 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-56}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+65}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error19.4
Cost1176
\[\begin{array}{l} t_0 := z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4.15 \cdot 10^{+124}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -1 \cdot 10^{+59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-56}:\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+67}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error19.5
Cost1176
\[\begin{array}{l} t_0 := z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.15 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5 \cdot 10^{+59}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{+15}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-56}:\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{+65}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.6
Cost1176
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{+161}:\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{elif}\;z \leq -1.2 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{+61}:\\ \;\;\;\;\frac{-x}{\frac{y}{z}}\\ \mathbf{elif}\;z \leq -8.3 \cdot 10^{+15}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.6 \cdot 10^{-56}:\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+66}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \end{array} \]
Alternative 5
Error19.6
Cost1176
\[\begin{array}{l} t_0 := \frac{x \cdot \left(-z\right)}{y}\\ \mathbf{if}\;z \leq -3.2 \cdot 10^{+161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.35 \cdot 10^{+126}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{+50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-56}:\\ \;\;\;\;x \cdot \frac{-z}{y}\\ \mathbf{elif}\;z \leq 10^{+70}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error2.5
Cost712
\[\begin{array}{l} t_0 := x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{if}\;x \leq -1.12 \cdot 10^{-296}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-115}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error2.4
Cost712
\[\begin{array}{l} t_0 := \frac{x}{\frac{y}{y - z}}\\ \mathbf{if}\;x \leq -9.2 \cdot 10^{-297}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-124}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error3.4
Cost448
\[x \cdot \left(1 - \frac{z}{y}\right) \]
Alternative 9
Error25.0
Cost64
\[x \]

Error

Reproduce

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