
(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 (+ (* 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(((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(((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(((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 (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(((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[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $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{re \cdot re + im \cdot im} - re \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 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 7.5%
Taylor expanded in re around inf 93.7%
*-commutative93.7%
associate-*l*94.2%
Simplified94.2%
add-cube-cbrt93.5%
pow393.5%
sqrt-div93.6%
metadata-eval93.6%
un-div-inv93.7%
associate-*r*93.7%
sqrt-unprod93.5%
metadata-eval93.5%
metadata-eval93.5%
*-un-lft-identity93.5%
Applied egg-rr93.5%
rem-cube-cbrt95.0%
clear-num93.2%
associate-/r/95.0%
pow1/295.0%
pow-flip95.2%
metadata-eval95.2%
Applied egg-rr95.2%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 44.2%
sub-neg44.2%
sqr-neg44.2%
sub-neg44.2%
sqr-neg44.2%
hypot-define89.9%
Simplified89.9%
Final simplification90.7%
(FPCore (re im)
:precision binary64
(if (<= re -0.18)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.4e-149)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 2.3e-97)
(* 0.5 (/ im (sqrt re)))
(if (<= re 2.35e+67)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.18) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.4e-149) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 2.3e-97) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 2.35e+67) {
tmp = 0.5 * sqrt((im * 2.0));
} 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.18d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.4d-149) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 2.3d-97) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 2.35d+67) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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.18) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.4e-149) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 2.3e-97) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 2.35e+67) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.18: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.4e-149: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 2.3e-97: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 2.35e+67: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.18) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.4e-149) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 2.3e-97) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 2.35e+67) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); 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.18) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.4e-149) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 2.3e-97) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 2.35e+67) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.18], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.4e-149], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.3e-97], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.35e+67], N[(0.5 * N[Sqrt[N[(im * 2.0), $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.18:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.4 \cdot 10^{-149}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 2.3 \cdot 10^{-97}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 2.35 \cdot 10^{+67}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -0.17999999999999999Initial program 37.2%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -0.17999999999999999 < re < 2.4000000000000001e-149Initial program 60.1%
Taylor expanded in re around 0 82.8%
if 2.4000000000000001e-149 < re < 2.29999999999999994e-97Initial program 33.5%
Taylor expanded in re around inf 71.0%
*-commutative71.0%
associate-*l*71.4%
Simplified71.4%
sqrt-div71.6%
metadata-eval71.6%
un-div-inv71.4%
associate-*r*71.2%
sqrt-unprod72.1%
metadata-eval72.1%
metadata-eval72.1%
*-un-lft-identity72.1%
Applied egg-rr72.1%
if 2.29999999999999994e-97 < re < 2.35000000000000009e67Initial program 27.8%
Taylor expanded in re around 0 70.4%
*-commutative70.4%
Simplified70.4%
if 2.35000000000000009e67 < re Initial program 7.8%
Taylor expanded in re around inf 90.4%
*-commutative90.4%
associate-*l*91.0%
Simplified91.0%
add-cube-cbrt90.3%
pow390.4%
sqrt-div90.3%
metadata-eval90.3%
un-div-inv90.3%
associate-*r*90.5%
sqrt-unprod90.0%
metadata-eval90.0%
metadata-eval90.0%
*-un-lft-identity90.0%
Applied egg-rr90.0%
rem-cube-cbrt91.5%
clear-num88.9%
associate-/r/91.3%
pow1/291.3%
pow-flip91.6%
metadata-eval91.6%
Applied egg-rr91.6%
Final simplification81.8%
(FPCore (re im)
:precision binary64
(if (<= re -1050.0)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.55e-149)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 1.65e-99)
(* 0.5 (* im (/ 1.0 (sqrt re))))
(if (<= re 7e+67)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))))
double code(double re, double im) {
double tmp;
if (re <= -1050.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.55e-149) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 1.65e-99) {
tmp = 0.5 * (im * (1.0 / sqrt(re)));
} else if (re <= 7e+67) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= (-1050.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.55d-149) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 1.65d-99) then
tmp = 0.5d0 * (im * (1.0d0 / sqrt(re)))
else if (re <= 7d+67) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= -1050.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.55e-149) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 1.65e-99) {
tmp = 0.5 * (im * (1.0 / Math.sqrt(re)));
} else if (re <= 7e+67) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1050.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.55e-149: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 1.65e-99: tmp = 0.5 * (im * (1.0 / math.sqrt(re))) elif re <= 7e+67: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1050.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.55e-149) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 1.65e-99) tmp = Float64(0.5 * Float64(im * Float64(1.0 / sqrt(re)))); elseif (re <= 7e+67) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); 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 <= -1050.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.55e-149) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 1.65e-99) tmp = 0.5 * (im * (1.0 / sqrt(re))); elseif (re <= 7e+67) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1050.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.55e-149], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.65e-99], N[(0.5 * N[(im * N[(1.0 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7e+67], N[(0.5 * N[Sqrt[N[(im * 2.0), $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 -1050:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.55 \cdot 10^{-149}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 1.65 \cdot 10^{-99}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \frac{1}{\sqrt{re}}\right)\\
\mathbf{elif}\;re \leq 7 \cdot 10^{+67}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -1050Initial program 37.2%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -1050 < re < 2.54999999999999991e-149Initial program 60.1%
Taylor expanded in re around 0 82.8%
if 2.54999999999999991e-149 < re < 1.64999999999999993e-99Initial program 33.5%
Taylor expanded in re around inf 71.0%
*-commutative71.0%
associate-*l*71.4%
Simplified71.4%
add-cube-cbrt70.9%
pow371.1%
sqrt-div71.4%
metadata-eval71.4%
un-div-inv71.4%
associate-*r*71.2%
sqrt-unprod71.1%
metadata-eval71.1%
metadata-eval71.1%
*-un-lft-identity71.1%
Applied egg-rr71.1%
rem-cube-cbrt72.1%
frac-2neg72.1%
div-inv72.2%
Applied egg-rr72.2%
if 1.64999999999999993e-99 < re < 7e67Initial program 27.8%
Taylor expanded in re around 0 70.4%
*-commutative70.4%
Simplified70.4%
if 7e67 < re Initial program 7.8%
Taylor expanded in re around inf 90.4%
*-commutative90.4%
associate-*l*91.0%
Simplified91.0%
add-cube-cbrt90.3%
pow390.4%
sqrt-div90.3%
metadata-eval90.3%
un-div-inv90.3%
associate-*r*90.5%
sqrt-unprod90.0%
metadata-eval90.0%
metadata-eval90.0%
*-un-lft-identity90.0%
Applied egg-rr90.0%
rem-cube-cbrt91.5%
clear-num88.9%
associate-/r/91.3%
pow1/291.3%
pow-flip91.6%
metadata-eval91.6%
Applied egg-rr91.6%
Final simplification81.8%
(FPCore (re im)
:precision binary64
(if (<= re -27.5)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.5e+71)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -27.5) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.5e+71) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= (-27.5d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.5d+71) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= -27.5) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.5e+71) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -27.5: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.5e+71: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -27.5) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.5e+71) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); 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 <= -27.5) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.5e+71) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -27.5], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.5e+71], N[(0.5 * N[Sqrt[N[(im * 2.0), $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 -27.5:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.5 \cdot 10^{+71}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -27.5Initial program 37.2%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -27.5 < re < 2.49999999999999986e71Initial program 49.2%
Taylor expanded in re around 0 74.6%
*-commutative74.6%
Simplified74.6%
if 2.49999999999999986e71 < re Initial program 7.8%
Taylor expanded in re around inf 90.4%
*-commutative90.4%
associate-*l*91.0%
Simplified91.0%
add-cube-cbrt90.3%
pow390.4%
sqrt-div90.3%
metadata-eval90.3%
un-div-inv90.3%
associate-*r*90.5%
sqrt-unprod90.0%
metadata-eval90.0%
metadata-eval90.0%
*-un-lft-identity90.0%
Applied egg-rr90.0%
rem-cube-cbrt91.5%
clear-num88.9%
associate-/r/91.3%
pow1/291.3%
pow-flip91.6%
metadata-eval91.6%
Applied egg-rr91.6%
Final simplification79.6%
(FPCore (re im) :precision binary64 (if (<= re -640.0) (* 0.5 (sqrt (* re -4.0))) (if (<= re 4.6e+76) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -640.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.6e+76) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= (-640.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.6d+76) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= -640.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.6e+76) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -640.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.6e+76: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -640.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.6e+76) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -640.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.6e+76) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -640.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.6e+76], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -640:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.6 \cdot 10^{+76}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -640Initial program 37.2%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -640 < re < 4.60000000000000002e76Initial program 49.2%
Taylor expanded in re around 0 74.6%
*-commutative74.6%
Simplified74.6%
if 4.60000000000000002e76 < re Initial program 7.8%
Taylor expanded in re around inf 90.4%
*-commutative90.4%
associate-*l*91.0%
Simplified91.0%
sqrt-div91.0%
metadata-eval91.0%
un-div-inv91.0%
associate-*r*90.5%
sqrt-unprod91.5%
metadata-eval91.5%
metadata-eval91.5%
*-un-lft-identity91.5%
Applied egg-rr91.5%
Final simplification79.5%
(FPCore (re im) :precision binary64 (if (<= re -0.0185) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (re <= -0.0185) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((im * 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.0185d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((im * 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.0185) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.0185: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.0185) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.0185) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0185], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0185:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -0.0184999999999999991Initial program 37.2%
Taylor expanded in re around -inf 81.9%
*-commutative81.9%
Simplified81.9%
if -0.0184999999999999991 < re Initial program 39.0%
Taylor expanded in re around 0 59.7%
*-commutative59.7%
Simplified59.7%
Final simplification65.0%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
double code(double re, double im) {
return 0.5 * sqrt((im * 2.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((im * 2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((im * 2.0));
}
def code(re, im): return 0.5 * math.sqrt((im * 2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(im * 2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((im * 2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Initial program 38.6%
Taylor expanded in re around 0 51.2%
*-commutative51.2%
Simplified51.2%
Final simplification51.2%
herbie shell --seed 2024075
(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)))))