
(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.8%
hypot-udef18.5%
add-cbrt-cube17.8%
pow1/317.3%
add-sqr-sqrt17.3%
pow117.3%
pow1/217.3%
pow-prod-up17.3%
metadata-eval17.3%
Applied egg-rr17.3%
unpow1/317.8%
Simplified17.8%
Taylor expanded in im around 0 92.2%
unpow1/292.2%
exp-to-pow86.8%
*-commutative86.8%
log-rec86.8%
neg-mul-186.8%
associate-*r*86.8%
metadata-eval86.8%
log-pow86.8%
rem-exp-log92.2%
Simplified92.2%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 45.7%
sub-neg45.7%
sqr-neg45.7%
sub-neg45.7%
sqr-neg45.7%
hypot-def90.8%
Simplified90.8%
Final simplification91.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re -2.7e+30)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 7.5e-54)
t_0
(if (<= re 2.2e+32)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 1e+70) 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 <= -2.7e+30) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 7.5e-54) {
tmp = t_0;
} else if (re <= 2.2e+32) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 1e+70) {
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 <= (-2.7d+30)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 7.5d-54) then
tmp = t_0
else if (re <= 2.2d+32) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 1d+70) 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 <= -2.7e+30) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 7.5e-54) {
tmp = t_0;
} else if (re <= 2.2e+32) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 1e+70) {
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 <= -2.7e+30: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 7.5e-54: tmp = t_0 elif re <= 2.2e+32: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 1e+70: 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 <= -2.7e+30) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 7.5e-54) tmp = t_0; elseif (re <= 2.2e+32) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 1e+70) 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 <= -2.7e+30) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 7.5e-54) tmp = t_0; elseif (re <= 2.2e+32) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 1e+70) 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, -2.7e+30], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.5e-54], t$95$0, If[LessEqual[re, 2.2e+32], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1e+70], 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 -2.7 \cdot 10^{+30}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 7.5 \cdot 10^{-54}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 2.2 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 10^{+70}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.6999999999999999e30Initial program 35.2%
Taylor expanded in re around -inf 83.0%
*-commutative83.0%
Simplified83.0%
if -2.6999999999999999e30 < re < 7.5000000000000005e-54 or 2.20000000000000001e32 < re < 1.00000000000000007e70Initial program 57.5%
hypot-udef91.4%
sub-neg91.4%
+-commutative91.4%
add-cbrt-cube85.8%
cbrt-prod89.2%
distribute-rgt-neg-in89.2%
fma-def89.2%
cbrt-prod91.3%
pow291.3%
Applied egg-rr91.3%
Taylor expanded in re around 0 77.3%
if 7.5000000000000005e-54 < re < 2.20000000000000001e32Initial program 20.1%
hypot-udef39.3%
add-cbrt-cube24.6%
pow1/323.4%
add-sqr-sqrt23.4%
pow123.4%
pow1/223.4%
pow-prod-up23.4%
metadata-eval23.4%
Applied egg-rr23.4%
unpow1/324.7%
Simplified24.7%
Taylor expanded in im around 0 66.7%
unpow1/266.7%
exp-to-pow64.1%
*-commutative64.1%
log-rec64.1%
neg-mul-164.1%
associate-*r*64.1%
metadata-eval64.1%
log-pow64.1%
rem-exp-log66.8%
Simplified66.8%
if 1.00000000000000007e70 < re Initial program 7.8%
Taylor expanded in im around 0 81.6%
*-commutative81.6%
Simplified81.6%
expm1-log1p-u81.1%
expm1-udef32.3%
sqrt-unprod32.3%
metadata-eval32.3%
metadata-eval32.3%
*-rgt-identity32.3%
add-sqr-sqrt32.3%
sqrt-prod27.9%
unpow227.9%
sqrt-prod27.9%
div-inv27.9%
sqrt-div27.9%
unpow227.9%
sqrt-prod32.3%
add-sqr-sqrt32.3%
Applied egg-rr32.3%
expm1-def81.9%
expm1-log1p82.5%
Simplified82.5%
Final simplification78.8%
(FPCore (re im)
:precision binary64
(if (<= re -2.7e+35)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 3.1e-54)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 6.8e+31)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 1.1e+69)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (/ im (sqrt re))))))))
double code(double re, double im) {
double tmp;
if (re <= -2.7e+35) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 3.1e-54) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 6.8e+31) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 1.1e+69) {
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 <= (-2.7d+35)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 3.1d-54) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 6.8d+31) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 1.1d+69) 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 <= -2.7e+35) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 3.1e-54) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 6.8e+31) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 1.1e+69) {
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 <= -2.7e+35: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 3.1e-54: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 6.8e+31: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 1.1e+69: 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 <= -2.7e+35) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 3.1e-54) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 6.8e+31) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 1.1e+69) 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 <= -2.7e+35) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 3.1e-54) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 6.8e+31) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 1.1e+69) 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, -2.7e+35], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.1e-54], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.8e+31], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.1e+69], 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 -2.7 \cdot 10^{+35}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 3.1 \cdot 10^{-54}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 6.8 \cdot 10^{+31}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 1.1 \cdot 10^{+69}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.70000000000000003e35Initial program 34.6%
Taylor expanded in re around -inf 84.0%
*-commutative84.0%
Simplified84.0%
if -2.70000000000000003e35 < re < 3.10000000000000004e-54Initial program 57.1%
Taylor expanded in re around 0 77.9%
if 3.10000000000000004e-54 < re < 6.7999999999999996e31Initial program 20.1%
hypot-udef39.3%
add-cbrt-cube24.6%
pow1/323.4%
add-sqr-sqrt23.4%
pow123.4%
pow1/223.4%
pow-prod-up23.4%
metadata-eval23.4%
Applied egg-rr23.4%
unpow1/324.7%
Simplified24.7%
Taylor expanded in im around 0 66.7%
unpow1/266.7%
exp-to-pow64.1%
*-commutative64.1%
log-rec64.1%
neg-mul-164.1%
associate-*r*64.1%
metadata-eval64.1%
log-pow64.1%
rem-exp-log66.8%
Simplified66.8%
if 6.7999999999999996e31 < re < 1.1000000000000001e69Initial program 64.4%
hypot-udef96.9%
sub-neg96.9%
+-commutative96.9%
add-cbrt-cube96.9%
cbrt-prod96.9%
distribute-rgt-neg-in96.9%
fma-def97.0%
cbrt-prod97.0%
pow297.0%
Applied egg-rr97.0%
Taylor expanded in re around 0 85.9%
if 1.1000000000000001e69 < re Initial program 7.8%
Taylor expanded in im around 0 81.6%
*-commutative81.6%
Simplified81.6%
expm1-log1p-u81.1%
expm1-udef32.3%
sqrt-unprod32.3%
metadata-eval32.3%
metadata-eval32.3%
*-rgt-identity32.3%
add-sqr-sqrt32.3%
sqrt-prod27.9%
unpow227.9%
sqrt-prod27.9%
div-inv27.9%
sqrt-div27.9%
unpow227.9%
sqrt-prod32.3%
add-sqr-sqrt32.3%
Applied egg-rr32.3%
expm1-def81.9%
expm1-log1p82.5%
Simplified82.5%
Final simplification79.5%
(FPCore (re im) :precision binary64 (if (or (<= re 2.4e-54) (and (not (<= re 5.6e+32)) (<= re 1.85e+68))) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (/ im (sqrt re)))))
double code(double re, double im) {
double tmp;
if ((re <= 2.4e-54) || (!(re <= 5.6e+32) && (re <= 1.85e+68))) {
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 <= 2.4d-54) .or. (.not. (re <= 5.6d+32)) .and. (re <= 1.85d+68)) 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 <= 2.4e-54) || (!(re <= 5.6e+32) && (re <= 1.85e+68))) {
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 <= 2.4e-54) or (not (re <= 5.6e+32) and (re <= 1.85e+68)): 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 <= 2.4e-54) || (!(re <= 5.6e+32) && (re <= 1.85e+68))) 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 <= 2.4e-54) || (~((re <= 5.6e+32)) && (re <= 1.85e+68))) 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, 2.4e-54], And[N[Not[LessEqual[re, 5.6e+32]], $MachinePrecision], LessEqual[re, 1.85e+68]]], 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 2.4 \cdot 10^{-54} \lor \neg \left(re \leq 5.6 \cdot 10^{+32}\right) \land re \leq 1.85 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 2.40000000000000013e-54 or 5.6e32 < re < 1.84999999999999999e68Initial program 49.9%
hypot-udef94.3%
sub-neg94.3%
+-commutative94.3%
add-cbrt-cube63.1%
cbrt-prod72.9%
distribute-rgt-neg-in72.9%
fma-def72.9%
cbrt-prod94.1%
pow294.1%
Applied egg-rr94.1%
Taylor expanded in re around 0 59.0%
if 2.40000000000000013e-54 < re < 5.6e32 or 1.84999999999999999e68 < re Initial program 11.6%
Taylor expanded in im around 0 76.7%
*-commutative76.7%
Simplified76.7%
expm1-log1p-u76.4%
expm1-udef25.2%
sqrt-unprod25.3%
metadata-eval25.3%
metadata-eval25.3%
*-rgt-identity25.3%
add-sqr-sqrt25.3%
sqrt-prod22.1%
unpow222.1%
sqrt-prod22.1%
div-inv22.1%
sqrt-div22.1%
unpow222.1%
sqrt-prod25.3%
add-sqr-sqrt25.3%
Applied egg-rr25.3%
expm1-def77.1%
expm1-log1p77.5%
Simplified77.5%
Final simplification63.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re 5.6e-54)
t_0
(if (<= re 3.25e+31)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 4.5e+68) 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.6e-54) {
tmp = t_0;
} else if (re <= 3.25e+31) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 4.5e+68) {
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.6d-54) then
tmp = t_0
else if (re <= 3.25d+31) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 4.5d+68) 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.6e-54) {
tmp = t_0;
} else if (re <= 3.25e+31) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 4.5e+68) {
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.6e-54: tmp = t_0 elif re <= 3.25e+31: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 4.5e+68: 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.6e-54) tmp = t_0; elseif (re <= 3.25e+31) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 4.5e+68) 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.6e-54) tmp = t_0; elseif (re <= 3.25e+31) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 4.5e+68) 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.6e-54], t$95$0, If[LessEqual[re, 3.25e+31], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.5e+68], 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.6 \cdot 10^{-54}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 3.25 \cdot 10^{+31}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 4.5 \cdot 10^{+68}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 5.6000000000000004e-54 or 3.2500000000000002e31 < re < 4.5000000000000003e68Initial program 49.9%
hypot-udef94.3%
sub-neg94.3%
+-commutative94.3%
add-cbrt-cube63.1%
cbrt-prod72.9%
distribute-rgt-neg-in72.9%
fma-def72.9%
cbrt-prod94.1%
pow294.1%
Applied egg-rr94.1%
Taylor expanded in re around 0 59.0%
if 5.6000000000000004e-54 < re < 3.2500000000000002e31Initial program 20.1%
hypot-udef39.3%
add-cbrt-cube24.6%
pow1/323.4%
add-sqr-sqrt23.4%
pow123.4%
pow1/223.4%
pow-prod-up23.4%
metadata-eval23.4%
Applied egg-rr23.4%
unpow1/324.7%
Simplified24.7%
Taylor expanded in im around 0 66.7%
unpow1/266.7%
exp-to-pow64.1%
*-commutative64.1%
log-rec64.1%
neg-mul-164.1%
associate-*r*64.1%
metadata-eval64.1%
log-pow64.1%
rem-exp-log66.8%
Simplified66.8%
if 4.5000000000000003e68 < re Initial program 7.8%
Taylor expanded in im around 0 81.6%
*-commutative81.6%
Simplified81.6%
expm1-log1p-u81.1%
expm1-udef32.3%
sqrt-unprod32.3%
metadata-eval32.3%
metadata-eval32.3%
*-rgt-identity32.3%
add-sqr-sqrt32.3%
sqrt-prod27.9%
unpow227.9%
sqrt-prod27.9%
div-inv27.9%
sqrt-div27.9%
unpow227.9%
sqrt-prod32.3%
add-sqr-sqrt32.3%
Applied egg-rr32.3%
expm1-def81.9%
expm1-log1p82.5%
Simplified82.5%
Final simplification63.7%
(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 40.4%
hypot-udef80.3%
sub-neg80.3%
+-commutative80.3%
add-cbrt-cube50.5%
cbrt-prod60.5%
distribute-rgt-neg-in60.5%
fma-def60.5%
cbrt-prod77.1%
pow277.1%
Applied egg-rr77.1%
Taylor expanded in re around 0 51.3%
Final simplification51.3%
herbie shell --seed 2024026
(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)))))