FastMath dist4

?

Percentage Accurate: 88.0% → 100.0%
Time: 5.4s
Precision: binary64
Cost: 576

?

\[\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1 \]
\[d1 \cdot \left(\left(d2 - d3\right) + \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 (* d1 (+ (- d2 d3) (- 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 d1 * ((d2 - d3) + (d4 - d1));
}
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
end function
real(8) function code(d1, d2, d3, d4)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    real(8), intent (in) :: d4
    code = d1 * ((d2 - d3) + (d4 - d1))
end function
public static double code(double d1, double d2, double d3, double d4) {
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
}
public static double code(double d1, double d2, double d3, double d4) {
	return d1 * ((d2 - d3) + (d4 - d1));
}
def code(d1, d2, d3, d4):
	return (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1)
def code(d1, d2, d3, d4):
	return d1 * ((d2 - d3) + (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 Float64(d1 * Float64(Float64(d2 - d3) + Float64(d4 - d1)))
end
function tmp = code(d1, d2, d3, d4)
	tmp = (((d1 * d2) - (d1 * d3)) + (d4 * d1)) - (d1 * d1);
end
function tmp = code(d1, d2, d3, d4)
	tmp = d1 * ((d2 - d3) + (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[(N[(d2 - d3), $MachinePrecision] + N[(d4 - d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(d1 \cdot d2 - d1 \cdot d3\right) + d4 \cdot d1\right) - d1 \cdot d1
d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 10 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original88.0%
Target100.0%
Herbie100.0%
\[d1 \cdot \left(\left(\left(d2 - d3\right) + d4\right) - d1\right) \]

Derivation?

  1. Initial program 85.1%

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

    \[\leadsto \color{blue}{d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right)} \]
    Step-by-step derivation

    [Start]85.1%

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

    associate--l+ [=>]85.1%

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

    distribute-lft-out-- [=>]85.9%

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

    distribute-rgt-out-- [=>]91.0%

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

    distribute-lft-out [=>]100.0%

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

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

Alternatives

Alternative 1
Accuracy100.0%
Cost576
\[d1 \cdot \left(\left(d2 - d3\right) + \left(d4 - d1\right)\right) \]
Alternative 2
Accuracy39.2%
Cost1048
\[\begin{array}{l} t_0 := -d1 \cdot d3\\ t_1 := d1 \cdot \left(-d1\right)\\ \mathbf{if}\;d2 \leq -5.5 \cdot 10^{+67}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -6.5 \cdot 10^{-193}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -2.3 \cdot 10^{-274}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -5.2 \cdot 10^{-305}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq 1.7 \cdot 10^{-249}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{elif}\;d2 \leq 1.18 \cdot 10^{-191}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 3
Accuracy65.2%
Cost848
\[\begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ t_1 := d1 \cdot \left(d2 + d4\right)\\ \mathbf{if}\;d1 \leq -4.5 \cdot 10^{+168}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d1 \leq -3 \cdot 10^{-32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d1 \leq -2.8 \cdot 10^{-85}:\\ \;\;\;\;-d1 \cdot d3\\ \mathbf{elif}\;d1 \leq 3.5 \cdot 10^{+143}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Accuracy62.7%
Cost717
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.25 \cdot 10^{-108} \lor \neg \left(d4 \leq 1.7 \cdot 10^{-79}\right) \land d4 \leq 22000000000:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 5
Accuracy81.5%
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -1.3 \cdot 10^{+35}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\ \end{array} \]
Alternative 6
Accuracy84.6%
Cost580
\[\begin{array}{l} \mathbf{if}\;d2 \leq -8.2 \cdot 10^{-22}:\\ \;\;\;\;d1 \cdot \left(\left(d2 + d4\right) - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - \left(d1 + d3\right)\right)\\ \end{array} \]
Alternative 7
Accuracy39.1%
Cost520
\[\begin{array}{l} \mathbf{if}\;d2 \leq -7.5 \cdot 10^{+67}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d2 \leq -2.3 \cdot 10^{-305}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 8
Accuracy61.9%
Cost452
\[\begin{array}{l} \mathbf{if}\;d2 \leq -1.12 \cdot 10^{-21}:\\ \;\;\;\;d1 \cdot \left(d2 + d4\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 9
Accuracy38.3%
Cost324
\[\begin{array}{l} \mathbf{if}\;d2 \leq -2.4 \cdot 10^{-18}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 10
Accuracy30.9%
Cost192
\[d1 \cdot d4 \]

Reproduce?

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