
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -1.7e+89)
(- (/ c b) (/ b a))
(if (<= b -5e-133)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(if (<= b 5.8e-147)
(/ (- (pow (* (cbrt (* c -4.0)) (cbrt a)) 1.5) b) (* a 2.0))
(/ c (- b))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.7e+89) {
tmp = (c / b) - (b / a);
} else if (b <= -5e-133) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 5.8e-147) {
tmp = (pow((cbrt((c * -4.0)) * cbrt(a)), 1.5) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.7e+89) {
tmp = (c / b) - (b / a);
} else if (b <= -5e-133) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else if (b <= 5.8e-147) {
tmp = (Math.pow((Math.cbrt((c * -4.0)) * Math.cbrt(a)), 1.5) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.7e+89) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -5e-133) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); elseif (b <= 5.8e-147) tmp = Float64(Float64((Float64(cbrt(Float64(c * -4.0)) * cbrt(a)) ^ 1.5) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.7e+89], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -5e-133], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-147], N[(N[(N[Power[N[(N[Power[N[(c * -4.0), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.7 \cdot 10^{+89}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -5 \cdot 10^{-133}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-147}:\\
\;\;\;\;\frac{{\left(\sqrt[3]{c \cdot -4} \cdot \sqrt[3]{a}\right)}^{1.5} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.7000000000000001e89Initial program 52.7%
*-commutative52.7%
Simplified52.7%
Taylor expanded in b around -inf 96.9%
mul-1-neg96.9%
*-commutative96.9%
distribute-rgt-neg-in96.9%
+-commutative96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
Taylor expanded in a around inf 97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
if -1.7000000000000001e89 < b < -4.9999999999999999e-133Initial program 95.1%
if -4.9999999999999999e-133 < b < 5.8000000000000002e-147Initial program 68.4%
*-commutative68.4%
Simplified68.4%
cancel-sign-sub-inv68.4%
metadata-eval68.4%
associate-*r*68.4%
*-commutative68.4%
fma-undefine68.4%
add-cube-cbrt67.8%
pow367.7%
associate-*r*67.7%
*-commutative67.7%
Applied egg-rr67.7%
sqrt-pow167.6%
metadata-eval67.6%
Applied egg-rr67.6%
Taylor expanded in b around 0 67.6%
*-commutative67.6%
associate-*r*67.6%
Simplified67.6%
*-commutative67.6%
cbrt-prod95.9%
Applied egg-rr95.9%
if 5.8000000000000002e-147 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Taylor expanded in b around inf 83.1%
associate-*r/83.1%
neg-mul-183.1%
Simplified83.1%
Final simplification91.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e+89)
(- (/ c b) (/ b a))
(if (<= b 5.8e-147)
(/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e+89) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-147) {
tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.85d+89)) then
tmp = (c / b) - (b / a)
else if (b <= 5.8d-147) then
tmp = (sqrt(((b * b) - (4.0d0 * (c * a)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.85e+89) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-147) {
tmp = (Math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.85e+89: tmp = (c / b) - (b / a) elif b <= 5.8e-147: tmp = (math.sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.85e+89) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.8e-147) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.85e+89) tmp = (c / b) - (b / a); elseif (b <= 5.8e-147) tmp = (sqrt(((b * b) - (4.0 * (c * a)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.85e+89], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-147], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.85 \cdot 10^{+89}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-147}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.8499999999999999e89Initial program 52.7%
*-commutative52.7%
Simplified52.7%
Taylor expanded in b around -inf 96.9%
mul-1-neg96.9%
*-commutative96.9%
distribute-rgt-neg-in96.9%
+-commutative96.9%
mul-1-neg96.9%
unsub-neg96.9%
Simplified96.9%
Taylor expanded in a around inf 97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
if -1.8499999999999999e89 < b < 5.8000000000000002e-147Initial program 81.0%
if 5.8000000000000002e-147 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Taylor expanded in b around inf 83.1%
associate-*r/83.1%
neg-mul-183.1%
Simplified83.1%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e-82)
(- (/ c b) (/ b a))
(if (<= b 5.8e-147)
(* 0.5 (/ (- (sqrt (* a (* c -4.0))) b) a))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e-82) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-147) {
tmp = 0.5 * ((sqrt((a * (c * -4.0))) - b) / a);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.5d-82)) then
tmp = (c / b) - (b / a)
else if (b <= 5.8d-147) then
tmp = 0.5d0 * ((sqrt((a * (c * (-4.0d0)))) - b) / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e-82) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-147) {
tmp = 0.5 * ((Math.sqrt((a * (c * -4.0))) - b) / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.5e-82: tmp = (c / b) - (b / a) elif b <= 5.8e-147: tmp = 0.5 * ((math.sqrt((a * (c * -4.0))) - b) / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.5e-82) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.8e-147) tmp = Float64(0.5 * Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.5e-82) tmp = (c / b) - (b / a); elseif (b <= 5.8e-147) tmp = 0.5 * ((sqrt((a * (c * -4.0))) - b) / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.5e-82], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-147], N[(0.5 * N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{-82}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-147}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.4999999999999999e-82Initial program 65.7%
*-commutative65.7%
Simplified65.7%
Taylor expanded in b around -inf 90.7%
mul-1-neg90.7%
*-commutative90.7%
distribute-rgt-neg-in90.7%
+-commutative90.7%
mul-1-neg90.7%
unsub-neg90.7%
Simplified90.7%
Taylor expanded in a around inf 90.9%
+-commutative90.9%
mul-1-neg90.9%
unsub-neg90.9%
Simplified90.9%
if -1.4999999999999999e-82 < b < 5.8000000000000002e-147Initial program 74.0%
*-commutative74.0%
Simplified74.0%
cancel-sign-sub-inv74.0%
metadata-eval74.0%
associate-*r*74.0%
*-commutative74.0%
fma-undefine74.0%
add-cube-cbrt73.3%
pow373.2%
associate-*r*73.2%
*-commutative73.2%
Applied egg-rr73.2%
sqrt-pow173.2%
metadata-eval73.2%
Applied egg-rr73.2%
Taylor expanded in b around 0 70.3%
*-commutative70.3%
associate-*r*70.3%
Simplified70.3%
Taylor expanded in a around 0 70.6%
rem-cube-cbrt71.1%
Simplified71.1%
if 5.8000000000000002e-147 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Taylor expanded in b around inf 83.1%
associate-*r/83.1%
neg-mul-183.1%
Simplified83.1%
Final simplification83.5%
(FPCore (a b c) :precision binary64 (if (<= b -5.5e-93) (- (/ c b) (/ b a)) (if (<= b 1.15e-154) (* 0.5 (sqrt (* c (/ -4.0 a)))) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-154) {
tmp = 0.5 * sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5.5d-93)) then
tmp = (c / b) - (b / a)
else if (b <= 1.15d-154) then
tmp = 0.5d0 * sqrt((c * ((-4.0d0) / a)))
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5.5e-93) {
tmp = (c / b) - (b / a);
} else if (b <= 1.15e-154) {
tmp = 0.5 * Math.sqrt((c * (-4.0 / a)));
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5.5e-93: tmp = (c / b) - (b / a) elif b <= 1.15e-154: tmp = 0.5 * math.sqrt((c * (-4.0 / a))) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5.5e-93) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.15e-154) tmp = Float64(0.5 * sqrt(Float64(c * Float64(-4.0 / a)))); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5.5e-93) tmp = (c / b) - (b / a); elseif (b <= 1.15e-154) tmp = 0.5 * sqrt((c * (-4.0 / a))); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5.5e-93], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.15e-154], N[(0.5 * N[Sqrt[N[(c * N[(-4.0 / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5.5 \cdot 10^{-93}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-154}:\\
\;\;\;\;0.5 \cdot \sqrt{c \cdot \frac{-4}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.49999999999999968e-93Initial program 66.4%
*-commutative66.4%
Simplified66.4%
Taylor expanded in b around -inf 89.0%
mul-1-neg89.0%
*-commutative89.0%
distribute-rgt-neg-in89.0%
+-commutative89.0%
mul-1-neg89.0%
unsub-neg89.0%
Simplified89.0%
Taylor expanded in a around inf 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
if -5.49999999999999968e-93 < b < 1.15e-154Initial program 73.1%
*-commutative73.1%
Simplified73.1%
cancel-sign-sub-inv73.1%
metadata-eval73.1%
associate-*r*73.1%
*-commutative73.1%
fma-undefine73.1%
add-cube-cbrt72.3%
pow372.3%
associate-*r*72.3%
*-commutative72.3%
Applied egg-rr72.3%
sqrt-pow172.2%
metadata-eval72.2%
Applied egg-rr72.2%
Taylor expanded in b around 0 69.2%
*-commutative69.2%
associate-*r*69.2%
Simplified69.2%
Taylor expanded in b around 0 41.5%
rem-cube-cbrt41.9%
associate-/l*41.9%
Simplified41.9%
if 1.15e-154 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Taylor expanded in b around inf 83.1%
associate-*r/83.1%
neg-mul-183.1%
Simplified83.1%
Final simplification76.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-312) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-312) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-312)) then
tmp = (c / b) - (b / a)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-312) {
tmp = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-312: tmp = (c / b) - (b / a) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-312) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-312) tmp = (c / b) - (b / a); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-312], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-312}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -5.0000000000022e-312Initial program 69.5%
*-commutative69.5%
Simplified69.5%
Taylor expanded in b around -inf 71.3%
mul-1-neg71.3%
*-commutative71.3%
distribute-rgt-neg-in71.3%
+-commutative71.3%
mul-1-neg71.3%
unsub-neg71.3%
Simplified71.3%
Taylor expanded in a around inf 71.7%
+-commutative71.7%
mul-1-neg71.7%
unsub-neg71.7%
Simplified71.7%
if -5.0000000000022e-312 < b Initial program 28.9%
*-commutative28.9%
Simplified28.9%
Taylor expanded in b around inf 68.5%
associate-*r/68.5%
neg-mul-168.5%
Simplified68.5%
Final simplification70.1%
(FPCore (a b c) :precision binary64 (if (<= b 1.9e-252) (/ (- b) a) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.9e-252) {
tmp = -b / a;
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 1.9d-252) then
tmp = -b / a
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.9e-252) {
tmp = -b / a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.9e-252: tmp = -b / a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.9e-252) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.9e-252) tmp = -b / a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.9e-252], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{-252}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 1.9e-252Initial program 69.8%
*-commutative69.8%
Simplified69.8%
Taylor expanded in b around -inf 66.1%
associate-*r/66.1%
mul-1-neg66.1%
Simplified66.1%
if 1.9e-252 < b Initial program 24.8%
*-commutative24.8%
Simplified24.8%
Taylor expanded in b around inf 74.5%
associate-*r/74.5%
neg-mul-174.5%
Simplified74.5%
Final simplification70.0%
(FPCore (a b c) :precision binary64 (if (<= b 14000000.0) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 14000000.0) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 14000000.0d0) then
tmp = -b / a
else
tmp = c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 14000000.0) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 14000000.0: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 14000000.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 14000000.0) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 14000000.0], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 14000000:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 1.4e7Initial program 65.1%
*-commutative65.1%
Simplified65.1%
Taylor expanded in b around -inf 53.2%
associate-*r/53.2%
mul-1-neg53.2%
Simplified53.2%
if 1.4e7 < b Initial program 14.9%
*-commutative14.9%
Simplified14.9%
Taylor expanded in b around -inf 2.7%
mul-1-neg2.7%
*-commutative2.7%
distribute-rgt-neg-in2.7%
+-commutative2.7%
mul-1-neg2.7%
unsub-neg2.7%
Simplified2.7%
Taylor expanded in a around inf 23.4%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 49.2%
*-commutative49.2%
Simplified49.2%
Taylor expanded in b around -inf 36.8%
mul-1-neg36.8%
*-commutative36.8%
distribute-rgt-neg-in36.8%
+-commutative36.8%
mul-1-neg36.8%
unsub-neg36.8%
Simplified36.8%
Taylor expanded in a around inf 9.3%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 49.2%
*-commutative49.2%
+-commutative49.2%
unsub-neg49.2%
fma-neg49.3%
*-commutative49.3%
associate-*r*49.3%
distribute-lft-neg-in49.3%
*-commutative49.3%
distribute-rgt-neg-in49.3%
associate-*r*49.3%
metadata-eval49.3%
Simplified49.3%
sub-neg49.3%
fma-undefine49.2%
add-sqr-sqrt37.5%
hypot-define45.2%
associate-*r*45.2%
*-commutative45.2%
add-sqr-sqrt29.8%
sqrt-unprod36.2%
sqr-neg36.2%
sqrt-prod11.5%
add-sqr-sqrt22.8%
Applied egg-rr22.8%
Taylor expanded in b around inf 2.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fabs (/ b 2.0)))
(t_1 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_2
(if (== (copysign a c) a)
(* (sqrt (- t_0 t_1)) (sqrt (+ t_0 t_1)))
(hypot (/ b 2.0) t_1))))
(if (< b 0.0) (/ (- t_2 (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) t_2)))))
double code(double a, double b, double c) {
double t_0 = fabs((b / 2.0));
double t_1 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1));
} else {
tmp = hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
public static double code(double a, double b, double c) {
double t_0 = Math.abs((b / 2.0));
double t_1 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((t_0 - t_1)) * Math.sqrt((t_0 + t_1));
} else {
tmp = Math.hypot((b / 2.0), t_1);
}
double t_2 = tmp;
double tmp_1;
if (b < 0.0) {
tmp_1 = (t_2 - (b / 2.0)) / a;
} else {
tmp_1 = -c / ((b / 2.0) + t_2);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.fabs((b / 2.0)) t_1 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((t_0 - t_1)) * math.sqrt((t_0 + t_1)) else: tmp = math.hypot((b / 2.0), t_1) t_2 = tmp tmp_1 = 0 if b < 0.0: tmp_1 = (t_2 - (b / 2.0)) / a else: tmp_1 = -c / ((b / 2.0) + t_2) return tmp_1
function code(a, b, c) t_0 = abs(Float64(b / 2.0)) t_1 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(t_0 - t_1)) * sqrt(Float64(t_0 + t_1))); else tmp = hypot(Float64(b / 2.0), t_1); end t_2 = tmp tmp_1 = 0.0 if (b < 0.0) tmp_1 = Float64(Float64(t_2 - Float64(b / 2.0)) / a); else tmp_1 = Float64(Float64(-c) / Float64(Float64(b / 2.0) + t_2)); end return tmp_1 end
function tmp_3 = code(a, b, c) t_0 = abs((b / 2.0)); t_1 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((t_0 - t_1)) * sqrt((t_0 + t_1)); else tmp = hypot((b / 2.0), t_1); end t_2 = tmp; tmp_2 = 0.0; if (b < 0.0) tmp_2 = (t_2 - (b / 2.0)) / a; else tmp_2 = -c / ((b / 2.0) + t_2); end tmp_3 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Abs[N[(b / 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(t$95$0 - t$95$1), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(t$95$0 + t$95$1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(b / 2.0), $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]]}, If[Less[b, 0.0], N[(N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{b}{2}\right|\\
t_1 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_2 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{t\_0 - t\_1} \cdot \sqrt{t\_0 + t\_1}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(\frac{b}{2}, t\_1\right)\\
\end{array}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{t\_2 - \frac{b}{2}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{\frac{b}{2} + t\_2}\\
\end{array}
\end{array}
herbie shell --seed 2024086
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-expected 10
:alt
(if (< b 0.0) (/ (- (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))) (/ b 2.0)) a) (/ (- c) (+ (/ b 2.0) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs (/ b 2.0)) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot (/ b 2.0) (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))