
(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 -5.2e-104)
(/ c (- b))
(if (<= b 4.4e+73)
(/ (- (- 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 <= -5.2e-104) {
tmp = c / -b;
} else if (b <= 4.4e+73) {
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 <= (-5.2d-104)) then
tmp = c / -b
else if (b <= 4.4d+73) 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 <= -5.2e-104) {
tmp = c / -b;
} else if (b <= 4.4e+73) {
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 <= -5.2e-104: tmp = c / -b elif b <= 4.4e+73: 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 <= -5.2e-104) tmp = Float64(c / Float64(-b)); elseif (b <= 4.4e+73) 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 <= -5.2e-104) tmp = c / -b; elseif (b <= 4.4e+73) 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, -5.2e-104], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 4.4e+73], 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 -5.2 \cdot 10^{-104}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 4.4 \cdot 10^{+73}:\\
\;\;\;\;\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 < -5.20000000000000005e-104Initial program 15.8%
div-sub14.3%
sub-neg14.3%
neg-mul-114.3%
*-commutative14.3%
associate-/l*13.2%
distribute-neg-frac13.2%
neg-mul-113.2%
*-commutative13.2%
associate-/l*14.3%
distribute-rgt-out15.8%
associate-/r*15.8%
metadata-eval15.8%
sub-neg15.8%
+-commutative15.8%
Simplified15.8%
Taylor expanded in b around -inf 88.6%
mul-1-neg88.6%
distribute-neg-frac288.6%
Simplified88.6%
if -5.20000000000000005e-104 < b < 4.4e73Initial program 80.4%
if 4.4e73 < b Initial program 60.9%
div-sub60.9%
sub-neg60.9%
neg-mul-160.9%
*-commutative60.9%
associate-/l*60.9%
distribute-neg-frac60.9%
neg-mul-160.9%
*-commutative60.9%
associate-/l*60.8%
distribute-rgt-out60.8%
associate-/r*60.8%
metadata-eval60.8%
sub-neg60.8%
+-commutative60.8%
Simplified60.9%
Taylor expanded in c around 0 94.7%
+-commutative94.7%
mul-1-neg94.7%
unsub-neg94.7%
Simplified94.7%
Final simplification87.2%
(FPCore (a b c)
:precision binary64
(if (<= b -9e-104)
(/ c (- b))
(if (<= b 0.102)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ c b) (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9e-104) {
tmp = c / -b;
} else if (b <= 0.102) {
tmp = (-b - sqrt((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-104)) then
tmp = c / -b
else if (b <= 0.102d0) then
tmp = (-b - sqrt((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-104) {
tmp = c / -b;
} else if (b <= 0.102) {
tmp = (-b - Math.sqrt((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-104: tmp = c / -b elif b <= 0.102: tmp = (-b - math.sqrt((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-104) tmp = Float64(c / Float64(-b)); elseif (b <= 0.102) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -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 <= -9e-104) tmp = c / -b; elseif (b <= 0.102) tmp = (-b - sqrt((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-104], N[(c / (-b)), $MachinePrecision], If[LessEqual[b, 0.102], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -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 -9 \cdot 10^{-104}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{elif}\;b \leq 0.102:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
if b < -8.9999999999999995e-104Initial program 15.8%
div-sub14.3%
sub-neg14.3%
neg-mul-114.3%
*-commutative14.3%
associate-/l*13.2%
distribute-neg-frac13.2%
neg-mul-113.2%
*-commutative13.2%
associate-/l*14.3%
distribute-rgt-out15.8%
associate-/r*15.8%
metadata-eval15.8%
sub-neg15.8%
+-commutative15.8%
Simplified15.8%
Taylor expanded in b around -inf 88.6%
mul-1-neg88.6%
distribute-neg-frac288.6%
Simplified88.6%
if -8.9999999999999995e-104 < b < 0.101999999999999993Initial program 78.6%
*-commutative78.6%
sqr-neg78.6%
*-commutative78.6%
sqr-neg78.6%
*-commutative78.6%
associate-*r*78.6%
*-commutative78.6%
Simplified78.6%
Taylor expanded in b around 0 73.6%
associate-*r*73.6%
*-commutative73.6%
Simplified73.6%
if 0.101999999999999993 < b Initial program 66.5%
div-sub66.5%
sub-neg66.5%
neg-mul-166.5%
*-commutative66.5%
associate-/l*66.5%
distribute-neg-frac66.5%
neg-mul-166.5%
*-commutative66.5%
associate-/l*66.4%
distribute-rgt-out66.4%
associate-/r*66.4%
metadata-eval66.4%
sub-neg66.4%
+-commutative66.4%
Simplified66.5%
Taylor expanded in c around 0 91.4%
+-commutative91.4%
mul-1-neg91.4%
unsub-neg91.4%
Simplified91.4%
Final simplification85.1%
(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 33.3%
div-sub32.3%
sub-neg32.3%
neg-mul-132.3%
*-commutative32.3%
associate-/l*31.5%
distribute-neg-frac31.5%
neg-mul-131.5%
*-commutative31.5%
associate-/l*32.2%
distribute-rgt-out33.3%
associate-/r*33.3%
metadata-eval33.3%
sub-neg33.3%
+-commutative33.3%
Simplified33.3%
Taylor expanded in b around -inf 66.3%
mul-1-neg66.3%
distribute-neg-frac266.3%
Simplified66.3%
if -4.999999999999985e-310 < b Initial program 71.5%
div-sub71.6%
sub-neg71.6%
neg-mul-171.6%
*-commutative71.6%
associate-/l*71.5%
distribute-neg-frac71.5%
neg-mul-171.5%
*-commutative71.5%
associate-/l*71.4%
distribute-rgt-out71.4%
associate-/r*71.4%
metadata-eval71.4%
sub-neg71.4%
+-commutative71.4%
Simplified71.5%
Taylor expanded in c around 0 71.8%
+-commutative71.8%
mul-1-neg71.8%
unsub-neg71.8%
Simplified71.8%
Final simplification68.8%
(FPCore (a b c) :precision binary64 (if (<= b -1.6e-148) (/ c (- b)) (/ -1.25 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-148) {
tmp = c / -b;
} else {
tmp = -1.25 / 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.6d-148)) then
tmp = c / -b
else
tmp = (-1.25d0) / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.6e-148) {
tmp = c / -b;
} else {
tmp = -1.25 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.6e-148: tmp = c / -b else: tmp = -1.25 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.6e-148) tmp = Float64(c / Float64(-b)); else tmp = Float64(-1.25 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.6e-148) tmp = c / -b; else tmp = -1.25 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.6e-148], N[(c / (-b)), $MachinePrecision], N[(-1.25 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.6 \cdot 10^{-148}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1.25}{a}\\
\end{array}
\end{array}
if b < -1.59999999999999997e-148Initial program 20.0%
div-sub18.6%
sub-neg18.6%
neg-mul-118.6%
*-commutative18.6%
associate-/l*17.7%
distribute-neg-frac17.7%
neg-mul-117.7%
*-commutative17.7%
associate-/l*18.6%
distribute-rgt-out20.0%
associate-/r*20.0%
metadata-eval20.0%
sub-neg20.0%
+-commutative20.0%
Simplified20.0%
Taylor expanded in b around -inf 84.5%
mul-1-neg84.5%
distribute-neg-frac284.5%
Simplified84.5%
if -1.59999999999999997e-148 < b Initial program 73.0%
div-sub73.0%
sub-neg73.0%
neg-mul-173.0%
*-commutative73.0%
associate-/l*72.9%
distribute-neg-frac72.9%
neg-mul-172.9%
*-commutative72.9%
associate-/l*72.9%
distribute-rgt-out72.9%
associate-/r*72.9%
metadata-eval72.9%
sub-neg72.9%
+-commutative72.9%
Simplified72.9%
Taylor expanded in a around 0 54.1%
associate-/l*56.3%
Simplified56.3%
Taylor expanded in c around -inf 47.2%
Simplified5.0%
Taylor expanded in c around 0 6.3%
Final simplification39.3%
(FPCore (a b c) :precision binary64 (if (<= b -1e-248) (/ c (- b)) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-248) {
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 <= (-1d-248)) 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 <= -1e-248) {
tmp = c / -b;
} else {
tmp = -b / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-248: tmp = c / -b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-248) 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 <= -1e-248) tmp = c / -b; else tmp = -b / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-248], N[(c / (-b)), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-248}:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -9.9999999999999998e-249Initial program 29.7%
div-sub28.6%
sub-neg28.6%
neg-mul-128.6%
*-commutative28.6%
associate-/l*27.8%
distribute-neg-frac27.8%
neg-mul-127.8%
*-commutative27.8%
associate-/l*28.5%
distribute-rgt-out29.7%
associate-/r*29.7%
metadata-eval29.7%
sub-neg29.7%
+-commutative29.7%
Simplified29.7%
Taylor expanded in b around -inf 71.1%
mul-1-neg71.1%
distribute-neg-frac271.1%
Simplified71.1%
if -9.9999999999999998e-249 < b Initial 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.1%
distribute-rgt-out72.1%
associate-/r*72.1%
metadata-eval72.1%
sub-neg72.1%
+-commutative72.1%
Simplified72.2%
Taylor expanded in a around 0 66.2%
associate-*r/66.2%
mul-1-neg66.2%
Simplified66.2%
Final simplification68.7%
(FPCore (a b c) :precision binary64 (if (<= b -2.45e+70) (/ c b) (/ -1.25 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e+70) {
tmp = c / b;
} else {
tmp = -1.25 / 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.45d+70)) then
tmp = c / b
else
tmp = (-1.25d0) / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.45e+70) {
tmp = c / b;
} else {
tmp = -1.25 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.45e+70: tmp = c / b else: tmp = -1.25 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.45e+70) tmp = Float64(c / b); else tmp = Float64(-1.25 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.45e+70) tmp = c / b; else tmp = -1.25 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.45e+70], N[(c / b), $MachinePrecision], N[(-1.25 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.45 \cdot 10^{+70}:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1.25}{a}\\
\end{array}
\end{array}
if b < -2.45000000000000014e70Initial program 14.2%
div-sub11.9%
sub-neg11.9%
neg-mul-111.9%
*-commutative11.9%
associate-/l*10.4%
distribute-neg-frac10.4%
neg-mul-110.4%
*-commutative10.4%
associate-/l*11.9%
distribute-rgt-out14.2%
associate-/r*14.2%
metadata-eval14.2%
sub-neg14.2%
+-commutative14.2%
Simplified14.2%
Taylor expanded in a around 0 2.3%
+-commutative2.3%
mul-1-neg2.3%
sub-neg2.3%
associate-/l*2.5%
Simplified2.5%
Taylor expanded in a around inf 39.0%
if -2.45000000000000014e70 < b Initial program 63.3%
div-sub63.3%
sub-neg63.3%
neg-mul-163.3%
*-commutative63.3%
associate-/l*63.3%
distribute-neg-frac63.3%
neg-mul-163.3%
*-commutative63.3%
associate-/l*63.2%
distribute-rgt-out63.2%
associate-/r*63.2%
metadata-eval63.2%
sub-neg63.2%
+-commutative63.2%
Simplified63.2%
Taylor expanded in a around 0 42.7%
associate-/l*44.4%
Simplified44.4%
Taylor expanded in c around -inf 37.3%
Simplified4.9%
Taylor expanded in c around 0 6.0%
Final simplification14.5%
(FPCore (a b c) :precision binary64 (/ -1.25 a))
double code(double a, double b, double c) {
return -1.25 / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-1.25d0) / a
end function
public static double code(double a, double b, double c) {
return -1.25 / a;
}
def code(a, b, c): return -1.25 / a
function code(a, b, c) return Float64(-1.25 / a) end
function tmp = code(a, b, c) tmp = -1.25 / a; end
code[a_, b_, c_] := N[(-1.25 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1.25}{a}
\end{array}
Initial program 50.6%
div-sub50.1%
sub-neg50.1%
neg-mul-150.1%
*-commutative50.1%
associate-/l*49.6%
distribute-neg-frac49.6%
neg-mul-149.6%
*-commutative49.6%
associate-/l*50.0%
distribute-rgt-out50.6%
associate-/r*50.6%
metadata-eval50.6%
sub-neg50.6%
+-commutative50.6%
Simplified50.6%
Taylor expanded in a around 0 32.3%
associate-/l*33.6%
Simplified33.6%
Taylor expanded in c around -inf 28.2%
Simplified4.4%
Taylor expanded in c around 0 5.2%
Final simplification5.2%
(FPCore (a b c) :precision binary64 -2.5)
double code(double a, double b, double c) {
return -2.5;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -2.5d0
end function
public static double code(double a, double b, double c) {
return -2.5;
}
def code(a, b, c): return -2.5
function code(a, b, c) return -2.5 end
function tmp = code(a, b, c) tmp = -2.5; end
code[a_, b_, c_] := -2.5
\begin{array}{l}
\\
-2.5
\end{array}
Initial program 50.6%
div-sub50.1%
sub-neg50.1%
neg-mul-150.1%
*-commutative50.1%
associate-/l*49.6%
distribute-neg-frac49.6%
neg-mul-149.6%
*-commutative49.6%
associate-/l*50.0%
distribute-rgt-out50.6%
associate-/r*50.6%
metadata-eval50.6%
sub-neg50.6%
+-commutative50.6%
Simplified50.6%
Applied egg-rr50.0%
Taylor expanded in b around inf 34.0%
Simplified3.4%
Final simplification3.4%
(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 2024100
(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)))