
(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 7 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 -3.5e-72)
(/ (- c) b)
(if (<= b 1.55e+125)
(/ (- (- b) (sqrt (fma b b (* c (* -4.0 a))))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-72) {
tmp = -c / b;
} else if (b <= 1.55e+125) {
tmp = (-b - sqrt(fma(b, b, (c * (-4.0 * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -3.5e-72) tmp = Float64(Float64(-c) / b); elseif (b <= 1.55e+125) tmp = Float64(Float64(Float64(-b) - sqrt(fma(b, b, Float64(c * Float64(-4.0 * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -3.5e-72], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.55e+125], N[(N[((-b) - N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{-72}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{+125}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.5e-72Initial program 16.0%
div-sub13.2%
sub-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*13.3%
distribute-rgt-out16.0%
associate-/r*16.0%
metadata-eval16.0%
sub-neg16.0%
+-commutative16.0%
Simplified16.0%
Taylor expanded in b around -inf 88.6%
associate-*r/88.6%
neg-mul-188.6%
Simplified88.6%
if -3.5e-72 < b < 1.55e125Initial program 83.8%
*-commutative83.8%
fma-neg83.8%
*-commutative83.8%
associate-*r*83.8%
distribute-lft-neg-in83.8%
*-commutative83.8%
distribute-rgt-neg-in83.8%
associate-*r*83.8%
metadata-eval83.8%
Simplified83.8%
if 1.55e125 < b Initial program 55.5%
div-sub55.5%
sub-neg55.5%
neg-mul-155.5%
*-commutative55.5%
associate-/l*55.5%
distribute-neg-frac55.5%
neg-mul-155.5%
*-commutative55.5%
associate-/l*55.4%
distribute-rgt-out55.4%
associate-/r*55.4%
metadata-eval55.4%
sub-neg55.4%
+-commutative55.4%
Simplified55.7%
Taylor expanded in a around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(if (<= b -2.15e-72)
(/ (- c) b)
(if (<= b 1e+125)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.15e-72) {
tmp = -c / b;
} else if (b <= 1e+125) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
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 <= (-2.15d-72)) then
tmp = -c / b
else if (b <= 1d+125) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (a * 2.0d0)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.15e-72) {
tmp = -c / b;
} else if (b <= 1e+125) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.15e-72: tmp = -c / b elif b <= 1e+125: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.15e-72) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+125) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.15e-72) tmp = -c / b; elseif (b <= 1e+125) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.15e-72], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+125], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.15 \cdot 10^{-72}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+125}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -2.1499999999999999e-72Initial program 16.0%
div-sub13.2%
sub-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*13.3%
distribute-rgt-out16.0%
associate-/r*16.0%
metadata-eval16.0%
sub-neg16.0%
+-commutative16.0%
Simplified16.0%
Taylor expanded in b around -inf 88.6%
associate-*r/88.6%
neg-mul-188.6%
Simplified88.6%
if -2.1499999999999999e-72 < b < 9.9999999999999992e124Initial program 83.8%
if 9.9999999999999992e124 < b Initial program 55.5%
div-sub55.5%
sub-neg55.5%
neg-mul-155.5%
*-commutative55.5%
associate-/l*55.5%
distribute-neg-frac55.5%
neg-mul-155.5%
*-commutative55.5%
associate-/l*55.4%
distribute-rgt-out55.4%
associate-/r*55.4%
metadata-eval55.4%
sub-neg55.4%
+-commutative55.4%
Simplified55.7%
Taylor expanded in a around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e-69)
(/ (- c) b)
(if (<= b 4.9e-93)
(/ (+ b (sqrt (* a (* c -4.0)))) (* a -2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-69) {
tmp = -c / b;
} else if (b <= 4.9e-93) {
tmp = (b + sqrt((a * (c * -4.0)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
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.05d-69)) then
tmp = -c / b
else if (b <= 4.9d-93) then
tmp = (b + sqrt((a * (c * (-4.0d0))))) / (a * (-2.0d0))
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-69) {
tmp = -c / b;
} else if (b <= 4.9e-93) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) / (a * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.05e-69: tmp = -c / b elif b <= 4.9e-93: tmp = (b + math.sqrt((a * (c * -4.0)))) / (a * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.05e-69) tmp = Float64(Float64(-c) / b); elseif (b <= 4.9e-93) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) / Float64(a * -2.0)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.05e-69) tmp = -c / b; elseif (b <= 4.9e-93) tmp = (b + sqrt((a * (c * -4.0)))) / (a * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.05e-69], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 4.9e-93], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{-69}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 4.9 \cdot 10^{-93}:\\
\;\;\;\;\frac{b + \sqrt{a \cdot \left(c \cdot -4\right)}}{a \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -1.05e-69Initial program 16.0%
div-sub13.2%
sub-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*13.3%
distribute-rgt-out16.0%
associate-/r*16.0%
metadata-eval16.0%
sub-neg16.0%
+-commutative16.0%
Simplified16.0%
Taylor expanded in b around -inf 88.6%
associate-*r/88.6%
neg-mul-188.6%
Simplified88.6%
if -1.05e-69 < b < 4.89999999999999965e-93Initial program 76.7%
remove-double-neg76.7%
distribute-rgt-neg-out76.7%
neg-mul-176.7%
associate-/r*76.7%
Simplified76.7%
Taylor expanded in a around inf 73.2%
*-commutative73.2%
associate-*r*73.2%
Simplified73.2%
if 4.89999999999999965e-93 < b Initial program 71.7%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.7%
distribute-neg-frac71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.7%
Taylor expanded in c around 0 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e-69)
(/ (- c) b)
(if (<= b 9.2e-85)
(* (+ b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-69) {
tmp = -c / b;
} else if (b <= 9.2e-85) {
tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = (c / b) - (b / a);
}
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 <= (-2.8d-69)) then
tmp = -c / b
else if (b <= 9.2d-85) then
tmp = (b + sqrt((a * (c * (-4.0d0))))) * ((-0.5d0) / a)
else
tmp = (c / b) - (b / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e-69) {
tmp = -c / b;
} else if (b <= 9.2e-85) {
tmp = (b + Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e-69: tmp = -c / b elif b <= 9.2e-85: tmp = (b + math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e-69) tmp = Float64(Float64(-c) / b); elseif (b <= 9.2e-85) tmp = Float64(Float64(b + sqrt(Float64(a * Float64(c * -4.0)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(c / b) - Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.8e-69) tmp = -c / b; elseif (b <= 9.2e-85) tmp = (b + sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e-69], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 9.2e-85], N[(N[(b + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{-69}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 9.2 \cdot 10^{-85}:\\
\;\;\;\;\left(b + \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -2.79999999999999979e-69Initial program 16.0%
div-sub13.2%
sub-neg13.2%
neg-mul-113.2%
*-commutative13.2%
associate-/l*12.8%
distribute-neg-frac12.8%
neg-mul-112.8%
*-commutative12.8%
associate-/l*13.3%
distribute-rgt-out16.0%
associate-/r*16.0%
metadata-eval16.0%
sub-neg16.0%
+-commutative16.0%
Simplified16.0%
Taylor expanded in b around -inf 88.6%
associate-*r/88.6%
neg-mul-188.6%
Simplified88.6%
if -2.79999999999999979e-69 < b < 9.2000000000000001e-85Initial program 76.7%
div-sub76.8%
sub-neg76.8%
neg-mul-176.8%
*-commutative76.8%
associate-/l*76.7%
distribute-neg-frac76.7%
neg-mul-176.7%
*-commutative76.7%
associate-/l*76.5%
distribute-rgt-out76.6%
associate-/r*76.6%
metadata-eval76.6%
sub-neg76.6%
+-commutative76.6%
Simplified76.6%
Taylor expanded in a around inf 73.0%
*-commutative73.2%
associate-*r*73.2%
Simplified73.0%
if 9.2000000000000001e-85 < b Initial program 71.7%
div-sub71.7%
sub-neg71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.7%
distribute-neg-frac71.7%
neg-mul-171.7%
*-commutative71.7%
associate-/l*71.6%
distribute-rgt-out71.6%
associate-/r*71.6%
metadata-eval71.6%
sub-neg71.6%
+-commutative71.6%
Simplified71.7%
Taylor expanded in c around 0 91.6%
+-commutative91.6%
mul-1-neg91.6%
unsub-neg91.6%
Simplified91.6%
Final simplification86.0%
(FPCore (a b c) :precision binary64 (if (<= b -1.1e-308) (/ (- c) b) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-308) {
tmp = -c / b;
} else {
tmp = b / -a;
}
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.1d-308)) then
tmp = -c / b
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.1e-308) {
tmp = -c / b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.1e-308: tmp = -c / b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.1e-308) tmp = Float64(Float64(-c) / b); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.1e-308) tmp = -c / b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.1e-308], N[((-c) / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1 \cdot 10^{-308}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.1000000000000001e-308Initial program 34.4%
div-sub32.5%
sub-neg32.5%
neg-mul-132.5%
*-commutative32.5%
associate-/l*32.2%
distribute-neg-frac32.2%
neg-mul-132.2%
*-commutative32.2%
associate-/l*32.4%
distribute-rgt-out34.4%
associate-/r*34.4%
metadata-eval34.4%
sub-neg34.4%
+-commutative34.4%
Simplified34.3%
Taylor expanded in b around -inf 65.5%
associate-*r/65.5%
neg-mul-165.5%
Simplified65.5%
if -1.1000000000000001e-308 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.4%
distribute-rgt-out72.4%
associate-/r*72.4%
metadata-eval72.4%
sub-neg72.4%
+-commutative72.4%
Simplified72.6%
Taylor expanded in a around 0 75.1%
associate-*r/75.1%
mul-1-neg75.1%
Simplified75.1%
Final simplification70.6%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) 0.0 (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = 0.0;
} else {
tmp = b / -a;
}
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 <= (-4d-310)) then
tmp = 0.0d0
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = 0.0;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = 0.0 else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = 0.0; else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = 0.0; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], 0.0, N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 34.4%
remove-double-neg34.4%
distribute-rgt-neg-out34.4%
neg-mul-134.4%
associate-/r*34.4%
Simplified34.4%
Taylor expanded in b around -inf 19.9%
mul-1-neg19.9%
Simplified19.9%
Taylor expanded in b around 0 19.9%
if -3.999999999999988e-310 < b Initial program 72.6%
div-sub72.6%
sub-neg72.6%
neg-mul-172.6%
*-commutative72.6%
associate-/l*72.5%
distribute-neg-frac72.5%
neg-mul-172.5%
*-commutative72.5%
associate-/l*72.4%
distribute-rgt-out72.4%
associate-/r*72.4%
metadata-eval72.4%
sub-neg72.4%
+-commutative72.4%
Simplified72.6%
Taylor expanded in a around 0 75.1%
associate-*r/75.1%
mul-1-neg75.1%
Simplified75.1%
Final simplification49.2%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = 0.0d0
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 54.7%
remove-double-neg54.7%
distribute-rgt-neg-out54.7%
neg-mul-154.7%
associate-/r*54.7%
Simplified54.7%
Taylor expanded in b around -inf 10.7%
mul-1-neg10.7%
Simplified10.7%
Taylor expanded in b around 0 10.7%
(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) (/ c (- t_2 (/ b 2.0))) (/ (+ (/ b 2.0) t_2) (- a)))))
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 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
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 = c / (t_2 - (b / 2.0));
} else {
tmp_1 = ((b / 2.0) + t_2) / -a;
}
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 = c / (t_2 - (b / 2.0)) else: tmp_1 = ((b / 2.0) + t_2) / -a 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(c / Float64(t_2 - Float64(b / 2.0))); else tmp_1 = Float64(Float64(Float64(b / 2.0) + t_2) / Float64(-a)); 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 = c / (t_2 - (b / 2.0)); else tmp_2 = ((b / 2.0) + t_2) / -a; 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[(c / N[(t$95$2 - N[(b / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b / 2.0), $MachinePrecision] + t$95$2), $MachinePrecision] / (-a)), $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{c}{t\_2 - \frac{b}{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b}{2} + t\_2}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024145
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs (/ b 2)) x)) (sqrt (+ (fabs (/ b 2)) x))) (hypot (/ b 2) x))))) (if (< b 0) (/ c (- sqtD (/ b 2))) (/ (+ (/ b 2) sqtD) (- a)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))