
(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 6 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 (/ (sqrt re) im)) (* 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 / (sqrt(re) / im);
} 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 / (Math.sqrt(re) / im);
} 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 / (math.sqrt(re) / im) 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(sqrt(re) / im)); 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 / (sqrt(re) / im); 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[(N[Sqrt[re], $MachinePrecision] / im), $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:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\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.1%
Taylor expanded in im around 0 94.2%
associate-*l*94.4%
*-commutative94.4%
associate-*l*94.4%
Simplified94.4%
add-log-exp9.5%
*-un-lft-identity9.5%
log-prod9.5%
metadata-eval9.5%
add-log-exp94.4%
associate-*r*94.4%
*-commutative94.4%
associate-*l*94.2%
associate-*r*94.2%
sqrt-div94.2%
metadata-eval94.2%
un-div-inv94.3%
Applied egg-rr95.1%
+-lft-identity95.1%
associate-/l*95.3%
Simplified95.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 52.0%
hypot-def89.1%
Simplified89.1%
Final simplification90.1%
(FPCore (re im)
:precision binary64
(if (<= re -2.7e-16)
(* 0.5 (sqrt (* re -4.0)))
(if (or (<= re 2.8e-59) (and (not (<= re 4.1e+98)) (<= re 2.3e+129)))
(* 0.5 (sqrt (* im 2.0)))
(* im (sqrt (/ 0.25 re))))))
double code(double re, double im) {
double tmp;
if (re <= -2.7e-16) {
tmp = 0.5 * sqrt((re * -4.0));
} else if ((re <= 2.8e-59) || (!(re <= 4.1e+98) && (re <= 2.3e+129))) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = im * sqrt((0.25 / 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.7d-16)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if ((re <= 2.8d-59) .or. (.not. (re <= 4.1d+98)) .and. (re <= 2.3d+129)) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = im * sqrt((0.25d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.7e-16) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if ((re <= 2.8e-59) || (!(re <= 4.1e+98) && (re <= 2.3e+129))) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = im * Math.sqrt((0.25 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.7e-16: tmp = 0.5 * math.sqrt((re * -4.0)) elif (re <= 2.8e-59) or (not (re <= 4.1e+98) and (re <= 2.3e+129)): tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = im * math.sqrt((0.25 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.7e-16) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif ((re <= 2.8e-59) || (!(re <= 4.1e+98) && (re <= 2.3e+129))) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(im * sqrt(Float64(0.25 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.7e-16) tmp = 0.5 * sqrt((re * -4.0)); elseif ((re <= 2.8e-59) || (~((re <= 4.1e+98)) && (re <= 2.3e+129))) tmp = 0.5 * sqrt((im * 2.0)); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.7e-16], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 2.8e-59], And[N[Not[LessEqual[re, 4.1e+98]], $MachinePrecision], LessEqual[re, 2.3e+129]]], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.7 \cdot 10^{-16}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.8 \cdot 10^{-59} \lor \neg \left(re \leq 4.1 \cdot 10^{+98}\right) \land re \leq 2.3 \cdot 10^{+129}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -2.69999999999999999e-16Initial program 49.9%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 83.9%
*-commutative83.9%
Simplified83.9%
if -2.69999999999999999e-16 < re < 2.79999999999999981e-59 or 4.1e98 < re < 2.2999999999999999e129Initial program 61.6%
hypot-def93.4%
Simplified93.4%
Taylor expanded in re around 0 86.9%
*-commutative86.9%
Simplified86.9%
if 2.79999999999999981e-59 < re < 4.1e98 or 2.2999999999999999e129 < re Initial program 15.4%
Taylor expanded in im around 0 73.6%
associate-*l*73.6%
*-commutative73.6%
associate-*l*73.7%
Simplified73.7%
add-log-exp7.1%
*-un-lft-identity7.1%
log-prod7.1%
metadata-eval7.1%
add-log-exp73.7%
associate-*r*73.6%
*-commutative73.6%
associate-*l*73.6%
associate-*r*73.6%
sqrt-div73.5%
metadata-eval73.5%
un-div-inv73.4%
Applied egg-rr74.2%
+-lft-identity74.2%
associate-*l/74.2%
Simplified74.2%
add-sqr-sqrt73.9%
sqrt-unprod74.2%
frac-times74.1%
metadata-eval74.1%
add-sqr-sqrt74.3%
Applied egg-rr74.3%
Final simplification82.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* im 2.0)))))
(if (<= re -1.08e-16)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.8e-59)
t_0
(if (<= re 4e+98)
(/ 0.5 (/ (sqrt re) im))
(if (<= re 2.3e+129) t_0 (* im (sqrt (/ 0.25 re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((im * 2.0));
double tmp;
if (re <= -1.08e-16) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.8e-59) {
tmp = t_0;
} else if (re <= 4e+98) {
tmp = 0.5 / (sqrt(re) / im);
} else if (re <= 2.3e+129) {
tmp = t_0;
} else {
tmp = im * sqrt((0.25 / re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt((im * 2.0d0))
if (re <= (-1.08d-16)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.8d-59) then
tmp = t_0
else if (re <= 4d+98) then
tmp = 0.5d0 / (sqrt(re) / im)
else if (re <= 2.3d+129) then
tmp = t_0
else
tmp = im * sqrt((0.25d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((im * 2.0));
double tmp;
if (re <= -1.08e-16) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.8e-59) {
tmp = t_0;
} else if (re <= 4e+98) {
tmp = 0.5 / (Math.sqrt(re) / im);
} else if (re <= 2.3e+129) {
tmp = t_0;
} else {
tmp = im * Math.sqrt((0.25 / re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((im * 2.0)) tmp = 0 if re <= -1.08e-16: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.8e-59: tmp = t_0 elif re <= 4e+98: tmp = 0.5 / (math.sqrt(re) / im) elif re <= 2.3e+129: tmp = t_0 else: tmp = im * math.sqrt((0.25 / re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(im * 2.0))) tmp = 0.0 if (re <= -1.08e-16) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.8e-59) tmp = t_0; elseif (re <= 4e+98) tmp = Float64(0.5 / Float64(sqrt(re) / im)); elseif (re <= 2.3e+129) tmp = t_0; else tmp = Float64(im * sqrt(Float64(0.25 / re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((im * 2.0)); tmp = 0.0; if (re <= -1.08e-16) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.8e-59) tmp = t_0; elseif (re <= 4e+98) tmp = 0.5 / (sqrt(re) / im); elseif (re <= 2.3e+129) tmp = t_0; else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.08e-16], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.8e-59], t$95$0, If[LessEqual[re, 4e+98], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.3e+129], t$95$0, N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{if}\;re \leq -1.08 \cdot 10^{-16}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.8 \cdot 10^{-59}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 4 \cdot 10^{+98}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\mathbf{elif}\;re \leq 2.3 \cdot 10^{+129}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -1.08e-16Initial program 49.9%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 83.9%
*-commutative83.9%
Simplified83.9%
if -1.08e-16 < re < 2.79999999999999981e-59 or 3.99999999999999999e98 < re < 2.2999999999999999e129Initial program 61.6%
hypot-def93.4%
Simplified93.4%
Taylor expanded in re around 0 86.9%
*-commutative86.9%
Simplified86.9%
if 2.79999999999999981e-59 < re < 3.99999999999999999e98Initial program 24.8%
Taylor expanded in im around 0 62.7%
associate-*l*62.8%
*-commutative62.8%
associate-*l*62.8%
Simplified62.8%
add-log-exp8.7%
*-un-lft-identity8.7%
log-prod8.7%
metadata-eval8.7%
add-log-exp62.8%
associate-*r*62.8%
*-commutative62.8%
associate-*l*62.7%
associate-*r*62.7%
sqrt-div62.6%
metadata-eval62.6%
un-div-inv62.6%
Applied egg-rr63.2%
+-lft-identity63.2%
associate-/l*63.4%
Simplified63.4%
if 2.2999999999999999e129 < re Initial program 3.5%
Taylor expanded in im around 0 87.3%
associate-*l*87.3%
*-commutative87.3%
associate-*l*87.5%
Simplified87.5%
add-log-exp5.0%
*-un-lft-identity5.0%
log-prod5.0%
metadata-eval5.0%
add-log-exp87.5%
associate-*r*87.3%
*-commutative87.3%
associate-*l*87.3%
associate-*r*87.3%
sqrt-div87.2%
metadata-eval87.2%
un-div-inv87.1%
Applied egg-rr88.0%
+-lft-identity88.0%
associate-*l/88.1%
Simplified88.1%
add-sqr-sqrt87.6%
sqrt-unprod88.1%
frac-times87.9%
metadata-eval87.9%
add-sqr-sqrt88.3%
Applied egg-rr88.3%
Final simplification82.4%
(FPCore (re im)
:precision binary64
(if (<= re -4.6e-18)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.22e-61)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 1.4e+97)
(/ 0.5 (/ (sqrt re) im))
(if (<= re 2.3e+129)
(* 0.5 (sqrt (* im 2.0)))
(* im (sqrt (/ 0.25 re))))))))
double code(double re, double im) {
double tmp;
if (re <= -4.6e-18) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.22e-61) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 1.4e+97) {
tmp = 0.5 / (sqrt(re) / im);
} else if (re <= 2.3e+129) {
tmp = 0.5 * sqrt((im * 2.0));
} else {
tmp = im * sqrt((0.25 / re));
}
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-18)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.22d-61) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 1.4d+97) then
tmp = 0.5d0 / (sqrt(re) / im)
else if (re <= 2.3d+129) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = im * sqrt((0.25d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.6e-18) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.22e-61) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 1.4e+97) {
tmp = 0.5 / (Math.sqrt(re) / im);
} else if (re <= 2.3e+129) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = im * Math.sqrt((0.25 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.6e-18: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.22e-61: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 1.4e+97: tmp = 0.5 / (math.sqrt(re) / im) elif re <= 2.3e+129: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = im * math.sqrt((0.25 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.6e-18) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.22e-61) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 1.4e+97) tmp = Float64(0.5 / Float64(sqrt(re) / im)); elseif (re <= 2.3e+129) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(im * sqrt(Float64(0.25 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.6e-18) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.22e-61) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 1.4e+97) tmp = 0.5 / (sqrt(re) / im); elseif (re <= 2.3e+129) tmp = 0.5 * sqrt((im * 2.0)); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.6e-18], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.22e-61], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.4e+97], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.3e+129], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.6 \cdot 10^{-18}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.22 \cdot 10^{-61}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 1.4 \cdot 10^{+97}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\mathbf{elif}\;re \leq 2.3 \cdot 10^{+129}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -4.6000000000000002e-18Initial program 49.9%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 83.9%
*-commutative83.9%
Simplified83.9%
if -4.6000000000000002e-18 < re < 1.22e-61Initial program 66.7%
Taylor expanded in re around 0 89.2%
if 1.22e-61 < re < 1.4e97Initial program 23.9%
Taylor expanded in im around 0 62.2%
associate-*l*62.3%
*-commutative62.3%
associate-*l*62.3%
Simplified62.3%
add-log-exp8.5%
*-un-lft-identity8.5%
log-prod8.5%
metadata-eval8.5%
add-log-exp62.3%
associate-*r*62.3%
*-commutative62.3%
associate-*l*62.2%
associate-*r*62.2%
sqrt-div62.1%
metadata-eval62.1%
un-div-inv62.1%
Applied egg-rr62.8%
+-lft-identity62.8%
associate-/l*62.9%
Simplified62.9%
if 1.4e97 < re < 2.2999999999999999e129Initial program 14.8%
hypot-def78.6%
Simplified78.6%
Taylor expanded in re around 0 79.4%
*-commutative79.4%
Simplified79.4%
if 2.2999999999999999e129 < re Initial program 3.5%
Taylor expanded in im around 0 87.3%
associate-*l*87.3%
*-commutative87.3%
associate-*l*87.5%
Simplified87.5%
add-log-exp5.0%
*-un-lft-identity5.0%
log-prod5.0%
metadata-eval5.0%
add-log-exp87.5%
associate-*r*87.3%
*-commutative87.3%
associate-*l*87.3%
associate-*r*87.3%
sqrt-div87.2%
metadata-eval87.2%
un-div-inv87.1%
Applied egg-rr88.0%
+-lft-identity88.0%
associate-*l/88.1%
Simplified88.1%
add-sqr-sqrt87.6%
sqrt-unprod88.1%
frac-times87.9%
metadata-eval87.9%
add-sqr-sqrt88.3%
Applied egg-rr88.3%
Final simplification82.8%
(FPCore (re im) :precision binary64 (if (<= re -7.8e-17) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (re <= -7.8e-17) {
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 <= (-7.8d-17)) 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 <= -7.8e-17) {
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 <= -7.8e-17: 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 <= -7.8e-17) 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 <= -7.8e-17) 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, -7.8e-17], 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 -7.8 \cdot 10^{-17}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -7.79999999999999979e-17Initial program 49.9%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 83.9%
*-commutative83.9%
Simplified83.9%
if -7.79999999999999979e-17 < re Initial program 43.2%
hypot-def69.2%
Simplified69.2%
Taylor expanded in re around 0 64.4%
*-commutative64.4%
Simplified64.4%
Final simplification69.2%
(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 44.8%
hypot-def76.8%
Simplified76.8%
Taylor expanded in re around 0 54.0%
*-commutative54.0%
Simplified54.0%
Final simplification54.0%
herbie shell --seed 2023188
(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)))))