FastMath test1

Percentage Accurate: 99.6% → 100.0%
Time: 800.0ms
Alternatives: 1
Speedup: 2.3×

Specification

?
\[\begin{array}{l} \\ d \cdot 10 + d \cdot 20 \end{array} \]
(FPCore (d) :precision binary64 (+ (* d 10.0) (* d 20.0)))
double code(double d) {
	return (d * 10.0) + (d * 20.0);
}
real(8) function code(d)
    real(8), intent (in) :: d
    code = (d * 10.0d0) + (d * 20.0d0)
end function
public static double code(double d) {
	return (d * 10.0) + (d * 20.0);
}
def code(d):
	return (d * 10.0) + (d * 20.0)
function code(d)
	return Float64(Float64(d * 10.0) + Float64(d * 20.0))
end
function tmp = code(d)
	tmp = (d * 10.0) + (d * 20.0);
end
code[d_] := N[(N[(d * 10.0), $MachinePrecision] + N[(d * 20.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
d \cdot 10 + d \cdot 20
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 1 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ d \cdot 10 + d \cdot 20 \end{array} \]
(FPCore (d) :precision binary64 (+ (* d 10.0) (* d 20.0)))
double code(double d) {
	return (d * 10.0) + (d * 20.0);
}
real(8) function code(d)
    real(8), intent (in) :: d
    code = (d * 10.0d0) + (d * 20.0d0)
end function
public static double code(double d) {
	return (d * 10.0) + (d * 20.0);
}
def code(d):
	return (d * 10.0) + (d * 20.0)
function code(d)
	return Float64(Float64(d * 10.0) + Float64(d * 20.0))
end
function tmp = code(d)
	tmp = (d * 10.0) + (d * 20.0);
end
code[d_] := N[(N[(d * 10.0), $MachinePrecision] + N[(d * 20.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
d \cdot 10 + d \cdot 20
\end{array}

Alternative 1: 100.0% accurate, 2.3× speedup?

\[\begin{array}{l} \\ d \cdot 30 \end{array} \]
(FPCore (d) :precision binary64 (* d 30.0))
double code(double d) {
	return d * 30.0;
}
real(8) function code(d)
    real(8), intent (in) :: d
    code = d * 30.0d0
end function
public static double code(double d) {
	return d * 30.0;
}
def code(d):
	return d * 30.0
function code(d)
	return Float64(d * 30.0)
end
function tmp = code(d)
	tmp = d * 30.0;
end
code[d_] := N[(d * 30.0), $MachinePrecision]
\begin{array}{l}

\\
d \cdot 30
\end{array}
Derivation
  1. Initial program 99.6%

    \[d \cdot 10 + d \cdot 20 \]
  2. Step-by-step derivation
    1. distribute-lft-out100.0%

      \[\leadsto \color{blue}{d \cdot \left(10 + 20\right)} \]
    2. metadata-eval100.0%

      \[\leadsto d \cdot \color{blue}{30} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{d \cdot 30} \]
  4. Final simplification100.0%

    \[\leadsto d \cdot 30 \]

Developer target: 100.0% accurate, 2.3× speedup?

\[\begin{array}{l} \\ d \cdot 30 \end{array} \]
(FPCore (d) :precision binary64 (* d 30.0))
double code(double d) {
	return d * 30.0;
}
real(8) function code(d)
    real(8), intent (in) :: d
    code = d * 30.0d0
end function
public static double code(double d) {
	return d * 30.0;
}
def code(d):
	return d * 30.0
function code(d)
	return Float64(d * 30.0)
end
function tmp = code(d)
	tmp = d * 30.0;
end
code[d_] := N[(d * 30.0), $MachinePrecision]
\begin{array}{l}

\\
d \cdot 30
\end{array}

Reproduce

?
herbie shell --seed 2023189 
(FPCore (d)
  :name "FastMath test1"
  :precision binary64

  :herbie-target
  (* d 30.0)

  (+ (* d 10.0) (* d 20.0)))