
(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) (* 0.5 (* im (sqrt (/ 1.0 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 = 0.5 * (im * sqrt((1.0 / 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 = 0.5 * (im * Math.sqrt((1.0 / 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 = 0.5 * (im * math.sqrt((1.0 / 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(0.5 * Float64(im * sqrt(Float64(1.0 / 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 = 0.5 * (im * sqrt((1.0 / 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[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $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{re \cdot re + im \cdot im} - re \leq 0:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\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 6.9%
Taylor expanded in re around inf 42.5%
unpow242.5%
Simplified42.5%
Taylor expanded in im around 0 97.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 51.0%
sqr-neg51.0%
sqr-neg51.0%
hypot-def87.5%
Simplified87.5%
Final simplification88.9%
(FPCore (re im)
:precision binary64
(if (<= re -510.0)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.4e-44)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 0.00026)
(* 0.5 (/ im (sqrt re)))
(if (<= re 3e+30)
(* 0.5 (sqrt (* 2.0 (+ im (- (/ 0.5 (/ im (* re re))) re)))))
(* 0.5 (* im (pow re -0.5))))))))
double code(double re, double im) {
double tmp;
if (re <= -510.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.4e-44) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 0.00026) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 3e+30) {
tmp = 0.5 * sqrt((2.0 * (im + ((0.5 / (im / (re * re))) - re))));
} 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) :: tmp
if (re <= (-510.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.4d-44) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 0.00026d0) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 3d+30) then
tmp = 0.5d0 * sqrt((2.0d0 * (im + ((0.5d0 / (im / (re * re))) - re))))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -510.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.4e-44) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 0.00026) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 3e+30) {
tmp = 0.5 * Math.sqrt((2.0 * (im + ((0.5 / (im / (re * re))) - re))));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -510.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.4e-44: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 0.00026: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 3e+30: tmp = 0.5 * math.sqrt((2.0 * (im + ((0.5 / (im / (re * re))) - re)))) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -510.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.4e-44) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 0.00026) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 3e+30) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im + Float64(Float64(0.5 / Float64(im / Float64(re * re))) - re))))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -510.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.4e-44) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 0.00026) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 3e+30) tmp = 0.5 * sqrt((2.0 * (im + ((0.5 / (im / (re * re))) - re)))); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -510.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.4e-44], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 0.00026], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3e+30], N[(0.5 * N[Sqrt[N[(2.0 * N[(im + N[(N[(0.5 / N[(im / N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -510:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.4 \cdot 10^{-44}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 0.00026:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 3 \cdot 10^{+30}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im + \left(\frac{0.5}{\frac{im}{re \cdot re}} - re\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -510Initial program 56.6%
Taylor expanded in re around -inf 75.6%
*-commutative75.6%
Simplified75.6%
if -510 < re < 1.4e-44Initial program 58.6%
Taylor expanded in re around 0 79.5%
if 1.4e-44 < re < 2.59999999999999977e-4Initial program 28.8%
Taylor expanded in re around inf 53.6%
unpow253.6%
Simplified53.6%
expm1-log1p-u53.6%
expm1-udef5.5%
sqrt-div5.5%
sqrt-prod5.5%
add-sqr-sqrt5.5%
Applied egg-rr5.5%
expm1-def76.6%
expm1-log1p76.6%
Simplified76.6%
if 2.59999999999999977e-4 < re < 2.99999999999999978e30Initial program 45.7%
Taylor expanded in re around 0 86.1%
associate-*r/86.1%
unpow286.1%
Simplified86.1%
expm1-log1p-u79.6%
expm1-udef79.6%
associate--l+79.6%
associate-/l*79.6%
associate-/r*79.6%
Applied egg-rr79.6%
expm1-def79.6%
expm1-log1p86.1%
associate-/l/86.1%
Simplified86.1%
if 2.99999999999999978e30 < re Initial program 10.8%
Taylor expanded in re around inf 45.1%
unpow245.1%
Simplified45.1%
expm1-log1p-u45.0%
expm1-udef17.8%
sqrt-div17.8%
sqrt-prod24.0%
add-sqr-sqrt24.0%
Applied egg-rr24.0%
expm1-def78.1%
expm1-log1p78.6%
Simplified78.6%
*-un-lft-identity78.6%
associate-*l/78.5%
metadata-eval78.5%
sqrt-div78.6%
inv-pow78.6%
sqrt-pow178.6%
metadata-eval78.6%
Applied egg-rr78.6%
Final simplification78.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (- im re))))))
(if (<= re -520.0)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3.8e-42)
t_0
(if (<= re 8.2e-5)
(* 0.5 (/ im (sqrt re)))
(if (<= re 2.8e+28) t_0 (* 0.5 (* im (pow re -0.5)))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (im - re)));
double tmp;
if (re <= -520.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.8e-42) {
tmp = t_0;
} else if (re <= 8.2e-5) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 2.8e+28) {
tmp = t_0;
} 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) :: tmp
t_0 = 0.5d0 * sqrt((2.0d0 * (im - re)))
if (re <= (-520.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.8d-42) then
tmp = t_0
else if (re <= 8.2d-5) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 2.8d+28) then
tmp = t_0
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((2.0 * (im - re)));
double tmp;
if (re <= -520.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.8e-42) {
tmp = t_0;
} else if (re <= 8.2e-5) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 2.8e+28) {
tmp = t_0;
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * math.sqrt((2.0 * (im - re))) tmp = 0 if re <= -520.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.8e-42: tmp = t_0 elif re <= 8.2e-5: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 2.8e+28: tmp = t_0 else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))) tmp = 0.0 if (re <= -520.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.8e-42) tmp = t_0; elseif (re <= 8.2e-5) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 2.8e+28) tmp = t_0; 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((2.0 * (im - re))); tmp = 0.0; if (re <= -520.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.8e-42) tmp = t_0; elseif (re <= 8.2e-5) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 2.8e+28) tmp = t_0; 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[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -520.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.8e-42], t$95$0, If[LessEqual[re, 8.2e-5], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.8e+28], t$95$0, 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{2 \cdot \left(im - re\right)}\\
\mathbf{if}\;re \leq -520:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.8 \cdot 10^{-42}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;re \leq 8.2 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 2.8 \cdot 10^{+28}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -520Initial program 56.6%
Taylor expanded in re around -inf 75.6%
*-commutative75.6%
Simplified75.6%
if -520 < re < 3.80000000000000017e-42 or 8.20000000000000009e-5 < re < 2.8000000000000001e28Initial program 57.9%
Taylor expanded in re around 0 79.8%
if 3.80000000000000017e-42 < re < 8.20000000000000009e-5Initial program 28.8%
Taylor expanded in re around inf 53.6%
unpow253.6%
Simplified53.6%
expm1-log1p-u53.6%
expm1-udef5.5%
sqrt-div5.5%
sqrt-prod5.5%
add-sqr-sqrt5.5%
Applied egg-rr5.5%
expm1-def76.6%
expm1-log1p76.6%
Simplified76.6%
if 2.8000000000000001e28 < re Initial program 10.8%
Taylor expanded in re around inf 45.1%
unpow245.1%
Simplified45.1%
expm1-log1p-u45.0%
expm1-udef17.8%
sqrt-div17.8%
sqrt-prod24.0%
add-sqr-sqrt24.0%
Applied egg-rr24.0%
expm1-def78.1%
expm1-log1p78.6%
Simplified78.6%
*-un-lft-identity78.6%
associate-*l/78.5%
metadata-eval78.5%
sqrt-div78.6%
inv-pow78.6%
sqrt-pow178.6%
metadata-eval78.6%
Applied egg-rr78.6%
Final simplification78.5%
(FPCore (re im)
:precision binary64
(if (<= re -550.0)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3.3e+28)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -550.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.3e+28) {
tmp = 0.5 * sqrt((im * 2.0));
} 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) :: tmp
if (re <= (-550.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.3d+28) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
else
tmp = 0.5d0 * (im * (re ** (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -550.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.3e+28) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im * Math.pow(re, -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -550.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.3e+28: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im * math.pow(re, -0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -550.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.3e+28) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(im * (re ^ -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -550.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.3e+28) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im * (re ^ -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -550.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.3e+28], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -550:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{-0.5}\right)\\
\end{array}
\end{array}
if re < -550Initial program 56.6%
Taylor expanded in re around -inf 75.6%
*-commutative75.6%
Simplified75.6%
if -550 < re < 3.3e28Initial program 56.2%
Taylor expanded in re around 0 76.0%
*-commutative76.0%
Simplified76.0%
if 3.3e28 < re Initial program 10.8%
Taylor expanded in re around inf 45.1%
unpow245.1%
Simplified45.1%
expm1-log1p-u45.0%
expm1-udef17.8%
sqrt-div17.8%
sqrt-prod24.0%
add-sqr-sqrt24.0%
Applied egg-rr24.0%
expm1-def78.1%
expm1-log1p78.6%
Simplified78.6%
*-un-lft-identity78.6%
associate-*l/78.5%
metadata-eval78.5%
sqrt-div78.6%
inv-pow78.6%
sqrt-pow178.6%
metadata-eval78.6%
Applied egg-rr78.6%
Final simplification76.6%
(FPCore (re im) :precision binary64 (if (<= re -600.0) (* 0.5 (sqrt (* re -4.0))) (if (<= re 2.3e+29) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -600.0) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.3e+29) {
tmp = 0.5 * sqrt((im * 2.0));
} 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 <= (-600.0d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.3d+29) then
tmp = 0.5d0 * sqrt((im * 2.0d0))
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 <= -600.0) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.3e+29) {
tmp = 0.5 * Math.sqrt((im * 2.0));
} else {
tmp = 0.5 * (im / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -600.0: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.3e+29: tmp = 0.5 * math.sqrt((im * 2.0)) else: tmp = 0.5 * (im / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -600.0) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.3e+29) tmp = Float64(0.5 * sqrt(Float64(im * 2.0))); else tmp = Float64(0.5 * Float64(im / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -600.0) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.3e+29) tmp = 0.5 * sqrt((im * 2.0)); else tmp = 0.5 * (im / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -600.0], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.3e+29], N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -600:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.3 \cdot 10^{+29}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -600Initial program 56.6%
Taylor expanded in re around -inf 75.6%
*-commutative75.6%
Simplified75.6%
if -600 < re < 2.3000000000000001e29Initial program 56.2%
Taylor expanded in re around 0 76.0%
*-commutative76.0%
Simplified76.0%
if 2.3000000000000001e29 < re Initial program 10.8%
Taylor expanded in re around inf 45.1%
unpow245.1%
Simplified45.1%
expm1-log1p-u45.0%
expm1-udef17.8%
sqrt-div17.8%
sqrt-prod24.0%
add-sqr-sqrt24.0%
Applied egg-rr24.0%
expm1-def78.1%
expm1-log1p78.6%
Simplified78.6%
Final simplification76.6%
(FPCore (re im) :precision binary64 (if (<= re -620.0) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (re <= -620.0) {
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 <= (-620.0d0)) 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 <= -620.0) {
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 <= -620.0: 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 <= -620.0) 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 <= -620.0) 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, -620.0], 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 -620:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -620Initial program 56.6%
Taylor expanded in re around -inf 75.6%
*-commutative75.6%
Simplified75.6%
if -620 < re Initial program 41.7%
Taylor expanded in re around 0 60.5%
*-commutative60.5%
Simplified60.5%
Final simplification63.6%
(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%
Taylor expanded in re around 0 53.5%
*-commutative53.5%
Simplified53.5%
Final simplification53.5%
herbie shell --seed 2023283
(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)))))