?

Average Accuracy: 80.0% → 99.3%
Time: 6.8s
Precision: binary64
Cost: 8332

?

\[\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 -\infty:\\ \;\;\;\;x - x \cdot \frac{z}{y}\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+34}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \mathbf{elif}\;t_0 \leq 9.08 \cdot 10^{+271}:\\ \;\;\;\;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 (- y z)) y)))
   (if (<= t_0 (- INFINITY))
     (- x (* x (/ z y)))
     (if (<= t_0 -1e-78)
       t_0
       (if (<= t_0 2e+34)
         (fma x (/ (- z) y) x)
         (if (<= t_0 9.08e+271) 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 * (y - z)) / y;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = x - (x * (z / y));
	} else if (t_0 <= -1e-78) {
		tmp = t_0;
	} else if (t_0 <= 2e+34) {
		tmp = fma(x, (-z / y), x);
	} else if (t_0 <= 9.08e+271) {
		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(Float64(x * Float64(y - z)) / y)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(x - Float64(x * Float64(z / y)));
	elseif (t_0 <= -1e-78)
		tmp = t_0;
	elseif (t_0 <= 2e+34)
		tmp = fma(x, Float64(Float64(-z) / y), x);
	elseif (t_0 <= 9.08e+271)
		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[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -1e-78], t$95$0, If[LessEqual[t$95$0, 2e+34], N[(x * N[((-z) / y), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$0, 9.08e+271], 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 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;x - x \cdot \frac{z}{y}\\

\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-78}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;t_0 \leq 9.08 \cdot 10^{+271}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original80.0%
Target94.7%
Herbie99.3%
\[\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 0.0%

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

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

      [Start]0.0

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

      associate-*r/ [<=]99.9

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

      div-sub [=>]99.9

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

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

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

      *-inverses [=>]99.9

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

      *-lft-identity [=>]99.9

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

      associate-*l/ [=>]66.2

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

      *-commutative [<=]66.2

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

      associate-/l* [=>]99.9

      \[ x - \color{blue}{\frac{x}{\frac{y}{z}}} \]
    3. Applied egg-rr99.9%

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

      [Start]99.9

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

      associate-/l* [<=]66.2

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

      *-commutative [=>]66.2

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

      associate-*l/ [<=]99.9

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -9.99999999999999999e-79 or 1.99999999999999989e34 < (/.f64 (*.f64 x (-.f64 y z)) y) < 9.0800000000000003e271

    1. Initial program 99.5%

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

    if -9.99999999999999999e-79 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.99999999999999989e34

    1. Initial program 88.6%

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

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

      [Start]88.6

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

      *-commutative [=>]88.6

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

      associate-*l/ [<=]99.8

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

      div-sub [=>]99.8

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

      sub-neg [=>]99.8

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

      +-commutative [=>]99.8

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

      *-inverses [=>]99.8

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

      distribute-lft1-in [<=]99.8

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

      *-commutative [=>]99.8

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

      fma-def [=>]99.8

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

      distribute-neg-frac [=>]99.8

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

    if 9.0800000000000003e271 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 20.7%

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

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

      [Start]20.7

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

      associate-*r/ [<=]96.0

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

      div-sub [=>]96.0

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

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

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

      *-inverses [=>]96.0

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

      *-lft-identity [=>]96.0

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

      associate-*l/ [=>]76.2

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

      *-commutative [<=]76.2

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

      associate-/l* [=>]96.1

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

    \[\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 -1 \cdot 10^{-78}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 2 \cdot 10^{+34}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-z}{y}, x\right)\\ \mathbf{elif}\;\frac{x \cdot \left(y - z\right)}{y} \leq 9.08 \cdot 10^{+271}:\\ \;\;\;\;\frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.3%
Cost2512
\[\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 -1 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 9.08 \cdot 10^{+271}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 2
Accuracy68.2%
Cost1444
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+80} \lor \neg \left(z \leq -0.1\right) \land \left(z \leq -2.6 \cdot 10^{-30} \lor \neg \left(z \leq 1.02 \cdot 10^{-117}\right) \land \left(z \leq 2 \cdot 10^{-94} \lor \neg \left(z \leq 1.05 \cdot 10^{+77}\right) \land \left(z \leq 1.5 \cdot 10^{+96} \lor \neg \left(z \leq 1.75 \cdot 10^{+167}\right)\right)\right)\right):\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy68.1%
Cost1440
\[\begin{array}{l} t_0 := z \cdot \left(-\frac{x}{y}\right)\\ t_1 := x \cdot \frac{-z}{y}\\ \mathbf{if}\;z \leq -5.5 \cdot 10^{+78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -46:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{-117}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+74}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.3 \cdot 10^{+168}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy67.9%
Cost1440
\[\begin{array}{l} t_0 := \frac{x \cdot \left(-z\right)}{y}\\ t_1 := x \cdot \frac{-z}{y}\\ \mathbf{if}\;z \leq -9 \cdot 10^{+79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -0.15:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-30}:\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{-117}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.85 \cdot 10^{+75}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.15 \cdot 10^{+92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{+167}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy87.5%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.4 \cdot 10^{+203}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+124}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Accuracy94.8%
Cost448
\[x - x \cdot \frac{z}{y} \]
Alternative 7
Accuracy95.2%
Cost448
\[x - \frac{x}{\frac{y}{z}} \]
Alternative 8
Accuracy59.4%
Cost64
\[x \]

Error

Reproduce?

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