
(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 10 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 9.5e-54)
(* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))
(*
0.5
(fma
im
(* (sqrt 2.0) (* (sqrt 0.5) (sqrt (/ 1.0 re))))
(*
(sqrt (/ 1.0 (pow re 5.0)))
(* -0.0625 (* (pow im 3.0) (/ (sqrt 2.0) (sqrt 0.5)))))))))
double code(double re, double im) {
double tmp;
if (re <= 9.5e-54) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = 0.5 * fma(im, (sqrt(2.0) * (sqrt(0.5) * sqrt((1.0 / re)))), (sqrt((1.0 / pow(re, 5.0))) * (-0.0625 * (pow(im, 3.0) * (sqrt(2.0) / sqrt(0.5))))));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= 9.5e-54) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); else tmp = Float64(0.5 * fma(im, Float64(sqrt(2.0) * Float64(sqrt(0.5) * sqrt(Float64(1.0 / re)))), Float64(sqrt(Float64(1.0 / (re ^ 5.0))) * Float64(-0.0625 * Float64((im ^ 3.0) * Float64(sqrt(2.0) / sqrt(0.5))))))); end return tmp end
code[re_, im_] := If[LessEqual[re, 9.5e-54], 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[(N[Sqrt[2.0], $MachinePrecision] * N[(N[Sqrt[0.5], $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[N[(1.0 / N[Power[re, 5.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-0.0625 * N[(N[Power[im, 3.0], $MachinePrecision] * N[(N[Sqrt[2.0], $MachinePrecision] / N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 9.5 \cdot 10^{-54}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, \sqrt{2} \cdot \left(\sqrt{0.5} \cdot \sqrt{\frac{1}{re}}\right), \sqrt{\frac{1}{{re}^{5}}} \cdot \left(-0.0625 \cdot \left({im}^{3} \cdot \frac{\sqrt{2}}{\sqrt{0.5}}\right)\right)\right)\\
\end{array}
\end{array}
if re < 9.4999999999999994e-54Initial program 52.4%
sub-neg52.4%
sqr-neg52.4%
sub-neg52.4%
sqr-neg52.4%
hypot-define95.0%
Simplified95.0%
if 9.4999999999999994e-54 < re Initial program 12.2%
Taylor expanded in re around inf 73.8%
+-commutative73.8%
associate-*l*73.8%
*-commutative73.8%
fma-define73.8%
*-commutative73.8%
*-commutative73.8%
associate-*l*74.2%
associate-*r*74.2%
*-commutative74.2%
associate-/l*74.2%
Simplified74.2%
Final simplification89.8%
(FPCore (re im) :precision binary64 (if (<= re -2.5e+26) (* 0.5 (sqrt (* 2.0 (* re -2.0)))) (* 0.5 (* (sqrt 2.0) (sqrt im)))))
double code(double re, double im) {
double tmp;
if (re <= -2.5e+26) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * (sqrt(2.0) * sqrt(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.5d+26)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.5e+26) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.5e+26: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) else: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.5e+26) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); else tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.5e+26) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); else tmp = 0.5 * (sqrt(2.0) * sqrt(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.5e+26], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.5 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{im}\right)\\
\end{array}
\end{array}
if re < -2.5e26Initial program 36.7%
Taylor expanded in re around -inf 74.1%
*-commutative74.1%
Simplified74.1%
if -2.5e26 < re Initial program 43.9%
Taylor expanded in re around 0 63.5%
Final simplification65.8%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
}
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}
\end{array}
Initial program 42.3%
sub-neg42.3%
sqr-neg42.3%
sub-neg42.3%
sqr-neg42.3%
hypot-define79.9%
Simplified79.9%
Final simplification79.9%
(FPCore (re im) :precision binary64 (if (<= re -5.8e+26) (* 0.5 (sqrt (* 2.0 (* re -2.0)))) (* 0.5 (sqrt (* 2.0 (+ im (* re (+ (* 0.5 (/ re im)) -1.0))))))))
double code(double re, double im) {
double tmp;
if (re <= -5.8e+26) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * sqrt((2.0 * (im + (re * ((0.5 * (re / im)) + -1.0)))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-5.8d+26)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (im + (re * ((0.5d0 * (re / im)) + (-1.0d0))))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5.8e+26) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (im + (re * ((0.5 * (re / im)) + -1.0)))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.8e+26: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) else: tmp = 0.5 * math.sqrt((2.0 * (im + (re * ((0.5 * (re / im)) + -1.0))))) return tmp
function code(re, im) tmp = 0.0 if (re <= -5.8e+26) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im + Float64(re * Float64(Float64(0.5 * Float64(re / im)) + -1.0)))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5.8e+26) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); else tmp = 0.5 * sqrt((2.0 * (im + (re * ((0.5 * (re / im)) + -1.0))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.8e+26], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im + N[(re * N[(N[(0.5 * N[(re / im), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.8 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + re \cdot \left(0.5 \cdot \frac{re}{im} + -1\right)\right)}\\
\end{array}
\end{array}
if re < -5.8e26Initial program 36.7%
Taylor expanded in re around -inf 74.1%
*-commutative74.1%
Simplified74.1%
if -5.8e26 < re Initial program 43.9%
Taylor expanded in re around 0 64.0%
Final simplification66.2%
(FPCore (re im) :precision binary64 (if (<= re -4.6e+26) (* 0.5 (sqrt (* 2.0 (* re -2.0)))) (* 0.5 (sqrt (* 2.0 (* im (- 1.0 (/ re im))))))))
double code(double re, double im) {
double tmp;
if (re <= -4.6e+26) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * sqrt((2.0 * (im * (1.0 - (re / im)))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-4.6d+26)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (im * (1.0d0 - (re / im)))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.6e+26) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (im * (1.0 - (re / im)))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.6e+26: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) else: tmp = 0.5 * math.sqrt((2.0 * (im * (1.0 - (re / im))))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.6e+26) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im * Float64(1.0 - Float64(re / im)))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.6e+26) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); else tmp = 0.5 * sqrt((2.0 * (im * (1.0 - (re / im))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.6e+26], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im * N[(1.0 - N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.6 \cdot 10^{+26}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im \cdot \left(1 - \frac{re}{im}\right)\right)}\\
\end{array}
\end{array}
if re < -4.6000000000000001e26Initial program 36.7%
Taylor expanded in re around -inf 74.1%
*-commutative74.1%
Simplified74.1%
if -4.6000000000000001e26 < re Initial program 43.9%
Taylor expanded in im around inf 63.1%
mul-1-neg63.1%
unsub-neg63.1%
Simplified63.1%
Final simplification65.5%
(FPCore (re im) :precision binary64 (if (<= re -1.22e+27) (* 0.5 (sqrt (* 2.0 (* re -2.0)))) (* 0.5 (sqrt (* 2.0 (- im re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.22e+27) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * sqrt((2.0 * (im - 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.22d+27)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.22e+27) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.22e+27: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) else: tmp = 0.5 * math.sqrt((2.0 * (im - re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.22e+27) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.22e+27) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); else tmp = 0.5 * sqrt((2.0 * (im - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.22e+27], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.22 \cdot 10^{+27}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if re < -1.2200000000000001e27Initial program 36.7%
Taylor expanded in re around -inf 74.1%
*-commutative74.1%
Simplified74.1%
if -1.2200000000000001e27 < re Initial program 43.9%
Taylor expanded in re around 0 63.1%
Final simplification65.5%
(FPCore (re im) :precision binary64 (if (<= re 1.85e+195) (* 0.5 (sqrt (* 2.0 (- im re)))) (* 0.5 (sqrt (* 2.0 (- re re))))))
double code(double re, double im) {
double tmp;
if (re <= 1.85e+195) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (re - 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.85d+195) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * sqrt((2.0d0 * (re - re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.85e+195) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (re - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.85e+195: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * math.sqrt((2.0 * (re - re))) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.85e+195) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.85e+195) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * sqrt((2.0 * (re - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.85e+195], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(re - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.85 \cdot 10^{+195}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re - re\right)}\\
\end{array}
\end{array}
if re < 1.85e195Initial program 45.7%
Taylor expanded in re around 0 62.2%
if 1.85e195 < re Initial program 2.2%
Taylor expanded in re around inf 29.4%
Final simplification59.7%
(FPCore (re im) :precision binary64 (if (<= re 1.75e-122) (* 0.5 (sqrt (* 2.0 (- im re)))) (* 0.5 (* im (sqrt (/ 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= 1.75e-122) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * sqrt((1.0 / 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.75d-122) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.75e-122) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.75e-122: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.75e-122) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.75e-122) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.75e-122], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.75 \cdot 10^{-122}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < 1.7500000000000001e-122Initial program 53.2%
Taylor expanded in re around 0 71.8%
if 1.7500000000000001e-122 < re Initial program 17.1%
Taylor expanded in re around inf 74.8%
associate-*l*74.8%
*-commutative74.8%
Simplified74.8%
add-log-exp14.1%
*-un-lft-identity14.1%
log-prod14.1%
metadata-eval14.1%
add-log-exp74.8%
sqrt-unprod75.7%
metadata-eval75.7%
metadata-eval75.7%
*-un-lft-identity75.7%
sqrt-div75.6%
metadata-eval75.6%
un-div-inv75.8%
Applied egg-rr75.8%
+-lft-identity75.8%
Simplified75.8%
Taylor expanded in im around 0 75.7%
Final simplification73.0%
(FPCore (re im) :precision binary64 (if (<= re 5.4e-123) (* 0.5 (sqrt (* 2.0 (- im re)))) (* 0.5 (* im (sqrt (/ 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= 5.4e-123) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * sqrt((1.0 / re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 5.4d-123) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 5.4e-123) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 5.4e-123: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= 5.4e-123) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 5.4e-123) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 5.4e-123], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 5.4 \cdot 10^{-123}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < 5.4000000000000002e-123Initial program 53.2%
Taylor expanded in re around 0 71.8%
if 5.4000000000000002e-123 < re Initial program 17.1%
Taylor expanded in re around inf 74.8%
associate-*l*74.8%
*-commutative74.8%
Simplified74.8%
sqrt-unprod75.7%
metadata-eval75.7%
metadata-eval75.7%
Applied egg-rr75.7%
Final simplification73.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.3%
Taylor expanded in re around 0 55.6%
add-log-exp9.6%
*-un-lft-identity9.6%
log-prod9.6%
metadata-eval9.6%
add-log-exp55.6%
sqrt-unprod55.9%
Applied egg-rr55.9%
+-lft-identity55.9%
Simplified55.9%
Final simplification55.9%
herbie shell --seed 2024066
(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)))))