
(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.55e+66) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (* 0.5 (* im (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= 1.55e+66) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = 0.5 * (im * pow(re, -0.5));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 1.55e+66) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.55e+66: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.55e+66) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); 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 <= 1.55e+66) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.55e+66], 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[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.55 \cdot 10^{+66}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < 1.55000000000000009e66Initial program 53.6%
sub-neg53.6%
sqr-neg53.6%
sub-neg53.6%
sqr-neg53.6%
hypot-def93.7%
Simplified93.7%
if 1.55000000000000009e66 < re Initial program 10.8%
Taylor expanded in re around inf 44.7%
div-inv44.7%
sqrt-prod67.6%
unpow267.6%
sqrt-prod86.7%
add-sqr-sqrt87.2%
*-commutative87.2%
inv-pow87.2%
sqrt-pow187.2%
metadata-eval87.2%
Applied egg-rr87.2%
Final simplification92.4%
(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.45e+63)
t_0
(if (<= re -3.4e-60)
t_1
(if (<= re -2.7e-117)
t_0
(if (<= re 8.8e+21) t_1 (* 0.5 (* im (pow re -0.5)))))))))
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.45e+63) {
tmp = t_0;
} else if (re <= -3.4e-60) {
tmp = t_1;
} else if (re <= -2.7e-117) {
tmp = t_0;
} else if (re <= 8.8e+21) {
tmp = t_1;
} 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) :: 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.45d+63)) then
tmp = t_0
else if (re <= (-3.4d-60)) then
tmp = t_1
else if (re <= (-2.7d-117)) then
tmp = t_0
else if (re <= 8.8d+21) then
tmp = t_1
else
tmp = 0.5d0 * (im * (re ** (-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 = 0.5 * Math.sqrt((2.0 * (im - re)));
double tmp;
if (re <= -1.45e+63) {
tmp = t_0;
} else if (re <= -3.4e-60) {
tmp = t_1;
} else if (re <= -2.7e-117) {
tmp = t_0;
} else if (re <= 8.8e+21) {
tmp = t_1;
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
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.45e+63: tmp = t_0 elif re <= -3.4e-60: tmp = t_1 elif re <= -2.7e-117: tmp = t_0 elif re <= 8.8e+21: tmp = t_1 else: tmp = 0.5 * (im * math.pow(re, -0.5)) 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.45e+63) tmp = t_0; elseif (re <= -3.4e-60) tmp = t_1; elseif (re <= -2.7e-117) tmp = t_0; elseif (re <= 8.8e+21) tmp = t_1; else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); 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.45e+63) tmp = t_0; elseif (re <= -3.4e-60) tmp = t_1; elseif (re <= -2.7e-117) tmp = t_0; elseif (re <= 8.8e+21) tmp = t_1; else tmp = 0.5 * (im * (re ^ -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[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.45e+63], t$95$0, If[LessEqual[re, -3.4e-60], t$95$1, If[LessEqual[re, -2.7e-117], t$95$0, If[LessEqual[re, 8.8e+21], t$95$1, N[(0.5 * N[(im * N[Power[re, -0.5], $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.45 \cdot 10^{+63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -3.4 \cdot 10^{-60}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.7 \cdot 10^{-117}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8.8 \cdot 10^{+21}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -1.45e63 or -3.40000000000000007e-60 < re < -2.70000000000000003e-117Initial program 42.9%
Taylor expanded in re around -inf 83.1%
*-commutative83.1%
Simplified83.1%
if -1.45e63 < re < -3.40000000000000007e-60 or -2.70000000000000003e-117 < re < 8.8e21Initial program 61.2%
Taylor expanded in re around 0 83.0%
if 8.8e21 < re Initial program 11.8%
Taylor expanded in re around inf 44.4%
div-inv44.4%
sqrt-prod64.2%
unpow264.2%
sqrt-prod82.0%
add-sqr-sqrt82.4%
*-commutative82.4%
inv-pow82.4%
sqrt-pow182.4%
metadata-eval82.4%
Applied egg-rr82.4%
Final simplification82.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -3.5e+55)
t_0
(if (<= re -2.2e-61)
t_1
(if (<= re -2.7e-117)
t_0
(if (<= re 7.5e+54) t_1 (* 0.5 (* im (pow re -0.5)))))))))
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 <= -3.5e+55) {
tmp = t_0;
} else if (re <= -2.2e-61) {
tmp = t_1;
} else if (re <= -2.7e-117) {
tmp = t_0;
} else if (re <= 7.5e+54) {
tmp = t_1;
} 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) :: 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 <= (-3.5d+55)) then
tmp = t_0
else if (re <= (-2.2d-61)) then
tmp = t_1
else if (re <= (-2.7d-117)) then
tmp = t_0
else if (re <= 7.5d+54) then
tmp = t_1
else
tmp = 0.5d0 * (im * (re ** (-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 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -3.5e+55) {
tmp = t_0;
} else if (re <= -2.2e-61) {
tmp = t_1;
} else if (re <= -2.7e-117) {
tmp = t_0;
} else if (re <= 7.5e+54) {
tmp = t_1;
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
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 <= -3.5e+55: tmp = t_0 elif re <= -2.2e-61: tmp = t_1 elif re <= -2.7e-117: tmp = t_0 elif re <= 7.5e+54: tmp = t_1 else: tmp = 0.5 * (im * math.pow(re, -0.5)) 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 <= -3.5e+55) tmp = t_0; elseif (re <= -2.2e-61) tmp = t_1; elseif (re <= -2.7e-117) tmp = t_0; elseif (re <= 7.5e+54) tmp = t_1; else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); 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 <= -3.5e+55) tmp = t_0; elseif (re <= -2.2e-61) tmp = t_1; elseif (re <= -2.7e-117) tmp = t_0; elseif (re <= 7.5e+54) tmp = t_1; else tmp = 0.5 * (im * (re ^ -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[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -3.5e+55], t$95$0, If[LessEqual[re, -2.2e-61], t$95$1, If[LessEqual[re, -2.7e-117], t$95$0, If[LessEqual[re, 7.5e+54], t$95$1, N[(0.5 * N[(im * N[Power[re, -0.5], $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 -3.5 \cdot 10^{+55}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -2.2 \cdot 10^{-61}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.7 \cdot 10^{-117}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 7.5 \cdot 10^{+54}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -3.5000000000000001e55 or -2.20000000000000009e-61 < re < -2.70000000000000003e-117Initial program 44.7%
Taylor expanded in re around -inf 81.5%
*-commutative81.5%
Simplified81.5%
if -3.5000000000000001e55 < re < -2.20000000000000009e-61 or -2.70000000000000003e-117 < re < 7.50000000000000042e54Initial program 58.9%
Taylor expanded in re around 0 81.0%
*-commutative81.0%
Simplified81.0%
if 7.50000000000000042e54 < re Initial program 10.9%
Taylor expanded in re around inf 43.5%
div-inv43.4%
sqrt-prod65.5%
unpow265.5%
sqrt-prod85.4%
add-sqr-sqrt85.8%
*-commutative85.8%
inv-pow85.8%
sqrt-pow185.8%
metadata-eval85.8%
Applied egg-rr85.8%
Final simplification82.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -1.32e+54)
t_0
(if (<= re -1.9e-61)
t_1
(if (<= re -2.7e-117)
t_0
(if (<= re 1.2e+55) 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 <= -1.32e+54) {
tmp = t_0;
} else if (re <= -1.9e-61) {
tmp = t_1;
} else if (re <= -2.7e-117) {
tmp = t_0;
} else if (re <= 1.2e+55) {
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 <= (-1.32d+54)) then
tmp = t_0
else if (re <= (-1.9d-61)) then
tmp = t_1
else if (re <= (-2.7d-117)) then
tmp = t_0
else if (re <= 1.2d+55) 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 <= -1.32e+54) {
tmp = t_0;
} else if (re <= -1.9e-61) {
tmp = t_1;
} else if (re <= -2.7e-117) {
tmp = t_0;
} else if (re <= 1.2e+55) {
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 <= -1.32e+54: tmp = t_0 elif re <= -1.9e-61: tmp = t_1 elif re <= -2.7e-117: tmp = t_0 elif re <= 1.2e+55: 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 <= -1.32e+54) tmp = t_0; elseif (re <= -1.9e-61) tmp = t_1; elseif (re <= -2.7e-117) tmp = t_0; elseif (re <= 1.2e+55) 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 <= -1.32e+54) tmp = t_0; elseif (re <= -1.9e-61) tmp = t_1; elseif (re <= -2.7e-117) tmp = t_0; elseif (re <= 1.2e+55) 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, -1.32e+54], t$95$0, If[LessEqual[re, -1.9e-61], t$95$1, If[LessEqual[re, -2.7e-117], t$95$0, If[LessEqual[re, 1.2e+55], 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 -1.32 \cdot 10^{+54}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -1.9 \cdot 10^{-61}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -2.7 \cdot 10^{-117}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 1.2 \cdot 10^{+55}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.3200000000000001e54 or -1.8999999999999999e-61 < re < -2.70000000000000003e-117Initial program 44.7%
Taylor expanded in re around -inf 81.5%
*-commutative81.5%
Simplified81.5%
if -1.3200000000000001e54 < re < -1.8999999999999999e-61 or -2.70000000000000003e-117 < re < 1.2e55Initial program 58.9%
Taylor expanded in re around 0 81.0%
*-commutative81.0%
Simplified81.0%
if 1.2e55 < re Initial program 10.9%
Taylor expanded in re around inf 43.5%
div-inv43.4%
sqrt-prod65.5%
unpow265.5%
sqrt-prod85.4%
add-sqr-sqrt85.8%
expm1-log1p-u84.7%
expm1-udef34.1%
sqrt-div34.1%
metadata-eval34.1%
div-inv34.1%
Applied egg-rr34.1%
expm1-def84.6%
expm1-log1p85.7%
Simplified85.7%
Final simplification82.0%
(FPCore (re im) :precision binary64 (if (or (<= re -3.1e+46) (and (not (<= re -7.5e-59)) (<= re -2.7e-117))) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if ((re <= -3.1e+46) || (!(re <= -7.5e-59) && (re <= -2.7e-117))) {
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 <= (-3.1d+46)) .or. (.not. (re <= (-7.5d-59))) .and. (re <= (-2.7d-117))) 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 <= -3.1e+46) || (!(re <= -7.5e-59) && (re <= -2.7e-117))) {
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 <= -3.1e+46) or (not (re <= -7.5e-59) and (re <= -2.7e-117)): 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 <= -3.1e+46) || (!(re <= -7.5e-59) && (re <= -2.7e-117))) 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 <= -3.1e+46) || (~((re <= -7.5e-59)) && (re <= -2.7e-117))) 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, -3.1e+46], And[N[Not[LessEqual[re, -7.5e-59]], $MachinePrecision], LessEqual[re, -2.7e-117]]], 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 -3.1 \cdot 10^{+46} \lor \neg \left(re \leq -7.5 \cdot 10^{-59}\right) \land re \leq -2.7 \cdot 10^{-117}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -3.09999999999999975e46 or -7.50000000000000019e-59 < re < -2.70000000000000003e-117Initial program 44.7%
Taylor expanded in re around -inf 81.5%
*-commutative81.5%
Simplified81.5%
if -3.09999999999999975e46 < re < -7.50000000000000019e-59 or -2.70000000000000003e-117 < re Initial program 45.7%
Taylor expanded in re around 0 63.8%
*-commutative63.8%
Simplified63.8%
Final simplification68.7%
(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 45.4%
Taylor expanded in re around 0 52.4%
*-commutative52.4%
Simplified52.4%
Final simplification52.4%
herbie shell --seed 2024010
(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)))))