
(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 (<= re 1.02e+18) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (* 0.5 (/ im (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 1.02e+18) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = 0.5 * (im / sqrt(re));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 1.02e+18) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.02e+18: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.02e+18) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.02e+18) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.02e+18], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.02 \cdot 10^{+18}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 1.02e18Initial program 48.0%
hypot-def92.9%
Simplified92.9%
if 1.02e18 < re Initial program 8.1%
Taylor expanded in re around inf 52.1%
unpow252.1%
Simplified52.1%
add-log-exp18.3%
*-un-lft-identity18.3%
log-prod18.3%
metadata-eval18.3%
add-log-exp52.1%
sqrt-div66.0%
sqrt-prod86.2%
add-sqr-sqrt86.6%
Applied egg-rr86.6%
+-lft-identity86.6%
Simplified86.6%
Final simplification91.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))))
(if (<= re -7.8e+90)
t_0
(if (<= re -1.55e+77)
(* 0.5 (* (sqrt 2.0) (sqrt im)))
(if (<= re -3.3e+15)
t_0
(if (<= re 3.7e+14)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double tmp;
if (re <= -7.8e+90) {
tmp = t_0;
} else if (re <= -1.55e+77) {
tmp = 0.5 * (sqrt(2.0) * sqrt(im));
} else if (re <= -3.3e+15) {
tmp = t_0;
} else if (re <= 3.7e+14) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} 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((re * (-4.0d0)))
if (re <= (-7.8d+90)) then
tmp = t_0
else if (re <= (-1.55d+77)) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(im))
else if (re <= (-3.3d+15)) then
tmp = t_0
else if (re <= 3.7d+14) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
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 tmp;
if (re <= -7.8e+90) {
tmp = t_0;
} else if (re <= -1.55e+77) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(im));
} else if (re <= -3.3e+15) {
tmp = t_0;
} else if (re <= 3.7e+14) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) tmp = 0 if re <= -7.8e+90: tmp = t_0 elif re <= -1.55e+77: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(im)) elif re <= -3.3e+15: tmp = t_0 elif re <= 3.7e+14: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) tmp = 0.0 if (re <= -7.8e+90) tmp = t_0; elseif (re <= -1.55e+77) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(im))); elseif (re <= -3.3e+15) tmp = t_0; elseif (re <= 3.7e+14) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); 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)); tmp = 0.0; if (re <= -7.8e+90) tmp = t_0; elseif (re <= -1.55e+77) tmp = 0.5 * (sqrt(2.0) * sqrt(im)); elseif (re <= -3.3e+15) tmp = t_0; elseif (re <= 3.7e+14) tmp = 0.5 * sqrt((2.0 * (im - re))); 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]}, If[LessEqual[re, -7.8e+90], t$95$0, If[LessEqual[re, -1.55e+77], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -3.3e+15], t$95$0, If[LessEqual[re, 3.7e+14], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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}\\
\mathbf{if}\;re \leq -7.8 \cdot 10^{+90}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.55 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{im}\right)\\
\mathbf{elif}\;re \leq -3.3 \cdot 10^{+15}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 3.7 \cdot 10^{+14}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -7.8000000000000004e90 or -1.54999999999999999e77 < re < -3.3e15Initial program 40.2%
Taylor expanded in re around -inf 90.3%
*-commutative90.3%
Simplified90.3%
if -7.8000000000000004e90 < re < -1.54999999999999999e77Initial program 20.2%
Taylor expanded in re around 0 99.2%
if -3.3e15 < re < 3.7e14Initial program 53.5%
Taylor expanded in re around 0 80.5%
if 3.7e14 < re Initial program 8.1%
Taylor expanded in re around inf 50.9%
unpow250.9%
Simplified50.9%
add-log-exp18.0%
*-un-lft-identity18.0%
log-prod18.0%
metadata-eval18.0%
add-log-exp50.9%
sqrt-div64.4%
sqrt-prod85.2%
add-sqr-sqrt85.6%
Applied egg-rr85.6%
+-lft-identity85.6%
Simplified85.6%
Final simplification84.5%
(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 -2.8e+91)
t_0
(if (<= re -4.2e+75)
t_1
(if (<= re -3.6e+16)
t_0
(if (<= re 2.4e+14) 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 = 0.5 * sqrt((2.0 * (im - re)));
double tmp;
if (re <= -2.8e+91) {
tmp = t_0;
} else if (re <= -4.2e+75) {
tmp = t_1;
} else if (re <= -3.6e+16) {
tmp = t_0;
} else if (re <= 2.4e+14) {
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 = 0.5d0 * sqrt((2.0d0 * (im - re)))
if (re <= (-2.8d+91)) then
tmp = t_0
else if (re <= (-4.2d+75)) then
tmp = t_1
else if (re <= (-3.6d+16)) then
tmp = t_0
else if (re <= 2.4d+14) 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 = 0.5 * Math.sqrt((2.0 * (im - re)));
double tmp;
if (re <= -2.8e+91) {
tmp = t_0;
} else if (re <= -4.2e+75) {
tmp = t_1;
} else if (re <= -3.6e+16) {
tmp = t_0;
} else if (re <= 2.4e+14) {
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 = 0.5 * math.sqrt((2.0 * (im - re))) tmp = 0 if re <= -2.8e+91: tmp = t_0 elif re <= -4.2e+75: tmp = t_1 elif re <= -3.6e+16: tmp = t_0 elif re <= 2.4e+14: 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 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))) tmp = 0.0 if (re <= -2.8e+91) tmp = t_0; elseif (re <= -4.2e+75) tmp = t_1; elseif (re <= -3.6e+16) tmp = t_0; elseif (re <= 2.4e+14) 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 = 0.5 * sqrt((2.0 * (im - re))); tmp = 0.0; if (re <= -2.8e+91) tmp = t_0; elseif (re <= -4.2e+75) tmp = t_1; elseif (re <= -3.6e+16) tmp = t_0; elseif (re <= 2.4e+14) 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[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2.8e+91], t$95$0, If[LessEqual[re, -4.2e+75], t$95$1, If[LessEqual[re, -3.6e+16], t$95$0, If[LessEqual[re, 2.4e+14], 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 := 0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -2.8 \cdot 10^{+91}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -4.2 \cdot 10^{+75}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -3.6 \cdot 10^{+16}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 2.4 \cdot 10^{+14}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -2.7999999999999999e91 or -4.19999999999999997e75 < re < -3.6e16Initial program 40.2%
Taylor expanded in re around -inf 90.3%
*-commutative90.3%
Simplified90.3%
if -2.7999999999999999e91 < re < -4.19999999999999997e75 or -3.6e16 < re < 2.4e14Initial program 52.0%
Taylor expanded in re around 0 80.7%
if 2.4e14 < re Initial program 8.1%
Taylor expanded in re around inf 50.9%
unpow250.9%
Simplified50.9%
add-log-exp18.0%
*-un-lft-identity18.0%
log-prod18.0%
metadata-eval18.0%
add-log-exp50.9%
sqrt-div64.4%
sqrt-prod85.2%
add-sqr-sqrt85.6%
Applied egg-rr85.6%
+-lft-identity85.6%
Simplified85.6%
Final simplification84.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -7.8e+90)
t_0
(if (<= re -1.55e+77)
t_1
(if (<= re -6.6e+18)
t_0
(if (<= re 2.35e+17) 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 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -7.8e+90) {
tmp = t_0;
} else if (re <= -1.55e+77) {
tmp = t_1;
} else if (re <= -6.6e+18) {
tmp = t_0;
} else if (re <= 2.35e+17) {
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 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-7.8d+90)) then
tmp = t_0
else if (re <= (-1.55d+77)) then
tmp = t_1
else if (re <= (-6.6d+18)) then
tmp = t_0
else if (re <= 2.35d+17) 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 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -7.8e+90) {
tmp = t_0;
} else if (re <= -1.55e+77) {
tmp = t_1;
} else if (re <= -6.6e+18) {
tmp = t_0;
} else if (re <= 2.35e+17) {
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 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -7.8e+90: tmp = t_0 elif re <= -1.55e+77: tmp = t_1 elif re <= -6.6e+18: tmp = t_0 elif re <= 2.35e+17: 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 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -7.8e+90) tmp = t_0; elseif (re <= -1.55e+77) tmp = t_1; elseif (re <= -6.6e+18) tmp = t_0; elseif (re <= 2.35e+17) 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 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -7.8e+90) tmp = t_0; elseif (re <= -1.55e+77) tmp = t_1; elseif (re <= -6.6e+18) tmp = t_0; elseif (re <= 2.35e+17) 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[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -7.8e+90], t$95$0, If[LessEqual[re, -1.55e+77], t$95$1, If[LessEqual[re, -6.6e+18], t$95$0, If[LessEqual[re, 2.35e+17], 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 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -7.8 \cdot 10^{+90}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.55 \cdot 10^{+77}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -6.6 \cdot 10^{+18}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 2.35 \cdot 10^{+17}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -7.8000000000000004e90 or -1.54999999999999999e77 < re < -6.6e18Initial program 40.2%
Taylor expanded in re around -inf 90.3%
*-commutative90.3%
Simplified90.3%
if -7.8000000000000004e90 < re < -1.54999999999999999e77 or -6.6e18 < re < 2.35e17Initial program 52.0%
Taylor expanded in re around 0 79.6%
*-commutative79.6%
Simplified79.6%
if 2.35e17 < re Initial program 8.1%
Taylor expanded in re around inf 50.9%
unpow250.9%
Simplified50.9%
add-log-exp18.0%
*-un-lft-identity18.0%
log-prod18.0%
metadata-eval18.0%
add-log-exp50.9%
sqrt-div64.4%
sqrt-prod85.2%
add-sqr-sqrt85.6%
Applied egg-rr85.6%
+-lft-identity85.6%
Simplified85.6%
Final simplification83.6%
(FPCore (re im) :precision binary64 (if (or (<= re -1.3e+91) (and (not (<= re -5.2e+76)) (<= re -1.1e+18))) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if ((re <= -1.3e+91) || (!(re <= -5.2e+76) && (re <= -1.1e+18))) {
tmp = 0.5 * sqrt((re * -4.0));
} 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 <= (-1.3d+91)) .or. (.not. (re <= (-5.2d+76))) .and. (re <= (-1.1d+18))) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
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 <= -1.3e+91) || (!(re <= -5.2e+76) && (re <= -1.1e+18))) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -1.3e+91) or (not (re <= -5.2e+76) and (re <= -1.1e+18)): tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if ((re <= -1.3e+91) || (!(re <= -5.2e+76) && (re <= -1.1e+18))) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); 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 <= -1.3e+91) || (~((re <= -5.2e+76)) && (re <= -1.1e+18))) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -1.3e+91], And[N[Not[LessEqual[re, -5.2e+76]], $MachinePrecision], LessEqual[re, -1.1e+18]]], N[(0.5 * N[Sqrt[N[(re * -4.0), $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 -1.3 \cdot 10^{+91} \lor \neg \left(re \leq -5.2 \cdot 10^{+76}\right) \land re \leq -1.1 \cdot 10^{+18}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -1.3e91 or -5.1999999999999999e76 < re < -1.1e18Initial program 40.2%
Taylor expanded in re around -inf 90.3%
*-commutative90.3%
Simplified90.3%
if -1.3e91 < re < -5.1999999999999999e76 or -1.1e18 < re Initial program 36.4%
Taylor expanded in re around 0 58.2%
*-commutative58.2%
Simplified58.2%
Final simplification65.2%
(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 37.2%
Taylor expanded in re around 0 48.8%
*-commutative48.8%
Simplified48.8%
Final simplification48.8%
herbie shell --seed 2023200
(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)))))