Average Error: 0.0 → 0.0
Time: 9.5s
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, d2 - d3, d1 \cdot \left(d4 - d1\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 (- d2 d3) (* d1 (- d4 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(d1, (d2 - d3), (d1 * (d4 - 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 fma(d1, Float64(d2 - d3), Float64(d1 * Float64(d4 - 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[(d1 * N[(d2 - d3), $MachinePrecision] + N[(d1 * N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
\mathsf{fma}\left(d1, d2 - d3, d1 \cdot \left(d4 - d1\right)\right)

Error

Target

Original0.0
Target0.0
Herbie0.0
\[d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \]

Derivation

  1. Initial program 0.0

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

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

    [Start]0.0

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

    associate--l+ [=>]0.0

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

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

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

    fma-def [=>]0.0

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

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

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

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

Alternatives

Alternative 1
Error12.9
Cost982
\[\begin{array}{l} \mathbf{if}\;d2 \leq -9.5 \cdot 10^{+63}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d2 \leq -7 \cdot 10^{-148} \lor \neg \left(d2 \leq -1.02 \cdot 10^{-177}\right) \land \left(d2 \leq 1.3 \cdot 10^{-186} \lor \neg \left(d2 \leq 1.15 \cdot 10^{-99}\right)\right):\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 2
Error0.0
Cost960
\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d1 \cdot d4\right) - d1 \cdot d1 \]
Alternative 3
Error0.0
Cost832
\[\left(d1 \cdot d4 - d1 \cdot d1\right) + d1 \cdot \left(d2 - d3\right) \]
Alternative 4
Error28.3
Cost784
\[\begin{array}{l} t_0 := d3 \cdot \left(-d1\right)\\ \mathbf{if}\;d4 \leq -7.4 \cdot 10^{-191}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 2.55 \cdot 10^{-290}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.25 \cdot 10^{-199}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.55 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 5
Error14.6
Cost716
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq 3.8 \cdot 10^{+20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 7.6 \cdot 10^{+44}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d4 \leq 3.7 \cdot 10^{+80}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
Alternative 6
Error5.6
Cost712
\[\begin{array}{l} \mathbf{if}\;d1 \leq -5.2 \cdot 10^{+104}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{elif}\;d1 \leq 1.7 \cdot 10^{+51}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 7
Error12.7
Cost648
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.35 \cdot 10^{-53}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 5.2 \cdot 10^{+36}:\\ \;\;\;\;d1 \cdot \left(\left(-d1\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 8
Error30.0
Cost588
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.25 \cdot 10^{-53}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 8.2 \cdot 10^{-24}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 4 \cdot 10^{-9}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 9
Error17.9
Cost585
\[\begin{array}{l} \mathbf{if}\;d3 \leq -5.2 \cdot 10^{+55} \lor \neg \left(d3 \leq 5.1 \cdot 10^{+151}\right):\\ \;\;\;\;d3 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
Alternative 10
Error2.4
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -1.4 \cdot 10^{-26}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\ \end{array} \]
Alternative 11
Error0.0
Cost576
\[d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right) \]
Alternative 12
Error30.0
Cost324
\[\begin{array}{l} \mathbf{if}\;d4 \leq 4 \cdot 10^{-9}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 13
Error43.0
Cost192
\[d1 \cdot d4 \]

Error

Reproduce

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