FastMath dist4

?

Percentage Accurate: 88.2% → 100.0%
Time: 10.2s
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?

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

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

Derivation?

  1. Initial program 87.9%

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

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

    associate--l+ [=>]87.9

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

    distribute-lft-out-- [=>]88.3

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

    distribute-rgt-out-- [=>]91.4

    \[ 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
Accuracy61.5%
Cost1245
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(d2 - d3\right)\\ \mathbf{if}\;d4 \leq -7.6 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 7 \cdot 10^{-110}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 2.75 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 1.6 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 4.4 \cdot 10^{+49} \lor \neg \left(d4 \leq 5.1 \cdot 10^{+72}\right) \land d4 \leq 9.8 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 2
Accuracy62.4%
Cost1245
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d3\right)\\ t_1 := d1 \cdot \left(d4 - d1\right)\\ \mathbf{if}\;d2 \leq -2.6 \cdot 10^{+111}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -2 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -1.46 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -1.25 \cdot 10^{-266}:\\ \;\;\;\;d1 \cdot \left(-\left(d1 + d3\right)\right)\\ \mathbf{elif}\;d2 \leq 8.5 \cdot 10^{-272} \lor \neg \left(d2 \leq 1.42 \cdot 10^{-213}\right) \land d2 \leq 2.8 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 3
Accuracy58.3%
Cost1244
\[\begin{array}{l} t_0 := d1 \cdot \left(d2 - d1\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d4 \leq -3.8 \cdot 10^{-47}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq -4.2 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 1.1 \cdot 10^{-106}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 3.1 \cdot 10^{+23}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 4.6 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 6.8 \cdot 10^{+96}:\\ \;\;\;\;d1 \cdot d4\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d1\right)\\ \end{array} \]
Alternative 4
Accuracy39.3%
Cost1180
\[\begin{array}{l} t_0 := d1 \cdot \left(-d1\right)\\ t_1 := d1 \cdot \left(-d3\right)\\ \mathbf{if}\;d4 \leq -5.5 \cdot 10^{-45}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq -5.2 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq -2.9 \cdot 10^{-217}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 1.15 \cdot 10^{-108}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 1.4 \cdot 10^{-58}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d4 \leq 2.9 \cdot 10^{+22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d4 \leq 4.2 \cdot 10^{+60}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 5
Accuracy63.1%
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.5 \cdot 10^{+111}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -2.8 \cdot 10^{+96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d2 \leq -370000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d2 \leq -5.9 \cdot 10^{-156} \lor \neg \left(d2 \leq -1.2 \cdot 10^{-194}\right) \land d2 \leq -9.2 \cdot 10^{-211}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(d4 - d3\right)\\ \end{array} \]
Alternative 6
Accuracy64.4%
Cost848
\[\begin{array}{l} t_0 := d1 \cdot \left(-d3\right)\\ t_1 := d1 \cdot \left(d4 - d1\right)\\ \mathbf{if}\;d3 \leq -2.4 \cdot 10^{+145}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d3 \leq 1.52 \cdot 10^{-249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d3 \leq 5.2 \cdot 10^{-190}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d3 \leq 1.85 \cdot 10^{+92}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Accuracy82.0%
Cost845
\[\begin{array}{l} \mathbf{if}\;d2 \leq -8.5 \cdot 10^{+119} \lor \neg \left(d2 \leq -3.5 \cdot 10^{+95}\right) \land d2 \leq -4.3 \cdot 10^{+33}:\\ \;\;\;\;d1 \cdot \left(d2 - d3\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\ \end{array} \]
Alternative 8
Accuracy39.0%
Cost589
\[\begin{array}{l} \mathbf{if}\;d2 \leq -2.4 \cdot 10^{+111} \lor \neg \left(d2 \leq -1.15 \cdot 10^{+92}\right) \land d2 \leq -9.8 \cdot 10^{+30}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 9
Accuracy83.6%
Cost580
\[\begin{array}{l} \mathbf{if}\;d4 \leq 1.15 \cdot 10^{+14}:\\ \;\;\;\;d1 \cdot \left(d2 - \left(d1 + d3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot \left(\left(d4 - d3\right) - d1\right)\\ \end{array} \]
Alternative 10
Accuracy39.2%
Cost520
\[\begin{array}{l} \mathbf{if}\;d4 \leq -4 \cdot 10^{-217}:\\ \;\;\;\;d1 \cdot d2\\ \mathbf{elif}\;d4 \leq 8.6 \cdot 10^{+48}:\\ \;\;\;\;d1 \cdot \left(-d1\right)\\ \mathbf{else}:\\ \;\;\;\;d1 \cdot d4\\ \end{array} \]
Alternative 11
Accuracy31.2%
Cost192
\[d1 \cdot d4 \]

Error

Reproduce?

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