?

Average Error: 12.6 → 1.8
Time: 16.6s
Precision: binary64
Cost: 1544

?

\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := \left(1 - \frac{z}{y}\right) \cdot x\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -20:\\ \;\;\;\;x + \left(-\frac{z \cdot x}{y}\right)\\ \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 (* (- 1.0 (/ z y)) x)))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -20.0) (+ x (- (/ (* z x) y))) 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 = (1.0 - (z / y)) * x;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -20.0) {
		tmp = x + -((z * x) / y);
	} 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 = (1.0 - (z / y)) * x;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else if (t_0 <= -20.0) {
		tmp = x + -((z * x) / y);
	} 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 = (1.0 - (z / y)) * x
	tmp = 0
	if t_0 <= -math.inf:
		tmp = t_1
	elif t_0 <= -20.0:
		tmp = x + -((z * x) / y)
	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(Float64(1.0 - Float64(z / y)) * x)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_0 <= -20.0)
		tmp = Float64(x + Float64(-Float64(Float64(z * x) / y)));
	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 = (1.0 - (z / y)) * x;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = t_1;
	elseif (t_0 <= -20.0)
		tmp = x + -((z * x) / y);
	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[(N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -20.0], N[(x + (-N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision])), $MachinePrecision], 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 := \left(1 - \frac{z}{y}\right) \cdot x\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

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

\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.1
Herbie1.8
\[\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 -20 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 15.9

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 5.8

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y} + x} \]
    3. Simplified5.8

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

      [Start]5.8

      \[ -1 \cdot \frac{z \cdot x}{y} + x \]

      rational_best-simplify-1 [=>]5.8

      \[ \color{blue}{x + -1 \cdot \frac{z \cdot x}{y}} \]

      rational_best-simplify-2 [=>]5.8

      \[ x + \color{blue}{\frac{z \cdot x}{y} \cdot -1} \]

      rational_best-simplify-12 [=>]5.8

      \[ x + \color{blue}{\left(-\frac{z \cdot x}{y}\right)} \]
    4. Taylor expanded in x around 0 2.3

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -20

    1. Initial program 0.2

      \[\frac{x \cdot \left(y - z\right)}{y} \]
    2. Taylor expanded in y around 0 0.1

      \[\leadsto \color{blue}{-1 \cdot \frac{z \cdot x}{y} + x} \]
    3. Simplified0.1

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

      [Start]0.1

      \[ -1 \cdot \frac{z \cdot x}{y} + x \]

      rational_best-simplify-1 [=>]0.1

      \[ \color{blue}{x + -1 \cdot \frac{z \cdot x}{y}} \]

      rational_best-simplify-2 [=>]0.1

      \[ x + \color{blue}{\frac{z \cdot x}{y} \cdot -1} \]

      rational_best-simplify-12 [=>]0.1

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

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

Alternatives

Alternative 1
Error1.9
Cost1480
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ t_1 := \left(1 - \frac{z}{y}\right) \cdot x\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -20:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error19.1
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+37}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 0.00088:\\ \;\;\;\;\frac{z \cdot \left(-x\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error3.2
Cost448
\[\left(1 - \frac{z}{y}\right) \cdot x \]
Alternative 4
Error24.9
Cost64
\[x \]

Error

Reproduce?

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