?

Average Error: 19.37% → 2.94%
Time: 6.0s
Precision: binary64
Cost: 7300

?

\[\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 5 \cdot 10^{+21}:\\ \;\;\;\;\mathsf{fma}\left(x, -\frac{z}{y}, x\right)\\ \mathbf{elif}\;t_0 \leq 10^{+304}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{y - 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)))
   (if (<= t_0 5e+21)
     (fma x (- (/ z y)) x)
     (if (<= t_0 1e+304) t_0 (/ (- y 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 <= 5e+21) {
		tmp = fma(x, -(z / y), x);
	} else if (t_0 <= 1e+304) {
		tmp = t_0;
	} else {
		tmp = (y - 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 <= 5e+21)
		tmp = fma(x, Float64(-Float64(z / y)), x);
	elseif (t_0 <= 1e+304)
		tmp = t_0;
	else
		tmp = Float64(Float64(y - z) / Float64(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, 5e+21], N[(x * (-N[(z / y), $MachinePrecision]) + x), $MachinePrecision], If[LessEqual[t$95$0, 1e+304], t$95$0, N[(N[(y - z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $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 5 \cdot 10^{+21}:\\
\;\;\;\;\mathsf{fma}\left(x, -\frac{z}{y}, x\right)\\

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

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


\end{array}

Error?

Target

Original19.37%
Target4.91%
Herbie2.94%
\[\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) < 5e21

    1. Initial program 16.22

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

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

      [Start]16.22

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

      *-commutative [=>]16.22

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

      associate-*l/ [<=]3.83

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

      div-sub [=>]3.82

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

      sub-neg [=>]3.82

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

      +-commutative [=>]3.82

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

      *-inverses [=>]3.82

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

      distribute-lft1-in [<=]3.81

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

      *-commutative [=>]3.81

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

      fma-def [=>]3.81

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

      distribute-neg-frac [=>]3.81

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

    if 5e21 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.9999999999999994e303

    1. Initial program 0.32

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

    if 9.9999999999999994e303 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 97.19

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

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

      [Start]97.19

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

      *-commutative [=>]97.19

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

      associate-/l* [=>]0.95

      \[ \color{blue}{\frac{y - z}{\frac{y}{x}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.94

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

Alternatives

Alternative 1
Error3.4%
Cost1481
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{+138} \lor \neg \left(t_0 \leq 5 \cdot 10^{+303}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error3.35%
Cost1480
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{+138}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;t_0 \leq 10^{+304}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{y - z}{\frac{y}{x}}\\ \end{array} \]
Alternative 3
Error32.19%
Cost1176
\[\begin{array}{l} t_0 := \left(-z\right) \cdot \frac{x}{y}\\ t_1 := \frac{x}{-\frac{y}{z}}\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{+132}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{+84}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -4.6 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3 \cdot 10^{-304}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.98 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-28}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error29.41%
Cost914
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+80} \lor \neg \left(z \leq -1.62 \cdot 10^{+63}\right) \land \left(z \leq -2300000000 \lor \neg \left(z \leq 4.3 \cdot 10^{+16}\right)\right):\\ \;\;\;\;\left(-z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error30.76%
Cost913
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{+80}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;z \leq -5.1 \cdot 10^{+62}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2300000000 \lor \neg \left(z \leq 1.02 \cdot 10^{+15}\right):\\ \;\;\;\;\left(-z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error30.7%
Cost912
\[\begin{array}{l} \mathbf{if}\;z \leq -8.2 \cdot 10^{+80}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;z \leq -1.42 \cdot 10^{+63}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2300000000:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 2.75 \cdot 10^{+16}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 7
Error30.89%
Cost912
\[\begin{array}{l} \mathbf{if}\;z \leq -8.2 \cdot 10^{+80}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;z \leq -1.25 \cdot 10^{+63}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -2300000000:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+98}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-x \cdot z}{y}\\ \end{array} \]
Alternative 8
Error5.83%
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 4.4 \cdot 10^{+191}:\\ \;\;\;\;x \cdot \left(1 - \frac{z}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-x \cdot z}{y}\\ \end{array} \]
Alternative 9
Error5.45%
Cost580
\[\begin{array}{l} \mathbf{if}\;z \leq 3.1 \cdot 10^{+190}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-x \cdot z}{y}\\ \end{array} \]
Alternative 10
Error40.14%
Cost64
\[x \]

Error

Reproduce?

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