
(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 12.4%
Taylor expanded in re around inf 34.8%
unpow234.8%
Simplified34.8%
expm1-log1p-u34.8%
expm1-udef12.4%
sqrt-div12.4%
sqrt-prod12.4%
add-sqr-sqrt12.4%
Applied egg-rr12.4%
expm1-def99.7%
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 45.7%
hypot-def90.0%
Simplified90.0%
Final simplification91.1%
(FPCore (re im)
:precision binary64
(if (<= re -5.5e+32)
(* 0.5 (sqrt (* re -4.0)))
(if (or (<= re 5.5e-104)
(and (not (<= re 3.9e-70))
(or (<= re 3e+66)
(and (not (<= re 2.05e+97)) (<= re 2e+113)))))
(* 0.5 (sqrt (* 2.0 im)))
(* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -5.5e+32) {
tmp = 0.5 * sqrt((re * -4.0));
} else if ((re <= 5.5e-104) || (!(re <= 3.9e-70) && ((re <= 3e+66) || (!(re <= 2.05e+97) && (re <= 2e+113))))) {
tmp = 0.5 * sqrt((2.0 * im));
} 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) :: tmp
if (re <= (-5.5d+32)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if ((re <= 5.5d-104) .or. (.not. (re <= 3.9d-70)) .and. (re <= 3d+66) .or. (.not. (re <= 2.05d+97)) .and. (re <= 2d+113)) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = 0.5d0 * (im / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -5.5e+32) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if ((re <= 5.5e-104) || (!(re <= 3.9e-70) && ((re <= 3e+66) || (!(re <= 2.05e+97) && (re <= 2e+113))))) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -5.5e+32: tmp = 0.5 * math.sqrt((re * -4.0)) elif (re <= 5.5e-104) or (not (re <= 3.9e-70) and ((re <= 3e+66) or (not (re <= 2.05e+97) and (re <= 2e+113)))): tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -5.5e+32) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif ((re <= 5.5e-104) || (!(re <= 3.9e-70) && ((re <= 3e+66) || (!(re <= 2.05e+97) && (re <= 2e+113))))) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -5.5e+32) tmp = 0.5 * sqrt((re * -4.0)); elseif ((re <= 5.5e-104) || (~((re <= 3.9e-70)) && ((re <= 3e+66) || (~((re <= 2.05e+97)) && (re <= 2e+113))))) tmp = 0.5 * sqrt((2.0 * im)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -5.5e+32], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 5.5e-104], And[N[Not[LessEqual[re, 3.9e-70]], $MachinePrecision], Or[LessEqual[re, 3e+66], And[N[Not[LessEqual[re, 2.05e+97]], $MachinePrecision], LessEqual[re, 2e+113]]]]], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -5.5 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 5.5 \cdot 10^{-104} \lor \neg \left(re \leq 3.9 \cdot 10^{-70}\right) \land \left(re \leq 3 \cdot 10^{+66} \lor \neg \left(re \leq 2.05 \cdot 10^{+97}\right) \land re \leq 2 \cdot 10^{+113}\right):\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -5.49999999999999984e32Initial program 38.1%
Taylor expanded in re around -inf 82.9%
*-commutative82.9%
Simplified82.9%
if -5.49999999999999984e32 < re < 5.4999999999999998e-104 or 3.90000000000000019e-70 < re < 3.00000000000000002e66 or 2.04999999999999994e97 < re < 2e113Initial program 54.4%
Taylor expanded in re around 0 79.1%
*-commutative79.1%
Simplified79.1%
if 5.4999999999999998e-104 < re < 3.90000000000000019e-70 or 3.00000000000000002e66 < re < 2.04999999999999994e97 or 2e113 < re Initial program 11.8%
Taylor expanded in re around inf 42.8%
unpow242.8%
Simplified42.8%
expm1-log1p-u42.5%
expm1-udef21.7%
sqrt-div21.7%
sqrt-prod29.1%
add-sqr-sqrt29.1%
Applied egg-rr29.1%
expm1-def86.2%
expm1-log1p87.0%
Simplified87.0%
Final simplification81.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (/ im (sqrt re)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -2e+32)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 5.5e-104)
t_1
(if (<= re 5.2e-68)
t_0
(if (<= re 1.25e+69)
t_1
(if (<= re 3.2e+97)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 2e+113) t_1 t_0))))))))
double code(double re, double im) {
double t_0 = 0.5 * (im / sqrt(re));
double t_1 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -2e+32) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 5.5e-104) {
tmp = t_1;
} else if (re <= 5.2e-68) {
tmp = t_0;
} else if (re <= 1.25e+69) {
tmp = t_1;
} else if (re <= 3.2e+97) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 2e+113) {
tmp = t_1;
} else {
tmp = t_0;
}
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 * (im / sqrt(re))
t_1 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-2d+32)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 5.5d-104) then
tmp = t_1
else if (re <= 5.2d-68) then
tmp = t_0
else if (re <= 1.25d+69) then
tmp = t_1
else if (re <= 3.2d+97) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 2d+113) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * (im / Math.sqrt(re));
double t_1 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -2e+32) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 5.5e-104) {
tmp = t_1;
} else if (re <= 5.2e-68) {
tmp = t_0;
} else if (re <= 1.25e+69) {
tmp = t_1;
} else if (re <= 3.2e+97) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 2e+113) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (im / math.sqrt(re)) t_1 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -2e+32: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 5.5e-104: tmp = t_1 elif re <= 5.2e-68: tmp = t_0 elif re <= 1.25e+69: tmp = t_1 elif re <= 3.2e+97: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 2e+113: tmp = t_1 else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(im / sqrt(re))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -2e+32) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 5.5e-104) tmp = t_1; elseif (re <= 5.2e-68) tmp = t_0; elseif (re <= 1.25e+69) tmp = t_1; elseif (re <= 3.2e+97) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 2e+113) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * (im / sqrt(re)); t_1 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -2e+32) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 5.5e-104) tmp = t_1; elseif (re <= 5.2e-68) tmp = t_0; elseif (re <= 1.25e+69) tmp = t_1; elseif (re <= 3.2e+97) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 2e+113) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -2e+32], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.5e-104], t$95$1, If[LessEqual[re, 5.2e-68], t$95$0, If[LessEqual[re, 1.25e+69], t$95$1, If[LessEqual[re, 3.2e+97], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2e+113], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im}{\sqrt{re}}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -2 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 5.5 \cdot 10^{-104}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq 5.2 \cdot 10^{-68}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 1.25 \cdot 10^{+69}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq 3.2 \cdot 10^{+97}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 2 \cdot 10^{+113}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if re < -2.00000000000000011e32Initial program 38.1%
Taylor expanded in re around -inf 82.9%
*-commutative82.9%
Simplified82.9%
if -2.00000000000000011e32 < re < 5.4999999999999998e-104 or 5.1999999999999996e-68 < re < 1.25000000000000009e69 or 3.20000000000000016e97 < re < 2e113Initial program 54.4%
Taylor expanded in re around 0 79.1%
*-commutative79.1%
Simplified79.1%
if 5.4999999999999998e-104 < re < 5.1999999999999996e-68 or 2e113 < re Initial program 10.3%
Taylor expanded in re around inf 44.7%
unpow244.7%
Simplified44.7%
expm1-log1p-u44.4%
expm1-udef21.3%
sqrt-div21.3%
sqrt-prod29.5%
add-sqr-sqrt29.5%
Applied egg-rr29.5%
expm1-def84.7%
expm1-log1p85.6%
Simplified85.6%
if 1.25000000000000009e69 < re < 3.20000000000000016e97Initial program 25.4%
Taylor expanded in re around inf 25.4%
unpow225.4%
Simplified25.4%
div-inv25.4%
sqrt-prod25.4%
sqrt-prod99.5%
add-sqr-sqrt99.7%
inv-pow99.7%
sqrt-pow199.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification81.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (/ im (sqrt re)))) (t_1 (* 0.5 (sqrt (* 2.0 im)))))
(if (<= re -6.1e+34)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 2.35e-104)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 1.05e-69)
t_0
(if (<= re 8e+68)
t_1
(if (<= re 2.4e+97)
(* 0.5 (* im (pow re -0.5)))
(if (<= re 8e+114) t_1 t_0))))))))
double code(double re, double im) {
double t_0 = 0.5 * (im / sqrt(re));
double t_1 = 0.5 * sqrt((2.0 * im));
double tmp;
if (re <= -6.1e+34) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.35e-104) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 1.05e-69) {
tmp = t_0;
} else if (re <= 8e+68) {
tmp = t_1;
} else if (re <= 2.4e+97) {
tmp = 0.5 * (im * pow(re, -0.5));
} else if (re <= 8e+114) {
tmp = t_1;
} else {
tmp = t_0;
}
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 * (im / sqrt(re))
t_1 = 0.5d0 * sqrt((2.0d0 * im))
if (re <= (-6.1d+34)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.35d-104) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 1.05d-69) then
tmp = t_0
else if (re <= 8d+68) then
tmp = t_1
else if (re <= 2.4d+97) then
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
else if (re <= 8d+114) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * (im / Math.sqrt(re));
double t_1 = 0.5 * Math.sqrt((2.0 * im));
double tmp;
if (re <= -6.1e+34) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.35e-104) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 1.05e-69) {
tmp = t_0;
} else if (re <= 8e+68) {
tmp = t_1;
} else if (re <= 2.4e+97) {
tmp = 0.5 * (im * Math.pow(re, -0.5));
} else if (re <= 8e+114) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (im / math.sqrt(re)) t_1 = 0.5 * math.sqrt((2.0 * im)) tmp = 0 if re <= -6.1e+34: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.35e-104: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 1.05e-69: tmp = t_0 elif re <= 8e+68: tmp = t_1 elif re <= 2.4e+97: tmp = 0.5 * (im * math.pow(re, -0.5)) elif re <= 8e+114: tmp = t_1 else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(im / sqrt(re))) t_1 = Float64(0.5 * sqrt(Float64(2.0 * im))) tmp = 0.0 if (re <= -6.1e+34) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.35e-104) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 1.05e-69) tmp = t_0; elseif (re <= 8e+68) tmp = t_1; elseif (re <= 2.4e+97) tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); elseif (re <= 8e+114) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * (im / sqrt(re)); t_1 = 0.5 * sqrt((2.0 * im)); tmp = 0.0; if (re <= -6.1e+34) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.35e-104) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 1.05e-69) tmp = t_0; elseif (re <= 8e+68) tmp = t_1; elseif (re <= 2.4e+97) tmp = 0.5 * (im * (re ^ -0.5)); elseif (re <= 8e+114) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -6.1e+34], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.35e-104], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.05e-69], t$95$0, If[LessEqual[re, 8e+68], t$95$1, If[LessEqual[re, 2.4e+97], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8e+114], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \frac{im}{\sqrt{re}}\\
t_1 := 0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{if}\;re \leq -6.1 \cdot 10^{+34}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.35 \cdot 10^{-104}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 1.05 \cdot 10^{-69}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+68}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;re \leq 2.4 \cdot 10^{+97}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+114}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if re < -6.09999999999999996e34Initial program 36.1%
Taylor expanded in re around -inf 83.8%
*-commutative83.8%
Simplified83.8%
if -6.09999999999999996e34 < re < 2.35e-104Initial program 59.4%
Taylor expanded in re around 0 81.5%
if 2.35e-104 < re < 1.05e-69 or 8e114 < re Initial program 10.3%
Taylor expanded in re around inf 44.7%
unpow244.7%
Simplified44.7%
expm1-log1p-u44.4%
expm1-udef21.3%
sqrt-div21.3%
sqrt-prod29.5%
add-sqr-sqrt29.5%
Applied egg-rr29.5%
expm1-def84.7%
expm1-log1p85.6%
Simplified85.6%
if 1.05e-69 < re < 7.99999999999999962e68 or 2.4e97 < re < 8e114Initial program 40.2%
Taylor expanded in re around 0 76.5%
*-commutative76.5%
Simplified76.5%
if 7.99999999999999962e68 < re < 2.4e97Initial program 25.4%
Taylor expanded in re around inf 25.4%
unpow225.4%
Simplified25.4%
div-inv25.4%
sqrt-prod25.4%
sqrt-prod99.5%
add-sqr-sqrt99.7%
inv-pow99.7%
sqrt-pow199.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification82.6%
(FPCore (re im) :precision binary64 (if (<= re -4.5e+31) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -4.5e+31) {
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 <= (-4.5d+31)) 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 <= -4.5e+31) {
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 <= -4.5e+31: 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 <= -4.5e+31) 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 <= -4.5e+31) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.5e+31], 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 -4.5 \cdot 10^{+31}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -4.4999999999999996e31Initial program 38.1%
Taylor expanded in re around -inf 82.9%
*-commutative82.9%
Simplified82.9%
if -4.4999999999999996e31 < re Initial program 43.0%
Taylor expanded in re around 0 63.1%
*-commutative63.1%
Simplified63.1%
Final simplification68.1%
(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 53.0%
*-commutative53.0%
Simplified53.0%
Final simplification53.0%
herbie shell --seed 2023257
(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)))))