
(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 -1.3e-67)
(* -1.0 (/ c b))
(if (<= b 4.2e+76)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a))
(+ (* -1.0 (/ b a)) (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-67) {
tmp = -1.0 * (c / b);
} else if (b <= 4.2e+76) {
tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
} else {
tmp = (-1.0 * (b / a)) + (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.3d-67)) then
tmp = (-1.0d0) * (c / b)
else if (b <= 4.2d+76) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
else
tmp = ((-1.0d0) * (b / a)) + (c / b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.3e-67) {
tmp = -1.0 * (c / b);
} else if (b <= 4.2e+76) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
} else {
tmp = (-1.0 * (b / a)) + (c / b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.3e-67: tmp = -1.0 * (c / b) elif b <= 4.2e+76: tmp = (-b - math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a) else: tmp = (-1.0 * (b / a)) + (c / b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.3e-67) tmp = Float64(-1.0 * Float64(c / b)); elseif (b <= 4.2e+76) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)); else tmp = Float64(Float64(-1.0 * Float64(b / a)) + Float64(c / b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.3e-67) tmp = -1.0 * (c / b); elseif (b <= 4.2e+76) tmp = (-b - sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); else tmp = (-1.0 * (b / a)) + (c / b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.3e-67], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.2e+76], 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], N[(N[(-1.0 * N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.3 \cdot 10^{-67}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{+76}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \frac{b}{a} + \frac{c}{b}\\
\end{array}
\end{array}
if b < -1.2999999999999999e-67Initial program 16.7%
div-sub14.2%
sub-neg14.2%
neg-mul-114.2%
*-commutative14.2%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*14.2%
distribute-rgt-out16.7%
associate-/r*16.7%
metadata-eval16.7%
sub-neg16.7%
+-commutative16.7%
Simplified16.7%
Taylor expanded in b around -inf 88.1%
if -1.2999999999999999e-67 < b < 4.20000000000000013e76Initial program 78.8%
if 4.20000000000000013e76 < b Initial program 45.7%
div-sub45.7%
sub-neg45.7%
neg-mul-145.7%
*-commutative45.7%
associate-/l*45.7%
distribute-neg-frac45.7%
neg-mul-145.7%
*-commutative45.7%
associate-/l*45.7%
distribute-rgt-out45.7%
associate-/r*45.7%
metadata-eval45.7%
sub-neg45.7%
+-commutative45.7%
Simplified45.9%
Taylor expanded in c around 0 96.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e-68)
(* -1.0 (/ c b))
(if (<= b 2.2e-33)
(/ (- (- b) (sqrt (* -4.0 (* a c)))) (* a 2.0))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.05e-68) {
tmp = -1.0 * (c / b);
} else if (b <= 2.2e-33) {
tmp = (-b - sqrt((-4.0 * (a * c)))) / (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 <= (-1.05d-68)) then
tmp = (-1.0d0) * (c / b)
else if (b <= 2.2d-33) then
tmp = (-b - sqrt(((-4.0d0) * (a * c)))) / (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 <= -1.05e-68) {
tmp = -1.0 * (c / b);
} else if (b <= 2.2e-33) {
tmp = (-b - Math.sqrt((-4.0 * (a * c)))) / (a * 2.0);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.05e-68: tmp = -1.0 * (c / b) elif b <= 2.2e-33: tmp = (-b - math.sqrt((-4.0 * (a * c)))) / (a * 2.0) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.05e-68) tmp = Float64(-1.0 * Float64(c / b)); elseif (b <= 2.2e-33) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(-4.0 * Float64(a * c)))) / 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 <= -1.05e-68) tmp = -1.0 * (c / b); elseif (b <= 2.2e-33) tmp = (-b - sqrt((-4.0 * (a * c)))) / (a * 2.0); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.05e-68], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.2e-33], N[(N[((-b) - N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.05 \cdot 10^{-68}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-33}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{-4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -1.05000000000000004e-68Initial program 16.7%
div-sub14.2%
sub-neg14.2%
neg-mul-114.2%
*-commutative14.2%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*14.2%
distribute-rgt-out16.7%
associate-/r*16.7%
metadata-eval16.7%
sub-neg16.7%
+-commutative16.7%
Simplified16.7%
Taylor expanded in b around -inf 88.1%
if -1.05000000000000004e-68 < b < 2.20000000000000005e-33Initial program 74.0%
*-commutative74.0%
*-commutative74.0%
sqr-neg74.0%
*-commutative74.0%
sqr-neg74.0%
*-commutative74.0%
associate-*r*74.0%
Simplified74.0%
Taylor expanded in b around 0 72.8%
if 2.20000000000000005e-33 < b Initial program 62.6%
div-sub62.6%
sub-neg62.6%
neg-mul-162.6%
*-commutative62.6%
associate-/l*62.6%
distribute-neg-frac62.6%
neg-mul-162.6%
*-commutative62.6%
associate-/l*62.5%
distribute-rgt-out62.5%
associate-/r*62.5%
metadata-eval62.5%
sub-neg62.5%
+-commutative62.5%
Simplified62.6%
Taylor expanded in a around 0 89.5%
mul-1-neg89.5%
distribute-neg-frac289.5%
Applied egg-rr89.5%
(FPCore (a b c)
:precision binary64
(if (<= b -7.6e-68)
(* -1.0 (/ c b))
(if (<= b 3.45e-41)
(* (+ b (sqrt (* -4.0 (* a c)))) (/ -0.5 a))
(/ b (- a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-68) {
tmp = -1.0 * (c / b);
} else if (b <= 3.45e-41) {
tmp = (b + sqrt((-4.0 * (a * c)))) * (-0.5 / a);
} 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 <= (-7.6d-68)) then
tmp = (-1.0d0) * (c / b)
else if (b <= 3.45d-41) then
tmp = (b + sqrt(((-4.0d0) * (a * c)))) * ((-0.5d0) / a)
else
tmp = b / -a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.6e-68) {
tmp = -1.0 * (c / b);
} else if (b <= 3.45e-41) {
tmp = (b + Math.sqrt((-4.0 * (a * c)))) * (-0.5 / a);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.6e-68: tmp = -1.0 * (c / b) elif b <= 3.45e-41: tmp = (b + math.sqrt((-4.0 * (a * c)))) * (-0.5 / a) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.6e-68) tmp = Float64(-1.0 * Float64(c / b)); elseif (b <= 3.45e-41) tmp = Float64(Float64(b + sqrt(Float64(-4.0 * Float64(a * c)))) * Float64(-0.5 / a)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.6e-68) tmp = -1.0 * (c / b); elseif (b <= 3.45e-41) tmp = (b + sqrt((-4.0 * (a * c)))) * (-0.5 / a); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.6e-68], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.45e-41], N[(N[(b + N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.6 \cdot 10^{-68}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{elif}\;b \leq 3.45 \cdot 10^{-41}:\\
\;\;\;\;\left(b + \sqrt{-4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -7.60000000000000075e-68Initial program 16.7%
div-sub14.2%
sub-neg14.2%
neg-mul-114.2%
*-commutative14.2%
associate-/l*13.1%
distribute-neg-frac13.1%
neg-mul-113.1%
*-commutative13.1%
associate-/l*14.2%
distribute-rgt-out16.7%
associate-/r*16.7%
metadata-eval16.7%
sub-neg16.7%
+-commutative16.7%
Simplified16.7%
Taylor expanded in b around -inf 88.1%
if -7.60000000000000075e-68 < b < 3.4499999999999999e-41Initial program 74.0%
*-commutative74.0%
*-commutative74.0%
sqr-neg74.0%
*-commutative74.0%
sqr-neg74.0%
*-commutative74.0%
associate-*r*74.0%
Simplified74.0%
Taylor expanded in b around 0 72.8%
frac-2neg72.8%
div-inv72.6%
Applied egg-rr72.6%
if 3.4499999999999999e-41 < b Initial program 62.6%
div-sub62.6%
sub-neg62.6%
neg-mul-162.6%
*-commutative62.6%
associate-/l*62.6%
distribute-neg-frac62.6%
neg-mul-162.6%
*-commutative62.6%
associate-/l*62.5%
distribute-rgt-out62.5%
associate-/r*62.5%
metadata-eval62.5%
sub-neg62.5%
+-commutative62.5%
Simplified62.6%
Taylor expanded in a around 0 89.5%
mul-1-neg89.5%
distribute-neg-frac289.5%
Applied egg-rr89.5%
(FPCore (a b c) :precision binary64 (if (<= b -8.4e-290) (* -1.0 (/ c b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.4e-290) {
tmp = -1.0 * (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 <= (-8.4d-290)) then
tmp = (-1.0d0) * (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 <= -8.4e-290) {
tmp = -1.0 * (c / b);
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.4e-290: tmp = -1.0 * (c / b) else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.4e-290) tmp = Float64(-1.0 * 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 <= -8.4e-290) tmp = -1.0 * (c / b); else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.4e-290], N[(-1.0 * N[(c / b), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.4 \cdot 10^{-290}:\\
\;\;\;\;-1 \cdot \frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -8.4000000000000005e-290Initial program 27.8%
div-sub25.8%
sub-neg25.8%
neg-mul-125.8%
*-commutative25.8%
associate-/l*24.9%
distribute-neg-frac24.9%
neg-mul-124.9%
*-commutative24.9%
associate-/l*25.7%
distribute-rgt-out27.7%
associate-/r*27.7%
metadata-eval27.7%
sub-neg27.7%
+-commutative27.7%
Simplified27.7%
Taylor expanded in b around -inf 72.4%
if -8.4000000000000005e-290 < b Initial program 67.2%
div-sub67.2%
sub-neg67.2%
neg-mul-167.2%
*-commutative67.2%
associate-/l*67.2%
distribute-neg-frac67.2%
neg-mul-167.2%
*-commutative67.2%
associate-/l*67.0%
distribute-rgt-out67.0%
associate-/r*67.0%
metadata-eval67.0%
sub-neg67.0%
+-commutative67.0%
Simplified67.1%
Taylor expanded in a around 0 61.2%
mul-1-neg61.2%
distribute-neg-frac261.2%
Applied egg-rr61.2%
(FPCore (a b c) :precision binary64 (if (<= b -0.0018) (/ c b) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -0.0018) {
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 <= (-0.0018d0)) 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 <= -0.0018) {
tmp = c / b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -0.0018: tmp = c / b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -0.0018) tmp = 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 <= -0.0018) tmp = c / b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -0.0018], N[(c / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -0.0018:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -0.0018Initial program 13.7%
div-sub10.8%
sub-neg10.8%
neg-mul-110.8%
*-commutative10.8%
associate-/l*9.5%
distribute-neg-frac9.5%
neg-mul-19.5%
*-commutative9.5%
associate-/l*10.8%
distribute-rgt-out13.7%
associate-/r*13.7%
metadata-eval13.7%
sub-neg13.7%
+-commutative13.7%
Simplified13.7%
Taylor expanded in c around 0 2.3%
Taylor expanded in b around 0 28.2%
if -0.0018 < b Initial program 64.6%
div-sub64.6%
sub-neg64.6%
neg-mul-164.6%
*-commutative64.6%
associate-/l*64.6%
distribute-neg-frac64.6%
neg-mul-164.6%
*-commutative64.6%
associate-/l*64.5%
distribute-rgt-out64.5%
associate-/r*64.5%
metadata-eval64.5%
sub-neg64.5%
+-commutative64.5%
Simplified64.5%
Taylor expanded in a around 0 46.1%
mul-1-neg46.1%
distribute-neg-frac246.1%
Applied egg-rr46.1%
(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 46.5%
div-sub45.5%
sub-neg45.5%
neg-mul-145.5%
*-commutative45.5%
associate-/l*45.0%
distribute-neg-frac45.0%
neg-mul-145.0%
*-commutative45.0%
associate-/l*45.4%
distribute-rgt-out46.4%
associate-/r*46.4%
metadata-eval46.4%
sub-neg46.4%
+-commutative46.4%
Simplified46.5%
Taylor expanded in c around 0 30.3%
Taylor expanded in b around 0 12.1%
(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 46.5%
div-sub45.5%
sub-neg45.5%
neg-mul-145.5%
*-commutative45.5%
associate-/l*45.0%
distribute-neg-frac45.0%
neg-mul-145.0%
*-commutative45.0%
associate-/l*45.4%
distribute-rgt-out46.4%
associate-/r*46.4%
metadata-eval46.4%
sub-neg46.4%
+-commutative46.4%
Simplified46.5%
Taylor expanded in a around 0 30.6%
add-sqr-sqrt14.9%
sqrt-unprod10.5%
mul-1-neg10.5%
mul-1-neg10.5%
sqr-neg10.5%
sqrt-unprod1.6%
add-sqr-sqrt2.7%
Applied egg-rr2.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 2024116 -o generate:simplify
(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)))