
(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 8 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 50000000.0)
(/
(* (* i (/ i 4.0)) (/ i i))
(+ (* (+ (fma i 2.0 1.0) -1.0) (* i 2.0)) -1.0))
0.0625))
double code(double i) {
double tmp;
if (i <= 50000000.0) {
tmp = ((i * (i / 4.0)) * (i / i)) / (((fma(i, 2.0, 1.0) + -1.0) * (i * 2.0)) + -1.0);
} else {
tmp = 0.0625;
}
return tmp;
}
function code(i) tmp = 0.0 if (i <= 50000000.0) tmp = Float64(Float64(Float64(i * Float64(i / 4.0)) * Float64(i / i)) / Float64(Float64(Float64(fma(i, 2.0, 1.0) + -1.0) * Float64(i * 2.0)) + -1.0)); else tmp = 0.0625; end return tmp end
code[i_] := If[LessEqual[i, 50000000.0], N[(N[(N[(i * N[(i / 4.0), $MachinePrecision]), $MachinePrecision] * N[(i / i), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(N[(i * 2.0 + 1.0), $MachinePrecision] + -1.0), $MachinePrecision] * N[(i * 2.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 50000000:\\
\;\;\;\;\frac{\left(i \cdot \frac{i}{4}\right) \cdot \frac{i}{i}}{\left(\mathsf{fma}\left(i, 2, 1\right) + -1\right) \cdot \left(i \cdot 2\right) + -1}\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 5e7Initial program 40.1%
associate-*r*40.0%
unpow339.9%
associate-*r*39.9%
times-frac87.7%
*-commutative87.7%
associate-*l*87.7%
metadata-eval87.7%
Applied egg-rr87.7%
cube-mult87.8%
*-commutative87.8%
times-frac100.0%
add-sqr-sqrt100.0%
sqrt-prod81.8%
sqr-neg81.8%
distribute-rgt-neg-out81.8%
distribute-rgt-neg-out81.8%
sqrt-unprod41.7%
add-sqr-sqrt43.6%
distribute-rgt-neg-out43.6%
neg-sub043.6%
metadata-eval43.6%
add-sqr-sqrt43.6%
sqrt-prod2.0%
sqr-neg2.0%
sqrt-unprod0.0%
add-sqr-sqrt100.0%
neg-sub0100.0%
sub-neg100.0%
add-sqr-sqrt0.0%
sqrt-unprod2.0%
sqr-neg2.0%
sqrt-prod43.6%
add-sqr-sqrt43.6%
Applied egg-rr100.0%
expm1-log1p-u99.9%
expm1-undefine99.9%
log1p-undefine99.9%
+-commutative99.9%
add-exp-log100.0%
*-commutative100.0%
fma-define100.0%
Applied egg-rr100.0%
if 5e7 < i Initial program 25.6%
Simplified47.0%
Taylor expanded in i around inf 100.0%
Final simplification100.0%
(FPCore (i) :precision binary64 (* 0.25 (* i (* (/ 1.0 (fma i 2.0 1.0)) (/ i (fma i 2.0 -1.0))))))
double code(double i) {
return 0.25 * (i * ((1.0 / fma(i, 2.0, 1.0)) * (i / fma(i, 2.0, -1.0))));
}
function code(i) return Float64(0.25 * Float64(i * Float64(Float64(1.0 / fma(i, 2.0, 1.0)) * Float64(i / fma(i, 2.0, -1.0))))) end
code[i_] := N[(0.25 * N[(i * N[(N[(1.0 / N[(i * 2.0 + 1.0), $MachinePrecision]), $MachinePrecision] * N[(i / N[(i * 2.0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.25 \cdot \left(i \cdot \left(\frac{1}{\mathsf{fma}\left(i, 2, 1\right)} \cdot \frac{i}{\mathsf{fma}\left(i, 2, -1\right)}\right)\right)
\end{array}
Initial program 32.4%
Simplified71.8%
*-un-lft-identity71.8%
fma-undefine71.8%
associate-*r*71.8%
*-commutative71.8%
metadata-eval71.8%
swap-sqr71.8%
difference-of-sqr--171.8%
times-frac99.8%
*-commutative99.8%
fma-define99.8%
*-commutative99.8%
fma-neg99.8%
metadata-eval99.8%
Applied egg-rr99.8%
(FPCore (i) :precision binary64 (/ (* i (* i (/ 0.25 (fma i 2.0 -1.0)))) (fma i 2.0 1.0)))
double code(double i) {
return (i * (i * (0.25 / fma(i, 2.0, -1.0)))) / fma(i, 2.0, 1.0);
}
function code(i) return Float64(Float64(i * Float64(i * Float64(0.25 / fma(i, 2.0, -1.0)))) / fma(i, 2.0, 1.0)) end
code[i_] := N[(N[(i * N[(i * N[(0.25 / N[(i * 2.0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(i * 2.0 + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{i \cdot \left(i \cdot \frac{0.25}{\mathsf{fma}\left(i, 2, -1\right)}\right)}{\mathsf{fma}\left(i, 2, 1\right)}
\end{array}
Initial program 32.4%
associate-*r*32.3%
unpow332.2%
associate-*r*32.2%
times-frac56.9%
*-commutative56.9%
associate-*l*56.9%
metadata-eval56.9%
Applied egg-rr56.9%
cube-mult57.0%
*-commutative57.0%
times-frac71.1%
add-sqr-sqrt71.1%
sqrt-prod52.0%
sqr-neg52.0%
distribute-rgt-neg-out52.0%
distribute-rgt-neg-out52.0%
sqrt-unprod19.5%
add-sqr-sqrt20.8%
distribute-rgt-neg-out20.8%
neg-sub020.8%
metadata-eval20.8%
add-sqr-sqrt20.8%
sqrt-prod1.3%
sqr-neg1.3%
sqrt-unprod0.0%
add-sqr-sqrt71.1%
neg-sub071.1%
sub-neg71.1%
add-sqr-sqrt0.0%
sqrt-unprod1.3%
sqr-neg1.3%
sqrt-prod20.8%
add-sqr-sqrt20.8%
Applied egg-rr71.1%
expm1-log1p-u69.2%
expm1-undefine69.2%
log1p-undefine69.2%
+-commutative69.2%
add-exp-log71.1%
*-commutative71.1%
fma-define71.1%
Applied egg-rr71.1%
*-inverses71.1%
*-un-lft-identity71.1%
*-rgt-identity71.1%
*-un-lft-identity71.1%
*-commutative71.1%
fma-neg71.1%
add-exp-log69.2%
fma-undefine69.2%
*-commutative69.2%
+-commutative69.2%
log1p-undefine69.2%
expm1-undefine69.2%
expm1-log1p-u71.1%
fma-neg71.1%
difference-of-sqr-171.1%
*-commutative71.1%
fma-undefine71.1%
Applied egg-rr99.9%
associate-*l/100.0%
associate-/l*99.8%
Simplified99.8%
(FPCore (i) :precision binary64 (if (<= i 50000000.0) (/ (/ (* i (- i)) -4.0) (+ (* (* i 2.0) (* i 2.0)) -1.0)) 0.0625))
double code(double i) {
double tmp;
if (i <= 50000000.0) {
tmp = ((i * -i) / -4.0) / (((i * 2.0) * (i * 2.0)) + -1.0);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 50000000.0d0) then
tmp = ((i * -i) / (-4.0d0)) / (((i * 2.0d0) * (i * 2.0d0)) + (-1.0d0))
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 50000000.0) {
tmp = ((i * -i) / -4.0) / (((i * 2.0) * (i * 2.0)) + -1.0);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 50000000.0: tmp = ((i * -i) / -4.0) / (((i * 2.0) * (i * 2.0)) + -1.0) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 50000000.0) tmp = Float64(Float64(Float64(i * Float64(-i)) / -4.0) / Float64(Float64(Float64(i * 2.0) * Float64(i * 2.0)) + -1.0)); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 50000000.0) tmp = ((i * -i) / -4.0) / (((i * 2.0) * (i * 2.0)) + -1.0); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 50000000.0], N[(N[(N[(i * (-i)), $MachinePrecision] / -4.0), $MachinePrecision] / N[(N[(N[(i * 2.0), $MachinePrecision] * N[(i * 2.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 50000000:\\
\;\;\;\;\frac{\frac{i \cdot \left(-i\right)}{-4}}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + -1}\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 5e7Initial program 40.1%
associate-*r*40.0%
unpow339.9%
associate-*r*39.9%
times-frac87.7%
*-commutative87.7%
associate-*l*87.7%
metadata-eval87.7%
Applied egg-rr87.7%
cube-mult87.8%
*-commutative87.8%
times-frac100.0%
add-sqr-sqrt100.0%
sqrt-prod81.8%
sqr-neg81.8%
distribute-rgt-neg-out81.8%
distribute-rgt-neg-out81.8%
sqrt-unprod41.7%
add-sqr-sqrt43.6%
distribute-rgt-neg-out43.6%
neg-sub043.6%
metadata-eval43.6%
add-sqr-sqrt43.6%
sqrt-prod2.0%
sqr-neg2.0%
sqrt-unprod0.0%
add-sqr-sqrt100.0%
neg-sub0100.0%
sub-neg100.0%
add-sqr-sqrt0.0%
sqrt-unprod2.0%
sqr-neg2.0%
sqrt-prod43.6%
add-sqr-sqrt43.6%
Applied egg-rr100.0%
Taylor expanded in i around 0 100.0%
*-rgt-identity100.0%
frac-2neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if 5e7 < i Initial program 25.6%
Simplified47.0%
Taylor expanded in i around inf 100.0%
Final simplification100.0%
(FPCore (i) :precision binary64 (if (<= i 50000000.0) (/ (/ i (/ 4.0 i)) (+ (* (* i 2.0) (* i 2.0)) -1.0)) 0.0625))
double code(double i) {
double tmp;
if (i <= 50000000.0) {
tmp = (i / (4.0 / i)) / (((i * 2.0) * (i * 2.0)) + -1.0);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 50000000.0d0) then
tmp = (i / (4.0d0 / i)) / (((i * 2.0d0) * (i * 2.0d0)) + (-1.0d0))
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 50000000.0) {
tmp = (i / (4.0 / i)) / (((i * 2.0) * (i * 2.0)) + -1.0);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 50000000.0: tmp = (i / (4.0 / i)) / (((i * 2.0) * (i * 2.0)) + -1.0) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 50000000.0) tmp = Float64(Float64(i / Float64(4.0 / i)) / Float64(Float64(Float64(i * 2.0) * Float64(i * 2.0)) + -1.0)); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 50000000.0) tmp = (i / (4.0 / i)) / (((i * 2.0) * (i * 2.0)) + -1.0); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 50000000.0], N[(N[(i / N[(4.0 / i), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(i * 2.0), $MachinePrecision] * N[(i * 2.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 50000000:\\
\;\;\;\;\frac{\frac{i}{\frac{4}{i}}}{\left(i \cdot 2\right) \cdot \left(i \cdot 2\right) + -1}\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 5e7Initial program 40.1%
associate-*r*40.0%
unpow339.9%
associate-*r*39.9%
times-frac87.7%
*-commutative87.7%
associate-*l*87.7%
metadata-eval87.7%
Applied egg-rr87.7%
cube-mult87.8%
*-commutative87.8%
times-frac100.0%
add-sqr-sqrt100.0%
sqrt-prod81.8%
sqr-neg81.8%
distribute-rgt-neg-out81.8%
distribute-rgt-neg-out81.8%
sqrt-unprod41.7%
add-sqr-sqrt43.6%
distribute-rgt-neg-out43.6%
neg-sub043.6%
metadata-eval43.6%
add-sqr-sqrt43.6%
sqrt-prod2.0%
sqr-neg2.0%
sqrt-unprod0.0%
add-sqr-sqrt100.0%
neg-sub0100.0%
sub-neg100.0%
add-sqr-sqrt0.0%
sqrt-unprod2.0%
sqr-neg2.0%
sqrt-prod43.6%
add-sqr-sqrt43.6%
Applied egg-rr100.0%
Taylor expanded in i around 0 100.0%
*-rgt-identity100.0%
associate-/r/99.7%
Applied egg-rr99.7%
if 5e7 < i Initial program 25.6%
Simplified47.0%
Taylor expanded in i around inf 100.0%
Final simplification99.8%
(FPCore (i) :precision binary64 (if (<= i 0.5) (* 0.25 (* i (- i))) 0.0625))
double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = 0.25 * (i * -i);
} 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 = 0.25d0 * (i * -i)
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 0.5) {
tmp = 0.25 * (i * -i);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 0.5: tmp = 0.25 * (i * -i) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 0.5) tmp = Float64(0.25 * Float64(i * Float64(-i))); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 0.5) tmp = 0.25 * (i * -i); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 0.5], N[(0.25 * N[(i * (-i)), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 0.5:\\
\;\;\;\;0.25 \cdot \left(i \cdot \left(-i\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 0.5Initial program 36.4%
Simplified100.0%
Taylor expanded in i around 0 98.5%
neg-mul-198.5%
Simplified98.5%
if 0.5 < i Initial program 29.2%
Simplified49.6%
Taylor expanded in i around inf 98.1%
(FPCore (i) :precision binary64 (if (<= i 0.8) (* 0.25 (* i i)) 0.0625))
double code(double i) {
double tmp;
if (i <= 0.8) {
tmp = 0.25 * (i * i);
} else {
tmp = 0.0625;
}
return tmp;
}
real(8) function code(i)
real(8), intent (in) :: i
real(8) :: tmp
if (i <= 0.8d0) then
tmp = 0.25d0 * (i * i)
else
tmp = 0.0625d0
end if
code = tmp
end function
public static double code(double i) {
double tmp;
if (i <= 0.8) {
tmp = 0.25 * (i * i);
} else {
tmp = 0.0625;
}
return tmp;
}
def code(i): tmp = 0 if i <= 0.8: tmp = 0.25 * (i * i) else: tmp = 0.0625 return tmp
function code(i) tmp = 0.0 if (i <= 0.8) tmp = Float64(0.25 * Float64(i * i)); else tmp = 0.0625; end return tmp end
function tmp_2 = code(i) tmp = 0.0; if (i <= 0.8) tmp = 0.25 * (i * i); else tmp = 0.0625; end tmp_2 = tmp; end
code[i_] := If[LessEqual[i, 0.8], N[(0.25 * N[(i * i), $MachinePrecision]), $MachinePrecision], 0.0625]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;i \leq 0.8:\\
\;\;\;\;0.25 \cdot \left(i \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;0.0625\\
\end{array}
\end{array}
if i < 0.80000000000000004Initial program 36.4%
Simplified100.0%
Taylor expanded in i around 0 98.5%
neg-mul-198.5%
Simplified98.5%
neg-sub098.5%
sub-neg98.5%
add-sqr-sqrt0.0%
sqrt-unprod46.2%
sqr-neg46.2%
sqrt-prod46.2%
add-sqr-sqrt46.2%
Applied egg-rr46.2%
+-lft-identity46.2%
Simplified46.2%
if 0.80000000000000004 < i Initial program 29.2%
Simplified49.6%
Taylor expanded in i around inf 98.1%
(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 32.4%
Simplified71.8%
Taylor expanded in i around inf 56.0%
herbie shell --seed 2024129
(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)))