
(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 7 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 (sqrt re))) (sqrt (* 0.5 (- (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 / sqrt(re));
} else {
tmp = sqrt((0.5 * (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.sqrt(re));
} else {
tmp = Math.sqrt((0.5 * (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.sqrt(re)) else: tmp = math.sqrt((0.5 * (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 / sqrt(re))); else tmp = sqrt(Float64(0.5 * 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 / sqrt(re)); else tmp = sqrt((0.5 * (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[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \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 7.9%
Taylor expanded in re around inf 41.5%
unpow241.5%
Simplified41.5%
add-log-exp9.3%
*-un-lft-identity9.3%
log-prod9.3%
metadata-eval9.3%
add-log-exp41.5%
sqrt-div47.7%
sqrt-prod87.4%
add-sqr-sqrt87.8%
Applied egg-rr87.8%
+-lft-identity87.8%
Simplified87.8%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 40.9%
hypot-def89.3%
Simplified89.3%
add-sqr-sqrt88.6%
sqrt-unprod89.3%
*-commutative89.3%
*-commutative89.3%
swap-sqr89.3%
add-sqr-sqrt89.3%
metadata-eval89.3%
Applied egg-rr89.3%
*-commutative89.3%
associate-*r*89.3%
metadata-eval89.3%
Simplified89.3%
Final simplification89.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0))))
(t_1 (* 0.5 (sqrt (* 2.0 (- im re))))))
(if (<= re -1.52e+97)
t_0
(if (<= re -2.4e-11)
t_1
(if (<= re -5.8e-25)
t_0
(if (<= re 12.5) t_1 (* im (/ 0.5 (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((2.0 * (im - re)));
double tmp;
if (re <= -1.52e+97) {
tmp = t_0;
} else if (re <= -2.4e-11) {
tmp = t_1;
} else if (re <= -5.8e-25) {
tmp = t_0;
} else if (re <= 12.5) {
tmp = t_1;
} else {
tmp = im * (0.5 / 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) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((2.0d0 * (im - re)))
if (re <= (-1.52d+97)) then
tmp = t_0
else if (re <= (-2.4d-11)) then
tmp = t_1
else if (re <= (-5.8d-25)) then
tmp = t_0
else if (re <= 12.5d0) then
tmp = t_1
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double t_1 = 0.5 * Math.sqrt((2.0 * (im - re)));
double tmp;
if (re <= -1.52e+97) {
tmp = t_0;
} else if (re <= -2.4e-11) {
tmp = t_1;
} else if (re <= -5.8e-25) {
tmp = t_0;
} else if (re <= 12.5) {
tmp = t_1;
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((2.0 * (im - re))) tmp = 0 if re <= -1.52e+97: tmp = t_0 elif re <= -2.4e-11: tmp = t_1 elif re <= -5.8e-25: tmp = t_0 elif re <= 12.5: tmp = t_1 else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))) tmp = 0.0 if (re <= -1.52e+97) tmp = t_0; elseif (re <= -2.4e-11) tmp = t_1; elseif (re <= -5.8e-25) tmp = t_0; elseif (re <= 12.5) tmp = t_1; else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = 0.5 * sqrt((2.0 * (im - re))); tmp = 0.0; if (re <= -1.52e+97) tmp = t_0; elseif (re <= -2.4e-11) tmp = t_1; elseif (re <= -5.8e-25) tmp = t_0; elseif (re <= 12.5) tmp = t_1; else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.52e+97], t$95$0, If[LessEqual[re, -2.4e-11], t$95$1, If[LessEqual[re, -5.8e-25], t$95$0, If[LessEqual[re, 12.5], t$95$1, N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -1.52 \cdot 10^{+97}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -2.4 \cdot 10^{-11}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -5.8 \cdot 10^{-25}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 12.5:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.5200000000000001e97 or -2.4000000000000001e-11 < re < -5.8000000000000001e-25Initial program 23.1%
Taylor expanded in re around -inf 91.4%
*-commutative91.4%
Simplified91.4%
if -1.5200000000000001e97 < re < -2.4000000000000001e-11 or -5.8000000000000001e-25 < re < 12.5Initial program 53.6%
Taylor expanded in re around 0 80.1%
if 12.5 < re Initial program 14.2%
Taylor expanded in re around inf 41.4%
unpow241.4%
Simplified41.4%
associate-/l*45.8%
sqrt-div59.8%
Applied egg-rr59.8%
add-log-exp13.6%
*-un-lft-identity13.6%
log-prod13.6%
metadata-eval13.6%
add-log-exp59.8%
clear-num59.7%
un-div-inv59.7%
sqrt-div72.4%
associate-/l/72.5%
add-sqr-sqrt72.7%
Applied egg-rr72.7%
+-lft-identity72.7%
associate-/r/73.8%
Simplified73.8%
Final simplification80.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (- im re))))))
(if (<= re -3.6e+97)
(* 0.5 (sqrt (- (* re -4.0) (/ im (/ re im)))))
(if (<= re -1.9e-11)
t_0
(if (<= re -2.2e-25)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.45e-15) t_0 (* im (/ 0.5 (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (im - re)));
double tmp;
if (re <= -3.6e+97) {
tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= -1.9e-11) {
tmp = t_0;
} else if (re <= -2.2e-25) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.45e-15) {
tmp = t_0;
} else {
tmp = im * (0.5 / 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((2.0d0 * (im - re)))
if (re <= (-3.6d+97)) then
tmp = 0.5d0 * sqrt(((re * (-4.0d0)) - (im / (re / im))))
else if (re <= (-1.9d-11)) then
tmp = t_0
else if (re <= (-2.2d-25)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.45d-15) then
tmp = t_0
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((2.0 * (im - re)));
double tmp;
if (re <= -3.6e+97) {
tmp = 0.5 * Math.sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= -1.9e-11) {
tmp = t_0;
} else if (re <= -2.2e-25) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.45e-15) {
tmp = t_0;
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((2.0 * (im - re))) tmp = 0 if re <= -3.6e+97: tmp = 0.5 * math.sqrt(((re * -4.0) - (im / (re / im)))) elif re <= -1.9e-11: tmp = t_0 elif re <= -2.2e-25: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.45e-15: tmp = t_0 else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))) tmp = 0.0 if (re <= -3.6e+97) tmp = Float64(0.5 * sqrt(Float64(Float64(re * -4.0) - Float64(im / Float64(re / im))))); elseif (re <= -1.9e-11) tmp = t_0; elseif (re <= -2.2e-25) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.45e-15) tmp = t_0; else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((2.0 * (im - re))); tmp = 0.0; if (re <= -3.6e+97) tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im)))); elseif (re <= -1.9e-11) tmp = t_0; elseif (re <= -2.2e-25) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.45e-15) tmp = t_0; else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -3.6e+97], N[(0.5 * N[Sqrt[N[(N[(re * -4.0), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.9e-11], t$95$0, If[LessEqual[re, -2.2e-25], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.45e-15], t$95$0, N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -3.6 \cdot 10^{+97}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\
\mathbf{elif}\;re \leq -1.9 \cdot 10^{-11}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -2.2 \cdot 10^{-25}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.45 \cdot 10^{-15}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.59999999999999966e97Initial program 13.8%
Taylor expanded in re around -inf 79.0%
+-commutative79.0%
mul-1-neg79.0%
unsub-neg79.0%
*-commutative79.0%
unpow279.0%
associate-/l*90.8%
Simplified90.8%
if -3.59999999999999966e97 < re < -1.8999999999999999e-11 or -2.2000000000000002e-25 < re < 1.45000000000000009e-15Initial program 53.6%
Taylor expanded in re around 0 80.1%
if -1.8999999999999999e-11 < re < -2.2000000000000002e-25Initial program 100.0%
Taylor expanded in re around -inf 100.0%
*-commutative100.0%
Simplified100.0%
if 1.45000000000000009e-15 < re Initial program 14.2%
Taylor expanded in re around inf 41.4%
unpow241.4%
Simplified41.4%
associate-/l*45.8%
sqrt-div59.8%
Applied egg-rr59.8%
add-log-exp13.6%
*-un-lft-identity13.6%
log-prod13.6%
metadata-eval13.6%
add-log-exp59.8%
clear-num59.7%
un-div-inv59.7%
sqrt-div72.4%
associate-/l/72.5%
add-sqr-sqrt72.7%
Applied egg-rr72.7%
+-lft-identity72.7%
associate-/r/73.8%
Simplified73.8%
Final simplification80.9%
(FPCore (re im) :precision binary64 (if (<= re -3.6e-26) (* 0.5 (sqrt (* re -4.0))) (if (<= re 7.2e-5) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -3.6e-26) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 7.2e-5) {
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 <= (-3.6d-26)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 7.2d-5) 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 <= -3.6e-26) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 7.2e-5) {
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 <= -3.6e-26: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 7.2e-5: 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 <= -3.6e-26) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 7.2e-5) 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 <= -3.6e-26) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 7.2e-5) 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, -3.6e-26], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.2e-5], 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 -3.6 \cdot 10^{-26}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 7.2 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.6000000000000001e-26Initial program 31.8%
Taylor expanded in re around -inf 79.5%
*-commutative79.5%
Simplified79.5%
if -3.6000000000000001e-26 < re < 7.20000000000000018e-5Initial program 52.6%
Taylor expanded in re around 0 80.9%
*-commutative80.9%
Simplified80.9%
if 7.20000000000000018e-5 < re Initial program 14.2%
Taylor expanded in re around inf 41.4%
unpow241.4%
Simplified41.4%
add-log-exp13.7%
*-un-lft-identity13.7%
log-prod13.7%
metadata-eval13.7%
add-log-exp41.4%
sqrt-div59.7%
sqrt-prod73.5%
add-sqr-sqrt73.8%
Applied egg-rr73.8%
+-lft-identity73.8%
Simplified73.8%
Final simplification78.5%
(FPCore (re im) :precision binary64 (if (<= re -1.1e-27) (* 0.5 (sqrt (* re -4.0))) (if (<= re 5.2e-5) (* 0.5 (sqrt (* im 2.0))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.1e-27) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 5.2e-5) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = im * (0.5 / 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 <= (-1.1d-27)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 5.2d-5) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.1e-27) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 5.2e-5) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.1e-27: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 5.2e-5: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.1e-27) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 5.2e-5) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.1e-27) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 5.2e-5) tmp = 0.5 * sqrt((im * 2.0)); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.1e-27], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.2e-5], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.1 \cdot 10^{-27}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 5.2 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.09999999999999993e-27Initial program 31.8%
Taylor expanded in re around -inf 79.5%
*-commutative79.5%
Simplified79.5%
if -1.09999999999999993e-27 < re < 5.19999999999999968e-5Initial program 52.6%
Taylor expanded in re around 0 80.9%
*-commutative80.9%
Simplified80.9%
if 5.19999999999999968e-5 < re Initial program 14.2%
Taylor expanded in re around inf 41.4%
unpow241.4%
Simplified41.4%
associate-/l*45.8%
sqrt-div59.8%
Applied egg-rr59.8%
add-log-exp13.6%
*-un-lft-identity13.6%
log-prod13.6%
metadata-eval13.6%
add-log-exp59.8%
clear-num59.7%
un-div-inv59.7%
sqrt-div72.4%
associate-/l/72.5%
add-sqr-sqrt72.7%
Applied egg-rr72.7%
+-lft-identity72.7%
associate-/r/73.8%
Simplified73.8%
Final simplification78.5%
(FPCore (re im) :precision binary64 (if (<= re -3.6e-25) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (re <= -3.6e-25) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((im * 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.6d-25)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((im * 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.6e-25) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.6e-25: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.6e-25) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.6e-25) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.6e-25], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.6 \cdot 10^{-25}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -3.5999999999999999e-25Initial program 31.8%
Taylor expanded in re around -inf 79.5%
*-commutative79.5%
Simplified79.5%
if -3.5999999999999999e-25 < re Initial program 37.7%
Taylor expanded in re around 0 61.8%
*-commutative61.8%
Simplified61.8%
Final simplification66.9%
(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 36.0%
Taylor expanded in re around 0 51.2%
*-commutative51.2%
Simplified51.2%
Final simplification51.2%
herbie shell --seed 2023173
(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)))))