
(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 (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* 0.5 (* im (pow re -0.5))) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im * pow(re, -0.5));
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = 0.5 * (im * math.pow(re, -0.5)) else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = 0.5 * (im * (re ^ -0.5)); else tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 10.3%
hypot-def10.3%
Simplified10.3%
Taylor expanded in re around inf 55.3%
unpow255.3%
Simplified55.3%
Taylor expanded in im around 0 99.6%
*-commutative99.6%
unpow1/299.6%
exp-to-pow93.9%
*-commutative93.9%
log-rec93.9%
neg-mul-193.9%
associate-*r*93.9%
metadata-eval93.9%
log-pow93.9%
rem-exp-log99.7%
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 49.6%
hypot-def90.8%
Simplified90.8%
Final simplification92.1%
(FPCore (re im)
:precision binary64
(if (<= re -4.6e+30)
(* 0.5 (sqrt (- (* re -4.0) (/ im (/ re im)))))
(if (<= re 1.75e-75)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -4.6e+30) {
tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= 1.75e-75) {
tmp = 0.5 * sqrt((2.0 * (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 <= (-4.6d+30)) then
tmp = 0.5d0 * sqrt(((re * (-4.0d0)) - (im / (re / im))))
else if (re <= 1.75d-75) then
tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -4.6e+30) {
tmp = 0.5 * Math.sqrt(((re * -4.0) - (im / (re / im))));
} else if (re <= 1.75e-75) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.6e+30: tmp = 0.5 * math.sqrt(((re * -4.0) - (im / (re / im)))) elif re <= 1.75e-75: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.6e+30) tmp = Float64(0.5 * sqrt(Float64(Float64(re * -4.0) - Float64(im / Float64(re / im))))); elseif (re <= 1.75e-75) tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -4.6e+30) tmp = 0.5 * sqrt(((re * -4.0) - (im / (re / im)))); elseif (re <= 1.75e-75) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.6e+30], N[(0.5 * N[Sqrt[N[(N[(re * -4.0), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.75e-75], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - 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 -4.6 \cdot 10^{+30}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4 - \frac{im}{\frac{re}{im}}}\\
\mathbf{elif}\;re \leq 1.75 \cdot 10^{-75}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -4.6e30Initial program 39.1%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 72.4%
+-commutative72.4%
mul-1-neg72.4%
unsub-neg72.4%
*-commutative72.4%
unpow272.4%
associate-/l*79.8%
Simplified79.8%
if -4.6e30 < re < 1.74999999999999993e-75Initial program 63.5%
Taylor expanded in re around 0 81.2%
if 1.74999999999999993e-75 < re Initial program 18.2%
hypot-def41.2%
Simplified41.2%
Taylor expanded in re around inf 44.4%
unpow244.4%
Simplified44.4%
Taylor expanded in im around 0 71.2%
*-commutative71.2%
unpow1/271.2%
exp-to-pow67.2%
*-commutative67.2%
log-rec67.2%
neg-mul-167.2%
associate-*r*67.2%
metadata-eval67.2%
log-pow67.2%
rem-exp-log71.2%
Simplified71.2%
Final simplification77.7%
(FPCore (re im)
:precision binary64
(if (<= re -6e+30)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.75e-75)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -6e+30) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.75e-75) {
tmp = 0.5 * sqrt((2.0 * (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 <= (-6d+30)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.75d-75) then
tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -6e+30) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.75e-75) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -6e+30: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.75e-75: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -6e+30) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.75e-75) tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -6e+30) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.75e-75) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -6e+30], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.75e-75], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - 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 -6 \cdot 10^{+30}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.75 \cdot 10^{-75}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -5.99999999999999956e30Initial program 39.1%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 79.5%
*-commutative79.5%
Simplified79.5%
if -5.99999999999999956e30 < re < 1.74999999999999993e-75Initial program 63.5%
Taylor expanded in re around 0 81.2%
if 1.74999999999999993e-75 < re Initial program 18.2%
hypot-def41.2%
Simplified41.2%
Taylor expanded in re around inf 44.4%
unpow244.4%
Simplified44.4%
Taylor expanded in im around 0 71.2%
*-commutative71.2%
unpow1/271.2%
exp-to-pow67.2%
*-commutative67.2%
log-rec67.2%
neg-mul-167.2%
associate-*r*67.2%
metadata-eval67.2%
log-pow67.2%
rem-exp-log71.2%
Simplified71.2%
Final simplification77.7%
(FPCore (re im)
:precision binary64
(if (<= re -0.108)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.75e-75)
(* 0.5 (sqrt (* 2.0 im)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -0.108) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.75e-75) {
tmp = 0.5 * sqrt((2.0 * im));
} 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 <= (-0.108d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.75d-75) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
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 <= -0.108) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.75e-75) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.108: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.75e-75: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.108) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.75e-75) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); 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 <= -0.108) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.75e-75) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.108], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.75e-75], N[(0.5 * N[Sqrt[N[(2.0 * im), $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 -0.108:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.75 \cdot 10^{-75}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -0.107999999999999999Initial program 45.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 74.8%
*-commutative74.8%
Simplified74.8%
if -0.107999999999999999 < re < 1.74999999999999993e-75Initial program 62.1%
hypot-def94.7%
Simplified94.7%
Taylor expanded in re around 0 81.7%
*-commutative81.7%
Simplified81.7%
if 1.74999999999999993e-75 < re Initial program 18.2%
hypot-def41.2%
Simplified41.2%
Taylor expanded in re around inf 44.4%
unpow244.4%
Simplified44.4%
Taylor expanded in im around 0 71.2%
*-commutative71.2%
unpow1/271.2%
exp-to-pow67.2%
*-commutative67.2%
log-rec67.2%
neg-mul-167.2%
associate-*r*67.2%
metadata-eval67.2%
log-pow67.2%
rem-exp-log71.2%
Simplified71.2%
Final simplification76.6%
(FPCore (re im) :precision binary64 (if (<= re -0.09) (* 0.5 (sqrt (* re -4.0))) (if (<= re 1.6e-75) (* 0.5 (sqrt (* 2.0 im))) (* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -0.09) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.6e-75) {
tmp = 0.5 * sqrt((2.0 * im));
} 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) :: tmp
if (re <= (-0.09d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.6d-75) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.09) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.6e-75) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.09: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.6e-75: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.09) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.6e-75) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.09) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.6e-75) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.09], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.6e-75], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.09:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.6 \cdot 10^{-75}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.089999999999999997Initial program 45.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 74.8%
*-commutative74.8%
Simplified74.8%
if -0.089999999999999997 < re < 1.59999999999999988e-75Initial program 62.1%
hypot-def94.7%
Simplified94.7%
Taylor expanded in re around 0 81.7%
*-commutative81.7%
Simplified81.7%
if 1.59999999999999988e-75 < re Initial program 18.2%
hypot-def41.2%
Simplified41.2%
Taylor expanded in re around inf 44.4%
unpow244.4%
Simplified44.4%
expm1-log1p-u44.1%
expm1-udef20.7%
sqrt-div20.7%
sqrt-prod25.9%
add-sqr-sqrt25.9%
Applied egg-rr25.9%
expm1-def70.6%
expm1-log1p71.2%
Simplified71.2%
Final simplification76.6%
(FPCore (re im) :precision binary64 (if (<= re -0.155) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -0.155) {
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 <= (-0.155d0)) 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 <= -0.155) {
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 <= -0.155: 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 <= -0.155) 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 <= -0.155) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.155], 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 -0.155:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -0.154999999999999999Initial program 45.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 74.8%
*-commutative74.8%
Simplified74.8%
if -0.154999999999999999 < re Initial program 43.3%
hypot-def71.8%
Simplified71.8%
Taylor expanded in re around 0 61.3%
*-commutative61.3%
Simplified61.3%
Final simplification64.8%
(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 44.0%
hypot-def79.2%
Simplified79.2%
Taylor expanded in re around 0 53.2%
*-commutative53.2%
Simplified53.2%
Final simplification53.2%
herbie shell --seed 2023252
(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)))))