
(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) (/ (* im 0.5) (sqrt re)) (* 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 = (im * 0.5) / sqrt(re);
} 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 = (im * 0.5) / Math.sqrt(re);
} 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 = (im * 0.5) / math.sqrt(re) 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(Float64(im * 0.5) / sqrt(re)); 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 = (im * 0.5) / sqrt(re); 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[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $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{im \cdot 0.5}{\sqrt{re}}\\
\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 4.1%
Taylor expanded in im around 0 90.9%
*-commutative90.9%
Simplified90.9%
associate-*r*90.9%
sqrt-div90.9%
metadata-eval90.9%
un-div-inv90.9%
sqrt-unprod92.3%
metadata-eval92.3%
metadata-eval92.3%
*-rgt-identity92.3%
*-commutative92.3%
Applied egg-rr92.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 47.1%
sub-neg47.1%
sqr-neg47.1%
sub-neg47.1%
sqr-neg47.1%
hypot-def93.3%
Simplified93.3%
Final simplification93.2%
(FPCore (re im)
:precision binary64
(if (<= re -0.44)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 5e-39)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -0.44) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 5e-39) {
tmp = 0.5 * sqrt((2.0 * (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 <= (-0.44d0)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 5d-39) then
tmp = 0.5d0 * sqrt((2.0d0 * (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 <= -0.44) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 5e-39) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.44: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 5e-39: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.44) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 5e-39) tmp = Float64(0.5 * sqrt(Float64(2.0 * 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 <= -0.44) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 5e-39) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.44], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5e-39], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.44:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 5 \cdot 10^{-39}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.440000000000000002Initial program 32.2%
Taylor expanded in re around -inf 79.0%
*-commutative79.0%
Simplified79.0%
if -0.440000000000000002 < re < 4.9999999999999998e-39Initial program 56.0%
Taylor expanded in re around 0 80.0%
if 4.9999999999999998e-39 < re Initial program 16.7%
Taylor expanded in im around 0 69.7%
*-commutative69.7%
Simplified69.7%
associate-*r*69.7%
sqrt-div69.6%
metadata-eval69.6%
un-div-inv69.6%
sqrt-unprod70.5%
metadata-eval70.5%
metadata-eval70.5%
*-rgt-identity70.5%
*-commutative70.5%
Applied egg-rr70.5%
Final simplification77.6%
(FPCore (re im)
:precision binary64
(if (<= re -0.078)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re 1750000000.0)
(* 0.5 (sqrt (* im 2.0)))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -0.078) {
tmp = 0.5 * sqrt((2.0 * (re * -2.0)));
} else if (re <= 1750000000.0) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= (-0.078d0)) then
tmp = 0.5d0 * sqrt((2.0d0 * (re * (-2.0d0))))
else if (re <= 1750000000.0d0) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= -0.078) {
tmp = 0.5 * Math.sqrt((2.0 * (re * -2.0)));
} else if (re <= 1750000000.0) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.078: tmp = 0.5 * math.sqrt((2.0 * (re * -2.0))) elif re <= 1750000000.0: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.078) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(re * -2.0)))); elseif (re <= 1750000000.0) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.078) tmp = 0.5 * sqrt((2.0 * (re * -2.0))); elseif (re <= 1750000000.0) tmp = 0.5 * sqrt((im * 2.0)); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.078], N[(0.5 * N[Sqrt[N[(2.0 * N[(re * -2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1750000000.0], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.078:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq 1750000000:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.0779999999999999999Initial program 32.2%
Taylor expanded in re around -inf 79.0%
*-commutative79.0%
Simplified79.0%
if -0.0779999999999999999 < re < 1.75e9Initial program 53.7%
Taylor expanded in re around 0 75.8%
expm1-log1p-u71.9%
expm1-udef57.9%
sqrt-unprod57.9%
Applied egg-rr57.9%
expm1-def72.0%
expm1-log1p76.2%
Simplified76.2%
if 1.75e9 < re Initial program 11.8%
Taylor expanded in im around 0 75.2%
*-commutative75.2%
Simplified75.2%
associate-*r*75.2%
sqrt-div75.1%
metadata-eval75.1%
un-div-inv75.1%
sqrt-unprod76.1%
metadata-eval76.1%
metadata-eval76.1%
*-rgt-identity76.1%
*-commutative76.1%
Applied egg-rr76.1%
Final simplification76.9%
(FPCore (re im) :precision binary64 (if (<= re 17000000000.0) (* 0.5 (sqrt (* im 2.0))) (* im (/ 0.5 (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= 17000000000.0) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= 17000000000.0d0) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= 17000000000.0) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 17000000000.0: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 17000000000.0) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 17000000000.0) tmp = 0.5 * sqrt((im * 2.0)); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 17000000000.0], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 17000000000:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 1.7e10Initial program 47.1%
Taylor expanded in re around 0 60.2%
expm1-log1p-u57.0%
expm1-udef47.0%
sqrt-unprod47.0%
Applied egg-rr47.0%
expm1-def57.1%
expm1-log1p60.6%
Simplified60.6%
if 1.7e10 < re Initial program 11.8%
Taylor expanded in im around 0 75.2%
*-commutative75.2%
Simplified75.2%
expm1-log1p-u74.7%
expm1-udef26.5%
associate-*r*26.5%
sqrt-div26.5%
metadata-eval26.5%
un-div-inv26.5%
sqrt-unprod26.5%
metadata-eval26.5%
metadata-eval26.5%
*-rgt-identity26.5%
*-commutative26.5%
Applied egg-rr26.5%
expm1-def75.5%
expm1-log1p76.1%
*-commutative76.1%
associate-/l*76.0%
Simplified76.0%
associate-/r/76.0%
Applied egg-rr76.0%
Final simplification63.2%
(FPCore (re im) :precision binary64 (if (<= re 320000000.0) (* 0.5 (sqrt (* im 2.0))) (/ 0.5 (/ (sqrt re) im))))
double code(double re, double im) {
double tmp;
if (re <= 320000000.0) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= 320000000.0d0) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= 320000000.0) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 / (Math.sqrt(re) / im);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 320000000.0: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 / (math.sqrt(re) / im) return tmp
function code(re, im) tmp = 0.0 if (re <= 320000000.0) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 / Float64(sqrt(re) / im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 320000000.0) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 / (sqrt(re) / im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 320000000.0], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 320000000:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\frac{\sqrt{re}}{im}}\\
\end{array}
\end{array}
if re < 3.2e8Initial program 47.1%
Taylor expanded in re around 0 60.2%
expm1-log1p-u57.0%
expm1-udef47.0%
sqrt-unprod47.0%
Applied egg-rr47.0%
expm1-def57.1%
expm1-log1p60.6%
Simplified60.6%
if 3.2e8 < re Initial program 11.8%
Taylor expanded in im around 0 75.2%
*-commutative75.2%
Simplified75.2%
expm1-log1p-u74.7%
expm1-udef26.5%
associate-*r*26.5%
sqrt-div26.5%
metadata-eval26.5%
un-div-inv26.5%
sqrt-unprod26.5%
metadata-eval26.5%
metadata-eval26.5%
*-rgt-identity26.5%
*-commutative26.5%
Applied egg-rr26.5%
expm1-def75.5%
expm1-log1p76.1%
*-commutative76.1%
associate-/l*76.0%
Simplified76.0%
Final simplification63.2%
(FPCore (re im) :precision binary64 (if (<= re 430000000000.0) (* 0.5 (sqrt (* im 2.0))) (/ (* im 0.5) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= 430000000000.0) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= 430000000000.0d0) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= 430000000000.0) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 430000000000.0: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 430000000000.0) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 430000000000.0) tmp = 0.5 * sqrt((im * 2.0)); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 430000000000.0], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 430000000000:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 4.3e11Initial program 47.1%
Taylor expanded in re around 0 60.2%
expm1-log1p-u57.0%
expm1-udef47.0%
sqrt-unprod47.0%
Applied egg-rr47.0%
expm1-def57.1%
expm1-log1p60.6%
Simplified60.6%
if 4.3e11 < re Initial program 11.8%
Taylor expanded in im around 0 75.2%
*-commutative75.2%
Simplified75.2%
associate-*r*75.2%
sqrt-div75.1%
metadata-eval75.1%
un-div-inv75.1%
sqrt-unprod76.1%
metadata-eval76.1%
metadata-eval76.1%
*-rgt-identity76.1%
*-commutative76.1%
Applied egg-rr76.1%
Final simplification63.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 41.0%
Taylor expanded in re around 0 54.7%
expm1-log1p-u51.8%
expm1-udef45.1%
sqrt-unprod45.1%
Applied egg-rr45.1%
expm1-def51.9%
expm1-log1p55.0%
Simplified55.0%
Final simplification55.0%
herbie shell --seed 2023330
(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)))))