Average Error: 12.8 → 0.3
Time: 4.6s
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:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -2000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+300}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \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))
     t_1
     (if (<= t_0 -2000.0)
       t_0
       (if (<= t_0 2e+36) t_1 (if (<= t_0 1e+300) t_0 (- x (/ z (/ y x)))))))))
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 = t_1;
	} else if (t_0 <= -2000.0) {
		tmp = t_0;
	} else if (t_0 <= 2e+36) {
		tmp = t_1;
	} else if (t_0 <= 1e+300) {
		tmp = t_0;
	} else {
		tmp = x - (z / (y / x));
	}
	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 = t_1;
	} else if (t_0 <= -2000.0) {
		tmp = t_0;
	} else if (t_0 <= 2e+36) {
		tmp = t_1;
	} else if (t_0 <= 1e+300) {
		tmp = t_0;
	} else {
		tmp = x - (z / (y / x));
	}
	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 = t_1
	elif t_0 <= -2000.0:
		tmp = t_0
	elif t_0 <= 2e+36:
		tmp = t_1
	elif t_0 <= 1e+300:
		tmp = t_0
	else:
		tmp = x - (z / (y / x))
	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 = t_1;
	elseif (t_0 <= -2000.0)
		tmp = t_0;
	elseif (t_0 <= 2e+36)
		tmp = t_1;
	elseif (t_0 <= 1e+300)
		tmp = t_0;
	else
		tmp = Float64(x - Float64(z / Float64(y / x)));
	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 = t_1;
	elseif (t_0 <= -2000.0)
		tmp = t_0;
	elseif (t_0 <= 2e+36)
		tmp = t_1;
	elseif (t_0 <= 1e+300)
		tmp = t_0;
	else
		tmp = x - (z / (y / x));
	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)], t$95$1, If[LessEqual[t$95$0, -2000.0], t$95$0, If[LessEqual[t$95$0, 2e+36], t$95$1, If[LessEqual[t$95$0, 1e+300], t$95$0, N[(x - N[(z / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\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:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -2000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+36}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 10^{+300}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;x - \frac{z}{\frac{y}{x}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.8
Target3.0
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 -2e3 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2.00000000000000008e36

    1. Initial program 14.8

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

      \[\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))): 60 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 31 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, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 79 points increase in error, 57 points decrease in error
    3. Taylor expanded in x around 0 0.2

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -2e3 or 2.00000000000000008e36 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.0000000000000001e300

    1. Initial program 0.2

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

    if 1.0000000000000001e300 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 61.0

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

      \[\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))): 60 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-*r/_binary64 (*.f64 y (/.f64 x y))) (*.f64 z (/.f64 x y))): 31 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, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 79 points increase in error, 57 points decrease in error
    3. Applied egg-rr1.9

      \[\leadsto x - \color{blue}{\frac{z}{\frac{y}{x}}} \]
  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:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq -2000:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{+36}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 10^{+300}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \end{array} \]

Alternatives

Alternative 1
Error1.8
Cost712
\[\begin{array}{l} t_0 := x - \frac{z}{\frac{y}{x}}\\ \mathbf{if}\;z \leq -1 \cdot 10^{+75}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.5628093914221708 \cdot 10^{-21}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+75}:\\ \;\;\;\;x - \frac{z}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 1.5628093914221708 \cdot 10^{-21}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot \frac{x}{y}\\ \end{array} \]
Alternative 3
Error19.5
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -3.0009859077370753 \cdot 10^{+50}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.9 \cdot 10^{-39}:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error19.6
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -3.0009859077370753 \cdot 10^{+50}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.9 \cdot 10^{-39}:\\ \;\;\;\;\frac{x}{y} \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error3.0
Cost448
\[\frac{x}{\frac{y}{y - z}} \]
Alternative 6
Error25.3
Cost64
\[x \]

Error

Reproduce

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