?

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

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{+80}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 10^{-108}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.3
Target3.3
Herbie0.5
\[\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 -2e80 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000004e-108

    1. Initial program 14.9

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

      \[\leadsto \color{blue}{x - \frac{x}{\frac{y}{z}}} \]
      Proof

      [Start]14.9

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

      associate-*r/ [<=]0.5

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

      div-sub [=>]0.5

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

      distribute-rgt-out-- [<=]0.5

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

      *-inverses [=>]0.5

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

      *-lft-identity [=>]0.5

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

      associate-*l/ [=>]5.8

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

      *-commutative [<=]5.8

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

      associate-/l* [=>]0.4

      \[ x - \color{blue}{\frac{x}{\frac{y}{z}}} \]
    3. Applied egg-rr0.5

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -2e80 or 1.00000000000000004e-108 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2.0000000000000001e299

    1. Initial program 0.3

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

    if 2.0000000000000001e299 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 60.2

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

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

      [Start]60.2

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

      *-commutative [=>]60.2

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

      associate-*r/ [<=]1.9

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

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

Alternatives

Alternative 1
Error7.6
Cost976
\[\begin{array}{l} t_0 := \left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{+127}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.1 \cdot 10^{-304}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.28 \cdot 10^{-256}:\\ \;\;\;\;\frac{x \cdot \left(-z\right)}{y}\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{+146}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error18.6
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -28000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-96}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-84}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+82}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error18.6
Cost912
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;z \leq -480:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-96}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-84}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+82}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error3.1
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -3.1 \cdot 10^{-198} \lor \neg \left(y \leq 1.2 \cdot 10^{-159}\right):\\ \;\;\;\;x - x \cdot \frac{z}{y}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 5
Error2.9
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.18 \cdot 10^{-198} \lor \neg \left(y \leq 1.06 \cdot 10^{-159}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 6
Error18.4
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -23000 \lor \neg \left(z \leq 1.8 \cdot 10^{+83}\right):\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error25.7
Cost64
\[x \]

Error

Reproduce?

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