
(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 (<= re 3.7e-37) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (/ (* 0.5 im) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= 3.7e-37) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = (0.5 * im) / sqrt(re);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 3.7e-37) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = (0.5 * im) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 3.7e-37: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = (0.5 * im) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 3.7e-37) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); else tmp = Float64(Float64(0.5 * im) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 3.7e-37) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = (0.5 * im) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 3.7e-37], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.7 \cdot 10^{-37}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 3.7e-37Initial program 50.7%
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
*-lowering-*.f64N/A
--lowering--.f64N/A
hypot-defineN/A
hypot-lowering-hypot.f6497.0%
Simplified97.0%
if 3.7e-37 < re Initial program 11.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6440.4%
Simplified40.4%
sqrt-divN/A
associate-*r/N/A
pow1/2N/A
unpow-prod-downN/A
/-lowering-/.f64N/A
pow-prod-upN/A
metadata-evalN/A
unpow1N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6476.2%
Applied egg-rr76.2%
(FPCore (re im)
:precision binary64
(if (<= re -1.75e-31)
(* 0.5 (sqrt (- (/ re -0.25) (/ im (/ re im)))))
(if (<= re 7.8e-26)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* 0.5 im) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.75e-31) {
tmp = 0.5 * sqrt(((re / -0.25) - (im / (re / im))));
} else if (re <= 7.8e-26) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} 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 <= (-1.75d-31)) then
tmp = 0.5d0 * sqrt(((re / (-0.25d0)) - (im / (re / im))))
else if (re <= 7.8d-26) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
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 <= -1.75e-31) {
tmp = 0.5 * Math.sqrt(((re / -0.25) - (im / (re / im))));
} else if (re <= 7.8e-26) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (0.5 * im) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.75e-31: tmp = 0.5 * math.sqrt(((re / -0.25) - (im / (re / im)))) elif re <= 7.8e-26: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (0.5 * im) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.75e-31) tmp = Float64(0.5 * sqrt(Float64(Float64(re / -0.25) - Float64(im / Float64(re / im))))); elseif (re <= 7.8e-26) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(0.5 * im) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.75e-31) tmp = 0.5 * sqrt(((re / -0.25) - (im / (re / im)))); elseif (re <= 7.8e-26) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (0.5 * im) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.75e-31], N[(0.5 * N[Sqrt[N[(N[(re / -0.25), $MachinePrecision] - N[(im / N[(re / im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.8e-26], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.75 \cdot 10^{-31}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{re}{-0.25} - \frac{im}{\frac{re}{im}}}\\
\mathbf{elif}\;re \leq 7.8 \cdot 10^{-26}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.74999999999999993e-31Initial program 42.3%
Taylor expanded in re around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
neg-sub0N/A
--lowering--.f6474.5%
Simplified74.5%
Taylor expanded in im around 0
*-commutativeN/A
metadata-evalN/A
distribute-rgt-out--N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
distribute-rgt-out--N/A
metadata-evalN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6475.1%
Simplified75.1%
*-commutativeN/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f64N/A
metadata-evalN/A
div-invN/A
--lowering--.f64N/A
/-lowering-/.f64N/A
associate-*l/N/A
associate-/r/N/A
/-lowering-/.f64N/A
/-lowering-/.f6481.8%
Applied egg-rr81.8%
if -1.74999999999999993e-31 < re < 7.79999999999999973e-26Initial program 55.9%
Taylor expanded in re around 0
Simplified87.8%
if 7.79999999999999973e-26 < re Initial program 11.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6440.4%
Simplified40.4%
sqrt-divN/A
associate-*r/N/A
pow1/2N/A
unpow-prod-downN/A
/-lowering-/.f64N/A
pow-prod-upN/A
metadata-evalN/A
unpow1N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6476.2%
Applied egg-rr76.2%
Final simplification83.2%
(FPCore (re im)
:precision binary64
(if (<= re -1.65e-31)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 1.3e-35)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* 0.5 im) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.65e-31) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 1.3e-35) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} 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 <= (-1.65d-31)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 1.3d-35) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
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 <= -1.65e-31) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 1.3e-35) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (0.5 * im) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.65e-31: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 1.3e-35: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (0.5 * im) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.65e-31) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 1.3e-35) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(0.5 * im) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.65e-31) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 1.3e-35) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (0.5 * im) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.65e-31], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.3e-35], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.65 \cdot 10^{-31}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-35}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.65e-31Initial program 42.3%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6481.7%
Simplified81.7%
if -1.65e-31 < re < 1.30000000000000002e-35Initial program 55.9%
Taylor expanded in re around 0
Simplified87.8%
if 1.30000000000000002e-35 < re Initial program 11.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6440.4%
Simplified40.4%
sqrt-divN/A
associate-*r/N/A
pow1/2N/A
unpow-prod-downN/A
/-lowering-/.f64N/A
pow-prod-upN/A
metadata-evalN/A
unpow1N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6476.2%
Applied egg-rr76.2%
(FPCore (re im) :precision binary64 (if (<= re -3e-84) (* 0.5 (sqrt (* re -4.0))) (if (<= re 5.5e-40) (* 0.5 (sqrt (* 2.0 im))) (/ (* 0.5 im) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -3e-84) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 5.5e-40) {
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 <= (-3d-84)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 5.5d-40) 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 <= -3e-84) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 5.5e-40) {
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 <= -3e-84: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 5.5e-40: 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 <= -3e-84) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 5.5e-40) tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); else tmp = Float64(Float64(0.5 * im) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3e-84) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 5.5e-40) 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, -3e-84], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.5e-40], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 5.5 \cdot 10^{-40}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot im}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.0000000000000001e-84Initial program 45.4%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6479.6%
Simplified79.6%
if -3.0000000000000001e-84 < re < 5.50000000000000002e-40Initial program 54.4%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6488.4%
Simplified88.4%
if 5.50000000000000002e-40 < re Initial program 11.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6440.4%
Simplified40.4%
sqrt-divN/A
associate-*r/N/A
pow1/2N/A
unpow-prod-downN/A
/-lowering-/.f64N/A
pow-prod-upN/A
metadata-evalN/A
unpow1N/A
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6476.2%
Applied egg-rr76.2%
Final simplification82.6%
(FPCore (re im) :precision binary64 (if (<= re -1.65e-84) (* 0.5 (sqrt (* re -4.0))) (if (<= re 2.7e-37) (* 0.5 (sqrt (* 2.0 im))) (* im (/ 0.5 (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -1.65e-84) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 2.7e-37) {
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.65d-84)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 2.7d-37) 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.65e-84) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 2.7e-37) {
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.65e-84: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 2.7e-37: 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.65e-84) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 2.7e-37) 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 <= -1.65e-84) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 2.7e-37) 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.65e-84], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.7e-37], 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 -1.65 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 2.7 \cdot 10^{-37}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\mathbf{else}:\\
\;\;\;\;im \cdot \frac{0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.64999999999999992e-84Initial program 45.4%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6479.6%
Simplified79.6%
if -1.64999999999999992e-84 < re < 2.70000000000000016e-37Initial program 54.4%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6488.4%
Simplified88.4%
if 2.70000000000000016e-37 < re Initial program 11.2%
Taylor expanded in re around inf
/-lowering-/.f64N/A
unpow2N/A
*-lowering-*.f6440.4%
Simplified40.4%
*-commutativeN/A
sqrt-divN/A
sqrt-prodN/A
rem-square-sqrtN/A
associate-*l/N/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
sqrt-lowering-sqrt.f6476.0%
Applied egg-rr76.0%
Final simplification82.6%
(FPCore (re im) :precision binary64 (if (<= re -4.8e-84) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -4.8e-84) {
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.8d-84)) 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.8e-84) {
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.8e-84: 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.8e-84) 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.8e-84) 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.8e-84], 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.8 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -4.80000000000000035e-84Initial program 45.4%
Taylor expanded in re around -inf
*-commutativeN/A
*-lowering-*.f6479.6%
Simplified79.6%
if -4.80000000000000035e-84 < re Initial program 38.7%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6466.8%
Simplified66.8%
Final simplification70.8%
(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 40.8%
Taylor expanded in re around 0
*-commutativeN/A
*-lowering-*.f6454.2%
Simplified54.2%
Final simplification54.2%
herbie shell --seed 2024164
(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)))))