?

Average Accuracy: 67.0% → 67.0%
Time: 9.1s
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(d4 - d1, 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 (- d4 d1) 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((d4 - d1), 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(Float64(d4 - d1), 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[(N[(d4 - d1), $MachinePrecision] * d1 + 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(d4 - d1, d1, d1 \cdot \left(d2 - d3\right)\right)

Error?

Target

Original67.0%
Target67.0%
Herbie67.0%
\[d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \]

Derivation?

  1. Initial program 67.0%

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

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

    [Start]67.0

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

    associate--l+ [=>]67.0

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

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

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

    distribute-rgt-out-- [=>]67.0

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

    distribute-lft-out [=>]67.0

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

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

    [Start]67.0

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

    +-commutative [=>]67.0

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

    distribute-rgt-in [=>]67.0

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

    fma-def [=>]67.0

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

    *-commutative [=>]67.0

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

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

Alternatives

Alternative 1
Accuracy45.4%
Cost848
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -2.2 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 5.1 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 1.6 \cdot 10^{-68}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d3 \leq 6.5 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy36.9%
Cost784
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d2 \leq -8.8 \cdot 10^{+77}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -3.4 \cdot 10^{-83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -1.45 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d2 \leq 2.4 \cdot 10^{-118}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
Alternative 3
Accuracy67.0%
Cost704
\[d1 \cdot \left(d4 - \left(d1 + d3\right)\right) + d1 \cdot d2 \]
Alternative 4
Accuracy52.2%
Cost648
\[\begin{array}{l} \mathbf{if}\;d2 \leq -3.5 \cdot 10^{+28}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq 3.2 \cdot 10^{-269}:\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 5
Accuracy47.9%
Cost585
\[\begin{array}{l} \mathbf{if}\;d3 \leq -2.2 \cdot 10^{+29} \lor \neg \left(d3 \leq 1.85 \cdot 10^{+73}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
Alternative 6
Accuracy45.4%
Cost585
\[\begin{array}{l} \mathbf{if}\;d3 \leq -0.000215 \lor \neg \left(d3 \leq 8 \cdot 10^{-25}\right):\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 7
Accuracy53.0%
Cost584
\[\begin{array}{l} \mathbf{if}\;d2 \leq -3.9 \cdot 10^{-81}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -1.5 \cdot 10^{-147}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 8
Accuracy61.2%
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -3.1 \cdot 10^{+31}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\ \end{array} \]
Alternative 9
Accuracy64.2%
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -2.6 \cdot 10^{+30}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\ \end{array} \]
Alternative 10
Accuracy67.0%
Cost576
\[d1 \cdot \left(\left(d4 - d1\right) + \left(d2 - d3\right)\right) \]
Alternative 11
Accuracy33.6%
Cost520
\[\begin{array}{l} \mathbf{if}\;d2 \leq -5.5 \cdot 10^{+32}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq 4.8 \cdot 10^{-267}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
Alternative 12
Accuracy35.9%
Cost324
\[\begin{array}{l} \mathbf{if}\;d2 \leq -2 \cdot 10^{+29}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d4 \cdot d1\\ \end{array} \]
Alternative 13
Accuracy3.9%
Cost192
\[d1 \cdot d3 \]
Alternative 14
Accuracy22.2%
Cost192
\[d4 \cdot d1 \]

Error

Reproduce?

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