
(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 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(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(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(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(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(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[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{re \cdot re + im \cdot im} - re \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 (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) < 0.0Initial program 7.0%
Taylor expanded in im around 0 90.1%
associate-*l*90.3%
associate-*l*90.6%
Simplified90.6%
add-log-exp12.7%
*-un-lft-identity12.7%
log-prod12.7%
metadata-eval12.7%
add-log-exp90.6%
associate-*r*90.3%
*-commutative90.3%
sqrt-unprod91.2%
metadata-eval91.2%
metadata-eval91.2%
*-un-lft-identity91.2%
sqrt-div90.9%
metadata-eval90.9%
un-div-inv91.3%
Applied egg-rr91.3%
+-lft-identity91.3%
Simplified91.3%
if 0.0 < (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re) Initial program 46.5%
sub-neg46.5%
sqr-neg46.5%
sub-neg46.5%
sqr-neg46.5%
hypot-def92.6%
Simplified92.6%
Final simplification92.4%
(FPCore (re im)
:precision binary64
(if (<= re -0.00082)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3.4e+17)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 8.2e+61)
(* 0.5 (/ im (sqrt re)))
(if (<= re 4.55e+111)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.00082) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.4e+17) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 8.2e+61) {
tmp = 0.5 * (im / sqrt(re));
} else if (re <= 4.55e+111) {
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 <= (-0.00082d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.4d+17) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 8.2d+61) then
tmp = 0.5d0 * (im / sqrt(re))
else if (re <= 4.55d+111) 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 <= -0.00082) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.4e+17) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 8.2e+61) {
tmp = 0.5 * (im / Math.sqrt(re));
} else if (re <= 4.55e+111) {
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 <= -0.00082: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.4e+17: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 8.2e+61: tmp = 0.5 * (im / math.sqrt(re)) elif re <= 4.55e+111: 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 <= -0.00082) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.4e+17) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 8.2e+61) tmp = Float64(0.5 * Float64(im / sqrt(re))); elseif (re <= 4.55e+111) 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 <= -0.00082) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.4e+17) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 8.2e+61) tmp = 0.5 * (im / sqrt(re)); elseif (re <= 4.55e+111) 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, -0.00082], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.4e+17], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.2e+61], N[(0.5 * N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.55e+111], 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 -0.00082:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.4 \cdot 10^{+17}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 8.2 \cdot 10^{+61}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\mathbf{elif}\;re \leq 4.55 \cdot 10^{+111}:\\
\;\;\;\;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 < -8.1999999999999998e-4Initial program 39.6%
Taylor expanded in re around -inf 77.1%
*-commutative77.1%
Simplified77.1%
if -8.1999999999999998e-4 < re < 3.4e17Initial program 55.2%
Taylor expanded in re around 0 84.0%
if 3.4e17 < re < 8.19999999999999944e61Initial program 23.4%
Taylor expanded in im around 0 71.0%
associate-*l*71.0%
associate-*l*71.3%
Simplified71.3%
add-log-exp6.4%
*-un-lft-identity6.4%
log-prod6.4%
metadata-eval6.4%
add-log-exp71.3%
associate-*r*71.0%
*-commutative71.0%
sqrt-unprod71.6%
metadata-eval71.6%
metadata-eval71.6%
*-un-lft-identity71.6%
sqrt-div71.3%
metadata-eval71.3%
un-div-inv71.9%
Applied egg-rr71.9%
+-lft-identity71.9%
Simplified71.9%
if 8.19999999999999944e61 < re < 4.55000000000000002e111Initial program 41.2%
Taylor expanded in re around 0 85.4%
*-commutative85.4%
Simplified85.4%
if 4.55000000000000002e111 < re Initial program 6.1%
Taylor expanded in im around 0 81.2%
associate-*l*81.3%
associate-*l*81.5%
Simplified81.5%
associate-*r*81.3%
*-commutative81.3%
sqrt-unprod82.3%
metadata-eval82.3%
metadata-eval82.3%
*-un-lft-identity82.3%
add-log-exp18.1%
*-un-lft-identity18.1%
log-prod18.1%
metadata-eval18.1%
add-log-exp82.3%
inv-pow82.3%
sqrt-pow182.4%
metadata-eval82.4%
Applied egg-rr82.4%
+-lft-identity82.4%
Simplified82.4%
Final simplification81.6%
(FPCore (re im)
:precision binary64
(if (<= re -0.095)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 4.2e+17)
(* 0.5 (sqrt (* 2.0 (- im re))))
(if (<= re 1.25e+65)
(* 0.5 (/ 1.0 (/ (sqrt re) im)))
(if (<= re 4.55e+111)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.095) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.2e+17) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else if (re <= 1.25e+65) {
tmp = 0.5 * (1.0 / (sqrt(re) / im));
} else if (re <= 4.55e+111) {
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 <= (-0.095d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.2d+17) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else if (re <= 1.25d+65) then
tmp = 0.5d0 * (1.0d0 / (sqrt(re) / im))
else if (re <= 4.55d+111) 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 <= -0.095) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.2e+17) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else if (re <= 1.25e+65) {
tmp = 0.5 * (1.0 / (Math.sqrt(re) / im));
} else if (re <= 4.55e+111) {
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 <= -0.095: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.2e+17: tmp = 0.5 * math.sqrt((2.0 * (im - re))) elif re <= 1.25e+65: tmp = 0.5 * (1.0 / (math.sqrt(re) / im)) elif re <= 4.55e+111: 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 <= -0.095) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.2e+17) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); elseif (re <= 1.25e+65) tmp = Float64(0.5 * Float64(1.0 / Float64(sqrt(re) / im))); elseif (re <= 4.55e+111) 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 <= -0.095) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.2e+17) tmp = 0.5 * sqrt((2.0 * (im - re))); elseif (re <= 1.25e+65) tmp = 0.5 * (1.0 / (sqrt(re) / im)); elseif (re <= 4.55e+111) 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, -0.095], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.2e+17], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.25e+65], N[(0.5 * N[(1.0 / N[(N[Sqrt[re], $MachinePrecision] / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.55e+111], 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 -0.095:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{+17}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{elif}\;re \leq 1.25 \cdot 10^{+65}:\\
\;\;\;\;0.5 \cdot \frac{1}{\frac{\sqrt{re}}{im}}\\
\mathbf{elif}\;re \leq 4.55 \cdot 10^{+111}:\\
\;\;\;\;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 < -0.095000000000000001Initial program 39.6%
Taylor expanded in re around -inf 77.1%
*-commutative77.1%
Simplified77.1%
if -0.095000000000000001 < re < 4.2e17Initial program 55.2%
Taylor expanded in re around 0 84.0%
if 4.2e17 < re < 1.24999999999999993e65Initial program 23.4%
Taylor expanded in im around 0 71.0%
associate-*l*71.0%
associate-*l*71.3%
Simplified71.3%
associate-*r*71.0%
*-commutative71.0%
sqrt-unprod71.6%
metadata-eval71.6%
metadata-eval71.6%
*-un-lft-identity71.6%
add-log-exp11.3%
*-un-lft-identity11.3%
log-prod11.3%
metadata-eval11.3%
add-log-exp71.6%
inv-pow71.6%
sqrt-pow171.6%
metadata-eval71.6%
Applied egg-rr71.6%
+-lft-identity71.6%
Simplified71.6%
*-commutative71.6%
metadata-eval71.6%
pow-flip71.3%
pow1/271.3%
associate-/r/72.4%
Applied egg-rr72.4%
if 1.24999999999999993e65 < re < 4.55000000000000002e111Initial program 41.2%
Taylor expanded in re around 0 85.4%
*-commutative85.4%
Simplified85.4%
if 4.55000000000000002e111 < re Initial program 6.1%
Taylor expanded in im around 0 81.2%
associate-*l*81.3%
associate-*l*81.5%
Simplified81.5%
associate-*r*81.3%
*-commutative81.3%
sqrt-unprod82.3%
metadata-eval82.3%
metadata-eval82.3%
*-un-lft-identity82.3%
add-log-exp18.1%
*-un-lft-identity18.1%
log-prod18.1%
metadata-eval18.1%
add-log-exp82.3%
inv-pow82.3%
sqrt-pow182.4%
metadata-eval82.4%
Applied egg-rr82.4%
+-lft-identity82.4%
Simplified82.4%
Final simplification81.6%
(FPCore (re im)
:precision binary64
(if (<= re -0.0215)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 4.55e+111)
(* 0.5 (sqrt (* im 2.0)))
(* 0.5 (* im (pow re -0.5))))))
double code(double re, double im) {
double tmp;
if (re <= -0.0215) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.55e+111) {
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 <= (-0.0215d0)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.55d+111) 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 <= -0.0215) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.55e+111) {
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 <= -0.0215: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.55e+111: 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 <= -0.0215) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.55e+111) 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 <= -0.0215) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.55e+111) 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, -0.0215], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.55e+111], 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 -0.0215:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.55 \cdot 10^{+111}:\\
\;\;\;\;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 < -0.021499999999999998Initial program 39.6%
Taylor expanded in re around -inf 77.1%
*-commutative77.1%
Simplified77.1%
if -0.021499999999999998 < re < 4.55000000000000002e111Initial program 51.9%
Taylor expanded in re around 0 80.2%
*-commutative80.2%
Simplified80.2%
if 4.55000000000000002e111 < re Initial program 6.1%
Taylor expanded in im around 0 81.2%
associate-*l*81.3%
associate-*l*81.5%
Simplified81.5%
associate-*r*81.3%
*-commutative81.3%
sqrt-unprod82.3%
metadata-eval82.3%
metadata-eval82.3%
*-un-lft-identity82.3%
add-log-exp18.1%
*-un-lft-identity18.1%
log-prod18.1%
metadata-eval18.1%
add-log-exp82.3%
inv-pow82.3%
sqrt-pow182.4%
metadata-eval82.4%
Applied egg-rr82.4%
+-lft-identity82.4%
Simplified82.4%
Final simplification79.8%
(FPCore (re im) :precision binary64 (if (<= re -4.8e-7) (* 0.5 (sqrt (* re -4.0))) (if (<= re 4.55e+111) (* 0.5 (sqrt (* im 2.0))) (* 0.5 (/ im (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -4.8e-7) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 4.55e+111) {
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 <= (-4.8d-7)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 4.55d+111) 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 <= -4.8e-7) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 4.55e+111) {
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 <= -4.8e-7: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 4.55e+111: 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 <= -4.8e-7) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 4.55e+111) 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 <= -4.8e-7) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 4.55e+111) 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, -4.8e-7], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.55e+111], 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 -4.8 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 4.55 \cdot 10^{+111}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -4.79999999999999957e-7Initial program 39.6%
Taylor expanded in re around -inf 77.1%
*-commutative77.1%
Simplified77.1%
if -4.79999999999999957e-7 < re < 4.55000000000000002e111Initial program 51.9%
Taylor expanded in re around 0 80.2%
*-commutative80.2%
Simplified80.2%
if 4.55000000000000002e111 < re Initial program 6.1%
Taylor expanded in im around 0 81.2%
associate-*l*81.3%
associate-*l*81.5%
Simplified81.5%
add-log-exp21.5%
*-un-lft-identity21.5%
log-prod21.5%
metadata-eval21.5%
add-log-exp81.5%
associate-*r*81.3%
*-commutative81.3%
sqrt-unprod82.3%
metadata-eval82.3%
metadata-eval82.3%
*-un-lft-identity82.3%
sqrt-div82.1%
metadata-eval82.1%
un-div-inv82.3%
Applied egg-rr82.3%
+-lft-identity82.3%
Simplified82.3%
Final simplification79.8%
(FPCore (re im) :precision binary64 (if (<= re -0.0072) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* im 2.0)))))
double code(double re, double im) {
double tmp;
if (re <= -0.0072) {
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 <= (-0.0072d0)) 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 <= -0.0072) {
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 <= -0.0072: 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 <= -0.0072) 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 <= -0.0072) 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, -0.0072], 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 -0.0072:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im \cdot 2}\\
\end{array}
\end{array}
if re < -0.0071999999999999998Initial program 39.6%
Taylor expanded in re around -inf 77.1%
*-commutative77.1%
Simplified77.1%
if -0.0071999999999999998 < re Initial program 42.0%
Taylor expanded in re around 0 67.6%
*-commutative67.6%
Simplified67.6%
Final simplification70.0%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* im 2.0))))
double code(double re, double im) {
return 0.5 * sqrt((im * 2.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((im * 2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((im * 2.0));
}
def code(re, im): return 0.5 * math.sqrt((im * 2.0))
function code(re, im) return Float64(0.5 * sqrt(Float64(im * 2.0))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((im * 2.0)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(im * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{im \cdot 2}
\end{array}
Initial program 41.4%
Taylor expanded in re around 0 57.6%
*-commutative57.6%
Simplified57.6%
Final simplification57.6%
herbie shell --seed 2024019
(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)))))