
(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 (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* 0.5 (/ im (sqrt re))) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im / sqrt(re));
} 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((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im / Math.sqrt(re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = 0.5 * (im / math.sqrt(re)) else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(0.5 * Float64(im / sqrt(re))); 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((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = 0.5 * (im / sqrt(re)); else tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[(im / N[Sqrt[re], $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{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 5.4%
Taylor expanded in re around inf 54.8%
unpow254.8%
associate-/l*58.0%
Simplified58.0%
Taylor expanded in im around 0 99.6%
*-commutative99.6%
unpow1/299.6%
unpow-199.6%
exp-to-pow93.5%
*-commutative93.5%
neg-mul-193.5%
exp-prod93.6%
distribute-lft-neg-out93.6%
distribute-rgt-neg-in93.6%
metadata-eval93.6%
exp-to-pow99.6%
Simplified99.6%
add-sqr-sqrt99.2%
associate-*l*99.0%
add-sqr-sqrt98.8%
sqrt-unprod99.0%
pow-prod-up98.9%
metadata-eval98.9%
inv-pow98.9%
sqrt-prod90.1%
div-inv90.3%
sqrt-div99.1%
associate-*r/99.3%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
if 0.0 < (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 48.1%
hypot-def90.7%
Simplified90.7%
Final simplification91.8%
(FPCore (re im)
:precision binary64
(if (<= re -6700.0)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (or (<= re 4.6e-29) (and (not (<= re 3.15e+68)) (<= re 3.2e+113)))
(* 0.5 (sqrt (* 2.0 im)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -6700.0) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if ((re <= 4.6e-29) || (!(re <= 3.15e+68) && (re <= 3.2e+113))) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-6700.0d0)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if ((re <= 4.6d-29) .or. (.not. (re <= 3.15d+68)) .and. (re <= 3.2d+113)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -6700.0) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if ((re <= 4.6e-29) || (!(re <= 3.15e+68) && (re <= 3.2e+113))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6700.0: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif (re <= 4.6e-29) or (not (re <= 3.15e+68) and (re <= 3.2e+113)): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -6700.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif ((re <= 4.6e-29) || (!(re <= 3.15e+68) && (re <= 3.2e+113))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -6700.0) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif ((re <= 4.6e-29) || (~((re <= 3.15e+68)) && (re <= 3.2e+113))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6700.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 4.6e-29], And[N[Not[LessEqual[re, 3.15e+68]], $MachinePrecision], LessEqual[re, 3.2e+113]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6700:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 4.6 \cdot 10^{-29} \lor \neg \left(re \leq 3.15 \cdot 10^{+68}\right) \land re \leq 3.2 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -6700Initial program 38.3%
Taylor expanded in re around -inf 77.5%
*-commutative77.5%
Simplified77.5%
if -6700 < re < 4.59999999999999982e-29 or 3.15000000000000013e68 < re < 3.1999999999999998e113Initial program 57.8%
Taylor expanded in re around 0 83.5%
expm1-log1p-u79.7%
expm1-udef57.5%
sqrt-unprod57.5%
Applied egg-rr57.5%
expm1-def79.9%
expm1-log1p84.0%
*-commutative84.0%
Simplified84.0%
if 4.59999999999999982e-29 < re < 3.15000000000000013e68 or 3.1999999999999998e113 < re Initial program 14.7%
Taylor expanded in re around inf 50.3%
unpow250.3%
associate-/l*55.7%
Simplified55.7%
Taylor expanded in im around 0 76.5%
*-commutative76.5%
unpow1/276.5%
unpow-176.5%
exp-to-pow71.7%
*-commutative71.7%
neg-mul-171.7%
exp-prod71.7%
distribute-lft-neg-out71.7%
distribute-rgt-neg-in71.7%
metadata-eval71.7%
exp-to-pow76.5%
Simplified76.5%
Final simplification80.7%
(FPCore (re im)
:precision binary64
(if (<= re -3.1e+70)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 8.8e-30)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (or (<= re 8e+65) (not (<= re 3.4e+113)))
(* 0.5 (* im (pow re -0.5)))
(* 0.5 (sqrt (* 2.0 im)))))))
double code(double re, double im) {
double tmp;
if (re <= -3.1e+70) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 8.8e-30) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if ((re <= 8e+65) || !(re <= 3.4e+113)) {
tmp = 0.5 * (im * pow(re, -0.5));
} else {
tmp = 0.5 * sqrt((2.0 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.1d+70)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 8.8d-30) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if ((re <= 8d+65) .or. (.not. (re <= 3.4d+113))) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.1e+70) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 8.8e-30) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if ((re <= 8e+65) || !(re <= 3.4e+113)) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.1e+70: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 8.8e-30: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif (re <= 8e+65) or not (re <= 3.4e+113): tmp = 0.5 * (im * math.pow(re, -0.5)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.1e+70) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 8.8e-30) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif ((re <= 8e+65) || !(re <= 3.4e+113)) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.1e+70) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 8.8e-30) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif ((re <= 8e+65) || ~((re <= 3.4e+113))) tmp = 0.5 * (im * (re ^ -0.5)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.1e+70], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.8e-30], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 8e+65], N[Not[LessEqual[re, 3.4e+113]], $MachinePrecision]], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.1 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 8.8 \cdot 10^{-30}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+65} \lor \neg \left(re \leq 3.4 \cdot 10^{+113}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -3.1000000000000003e70Initial program 25.1%
Taylor expanded in re around -inf 84.8%
*-commutative84.8%
Simplified84.8%
if -3.1000000000000003e70 < re < 8.79999999999999933e-30Initial program 63.6%
Taylor expanded in re around 0 82.8%
if 8.79999999999999933e-30 < re < 7.9999999999999999e65 or 3.40000000000000019e113 < re Initial program 14.7%
Taylor expanded in re around inf 50.3%
unpow250.3%
associate-/l*55.7%
Simplified55.7%
Taylor expanded in im around 0 76.5%
*-commutative76.5%
unpow1/276.5%
unpow-176.5%
exp-to-pow71.7%
*-commutative71.7%
neg-mul-171.7%
exp-prod71.7%
distribute-lft-neg-out71.7%
distribute-rgt-neg-in71.7%
metadata-eval71.7%
exp-to-pow76.5%
Simplified76.5%
if 7.9999999999999999e65 < re < 3.40000000000000019e113Initial program 18.1%
Taylor expanded in re around 0 73.9%
expm1-log1p-u68.8%
expm1-udef69.3%
sqrt-unprod69.3%
Applied egg-rr69.3%
expm1-def68.8%
expm1-log1p74.4%
*-commutative74.4%
Simplified74.4%
Final simplification81.3%
(FPCore (re im) :precision binary64 (if (or (<= re 3.7e-31) (and (not (<= re 3.15e+68)) (<= re 3.2e+113))) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (* im (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if ((re <= 3.7e-31) || (!(re <= 3.15e+68) && (re <= 3.2e+113))) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= 3.7d-31) .or. (.not. (re <= 3.15d+68)) .and. (re <= 3.2d+113)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= 3.7e-31) || (!(re <= 3.15e+68) && (re <= 3.2e+113))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= 3.7e-31) or (not (re <= 3.15e+68) and (re <= 3.2e+113)): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if ((re <= 3.7e-31) || (!(re <= 3.15e+68) && (re <= 3.2e+113))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= 3.7e-31) || (~((re <= 3.15e+68)) && (re <= 3.2e+113))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, 3.7e-31], And[N[Not[LessEqual[re, 3.15e+68]], $MachinePrecision], LessEqual[re, 3.2e+113]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.7 \cdot 10^{-31} \lor \neg \left(re \leq 3.15 \cdot 10^{+68}\right) \land re \leq 3.2 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < 3.6999999999999998e-31 or 3.15000000000000013e68 < re < 3.1999999999999998e113Initial program 51.9%
Taylor expanded in re around 0 66.2%
expm1-log1p-u63.1%
expm1-udef47.4%
sqrt-unprod47.4%
Applied egg-rr47.4%
expm1-def63.3%
expm1-log1p66.6%
*-commutative66.6%
Simplified66.6%
if 3.6999999999999998e-31 < re < 3.15000000000000013e68 or 3.1999999999999998e113 < re Initial program 14.7%
Taylor expanded in re around inf 50.3%
unpow250.3%
associate-/l*55.7%
Simplified55.7%
Taylor expanded in im around 0 76.5%
*-commutative76.5%
unpow1/276.5%
unpow-176.5%
exp-to-pow71.7%
*-commutative71.7%
neg-mul-171.7%
exp-prod71.7%
distribute-lft-neg-out71.7%
distribute-rgt-neg-in71.7%
metadata-eval71.7%
exp-to-pow76.5%
Simplified76.5%
Final simplification69.0%
(FPCore (re im) :precision binary64 (if (or (<= re 7.2e-30) (and (not (<= re 5.5e+65)) (<= re 3.2e+113))) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (/ im (sqrt re)))))
double code(double re, double im) {
double tmp;
if ((re <= 7.2e-30) || (!(re <= 5.5e+65) && (re <= 3.2e+113))) {
tmp = 0.5 * sqrt((2.0 * im));
} 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 <= 7.2d-30) .or. (.not. (re <= 5.5d+65)) .and. (re <= 3.2d+113)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
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 <= 7.2e-30) || (!(re <= 5.5e+65) && (re <= 3.2e+113))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= 7.2e-30) or (not (re <= 5.5e+65) and (re <= 3.2e+113)): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if ((re <= 7.2e-30) || (!(re <= 5.5e+65) && (re <= 3.2e+113))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= 7.2e-30) || (~((re <= 5.5e+65)) && (re <= 3.2e+113))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, 7.2e-30], And[N[Not[LessEqual[re, 5.5e+65]], $MachinePrecision], LessEqual[re, 3.2e+113]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 7.2 \cdot 10^{-30} \lor \neg \left(re \leq 5.5 \cdot 10^{+65}\right) \land re \leq 3.2 \cdot 10^{+113}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 7.2000000000000006e-30 or 5.4999999999999996e65 < re < 3.1999999999999998e113Initial program 51.9%
Taylor expanded in re around 0 66.2%
expm1-log1p-u63.1%
expm1-udef47.4%
sqrt-unprod47.4%
Applied egg-rr47.4%
expm1-def63.3%
expm1-log1p66.6%
*-commutative66.6%
Simplified66.6%
if 7.2000000000000006e-30 < re < 5.4999999999999996e65 or 3.1999999999999998e113 < re Initial program 14.7%
Taylor expanded in re around inf 50.3%
unpow250.3%
associate-/l*55.7%
Simplified55.7%
Taylor expanded in im around 0 76.5%
*-commutative76.5%
unpow1/276.5%
unpow-176.5%
exp-to-pow71.7%
*-commutative71.7%
neg-mul-171.7%
exp-prod71.7%
distribute-lft-neg-out71.7%
distribute-rgt-neg-in71.7%
metadata-eval71.7%
exp-to-pow76.5%
Simplified76.5%
add-sqr-sqrt76.2%
associate-*l*76.1%
add-sqr-sqrt76.0%
sqrt-unprod76.1%
pow-prod-up76.1%
metadata-eval76.1%
inv-pow76.1%
sqrt-prod66.4%
div-inv66.5%
sqrt-div76.1%
associate-*r/76.2%
add-sqr-sqrt76.4%
Applied egg-rr76.4%
Final simplification69.0%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 42.9%
Taylor expanded in re around 0 57.0%
expm1-log1p-u54.3%
expm1-udef44.3%
sqrt-unprod44.3%
Applied egg-rr44.3%
expm1-def54.4%
expm1-log1p57.3%
*-commutative57.3%
Simplified57.3%
Final simplification57.3%
herbie shell --seed 2023215
(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)))))