
(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 6.0%
sqr-neg6.0%
sqr-neg6.0%
hypot-def15.2%
Simplified15.2%
Taylor expanded in re around inf 48.6%
unpow248.6%
associate-/l*60.6%
Simplified60.6%
div-inv60.7%
clear-num60.7%
*-un-lft-identity60.7%
add-sqr-sqrt60.5%
times-frac60.6%
metadata-eval60.6%
sqrt-div60.6%
un-div-inv60.6%
metadata-eval60.6%
sqrt-div60.5%
associate-*l*60.5%
sqrt-unprod91.2%
add-sqr-sqrt91.7%
expm1-log1p-u91.2%
expm1-udef23.8%
sqrt-div23.8%
metadata-eval23.8%
un-div-inv23.8%
Applied egg-rr23.8%
expm1-def91.4%
expm1-log1p91.8%
Simplified91.8%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 42.2%
*-commutative42.2%
hypot-udef90.2%
*-commutative90.2%
add-sqr-sqrt89.4%
sqrt-unprod90.2%
*-commutative90.2%
*-commutative90.2%
swap-sqr90.2%
add-sqr-sqrt90.2%
metadata-eval90.2%
Applied egg-rr90.2%
*-commutative90.2%
associate-*r*90.2%
metadata-eval90.2%
Simplified90.2%
Final simplification90.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (sqrt (* 0.5 (- im re)))))
(if (<= re -1.8e+152)
t_0
(if (<= re -9.2e+103)
t_1
(if (<= re -2.9e+41)
t_0
(if (<= re 0.016) t_1 (* (pow re -0.5) (* im 0.5))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -9.2e+103) {
tmp = t_1;
} else if (re <= -2.9e+41) {
tmp = t_0;
} else if (re <= 0.016) {
tmp = t_1;
} else {
tmp = pow(re, -0.5) * (im * 0.5);
}
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 = sqrt((0.5d0 * (im - re)))
if (re <= (-1.8d+152)) then
tmp = t_0
else if (re <= (-9.2d+103)) then
tmp = t_1
else if (re <= (-2.9d+41)) then
tmp = t_0
else if (re <= 0.016d0) then
tmp = t_1
else
tmp = (re ** (-0.5d0)) * (im * 0.5d0)
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 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -9.2e+103) {
tmp = t_1;
} else if (re <= -2.9e+41) {
tmp = t_0;
} else if (re <= 0.016) {
tmp = t_1;
} else {
tmp = Math.pow(re, -0.5) * (im * 0.5);
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -1.8e+152: tmp = t_0 elif re <= -9.2e+103: tmp = t_1 elif re <= -2.9e+41: tmp = t_0 elif re <= 0.016: tmp = t_1 else: tmp = math.pow(re, -0.5) * (im * 0.5) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -1.8e+152) tmp = t_0; elseif (re <= -9.2e+103) tmp = t_1; elseif (re <= -2.9e+41) tmp = t_0; elseif (re <= 0.016) tmp = t_1; else tmp = Float64((re ^ -0.5) * Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -1.8e+152) tmp = t_0; elseif (re <= -9.2e+103) tmp = t_1; elseif (re <= -2.9e+41) tmp = t_0; elseif (re <= 0.016) tmp = t_1; else tmp = (re ^ -0.5) * (im * 0.5); 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[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -1.8e+152], t$95$0, If[LessEqual[re, -9.2e+103], t$95$1, If[LessEqual[re, -2.9e+41], t$95$0, If[LessEqual[re, 0.016], t$95$1, N[(N[Power[re, -0.5], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -1.8 \cdot 10^{+152}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -9.2 \cdot 10^{+103}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.9 \cdot 10^{+41}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 0.016:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;{re}^{-0.5} \cdot \left(im \cdot 0.5\right)\\
\end{array}
\end{array}
if re < -1.7999999999999999e152 or -9.20000000000000034e103 < re < -2.89999999999999988e41Initial program 23.4%
sqr-neg23.4%
sqr-neg23.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 91.8%
*-commutative91.8%
Simplified91.8%
if -1.7999999999999999e152 < re < -9.20000000000000034e103 or -2.89999999999999988e41 < re < 0.016Initial program 51.2%
*-commutative51.2%
hypot-udef89.7%
*-commutative89.7%
add-sqr-sqrt88.8%
sqrt-unprod89.7%
*-commutative89.7%
*-commutative89.7%
swap-sqr89.7%
add-sqr-sqrt89.7%
metadata-eval89.7%
Applied egg-rr89.7%
*-commutative89.7%
associate-*r*89.7%
metadata-eval89.7%
Simplified89.7%
Taylor expanded in re around 0 75.9%
neg-mul-175.9%
sub-neg75.9%
Simplified75.9%
if 0.016 < re Initial program 13.9%
sqr-neg13.9%
sqr-neg13.9%
hypot-def37.9%
Simplified37.9%
Taylor expanded in re around inf 48.9%
unpow248.9%
associate-/l*59.3%
Simplified59.3%
add-sqr-sqrt59.1%
pow259.1%
Applied egg-rr76.0%
unpow276.0%
add-sqr-sqrt76.3%
associate-*r/76.3%
*-commutative76.3%
*-un-lft-identity76.3%
associate-*l/76.2%
pow1/276.2%
pow-flip76.3%
metadata-eval76.3%
Applied egg-rr76.3%
Final simplification78.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (sqrt (* 0.5 (- im re)))))
(if (<= re -1.8e+152)
t_0
(if (<= re -1.45e+103)
t_1
(if (<= re -2.9e+41)
t_0
(if (<= re 8e-5) t_1 (* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -1.45e+103) {
tmp = t_1;
} else if (re <= -2.9e+41) {
tmp = t_0;
} else if (re <= 8e-5) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = sqrt((0.5d0 * (im - re)))
if (re <= (-1.8d+152)) then
tmp = t_0
else if (re <= (-1.45d+103)) then
tmp = t_1
else if (re <= (-2.9d+41)) then
tmp = t_0
else if (re <= 8d-5) then
tmp = t_1
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((re * -4.0));
double t_1 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -1.45e+103) {
tmp = t_1;
} else if (re <= -2.9e+41) {
tmp = t_0;
} else if (re <= 8e-5) {
tmp = t_1;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -1.8e+152: tmp = t_0 elif re <= -1.45e+103: tmp = t_1 elif re <= -2.9e+41: tmp = t_0 elif re <= 8e-5: tmp = t_1 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -1.8e+152) tmp = t_0; elseif (re <= -1.45e+103) tmp = t_1; elseif (re <= -2.9e+41) tmp = t_0; elseif (re <= 8e-5) tmp = t_1; else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -1.8e+152) tmp = t_0; elseif (re <= -1.45e+103) tmp = t_1; elseif (re <= -2.9e+41) tmp = t_0; elseif (re <= 8e-5) tmp = t_1; 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[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -1.8e+152], t$95$0, If[LessEqual[re, -1.45e+103], t$95$1, If[LessEqual[re, -2.9e+41], t$95$0, If[LessEqual[re, 8e-5], t$95$1, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -1.8 \cdot 10^{+152}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.45 \cdot 10^{+103}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.9 \cdot 10^{+41}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8 \cdot 10^{-5}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.7999999999999999e152 or -1.4499999999999999e103 < re < -2.89999999999999988e41Initial program 23.4%
sqr-neg23.4%
sqr-neg23.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 91.8%
*-commutative91.8%
Simplified91.8%
if -1.7999999999999999e152 < re < -1.4499999999999999e103 or -2.89999999999999988e41 < re < 8.00000000000000065e-5Initial program 51.2%
*-commutative51.2%
hypot-udef89.7%
*-commutative89.7%
add-sqr-sqrt88.8%
sqrt-unprod89.7%
*-commutative89.7%
*-commutative89.7%
swap-sqr89.7%
add-sqr-sqrt89.7%
metadata-eval89.7%
Applied egg-rr89.7%
*-commutative89.7%
associate-*r*89.7%
metadata-eval89.7%
Simplified89.7%
Taylor expanded in re around 0 75.9%
neg-mul-175.9%
sub-neg75.9%
Simplified75.9%
if 8.00000000000000065e-5 < re Initial program 13.9%
sqr-neg13.9%
sqr-neg13.9%
hypot-def37.9%
Simplified37.9%
Taylor expanded in re around inf 48.9%
unpow248.9%
associate-/l*59.3%
Simplified59.3%
div-inv59.4%
clear-num59.4%
*-un-lft-identity59.4%
add-sqr-sqrt59.2%
times-frac59.3%
metadata-eval59.3%
sqrt-div59.4%
un-div-inv59.4%
metadata-eval59.4%
sqrt-div59.3%
associate-*l*59.3%
sqrt-unprod75.9%
add-sqr-sqrt76.2%
expm1-log1p-u75.1%
expm1-udef36.7%
sqrt-div36.7%
metadata-eval36.7%
un-div-inv36.7%
Applied egg-rr36.7%
expm1-def75.1%
expm1-log1p76.3%
Simplified76.3%
Final simplification78.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (sqrt (* 0.5 (- im re)))))
(if (<= re -1.8e+152)
t_0
(if (<= re -1.36e+104)
t_1
(if (<= re -2.9e+41)
t_0
(if (<= re 0.00038) 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 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -1.36e+104) {
tmp = t_1;
} else if (re <= -2.9e+41) {
tmp = t_0;
} else if (re <= 0.00038) {
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 = sqrt((0.5d0 * (im - re)))
if (re <= (-1.8d+152)) then
tmp = t_0
else if (re <= (-1.36d+104)) then
tmp = t_1
else if (re <= (-2.9d+41)) then
tmp = t_0
else if (re <= 0.00038d0) 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 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -1.36e+104) {
tmp = t_1;
} else if (re <= -2.9e+41) {
tmp = t_0;
} else if (re <= 0.00038) {
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 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -1.8e+152: tmp = t_0 elif re <= -1.36e+104: tmp = t_1 elif re <= -2.9e+41: tmp = t_0 elif re <= 0.00038: 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 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -1.8e+152) tmp = t_0; elseif (re <= -1.36e+104) tmp = t_1; elseif (re <= -2.9e+41) tmp = t_0; elseif (re <= 0.00038) tmp = t_1; else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -1.8e+152) tmp = t_0; elseif (re <= -1.36e+104) tmp = t_1; elseif (re <= -2.9e+41) tmp = t_0; elseif (re <= 0.00038) 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[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -1.8e+152], t$95$0, If[LessEqual[re, -1.36e+104], t$95$1, If[LessEqual[re, -2.9e+41], t$95$0, If[LessEqual[re, 0.00038], t$95$1, N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -1.8 \cdot 10^{+152}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.36 \cdot 10^{+104}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.9 \cdot 10^{+41}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 0.00038:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.7999999999999999e152 or -1.3599999999999999e104 < re < -2.89999999999999988e41Initial program 23.4%
sqr-neg23.4%
sqr-neg23.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 91.8%
*-commutative91.8%
Simplified91.8%
if -1.7999999999999999e152 < re < -1.3599999999999999e104 or -2.89999999999999988e41 < re < 3.8000000000000002e-4Initial program 51.2%
*-commutative51.2%
hypot-udef89.7%
*-commutative89.7%
add-sqr-sqrt88.8%
sqrt-unprod89.7%
*-commutative89.7%
*-commutative89.7%
swap-sqr89.7%
add-sqr-sqrt89.7%
metadata-eval89.7%
Applied egg-rr89.7%
*-commutative89.7%
associate-*r*89.7%
metadata-eval89.7%
Simplified89.7%
Taylor expanded in re around 0 75.9%
neg-mul-175.9%
sub-neg75.9%
Simplified75.9%
if 3.8000000000000002e-4 < re Initial program 13.9%
sqr-neg13.9%
sqr-neg13.9%
hypot-def37.9%
Simplified37.9%
Taylor expanded in re around inf 48.9%
unpow248.9%
associate-/l*59.3%
Simplified59.3%
div-inv59.4%
clear-num59.4%
*-un-lft-identity59.4%
add-sqr-sqrt59.2%
times-frac59.3%
metadata-eval59.3%
sqrt-div59.4%
un-div-inv59.4%
metadata-eval59.4%
sqrt-div59.3%
associate-*l*59.3%
sqrt-unprod75.9%
add-sqr-sqrt76.2%
expm1-log1p-u75.1%
expm1-udef36.7%
sqrt-div36.7%
metadata-eval36.7%
un-div-inv36.7%
Applied egg-rr36.7%
expm1-def75.1%
expm1-log1p76.3%
Simplified76.3%
associate-*r/76.3%
*-commutative76.3%
Applied egg-rr76.3%
Final simplification78.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))))
(if (<= re -1.8e+152)
t_0
(if (<= re -1.8e+104)
(sqrt (* 0.5 (- im re)))
(if (<= re -4.75e+33) t_0 (sqrt (* im 0.5)))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -1.8e+104) {
tmp = sqrt((0.5 * (im - re)));
} else if (re <= -4.75e+33) {
tmp = t_0;
} else {
tmp = sqrt((im * 0.5));
}
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((re * (-4.0d0)))
if (re <= (-1.8d+152)) then
tmp = t_0
else if (re <= (-1.8d+104)) then
tmp = sqrt((0.5d0 * (im - re)))
else if (re <= (-4.75d+33)) then
tmp = t_0
else
tmp = sqrt((im * 0.5d0))
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 tmp;
if (re <= -1.8e+152) {
tmp = t_0;
} else if (re <= -1.8e+104) {
tmp = Math.sqrt((0.5 * (im - re)));
} else if (re <= -4.75e+33) {
tmp = t_0;
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) tmp = 0 if re <= -1.8e+152: tmp = t_0 elif re <= -1.8e+104: tmp = math.sqrt((0.5 * (im - re))) elif re <= -4.75e+33: tmp = t_0 else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) tmp = 0.0 if (re <= -1.8e+152) tmp = t_0; elseif (re <= -1.8e+104) tmp = sqrt(Float64(0.5 * Float64(im - re))); elseif (re <= -4.75e+33) tmp = t_0; else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); tmp = 0.0; if (re <= -1.8e+152) tmp = t_0; elseif (re <= -1.8e+104) tmp = sqrt((0.5 * (im - re))); elseif (re <= -4.75e+33) tmp = t_0; else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.8e+152], t$95$0, If[LessEqual[re, -1.8e+104], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[re, -4.75e+33], t$95$0, N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{if}\;re \leq -1.8 \cdot 10^{+152}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.8 \cdot 10^{+104}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq -4.75 \cdot 10^{+33}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -1.7999999999999999e152 or -1.8e104 < re < -4.7500000000000002e33Initial program 28.6%
sqr-neg28.6%
sqr-neg28.6%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 87.3%
*-commutative87.3%
Simplified87.3%
if -1.7999999999999999e152 < re < -1.8e104Initial program 17.9%
*-commutative17.9%
hypot-udef100.0%
*-commutative100.0%
add-sqr-sqrt99.3%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 88.7%
neg-mul-188.7%
sub-neg88.7%
Simplified88.7%
if -4.7500000000000002e33 < re Initial program 38.1%
*-commutative38.1%
hypot-udef69.9%
*-commutative69.9%
add-sqr-sqrt69.4%
sqrt-unprod69.9%
*-commutative69.9%
*-commutative69.9%
swap-sqr69.9%
add-sqr-sqrt69.9%
metadata-eval69.9%
Applied egg-rr69.9%
*-commutative69.9%
associate-*r*69.9%
metadata-eval69.9%
Simplified69.9%
Taylor expanded in re around 0 58.0%
Final simplification64.7%
(FPCore (re im) :precision binary64 (if (<= re -2.6e-303) (sqrt (* 0.5 (- im re))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -2.6e-303) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = sqrt((im * 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 <= (-2.6d-303)) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.6e-303) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.6e-303: tmp = math.sqrt((0.5 * (im - re))) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.6e-303) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.6e-303) tmp = sqrt((0.5 * (im - re))); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.6e-303], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.6 \cdot 10^{-303}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -2.60000000000000005e-303Initial program 46.0%
*-commutative46.0%
hypot-udef100.0%
*-commutative100.0%
add-sqr-sqrt99.1%
sqrt-unprod100.0%
*-commutative100.0%
*-commutative100.0%
swap-sqr100.0%
add-sqr-sqrt100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-commutative100.0%
associate-*r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 59.5%
neg-mul-159.5%
sub-neg59.5%
Simplified59.5%
if -2.60000000000000005e-303 < re Initial program 25.7%
*-commutative25.7%
hypot-udef54.2%
*-commutative54.2%
add-sqr-sqrt53.8%
sqrt-unprod54.2%
*-commutative54.2%
*-commutative54.2%
swap-sqr54.2%
add-sqr-sqrt54.2%
metadata-eval54.2%
Applied egg-rr54.2%
*-commutative54.2%
associate-*r*54.2%
metadata-eval54.2%
Simplified54.2%
Taylor expanded in re around 0 49.5%
Final simplification54.4%
(FPCore (re im) :precision binary64 (sqrt (* im 0.5)))
double code(double re, double im) {
return sqrt((im * 0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((im * 0.5d0))
end function
public static double code(double re, double im) {
return Math.sqrt((im * 0.5));
}
def code(re, im): return math.sqrt((im * 0.5))
function code(re, im) return sqrt(Float64(im * 0.5)) end
function tmp = code(re, im) tmp = sqrt((im * 0.5)); end
code[re_, im_] := N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{im \cdot 0.5}
\end{array}
Initial program 35.7%
*-commutative35.7%
hypot-udef76.7%
*-commutative76.7%
add-sqr-sqrt76.1%
sqrt-unprod76.7%
*-commutative76.7%
*-commutative76.7%
swap-sqr76.7%
add-sqr-sqrt76.7%
metadata-eval76.7%
Applied egg-rr76.7%
*-commutative76.7%
associate-*r*76.7%
metadata-eval76.7%
Simplified76.7%
Taylor expanded in re around 0 50.8%
Final simplification50.8%
herbie shell --seed 2023271
(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)))))