?

Average Error: 0.0 → 0.0
Time: 8.7s
Precision: binary64
Cost: 6976

?

\[\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
Error39.8
Cost1180
\[\begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d2 \leq -3.8 \cdot 10^{+52}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.18 \cdot 10^{-17}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -1.05 \cdot 10^{-76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -3.4 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -1.4 \cdot 10^{-182}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -7 \cdot 10^{-254}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq 2.85 \cdot 10^{-297}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 2
Error22.6
Cost1113
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(d4 - d1\right)\\ \mathbf{if}\;d2 \leq -3.8 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -4.5 \cdot 10^{-77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -5 \cdot 10^{-111}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -1.95 \cdot 10^{-179} \lor \neg \left(d2 \leq -1.35 \cdot 10^{-252}\right) \land d2 \leq 8 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 3
Error7.9
Cost980
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \mathbf{if}\;d3 \leq -4.6 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 5.8 \cdot 10^{+53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 7.8 \cdot 10^{+79}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 2.75 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 4.1 \cdot 10^{+145}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error31.1
Cost849
\[\begin{array}{l} \mathbf{if}\;d2 \leq -4.7 \cdot 10^{+52}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d2 \leq -1.25 \cdot 10^{-11} \lor \neg \left(d2 \leq -9.5 \cdot 10^{-78}\right) \land d2 \leq -5.2 \cdot 10^{-111}:\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 5
Error19.8
Cost716
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d3 \leq -3.5 \cdot 10^{+68}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -4.9 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d3 \leq 3.1 \cdot 10^{+118}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error16.2
Cost716
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d3 \leq -7800000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -4.6 \cdot 10^{-151}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.6 \cdot 10^{+41}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error2.6
Cost713
\[\begin{array}{l} \mathbf{if}\;d3 \leq -22000000000 \lor \neg \left(d3 \leq 4 \cdot 10^{-12}\right):\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d1\right)\\ \end{array} \]
Alternative 8
Error0.0
Cost704
\[d1 \cdot \left(d2 - \left(d1 + d3\right)\right) + d1 \cdot d4 \]
Alternative 9
Error17.8
Cost585
\[\begin{array}{l} \mathbf{if}\;d3 \leq -2.3 \cdot 10^{+72} \lor \neg \left(d3 \leq 1.6 \cdot 10^{+119}\right):\\ \;\;\;\;d1 \cdot \left(-d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \end{array} \]
Alternative 10
Error0.0
Cost576
\[d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right) \]
Alternative 11
Error39.9
Cost520
\[\begin{array}{l} \mathbf{if}\;d2 \leq -0.0152:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1 \cdot 10^{-179}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 12
Error38.3
Cost324
\[\begin{array}{l} \mathbf{if}\;d2 \leq -6 \cdot 10^{-12}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 13
Error43.8
Cost192
\[d1 \cdot d4 \]

Error

Reproduce?

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