?

Average Error: 19.35% → 3.29%
Time: 5.0s
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 -1 \cdot 10^{+35}:\\ \;\;\;\;\frac{y - z}{\frac{y}{x}}\\ \mathbf{elif}\;t_0 \leq 50000000:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;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 -1e+35)
     (/ (- y z) (/ y x))
     (if (<= t_0 50000000.0)
       (- x (/ x (/ y z)))
       (if (<= t_0 2e+251) 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 <= -1e+35) {
		tmp = (y - z) / (y / x);
	} else if (t_0 <= 50000000.0) {
		tmp = x - (x / (y / z));
	} else if (t_0 <= 2e+251) {
		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 <= -1e+35)
		tmp = Float64(Float64(y - z) / Float64(y / x));
	elseif (t_0 <= 50000000.0)
		tmp = Float64(x - Float64(x / Float64(y / z)));
	elseif (t_0 <= 2e+251)
		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, -1e+35], N[(N[(y - z), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 50000000.0], N[(x - N[(x / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+251], 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 -1 \cdot 10^{+35}:\\
\;\;\;\;\frac{y - z}{\frac{y}{x}}\\

\mathbf{elif}\;t_0 \leq 50000000:\\
\;\;\;\;x - \frac{x}{\frac{y}{z}}\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+251}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

Original19.35%
Target5.07%
Herbie3.29%
\[\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) < -9.9999999999999997e34

    1. Initial program 28.61

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

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

      [Start]28.61

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

      *-commutative [=>]28.61

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

      associate-/l* [=>]9.68

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

    if -9.9999999999999997e34 < (/.f64 (*.f64 x (-.f64 y z)) y) < 5e7

    1. Initial program 9.04

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

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

      [Start]9.04

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

      associate-*r/ [<=]0.32

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

      div-sub [=>]0.31

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

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

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

      *-inverses [=>]0.3

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

      *-lft-identity [=>]0.3

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

      associate-*l/ [=>]4.99

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

      *-commutative [<=]4.99

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

      associate-/l* [=>]0.2

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

    if 5e7 < (/.f64 (*.f64 x (-.f64 y z)) y) < 2.0000000000000001e251

    1. Initial program 0.34

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

    if 2.0000000000000001e251 < (/.f64 (*.f64 x (-.f64 y z)) y)

    1. Initial program 72.17

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

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

      [Start]72.17

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

      *-commutative [=>]72.17

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

      associate-*l/ [<=]6.1

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

      div-sub [=>]6.09

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

      sub-neg [=>]6.09

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

      +-commutative [=>]6.09

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

      *-inverses [=>]6.09

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

      distribute-lft1-in [<=]6.09

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

      *-commutative [=>]6.09

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

      fma-def [=>]6.08

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

      distribute-neg-frac [=>]6.08

      \[ \mathsf{fma}\left(x, \color{blue}{\frac{-z}{y}}, x\right) \]
  3. Recombined 4 regimes into one program.
  4. Final simplification3.29

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

Alternatives

Alternative 1
Error3.44%
Cost1997
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+35}:\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{elif}\;t_0 \leq 50000000 \lor \neg \left(t_0 \leq 5 \cdot 10^{+262}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error3.14%
Cost1997
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y - z\right)}{y}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+35}:\\ \;\;\;\;\frac{y - z}{\frac{y}{x}}\\ \mathbf{elif}\;t_0 \leq 50000000 \lor \neg \left(t_0 \leq 5 \cdot 10^{+262}\right):\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error32.57%
Cost913
\[\begin{array}{l} \mathbf{if}\;y \leq -1.38 \cdot 10^{+44}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -5.6 \cdot 10^{-150} \lor \neg \left(y \leq -3.4 \cdot 10^{-209}\right) \land y \leq 1.45 \cdot 10^{-43}:\\ \;\;\;\;z \cdot \frac{-x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error15.66%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{-119} \lor \neg \left(z \leq 5.4 \cdot 10^{-168}\right):\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error6.09%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -820000000000 \lor \neg \left(z \leq 3.6 \cdot 10^{+47}\right):\\ \;\;\;\;\left(y - z\right) \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{x}{\frac{y}{z}}\\ \end{array} \]
Alternative 6
Error40.21%
Cost64
\[x \]

Error

Reproduce?

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