
(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 (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* 0.5 (/ im (sqrt re))) (* 0.5 (sqrt (* 2.0 (- (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 = 0.5 * (im / 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((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im / 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((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = 0.5 * (im / 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 (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(0.5 * Float64(im / 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((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = 0.5 * (im / sqrt(re)); else tmp = 0.5 * sqrt((2.0 * (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[(0.5 * N[(im / N[Sqrt[re], $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{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \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 7.9%
Taylor expanded in re around inf 57.1%
Taylor expanded in im around 0 99.4%
*-commutative99.4%
unpow1/299.4%
unpow-199.4%
exp-to-pow94.1%
*-commutative94.1%
neg-mul-194.1%
exp-prod94.1%
distribute-lft-neg-out94.1%
exp-neg94.0%
exp-to-pow99.2%
unpow1/299.2%
associate-*l/99.5%
*-lft-identity99.5%
Simplified99.5%
if 0.0 < (sqrt.f64 (*.f64 2 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 46.3%
sub-neg46.3%
sqr-neg46.3%
sub-neg46.3%
sqr-neg46.3%
hypot-def88.8%
Simplified88.8%
Final simplification90.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -0.037)
t_0
(if (<= re -2.7e-70)
t_1
(if (<= re -9e-124)
t_0
(if (<= re 3.6e-22)
t_1
(if (<= re 1.8e+106)
(* 0.5 (/ im (sqrt re)))
(if (<= re 8.6e+119) t_1 (* 0.5 (* im (pow re -0.5)))))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -0.037) {
tmp = t_0;
} else if (re <= -2.7e-70) {
tmp = t_1;
} else if (re <= -9e-124) {
tmp = t_0;
} else if (re <= 3.6e-22) {
tmp = t_1;
} else if (re <= 1.8e+106) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 8.6e+119) {
tmp = t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-0.037d0)) then
tmp = t_0
else if (re <= (-2.7d-70)) then
tmp = t_1
else if (re <= (-9d-124)) then
tmp = t_0
else if (re <= 3.6d-22) then
tmp = t_1
else if (re <= 1.8d+106) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 8.6d+119) then
tmp = t_1
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double t_1 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -0.037) {
tmp = t_0;
} else if (re <= -2.7e-70) {
tmp = t_1;
} else if (re <= -9e-124) {
tmp = t_0;
} else if (re <= 3.6e-22) {
tmp = t_1;
} else if (re <= 1.8e+106) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 8.6e+119) {
tmp = t_1;
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -0.037: tmp = t_0 elif re <= -2.7e-70: tmp = t_1 elif re <= -9e-124: tmp = t_0 elif re <= 3.6e-22: tmp = t_1 elif re <= 1.8e+106: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 8.6e+119: tmp = t_1 else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -0.037) tmp = t_0; elseif (re <= -2.7e-70) tmp = t_1; elseif (re <= -9e-124) tmp = t_0; elseif (re <= 3.6e-22) tmp = t_1; elseif (re <= 1.8e+106) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 8.6e+119) tmp = t_1; else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -0.037) tmp = t_0; elseif (re <= -2.7e-70) tmp = t_1; elseif (re <= -9e-124) tmp = t_0; elseif (re <= 3.6e-22) tmp = t_1; elseif (re <= 1.8e+106) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 8.6e+119) tmp = t_1; else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -0.037], t$95$0, If[LessEqual[re, -2.7e-70], t$95$1, If[LessEqual[re, -9e-124], t$95$0, If[LessEqual[re, 3.6e-22], t$95$1, If[LessEqual[re, 1.8e+106], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.6e+119], t$95$1, N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -0.037:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -2.7 \cdot 10^{-70}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-124}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 3.6 \cdot 10^{-22}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq 1.8 \cdot 10^{+106}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 8.6 \cdot 10^{+119}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -0.0369999999999999982 or -2.7000000000000001e-70 < re < -8.9999999999999992e-124Initial program 46.3%
Taylor expanded in re around -inf 79.9%
*-commutative79.9%
Simplified79.9%
if -0.0369999999999999982 < re < -2.7000000000000001e-70 or -8.9999999999999992e-124 < re < 3.5999999999999998e-22 or 1.8e106 < re < 8.60000000000000063e119Initial program 59.9%
Taylor expanded in re around 0 86.1%
*-commutative86.1%
Simplified86.1%
if 3.5999999999999998e-22 < re < 1.8e106Initial program 15.6%
Taylor expanded in re around inf 35.5%
Taylor expanded in im around 0 64.5%
*-commutative64.5%
unpow1/264.5%
unpow-164.5%
exp-to-pow61.8%
*-commutative61.8%
neg-mul-161.8%
exp-prod61.8%
distribute-lft-neg-out61.8%
exp-neg61.7%
exp-to-pow64.4%
unpow1/264.4%
associate-*l/64.6%
*-lft-identity64.6%
Simplified64.6%
if 8.60000000000000063e119 < re Initial program 5.0%
Taylor expanded in re around inf 56.8%
div-inv56.8%
sqrt-prod76.6%
unpow276.6%
sqrt-prod88.7%
add-sqr-sqrt89.2%
*-commutative89.2%
inv-pow89.2%
sqrt-pow189.2%
metadata-eval89.2%
Applied egg-rr89.2%
Final simplification82.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -8e+77)
t_0
(if (<= re -2.15e-69)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re -2.6e-124)
t_0
(if (<= re 5.9e-22)
t_1
(if (<= re 1.8e+106)
(* 0.5 (/ im (sqrt re)))
(if (<= re 8.6e+119) t_1 (* 0.5 (* im (pow re -0.5)))))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -8e+77) {
tmp = t_0;
} else if (re <= -2.15e-69) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= -2.6e-124) {
tmp = t_0;
} else if (re <= 5.9e-22) {
tmp = t_1;
} else if (re <= 1.8e+106) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 8.6e+119) {
tmp = t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-8d+77)) then
tmp = t_0
else if (re <= (-2.15d-69)) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= (-2.6d-124)) then
tmp = t_0
else if (re <= 5.9d-22) then
tmp = t_1
else if (re <= 1.8d+106) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 8.6d+119) then
tmp = t_1
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double t_1 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -8e+77) {
tmp = t_0;
} else if (re <= -2.15e-69) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= -2.6e-124) {
tmp = t_0;
} else if (re <= 5.9e-22) {
tmp = t_1;
} else if (re <= 1.8e+106) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 8.6e+119) {
tmp = t_1;
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -8e+77: tmp = t_0 elif re <= -2.15e-69: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= -2.6e-124: tmp = t_0 elif re <= 5.9e-22: tmp = t_1 elif re <= 1.8e+106: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 8.6e+119: tmp = t_1 else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -8e+77) tmp = t_0; elseif (re <= -2.15e-69) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= -2.6e-124) tmp = t_0; elseif (re <= 5.9e-22) tmp = t_1; elseif (re <= 1.8e+106) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 8.6e+119) tmp = t_1; else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -8e+77) tmp = t_0; elseif (re <= -2.15e-69) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= -2.6e-124) tmp = t_0; elseif (re <= 5.9e-22) tmp = t_1; elseif (re <= 1.8e+106) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 8.6e+119) tmp = t_1; else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -8e+77], t$95$0, If[LessEqual[re, -2.15e-69], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.6e-124], t$95$0, If[LessEqual[re, 5.9e-22], t$95$1, If[LessEqual[re, 1.8e+106], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.6e+119], t$95$1, N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -8 \cdot 10^{+77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -2.15 \cdot 10^{-69}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq -2.6 \cdot 10^{-124}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 5.9 \cdot 10^{-22}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq 1.8 \cdot 10^{+106}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 8.6 \cdot 10^{+119}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -7.99999999999999986e77 or -2.15e-69 < re < -2.6e-124Initial program 39.1%
Taylor expanded in re around -inf 86.1%
*-commutative86.1%
Simplified86.1%
if -7.99999999999999986e77 < re < -2.15e-69Initial program 78.7%
Taylor expanded in re around 0 67.5%
if -2.6e-124 < re < 5.90000000000000008e-22 or 1.8e106 < re < 8.60000000000000063e119Initial program 57.2%
Taylor expanded in re around 0 87.5%
*-commutative87.5%
Simplified87.5%
if 5.90000000000000008e-22 < re < 1.8e106Initial program 15.6%
Taylor expanded in re around inf 35.5%
Taylor expanded in im around 0 64.5%
*-commutative64.5%
unpow1/264.5%
unpow-164.5%
exp-to-pow61.8%
*-commutative61.8%
neg-mul-161.8%
exp-prod61.8%
distribute-lft-neg-out61.8%
exp-neg61.7%
exp-to-pow64.4%
unpow1/264.4%
associate-*l/64.6%
*-lft-identity64.6%
Simplified64.6%
if 8.60000000000000063e119 < re Initial program 5.0%
Taylor expanded in re around inf 56.8%
div-inv56.8%
sqrt-prod76.6%
unpow276.6%
sqrt-prod88.7%
add-sqr-sqrt89.2%
*-commutative89.2%
inv-pow89.2%
sqrt-pow189.2%
metadata-eval89.2%
Applied egg-rr89.2%
Final simplification83.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* re -4.0)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -0.054)
t_0
(if (<= re -9.6e-70)
t_1
(if (<= re -7.5e-124)
t_0
(if (or (<= re 9.5e-22) (and (not (<= re 1.8e+106)) (<= re 8.6e+119)))
t_1
(* 0.5 (/ im (sqrt re)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((re * -4.0));
double t_1 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -0.054) {
tmp = t_0;
} else if (re <= -9.6e-70) {
tmp = t_1;
} else if (re <= -7.5e-124) {
tmp = t_0;
} else if ((re <= 9.5e-22) || (!(re <= 1.8e+106) && (re <= 8.6e+119))) {
tmp = t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * sqrt((re * (-4.0d0)))
t_1 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-0.054d0)) then
tmp = t_0
else if (re <= (-9.6d-70)) then
tmp = t_1
else if (re <= (-7.5d-124)) then
tmp = t_0
else if ((re <= 9.5d-22) .or. (.not. (re <= 1.8d+106)) .and. (re <= 8.6d+119)) then
tmp = t_1
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * Math.sqrt((re * -4.0));
double t_1 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -0.054) {
tmp = t_0;
} else if (re <= -9.6e-70) {
tmp = t_1;
} else if (re <= -7.5e-124) {
tmp = t_0;
} else if ((re <= 9.5e-22) || (!(re <= 1.8e+106) && (re <= 8.6e+119))) {
tmp = t_1;
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((re * -4.0)) t_1 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -0.054: tmp = t_0 elif re <= -9.6e-70: tmp = t_1 elif re <= -7.5e-124: tmp = t_0 elif (re <= 9.5e-22) or (not (re <= 1.8e+106) and (re <= 8.6e+119)): tmp = t_1 else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(re * -4.0))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -0.054) tmp = t_0; elseif (re <= -9.6e-70) tmp = t_1; elseif (re <= -7.5e-124) tmp = t_0; elseif ((re <= 9.5e-22) || (!(re <= 1.8e+106) && (re <= 8.6e+119))) tmp = t_1; else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * sqrt((re * -4.0)); t_1 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -0.054) tmp = t_0; elseif (re <= -9.6e-70) tmp = t_1; elseif (re <= -7.5e-124) tmp = t_0; elseif ((re <= 9.5e-22) || (~((re <= 1.8e+106)) && (re <= 8.6e+119))) tmp = t_1; else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -0.054], t$95$0, If[LessEqual[re, -9.6e-70], t$95$1, If[LessEqual[re, -7.5e-124], t$95$0, If[Or[LessEqual[re, 9.5e-22], And[N[Not[LessEqual[re, 1.8e+106]], $MachinePrecision], LessEqual[re, 8.6e+119]]], t$95$1, N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{re \cdot -4}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -0.054:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq -9.6 \cdot 10^{-70}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq -7.5 \cdot 10^{-124}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 9.5 \cdot 10^{-22} \lor \neg \left(re \leq 1.8 \cdot 10^{+106}\right) \land re \leq 8.6 \cdot 10^{+119}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.0539999999999999994 or -9.6000000000000005e-70 < re < -7.4999999999999996e-124Initial program 46.3%
Taylor expanded in re around -inf 79.9%
*-commutative79.9%
Simplified79.9%
if -0.0539999999999999994 < re < -9.6000000000000005e-70 or -7.4999999999999996e-124 < re < 9.4999999999999994e-22 or 1.8e106 < re < 8.60000000000000063e119Initial program 59.9%
Taylor expanded in re around 0 86.1%
*-commutative86.1%
Simplified86.1%
if 9.4999999999999994e-22 < re < 1.8e106 or 8.60000000000000063e119 < re Initial program 9.0%
Taylor expanded in re around inf 48.8%
Taylor expanded in im around 0 79.9%
*-commutative79.9%
unpow1/279.9%
unpow-179.9%
exp-to-pow75.3%
*-commutative75.3%
neg-mul-175.3%
exp-prod75.3%
distribute-lft-neg-out75.3%
exp-neg75.3%
exp-to-pow79.7%
unpow1/279.7%
associate-*l/79.8%
*-lft-identity79.8%
Simplified79.8%
Final simplification82.4%
(FPCore (re im) :precision binary64 (if (or (<= re -0.019) (and (not (<= re -4.4e-69)) (<= re -9e-124))) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if ((re <= -0.019) || (!(re <= -4.4e-69) && (re <= -9e-124))) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((2.0 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-0.019d0)) .or. (.not. (re <= (-4.4d-69))) .and. (re <= (-9d-124))) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.019) || (!(re <= -4.4e-69) && (re <= -9e-124))) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.019) or (not (re <= -4.4e-69) and (re <= -9e-124)): tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.019) || (!(re <= -4.4e-69) && (re <= -9e-124))) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.019) || (~((re <= -4.4e-69)) && (re <= -9e-124))) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.019], And[N[Not[LessEqual[re, -4.4e-69]], $MachinePrecision], LessEqual[re, -9e-124]]], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.019 \lor \neg \left(re \leq -4.4 \cdot 10^{-69}\right) \land re \leq -9 \cdot 10^{-124}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -0.0189999999999999995 or -4.4e-69 < re < -8.9999999999999992e-124Initial program 46.3%
Taylor expanded in re around -inf 79.9%
*-commutative79.9%
Simplified79.9%
if -0.0189999999999999995 < re < -4.4e-69 or -8.9999999999999992e-124 < re Initial program 39.7%
Taylor expanded in re around 0 62.0%
*-commutative62.0%
Simplified62.0%
Final simplification67.7%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 41.8%
Taylor expanded in re around 0 49.9%
*-commutative49.9%
Simplified49.9%
Final simplification49.9%
herbie shell --seed 2024020
(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)))))