
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
(FPCore (re im) :precision binary64 (if (<= (- (sqrt (+ (* re re) (* im im))) re) 0.0) (* 0.5 (* im (pow re -0.5))) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
double code(double re, double im) {
double tmp;
if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = 0.5 * (im * pow(re, -0.5));
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((Math.sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (math.sqrt(((re * re) + (im * im))) - re) <= 0.0: tmp = 0.5 * (im * math.pow(re, -0.5)) else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re) <= 0.0) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) tmp = 0.5 * (im * (re ^ -0.5)); else tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision], 0.0], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 8.4%
Taylor expanded in re around inf 38.9%
associate-*r*38.9%
metadata-eval38.9%
*-un-lft-identity38.9%
div-inv39.0%
sqrt-prod45.5%
unpow245.5%
sqrt-prod96.9%
add-log-exp10.1%
add-sqr-sqrt10.1%
pow110.1%
metadata-eval10.1%
metadata-eval10.1%
sqrt-unprod10.1%
exp-prod10.1%
associate-*l*10.1%
add-log-exp96.5%
*-commutative96.5%
Applied egg-rr97.4%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 43.3%
sub-neg43.3%
sqr-neg43.3%
sub-neg43.3%
sqr-neg43.3%
hypot-define88.6%
Simplified88.6%
Final simplification89.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re -5.4e+60)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 6e-164)
t_0
(if (<= re 5.4e-89)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 9.6e-49) t_0 (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((im * 2.0));
double tmp;
if (re <= -5.4e+60) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 6e-164) {
tmp = t_0;
} else if (re <= 5.4e-89) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 9.6e-49) {
tmp = t_0;
} else {
tmp = 0.5 * (im / sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt((im * 2.0d0))
if (re <= (-5.4d+60)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 6d-164) then
tmp = t_0
else if (re <= 5.4d-89) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 9.6d-49) then
tmp = t_0
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((im * 2.0));
double tmp;
if (re <= -5.4e+60) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 6e-164) {
tmp = t_0;
} else if (re <= 5.4e-89) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 9.6e-49) {
tmp = t_0;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((im * 2.0)) tmp = 0 if re <= -5.4e+60: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 6e-164: tmp = t_0 elif re <= 5.4e-89: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 9.6e-49: tmp = t_0 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(im * 2.0))) tmp = 0.0 if (re <= -5.4e+60) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 6e-164) tmp = t_0; elseif (re <= 5.4e-89) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 9.6e-49) tmp = t_0; else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((im * 2.0)); tmp = 0.0; if (re <= -5.4e+60) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 6e-164) tmp = t_0; elseif (re <= 5.4e-89) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 9.6e-49) tmp = t_0; else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -5.4e+60], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6e-164], t$95$0, If[LessEqual[re, 5.4e-89], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 9.6e-49], t$95$0, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{if}\;re \leq -5.4 \cdot 10^{+60}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 6 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 5.4 \cdot 10^{-89}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 9.6 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.3999999999999999e60Initial program 30.0%
Taylor expanded in re around -inf 84.3%
*-commutative84.3%
Simplified84.3%
if -5.3999999999999999e60 < re < 6.0000000000000002e-164 or 5.39999999999999975e-89 < re < 9.59999999999999969e-49Initial program 60.9%
Taylor expanded in re around 0 80.8%
Taylor expanded in im around inf 80.3%
if 6.0000000000000002e-164 < re < 5.39999999999999975e-89Initial program 20.2%
Taylor expanded in re around inf 8.5%
associate-*r*8.5%
metadata-eval8.5%
*-un-lft-identity8.5%
div-inv8.5%
sqrt-prod8.5%
unpow28.5%
sqrt-prod63.4%
add-log-exp4.4%
add-sqr-sqrt4.4%
pow14.4%
metadata-eval4.4%
metadata-eval4.4%
sqrt-unprod4.4%
exp-prod4.4%
associate-*l*4.4%
add-log-exp62.8%
*-commutative62.8%
Applied egg-rr63.5%
if 9.59999999999999969e-49 < re Initial program 14.6%
Taylor expanded in re around inf 45.5%
*-un-lft-identity45.5%
associate-*r*45.5%
metadata-eval45.5%
*-un-lft-identity45.5%
sqrt-div58.1%
sqrt-pow176.9%
metadata-eval76.9%
pow176.9%
Applied egg-rr76.9%
*-lft-identity76.9%
Simplified76.9%
Final simplification78.9%
(FPCore (re im)
:precision binary64
(if (<= re -6e+87)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 5.7e-164)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 5.4e-89)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 5.9e-49)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (/ im (sqrt re))))))))
double code(double re, double im) {
double tmp;
if (re <= -6e+87) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 5.7e-164) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 5.4e-89) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 5.9e-49) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-6d+87)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 5.7d-164) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 5.4d-89) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 5.9d-49) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -6e+87) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 5.7e-164) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 5.4e-89) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 5.9e-49) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6e+87: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 5.7e-164: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 5.4e-89: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 5.9e-49: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -6e+87) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 5.7e-164) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 5.4e-89) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 5.9e-49) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -6e+87) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 5.7e-164) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 5.4e-89) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 5.9e-49) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6e+87], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.7e-164], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.4e-89], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.9e-49], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6 \cdot 10^{+87}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 5.7 \cdot 10^{-164}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 5.4 \cdot 10^{-89}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 5.9 \cdot 10^{-49}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.9999999999999998e87Initial program 26.2%
Taylor expanded in re around -inf 86.8%
*-commutative86.8%
Simplified86.8%
if -5.9999999999999998e87 < re < 5.70000000000000023e-164Initial program 63.0%
Taylor expanded in re around 0 81.4%
if 5.70000000000000023e-164 < re < 5.39999999999999975e-89Initial program 20.2%
Taylor expanded in re around inf 8.5%
associate-*r*8.5%
metadata-eval8.5%
*-un-lft-identity8.5%
div-inv8.5%
sqrt-prod8.5%
unpow28.5%
sqrt-prod63.4%
add-log-exp4.4%
add-sqr-sqrt4.4%
pow14.4%
metadata-eval4.4%
metadata-eval4.4%
sqrt-unprod4.4%
exp-prod4.4%
associate-*l*4.4%
add-log-exp62.8%
*-commutative62.8%
Applied egg-rr63.5%
if 5.39999999999999975e-89 < re < 5.90000000000000037e-49Initial program 40.1%
Taylor expanded in re around 0 88.1%
Taylor expanded in im around inf 88.4%
if 5.90000000000000037e-49 < re Initial program 14.6%
Taylor expanded in re around inf 45.5%
*-un-lft-identity45.5%
associate-*r*45.5%
metadata-eval45.5%
*-un-lft-identity45.5%
sqrt-div58.1%
sqrt-pow176.9%
metadata-eval76.9%
pow176.9%
Applied egg-rr76.9%
*-lft-identity76.9%
Simplified76.9%
Final simplification80.1%
(FPCore (re im) :precision binary64 (if (or (<= re 6e-164) (and (not (<= re 6e-89)) (<= re 4e-49))) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (/ im (sqrt re)))))
double code(double re, double im) {
double tmp;
if ((re <= 6e-164) || (!(re <= 6e-89) && (re <= 4e-49))) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= 6d-164) .or. (.not. (re <= 6d-89)) .and. (re <= 4d-49)) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= 6e-164) || (!(re <= 6e-89) && (re <= 4e-49))) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= 6e-164) or (not (re <= 6e-89) and (re <= 4e-49)): tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if ((re <= 6e-164) || (!(re <= 6e-89) && (re <= 4e-49))) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= 6e-164) || (~((re <= 6e-89)) && (re <= 4e-49))) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, 6e-164], And[N[Not[LessEqual[re, 6e-89]], $MachinePrecision], LessEqual[re, 4e-49]]], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 6 \cdot 10^{-164} \lor \neg \left(re \leq 6 \cdot 10^{-89}\right) \land re \leq 4 \cdot 10^{-49}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 6.0000000000000002e-164 or 5.9999999999999999e-89 < re < 3.99999999999999975e-49Initial program 51.1%
Taylor expanded in re around 0 61.9%
Taylor expanded in im around inf 61.4%
if 6.0000000000000002e-164 < re < 5.9999999999999999e-89 or 3.99999999999999975e-49 < re Initial program 15.7%
Taylor expanded in re around inf 38.3%
*-un-lft-identity38.3%
associate-*r*38.3%
metadata-eval38.3%
*-un-lft-identity38.3%
sqrt-div48.5%
sqrt-pow174.3%
metadata-eval74.3%
pow174.3%
Applied egg-rr74.3%
*-lft-identity74.3%
Simplified74.3%
Final simplification66.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re 6e-164)
t_0
(if (<= re 7e-89)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 1.6e-50) t_0 (* 0.5 (/ im (sqrt re))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((im * 2.0));
double tmp;
if (re <= 6e-164) {
tmp = t_0;
} else if (re <= 7e-89) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 1.6e-50) {
tmp = t_0;
} else {
tmp = 0.5 * (im / sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt((im * 2.0d0))
if (re <= 6d-164) then
tmp = t_0
else if (re <= 7d-89) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 1.6d-50) then
tmp = t_0
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((im * 2.0));
double tmp;
if (re <= 6e-164) {
tmp = t_0;
} else if (re <= 7e-89) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 1.6e-50) {
tmp = t_0;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((im * 2.0)) tmp = 0 if re <= 6e-164: tmp = t_0 elif re <= 7e-89: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 1.6e-50: tmp = t_0 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(im * 2.0))) tmp = 0.0 if (re <= 6e-164) tmp = t_0; elseif (re <= 7e-89) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 1.6e-50) tmp = t_0; else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((im * 2.0)); tmp = 0.0; if (re <= 6e-164) tmp = t_0; elseif (re <= 7e-89) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 1.6e-50) tmp = t_0; else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, 6e-164], t$95$0, If[LessEqual[re, 7e-89], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.6e-50], t$95$0, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{if}\;re \leq 6 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;re \leq 7 \cdot 10^{-89}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 1.6 \cdot 10^{-50}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 6.0000000000000002e-164 or 6.9999999999999994e-89 < re < 1.6e-50Initial program 51.1%
Taylor expanded in re around 0 61.9%
Taylor expanded in im around inf 61.4%
if 6.0000000000000002e-164 < re < 6.9999999999999994e-89Initial program 20.2%
Taylor expanded in re around inf 8.5%
associate-*r*8.5%
metadata-eval8.5%
*-un-lft-identity8.5%
div-inv8.5%
sqrt-prod8.5%
unpow28.5%
sqrt-prod63.4%
add-log-exp4.4%
add-sqr-sqrt4.4%
pow14.4%
metadata-eval4.4%
metadata-eval4.4%
sqrt-unprod4.4%
exp-prod4.4%
associate-*l*4.4%
add-log-exp62.8%
*-commutative62.8%
Applied egg-rr63.5%
if 1.6e-50 < re Initial program 14.6%
Taylor expanded in re around inf 45.5%
*-un-lft-identity45.5%
associate-*r*45.5%
metadata-eval45.5%
*-un-lft-identity45.5%
sqrt-div58.1%
sqrt-pow176.9%
metadata-eval76.9%
pow176.9%
Applied egg-rr76.9%
*-lft-identity76.9%
Simplified76.9%
Final simplification66.1%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
double code(double re, double im) {
return 0.5 * sqrt((im * 2.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((im * 2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((im * 2.0));
}
def code(re, im): return 0.5 * math.sqrt((im * 2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(im * 2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((im * 2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Initial program 38.2%
Taylor expanded in re around 0 50.1%
Taylor expanded in im around inf 50.1%
Final simplification50.1%
herbie shell --seed 2024112
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))