?

Average Error: 19.84% → 0.81%
Time: 6.7s
Precision: binary64
Cost: 8332

?

\[\frac{x \cdot \left(y - z\right)}{y} \]
\[\begin{array}{l} t_0 := x - \frac{x \cdot z}{y}\\ t_1 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\frac{y - z}{\frac{y}{x}}\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{+18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-121}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \mathbf{elif}\;t_1 \leq 10^{+258}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- x (/ (* x z) y))) (t_1 (/ (* x (- y z)) y)))
   (if (<= t_1 (- INFINITY))
     (/ (- y z) (/ y x))
     (if (<= t_1 -2e+18)
       t_0
       (if (<= t_1 2e-121)
         (fma x (/ (- z) y) x)
         (if (<= t_1 1e+258) t_0 (- x (/ x (/ y z)))))))))
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 - ((x * z) / y);
	double t_1 = (x * (y - z)) / y;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (y - z) / (y / x);
	} else if (t_1 <= -2e+18) {
		tmp = t_0;
	} else if (t_1 <= 2e-121) {
		tmp = fma(x, (-z / y), x);
	} else if (t_1 <= 1e+258) {
		tmp = t_0;
	} else {
		tmp = x - (x / (y / z));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(y - z)) / y)
end
function code(x, y, z)
	t_0 = Float64(x - Float64(Float64(x * z) / y))
	t_1 = Float64(Float64(x * Float64(y - z)) / y)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(y - z) / Float64(y / x));
	elseif (t_1 <= -2e+18)
		tmp = t_0;
	elseif (t_1 <= 2e-121)
		tmp = fma(x, Float64(Float64(-z) / y), x);
	elseif (t_1 <= 1e+258)
		tmp = t_0;
	else
		tmp = Float64(x - Float64(x / Float64(y / z)));
	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[(x - N[(N[(x * z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(y - z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e+18], t$95$0, If[LessEqual[t$95$1, 2e-121], N[(x * N[((-z) / y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 1e+258], t$95$0, N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := x - \frac{x \cdot z}{y}\\
t_1 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{y - z}{\frac{y}{x}}\\

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

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-121}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\

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

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


\end{array}

Error?

Target

Original19.84%
Target4.91%
Herbie0.81%
\[\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 4 regimes
  2. if (/.f64 (*.f64 x (-.f64 y z)) y) < -inf.0

    1. Initial program 100

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

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

      [Start]100

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

      *-commutative [=>]100

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

      associate-/l* [=>]0.21

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -2e18 or 2e-121 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.00000000000000006e258

    1. Initial program 0.49

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

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

      [Start]0.49

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

      associate-*r/ [<=]8.96

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

      div-sub [=>]8.95

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

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

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

      *-inverses [=>]8.94

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

      *-lft-identity [=>]8.94

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

      associate-*l/ [=>]0.36

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

      *-commutative [<=]0.36

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

      associate-/l* [=>]8.36

      \[ x - \color{blue}{\frac{x}{\frac{y}{z}}} \]
    3. Taylor expanded in x around 0 0.36

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

    if -2e18 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2e-121

    1. Initial program 12.21

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

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

      [Start]12.21

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

      *-commutative [=>]12.21

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

      associate-*l/ [<=]0.17

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

      div-sub [=>]0.17

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

      sub-neg [=>]0.17

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

      +-commutative [=>]0.17

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

      *-inverses [=>]0.17

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

      distribute-lft1-in [<=]0.15

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

      *-commutative [=>]0.15

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

      fma-def [=>]0.15

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

      distribute-neg-frac [=>]0.15

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

    if 1.00000000000000006e258 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 76.22

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

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

      [Start]76.22

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

      associate-*r/ [<=]5.95

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

      div-sub [=>]5.95

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

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

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

      *-inverses [=>]5.94

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

      *-lft-identity [=>]5.94

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

      associate-*l/ [=>]26.21

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

      *-commutative [<=]26.21

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

      associate-/l* [=>]5.83

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

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

Alternatives

Alternative 1
Error0.87%
Cost2513
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+18} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 10^{+258}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 2
Error0.86%
Cost2513
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\frac{y - z}{\frac{y}{x}}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{+18} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 10^{+258}:\\ \;\;\;\;x - \frac{x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 3
Error5.05%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-15} \lor \neg \left(y \leq 4 \cdot 10^{-198}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 4
Error12.3%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{+171}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5.2 \cdot 10^{+192}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error29.81%
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -3950000 \lor \neg \left(z \leq 2.36 \cdot 10^{+58}\right):\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error29.84%
Cost648
\[\begin{array}{l} \mathbf{if}\;z \leq -1050000:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+58}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \end{array} \]
Alternative 7
Error39.63%
Cost64
\[x \]

Error

Reproduce?

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