FastMath dist3

?

Percentage Accurate: 97.9% → 100.0%
Time: 5.1s
Precision: binary64
Cost: 448

?

\[\left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32 \]
\[d1 \cdot \left(d2 + \left(d3 + 37\right)\right) \]
(FPCore (d1 d2 d3)
 :precision binary64
 (+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))
(FPCore (d1 d2 d3) :precision binary64 (* d1 (+ d2 (+ d3 37.0))))
double code(double d1, double d2, double d3) {
	return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
}
double code(double d1, double d2, double d3) {
	return d1 * (d2 + (d3 + 37.0));
}
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    code = ((d1 * d2) + ((d3 + 5.0d0) * d1)) + (d1 * 32.0d0)
end function
real(8) function code(d1, d2, d3)
    real(8), intent (in) :: d1
    real(8), intent (in) :: d2
    real(8), intent (in) :: d3
    code = d1 * (d2 + (d3 + 37.0d0))
end function
public static double code(double d1, double d2, double d3) {
	return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
}
public static double code(double d1, double d2, double d3) {
	return d1 * (d2 + (d3 + 37.0));
}
def code(d1, d2, d3):
	return ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0)
def code(d1, d2, d3):
	return d1 * (d2 + (d3 + 37.0))
function code(d1, d2, d3)
	return Float64(Float64(Float64(d1 * d2) + Float64(Float64(d3 + 5.0) * d1)) + Float64(d1 * 32.0))
end
function code(d1, d2, d3)
	return Float64(d1 * Float64(d2 + Float64(d3 + 37.0)))
end
function tmp = code(d1, d2, d3)
	tmp = ((d1 * d2) + ((d3 + 5.0) * d1)) + (d1 * 32.0);
end
function tmp = code(d1, d2, d3)
	tmp = d1 * (d2 + (d3 + 37.0));
end
code[d1_, d2_, d3_] := N[(N[(N[(d1 * d2), $MachinePrecision] + N[(N[(d3 + 5.0), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] + N[(d1 * 32.0), $MachinePrecision]), $MachinePrecision]
code[d1_, d2_, d3_] := N[(d1 * N[(d2 + N[(d3 + 37.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32
d1 \cdot \left(d2 + \left(d3 + 37\right)\right)

Local Percentage Accuracy?

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.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original97.9%
Target100.0%
Herbie100.0%
\[d1 \cdot \left(\left(37 + d3\right) + d2\right) \]

Derivation?

  1. Initial program 98.8%

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

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

    [Start]98.8

    \[ \left(d1 \cdot d2 + \left(d3 + 5\right) \cdot d1\right) + d1 \cdot 32 \]

    *-commutative [=>]98.8

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

    distribute-lft-out [=>]99.9

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

    distribute-lft-out [=>]100.0

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

    associate-+r+ [<=]100.0

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

    associate-+l+ [=>]100.0

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

    metadata-eval [=>]100.0

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

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

Alternatives

Alternative 1
Accuracy50.8%
Cost720
\[\begin{array}{l} \mathbf{if}\;d3 \leq -6.4 \cdot 10^{-243}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d3 \leq 4.1 \cdot 10^{-299}:\\ \;\;\;\;d1 \cdot 37\\ \mathbf{elif}\;d3 \leq 1.25 \cdot 10^{-188}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d3 \leq 36:\\ \;\;\;\;d1 \cdot 37\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]
Alternative 2
Accuracy75.8%
Cost452
\[\begin{array}{l} \mathbf{if}\;d3 \leq 1.86 \cdot 10^{+25}:\\ \;\;\;\;d1 \cdot \left(d2 + 37\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]
Alternative 3
Accuracy76.6%
Cost452
\[\begin{array}{l} \mathbf{if}\;d2 \leq -3 \cdot 10^{+16}:\\ \;\;\;\;d1 \cdot \left(d2 + 32\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d3 + 37\right)\\ \end{array} \]
Alternative 4
Accuracy45.0%
Cost324
\[\begin{array}{l} \mathbf{if}\;d3 \leq 36:\\ \;\;\;\;d1 \cdot 37\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d3\\ \end{array} \]
Alternative 5
Accuracy27.4%
Cost192
\[d1 \cdot 37 \]

Error

Reproduce?

herbie shell --seed 2023160 
(FPCore (d1 d2 d3)
  :name "FastMath dist3"
  :precision binary64

  :herbie-target
  (* d1 (+ (+ 37.0 d3) d2))

  (+ (+ (* d1 d2) (* (+ d3 5.0) d1)) (* d1 32.0)))