
(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
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
(if (<= re 2.2e-66)
t_0
(if (<= re 6.5e-53)
(* 0.5 (* im (sqrt (/ 1.0 re))))
(if (<= re 750000000000.0)
t_0
(* 0.5 (* (sqrt 2.0) (* im (sqrt (/ 0.5 re))))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
double tmp;
if (re <= 2.2e-66) {
tmp = t_0;
} else if (re <= 6.5e-53) {
tmp = 0.5 * (im * sqrt((1.0 / re)));
} else if (re <= 750000000000.0) {
tmp = t_0;
} else {
tmp = 0.5 * (sqrt(2.0) * (im * sqrt((0.5 / re))));
}
return tmp;
}
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
double tmp;
if (re <= 2.2e-66) {
tmp = t_0;
} else if (re <= 6.5e-53) {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
} else if (re <= 750000000000.0) {
tmp = t_0;
} else {
tmp = 0.5 * (Math.sqrt(2.0) * (im * Math.sqrt((0.5 / re))));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) tmp = 0 if re <= 2.2e-66: tmp = t_0 elif re <= 6.5e-53: tmp = 0.5 * (im * math.sqrt((1.0 / re))) elif re <= 750000000000.0: tmp = t_0 else: tmp = 0.5 * (math.sqrt(2.0) * (im * math.sqrt((0.5 / re)))) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))) tmp = 0.0 if (re <= 2.2e-66) tmp = t_0; elseif (re <= 6.5e-53) tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); elseif (re <= 750000000000.0) tmp = t_0; else tmp = Float64(0.5 * Float64(sqrt(2.0) * Float64(im * sqrt(Float64(0.5 / re))))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); tmp = 0.0; if (re <= 2.2e-66) tmp = t_0; elseif (re <= 6.5e-53) tmp = 0.5 * (im * sqrt((1.0 / re))); elseif (re <= 750000000000.0) tmp = t_0; else tmp = 0.5 * (sqrt(2.0) * (im * sqrt((0.5 / re)))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, 2.2e-66], t$95$0, If[LessEqual[re, 6.5e-53], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 750000000000.0], t$95$0, N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[(im * N[Sqrt[N[(0.5 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{if}\;re \leq 2.2 \cdot 10^{-66}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{-53}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\mathbf{elif}\;re \leq 750000000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \left(im \cdot \sqrt{\frac{0.5}{re}}\right)\right)\\
\end{array}
\end{array}
if re < 2.2000000000000001e-66 or 6.4999999999999997e-53 < re < 7.5e11Initial program 47.3%
hypot-def92.6%
Simplified92.6%
if 2.2000000000000001e-66 < re < 6.4999999999999997e-53Initial program 4.8%
hypot-udef4.8%
expm1-log1p-u4.8%
Applied egg-rr4.8%
pow1/24.8%
pow-to-exp4.8%
expm1-log1p-u4.8%
*-commutative4.8%
Applied egg-rr4.8%
Taylor expanded in im around 0 100.0%
if 7.5e11 < re Initial program 8.8%
Taylor expanded in im around 0 76.3%
associate-*l*76.4%
*-commutative76.4%
associate-*l*76.3%
Simplified76.3%
expm1-log1p-u76.3%
expm1-udef12.6%
sqrt-unprod12.6%
un-div-inv12.6%
Applied egg-rr12.6%
expm1-def76.9%
expm1-log1p76.9%
Simplified76.9%
Final simplification88.3%
(FPCore (re im) :precision binary64 (if (<= (- (sqrt (+ (* re re) (* im im))) re) 0.0) (* 0.5 (* im (sqrt (/ 1.0 re)))) (* 0.5 (pow (* 2.0 (- (hypot re im) re)) 0.5))))
double code(double re, double im) {
double tmp;
if ((sqrt(((re * re) + (im * im))) - re) <= 0.0) {
tmp = 0.5 * (im * sqrt((1.0 / re)));
} else {
tmp = 0.5 * pow((2.0 * (hypot(re, im) - re)), 0.5);
}
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.sqrt((1.0 / re)));
} else {
tmp = 0.5 * Math.pow((2.0 * (Math.hypot(re, im) - re)), 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.sqrt(((re * re) + (im * im))) - re) <= 0.0: tmp = 0.5 * (im * math.sqrt((1.0 / re))) else: tmp = 0.5 * math.pow((2.0 * (math.hypot(re, im) - re)), 0.5) 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 * sqrt(Float64(1.0 / re)))); else tmp = Float64(0.5 * (Float64(2.0 * Float64(hypot(re, im) - re)) ^ 0.5)); 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 * sqrt((1.0 / re))); else tmp = 0.5 * ((2.0 * (hypot(re, im) - re)) ^ 0.5); 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[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision], 0.5], $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 \sqrt{\frac{1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {\left(2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)\right)}^{0.5}\\
\end{array}
\end{array}
if (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 4.4%
hypot-udef10.1%
expm1-log1p-u10.1%
Applied egg-rr10.1%
pow1/210.1%
pow-to-exp9.7%
expm1-log1p-u9.7%
*-commutative9.7%
Applied egg-rr9.7%
Taylor expanded in im around 0 94.8%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 40.9%
pow1/240.9%
hypot-udef85.9%
Applied egg-rr85.9%
Final simplification87.2%
(FPCore (re im)
:precision binary64
(if (<= re 2.45e-64)
(* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))
(if (or (<= re 4.6e-53) (not (<= re 1.05e+32)))
(* 0.5 (* im (sqrt (/ 1.0 re))))
(* 0.5 (sqrt (* im 2.0))))))
double code(double re, double im) {
double tmp;
if (re <= 2.45e-64) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else if ((re <= 4.6e-53) || !(re <= 1.05e+32)) {
tmp = 0.5 * (im * sqrt((1.0 / re)));
} else {
tmp = 0.5 * sqrt((im * 2.0));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 2.45e-64) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else if ((re <= 4.6e-53) || !(re <= 1.05e+32)) {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.45e-64: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) elif (re <= 4.6e-53) or not (re <= 1.05e+32): tmp = 0.5 * (im * math.sqrt((1.0 / re))) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.45e-64) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); elseif ((re <= 4.6e-53) || !(re <= 1.05e+32)) tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); 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 <= 2.45e-64) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); elseif ((re <= 4.6e-53) || ~((re <= 1.05e+32))) tmp = 0.5 * (im * sqrt((1.0 / re))); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.45e-64], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 4.6e-53], N[Not[LessEqual[re, 1.05e+32]], $MachinePrecision]], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $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 2.45 \cdot 10^{-64}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{elif}\;re \leq 4.6 \cdot 10^{-53} \lor \neg \left(re \leq 1.05 \cdot 10^{+32}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < 2.4500000000000001e-64Initial program 47.0%
hypot-def93.5%
Simplified93.5%
if 2.4500000000000001e-64 < re < 4.6000000000000003e-53 or 1.05e32 < re Initial program 8.8%
hypot-udef32.9%
expm1-log1p-u31.2%
Applied egg-rr31.2%
pow1/231.2%
pow-to-exp30.9%
expm1-log1p-u31.0%
*-commutative31.0%
Applied egg-rr31.0%
Taylor expanded in im around 0 79.7%
if 4.6000000000000003e-53 < re < 1.05e32Initial program 41.0%
Taylor expanded in re around 0 77.2%
expm1-log1p-u72.5%
expm1-udef69.0%
*-commutative69.0%
sqrt-unprod69.0%
Applied egg-rr69.0%
expm1-def72.6%
expm1-log1p77.7%
Simplified77.7%
Final simplification88.3%
(FPCore (re im)
:precision binary64
(if (<= re -9.6e+70)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 1.86e-65)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (or (<= re 5.8e-53) (not (<= re 1.4e+36)))
(* 0.5 (* im (sqrt (/ 1.0 re))))
(* 0.5 (sqrt (* im 2.0)))))))
double code(double re, double im) {
double tmp;
if (re <= -9.6e+70) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 1.86e-65) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if ((re <= 5.8e-53) || !(re <= 1.4e+36)) {
tmp = 0.5 * (im * sqrt((1.0 / re)));
} 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 <= (-9.6d+70)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 1.86d-65) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if ((re <= 5.8d-53) .or. (.not. (re <= 1.4d+36))) then
tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
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 <= -9.6e+70) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 1.86e-65) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if ((re <= 5.8e-53) || !(re <= 1.4e+36)) {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -9.6e+70: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 1.86e-65: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif (re <= 5.8e-53) or not (re <= 1.4e+36): tmp = 0.5 * (im * math.sqrt((1.0 / re))) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (re <= -9.6e+70) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 1.86e-65) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif ((re <= 5.8e-53) || !(re <= 1.4e+36)) tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); 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 <= -9.6e+70) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 1.86e-65) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif ((re <= 5.8e-53) || ~((re <= 1.4e+36))) tmp = 0.5 * (im * sqrt((1.0 / re))); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -9.6e+70], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.86e-65], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 5.8e-53], N[Not[LessEqual[re, 1.4e+36]], $MachinePrecision]], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $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 -9.6 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 1.86 \cdot 10^{-65}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 5.8 \cdot 10^{-53} \lor \neg \left(re \leq 1.4 \cdot 10^{+36}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -9.59999999999999947e70Initial program 28.2%
Taylor expanded in re around -inf 89.6%
*-commutative89.6%
Simplified89.6%
if -9.59999999999999947e70 < re < 1.86000000000000006e-65Initial program 54.0%
Taylor expanded in re around 0 81.0%
if 1.86000000000000006e-65 < re < 5.7999999999999996e-53 or 1.4e36 < re Initial program 8.8%
hypot-udef32.9%
expm1-log1p-u31.2%
Applied egg-rr31.2%
pow1/231.2%
pow-to-exp30.9%
expm1-log1p-u31.0%
*-commutative31.0%
Applied egg-rr31.0%
Taylor expanded in im around 0 79.7%
if 5.7999999999999996e-53 < re < 1.4e36Initial program 41.0%
Taylor expanded in re around 0 77.2%
expm1-log1p-u72.5%
expm1-udef69.0%
*-commutative69.0%
sqrt-unprod69.0%
Applied egg-rr69.0%
expm1-def72.6%
expm1-log1p77.7%
Simplified77.7%
Final simplification81.8%
(FPCore (re im)
:precision binary64
(if (<= re -2.55e+70)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 280000000000.0)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (sqrt (/ (* im im) re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.55e+70) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 280000000000.0) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * sqrt(((im * 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 <= (-2.55d+70)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 280000000000.0d0) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * sqrt(((im * im) / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.55e+70) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 280000000000.0) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * Math.sqrt(((im * im) / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.55e+70: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 280000000000.0: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * math.sqrt(((im * im) / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.55e+70) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 280000000000.0) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * sqrt(Float64(Float64(im * im) / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.55e+70) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 280000000000.0) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * sqrt(((im * im) / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.55e+70], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 280000000000.0], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.55 \cdot 10^{+70}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 280000000000:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{im \cdot im}{re}}\\
\end{array}
\end{array}
if re < -2.55000000000000007e70Initial program 28.2%
Taylor expanded in re around -inf 89.6%
*-commutative89.6%
Simplified89.6%
if -2.55000000000000007e70 < re < 2.8e11Initial program 51.7%
Taylor expanded in re around 0 78.2%
if 2.8e11 < re Initial program 8.8%
Taylor expanded in im around 0 76.3%
associate-*l*76.4%
*-commutative76.4%
associate-*l*76.3%
Simplified76.3%
expm1-log1p-u75.7%
expm1-udef22.9%
*-commutative22.9%
*-commutative22.9%
associate-*l*22.9%
sqrt-unprod22.9%
un-div-inv22.9%
Applied egg-rr22.9%
expm1-def76.0%
expm1-log1p76.7%
associate-*r*76.9%
*-commutative76.9%
associate-*l*76.7%
Simplified76.7%
add-sqr-sqrt76.5%
sqrt-unprod56.8%
swap-sqr48.4%
sqrt-unprod48.5%
sqrt-unprod48.5%
add-sqr-sqrt48.6%
associate-*l/48.6%
metadata-eval48.6%
Applied egg-rr48.6%
unpow248.6%
associate-*r/48.6%
*-rgt-identity48.6%
unpow248.6%
Simplified48.6%
Final simplification71.9%
(FPCore (re im) :precision binary64 (if (<= re -3.6e+71) (* 0.5 (sqrt (* 2.0 (* re -2.0)))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (re <= -3.6e+71) {
tmp = 0.5 * sqrt((2.0 * (re * -2.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 <= (-3.6d+71)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.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 <= -3.6e+71) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else {
tmp = 0.5 * Math.sqrt((im * 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.6e+71: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) else: tmp = 0.5 * math.sqrt((im * 2.0)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.6e+71) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.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 <= -3.6e+71) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); else tmp = 0.5 * sqrt((im * 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.6e+71], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $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 -3.6 \cdot 10^{+71}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -3.6e71Initial program 28.2%
Taylor expanded in re around -inf 89.6%
*-commutative89.6%
Simplified89.6%
if -3.6e71 < re Initial program 37.1%
Taylor expanded in re around 0 59.0%
expm1-log1p-u55.8%
expm1-udef48.4%
*-commutative48.4%
sqrt-unprod48.4%
Applied egg-rr48.4%
expm1-def55.8%
expm1-log1p59.4%
Simplified59.4%
Final simplification64.6%
(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 35.6%
Taylor expanded in re around 0 51.7%
expm1-log1p-u48.9%
expm1-udef42.6%
*-commutative42.6%
sqrt-unprod42.6%
Applied egg-rr42.6%
expm1-def48.9%
expm1-log1p52.1%
Simplified52.1%
Final simplification52.1%
herbie shell --seed 2023196
(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)))))