
(FPCore (i) :precision binary64 (let* ((t_0 (* (* 2.0 i) (* 2.0 i)))) (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: t_0
t_0 = (2.0d0 * i) * (2.0d0 * i)
code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0d0)
end function
public static double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
def code(i): t_0 = (2.0 * i) * (2.0 * i) return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0)
function code(i) t_0 = Float64(Float64(2.0 * i) * Float64(2.0 * i)) return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(t_0 - 1.0)) end
function tmp = code(i) t_0 = (2.0 * i) * (2.0 * i); tmp = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0); end
code[i_] := Block[{t$95$0 = N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(t$95$0 - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t_0}}{t_0 - 1}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (i) :precision binary64 (let* ((t_0 (* (* 2.0 i) (* 2.0 i)))) (/ (/ (* (* i i) (* i i)) t_0) (- t_0 1.0))))
double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: t_0
t_0 = (2.0d0 * i) * (2.0d0 * i)
code = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0d0)
end function
public static double code(double i) {
double t_0 = (2.0 * i) * (2.0 * i);
return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0);
}
def code(i): t_0 = (2.0 * i) * (2.0 * i) return (((i * i) * (i * i)) / t_0) / (t_0 - 1.0)
function code(i) t_0 = Float64(Float64(2.0 * i) * Float64(2.0 * i)) return Float64(Float64(Float64(Float64(i * i) * Float64(i * i)) / t_0) / Float64(t_0 - 1.0)) end
function tmp = code(i) t_0 = (2.0 * i) * (2.0 * i); tmp = (((i * i) * (i * i)) / t_0) / (t_0 - 1.0); end
code[i_] := Block[{t$95$0 = N[(N[(2.0 * i), $MachinePrecision] * N[(2.0 * i), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(N[(i * i), $MachinePrecision] * N[(i * i), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] / N[(t$95$0 - 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot i\right) \cdot \left(2 \cdot i\right)\\
\frac{\frac{\left(i \cdot i\right) \cdot \left(i \cdot i\right)}{t_0}}{t_0 - 1}
\end{array}
\end{array}
(FPCore (i) :precision binary64 (if (<= i 0.5) (* i (/ (- i) 4.0)) 0.0625))
double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = i * (-i / 4.0);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 0.5d0) then
tmp = i * (-i / 4.0d0)
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = i * (-i / 4.0);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 0.5: tmp = i * (-i / 4.0) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 0.5) tmp = Float64(i * Float64(Float64(-i) / 4.0)); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 0.5) tmp = i * (-i / 4.0); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 0.5], N[(i * N[((-i) / 4.0), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 0.5:\\
\;\;\;\;i \cdot \frac{-i}{4}\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 0.5Initial program 29.4%
sqr-neg29.4%
sqr-neg29.4%
associate-/l*57.2%
sqr-neg57.2%
swap-sqr57.2%
metadata-eval57.2%
sqr-neg57.2%
sub-neg57.2%
swap-sqr57.2%
metadata-eval57.2%
metadata-eval57.2%
Simplified57.2%
associate-/l/57.2%
times-frac57.2%
fma-def57.2%
pow257.2%
associate-/l*57.2%
*-inverses100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in i around 0 99.6%
neg-mul-199.6%
Simplified99.6%
if 0.5 < i Initial program 25.4%
Simplified100.0%
Taylor expanded in i around inf 98.8%
Final simplification99.2%
(FPCore (i) :precision binary64 (/ 0.25 (+ 4.0 (/ -1.0 (* i i)))))
double code(double i) {
return 0.25 / (4.0 + (-1.0 / (i * i)));
}
real(8) function code(i)
real(8), intent (in) :: i
code = 0.25d0 / (4.0d0 + ((-1.0d0) / (i * i)))
end function
public static double code(double i) {
return 0.25 / (4.0 + (-1.0 / (i * i)));
}
def code(i): return 0.25 / (4.0 + (-1.0 / (i * i)))
function code(i) return Float64(0.25 / Float64(4.0 + Float64(-1.0 / Float64(i * i)))) end
function tmp = code(i) tmp = 0.25 / (4.0 + (-1.0 / (i * i))); end
code[i_] := N[(0.25 / N[(4.0 + N[(-1.0 / N[(i * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.25}{4 + \frac{-1}{i \cdot i}}
\end{array}
Initial program 27.5%
Simplified99.2%
Final simplification99.2%
(FPCore (i) :precision binary64 0.0625)
double code(double i) {
return 0.0625;
}
real(8) function code(i)
real(8), intent (in) :: i
code = 0.0625d0
end function
public static double code(double i) {
return 0.0625;
}
def code(i): return 0.0625
function code(i) return 0.0625 end
function tmp = code(i) tmp = 0.0625; end
code[i_] := 0.0625
\begin{array}{l}
\\
0.0625
\end{array}
Initial program 27.5%
Simplified99.2%
Taylor expanded in i around inf 49.6%
Final simplification49.6%
herbie shell --seed 2023309
(FPCore (i)
:name "Octave 3.8, jcobi/4, as called"
:precision binary64
:pre (> i 0.0)
(/ (/ (* (* i i) (* i i)) (* (* 2.0 i) (* 2.0 i))) (- (* (* 2.0 i) (* 2.0 i)) 1.0)))