
(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 -6.5e-89)
(- (/ c (- b)) (* a (* c (/ c (pow b 3.0)))))
(if (<= b 1.55e+92)
(/ (- (- 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 <= -6.5e-89) {
tmp = (c / -b) - (a * (c * (c / pow(b, 3.0))));
} else if (b <= 1.55e+92) {
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 <= (-6.5d-89)) then
tmp = (c / -b) - (a * (c * (c / (b ** 3.0d0))))
else if (b <= 1.55d+92) 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 <= -6.5e-89) {
tmp = (c / -b) - (a * (c * (c / Math.pow(b, 3.0))));
} else if (b <= 1.55e+92) {
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 <= -6.5e-89: tmp = (c / -b) - (a * (c * (c / math.pow(b, 3.0)))) elif b <= 1.55e+92: 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 <= -6.5e-89) tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64(c * Float64(c / (b ^ 3.0))))); elseif (b <= 1.55e+92) 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 <= -6.5e-89) tmp = (c / -b) - (a * (c * (c / (b ^ 3.0)))); elseif (b <= 1.55e+92) 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, -6.5e-89], N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(c * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.55e+92], 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 -6.5 \cdot 10^{-89}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \left(c \cdot \frac{c}{{b}^{3}}\right)\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{+92}:\\
\;\;\;\;\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 < -6.50000000000000034e-89Initial program 23.6%
div-sub22.0%
sub-neg22.0%
neg-mul-122.0%
*-commutative22.0%
associate-/l*21.8%
distribute-neg-frac21.8%
neg-mul-121.8%
*-commutative21.8%
associate-/l*22.0%
distribute-rgt-out23.6%
associate-/r*23.6%
metadata-eval23.6%
sub-neg23.6%
+-commutative23.6%
Simplified23.6%
Taylor expanded in b around -inf 69.1%
distribute-lft-out69.1%
associate-/l*72.6%
Simplified72.6%
unpow272.6%
associate-/l*85.7%
Applied egg-rr85.7%
if -6.50000000000000034e-89 < b < 1.5500000000000001e92Initial program 79.9%
if 1.5500000000000001e92 < b Initial program 55.1%
div-sub55.1%
sub-neg55.1%
neg-mul-155.1%
*-commutative55.1%
associate-/l*55.1%
distribute-neg-frac55.1%
neg-mul-155.1%
*-commutative55.1%
associate-/l*55.1%
distribute-rgt-out55.1%
associate-/r*55.1%
metadata-eval55.1%
sub-neg55.1%
+-commutative55.1%
Simplified55.2%
Taylor expanded in a around 0 98.1%
associate-*r/98.1%
mul-1-neg98.1%
Simplified98.1%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e-92)
(/ c (- b))
(if (<= b 3.8e-86)
(* (/ -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 <= -1.15e-92) {
tmp = c / -b;
} else if (b <= 3.8e-86) {
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 <= (-1.15d-92)) then
tmp = c / -b
else if (b <= 3.8d-86) 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 <= -1.15e-92) {
tmp = c / -b;
} else if (b <= 3.8e-86) {
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 <= -1.15e-92: tmp = c / -b elif b <= 3.8e-86: 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 <= -1.15e-92) tmp = Float64(c / Float64(-b)); elseif (b <= 3.8e-86) 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 <= -1.15e-92) tmp = c / -b; elseif (b <= 3.8e-86) 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, -1.15e-92], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 3.8e-86], 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 -1.15 \cdot 10^{-92}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{-86}:\\
\;\;\;\;\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 < -1.15000000000000008e-92Initial program 24.0%
div-sub22.5%
sub-neg22.5%
neg-mul-122.5%
*-commutative22.5%
associate-/l*22.3%
distribute-neg-frac22.3%
neg-mul-122.3%
*-commutative22.3%
associate-/l*22.4%
distribute-rgt-out24.0%
associate-/r*24.0%
metadata-eval24.0%
sub-neg24.0%
+-commutative24.0%
Simplified24.1%
Taylor expanded in b around -inf 85.0%
mul-1-neg85.0%
distribute-neg-frac285.0%
Simplified85.0%
if -1.15000000000000008e-92 < b < 3.8e-86Initial program 73.0%
div-sub73.0%
sub-neg73.0%
neg-mul-173.0%
*-commutative73.0%
associate-/l*73.0%
distribute-neg-frac73.0%
neg-mul-173.0%
*-commutative73.0%
associate-/l*73.0%
distribute-rgt-out73.0%
associate-/r*73.0%
metadata-eval73.0%
sub-neg73.0%
+-commutative73.0%
Simplified73.0%
Taylor expanded in a around inf 69.2%
*-commutative69.2%
Simplified69.2%
if 3.8e-86 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-neg-frac70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.3%
distribute-rgt-out70.3%
associate-/r*70.3%
metadata-eval70.3%
sub-neg70.3%
+-commutative70.3%
Simplified70.4%
Taylor expanded in a around 0 87.4%
+-commutative87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
Final simplification82.3%
(FPCore (a b c)
:precision binary64
(if (<= b -7.6e-90)
(- (/ c (- b)) (* a (* c (/ c (pow b 3.0)))))
(if (<= b 1.5e-82)
(* (/ -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 <= -7.6e-90) {
tmp = (c / -b) - (a * (c * (c / pow(b, 3.0))));
} else if (b <= 1.5e-82) {
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 <= (-7.6d-90)) then
tmp = (c / -b) - (a * (c * (c / (b ** 3.0d0))))
else if (b <= 1.5d-82) 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 <= -7.6e-90) {
tmp = (c / -b) - (a * (c * (c / Math.pow(b, 3.0))));
} else if (b <= 1.5e-82) {
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 <= -7.6e-90: tmp = (c / -b) - (a * (c * (c / math.pow(b, 3.0)))) elif b <= 1.5e-82: 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 <= -7.6e-90) tmp = Float64(Float64(c / Float64(-b)) - Float64(a * Float64(c * Float64(c / (b ^ 3.0))))); elseif (b <= 1.5e-82) 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 <= -7.6e-90) tmp = (c / -b) - (a * (c * (c / (b ^ 3.0)))); elseif (b <= 1.5e-82) 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, -7.6e-90], N[(N[(c / (-b)), $MachinePrecision] - N[(a * N[(c * N[(c / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.5e-82], 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 -7.6 \cdot 10^{-90}:\\
\;\;\;\;\frac{c}{-b} - a \cdot \left(c \cdot \frac{c}{{b}^{3}}\right)\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-82}:\\
\;\;\;\;\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 < -7.6e-90Initial program 23.6%
div-sub22.0%
sub-neg22.0%
neg-mul-122.0%
*-commutative22.0%
associate-/l*21.8%
distribute-neg-frac21.8%
neg-mul-121.8%
*-commutative21.8%
associate-/l*22.0%
distribute-rgt-out23.6%
associate-/r*23.6%
metadata-eval23.6%
sub-neg23.6%
+-commutative23.6%
Simplified23.6%
Taylor expanded in b around -inf 69.1%
distribute-lft-out69.1%
associate-/l*72.6%
Simplified72.6%
unpow272.6%
associate-/l*85.7%
Applied egg-rr85.7%
if -7.6e-90 < b < 1.4999999999999999e-82Initial program 72.2%
div-sub72.2%
sub-neg72.2%
neg-mul-172.2%
*-commutative72.2%
associate-/l*72.2%
distribute-neg-frac72.2%
neg-mul-172.2%
*-commutative72.2%
associate-/l*72.3%
distribute-rgt-out72.3%
associate-/r*72.3%
metadata-eval72.3%
sub-neg72.3%
+-commutative72.3%
Simplified72.3%
Taylor expanded in a around inf 68.6%
*-commutative68.6%
Simplified68.6%
if 1.4999999999999999e-82 < b Initial program 70.4%
div-sub70.4%
sub-neg70.4%
neg-mul-170.4%
*-commutative70.4%
associate-/l*70.3%
distribute-neg-frac70.3%
neg-mul-170.3%
*-commutative70.3%
associate-/l*70.3%
distribute-rgt-out70.3%
associate-/r*70.3%
metadata-eval70.3%
sub-neg70.3%
+-commutative70.3%
Simplified70.4%
Taylor expanded in a around 0 87.4%
+-commutative87.4%
mul-1-neg87.4%
unsub-neg87.4%
Simplified87.4%
Final simplification82.4%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (/ c (- b)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-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 <= (-1d-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 <= -1e-310) {
tmp = c / -b;
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = c / -b else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-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 <= -1e-310) tmp = c / -b; else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 33.4%
div-sub32.1%
sub-neg32.1%
neg-mul-132.1%
*-commutative32.1%
associate-/l*32.0%
distribute-neg-frac32.0%
neg-mul-132.0%
*-commutative32.0%
associate-/l*32.1%
distribute-rgt-out33.4%
associate-/r*33.4%
metadata-eval33.4%
sub-neg33.4%
+-commutative33.4%
Simplified33.4%
Taylor expanded in b around -inf 70.1%
mul-1-neg70.1%
distribute-neg-frac270.1%
Simplified70.1%
if -9.999999999999969e-311 < b Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
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 a around 0 71.7%
+-commutative71.7%
mul-1-neg71.7%
unsub-neg71.7%
Simplified71.7%
Final simplification70.8%
(FPCore (a b c) :precision binary64 (if (<= b -7.4e-304) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.4e-304) {
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 <= (-7.4d-304)) 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 <= -7.4e-304) {
tmp = c / -b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.4e-304: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.4e-304) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7.4e-304) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.4e-304], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.4 \cdot 10^{-304}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
if b < -7.4000000000000006e-304Initial program 33.4%
div-sub32.1%
sub-neg32.1%
neg-mul-132.1%
*-commutative32.1%
associate-/l*32.0%
distribute-neg-frac32.0%
neg-mul-132.0%
*-commutative32.0%
associate-/l*32.1%
distribute-rgt-out33.4%
associate-/r*33.4%
metadata-eval33.4%
sub-neg33.4%
+-commutative33.4%
Simplified33.4%
Taylor expanded in b around -inf 70.1%
mul-1-neg70.1%
distribute-neg-frac270.1%
Simplified70.1%
if -7.4000000000000006e-304 < b Initial program 71.8%
div-sub71.8%
sub-neg71.8%
neg-mul-171.8%
*-commutative71.8%
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 a around 0 71.7%
associate-*r/71.7%
mul-1-neg71.7%
Simplified71.7%
Final simplification70.8%
(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 49.4%
div-sub48.7%
sub-neg48.7%
neg-mul-148.7%
*-commutative48.7%
associate-/l*48.6%
distribute-neg-frac48.6%
neg-mul-148.6%
*-commutative48.6%
associate-/l*48.6%
distribute-rgt-out49.4%
associate-/r*49.4%
metadata-eval49.4%
sub-neg49.4%
+-commutative49.4%
Simplified49.4%
Taylor expanded in b around -inf 41.9%
mul-1-neg41.9%
distribute-neg-frac241.9%
Simplified41.9%
Final simplification41.9%
(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}
\\
b \cdot a
\end{array}
Initial program 49.4%
div-sub48.7%
sub-neg48.7%
neg-mul-148.7%
*-commutative48.7%
associate-/l*48.6%
distribute-neg-frac48.6%
neg-mul-148.6%
*-commutative48.6%
associate-/l*48.6%
distribute-rgt-out49.4%
associate-/r*49.4%
metadata-eval49.4%
sub-neg49.4%
+-commutative49.4%
Simplified49.4%
add-cube-cbrt48.8%
pow348.8%
*-commutative48.8%
*-un-lft-identity48.8%
*-un-lft-identity48.8%
pow248.8%
Applied egg-rr48.8%
Taylor expanded in c around 0 15.0%
unpow1/330.9%
*-lft-identity30.9%
Simplified30.9%
Applied egg-rr2.7%
Final simplification2.7%
(FPCore (a b c) :precision binary64 (/ a b))
double code(double a, double b, double c) {
return a / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = a / b
end function
public static double code(double a, double b, double c) {
return a / b;
}
def code(a, b, c): return a / b
function code(a, b, c) return Float64(a / b) end
function tmp = code(a, b, c) tmp = a / b; end
code[a_, b_, c_] := N[(a / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{b}
\end{array}
Initial program 49.4%
div-sub48.7%
sub-neg48.7%
neg-mul-148.7%
*-commutative48.7%
associate-/l*48.6%
distribute-neg-frac48.6%
neg-mul-148.6%
*-commutative48.6%
associate-/l*48.6%
distribute-rgt-out49.4%
associate-/r*49.4%
metadata-eval49.4%
sub-neg49.4%
+-commutative49.4%
Simplified49.4%
add-cube-cbrt48.8%
pow348.8%
*-commutative48.8%
*-un-lft-identity48.8%
*-un-lft-identity48.8%
pow248.8%
Applied egg-rr48.8%
Taylor expanded in c around 0 15.0%
unpow1/330.9%
*-lft-identity30.9%
Simplified30.9%
Applied egg-rr6.9%
Final simplification6.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 2024047
(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)))