
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
(FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* (pow (* re re) -0.25) (* im 0.5)) (* 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 = pow((re * re), -0.25) * (im * 0.5);
} 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 = Math.pow((re * re), -0.25) * (im * 0.5);
} 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 = math.pow((re * re), -0.25) * (im * 0.5) 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((Float64(re * re) ^ -0.25) * Float64(im * 0.5)); 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 = ((re * re) ^ -0.25) * (im * 0.5); 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[(N[Power[N[(re * re), $MachinePrecision], -0.25], $MachinePrecision] * N[(im * 0.5), $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:\\
\;\;\;\;{\left(re \cdot re\right)}^{-0.25} \cdot \left(im \cdot 0.5\right)\\
\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 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 12.6%
Taylor expanded in re around inf
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
unpow2N/A
*-lowering-*.f6452.2%
Simplified52.2%
Taylor expanded in im around 0
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6499.7%
Simplified99.7%
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-lowering-*.f6499.7%
Applied egg-rr99.7%
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
pow-lowering-pow.f64N/A
*-lowering-*.f6499.7%
Applied egg-rr99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 46.8%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6488.3%
Simplified88.3%
Final simplification90.0%
(FPCore (re im)
:precision binary64
(if (<= re -2.1e-23)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.15e+49)
(* 0.5 (sqrt (* 2.0 (- (+ im (* (* re re) (/ 0.5 im))) re))))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -2.1e-23) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.15e+49) {
tmp = 0.5 * sqrt((2.0 * ((im + ((re * re) * (0.5 / im))) - re)));
} else {
tmp = (im * 0.5) * 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 <= (-2.1d-23)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.15d+49) then
tmp = 0.5d0 * sqrt((2.0d0 * ((im + ((re * re) * (0.5d0 / im))) - re)))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.1e-23) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.15e+49) {
tmp = 0.5 * Math.sqrt((2.0 * ((im + ((re * re) * (0.5 / im))) - re)));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.1e-23: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.15e+49: tmp = 0.5 * math.sqrt((2.0 * ((im + ((re * re) * (0.5 / im))) - re))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.1e-23) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.15e+49) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(Float64(im + Float64(Float64(re * re) * Float64(0.5 / im))) - re)))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.1e-23) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.15e+49) tmp = 0.5 * sqrt((2.0 * ((im + ((re * re) * (0.5 / im))) - re))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.1e-23], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.15e+49], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[(im + N[(N[(re * re), $MachinePrecision] * N[(0.5 / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.1 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.15 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(im + \left(re \cdot re\right) \cdot \frac{0.5}{im}\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -2.1000000000000001e-23Initial program 53.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.5%
Simplified75.5%
if -2.1000000000000001e-23 < re < 1.15000000000000001e49Initial program 49.3%
Taylor expanded in re around 0
associate-*r/N/A
*-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
+-lowering-+.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
metadata-evalN/A
/-lowering-/.f6479.8%
Simplified79.8%
if 1.15000000000000001e49 < re Initial program 9.4%
Taylor expanded in re around inf
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
unpow2N/A
*-lowering-*.f6448.0%
Simplified48.0%
Taylor expanded in im around 0
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6483.1%
Simplified83.1%
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-lowering-*.f6483.1%
Applied egg-rr83.1%
Final simplification79.4%
(FPCore (re im)
:precision binary64
(if (<= re -4.9e-23)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 3.9e+49)
(* 0.5 (sqrt (+ (* 2.0 im) (* re (+ -2.0 (/ re im))))))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -4.9e-23) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 3.9e+49) {
tmp = 0.5 * sqrt(((2.0 * im) + (re * (-2.0 + (re / im)))));
} else {
tmp = (im * 0.5) * 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 <= (-4.9d-23)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 3.9d+49) then
tmp = 0.5d0 * sqrt(((2.0d0 * im) + (re * ((-2.0d0) + (re / im)))))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.9e-23) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 3.9e+49) {
tmp = 0.5 * Math.sqrt(((2.0 * im) + (re * (-2.0 + (re / im)))));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.9e-23: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 3.9e+49: tmp = 0.5 * math.sqrt(((2.0 * im) + (re * (-2.0 + (re / im))))) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.9e-23) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 3.9e+49) tmp = Float64(0.5 * sqrt(Float64(Float64(2.0 * im) + Float64(re * Float64(-2.0 + Float64(re / im)))))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.9e-23) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 3.9e+49) tmp = 0.5 * sqrt(((2.0 * im) + (re * (-2.0 + (re / im))))); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.9e-23], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.9e+49], N[(0.5 * N[Sqrt[N[(N[(2.0 * im), $MachinePrecision] + N[(re * N[(-2.0 + N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.9 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 3.9 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im + re \cdot \left(-2 + \frac{re}{im}\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -4.8999999999999998e-23Initial program 53.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.5%
Simplified75.5%
if -4.8999999999999998e-23 < re < 3.9000000000000001e49Initial program 49.3%
Taylor expanded in re around 0
+-lowering-+.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f6479.8%
Simplified79.8%
if 3.9000000000000001e49 < re Initial program 9.4%
Taylor expanded in re around inf
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
unpow2N/A
*-lowering-*.f6448.0%
Simplified48.0%
Taylor expanded in im around 0
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6483.1%
Simplified83.1%
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-lowering-*.f6483.1%
Applied egg-rr83.1%
Final simplification79.4%
(FPCore (re im)
:precision binary64
(if (<= re -4.8e-23)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.5e+49)
(* 0.5 (sqrt (* 2.0 im)))
(* (* im 0.5) (pow re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -4.8e-23) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.5e+49) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = (im * 0.5) * 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 <= (-4.8d-23)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.5d+49) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = (im * 0.5d0) * (re ** (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -4.8e-23) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.5e+49) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = (im * 0.5) * Math.pow(re, -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4.8e-23: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.5e+49: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = (im * 0.5) * math.pow(re, -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -4.8e-23) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.5e+49) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(Float64(im * 0.5) * (re ^ -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -4.8e-23) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.5e+49) tmp = 0.5 * sqrt((2.0 * im)); else tmp = (im * 0.5) * (re ^ -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4.8e-23], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.5e+49], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] * N[Power[re, -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.8 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.5 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot 0.5\right) \cdot {re}^{-0.5}\\
\end{array}
\end{array}
if re < -4.79999999999999993e-23Initial program 53.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.5%
Simplified75.5%
if -4.79999999999999993e-23 < re < 1.5000000000000001e49Initial program 49.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6479.2%
Simplified79.2%
if 1.5000000000000001e49 < re Initial program 9.4%
Taylor expanded in re around inf
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
unpow2N/A
*-lowering-*.f6448.0%
Simplified48.0%
Taylor expanded in im around 0
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6483.1%
Simplified83.1%
*-commutativeN/A
*-lowering-*.f64N/A
pow1/2N/A
inv-powN/A
pow-powN/A
pow-lowering-pow.f64N/A
metadata-evalN/A
*-lowering-*.f6483.1%
Applied egg-rr83.1%
Final simplification79.1%
(FPCore (re im) :precision binary64 (if (<= re -1.8e-26) (* 0.5 (sqrt (* re -4.0))) (if (<= re 1.75e+49) (* 0.5 (sqrt (* 2.0 im))) (/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e-26) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.75e+49) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.8d-26)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.75d+49) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e-26) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.75e+49) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e-26: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.75e+49: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e-26) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.75e+49) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e-26) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.75e+49) tmp = 0.5 * sqrt((2.0 * im)); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e-26], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.75e+49], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{-26}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.75 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.8000000000000001e-26Initial program 53.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.5%
Simplified75.5%
if -1.8000000000000001e-26 < re < 1.74999999999999987e49Initial program 49.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6479.2%
Simplified79.2%
if 1.74999999999999987e49 < re Initial program 9.4%
Taylor expanded in re around inf
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
unpow2N/A
*-lowering-*.f6448.0%
Simplified48.0%
*-commutativeN/A
sqrt-divN/A
associate-*l/N/A
/-lowering-/.f64N/A
Applied egg-rr64.4%
Taylor expanded in im around 0
Simplified82.9%
Final simplification79.0%
(FPCore (re im) :precision binary64 (if (<= re -8.5e-27) (* 0.5 (sqrt (* re -4.0))) (if (<= re 1.7e+49) (* 0.5 (sqrt (* 2.0 im))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -8.5e-27) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.7e+49) {
tmp = 0.5 * sqrt((2.0 * im));
} else {
tmp = im * (0.5 / sqrt(re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-8.5d-27)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.7d+49) then
tmp = 0.5d0 * sqrt((2.0d0 * im))
else
tmp = im * (0.5d0 / sqrt(re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -8.5e-27) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.7e+49) {
tmp = 0.5 * Math.sqrt((2.0 * im));
} else {
tmp = im * (0.5 / Math.sqrt(re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -8.5e-27: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.7e+49: tmp = 0.5 * math.sqrt((2.0 * im)) else: tmp = im * (0.5 / math.sqrt(re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -8.5e-27) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.7e+49) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(im * Float64(0.5 / sqrt(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -8.5e-27) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.7e+49) tmp = 0.5 * sqrt((2.0 * im)); else tmp = im * (0.5 / sqrt(re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -8.5e-27], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.7e+49], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -8.5 \cdot 10^{-27}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.7 \cdot 10^{+49}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -8.50000000000000033e-27Initial program 53.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.5%
Simplified75.5%
if -8.50000000000000033e-27 < re < 1.7e49Initial program 49.3%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6479.2%
Simplified79.2%
if 1.7e49 < re Initial program 9.4%
Taylor expanded in re around inf
/-lowering-/.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
unpow2N/A
*-lowering-*.f6448.0%
Simplified48.0%
Taylor expanded in im around 0
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
/-lowering-/.f6483.1%
Simplified83.1%
*-commutativeN/A
associate-*l*N/A
sqrt-divN/A
metadata-evalN/A
div-invN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6482.8%
Applied egg-rr82.8%
Final simplification79.0%
(FPCore (re im) :precision binary64 (if (<= re -1.35e-26) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -1.35e-26) {
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 <= (-1.35d-26)) 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 <= -1.35e-26) {
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 <= -1.35e-26: 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 <= -1.35e-26) 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 <= -1.35e-26) 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, -1.35e-26], 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 -1.35 \cdot 10^{-26}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -1.34999999999999991e-26Initial program 53.6%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6475.5%
Simplified75.5%
if -1.34999999999999991e-26 < re Initial program 37.8%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6462.9%
Simplified62.9%
Final simplification66.2%
(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
*-commutativeN/A
*-lowering-*.f6453.8%
Simplified53.8%
Final simplification53.8%
herbie shell --seed 2024144
(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)))))