Average Error: 0.0 → 0.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(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

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}{d1 \cdot \left(d2 - d3\right) + \left(d1 \cdot d4 - d1 \cdot d1\right)} \]
    Proof
    (+.f64 (*.f64 d1 (-.f64 d2 d3)) (-.f64 (*.f64 d1 d4) (*.f64 d1 d1))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3))) (-.f64 (*.f64 d1 d4) (*.f64 d1 d1))): 0 points increase in error, 1 points decrease in error
    (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (-.f64 (Rewrite<= *-commutative_binary64 (*.f64 d4 d1)) (*.f64 d1 d1))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (-.f64 (*.f64 d1 d2) (*.f64 d1 d3)) (*.f64 d4 d1)) (*.f64 d1 d1))): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.0

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

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

Alternatives

Alternative 1
Error0.0
Cost6976
\[\mathsf{fma}\left(d1, d2 - d3, d1 \cdot \left(d4 - d1\right)\right) \]
Alternative 2
Error29.1
Cost1312
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d2 \leq -2 \cdot 10^{+52}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -1.9 \cdot 10^{+34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -1.85 \cdot 10^{-20}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -3.25 \cdot 10^{-149}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -9.8 \cdot 10^{-244}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -5.3 \cdot 10^{-294}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq 1.15 \cdot 10^{-185}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq 6.6 \cdot 10^{-107}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 3
Error19.4
Cost1112
\[\begin{array}{l} t_0 := d1 \cdot \left(d4 - d1\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ t_2 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -1.35 \cdot 10^{+168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -9.5 \cdot 10^{-23}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq -2.65 \cdot 10^{-107}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 1.05 \cdot 10^{-28}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 6.2 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 9.2 \cdot 10^{+121}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error19.8
Cost1112
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -1.15 \cdot 10^{+168}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -1.02 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -6.3 \cdot 10^{-111}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d3 \leq 2.2 \cdot 10^{-44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+16}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 7.7 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error15.4
Cost980
\[\begin{array}{l} t_0 := d1 \cdot \left(d4 + d2\right)\\ t_1 := d1 \cdot \left(d4 - d3\right)\\ \mathbf{if}\;d3 \leq -5.7 \cdot 10^{+116}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -1.06 \cdot 10^{+60}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 8 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+16}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 4 \cdot 10^{+95}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error15.9
Cost848
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -1.02 \cdot 10^{+114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 2.2 \cdot 10^{-44}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 4.2 \cdot 10^{+16}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{elif}\;d3 \leq 3 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error7.7
Cost844
\[\begin{array}{l} t_0 := d1 \cdot \left(d4 - d3\right)\\ \mathbf{if}\;d3 \leq -6.4 \cdot 10^{+115}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d3 \leq -3.6 \cdot 10^{+59}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 9.4 \cdot 10^{+107}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error2.4
Cost712
\[\begin{array}{l} t_0 := d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \mathbf{if}\;d3 \leq -220000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 33:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error30.0
Cost652
\[\begin{array}{l} \mathbf{if}\;d2 \leq -0.0012:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -4 \cdot 10^{-126}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq -4.5 \cdot 10^{-148}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 10
Error18.3
Cost584
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d3 \leq -1.15 \cdot 10^{+168}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 3.4 \cdot 10^{+121}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error0.0
Cost576
\[d1 \cdot \left(\left(d2 + \left(d4 - d3\right)\right) - d1\right) \]
Alternative 12
Error30.2
Cost324
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.5 \cdot 10^{-51}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 13
Error43.5
Cost192
\[d1 \cdot d4 \]

Error

Reproduce

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