?

Average Accuracy: 80.1% → 99.5%
Time: 8.5s
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 -\infty:\\ \;\;\;\;\mathsf{fma}\left(x, -\frac{z}{y}, x\right)\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{+80} \lor \neg \left(t_0 \leq 2 \cdot 10^{-48}\right) \land t_0 \leq 5 \cdot 10^{+304}:\\ \;\;\;\;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))
     (fma x (- (/ z y)) x)
     (if (or (<= t_0 -5e+80) (and (not (<= t_0 2e-48)) (<= t_0 5e+304)))
       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 = fma(x, -(z / y), x);
	} else if ((t_0 <= -5e+80) || (!(t_0 <= 2e-48) && (t_0 <= 5e+304))) {
		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 = fma(x, Float64(-Float64(z / y)), x);
	elseif ((t_0 <= -5e+80) || (!(t_0 <= 2e-48) && (t_0 <= 5e+304)))
		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[(z / y), $MachinePrecision]) + x), $MachinePrecision], If[Or[LessEqual[t$95$0, -5e+80], And[N[Not[LessEqual[t$95$0, 2e-48]], $MachinePrecision], LessEqual[t$95$0, 5e+304]]], 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:\\
\;\;\;\;\mathsf{fma}\left(x, -\frac{z}{y}, x\right)\\

\mathbf{elif}\;t_0 \leq -5 \cdot 10^{+80} \lor \neg \left(t_0 \leq 2 \cdot 10^{-48}\right) \land t_0 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original80.1%
Target95.2%
Herbie99.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

    1. Initial program 0.0%

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

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

      [Start]0.0

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

      *-commutative [=>]0.0

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

      associate-*l/ [<=]99.9

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

      div-sub [=>]99.9

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

      sub-neg [=>]99.9

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

      +-commutative [=>]99.9

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

      *-inverses [=>]99.9

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

      distribute-lft1-in [<=]99.9

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

      *-commutative [=>]99.9

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

      fma-def [=>]99.9

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

      distribute-neg-frac [=>]99.9

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

    if -inf.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < -4.99999999999999961e80 or 1.9999999999999999e-48 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.9999999999999997e304

    1. Initial program 99.6%

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

    if -4.99999999999999961e80 < (/.f64 (*.f64 x (-.f64 y z)) y) < 1.9999999999999999e-48 or 4.9999999999999997e304 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 77.1%

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

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

      [Start]77.1

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

      associate-*r/ [<=]99.2

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

      div-sub [=>]99.3

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

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

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

      *-inverses [=>]99.3

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

      *-lft-identity [=>]99.3

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

      associate-*l/ [=>]90.5

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

      *-commutative [<=]90.5

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

      associate-/l* [=>]99.3

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

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

Alternatives

Alternative 1
Accuracy99.5%
Cost2514
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq -5 \cdot 10^{+80}\right) \land \left(t_0 \leq 2 \cdot 10^{-48} \lor \neg \left(t_0 \leq 5 \cdot 10^{+304}\right)\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy68.9%
Cost1044
\[\begin{array}{l} t_0 := x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{if}\;y \leq -1.65 \cdot 10^{+88}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-55}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-193}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-109}:\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Accuracy69.2%
Cost1044
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+88}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{+81}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-55}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-203}:\\ \;\;\;\;\frac{x}{-\frac{y}{z}}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{-109}:\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Accuracy69.5%
Cost1044
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+88}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{+81}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -3.8 \cdot 10^{-55}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-226}:\\ \;\;\;\;\frac{x}{-\frac{y}{z}}\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{-109}:\\ \;\;\;\;\frac{-z}{\frac{y}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Accuracy95.3%
Cost977
\[\begin{array}{l} t_0 := x - \frac{x}{\frac{y}{z}}\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{-280}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{-272}:\\ \;\;\;\;\frac{-x \cdot z}{y}\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-202} \lor \neg \left(y \leq 1.7 \cdot 10^{-41}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \end{array} \]
Alternative 6
Accuracy87.7%
Cost976
\[\begin{array}{l} t_0 := \left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{+140}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.2 \cdot 10^{-221}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{-227}:\\ \;\;\;\;\frac{-x \cdot z}{y}\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+93}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy68.7%
Cost914
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{-33} \lor \neg \left(z \leq 2.3 \cdot 10^{-66} \lor \neg \left(z \leq 2.6 \cdot 10^{-30}\right) \land z \leq 1.1 \cdot 10^{+129}\right):\\ \;\;\;\;z \cdot \left(-\frac{x}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Accuracy70.4%
Cost912
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{+88}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{+81}:\\ \;\;\;\;x \cdot \left(-\frac{z}{y}\right)\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{-55}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-109}:\\ \;\;\;\;\frac{-x \cdot z}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Accuracy60.6%
Cost64
\[x \]

Error

Reproduce?

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