
(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 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ c (* a (/ (+ (- b) t_0) (* 2.0 a))))
(/ (- (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * 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) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
if (b < 0.0d0) then
tmp = c / (a * ((-b + t_0) / (2.0d0 * a)))
else
tmp = (-b - t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (4.0 * (a * c))));
double tmp;
if (b < 0.0) {
tmp = c / (a * ((-b + t_0) / (2.0 * a)));
} else {
tmp = (-b - t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) tmp = 0 if b < 0.0: tmp = c / (a * ((-b + t_0) / (2.0 * a))) else: tmp = (-b - t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(c / Float64(a * Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)))); else tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); tmp = 0.0; if (b < 0.0) tmp = c / (a * ((-b + t_0) / (2.0 * a))); else tmp = (-b - t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(c / N[(a * N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + t\_0}{2 \cdot a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{2 \cdot a}\\
\end{array}
\end{array}
herbie shell --seed 2024145
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (sqrt (- (* b b) (* 4 (* a c)))))) (let ((r1 (/ (+ (- b) d) (* 2 a)))) (let ((r2 (/ (- (- b) d) (* 2 a)))) (if (< b 0) (/ c (* a r1)) r2)))))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))