fma_test2

Percentage Accurate: 33.8% → 99.6%
Time: 10.0s
Alternatives: 4
Speedup: 1.7×

Specification

?
\[1.9 \leq t \land t \leq 2.1\]
\[\begin{array}{l} \\ 1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308} \end{array} \]
(FPCore (t) :precision binary64 (- (* 1.7e+308 t) 1.7e+308))
double code(double t) {
	return (1.7e+308 * t) - 1.7e+308;
}
real(8) function code(t)
    real(8), intent (in) :: t
    code = (1.7d+308 * t) - 1.7d+308
end function
public static double code(double t) {
	return (1.7e+308 * t) - 1.7e+308;
}
def code(t):
	return (1.7e+308 * t) - 1.7e+308
function code(t)
	return Float64(Float64(1.7e+308 * t) - 1.7e+308)
end
function tmp = code(t)
	tmp = (1.7e+308 * t) - 1.7e+308;
end
code[t_] := N[(N[(1.7e+308 * t), $MachinePrecision] - 1.7e+308), $MachinePrecision]
\begin{array}{l}

\\
1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308}
\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 4 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: 33.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308} \end{array} \]
(FPCore (t) :precision binary64 (- (* 1.7e+308 t) 1.7e+308))
double code(double t) {
	return (1.7e+308 * t) - 1.7e+308;
}
real(8) function code(t)
    real(8), intent (in) :: t
    code = (1.7d+308 * t) - 1.7d+308
end function
public static double code(double t) {
	return (1.7e+308 * t) - 1.7e+308;
}
def code(t):
	return (1.7e+308 * t) - 1.7e+308
function code(t)
	return Float64(Float64(1.7e+308 * t) - 1.7e+308)
end
function tmp = code(t)
	tmp = (1.7e+308 * t) - 1.7e+308;
end
code[t_] := N[(N[(1.7e+308 * t), $MachinePrecision] - 1.7e+308), $MachinePrecision]
\begin{array}{l}

\\
1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308}
\end{array}

Alternative 1: 99.6% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right) \end{array} \]
(FPCore (t) :precision binary64 (fma 1.7e+308 t -1.7e+308))
double code(double t) {
	return fma(1.7e+308, t, -1.7e+308);
}
function code(t)
	return fma(1.7e+308, t, -1.7e+308)
end
code[t_] := N[(1.7e+308 * t + -1.7e+308), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right)
\end{array}
Derivation
  1. Initial program 32.4%

    \[1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308} \]
  2. Step-by-step derivation
    1. fma-neg99.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right)} \]
    2. metadata-eval99.6%

      \[\leadsto \mathsf{fma}\left(1.7 \cdot 10^{+308}, t, \color{blue}{-1.7 \cdot 10^{+308}}\right) \]
  3. Simplified99.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right)} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 99.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ t \cdot \left(1.7 \cdot 10^{+308} - \frac{1.7 \cdot 10^{+308}}{t}\right) \end{array} \]
(FPCore (t) :precision binary64 (* t (- 1.7e+308 (/ 1.7e+308 t))))
double code(double t) {
	return t * (1.7e+308 - (1.7e+308 / t));
}
real(8) function code(t)
    real(8), intent (in) :: t
    code = t * (1.7d+308 - (1.7d+308 / t))
end function
public static double code(double t) {
	return t * (1.7e+308 - (1.7e+308 / t));
}
def code(t):
	return t * (1.7e+308 - (1.7e+308 / t))
function code(t)
	return Float64(t * Float64(1.7e+308 - Float64(1.7e+308 / t)))
end
function tmp = code(t)
	tmp = t * (1.7e+308 - (1.7e+308 / t));
