
(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 -68000000.0)
(/ c (- b))
(if (<= b 0.195)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(*
(/ -0.5 a)
(+ b (* b (sqrt (fma -4.0 (* a (* c (pow b -2.0))) 1.0))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -68000000.0) {
tmp = c / -b;
} else if (b <= 0.195) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (-0.5 / a) * (b + (b * sqrt(fma(-4.0, (a * (c * pow(b, -2.0))), 1.0))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -68000000.0) tmp = Float64(c / Float64(-b)); elseif (b <= 0.195) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / Float64(a * 2.0)); else tmp = Float64(Float64(-0.5 / a) * Float64(b + Float64(b * sqrt(fma(-4.0, Float64(a * Float64(c * (b ^ -2.0))), 1.0))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -68000000.0], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 0.195], 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[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[(b * N[Sqrt[N[(-4.0 * N[(a * N[(c * N[Power[b, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -68000000:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 0.195:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + b \cdot \sqrt{\mathsf{fma}\left(-4, a \cdot \left(c \cdot {b}^{-2}\right), 1\right)}\right)\\
\end{array}
\end{array}
if b < -6.8e7Initial program 13.9%
div-sub12.1%
sub-neg12.1%
neg-mul-112.1%
*-commutative12.1%
associate-/l*10.7%
distribute-neg-frac10.7%
neg-mul-110.7%
*-commutative10.7%
associate-/l*12.1%
distribute-rgt-out13.9%
associate-/r*13.9%
metadata-eval13.9%
sub-neg13.9%
+-commutative13.9%
Simplified13.9%
Taylor expanded in b around -inf 91.1%
mul-1-neg91.1%
distribute-neg-frac291.1%
Simplified91.1%
if -6.8e7 < b < 0.19500000000000001Initial program 76.5%
if 0.19500000000000001 < b Initial program 65.7%
div-sub65.7%
sub-neg65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.7%
distribute-neg-frac65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.6%
distribute-rgt-out65.6%
associate-/r*65.6%
metadata-eval65.6%
sub-neg65.6%
+-commutative65.6%
Simplified65.8%
Taylor expanded in b around inf 65.6%
associate-/l*65.8%
Simplified65.8%
*-commutative65.8%
sqrt-prod70.7%
+-commutative70.7%
fma-define70.7%
div-inv70.7%
pow-flip70.7%
metadata-eval70.7%
sqrt-pow198.1%
metadata-eval98.1%
pow198.1%
Applied egg-rr98.1%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -75000000.0)
(/ c (- b))
(if (<= b 5.5e+97)
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* c a))))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -75000000.0) {
tmp = c / -b;
} else if (b <= 5.5e+97) {
tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (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 <= (-75000000.0d0)) then
tmp = c / -b
else if (b <= 5.5d+97) then
tmp = (-b - sqrt(((b * b) - (4.0d0 * (c * a))))) / (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 <= -75000000.0) {
tmp = c / -b;
} else if (b <= 5.5e+97) {
tmp = (-b - Math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -75000000.0: tmp = c / -b elif b <= 5.5e+97: tmp = (-b - math.sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -75000000.0) tmp = Float64(c / Float64(-b)); elseif (b <= 5.5e+97) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(c * a))))) / 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 <= -75000000.0) tmp = c / -b; elseif (b <= 5.5e+97) tmp = (-b - sqrt(((b * b) - (4.0 * (c * a))))) / (a * 2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -75000000.0], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 5.5e+97], 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[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -75000000:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{+97}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -7.5e7Initial program 13.9%
div-sub12.1%
sub-neg12.1%
neg-mul-112.1%
*-commutative12.1%
associate-/l*10.7%
distribute-neg-frac10.7%
neg-mul-110.7%
*-commutative10.7%
associate-/l*12.1%
distribute-rgt-out13.9%
associate-/r*13.9%
metadata-eval13.9%
sub-neg13.9%
+-commutative13.9%
Simplified13.9%
Taylor expanded in b around -inf 91.1%
mul-1-neg91.1%
distribute-neg-frac291.1%
Simplified91.1%
if -7.5e7 < b < 5.50000000000000021e97Initial program 77.5%
if 5.50000000000000021e97 < b Initial program 59.3%
div-sub59.3%
sub-neg59.3%
neg-mul-159.3%
*-commutative59.3%
associate-/l*59.1%
distribute-neg-frac59.1%
neg-mul-159.1%
*-commutative59.1%
associate-/l*59.1%
distribute-rgt-out59.1%
associate-/r*59.1%
metadata-eval59.1%
sub-neg59.1%
+-commutative59.1%
Simplified59.3%
Taylor expanded in c around 0 95.8%
+-commutative95.8%
mul-1-neg95.8%
unsub-neg95.8%
Simplified95.8%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e-40)
(/ c (- b))
(if (<= b 0.0024)
(* (/ -0.5 a) (+ b (sqrt (* (* c a) -4.0))))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e-40) {
tmp = c / -b;
} else if (b <= 0.0024) {
tmp = (-0.5 / a) * (b + sqrt(((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 <= (-3.5d-40)) then
tmp = c / -b
else if (b <= 0.0024d0) then
tmp = ((-0.5d0) / a) * (b + sqrt(((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 <= -3.5e-40) {
tmp = c / -b;
} else if (b <= 0.0024) {
tmp = (-0.5 / a) * (b + Math.sqrt(((c * a) * -4.0)));
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e-40: tmp = c / -b elif b <= 0.0024: tmp = (-0.5 / a) * (b + math.sqrt(((c * a) * -4.0))) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e-40) tmp = Float64(c / Float64(-b)); elseif (b <= 0.0024) tmp = Float64(Float64(-0.5 / a) * Float64(b + sqrt(Float64(Float64(c * 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 <= -3.5e-40) tmp = c / -b; elseif (b <= 0.0024) tmp = (-0.5 / a) * (b + sqrt(((c * a) * -4.0))); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e-40], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 0.0024], N[(N[(-0.5 / a), $MachinePrecision] * N[(b + N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{-40}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 0.0024:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b + \sqrt{\left(c \cdot a\right) \cdot -4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -3.5000000000000002e-40Initial program 19.0%
div-sub17.4%
sub-neg17.4%
neg-mul-117.4%
*-commutative17.4%
associate-/l*16.1%
distribute-neg-frac16.1%
neg-mul-116.1%
*-commutative16.1%
associate-/l*17.4%
distribute-rgt-out19.0%
associate-/r*19.0%
metadata-eval19.0%
sub-neg19.0%
+-commutative19.0%
Simplified19.1%
Taylor expanded in b around -inf 85.4%
mul-1-neg85.4%
distribute-neg-frac285.4%
Simplified85.4%
if -3.5000000000000002e-40 < b < 0.00239999999999999979Initial program 78.1%
div-sub78.1%
sub-neg78.1%
neg-mul-178.1%
*-commutative78.1%
associate-/l*78.1%
distribute-neg-frac78.1%
neg-mul-178.1%
*-commutative78.1%
associate-/l*77.9%
distribute-rgt-out77.9%
associate-/r*77.9%
metadata-eval77.9%
sub-neg77.9%
+-commutative77.9%
Simplified77.9%
Taylor expanded in a around inf 68.4%
*-commutative68.4%
Simplified68.4%
if 0.00239999999999999979 < b Initial program 65.7%
div-sub65.7%
sub-neg65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.7%
distribute-neg-frac65.7%
neg-mul-165.7%
*-commutative65.7%
associate-/l*65.6%
distribute-rgt-out65.6%
associate-/r*65.6%
metadata-eval65.6%
sub-neg65.6%
+-commutative65.6%
Simplified65.8%
Taylor expanded in c around 0 90.4%
+-commutative90.4%
mul-1-neg90.4%
unsub-neg90.4%
Simplified90.4%
Final simplification79.2%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(c / Float64(-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 <= -5e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-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 -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 38.9%
div-sub37.9%
sub-neg37.9%
neg-mul-137.9%
*-commutative37.9%
associate-/l*37.1%
distribute-neg-frac37.1%
neg-mul-137.1%
*-commutative37.1%
associate-/l*37.8%
distribute-rgt-out38.8%
associate-/r*38.8%
metadata-eval38.8%
sub-neg38.8%
+-commutative38.8%
Simplified38.9%
Taylor expanded in b around -inf 60.7%
mul-1-neg60.7%
distribute-neg-frac260.7%
Simplified60.7%
if -4.999999999999985e-310 < b Initial program 74.3%
div-sub74.3%
sub-neg74.3%
neg-mul-174.3%
*-commutative74.3%
associate-/l*74.2%
distribute-neg-frac74.2%
neg-mul-174.2%
*-commutative74.2%
associate-/l*74.1%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.2%
Taylor expanded in c around 0 56.6%
+-commutative56.6%
mul-1-neg56.6%
unsub-neg56.6%
Simplified56.6%
Final simplification58.8%
(FPCore (a b c) :precision binary64 (if (<= b -4.2e-229) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.2e-229) {
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 <= (-4.2d-229)) 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 <= -4.2e-229) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.2e-229: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.2e-229) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(-b) / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.2e-229) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.2e-229], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.2 \cdot 10^{-229}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -4.19999999999999967e-229Initial program 35.4%
div-sub34.3%
sub-neg34.3%
neg-mul-134.3%
*-commutative34.3%
associate-/l*33.4%
distribute-neg-frac33.4%
neg-mul-133.4%
*-commutative33.4%
associate-/l*34.2%
distribute-rgt-out35.4%
associate-/r*35.4%
metadata-eval35.4%
sub-neg35.4%
+-commutative35.4%
Simplified35.4%
Taylor expanded in b around -inf 66.2%
mul-1-neg66.2%
distribute-neg-frac266.2%
Simplified66.2%
if -4.19999999999999967e-229 < b Initial program 74.4%
div-sub74.4%
sub-neg74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.4%
distribute-neg-frac74.4%
neg-mul-174.4%
*-commutative74.4%
associate-/l*74.2%
distribute-rgt-out74.2%
associate-/r*74.2%
metadata-eval74.2%
sub-neg74.2%
+-commutative74.2%
Simplified74.3%
Taylor expanded in a around 0 51.2%
associate-*r/51.2%
mul-1-neg51.2%
Simplified51.2%
Final simplification58.6%
(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 / Float64(-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 55.2%
div-sub54.7%
sub-neg54.7%
neg-mul-154.7%
*-commutative54.7%
associate-/l*54.2%
distribute-neg-frac54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*54.5%
distribute-rgt-out55.1%
associate-/r*55.1%
metadata-eval55.1%
sub-neg55.1%
+-commutative55.1%
Simplified55.2%
Taylor expanded in b around -inf 33.7%
mul-1-neg33.7%
distribute-neg-frac233.7%
Simplified33.7%
Final simplification33.7%
(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 55.2%
div-sub54.7%
sub-neg54.7%
neg-mul-154.7%
*-commutative54.7%
associate-/l*54.2%
distribute-neg-frac54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*54.5%
distribute-rgt-out55.1%
associate-/r*55.1%
metadata-eval55.1%
sub-neg55.1%
+-commutative55.1%
Simplified55.2%
Applied egg-rr36.7%
Taylor expanded in b around -inf 2.9%
Final simplification2.9%
(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 55.2%
div-sub54.7%
sub-neg54.7%
neg-mul-154.7%
*-commutative54.7%
associate-/l*54.2%
distribute-neg-frac54.2%
neg-mul-154.2%
*-commutative54.2%
associate-/l*54.5%
distribute-rgt-out55.1%
associate-/r*55.1%
metadata-eval55.1%
sub-neg55.1%
+-commutative55.1%
Simplified55.2%
Taylor expanded in a around 0 26.3%
associate-/l*27.2%
Simplified27.2%
Taylor expanded in a around inf 10.9%
Final simplification10.9%
(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 2024053
(FPCore (a b c)
:name "The quadratic formula (r2)"
:precision binary64
:alt
(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)))