
(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 8 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) (* im (sqrt (/ 0.25 re))) (sqrt (* 0.5 (- (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 = im * sqrt((0.25 / re));
} else {
tmp = sqrt((0.5 * (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 = im * Math.sqrt((0.25 / re));
} else {
tmp = Math.sqrt((0.5 * (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 = im * math.sqrt((0.25 / re)) else: tmp = math.sqrt((0.5 * (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(im * sqrt(Float64(0.25 / re))); else tmp = sqrt(Float64(0.5 * 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 = im * sqrt((0.25 / re)); else tmp = sqrt((0.5 * (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[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $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:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \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 15.7%
Taylor expanded in im around 0 98.3%
associate-*l*98.4%
*-commutative98.4%
associate-*l*98.7%
Simplified98.7%
associate-*r*98.4%
sqrt-unprod99.7%
metadata-eval99.7%
metadata-eval99.7%
*-un-lft-identity99.7%
sqrt-div99.5%
metadata-eval99.5%
Applied egg-rr99.5%
associate-*r*99.5%
un-div-inv99.5%
Applied egg-rr99.5%
*-commutative99.5%
*-lft-identity99.5%
times-frac99.5%
/-rgt-identity99.5%
Simplified99.5%
expm1-log1p-u98.2%
expm1-udef57.1%
add-sqr-sqrt57.1%
sqrt-unprod57.1%
frac-times57.1%
metadata-eval57.1%
add-sqr-sqrt57.1%
Applied egg-rr57.1%
expm1-def98.3%
expm1-log1p99.7%
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 44.0%
hypot-udef90.0%
add-sqr-sqrt89.3%
sqrt-unprod90.0%
*-commutative90.0%
*-commutative90.0%
swap-sqr90.0%
add-sqr-sqrt90.0%
metadata-eval90.0%
Applied egg-rr90.0%
*-commutative90.0%
associate-*r*90.4%
metadata-eval90.4%
Simplified90.4%
Final simplification91.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (+ (* re -2.0) (+ (* 2.0 im) (* re (/ re im))))))))
(if (<= re -1.05e-72)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.7e-9)
t_0
(if (<= re 3.05e+23)
(* im (sqrt (/ 0.25 re)))
(if (<= re 3.6e+69) t_0 (* im (/ 0.5 (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt(((re * -2.0) + ((2.0 * im) + (re * (re / im)))));
double tmp;
if (re <= -1.05e-72) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.7e-9) {
tmp = t_0;
} else if (re <= 3.05e+23) {
tmp = im * sqrt((0.25 / re));
} else if (re <= 3.6e+69) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * sqrt(((re * (-2.0d0)) + ((2.0d0 * im) + (re * (re / im)))))
if (re <= (-1.05d-72)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.7d-9) then
tmp = t_0
else if (re <= 3.05d+23) then
tmp = im * sqrt((0.25d0 / re))
else if (re <= 3.6d+69) then
tmp = t_0
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt(((re * -2.0) + ((2.0 * im) + (re * (re / im)))));
double tmp;
if (re <= -1.05e-72) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.7e-9) {
tmp = t_0;
} else if (re <= 3.05e+23) {
tmp = im * Math.sqrt((0.25 / re));
} else if (re <= 3.6e+69) {
tmp = t_0;
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt(((re * -2.0) + ((2.0 * im) + (re * (re / im))))) tmp = 0 if re <= -1.05e-72: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.7e-9: tmp = t_0 elif re <= 3.05e+23: tmp = im * math.sqrt((0.25 / re)) elif re <= 3.6e+69: tmp = t_0 else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(Float64(re * -2.0) + Float64(Float64(2.0 * im) + Float64(re * Float64(re / im)))))) tmp = 0.0 if (re <= -1.05e-72) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.7e-9) tmp = t_0; elseif (re <= 3.05e+23) tmp = Float64(im * sqrt(Float64(0.25 / re))); elseif (re <= 3.6e+69) tmp = t_0; else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt(((re * -2.0) + ((2.0 * im) + (re * (re / im))))); tmp = 0.0; if (re <= -1.05e-72) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.7e-9) tmp = t_0; elseif (re <= 3.05e+23) tmp = im * sqrt((0.25 / re)); elseif (re <= 3.6e+69) tmp = t_0; else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(N[(re * -2.0), $MachinePrecision] + N[(N[(2.0 * im), $MachinePrecision] + N[(re * N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.05e-72], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.7e-9], t$95$0, If[LessEqual[re, 3.05e+23], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.6e+69], t$95$0, N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -2 + \left(2 \cdot im + re \cdot \frac{re}{im}\right)}\\
\mathbf{if}\;re \leq -1.05 \cdot 10^{-72}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.7 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 3.05 \cdot 10^{+23}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\mathbf{elif}\;re \leq 3.6 \cdot 10^{+69}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.05e-72Initial program 47.6%
sqr-neg47.6%
sqr-neg47.6%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 74.9%
*-commutative74.9%
Simplified74.9%
if -1.05e-72 < re < 1.6999999999999999e-9 or 3.0499999999999999e23 < re < 3.6000000000000003e69Initial program 53.1%
sqr-neg53.1%
sqr-neg53.1%
hypot-def91.3%
Simplified91.3%
Taylor expanded in re around 0 82.5%
unpow282.5%
*-un-lft-identity82.5%
times-frac83.0%
/-rgt-identity83.0%
Applied egg-rr83.0%
if 1.6999999999999999e-9 < re < 3.0499999999999999e23Initial program 6.4%
Taylor expanded in im around 0 85.0%
associate-*l*85.4%
*-commutative85.4%
associate-*l*86.0%
Simplified86.0%
associate-*r*85.4%
sqrt-unprod86.4%
metadata-eval86.4%
metadata-eval86.4%
*-un-lft-identity86.4%
sqrt-div86.0%
metadata-eval86.0%
Applied egg-rr86.0%
associate-*r*86.0%
un-div-inv86.0%
Applied egg-rr86.0%
*-commutative86.0%
*-lft-identity86.0%
times-frac86.0%
/-rgt-identity86.0%
Simplified86.0%
expm1-log1p-u86.0%
expm1-udef71.4%
add-sqr-sqrt71.4%
sqrt-unprod71.4%
frac-times71.4%
metadata-eval71.4%
add-sqr-sqrt71.4%
Applied egg-rr71.4%
expm1-def86.2%
expm1-log1p86.4%
Simplified86.4%
if 3.6000000000000003e69 < re Initial program 10.3%
Taylor expanded in im around 0 77.0%
associate-*l*77.0%
*-commutative77.0%
associate-*l*77.2%
Simplified77.2%
associate-*r*77.0%
sqrt-unprod77.8%
metadata-eval77.8%
metadata-eval77.8%
*-un-lft-identity77.8%
sqrt-div77.9%
metadata-eval77.9%
Applied egg-rr77.9%
associate-*r*77.9%
un-div-inv77.9%
Applied egg-rr77.9%
*-commutative77.9%
*-lft-identity77.9%
times-frac77.9%
/-rgt-identity77.9%
Simplified77.9%
Final simplification79.1%
(FPCore (re im)
:precision binary64
(if (<= re -1.7e-57)
(* 0.5 (sqrt (* re -4.0)))
(if (or (<= re 1.7e-9) (and (not (<= re 1.42e+23)) (<= re 3.6e+66)))
(sqrt (* 0.5 (- im re)))
(* im (sqrt (/ 0.25 re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.7e-57) {
tmp = 0.5 * sqrt((re * -4.0));
} else if ((re <= 1.7e-9) || (!(re <= 1.42e+23) && (re <= 3.6e+66))) {
tmp = sqrt((0.5 * (im - re)));
} 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 <= (-1.7d-57)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if ((re <= 1.7d-9) .or. (.not. (re <= 1.42d+23)) .and. (re <= 3.6d+66)) then
tmp = sqrt((0.5d0 * (im - re)))
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 <= -1.7e-57) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if ((re <= 1.7e-9) || (!(re <= 1.42e+23) && (re <= 3.6e+66))) {
tmp = Math.sqrt((0.5 * (im - re)));
} else {
tmp = im * Math.sqrt((0.25 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.7e-57: tmp = 0.5 * math.sqrt((re * -4.0)) elif (re <= 1.7e-9) or (not (re <= 1.42e+23) and (re <= 3.6e+66)): tmp = math.sqrt((0.5 * (im - re))) else: tmp = im * math.sqrt((0.25 / re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.7e-57) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif ((re <= 1.7e-9) || (!(re <= 1.42e+23) && (re <= 3.6e+66))) tmp = sqrt(Float64(0.5 * Float64(im - re))); else tmp = Float64(im * sqrt(Float64(0.25 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.7e-57) tmp = 0.5 * sqrt((re * -4.0)); elseif ((re <= 1.7e-9) || (~((re <= 1.42e+23)) && (re <= 3.6e+66))) tmp = sqrt((0.5 * (im - re))); else tmp = im * sqrt((0.25 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.7e-57], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 1.7e-9], And[N[Not[LessEqual[re, 1.42e+23]], $MachinePrecision], LessEqual[re, 3.6e+66]]], N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.7 \cdot 10^{-57}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.7 \cdot 10^{-9} \lor \neg \left(re \leq 1.42 \cdot 10^{+23}\right) \land re \leq 3.6 \cdot 10^{+66}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\end{array}
\end{array}
if re < -1.70000000000000008e-57Initial program 46.4%
sqr-neg46.4%
sqr-neg46.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.3%
*-commutative75.3%
Simplified75.3%
if -1.70000000000000008e-57 < re < 1.6999999999999999e-9 or 1.42000000000000004e23 < re < 3.6e66Initial program 53.9%
hypot-udef91.5%
add-sqr-sqrt90.7%
sqrt-unprod91.5%
*-commutative91.5%
*-commutative91.5%
swap-sqr91.5%
add-sqr-sqrt91.5%
metadata-eval91.5%
Applied egg-rr91.5%
*-commutative91.5%
associate-*r*91.5%
metadata-eval91.5%
Simplified91.5%
Taylor expanded in re around 0 81.7%
neg-mul-181.7%
unsub-neg81.7%
Simplified81.7%
if 1.6999999999999999e-9 < re < 1.42000000000000004e23 or 3.6e66 < re Initial program 9.8%
Taylor expanded in im around 0 78.0%
associate-*l*78.1%
*-commutative78.1%
associate-*l*78.2%
Simplified78.2%
associate-*r*78.1%
sqrt-unprod78.9%
metadata-eval78.9%
metadata-eval78.9%
*-un-lft-identity78.9%
sqrt-div78.9%
metadata-eval78.9%
Applied egg-rr78.9%
associate-*r*78.9%
un-div-inv78.9%
Applied egg-rr78.9%
*-commutative78.9%
*-lft-identity78.9%
times-frac78.9%
/-rgt-identity78.9%
Simplified78.9%
expm1-log1p-u78.9%
expm1-udef27.1%
add-sqr-sqrt27.1%
sqrt-unprod27.1%
frac-times27.1%
metadata-eval27.1%
add-sqr-sqrt27.1%
Applied egg-rr27.1%
expm1-def78.9%
expm1-log1p78.9%
Simplified78.9%
Final simplification78.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 0.5 (- im re)))))
(if (<= re -7.5e-64)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 5.6e-9)
t_0
(if (<= re 1.36e+25)
(* im (sqrt (/ 0.25 re)))
(if (<= re 2.95e+66) t_0 (* im (/ 0.5 (sqrt re)))))))))
double code(double re, double im) {
double t_0 = sqrt((0.5 * (im - re)));
double tmp;
if (re <= -7.5e-64) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 5.6e-9) {
tmp = t_0;
} else if (re <= 1.36e+25) {
tmp = im * sqrt((0.25 / re));
} else if (re <= 2.95e+66) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = sqrt((0.5d0 * (im - re)))
if (re <= (-7.5d-64)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 5.6d-9) then
tmp = t_0
else if (re <= 1.36d+25) then
tmp = im * sqrt((0.25d0 / re))
else if (re <= 2.95d+66) then
tmp = t_0
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt((0.5 * (im - re)));
double tmp;
if (re <= -7.5e-64) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 5.6e-9) {
tmp = t_0;
} else if (re <= 1.36e+25) {
tmp = im * Math.sqrt((0.25 / re));
} else if (re <= 2.95e+66) {
tmp = t_0;
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt((0.5 * (im - re))) tmp = 0 if re <= -7.5e-64: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 5.6e-9: tmp = t_0 elif re <= 1.36e+25: tmp = im * math.sqrt((0.25 / re)) elif re <= 2.95e+66: tmp = t_0 else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) t_0 = sqrt(Float64(0.5 * Float64(im - re))) tmp = 0.0 if (re <= -7.5e-64) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 5.6e-9) tmp = t_0; elseif (re <= 1.36e+25) tmp = Float64(im * sqrt(Float64(0.25 / re))); elseif (re <= 2.95e+66) tmp = t_0; else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt((0.5 * (im - re))); tmp = 0.0; if (re <= -7.5e-64) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 5.6e-9) tmp = t_0; elseif (re <= 1.36e+25) tmp = im * sqrt((0.25 / re)); elseif (re <= 2.95e+66) tmp = t_0; else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[re, -7.5e-64], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.6e-9], t$95$0, If[LessEqual[re, 1.36e+25], N[(im * N[Sqrt[N[(0.25 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.95e+66], t$95$0, N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{0.5 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -7.5 \cdot 10^{-64}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 5.6 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 1.36 \cdot 10^{+25}:\\
\;\;\;\;im \cdot \sqrt{\frac{0.25}{re}}\\
\mathbf{elif}\;re \leq 2.95 \cdot 10^{+66}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -7.49999999999999949e-64Initial program 46.4%
sqr-neg46.4%
sqr-neg46.4%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 75.3%
*-commutative75.3%
Simplified75.3%
if -7.49999999999999949e-64 < re < 5.59999999999999969e-9 or 1.36e25 < re < 2.94999999999999994e66Initial program 53.9%
hypot-udef91.5%
add-sqr-sqrt90.7%
sqrt-unprod91.5%
*-commutative91.5%
*-commutative91.5%
swap-sqr91.5%
add-sqr-sqrt91.5%
metadata-eval91.5%
Applied egg-rr91.5%
*-commutative91.5%
associate-*r*91.5%
metadata-eval91.5%
Simplified91.5%
Taylor expanded in re around 0 81.7%
neg-mul-181.7%
unsub-neg81.7%
Simplified81.7%
if 5.59999999999999969e-9 < re < 1.36e25Initial program 6.4%
Taylor expanded in im around 0 85.0%
associate-*l*85.4%
*-commutative85.4%
associate-*l*86.0%
Simplified86.0%
associate-*r*85.4%
sqrt-unprod86.4%
metadata-eval86.4%
metadata-eval86.4%
*-un-lft-identity86.4%
sqrt-div86.0%
metadata-eval86.0%
Applied egg-rr86.0%
associate-*r*86.0%
un-div-inv86.0%
Applied egg-rr86.0%
*-commutative86.0%
*-lft-identity86.0%
times-frac86.0%
/-rgt-identity86.0%
Simplified86.0%
expm1-log1p-u86.0%
expm1-udef71.4%
add-sqr-sqrt71.4%
sqrt-unprod71.4%
frac-times71.4%
metadata-eval71.4%
add-sqr-sqrt71.4%
Applied egg-rr71.4%
expm1-def86.2%
expm1-log1p86.4%
Simplified86.4%
if 2.94999999999999994e66 < re Initial program 10.3%
Taylor expanded in im around 0 77.0%
associate-*l*77.0%
*-commutative77.0%
associate-*l*77.2%
Simplified77.2%
associate-*r*77.0%
sqrt-unprod77.8%
metadata-eval77.8%
metadata-eval77.8%
*-un-lft-identity77.8%
sqrt-div77.9%
metadata-eval77.9%
Applied egg-rr77.9%
associate-*r*77.9%
un-div-inv77.9%
Applied egg-rr77.9%
*-commutative77.9%
*-lft-identity77.9%
times-frac77.9%
/-rgt-identity77.9%
Simplified77.9%
Final simplification78.8%
(FPCore (re im) :precision binary64 (if (<= re -1.8e-72) (* 0.5 (sqrt (* re -4.0))) (sqrt (* im 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e-72) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = sqrt((im * 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 <= (-1.8d-72)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = sqrt((im * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e-72) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = Math.sqrt((im * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e-72: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = math.sqrt((im * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e-72) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = sqrt(Float64(im * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e-72) tmp = 0.5 * sqrt((re * -4.0)); else tmp = sqrt((im * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e-72], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{-72}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im \cdot 0.5}\\
\end{array}
\end{array}
if re < -1.8e-72Initial program 47.6%
sqr-neg47.6%
sqr-neg47.6%
hypot-def100.0%
Simplified100.0%
Taylor expanded in re around -inf 74.9%
*-commutative74.9%
Simplified74.9%
if -1.8e-72 < re Initial program 37.7%
hypot-udef73.0%
add-sqr-sqrt72.5%
sqrt-unprod73.0%
*-commutative73.0%
*-commutative73.0%
swap-sqr73.0%
add-sqr-sqrt73.0%
metadata-eval73.0%
Applied egg-rr73.0%
*-commutative73.0%
associate-*r*73.6%
metadata-eval73.6%
Simplified73.6%
Taylor expanded in re around 0 61.5%
Final simplification66.5%
(FPCore (re im) :precision binary64 (sqrt (* 0.5 (- im re))))
double code(double re, double im) {
return sqrt((0.5 * (im - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((0.5d0 * (im - re)))
end function
public static double code(double re, double im) {
return Math.sqrt((0.5 * (im - re)));
}
def code(re, im): return math.sqrt((0.5 * (im - re)))
function code(re, im) return sqrt(Float64(0.5 * Float64(im - re))) end
function tmp = code(re, im) tmp = sqrt((0.5 * (im - re))); end
code[re_, im_] := N[Sqrt[N[(0.5 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(im - re\right)}
\end{array}
Initial program 41.4%
hypot-udef83.0%
add-sqr-sqrt82.4%
sqrt-unprod83.0%
*-commutative83.0%
*-commutative83.0%
swap-sqr83.0%
add-sqr-sqrt83.0%
metadata-eval83.0%
Applied egg-rr83.0%
*-commutative83.0%
associate-*r*83.4%
metadata-eval83.4%
Simplified83.4%
Taylor expanded in re around 0 53.6%
neg-mul-153.6%
unsub-neg53.6%
Simplified53.6%
Final simplification53.6%
(FPCore (re im) :precision binary64 (sqrt (* im 0.5)))
double code(double re, double im) {
return sqrt((im * 0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sqrt((im * 0.5d0))
end function
public static double code(double re, double im) {
return Math.sqrt((im * 0.5));
}
def code(re, im): return math.sqrt((im * 0.5))
function code(re, im) return sqrt(Float64(im * 0.5)) end
function tmp = code(re, im) tmp = sqrt((im * 0.5)); end
code[re_, im_] := N[Sqrt[N[(im * 0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{im \cdot 0.5}
\end{array}
Initial program 41.4%
hypot-udef83.0%
add-sqr-sqrt82.4%
sqrt-unprod83.0%
*-commutative83.0%
*-commutative83.0%
swap-sqr83.0%
add-sqr-sqrt83.0%
metadata-eval83.0%
Applied egg-rr83.0%
*-commutative83.0%
associate-*r*83.4%
metadata-eval83.4%
Simplified83.4%
Taylor expanded in re around 0 50.0%
Final simplification50.0%
(FPCore (re im) :precision binary64 (* im 0.5))
double code(double re, double im) {
return im * 0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * 0.5d0
end function
public static double code(double re, double im) {
return im * 0.5;
}
def code(re, im): return im * 0.5
function code(re, im) return Float64(im * 0.5) end
function tmp = code(re, im) tmp = im * 0.5; end
code[re_, im_] := N[(im * 0.5), $MachinePrecision]
\begin{array}{l}
\\
im \cdot 0.5
\end{array}
Initial program 41.4%
Taylor expanded in im around 0 22.7%
associate-*l*22.7%
*-commutative22.7%
associate-*l*22.8%
Simplified22.8%
add-sqr-sqrt22.7%
pow222.7%
associate-*r*22.7%
sqrt-unprod22.9%
metadata-eval22.9%
metadata-eval22.9%
*-un-lft-identity22.9%
inv-pow22.9%
sqrt-pow122.9%
metadata-eval22.9%
Applied egg-rr22.9%
unpow222.9%
add-sqr-sqrt23.0%
metadata-eval23.0%
sqrt-pow222.9%
inv-pow22.9%
un-div-inv22.9%
*-un-lft-identity22.9%
add-sqr-sqrt22.9%
times-frac22.8%
metadata-eval22.8%
sqrt-div22.9%
inv-pow22.9%
sqrt-pow222.9%
metadata-eval22.9%
sqrt-pow122.9%
metadata-eval22.9%
add-exp-log22.0%
add-sqr-sqrt17.2%
sqrt-unprod18.8%
sqr-neg18.8%
sqrt-unprod1.4%
add-sqr-sqrt3.1%
Applied egg-rr3.1%
*-commutative3.1%
associate-*l/3.5%
associate-/l*3.1%
*-inverses6.3%
/-rgt-identity6.3%
Simplified6.3%
Final simplification6.3%
herbie shell --seed 2023320
(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)))))