
(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 8 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 -9e-192)
(/ (- c) b)
(if (<= b 120000000.0)
(/ (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-192) {
tmp = -c / b;
} else if (b <= 120000000.0) {
tmp = (-b - sqrt(((b * b) - (c * (a * 4.0))))) / (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 <= (-9d-192)) then
tmp = -c / b
else if (b <= 120000000.0d0) then
tmp = (-b - sqrt(((b * b) - (c * (a * 4.0d0))))) / (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 <= -9e-192) {
tmp = -c / b;
} else if (b <= 120000000.0) {
tmp = (-b - Math.sqrt(((b * b) - (c * (a * 4.0))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-192: tmp = -c / b elif b <= 120000000.0: tmp = (-b - math.sqrt(((b * b) - (c * (a * 4.0))))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-192) tmp = Float64(Float64(-c) / b); elseif (b <= 120000000.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0))))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-192) tmp = -c / b; elseif (b <= 120000000.0) tmp = (-b - sqrt(((b * b) - (c * (a * 4.0))))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-192], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 120000000.0], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $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 -9 \cdot 10^{-192}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 120000000:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -9.00000000000000048e-192Initial program 21.3%
Taylor expanded in b around -inf 87.7%
mul-1-neg87.7%
distribute-neg-frac87.7%
Simplified87.7%
if -9.00000000000000048e-192 < b < 1.2e8Initial program 90.9%
Taylor expanded in a around 0 90.9%
*-commutative90.9%
associate-*r*90.9%
Simplified90.9%
if 1.2e8 < b Initial program 86.9%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-192)
(/ (- c) b)
(if (<= b 120000000.0)
(/ (- (- 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 <= -9e-192) {
tmp = -c / b;
} else if (b <= 120000000.0) {
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 <= (-9d-192)) then
tmp = -c / b
else if (b <= 120000000.0d0) 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 <= -9e-192) {
tmp = -c / b;
} else if (b <= 120000000.0) {
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 <= -9e-192: tmp = -c / b elif b <= 120000000.0: 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 <= -9e-192) tmp = Float64(Float64(-c) / b); elseif (b <= 120000000.0) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -9e-192) tmp = -c / b; elseif (b <= 120000000.0) 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, -9e-192], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 120000000.0], 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 -9 \cdot 10^{-192}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 120000000:\\
\;\;\;\;\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 < -9.00000000000000048e-192Initial program 21.3%
Taylor expanded in b around -inf 87.7%
mul-1-neg87.7%
distribute-neg-frac87.7%
Simplified87.7%
if -9.00000000000000048e-192 < b < 1.2e8Initial program 90.9%
if 1.2e8 < b Initial program 86.9%
Taylor expanded in b around inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification91.7%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-192)
(/ (- c) b)
(if (<= b 1.55e-108)
(/ 0.5 (/ a (- b (sqrt (- (* b b) (* c (* a 4.0)))))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-192) {
tmp = -c / b;
} else if (b <= 1.55e-108) {
tmp = 0.5 / (a / (b - sqrt(((b * b) - (c * (a * 4.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 <= (-9d-192)) then
tmp = -c / b
else if (b <= 1.55d-108) then
tmp = 0.5d0 / (a / (b - sqrt(((b * b) - (c * (a * 4.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 <= -9e-192) {
tmp = -c / b;
} else if (b <= 1.55e-108) {
tmp = 0.5 / (a / (b - Math.sqrt(((b * b) - (c * (a * 4.0))))));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-192: tmp = -c / b elif b <= 1.55e-108: tmp = 0.5 / (a / (b - math.sqrt(((b * b) - (c * (a * 4.0)))))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-192) tmp = Float64(Float64(-c) / b); elseif (b <= 1.55e-108) tmp = Float64(0.5 / Float64(a / Float64(b - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.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 <= -9e-192) tmp = -c / b; elseif (b <= 1.55e-108) tmp = 0.5 / (a / (b - sqrt(((b * b) - (c * (a * 4.0)))))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-192], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.55e-108], N[(0.5 / N[(a / N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-192}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-108}:\\
\;\;\;\;\frac{0.5}{\frac{a}{b - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.00000000000000048e-192Initial program 21.3%
Taylor expanded in b around -inf 87.7%
mul-1-neg87.7%
distribute-neg-frac87.7%
Simplified87.7%
if -9.00000000000000048e-192 < b < 1.55000000000000007e-108Initial program 83.8%
add-sqr-sqrt5.7%
sqrt-unprod9.0%
*-commutative9.0%
*-commutative9.0%
swap-sqr9.0%
metadata-eval9.0%
metadata-eval9.0%
swap-sqr9.0%
associate-*r*9.0%
associate-*r*9.0%
sqrt-unprod7.9%
add-sqr-sqrt7.9%
add-cube-cbrt7.9%
pow37.9%
Applied egg-rr83.6%
associate-*r*83.5%
cbrt-prod83.3%
Applied egg-rr83.3%
clear-num83.2%
inv-pow83.2%
Applied egg-rr83.8%
unpow-183.7%
*-commutative83.7%
*-un-lft-identity83.7%
times-frac83.7%
metadata-eval83.7%
add-sqr-sqrt24.1%
sqrt-unprod76.0%
sqr-neg76.0%
sqrt-prod51.8%
add-sqr-sqrt76.1%
associate-*l*76.2%
Applied egg-rr76.2%
associate-/r*76.2%
metadata-eval76.2%
Simplified76.2%
if 1.55000000000000007e-108 < b Initial program 91.5%
Taylor expanded in b around inf 88.6%
mul-1-neg88.6%
unsub-neg88.6%
Simplified88.6%
Final simplification86.1%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-192)
(/ (- c) b)
(if (<= b 1.7e-109)
(/ (/ (- b (sqrt (- (* b b) (* c (* a 4.0))))) a) 2.0)
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-192) {
tmp = -c / b;
} else if (b <= 1.7e-109) {
tmp = ((b - sqrt(((b * b) - (c * (a * 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 <= (-9d-192)) then
tmp = -c / b
else if (b <= 1.7d-109) then
tmp = ((b - sqrt(((b * b) - (c * (a * 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 <= -9e-192) {
tmp = -c / b;
} else if (b <= 1.7e-109) {
tmp = ((b - Math.sqrt(((b * b) - (c * (a * 4.0))))) / a) / 2.0;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -9e-192: tmp = -c / b elif b <= 1.7e-109: tmp = ((b - math.sqrt(((b * b) - (c * (a * 4.0))))) / a) / 2.0 else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -9e-192) tmp = Float64(Float64(-c) / b); elseif (b <= 1.7e-109) tmp = Float64(Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0))))) / 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 <= -9e-192) tmp = -c / b; elseif (b <= 1.7e-109) tmp = ((b - sqrt(((b * b) - (c * (a * 4.0))))) / a) / 2.0; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -9e-192], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1.7e-109], N[(N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9 \cdot 10^{-192}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-109}:\\
\;\;\;\;\frac{\frac{b - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.00000000000000048e-192Initial program 21.3%
Taylor expanded in b around -inf 87.7%
mul-1-neg87.7%
distribute-neg-frac87.7%
Simplified87.7%
if -9.00000000000000048e-192 < b < 1.70000000000000006e-109Initial program 83.8%
add-sqr-sqrt5.7%
sqrt-unprod9.0%
*-commutative9.0%
*-commutative9.0%
swap-sqr9.0%
metadata-eval9.0%
metadata-eval9.0%
swap-sqr9.0%
associate-*r*9.0%
associate-*r*9.0%
sqrt-unprod7.9%
add-sqr-sqrt7.9%
add-cube-cbrt7.9%
pow37.9%
Applied egg-rr83.6%
associate-*r*83.5%
cbrt-prod83.3%
Applied egg-rr83.3%
clear-num83.2%
inv-pow83.2%
Applied egg-rr83.8%
unpow-183.7%
clear-num83.8%
associate-/r*83.8%
add-sqr-sqrt24.2%
sqrt-unprod76.1%
sqr-neg76.1%
sqrt-prod51.8%
add-sqr-sqrt76.2%
associate-*l*76.3%
Applied egg-rr76.3%
if 1.70000000000000006e-109 < b Initial program 91.5%
Taylor expanded in b around inf 88.6%
mul-1-neg88.6%
unsub-neg88.6%
Simplified88.6%
Final simplification86.1%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (/ (+ (* 2.0 (/ (* c a) b)) (* b -2.0)) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0);
}
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 = -c / b
else
tmp = ((2.0d0 * ((c * a) / b)) + (b * (-2.0d0))) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} else {
tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(Float64(2.0 * Float64(Float64(c * a) / b)) + Float64(b * -2.0)) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -c / b; else tmp = ((2.0 * ((c * a) / b)) + (b * -2.0)) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], N[(N[(N[(2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{c \cdot a}{b} + b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 27.3%
Taylor expanded in b around -inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
if -3.999999999999988e-310 < b Initial program 90.6%
Taylor expanded in b around inf 72.2%
Final simplification75.8%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = -c / b;
} 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 <= (-4d-310)) then
tmp = -c / b
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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-c) / b); 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 <= -4e-310) tmp = -c / b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 27.3%
Taylor expanded in b around -inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
if -3.999999999999988e-310 < b Initial program 90.6%
Taylor expanded in b around inf 72.2%
mul-1-neg72.2%
unsub-neg72.2%
Simplified72.2%
Final simplification75.8%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
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 <= (-4d-310)) 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 <= -4e-310) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(Float64(-c) / b); else tmp = Float64(-Float64(b / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4e-310) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 27.3%
Taylor expanded in b around -inf 79.5%
mul-1-neg79.5%
distribute-neg-frac79.5%
Simplified79.5%
if -3.999999999999988e-310 < b Initial program 90.6%
Taylor expanded in b around inf 72.0%
associate-*r/72.0%
mul-1-neg72.0%
Simplified72.0%
Final simplification75.8%
(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(-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 58.9%
Taylor expanded in b around inf 37.1%
associate-*r/37.1%
mul-1-neg37.1%
Simplified37.1%
Final simplification37.1%
(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 2023278
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))