?

Average Error: 0.0 → 0.0
Time: 9.3s
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

    [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) \]

    *-commutative [=>]0.0

    \[ d1 \cdot \left(d2 - d3\right) + \left(\color{blue}{d1 \cdot d4} - d1 \cdot d1\right) \]
  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
Error20.9
Cost1509
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := -d1 \cdot d3\\ t_2 := d1 \cdot \left(d4 - d1\right)\\ t_3 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -5.2 \cdot 10^{+104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -5 \cdot 10^{-213}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;d3 \leq -7.6 \cdot 10^{-304}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 4.6 \cdot 10^{-274}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 7.2 \cdot 10^{-262}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 3.2 \cdot 10^{-182}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 4 \cdot 10^{+95} \lor \neg \left(d3 \leq 5.9 \cdot 10^{+141}\right) \land d3 \leq 4.2 \cdot 10^{+192}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error17.1
Cost1244
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ t_2 := d1 \cdot \left(d4 - d1\right)\\ t_3 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -2.2 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq -1.25 \cdot 10^{-213}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;d3 \leq -1.8 \cdot 10^{-305}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 5.4 \cdot 10^{-274}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 1.32 \cdot 10^{-261}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 2.75 \cdot 10^{-182}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;d3 \leq 10^{+81}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error20.1
Cost1113
\[\begin{array}{l} t_0 := -d1 \cdot d3\\ t_1 := d1 \cdot \left(d4 + d2\right)\\ \mathbf{if}\;d3 \leq -3.2 \cdot 10^{+104}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq -7.5 \cdot 10^{-301}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 2 \cdot 10^{-183}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \mathbf{elif}\;d3 \leq 1.05 \cdot 10^{+96} \lor \neg \left(d3 \leq 8 \cdot 10^{+142}\right) \land d3 \leq 2.4 \cdot 10^{+192}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error30.4
Cost984
\[\begin{array}{l} t_0 := -d1 \cdot d3\\ \mathbf{if}\;d4 \leq -1.12 \cdot 10^{-105}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.22 \cdot 10^{-108}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 6.6 \cdot 10^{-68}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.7 \cdot 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.06 \cdot 10^{+20}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 1.4 \cdot 10^{+38}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 6
Error19.0
Cost850
\[\begin{array}{l} \mathbf{if}\;d3 \leq -2.1 \cdot 10^{+104} \lor \neg \left(d3 \leq 1.06 \cdot 10^{+96}\right) \land \left(d3 \leq 7.5 \cdot 10^{+142} \lor \neg \left(d3 \leq 2.4 \cdot 10^{+192}\right)\right):\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \end{array} \]
Alternative 7
Error8.0
Cost848
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d3 \leq -3.2 \cdot 10^{+103}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 7.8 \cdot 10^{+80}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \mathbf{elif}\;d3 \leq 8 \cdot 10^{+142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 2.5 \cdot 10^{+159}:\\ \;\;\;\;d1 \cdot \left(d4 + d2\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 8
Error2.8
Cost713
\[\begin{array}{l} \mathbf{if}\;d3 \leq -8.2 \cdot 10^{-57} \lor \neg \left(d3 \leq 1.35 \cdot 10^{-53}\right):\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \end{array} \]
Alternative 9
Error4.7
Cost712
\[\begin{array}{l} \mathbf{if}\;d1 \leq -17500000000000:\\ \;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\ \mathbf{elif}\;d1 \leq 1.35 \cdot 10^{+22}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 + d2\right) - d1\right)\\ \end{array} \]
Alternative 10
Error30.8
Cost588
\[\begin{array}{l} \mathbf{if}\;d4 \leq 6.2 \cdot 10^{-22}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 9.5 \cdot 10^{+19}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{elif}\;d4 \leq 1.2 \cdot 10^{+30}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 11
Error13.0
Cost584
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.7 \cdot 10^{-18}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{elif}\;d4 \leq 6 \cdot 10^{+27}:\\ \;\;\;\;d1 \cdot \left(d2 - d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 12
Error0.0
Cost576
\[d1 \cdot \left(\left(d4 - d1\right) + \left(d2 - d3\right)\right) \]
Alternative 13
Error30.7
Cost324
\[\begin{array}{l} \mathbf{if}\;d4 \leq 3.2 \cdot 10^{+30}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 14
Error44.1
Cost192
\[d1 \cdot d4 \]

Error

Reproduce?

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