end
code[t_] := N[(t * N[(1.7e+308 - N[(1.7e+308 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
t \cdot \left(1.7 \cdot 10^{+308} - \frac{1.7 \cdot 10^{+308}}{t}\right)
\end{array}
Derivation
  1. Initial program 32.4%

    \[1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308} \]
  2. Add Preprocessing
  3. Taylor expanded in t around inf 99.3%

    \[\leadsto \color{blue}{t \cdot \left(1.7 \cdot 10^{+308} - 1.7 \cdot 10^{+308} \cdot \frac{1}{t}\right)} \]
  4. Step-by-step derivation
    1. associate-*r/99.5%

      \[\leadsto t \cdot \left(1.7 \cdot 10^{+308} - \color{blue}{\frac{1.7 \cdot 10^{+308} \cdot 1}{t}}\right) \]
    2. metadata-eval99.5%

      \[\leadsto t \cdot \left(1.7 \cdot 10^{+308} - \frac{\color{blue}{1.7 \cdot 10^{+308}}}{t}\right) \]
  5. Simplified99.5%

    \[\leadsto \color{blue}{t \cdot \left(1.7 \cdot 10^{+308} - \frac{1.7 \cdot 10^{+308}}{t}\right)} \]
  6. Add Preprocessing

Alternative 3: 33.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ 1.7 \cdot 10^{+308} \cdot t \end{array} \]
(FPCore (t) :precision binary64 (* 1.7e+308 t))
double code(double t) {
	return 1.7e+308 * t;
}
real(8) function code(t)
    real(8), intent (in) :: t
    code = 1.7d+308 * t
end function
public static double code(double t) {
	return 1.7e+308 * t;
}
def code(t):
	return 1.7e+308 * t
function code(t)
	return Float64(1.7e+308 * t)
end
function tmp = code(t)
	tmp = 1.7e+308 * t;
end
code[t_] := N[(1.7e+308 * t), $MachinePrecision]
\begin{array}{l}

\\
1.7 \cdot 10^{+308} \cdot t
\end{array}
Derivation
  1. Initial program 32.4%

    \[1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308} \]
  2. Add Preprocessing
  3. Taylor expanded in t around inf 32.4%

    \[\leadsto \color{blue}{1.7 \cdot 10^{+308} \cdot t} \]
  4. Add Preprocessing

Alternative 4: 0.0% accurate, 5.0× speedup?

\[\begin{array}{l} \\ -1.7 \cdot 10^{+308} \end{array} \]
(FPCore (t) :precision binary64 -1.7e+308)
double code(double t) {
	return -1.7e+308;
}
real(8) function code(t)
    real(8), intent (in) :: t
    code = -1.7d+308
end function
public static double code(double t) {
	return -1.7e+308;
}
def code(t):
	return -1.7e+308
function code(t)
	return -1.7e+308
end
function tmp = code(t)
	tmp = -1.7e+308;
end
code[t_] := -1.7e+308
\begin{array}{l}

\\
-1.7 \cdot 10^{+308}
\end{array}
Derivation
  1. Initial program 32.4%

    \[1.7 \cdot 10^{+308} \cdot t - 1.7 \cdot 10^{+308} \]
  2. Add Preprocessing
  3. Taylor expanded in t around 0 0.0%

    \[\leadsto \color{blue}{-1.7 \cdot 10^{+308}} \]
  4. Add Preprocessing

Developer Target 1: 99.6% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right) \end{array} \]
(FPCore (t) :precision binary64 (fma 1.7e+308 t (- 1.7e+308)))
double code(double t) {
	return fma(1.7e+308, t, -1.7e+308);
}
function code(t)
	return fma(1.7e+308, t, Float64(-1.7e+308))
end
code[t_] := N[(1.7e+308 * t + (-1.7e+308)), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(1.7 \cdot 10^{+308}, t, -1.7 \cdot 10^{+308}\right)
\end{array}

Reproduce

?
herbie shell --seed 2024123 
(FPCore (t)
  :name "fma_test2"
  :precision binary64
  :pre (and (<= 1.9 t) (<= t 2.1))

  :alt
  (! :herbie-platform default (let ((x 170000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)) (fma x t (- x))))

  (- (* 1.7e+308 t) 1.7e+308))