
(FPCore (t) :precision binary64 (let* ((t_1 (+ 1.0 (* t 2e-16)))) (+ (* t_1 t_1) (- -1.0 (* 2.0 (* t 2e-16))))))
double code(double t) {
double t_1 = 1.0 + (t * 2e-16);
return (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16)));
}
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: t_1
t_1 = 1.0d0 + (t * 2d-16)
code = (t_1 * t_1) + ((-1.0d0) - (2.0d0 * (t * 2d-16)))
end function
public static double code(double t) {
double t_1 = 1.0 + (t * 2e-16);
return (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16)));
}
def code(t): t_1 = 1.0 + (t * 2e-16) return (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16)))
function code(t) t_1 = Float64(1.0 + Float64(t * 2e-16)) return Float64(Float64(t_1 * t_1) + Float64(-1.0 - Float64(2.0 * Float64(t * 2e-16)))) end
function tmp = code(t) t_1 = 1.0 + (t * 2e-16); tmp = (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16))); end
code[t_] := Block[{t$95$1 = N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * t$95$1), $MachinePrecision] + N[(-1.0 - N[(2.0 * N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\
t\_1 \cdot t\_1 + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (t) :precision binary64 (let* ((t_1 (+ 1.0 (* t 2e-16)))) (+ (* t_1 t_1) (- -1.0 (* 2.0 (* t 2e-16))))))
double code(double t) {
double t_1 = 1.0 + (t * 2e-16);
return (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16)));
}
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: t_1
t_1 = 1.0d0 + (t * 2d-16)
code = (t_1 * t_1) + ((-1.0d0) - (2.0d0 * (t * 2d-16)))
end function
public static double code(double t) {
double t_1 = 1.0 + (t * 2e-16);
return (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16)));
}
def code(t): t_1 = 1.0 + (t * 2e-16) return (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16)))
function code(t) t_1 = Float64(1.0 + Float64(t * 2e-16)) return Float64(Float64(t_1 * t_1) + Float64(-1.0 - Float64(2.0 * Float64(t * 2e-16)))) end
function tmp = code(t) t_1 = 1.0 + (t * 2e-16); tmp = (t_1 * t_1) + (-1.0 - (2.0 * (t * 2e-16))); end
code[t_] := Block[{t$95$1 = N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * t$95$1), $MachinePrecision] + N[(-1.0 - N[(2.0 * N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\
t\_1 \cdot t\_1 + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)
\end{array}
\end{array}
(FPCore (t) :precision binary64 (sqrt (* (pow t 4.0) 1.6e-63)))
double code(double t) {
return sqrt((pow(t, 4.0) * 1.6e-63));
}
real(8) function code(t)
real(8), intent (in) :: t
code = sqrt(((t ** 4.0d0) * 1.6d-63))
end function
public static double code(double t) {
return Math.sqrt((Math.pow(t, 4.0) * 1.6e-63));
}
def code(t): return math.sqrt((math.pow(t, 4.0) * 1.6e-63))
function code(t) return sqrt(Float64((t ^ 4.0) * 1.6e-63)) end
function tmp = code(t) tmp = sqrt(((t ^ 4.0) * 1.6e-63)); end
code[t_] := N[Sqrt[N[(N[Power[t, 4.0], $MachinePrecision] * 1.6e-63), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{t}^{4} \cdot 1.6 \cdot 10^{-63}}
\end{array}
Initial program 3.4%
Simplified99.5%
pow199.5%
metadata-eval99.5%
sqrt-pow199.5%
associate-*r*99.4%
unpow-prod-down99.2%
pow-prod-down99.2%
pow-sqr99.4%
metadata-eval99.4%
metadata-eval99.6%
Applied egg-rr99.6%
(FPCore (t) :precision binary64 (* t (* t 4e-32)))
double code(double t) {
return t * (t * 4e-32);
}
real(8) function code(t)
real(8), intent (in) :: t
code = t * (t * 4d-32)
end function
public static double code(double t) {
return t * (t * 4e-32);
}
def code(t): return t * (t * 4e-32)
function code(t) return Float64(t * Float64(t * 4e-32)) end
function tmp = code(t) tmp = t * (t * 4e-32); end
code[t_] := N[(t * N[(t * 4e-32), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
t \cdot \left(t \cdot 4 \cdot 10^{-32}\right)
\end{array}
Initial program 3.4%
Simplified99.5%
(FPCore (t) :precision binary64 (* 4e-32 (* t t)))
double code(double t) {
return 4e-32 * (t * t);
}
real(8) function code(t)
real(8), intent (in) :: t
code = 4d-32 * (t * t)
end function
public static double code(double t) {
return 4e-32 * (t * t);
}
def code(t): return 4e-32 * (t * t)
function code(t) return Float64(4e-32 * Float64(t * t)) end
function tmp = code(t) tmp = 4e-32 * (t * t); end
code[t_] := N[(4e-32 * N[(t * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot 10^{-32} \cdot \left(t \cdot t\right)
\end{array}
Initial program 3.4%
Simplified99.5%
Taylor expanded in t around 0 99.4%
unpow299.4%
Applied egg-rr99.4%
(FPCore (t) :precision binary64 (let* ((t_1 (+ 1.0 (* t 2e-16)))) (fma t_1 t_1 (- -1.0 (* 2.0 (* t 2e-16))))))
double code(double t) {
double t_1 = 1.0 + (t * 2e-16);
return fma(t_1, t_1, (-1.0 - (2.0 * (t * 2e-16))));
}
function code(t) t_1 = Float64(1.0 + Float64(t * 2e-16)) return fma(t_1, t_1, Float64(-1.0 - Float64(2.0 * Float64(t * 2e-16)))) end
code[t_] := Block[{t$95$1 = N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]}, N[(t$95$1 * t$95$1 + N[(-1.0 - N[(2.0 * N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\
\mathsf{fma}\left(t\_1, t\_1, -1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)
\end{array}
\end{array}
herbie shell --seed 2024116
(FPCore (t)
:name "fma_test1"
:precision binary64
:pre (and (<= 0.9 t) (<= t 1.1))
:alt
(! :herbie-platform default (let ((x (+ 1 (* t 1/5000000000000000))) (z (- -1 (* 2 (* t 1/5000000000000000))))) (fma x x z)))
(+ (* (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16))) (- -1.0 (* 2.0 (* t 2e-16)))))