
(FPCore (t) :precision binary64 (let* ((t_1 (/ (* 2.0 t) (+ 1.0 t))) (t_2 (* t_1 t_1))) (/ (+ 1.0 t_2) (+ 2.0 t_2))))
double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double t_2 = t_1 * t_1;
return (1.0 + t_2) / (2.0 + t_2);
}
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
t_1 = (2.0d0 * t) / (1.0d0 + t)
t_2 = t_1 * t_1
code = (1.0d0 + t_2) / (2.0d0 + t_2)
end function
public static double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double t_2 = t_1 * t_1;
return (1.0 + t_2) / (2.0 + t_2);
}
def code(t): t_1 = (2.0 * t) / (1.0 + t) t_2 = t_1 * t_1 return (1.0 + t_2) / (2.0 + t_2)
function code(t) t_1 = Float64(Float64(2.0 * t) / Float64(1.0 + t)) t_2 = Float64(t_1 * t_1) return Float64(Float64(1.0 + t_2) / Float64(2.0 + t_2)) end
function tmp = code(t) t_1 = (2.0 * t) / (1.0 + t); t_2 = t_1 * t_1; tmp = (1.0 + t_2) / (2.0 + t_2); end
code[t_] := Block[{t$95$1 = N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, N[(N[(1.0 + t$95$2), $MachinePrecision] / N[(2.0 + t$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{2 \cdot t}{1 + t}\\
t_2 := t\_1 \cdot t\_1\\
\frac{1 + t\_2}{2 + t\_2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (t) :precision binary64 (let* ((t_1 (/ (* 2.0 t) (+ 1.0 t))) (t_2 (* t_1 t_1))) (/ (+ 1.0 t_2) (+ 2.0 t_2))))
double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double t_2 = t_1 * t_1;
return (1.0 + t_2) / (2.0 + t_2);
}
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
t_1 = (2.0d0 * t) / (1.0d0 + t)
t_2 = t_1 * t_1
code = (1.0d0 + t_2) / (2.0d0 + t_2)
end function
public static double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double t_2 = t_1 * t_1;
return (1.0 + t_2) / (2.0 + t_2);
}
def code(t): t_1 = (2.0 * t) / (1.0 + t) t_2 = t_1 * t_1 return (1.0 + t_2) / (2.0 + t_2)
function code(t) t_1 = Float64(Float64(2.0 * t) / Float64(1.0 + t)) t_2 = Float64(t_1 * t_1) return Float64(Float64(1.0 + t_2) / Float64(2.0 + t_2)) end
function tmp = code(t) t_1 = (2.0 * t) / (1.0 + t); t_2 = t_1 * t_1; tmp = (1.0 + t_2) / (2.0 + t_2); end
code[t_] := Block[{t$95$1 = N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, N[(N[(1.0 + t$95$2), $MachinePrecision] / N[(2.0 + t$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{2 \cdot t}{1 + t}\\
t_2 := t\_1 \cdot t\_1\\
\frac{1 + t\_2}{2 + t\_2}
\end{array}
\end{array}
(FPCore (t) :precision binary64 (let* ((t_1 (/ (* 2.0 t) (+ 1.0 t))) (t_2 (* t_1 t_1))) (/ (+ 1.0 t_2) (+ 2.0 t_2))))
double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double t_2 = t_1 * t_1;
return (1.0 + t_2) / (2.0 + t_2);
}
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
t_1 = (2.0d0 * t) / (1.0d0 + t)
t_2 = t_1 * t_1
code = (1.0d0 + t_2) / (2.0d0 + t_2)
end function
public static double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double t_2 = t_1 * t_1;
return (1.0 + t_2) / (2.0 + t_2);
}
def code(t): t_1 = (2.0 * t) / (1.0 + t) t_2 = t_1 * t_1 return (1.0 + t_2) / (2.0 + t_2)
function code(t) t_1 = Float64(Float64(2.0 * t) / Float64(1.0 + t)) t_2 = Float64(t_1 * t_1) return Float64(Float64(1.0 + t_2) / Float64(2.0 + t_2)) end
function tmp = code(t) t_1 = (2.0 * t) / (1.0 + t); t_2 = t_1 * t_1; tmp = (1.0 + t_2) / (2.0 + t_2); end
code[t_] := Block[{t$95$1 = N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, N[(N[(1.0 + t$95$2), $MachinePrecision] / N[(2.0 + t$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{2 \cdot t}{1 + t}\\
t_2 := t\_1 \cdot t\_1\\
\frac{1 + t\_2}{2 + t\_2}
\end{array}
\end{array}
Initial program 100.0%
(FPCore (t) :precision binary64 (let* ((t_1 (/ (* 2.0 t) (+ 1.0 t)))) (if (<= t_1 1e-15) (+ 1.0 t) t_1)))
double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double tmp;
if (t_1 <= 1e-15) {
tmp = 1.0 + t;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(t)
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = (2.0d0 * t) / (1.0d0 + t)
if (t_1 <= 1d-15) then
tmp = 1.0d0 + t
else
tmp = t_1
end if
code = tmp
end function
public static double code(double t) {
double t_1 = (2.0 * t) / (1.0 + t);
double tmp;
if (t_1 <= 1e-15) {
tmp = 1.0 + t;
} else {
tmp = t_1;
}
return tmp;
}
def code(t): t_1 = (2.0 * t) / (1.0 + t) tmp = 0 if t_1 <= 1e-15: tmp = 1.0 + t else: tmp = t_1 return tmp
function code(t) t_1 = Float64(Float64(2.0 * t) / Float64(1.0 + t)) tmp = 0.0 if (t_1 <= 1e-15) tmp = Float64(1.0 + t); else tmp = t_1; end return tmp end
function tmp_2 = code(t) t_1 = (2.0 * t) / (1.0 + t); tmp = 0.0; if (t_1 <= 1e-15) tmp = 1.0 + t; else tmp = t_1; end tmp_2 = tmp; end
code[t_] := Block[{t$95$1 = N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 1e-15], N[(1.0 + t), $MachinePrecision], t$95$1]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{2 \cdot t}{1 + t}\\
\mathbf{if}\;t\_1 \leq 10^{-15}:\\
\;\;\;\;1 + t\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (*.f64 #s(literal 2 binary64) t) (+.f64 #s(literal 1 binary64) t)) < 1.0000000000000001e-15Initial program 100.0%
Taylor expanded in t around 0
Applied rewrites4.2%
Taylor expanded in t around 0
Applied rewrites18.8%
if 1.0000000000000001e-15 < (/.f64 (*.f64 #s(literal 2 binary64) t) (+.f64 #s(literal 1 binary64) t)) Initial program 100.0%
Taylor expanded in t around 0
Applied rewrites18.1%
(FPCore (t) :precision binary64 (+ 1.0 (/ (* 2.0 t) (+ 1.0 t))))
double code(double t) {
return 1.0 + ((2.0 * t) / (1.0 + t));
}
real(8) function code(t)
real(8), intent (in) :: t
code = 1.0d0 + ((2.0d0 * t) / (1.0d0 + t))
end function
public static double code(double t) {
return 1.0 + ((2.0 * t) / (1.0 + t));
}
def code(t): return 1.0 + ((2.0 * t) / (1.0 + t))
function code(t) return Float64(1.0 + Float64(Float64(2.0 * t) / Float64(1.0 + t))) end
function tmp = code(t) tmp = 1.0 + ((2.0 * t) / (1.0 + t)); end
code[t_] := N[(1.0 + N[(N[(2.0 * t), $MachinePrecision] / N[(1.0 + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{2 \cdot t}{1 + t}
\end{array}
Initial program 100.0%
Taylor expanded in t around 0
Applied rewrites17.6%
Taylor expanded in t around 0
Applied rewrites18.0%
(FPCore (t) :precision binary64 (+ 1.0 t))
double code(double t) {
return 1.0 + t;
}
real(8) function code(t)
real(8), intent (in) :: t
code = 1.0d0 + t
end function
public static double code(double t) {
return 1.0 + t;
}
def code(t): return 1.0 + t
function code(t) return Float64(1.0 + t) end
function tmp = code(t) tmp = 1.0 + t; end
code[t_] := N[(1.0 + t), $MachinePrecision]
\begin{array}{l}
\\
1 + t
\end{array}
Initial program 100.0%
Taylor expanded in t around 0
Applied rewrites10.8%
Taylor expanded in t around 0
Applied rewrites10.7%
herbie shell --seed 2024321
(FPCore (t)
:name "Kahan p13 Example 1"
:precision binary64
:pre (TRUE)
(/ (+ 1.0 (* (/ (* 2.0 t) (+ 1.0 t)) (/ (* 2.0 t) (+ 1.0 t)))) (+ 2.0 (* (/ (* 2.0 t) (+ 1.0 t)) (/ (* 2.0 t) (+ 1.0 t))))))