?

Average Accuracy: 100.0% → 100.0%
Time: 10.4s
Precision: binary64
Cost: 6976

?

\[ \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(d1, d4 - d1, d1 \cdot \left(d2 - d3\right)\right) \]
(FPCore (d1 d2 d3 d4)
 :precision binary64
 (- (+ (- (* d1 d2) (* d1 d3)) (* d4 d1)) (* d1 d1)))
(FPCore (d1 d2 d3 d4) :precision binary64 (fma d1 (- d4 d1) (* d1 (- d2 d3))))
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(d1, (d4 - d1), (d1 * (d2 - d3)));
}
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 fma(d1, Float64(d4 - d1), Float64(d1 * Float64(d2 - d3)))
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[(d1 * N[(d4 - d1), $MachinePrecision] + N[(d1 * N[(d2 - d3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d1, d4 - d1, d1 \cdot \left(d2 - d3\right)\right)

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. Simplified100.0%

    \[\leadsto \color{blue}{d1 \cdot \left(d2 - d3\right) + \left(d1 \cdot d4 - d1 \cdot d1\right)} \]
    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 - d1 \cdot d3\right) + \left(d4 \cdot d1 - d1 \cdot d1\right)} \]

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

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

    *-commutative [=>]100.0

    \[ d1 \cdot \left(d2 - d3\right) + \left(\color{blue}{d1 \cdot d4} - d1 \cdot d1\right) \]
  3. Applied egg-rr100.0%

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

    [Start]100.0

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

    +-commutative [=>]100.0

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

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

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

    fma-def [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy55.9%
Cost1048
\[\begin{array}{l} t_0 := d3 \cdot \left(-d1\right)\\ \mathbf{if}\;d4 \leq -4.7 \cdot 10^{-171}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq -1.8 \cdot 10^{-235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 8.8 \cdot 10^{-254}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 10^{-153}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 2.25 \cdot 10^{-129}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 9 \cdot 10^{+61}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 2
Accuracy77.4%
Cost716
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 6.4 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.38 \cdot 10^{-129}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.3 \cdot 10^{+60}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
Alternative 3
Accuracy80.5%
Cost716
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 6.8 \cdot 10^{-154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.38 \cdot 10^{-129}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d4 \leq 1.15 \cdot 10^{-31}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 4
Accuracy91.0%
Cost713
\[\begin{array}{l} \mathbf{if}\;d1 \leq -3.8 \cdot 10^{+55} \lor \neg \left(d1 \leq 9 \cdot 10^{+60}\right):\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \end{array} \]
Alternative 5
Accuracy79.9%
Cost648
\[\begin{array}{l} \mathbf{if}\;d4 \leq 2.2 \cdot 10^{-157}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 6 \cdot 10^{+18}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 6
Accuracy72.3%
Cost585
\[\begin{array}{l} \mathbf{if}\;d3 \leq -3.6 \cdot 10^{+97} \lor \neg \left(d3 \leq 3.5 \cdot 10^{+139}\right):\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
Alternative 7
Accuracy95.6%
Cost580
\[\begin{array}{l} \mathbf{if}\;d4 \leq 9.5 \cdot 10^{+17}:\\ \;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \end{array} \]
Alternative 8
Accuracy100.0%
Cost576
\[d1 \cdot \left(\left(d4 - d1\right) + \left(d2 - d3\right)\right) \]
Alternative 9
Accuracy51.8%
Cost520
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.45 \cdot 10^{-156}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{+17}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 10
Accuracy52.8%
Cost324
\[\begin{array}{l} \mathbf{if}\;d4 \leq 2.3 \cdot 10^{-31}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 11
Accuracy32.4%
Cost192
\[d1 \cdot d4 \]

Error

Reproduce?

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