(x * .985) - 0.35/2

Percentage Accurate: 100.0% → 100.0%
Time: 2.2s
Alternatives: 2
Speedup: 2.9×

Specification

?
\[0 \leq x \land x \leq 1000000000\]
\[\begin{array}{l} \\ x \cdot 0.985 - \frac{0.35}{2} \end{array} \]
(FPCore (x) :precision binary64 (- (* x 0.985) (/ 0.35 2.0)))
double code(double x) {
	return (x * 0.985) - (0.35 / 2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * 0.985d0) - (0.35d0 / 2.0d0)
end function
public static double code(double x) {
	return (x * 0.985) - (0.35 / 2.0);
}
def code(x):
	return (x * 0.985) - (0.35 / 2.0)
function code(x)
	return Float64(Float64(x * 0.985) - Float64(0.35 / 2.0))
end
function tmp = code(x)
	tmp = (x * 0.985) - (0.35 / 2.0);
end
code[x_] := N[(N[(x * 0.985), $MachinePrecision] - N[(0.35 / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.985 - \frac{0.35}{2}
\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 2 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot 0.985 - \frac{0.35}{2} \end{array} \]
(FPCore (x) :precision binary64 (- (* x 0.985) (/ 0.35 2.0)))
double code(double x) {
	return (x * 0.985) - (0.35 / 2.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x * 0.985d0) - (0.35d0 / 2.0d0)
end function
public static double code(double x) {
	return (x * 0.985) - (0.35 / 2.0);
}
def code(x):
	return (x * 0.985) - (0.35 / 2.0)
function code(x)
	return Float64(Float64(x * 0.985) - Float64(0.35 / 2.0))
end
function tmp = code(x)
	tmp = (x * 0.985) - (0.35 / 2.0);
end
code[x_] := N[(N[(x * 0.985), $MachinePrecision] - N[(0.35 / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot 0.985 - \frac{0.35}{2}
\end{array}

Alternative 1: 100.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x, 0.985, -0.175\right) \end{array} \]
(FPCore (x) :precision binary64 (fma x 0.985 -0.175))
double code(double x) {
	return fma(x, 0.985, -0.175);
}
function code(x)
	return fma(x, 0.985, -0.175)
end
code[x_] := N[(x * 0.985 + -0.175), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x, 0.985, -0.175\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[x \cdot 0.985 - \frac{0.35}{2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \color{blue}{x \cdot \frac{8872091265919877}{9007199254740992} + \left(\mathsf{neg}\left(\frac{\frac{3152519739159347}{9007199254740992}}{2}\right)\right)} \]
    2. accelerator-lowering-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{8872091265919877}{9007199254740992}, \mathsf{neg}\left(\frac{\frac{3152519739159347}{9007199254740992}}{2}\right)\right)} \]
    3. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(x, \frac{8872091265919877}{9007199254740992}, \mathsf{neg}\left(\color{blue}{\frac{3152519739159347}{18014398509481984}}\right)\right) \]
    4. metadata-eval100.0

      \[\leadsto \mathsf{fma}\left(x, 0.985, \color{blue}{-0.175}\right) \]
  4. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, 0.985, -0.175\right)} \]
  5. Add Preprocessing

Alternative 2: 94.6% accurate, 20.0× speedup?

\[\begin{array}{l} \\ -0.175 \end{array} \]
(FPCore (x) :precision binary64 -0.175)
double code(double x) {
	return -0.175;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = -0.175d0
end function
public static double code(double x) {
	return -0.175;
}
def code(x):
	return -0.175
function code(x)
	return -0.175
end
function tmp = code(x)
	tmp = -0.175;
end
code[x_] := -0.175
\begin{array}{l}

\\
-0.175
\end{array}
Derivation
  1. Initial program 100.0%

    \[x \cdot 0.985 - \frac{0.35}{2} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{-3152519739159347}{18014398509481984}} \]
  4. Step-by-step derivation
    1. Simplified94.6%

      \[\leadsto \color{blue}{-0.175} \]
    2. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 5 
    (FPCore (x)
      :name "(x * .985) - 0.35/2"
      :precision binary64
      :pre (and (<= 0.0 x) (<= x 1000000000.0))
      (- (* x 0.985) (/ 0.35 2.0)))