
(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 9 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) (/ (* im 0.5) (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 = (im * 0.5) / 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 = (im * 0.5) / 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 = (im * 0.5) / 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(Float64(im * 0.5) / 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 = (im * 0.5) / 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[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $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:\\
\;\;\;\;\frac{im \cdot 0.5}{\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.3%
hypot-def13.9%
Simplified13.9%
Taylor expanded in re around inf 41.6%
unpow241.6%
Simplified41.6%
sqrt-div46.5%
sqrt-prod94.6%
add-sqr-sqrt95.0%
associate-*r/95.0%
Applied egg-rr95.0%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 51.8%
hypot-def92.7%
Simplified92.7%
add-sqr-sqrt92.0%
sqrt-unprod92.7%
*-commutative92.7%
*-commutative92.7%
swap-sqr92.7%
add-sqr-sqrt92.7%
metadata-eval92.7%
Applied egg-rr92.7%
*-commutative92.7%
associate-*r*92.7%
metadata-eval92.7%
Simplified92.7%
Final simplification93.0%
(FPCore (re im)
:precision binary64
(if (<= re -7.8e-22)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6.6e+16)
(sqrt (* 0.5 (- im re)))
(* (* im 0.5) (sqrt (/ 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= -7.8e-22) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.6e+16) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * 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 <= (-7.8d-22)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.6d+16) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) * sqrt((1.0d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -7.8e-22) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.6e+16) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * Math.sqrt((1.0 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -7.8e-22: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.6e+16: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) * math.sqrt((1.0 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -7.8e-22) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.6e+16) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) * sqrt(Float64(1.0 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -7.8e-22) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.6e+16) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) * sqrt((1.0 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -7.8e-22], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e+16], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7.8 \cdot 10^{-22}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{+16}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot \sqrt{\frac{1}{re}}\\
\end{array}
\end{array}
if re < -7.79999999999999996e-22Initial program 41.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 80.0%
*-commutative80.0%
Simplified80.0%
if -7.79999999999999996e-22 < re < 6.6e16Initial program 59.7%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.4%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in re around 0 78.2%
neg-mul-178.2%
+-commutative78.2%
unsub-neg78.2%
Simplified78.2%
if 6.6e16 < re Initial program 11.4%
hypot-def37.6%
Simplified37.6%
Taylor expanded in re around inf 45.8%
unpow245.8%
Simplified45.8%
Taylor expanded in im around 0 77.2%
*-commutative77.2%
associate-*r*77.2%
Simplified77.2%
Final simplification78.4%
(FPCore (re im) :precision binary64 (if (<= re -3.35e-22) (* 0.5 (sqrt (* re -4.0))) (if (<= re 5e+16) (sqrt (* 0.5 (- im re))) (* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -3.35e-22) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 5e+16) {
tmp = sqrt((0.5 * (im - re)));
} 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) :: tmp
if (re <= (-3.35d-22)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 5d+16) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.35e-22) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 5e+16) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.35e-22: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 5e+16: tmp = math.sqrt((0.5 * (im - re))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.35e-22) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 5e+16) tmp = sqrt(Float64(0.5 * Float64(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 <= -3.35e-22) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 5e+16) tmp = sqrt((0.5 * (im - re))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.35e-22], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5e+16], N[Sqrt[N[(0.5 * N[(im - re), $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 -3.35 \cdot 10^{-22}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 5 \cdot 10^{+16}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -3.34999999999999996e-22Initial program 41.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 80.0%
*-commutative80.0%
Simplified80.0%
if -3.34999999999999996e-22 < re < 5e16Initial program 59.7%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.4%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in re around 0 78.2%
neg-mul-178.2%
+-commutative78.2%
unsub-neg78.2%
Simplified78.2%
if 5e16 < re Initial program 11.4%
hypot-def37.6%
Simplified37.6%
add-sqr-sqrt37.4%
sqrt-unprod37.6%
*-commutative37.6%
*-commutative37.6%
swap-sqr37.6%
add-sqr-sqrt37.6%
metadata-eval37.6%
Applied egg-rr37.6%
*-commutative37.6%
associate-*r*37.6%
metadata-eval37.6%
Simplified37.6%
Taylor expanded in im around 0 76.3%
associate-*l*76.4%
unpow276.4%
rem-square-sqrt77.2%
unpow1/277.2%
exp-to-pow72.3%
*-commutative72.3%
log-rec72.3%
neg-mul-172.3%
associate-*r*72.3%
metadata-eval72.3%
log-pow72.3%
rem-exp-log77.2%
Simplified77.2%
Final simplification78.4%
(FPCore (re im) :precision binary64 (if (<= re -5.3e-20) (* 0.5 (sqrt (* re -4.0))) (if (<= re 6.6e+16) (sqrt (* 0.5 (- im re))) (* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -5.3e-20) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.6e+16) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * pow(re, -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 <= (-5.3d-20)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.6d+16) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5.3e-20) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.6e+16) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.3e-20: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.6e+16: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -5.3e-20) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.6e+16) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5.3e-20) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.6e+16) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.3e-20], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e+16], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.3 \cdot 10^{-20}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{+16}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -5.3000000000000002e-20Initial program 41.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 80.0%
*-commutative80.0%
Simplified80.0%
if -5.3000000000000002e-20 < re < 6.6e16Initial program 59.7%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.4%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in re around 0 78.2%
neg-mul-178.2%
+-commutative78.2%
unsub-neg78.2%
Simplified78.2%
if 6.6e16 < re Initial program 11.4%
hypot-def37.6%
Simplified37.6%
Taylor expanded in re around inf 45.8%
unpow245.8%
associate-/l*51.6%
Simplified51.6%
*-commutative51.6%
sqrt-div60.9%
associate-*l/60.9%
Applied egg-rr60.9%
associate-/l*60.9%
associate-/r/60.9%
sqrt-div51.6%
associate-/l*45.8%
div-inv45.8%
sqrt-prod60.2%
sqrt-prod77.1%
add-sqr-sqrt77.2%
*-commutative77.2%
associate-*l*77.2%
*-commutative77.2%
inv-pow77.2%
sqrt-pow177.2%
metadata-eval77.2%
Applied egg-rr77.2%
Final simplification78.4%
(FPCore (re im) :precision binary64 (if (<= re -6.8e-21) (* 0.5 (sqrt (* re -4.0))) (if (<= re 6.6e+16) (sqrt (* 0.5 (- im re))) (/ 0.5 (/ (sqrt re) im)))))
double code(double re, double im) {
double tmp;
if (re <= -6.8e-21) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.6e+16) {
tmp = sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 / (sqrt(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 <= (-6.8d-21)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.6d+16) then
tmp = sqrt((0.5d0 * (im - re)))
else
tmp = 0.5d0 / (sqrt(re) / im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -6.8e-21) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.6e+16) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = 0.5 / (Math.sqrt(re) / im);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6.8e-21: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.6e+16: tmp = math.sqrt((0.5 * (im - re))) else: tmp = 0.5 / (math.sqrt(re) / im) return tmp
function code(re, im) tmp = 0.0 if (re <= -6.8e-21) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.6e+16) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(0.5 / Float64(sqrt(re) / im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -6.8e-21) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.6e+16) tmp = sqrt((0.5 * (im - re))); else tmp = 0.5 / (sqrt(re) / im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6.8e-21], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.6e+16], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6.8 \cdot 10^{-21}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.6 \cdot 10^{+16}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\end{array}
\end{array}
if re < -6.8e-21Initial program 41.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 80.0%
*-commutative80.0%
Simplified80.0%
if -6.8e-21 < re < 6.6e16Initial program 59.7%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.4%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in re around 0 78.2%
neg-mul-178.2%
+-commutative78.2%
unsub-neg78.2%
Simplified78.2%
if 6.6e16 < re Initial program 11.4%
hypot-def37.6%
Simplified37.6%
Taylor expanded in re around inf 45.8%
unpow245.8%
Simplified45.8%
*-commutative45.8%
associate-/l*51.6%
sqrt-div60.9%
associate-/r/60.9%
associate-/l*60.9%
expm1-log1p-u60.4%
expm1-udef28.6%
Applied egg-rr28.6%
expm1-def76.6%
expm1-log1p77.1%
associate-*r/77.2%
associate-/l*76.8%
Simplified76.8%
Final simplification78.3%
(FPCore (re im) :precision binary64 (if (<= re -1.02e-20) (* 0.5 (sqrt (* re -4.0))) (if (<= re 6.8e+16) (sqrt (* 0.5 (- im re))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.02e-20) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.8e+16) {
tmp = sqrt((0.5 * (im - re)));
} 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.02d-20)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.8d+16) then
tmp = sqrt((0.5d0 * (im - re)))
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.02e-20) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.8e+16) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.02e-20: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.8e+16: tmp = math.sqrt((0.5 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.02e-20) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.8e+16) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.02e-20) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.8e+16) tmp = sqrt((0.5 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.02e-20], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.8e+16], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.02 \cdot 10^{-20}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.8 \cdot 10^{+16}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.02000000000000001e-20Initial program 41.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 80.0%
*-commutative80.0%
Simplified80.0%
if -1.02000000000000001e-20 < re < 6.8e16Initial program 59.7%
hypot-def89.0%
Simplified89.0%
add-sqr-sqrt88.4%
sqrt-unprod89.0%
*-commutative89.0%
*-commutative89.0%
swap-sqr89.0%
add-sqr-sqrt89.0%
metadata-eval89.0%
Applied egg-rr89.0%
*-commutative89.0%
associate-*r*89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in re around 0 78.2%
neg-mul-178.2%
+-commutative78.2%
unsub-neg78.2%
Simplified78.2%
if 6.8e16 < re Initial program 11.4%
hypot-def37.6%
Simplified37.6%
Taylor expanded in re around inf 45.8%
unpow245.8%
Simplified45.8%
sqrt-div60.0%
sqrt-prod77.0%
add-sqr-sqrt77.1%
associate-*r/77.2%
Applied egg-rr77.2%
Final simplification78.4%
(FPCore (re im) :precision binary64 (if (<= re -1.46e-22) (* 0.5 (sqrt (* re -4.0))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.46e-22) {
tmp = 0.5 * sqrt((re * -4.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) :: tmp
if (re <= (-1.46d-22)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.46e-22) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.46e-22: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.46e-22) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.46e-22) tmp = 0.5 * sqrt((re * -4.0)); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.46e-22], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.46 \cdot 10^{-22}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -1.46000000000000001e-22Initial program 41.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 80.0%
*-commutative80.0%
Simplified80.0%
if -1.46000000000000001e-22 < re Initial program 46.6%
hypot-def75.1%
Simplified75.1%
add-sqr-sqrt74.6%
sqrt-unprod75.1%
*-commutative75.1%
*-commutative75.1%
swap-sqr75.1%
add-sqr-sqrt75.1%
metadata-eval75.1%
Applied egg-rr75.1%
*-commutative75.1%
associate-*r*75.1%
metadata-eval75.1%
Simplified75.1%
Taylor expanded in re around 0 63.7%
Final simplification67.8%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 (- im re))))
double code(double re, double im) {
return sqrt((0.5 * (im - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((0.5d0 * (im - re)))
end function
public static double code(double re, double im) {
return Math.sqrt((0.5 * (im - re)));
}
def code(re, im): return math.sqrt((0.5 * (im - re)))
function code(re, im) return sqrt(Float64(0.5 * Float64(im - re))) end
function tmp = code(re, im) tmp = sqrt((0.5 * (im - re))); end
code[re_, im_] := N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(im - re\right)}
\end{array}
Initial program 45.4%
hypot-def81.3%
Simplified81.3%
add-sqr-sqrt80.8%
sqrt-unprod81.3%
*-commutative81.3%
*-commutative81.3%
swap-sqr81.3%
add-sqr-sqrt81.3%
metadata-eval81.3%
Applied egg-rr81.3%
*-commutative81.3%
associate-*r*81.3%
metadata-eval81.3%
Simplified81.3%
Taylor expanded in re around 0 56.5%
neg-mul-156.5%
+-commutative56.5%
unsub-neg56.5%
Simplified56.5%
Final simplification56.5%
(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 45.4%
hypot-def81.3%
Simplified81.3%
add-sqr-sqrt80.8%
sqrt-unprod81.3%
*-commutative81.3%
*-commutative81.3%
swap-sqr81.3%
add-sqr-sqrt81.3%
metadata-eval81.3%
Applied egg-rr81.3%
*-commutative81.3%
associate-*r*81.3%
metadata-eval81.3%
Simplified81.3%
Taylor expanded in re around 0 54.0%
Final simplification54.0%
herbie shell --seed 2023242
(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)))))