?

Average Accuracy: 100.0% → 100.0%
Time: 12.7s
Precision: binary64
Cost: 7104

?

\[ \begin{array}{c}[d2, d4] = \mathsf{sort}([d2, d4])\\ \end{array} \]
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
\[\mathsf{fma}\left(d2, d1, d1 \cdot \left(d4 - d3\right)\right) - d1 \cdot d1 \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (fma d2 d1 (* d1 (- d4 d3))) (* d1 d1)))
double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
double code(double d1, double d2, double d3, double d4) {
	return fma(d2, d1, (d1 * (d4 - d3))) - (d1 * d1);
}
function code(d1, d2, d3, d4)
	return Float64(Float64(Float64(Float64(d1 * d2) - Float64(d1 * d3)) + Float64(d4 * d1)) - Float64(d1 * d1))
end
function code(d1, d2, d3, d4)
	return Float64(fma(d2, d1, Float64(d1 * Float64(d4 - d3))) - Float64(d1 * d1))
end
code[d1_, d2_, d3_, d4_] := N[(N[(N[(N[(d1 * d2), $MachinePrecision] - N[(d1 * d3), $MachinePrecision]), $MachinePrecision] + N[(d4 * d1), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
code[d1_, d2_, d3_, d4_] := N[(N[(d2 * d1 + N[(d1 * N[(d4 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(d1 * d1), $MachinePrecision]), $MachinePrecision]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d2, d1, d1 \cdot \left(d4 - d3\right)\right) - d1 \cdot d1

Error?

Target

Original100.0%
Target100.0%
Herbie100.0%
\[d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \]

Derivation?

  1. Initial program 100.0%

    \[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
  2. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(d2, d1, -d1 \cdot \left(d3 - d4\right)\right)} - d1 \cdot d1 \]
    Proof

    [Start]100.0

    \[ \left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]

    associate-+l- [=>]100.0

    \[ \color{blue}{\left(d1 \cdot d2 - \left(d1 \cdot d3 - d4 \cdot d1\right)\right)} - d1 \cdot d1 \]

    *-commutative [=>]100.0

    \[ \left(\color{blue}{d2 \cdot d1} - \left(d1 \cdot d3 - d4 \cdot d1\right)\right) - d1 \cdot d1 \]

    fma-neg [=>]100.0

    \[ \color{blue}{\mathsf{fma}\left(d2, d1, -\left(d1 \cdot d3 - d4 \cdot d1\right)\right)} - d1 \cdot d1 \]

    *-commutative [=>]100.0

    \[ \mathsf{fma}\left(d2, d1, -\left(d1 \cdot d3 - \color{blue}{d1 \cdot d4}\right)\right) - d1 \cdot d1 \]

    distribute-lft-out-- [=>]100.0

    \[ \mathsf{fma}\left(d2, d1, -\color{blue}{d1 \cdot \left(d3 - d4\right)}\right) - d1 \cdot d1 \]
  3. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(d2, d1, d1 \cdot \left(d4 - d3\right)\right) - d1 \cdot d1 \]

Alternatives

Alternative 1
Accuracy52.9%
Cost1313
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d2 \leq -1.1 \cdot 10^{+102}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d2 \leq -0.03:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -8.8 \cdot 10^{-52}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -1.5 \cdot 10^{-86}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -4.6 \cdot 10^{-126}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{elif}\;d2 \leq -3 \cdot 10^{-306} \lor \neg \left(d2 \leq 8 \cdot 10^{-140}\right) \land d2 \leq 1.5 \cdot 10^{-67}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 2
Accuracy78.7%
Cost1308
\[\begin{array}{l} t_0 := d1 \cdot \left(d4 - d1\right)\\ t_1 := d1 \cdot \left(d4 - d3\right)\\ \mathbf{if}\;d2 \leq -1.15 \cdot 10^{+70}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -1.55 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -1.55 \cdot 10^{-16}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d2 \leq -4.9 \cdot 10^{-52}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -5.4 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -3.3 \cdot 10^{-127}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -1.75 \cdot 10^{-134}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy78.5%
Cost1244
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(d4 - d1\right)\\ t_2 := d1 \cdot \left(d4 - d3\right)\\ \mathbf{if}\;d2 \leq -1.28 \cdot 10^{+70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -1.55 \cdot 10^{-13}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d2 \leq -1.22 \cdot 10^{-16}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d2 \leq -7.6 \cdot 10^{-51}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -5.4 \cdot 10^{-82}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d2 \leq -3 \cdot 10^{-127}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -1.9 \cdot 10^{-134}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy65.6%
Cost980
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d4 \leq 1.9 \cdot 10^{-289}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 2.5 \cdot 10^{-235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.4 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 1.12 \cdot 10^{-13}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
Alternative 5
Accuracy76.7%
Cost716
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 3 \cdot 10^{-131}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.2 \cdot 10^{-95}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 4.2 \cdot 10^{+81}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
Alternative 6
Accuracy52.5%
Cost588
\[\begin{array}{l} \mathbf{if}\;d4 \leq 3.1 \cdot 10^{-137}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{elif}\;d4 \leq 2.3 \cdot 10^{-70}:\\ \;\;\;\;-d1 \cdot d1\\ \mathbf{elif}\;d4 \leq 15000000000000:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 7
Accuracy72.2%
Cost585
\[\begin{array}{l} \mathbf{if}\;d3 \leq -4.1 \cdot 10^{+133} \lor \neg \left(d3 \leq 2.2 \cdot 10^{+95}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
Alternative 8
Accuracy90.5%
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -8.5 \cdot 10^{+102}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\ \end{array} \]
Alternative 9
Accuracy95.6%
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -3.3 \cdot 10^{+44}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\ \end{array} \]
Alternative 10
Accuracy95.3%
Cost580
\[\begin{array}{l} \mathbf{if}\;d4 \leq 2.65 \cdot 10^{-71}:\\ \;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \end{array} \]
Alternative 11
Accuracy100.0%
Cost576
\[d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right) \]
Alternative 12
Accuracy51.7%
Cost324
\[\begin{array}{l} \mathbf{if}\;d2 \leq -9 \cdot 10^{+69}:\\ \;\;\;\;d2 \cdot d1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 13
Accuracy32.0%
Cost192
\[d1 \cdot d4 \]

Error

Reproduce?

herbie shell --seed 2023133 
(FPCore (d1 d2 d3 d4)
  :name "FastMath dist4"
  :precision binary64

  :herbie-target
  (* d1 (- (+ (- d2 d3) d4) d1))

  (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))