Average Error: 12.7 → 1.8
Time: 8.3s
Precision: binary64
Cost: 7816
\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{+50}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;t_0 \leq 10^{+294}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \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)))
   (if (<= t_0 2e+50)
     (- x (/ x (/ y z)))
     (if (<= t_0 1e+294) t_0 (fma 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 tmp;
	if (t_0 <= 2e+50) {
		tmp = x - (x / (y / z));
	} else if (t_0 <= 1e+294) {
		tmp = t_0;
	} else {
		tmp = fma(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)
	tmp = 0.0
	if (t_0 <= 2e+50)
		tmp = Float64(x - Float64(x / Float64(y / z)));
	elseif (t_0 <= 1e+294)
		tmp = t_0;
	else
		tmp = fma(x, Float64(Float64(-z) / y), x);
	end
	return 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]}, If[LessEqual[t$95$0, 2e+50], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+294], t$95$0, N[(x * N[((-z) / y), $MachinePrecision] + x), $MachinePrecision]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{+50}:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\

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

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


\end{array}

Error

Target

Original12.7
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 3 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < 2.0000000000000002e50

    1. Initial program 10.4

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

      \[\leadsto \color{blue}{x - \frac{x}{\frac{y}{z}}} \]
      Proof
      (-.f64 x (/.f64 x (/.f64 y z))): 0 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x z) y))): 7 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 z x)) y)): 6 points increase in error, 3 points decrease in error
      (-.f64 x (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 z y) x))): 1 points increase in error, 6 points decrease in error
      (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) (*.f64 (/.f64 z y) x)): 0 points increase in error, 1 points decrease in error
      (-.f64 (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) x) (*.f64 (/.f64 z y) x)): 3 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 x (-.f64 (/.f64 y y) (/.f64 z y)))): 0 points increase in error, 3 points decrease in error
      (*.f64 x (Rewrite<= div-sub_binary64 (/.f64 (-.f64 y z) y))): 3 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 0 points increase in error, 3 points decrease in error

    if 2.0000000000000002e50 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000007e294

    1. Initial program 0.2

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

    if 1.00000000000000007e294 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{-z}{y}, x\right)} \]
      Proof
      (-.f64 x (/.f64 x (/.f64 y z))): 0 points increase in error, 0 points decrease in error
      (-.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x z) y))): 7 points increase in error, 0 points decrease in error
      (-.f64 x (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 z x)) y)): 6 points increase in error, 3 points decrease in error
      (-.f64 x (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 z y) x))): 1 points increase in error, 6 points decrease in error
      (-.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 x)) (*.f64 (/.f64 z y) x)): 0 points increase in error, 1 points decrease in error
      (-.f64 (*.f64 (Rewrite<= *-inverses_binary64 (/.f64 y y)) x) (*.f64 (/.f64 z y) x)): 3 points increase in error, 0 points decrease in error
      (Rewrite=> distribute-rgt-out--_binary64 (*.f64 x (-.f64 (/.f64 y y) (/.f64 z y)))): 0 points increase in error, 3 points decrease in error
      (*.f64 x (Rewrite<= div-sub_binary64 (/.f64 (-.f64 y z) y))): 3 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x (-.f64 y z)) y)): 0 points increase in error, 3 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{+50}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 10^{+294}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.8
Cost1480
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{+50}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;t_0 \leq 10^{+297}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 2
Error20.9
Cost1440
\[\begin{array}{l} t_0 := \left(-x\right) \cdot \frac{z}{y}\\ t_1 := z \cdot \frac{-x}{y}\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+158}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{+141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -0.00018:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -5.3 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-254}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.36 \cdot 10^{-188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-165}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error20.8
Cost1440
\[\begin{array}{l} t_0 := z \cdot \frac{-x}{y}\\ t_1 := \left(-x\right) \cdot \frac{z}{y}\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+158}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{+141}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;y \leq -0.000145:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.2 \cdot 10^{-253}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.2 \cdot 10^{-256}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-189}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-165}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error20.9
Cost1440
\[\begin{array}{l} t_0 := \left(-x\right) \cdot \frac{z}{y}\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+158}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{+141}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;y \leq -0.00027:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -6.7 \cdot 10^{-254}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-297}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-188}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{-166}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error20.8
Cost1440
\[\begin{array}{l} t_0 := \frac{x \cdot \left(-z\right)}{y}\\ t_1 := \left(-x\right) \cdot \frac{z}{y}\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+158}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{+141}:\\ \;\;\;\;\frac{x}{\frac{-y}{z}}\\ \mathbf{elif}\;y \leq -0.000175:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{-285}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-243}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-189}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-166}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+34}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error20.4
Cost1178
\[\begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+158}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -2.45 \cdot 10^{+141} \lor \neg \left(y \leq -0.00021\right) \land \left(y \leq 1.3 \cdot 10^{-188} \lor \neg \left(y \leq 1.65 \cdot 10^{-165}\right) \land y \leq 7.4 \cdot 10^{+37}\right):\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error3.2
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -8.5 \cdot 10^{+37} \lor \neg \left(y \leq -1.4 \cdot 10^{-253}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 8
Error8.1
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.85 \cdot 10^{+218}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+190}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error25.3
Cost64
\[x \]

Error

Reproduce

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