?

Average Accuracy: 83.2% → 99.1%
Time: 8.5s
Precision: binary64
Cost: 7112

?

\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{+134}:\\ \;\;\;\;\frac{x}{\frac{z}{y}} - x\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-27}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, x\right)}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -5e+134)
   (- (/ x (/ z y)) x)
   (if (<= z 5e-27) (- (/ (fma x y x) z) x) (/ x (/ z (+ (- y z) 1.0))))))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -5e+134) {
		tmp = (x / (z / y)) - x;
	} else if (z <= 5e-27) {
		tmp = (fma(x, y, x) / z) - x;
	} else {
		tmp = x / (z / ((y - z) + 1.0));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z)
end
function code(x, y, z)
	tmp = 0.0
	if (z <= -5e+134)
		tmp = Float64(Float64(x / Float64(z / y)) - x);
	elseif (z <= 5e-27)
		tmp = Float64(Float64(fma(x, y, x) / z) - x);
	else
		tmp = Float64(x / Float64(z / Float64(Float64(y - z) + 1.0)));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, -5e+134], N[(N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[z, 5e-27], N[(N[(N[(x * y + x), $MachinePrecision] / z), $MachinePrecision] - x), $MachinePrecision], N[(x / N[(z / N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+134}:\\
\;\;\;\;\frac{x}{\frac{z}{y}} - x\\

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

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\


\end{array}

Error?

Target

Original83.2%
Target99.2%
Herbie99.1%
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -4.99999999999999981e134

    1. Initial program 62.3%

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

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

      [Start]62.3

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

      associate-*r/ [<=]99.9

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

      +-commutative [=>]99.9

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

      associate-+r- [=>]99.9

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

      div-sub [=>]99.9

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

      *-inverses [=>]99.9

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

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

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

      *-lft-identity [=>]99.9

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

      *-commutative [=>]99.9

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

      associate-*r/ [=>]87.8

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

      *-commutative [=>]87.8

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

      +-commutative [=>]87.8

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

      distribute-lft1-in [<=]87.8

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

      *-commutative [=>]87.8

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

      fma-def [=>]87.8

      \[ \frac{\color{blue}{\mathsf{fma}\left(x, y, x\right)}}{z} - x \]
    3. Taylor expanded in y around inf 87.8%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    4. Simplified95.9%

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

      [Start]87.8

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

      associate-/l* [=>]95.9

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

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

      [Start]95.9

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

      associate-/r/ [=>]99.9

      \[ \color{blue}{\frac{y}{z} \cdot x} - x \]
    6. Taylor expanded in y around 0 87.8%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} - x \]
    7. Simplified99.9%

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

      [Start]87.8

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

      *-commutative [=>]87.8

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

      associate-/l* [=>]99.9

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

    if -4.99999999999999981e134 < z < 5.0000000000000002e-27

    1. Initial program 96.5%

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

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

      [Start]96.5

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

      associate-*r/ [<=]88.7

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

      +-commutative [=>]88.7

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

      associate-+r- [=>]88.7

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

      div-sub [=>]88.7

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

      *-inverses [=>]88.7

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

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

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

      *-lft-identity [=>]88.8

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

      *-commutative [=>]88.8

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

      associate-*r/ [=>]98.3

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

      *-commutative [=>]98.3

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

      +-commutative [=>]98.3

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

      distribute-lft1-in [<=]98.3

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

      *-commutative [=>]98.3

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

      fma-def [=>]98.3

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

    if 5.0000000000000002e-27 < z

    1. Initial program 74.2%

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

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

      [Start]74.2

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

      associate-/l* [=>]99.9

      \[ \color{blue}{\frac{x}{\frac{z}{\left(y - z\right) + 1}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.1%

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

Alternatives

Alternative 1
Accuracy99.8%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -5 \cdot 10^{-17} \lor \neg \left(z \leq 7.7 \cdot 10^{-28}\right):\\ \;\;\;\;\frac{x}{\frac{z}{\left(y - z\right) + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z}\\ \end{array} \]
Alternative 2
Accuracy99.8%
Cost840
\[\begin{array}{l} t_0 := \left(y - z\right) + 1\\ \mathbf{if}\;z \leq -3.6 \cdot 10^{+39}:\\ \;\;\;\;\frac{x}{\frac{z}{y}} - x\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-27}:\\ \;\;\;\;\frac{x \cdot t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{t_0}}\\ \end{array} \]
Alternative 3
Accuracy67.7%
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -3700000000000:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -1.32 \cdot 10^{-204}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-258}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 4
Accuracy93.4%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;x \cdot \frac{y}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
Alternative 5
Accuracy93.8%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
Alternative 6
Accuracy96.2%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;\frac{y}{\frac{z}{x}} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
Alternative 7
Accuracy98.3%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -3700000000000 \lor \neg \left(z \leq 0.0018\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + 1\right)}{z}\\ \end{array} \]
Alternative 8
Accuracy82.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.6 \cdot 10^{+59} \lor \neg \left(y \leq 3.4 \cdot 10^{+16}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{z} - x\\ \end{array} \]
Alternative 9
Accuracy69.5%
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -3700000000000:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 10
Accuracy47.5%
Cost128
\[-x \]

Error

Reproduce?

herbie shell --seed 2023138 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

  (/ (* x (+ (- y z) 1.0)) z))