
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(*
(/ 1.0 2.0)
(+
1.0
(/
1.0
(sqrt
(+
1.0
(*
(pow (/ (* 2.0 l) Om) 2.0)
(+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))))))
double code(double l, double Om, double kx, double ky) {
return sqrt(((1.0 / 2.0) * (1.0 + (1.0 / sqrt((1.0 + (pow(((2.0 * l) / Om), 2.0) * (pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))))))));
}
real(8) function code(l, om, kx, ky)
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: kx
real(8), intent (in) :: ky
code = sqrt(((1.0d0 / 2.0d0) * (1.0d0 + (1.0d0 / sqrt((1.0d0 + ((((2.0d0 * l) / om) ** 2.0d0) * ((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))))))))
end function
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt(((1.0 / 2.0) * (1.0 + (1.0 / Math.sqrt((1.0 + (Math.pow(((2.0 * l) / Om), 2.0) * (Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))))))));
}
def code(l, Om, kx, ky): return math.sqrt(((1.0 / 2.0) * (1.0 + (1.0 / math.sqrt((1.0 + (math.pow(((2.0 * l) / Om), 2.0) * (math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))))))))
function code(l, Om, kx, ky) return sqrt(Float64(Float64(1.0 / 2.0) * Float64(1.0 + Float64(1.0 / sqrt(Float64(1.0 + Float64((Float64(Float64(2.0 * l) / Om) ^ 2.0) * Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))))))) end
function tmp = code(l, Om, kx, ky) tmp = sqrt(((1.0 / 2.0) * (1.0 + (1.0 / sqrt((1.0 + ((((2.0 * l) / Om) ^ 2.0) * ((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))))))); end
code[l_, Om_, kx_, ky_] := N[Sqrt[N[(N[(1.0 / 2.0), $MachinePrecision] * N[(1.0 + N[(1.0 / N[Sqrt[N[(1.0 + N[(N[Power[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(*
(/ 1.0 2.0)
(+
1.0
(/
1.0
(sqrt
(+
1.0
(*
(pow (/ (* 2.0 l) Om) 2.0)
(+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))))))
double code(double l, double Om, double kx, double ky) {
return sqrt(((1.0 / 2.0) * (1.0 + (1.0 / sqrt((1.0 + (pow(((2.0 * l) / Om), 2.0) * (pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))))))));
}
real(8) function code(l, om, kx, ky)
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: kx
real(8), intent (in) :: ky
code = sqrt(((1.0d0 / 2.0d0) * (1.0d0 + (1.0d0 / sqrt((1.0d0 + ((((2.0d0 * l) / om) ** 2.0d0) * ((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))))))))
end function
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt(((1.0 / 2.0) * (1.0 + (1.0 / Math.sqrt((1.0 + (Math.pow(((2.0 * l) / Om), 2.0) * (Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))))))));
}
def code(l, Om, kx, ky): return math.sqrt(((1.0 / 2.0) * (1.0 + (1.0 / math.sqrt((1.0 + (math.pow(((2.0 * l) / Om), 2.0) * (math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))))))))
function code(l, Om, kx, ky) return sqrt(Float64(Float64(1.0 / 2.0) * Float64(1.0 + Float64(1.0 / sqrt(Float64(1.0 + Float64((Float64(Float64(2.0 * l) / Om) ^ 2.0) * Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))))))) end
function tmp = code(l, Om, kx, ky) tmp = sqrt(((1.0 / 2.0) * (1.0 + (1.0 / sqrt((1.0 + ((((2.0 * l) / Om) ^ 2.0) * ((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))))))); end
code[l_, Om_, kx_, ky_] := N[Sqrt[N[(N[(1.0 / 2.0), $MachinePrecision] * N[(1.0 + N[(1.0 / N[Sqrt[N[(1.0 + N[(N[Power[N[(N[(2.0 * l), $MachinePrecision] / Om), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{2} \cdot \left(1 + \frac{1}{\sqrt{1 + {\left(\frac{2 \cdot \ell}{Om}\right)}^{2} \cdot \left({\sin kx}^{2} + {\sin ky}^{2}\right)}}\right)}
\end{array}
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(+
0.5
(*
0.5
(/
1.0
(sqrt
(+
1.0
(exp
(* 2.0 (log (* (* l (/ 2.0 Om)) (hypot (sin kx) (sin ky)))))))))))))l = abs(l);
Om = abs(Om);
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 * (1.0 / sqrt((1.0 + exp((2.0 * log(((l * (2.0 / Om)) * hypot(sin(kx), sin(ky))))))))))));
}
l = Math.abs(l);
Om = Math.abs(Om);
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt((0.5 + (0.5 * (1.0 / Math.sqrt((1.0 + Math.exp((2.0 * Math.log(((l * (2.0 / Om)) * Math.hypot(Math.sin(kx), Math.sin(ky))))))))))));
}
l = abs(l) Om = abs(Om) def code(l, Om, kx, ky): return math.sqrt((0.5 + (0.5 * (1.0 / math.sqrt((1.0 + math.exp((2.0 * math.log(((l * (2.0 / Om)) * math.hypot(math.sin(kx), math.sin(ky))))))))))))
l = abs(l) Om = abs(Om) function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / sqrt(Float64(1.0 + exp(Float64(2.0 * log(Float64(Float64(l * Float64(2.0 / Om)) * hypot(sin(kx), sin(ky)))))))))))) end
l = abs(l) Om = abs(Om) function tmp = code(l, Om, kx, ky) tmp = sqrt((0.5 + (0.5 * (1.0 / sqrt((1.0 + exp((2.0 * log(((l * (2.0 / Om)) * hypot(sin(kx), sin(ky)))))))))))); end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[Sqrt[N[(1.0 + N[Exp[N[(2.0 * N[Log[N[(N[(l * N[(2.0 / Om), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
\\
\sqrt{0.5 + 0.5 \cdot \frac{1}{\sqrt{1 + e^{2 \cdot \log \left(\left(\ell \cdot \frac{2}{Om}\right) \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}}}}
\end{array}
Initial program 98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
metadata-eval98.0%
associate-/l*98.0%
metadata-eval98.0%
Simplified98.0%
add-exp-log98.0%
add-sqr-sqrt98.0%
pow298.0%
sqrt-prod98.0%
unpow298.0%
sqrt-prod55.1%
add-sqr-sqrt98.1%
associate-/r/98.1%
*-commutative98.1%
unpow298.1%
unpow298.1%
hypot-def100.0%
Applied egg-rr100.0%
pow-to-exp58.2%
add-log-exp58.2%
Applied egg-rr58.2%
Final simplification58.2%
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
(FPCore (l Om kx ky)
:precision binary64
(sqrt
(+
0.5
(*
0.5
(/ 1.0 (hypot 1.0 (* (hypot (sin ky) (sin kx)) (* 2.0 (/ l Om)))))))))l = abs(l);
Om = abs(Om);
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 * (1.0 / hypot(1.0, (hypot(sin(ky), sin(kx)) * (2.0 * (l / Om))))))));
}
l = Math.abs(l);
Om = Math.abs(Om);
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt((0.5 + (0.5 * (1.0 / Math.hypot(1.0, (Math.hypot(Math.sin(ky), Math.sin(kx)) * (2.0 * (l / Om))))))));
}
l = abs(l) Om = abs(Om) def code(l, Om, kx, ky): return math.sqrt((0.5 + (0.5 * (1.0 / math.hypot(1.0, (math.hypot(math.sin(ky), math.sin(kx)) * (2.0 * (l / Om))))))))
l = abs(l) Om = abs(Om) function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 * Float64(1.0 / hypot(1.0, Float64(hypot(sin(ky), sin(kx)) * Float64(2.0 * Float64(l / Om)))))))) end
l = abs(l) Om = abs(Om) function tmp = code(l, Om, kx, ky) tmp = sqrt((0.5 + (0.5 * (1.0 / hypot(1.0, (hypot(sin(ky), sin(kx)) * (2.0 * (l / Om)))))))); end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 * N[(1.0 / N[Sqrt[1.0 ^ 2 + N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] * N[(2.0 * N[(l / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
\\
\sqrt{0.5 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, \mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}
\end{array}
Initial program 98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
metadata-eval98.0%
associate-/l*98.0%
metadata-eval98.0%
Simplified98.0%
expm1-log1p-u98.0%
expm1-udef98.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
hypot-def98.1%
unpow298.1%
unpow298.1%
+-commutative98.1%
unpow298.1%
unpow298.1%
hypot-def100.0%
*-commutative100.0%
associate-*l/100.0%
associate-*r/100.0%
Simplified100.0%
Final simplification100.0%
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function (FPCore (l Om kx ky) :precision binary64 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 (* (sin ky) (* 2.0 (/ l Om))))))))
l = abs(l);
Om = abs(Om);
double code(double l, double Om, double kx, double ky) {
return sqrt((0.5 + (0.5 / hypot(1.0, (sin(ky) * (2.0 * (l / Om)))))));
}
l = Math.abs(l);
Om = Math.abs(Om);
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, (Math.sin(ky) * (2.0 * (l / Om)))))));
}
l = abs(l) Om = abs(Om) def code(l, Om, kx, ky): return math.sqrt((0.5 + (0.5 / math.hypot(1.0, (math.sin(ky) * (2.0 * (l / Om)))))))
l = abs(l) Om = abs(Om) function code(l, Om, kx, ky) return sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, Float64(sin(ky) * Float64(2.0 * Float64(l / Om))))))) end
l = abs(l) Om = abs(Om) function tmp = code(l, Om, kx, ky) tmp = sqrt((0.5 + (0.5 / hypot(1.0, (sin(ky) * (2.0 * (l / Om))))))); end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function code[l_, Om_, kx_, ky_] := N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + N[(N[Sin[ky], $MachinePrecision] * N[(2.0 * N[(l / Om), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
\\
\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, \sin ky \cdot \left(2 \cdot \frac{\ell}{Om}\right)\right)}}
\end{array}
Initial program 98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
metadata-eval98.0%
associate-/l*98.0%
metadata-eval98.0%
Simplified98.0%
expm1-log1p-u98.0%
expm1-udef98.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
hypot-def98.1%
unpow298.1%
unpow298.1%
+-commutative98.1%
unpow298.1%
unpow298.1%
hypot-def100.0%
*-commutative100.0%
associate-*l/100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in kx around 0 95.5%
expm1-log1p-u95.5%
expm1-udef95.5%
associate-*l/95.5%
metadata-eval95.5%
Applied egg-rr95.5%
expm1-def95.5%
expm1-log1p95.5%
Simplified95.5%
Final simplification95.5%
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function (FPCore (l Om kx ky) :precision binary64 (if (<= l 5.6e-93) 1.0 (if (<= l 1.2e-68) (sqrt 0.5) (if (<= l 2e+32) 1.0 (sqrt 0.5)))))
l = abs(l);
Om = abs(Om);
double code(double l, double Om, double kx, double ky) {
double tmp;
if (l <= 5.6e-93) {
tmp = 1.0;
} else if (l <= 1.2e-68) {
tmp = sqrt(0.5);
} else if (l <= 2e+32) {
tmp = 1.0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
real(8) function code(l, om, kx, ky)
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: kx
real(8), intent (in) :: ky
real(8) :: tmp
if (l <= 5.6d-93) then
tmp = 1.0d0
else if (l <= 1.2d-68) then
tmp = sqrt(0.5d0)
else if (l <= 2d+32) then
tmp = 1.0d0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
l = Math.abs(l);
Om = Math.abs(Om);
public static double code(double l, double Om, double kx, double ky) {
double tmp;
if (l <= 5.6e-93) {
tmp = 1.0;
} else if (l <= 1.2e-68) {
tmp = Math.sqrt(0.5);
} else if (l <= 2e+32) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
l = abs(l) Om = abs(Om) def code(l, Om, kx, ky): tmp = 0 if l <= 5.6e-93: tmp = 1.0 elif l <= 1.2e-68: tmp = math.sqrt(0.5) elif l <= 2e+32: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
l = abs(l) Om = abs(Om) function code(l, Om, kx, ky) tmp = 0.0 if (l <= 5.6e-93) tmp = 1.0; elseif (l <= 1.2e-68) tmp = sqrt(0.5); elseif (l <= 2e+32) tmp = 1.0; else tmp = sqrt(0.5); end return tmp end
l = abs(l) Om = abs(Om) function tmp_2 = code(l, Om, kx, ky) tmp = 0.0; if (l <= 5.6e-93) tmp = 1.0; elseif (l <= 1.2e-68) tmp = sqrt(0.5); elseif (l <= 2e+32) tmp = 1.0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function code[l_, Om_, kx_, ky_] := If[LessEqual[l, 5.6e-93], 1.0, If[LessEqual[l, 1.2e-68], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[l, 2e+32], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 5.6 \cdot 10^{-93}:\\
\;\;\;\;1\\
\mathbf{elif}\;\ell \leq 1.2 \cdot 10^{-68}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;\ell \leq 2 \cdot 10^{+32}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if l < 5.59999999999999997e-93 or 1.19999999999999996e-68 < l < 2.00000000000000011e32Initial program 98.5%
distribute-rgt-in98.5%
metadata-eval98.5%
metadata-eval98.5%
associate-/l*98.5%
metadata-eval98.5%
Simplified98.5%
expm1-log1p-u98.5%
expm1-udef98.5%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
*-commutative100.0%
hypot-def98.5%
unpow298.5%
unpow298.5%
+-commutative98.5%
unpow298.5%
unpow298.5%
hypot-def100.0%
*-commutative100.0%
associate-*l/100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in kx around 0 97.5%
add-cbrt-cube97.1%
associate-*l/97.1%
metadata-eval97.1%
associate-*l/97.1%
metadata-eval97.1%
associate-*l/97.1%
metadata-eval97.1%
Applied egg-rr97.1%
associate-*l*97.1%
cube-unmult97.1%
*-commutative97.1%
associate-*l*97.1%
Simplified97.1%
Taylor expanded in l around 0 74.7%
if 5.59999999999999997e-93 < l < 1.19999999999999996e-68 or 2.00000000000000011e32 < l Initial program 96.3%
distribute-rgt-in96.3%
metadata-eval96.3%
metadata-eval96.3%
associate-/l*96.3%
metadata-eval96.3%
Simplified96.3%
Taylor expanded in Om around 0 80.7%
associate-*r*80.7%
*-commutative80.7%
associate-*r*80.7%
unpow280.7%
unpow280.7%
hypot-def84.3%
Simplified84.3%
Taylor expanded in l around inf 86.3%
Final simplification77.2%
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function (FPCore (l Om kx ky) :precision binary64 (sqrt 0.5))
l = abs(l);
Om = abs(Om);
double code(double l, double Om, double kx, double ky) {
return sqrt(0.5);
}
NOTE: l should be positive before calling this function
NOTE: Om should be positive before calling this function
real(8) function code(l, om, kx, ky)
real(8), intent (in) :: l
real(8), intent (in) :: om
real(8), intent (in) :: kx
real(8), intent (in) :: ky
code = sqrt(0.5d0)
end function
l = Math.abs(l);
Om = Math.abs(Om);
public static double code(double l, double Om, double kx, double ky) {
return Math.sqrt(0.5);
}
l = abs(l) Om = abs(Om) def code(l, Om, kx, ky): return math.sqrt(0.5)
l = abs(l) Om = abs(Om) function code(l, Om, kx, ky) return sqrt(0.5) end
l = abs(l) Om = abs(Om) function tmp = code(l, Om, kx, ky) tmp = sqrt(0.5); end
NOTE: l should be positive before calling this function NOTE: Om should be positive before calling this function code[l_, Om_, kx_, ky_] := N[Sqrt[0.5], $MachinePrecision]
\begin{array}{l}
l = |l|\\
Om = |Om|\\
\\
\sqrt{0.5}
\end{array}
Initial program 98.0%
distribute-rgt-in98.0%
metadata-eval98.0%
metadata-eval98.0%
associate-/l*98.0%
metadata-eval98.0%
Simplified98.0%
Taylor expanded in Om around 0 42.1%
associate-*r*42.1%
*-commutative42.1%
associate-*r*42.1%
unpow242.1%
unpow242.1%
hypot-def44.1%
Simplified44.1%
Taylor expanded in l around inf 53.6%
Final simplification53.6%
herbie shell --seed 2023242
(FPCore (l Om kx ky)
:name "Toniolo and Linder, Equation (3a)"
:precision binary64
(sqrt (* (/ 1.0 2.0) (+ 1.0 (/ 1.0 (sqrt (+ 1.0 (* (pow (/ (* 2.0 l) Om) 2.0) (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))))))