
(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 9 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
(let* ((t_0 (/ (- c) b)))
(if (<= b -8.5e+42)
t_0
(if (<= b -2.2e-13)
(/ (* (/ (* c a) a) -2.0) (- b (hypot b (sqrt (* a (* c -4.0))))))
(if (<= b -9.6e-46)
t_0
(if (<= b 3.8e+96)
(/ (- (- b) (sqrt (fma (* a -4.0) c (* b b)))) (* a 2.0))
(- (/ b a))))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double tmp;
if (b <= -8.5e+42) {
tmp = t_0;
} else if (b <= -2.2e-13) {
tmp = (((c * a) / a) * -2.0) / (b - hypot(b, sqrt((a * (c * -4.0)))));
} else if (b <= -9.6e-46) {
tmp = t_0;
} else if (b <= 3.8e+96) {
tmp = (-b - sqrt(fma((a * -4.0), c, (b * b)))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(Float64(-c) / b) tmp = 0.0 if (b <= -8.5e+42) tmp = t_0; elseif (b <= -2.2e-13) tmp = Float64(Float64(Float64(Float64(c * a) / a) * -2.0) / Float64(b - hypot(b, sqrt(Float64(a * Float64(c * -4.0)))))); elseif (b <= -9.6e-46) tmp = t_0; elseif (b <= 3.8e+96) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(a * -4.0), c, Float64(b * b)))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -8.5e+42], t$95$0, If[LessEqual[b, -2.2e-13], N[(N[(N[(N[(c * a), $MachinePrecision] / a), $MachinePrecision] * -2.0), $MachinePrecision] / N[(b - N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -9.6e-46], t$95$0, If[LessEqual[b, 3.8e+96], N[(N[((-b) - N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -8.5 \cdot 10^{+42}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -2.2 \cdot 10^{-13}:\\
\;\;\;\;\frac{\frac{c \cdot a}{a} \cdot -2}{b - \mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right)}\\
\mathbf{elif}\;b \leq -9.6 \cdot 10^{-46}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 3.8 \cdot 10^{+96}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -8.5000000000000003e42 or -2.19999999999999997e-13 < b < -9.60000000000000053e-46Initial program 12.2%
*-commutative12.2%
sqr-neg12.2%
*-commutative12.2%
sqr-neg12.2%
associate-*r*12.2%
*-commutative12.2%
Simplified12.2%
Taylor expanded in b around -inf 94.2%
associate-*r/94.2%
neg-mul-194.2%
Simplified94.2%
if -8.5000000000000003e42 < b < -2.19999999999999997e-13Initial program 69.5%
*-commutative69.5%
sqr-neg69.5%
*-commutative69.5%
sqr-neg69.5%
associate-*r*69.5%
*-commutative69.5%
Simplified69.5%
flip--69.0%
frac-2neg69.0%
Applied egg-rr54.0%
neg-sub054.0%
+-commutative54.0%
associate--r+54.0%
neg-sub054.0%
distribute-lft-neg-in54.0%
metadata-eval54.0%
*-commutative54.0%
associate-*l*54.0%
fma-udef54.0%
distribute-lft-out54.0%
associate-*r*54.0%
*-commutative54.0%
associate-*l*54.0%
Simplified54.0%
Taylor expanded in a around inf 84.6%
associate-*r*84.6%
*-commutative84.6%
associate-*r*84.6%
*-commutative84.6%
Simplified84.6%
div-inv84.6%
Applied egg-rr84.6%
associate-*l/84.3%
associate-*r/84.6%
*-rgt-identity84.6%
associate-*r*84.6%
rem-square-sqrt0.0%
unpow20.0%
times-frac0.0%
unpow20.0%
rem-square-sqrt84.6%
metadata-eval84.6%
Simplified84.6%
if -9.60000000000000053e-46 < b < 3.8000000000000002e96Initial program 86.3%
*-commutative86.3%
sqr-neg86.3%
*-commutative86.3%
sqr-neg86.3%
associate-*r*86.4%
*-commutative86.4%
Simplified86.4%
sub-neg86.4%
+-commutative86.4%
distribute-lft-neg-in86.4%
fma-def86.4%
*-commutative86.4%
distribute-rgt-neg-in86.4%
metadata-eval86.4%
Applied egg-rr86.4%
if 3.8000000000000002e96 < b Initial program 54.0%
*-commutative54.0%
sqr-neg54.0%
*-commutative54.0%
sqr-neg54.0%
associate-*r*54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in b around inf 93.5%
associate-*r/93.5%
mul-1-neg93.5%
Simplified93.5%
Final simplification90.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.34e-45)
(/ (- c) b)
(if (<= b 2e+96)
(/ (- (- b) (sqrt (fma (* a -4.0) c (* b b)))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.34e-45) {
tmp = -c / b;
} else if (b <= 2e+96) {
tmp = (-b - sqrt(fma((a * -4.0), c, (b * b)))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.34e-45) tmp = Float64(Float64(-c) / b); elseif (b <= 2e+96) tmp = Float64(Float64(Float64(-b) - sqrt(fma(Float64(a * -4.0), c, Float64(b * b)))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.34e-45], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2e+96], N[(N[((-b) - N[Sqrt[N[(N[(a * -4.0), $MachinePrecision] * c + N[(b * b), $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.34 \cdot 10^{-45}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+96}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(a \cdot -4, c, b \cdot b\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -1.34e-45Initial program 20.0%
*-commutative20.0%
sqr-neg20.0%
*-commutative20.0%
sqr-neg20.0%
associate-*r*20.0%
*-commutative20.0%
Simplified20.0%
Taylor expanded in b around -inf 87.5%
associate-*r/87.5%
neg-mul-187.5%
Simplified87.5%
if -1.34e-45 < b < 2.0000000000000001e96Initial program 86.3%
*-commutative86.3%
sqr-neg86.3%
*-commutative86.3%
sqr-neg86.3%
associate-*r*86.4%
*-commutative86.4%
Simplified86.4%
sub-neg86.4%
+-commutative86.4%
distribute-lft-neg-in86.4%
fma-def86.4%
*-commutative86.4%
distribute-rgt-neg-in86.4%
metadata-eval86.4%
Applied egg-rr86.4%
if 2.0000000000000001e96 < b Initial program 54.0%
*-commutative54.0%
sqr-neg54.0%
*-commutative54.0%
sqr-neg54.0%
associate-*r*54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in b around inf 93.5%
associate-*r/93.5%
mul-1-neg93.5%
Simplified93.5%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.4e-45)
(/ (- c) b)
(if (<= b 2.05e+95)
(/ (- (- 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 <= -4.4e-45) {
tmp = -c / b;
} else if (b <= 2.05e+95) {
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 <= (-4.4d-45)) then
tmp = -c / b
else if (b <= 2.05d+95) 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 <= -4.4e-45) {
tmp = -c / b;
} else if (b <= 2.05e+95) {
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 <= -4.4e-45: tmp = -c / b elif b <= 2.05e+95: 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 <= -4.4e-45) tmp = Float64(Float64(-c) / b); elseif (b <= 2.05e+95) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(Float64(c * 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 <= -4.4e-45) tmp = -c / b; elseif (b <= 2.05e+95) 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, -4.4e-45], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.05e+95], N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(c * a), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.4 \cdot 10^{-45}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.05 \cdot 10^{+95}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -4.39999999999999987e-45Initial program 20.0%
*-commutative20.0%
sqr-neg20.0%
*-commutative20.0%
sqr-neg20.0%
associate-*r*20.0%
*-commutative20.0%
Simplified20.0%
Taylor expanded in b around -inf 87.5%
associate-*r/87.5%
neg-mul-187.5%
Simplified87.5%
if -4.39999999999999987e-45 < b < 2.04999999999999993e95Initial program 86.3%
if 2.04999999999999993e95 < b Initial program 54.0%
*-commutative54.0%
sqr-neg54.0%
*-commutative54.0%
sqr-neg54.0%
associate-*r*54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in b around inf 93.5%
associate-*r/93.5%
mul-1-neg93.5%
Simplified93.5%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(if (<= b -5.2e-45)
(/ (- c) b)
(if (<= b 1e+96)
(/ (- (- 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 <= -5.2e-45) {
tmp = -c / b;
} else if (b <= 1e+96) {
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 <= (-5.2d-45)) then
tmp = -c / b
else if (b <= 1d+96) 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 <= -5.2e-45) {
tmp = -c / b;
} else if (b <= 1e+96) {
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 <= -5.2e-45: tmp = -c / b elif b <= 1e+96: 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 <= -5.2e-45) tmp = Float64(Float64(-c) / b); elseif (b <= 1e+96) 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 <= -5.2e-45) tmp = -c / b; elseif (b <= 1e+96) 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, -5.2e-45], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 1e+96], 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 -5.2 \cdot 10^{-45}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 10^{+96}:\\
\;\;\;\;\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 < -5.19999999999999973e-45Initial program 20.0%
*-commutative20.0%
sqr-neg20.0%
*-commutative20.0%
sqr-neg20.0%
associate-*r*20.0%
*-commutative20.0%
Simplified20.0%
Taylor expanded in b around -inf 87.5%
associate-*r/87.5%
neg-mul-187.5%
Simplified87.5%
if -5.19999999999999973e-45 < b < 1.00000000000000005e96Initial program 86.3%
*-commutative86.3%
sqr-neg86.3%
*-commutative86.3%
sqr-neg86.3%
associate-*r*86.4%
*-commutative86.4%
Simplified86.4%
if 1.00000000000000005e96 < b Initial program 54.0%
*-commutative54.0%
sqr-neg54.0%
*-commutative54.0%
sqr-neg54.0%
associate-*r*54.0%
*-commutative54.0%
Simplified54.0%
Taylor expanded in b around inf 93.5%
associate-*r/93.5%
mul-1-neg93.5%
Simplified93.5%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.22e-68)
(/ (- c) b)
(if (<= b 2.5e-28)
(/ (- (- b) (sqrt (* c (* a -4.0)))) (* a 2.0))
(- (/ b a)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.22e-68) {
tmp = -c / b;
} else if (b <= 2.5e-28) {
tmp = (-b - sqrt((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 <= (-1.22d-68)) then
tmp = -c / b
else if (b <= 2.5d-28) then
tmp = (-b - sqrt((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 <= -1.22e-68) {
tmp = -c / b;
} else if (b <= 2.5e-28) {
tmp = (-b - Math.sqrt((c * (a * -4.0)))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.22e-68: tmp = -c / b elif b <= 2.5e-28: tmp = (-b - math.sqrt((c * (a * -4.0)))) / (a * 2.0) else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.22e-68) tmp = Float64(Float64(-c) / b); elseif (b <= 2.5e-28) tmp = Float64(Float64(Float64(-b) - sqrt(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 <= -1.22e-68) tmp = -c / b; elseif (b <= 2.5e-28) tmp = (-b - sqrt((c * (a * -4.0)))) / (a * 2.0); else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.22e-68], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 2.5e-28], N[(N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $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.22 \cdot 10^{-68}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-28}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -1.2200000000000001e-68Initial program 20.7%
*-commutative20.7%
sqr-neg20.7%
*-commutative20.7%
sqr-neg20.7%
associate-*r*20.7%
*-commutative20.7%
Simplified20.7%
Taylor expanded in b around -inf 86.8%
associate-*r/86.8%
neg-mul-186.8%
Simplified86.8%
if -1.2200000000000001e-68 < b < 2.5000000000000001e-28Initial program 82.9%
*-commutative82.9%
sqr-neg82.9%
*-commutative82.9%
sqr-neg82.9%
associate-*r*83.0%
*-commutative83.0%
Simplified83.0%
Taylor expanded in b around 0 77.1%
*-commutative77.1%
*-commutative77.1%
associate-*r*77.2%
Simplified77.2%
if 2.5000000000000001e-28 < b Initial program 68.5%
*-commutative68.5%
sqr-neg68.5%
*-commutative68.5%
sqr-neg68.5%
associate-*r*68.5%
*-commutative68.5%
Simplified68.5%
Taylor expanded in b around inf 87.3%
associate-*r/87.3%
mul-1-neg87.3%
Simplified87.3%
Final simplification84.3%
(FPCore (a b c) :precision binary64 (if (<= b -5500000000.0) (/ c b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5500000000.0) {
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 <= (-5500000000.0d0)) 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 <= -5500000000.0) {
tmp = c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5500000000.0: tmp = c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5500000000.0) tmp = 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 <= -5500000000.0) tmp = c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5500000000.0], N[(c / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5500000000:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -5.5e9Initial program 15.9%
*-commutative15.9%
sqr-neg15.9%
*-commutative15.9%
sqr-neg15.9%
associate-*r*15.9%
*-commutative15.9%
Simplified15.9%
Taylor expanded in b around inf 2.5%
Taylor expanded in b around 0 33.3%
if -5.5e9 < b Initial program 71.9%
*-commutative71.9%
sqr-neg71.9%
*-commutative71.9%
sqr-neg71.9%
associate-*r*71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in b around inf 48.9%
associate-*r/48.9%
mul-1-neg48.9%
Simplified48.9%
Final simplification44.0%
(FPCore (a b c) :precision binary64 (if (<= b -1e-311) (/ (- c) b) (- (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-311) {
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-311)) 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-311) {
tmp = -c / b;
} else {
tmp = -(b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-311: tmp = -c / b else: tmp = -(b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-311) 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 <= -1e-311) tmp = -c / b; else tmp = -(b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-311], N[((-c) / b), $MachinePrecision], (-N[(b / a), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-311}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
\end{array}
if b < -9.99999999999948e-312Initial program 33.9%
*-commutative33.9%
sqr-neg33.9%
*-commutative33.9%
sqr-neg33.9%
associate-*r*33.9%
*-commutative33.9%
Simplified33.9%
Taylor expanded in b around -inf 69.6%
associate-*r/69.6%
neg-mul-169.6%
Simplified69.6%
if -9.99999999999948e-312 < b Initial program 74.3%
*-commutative74.3%
sqr-neg74.3%
*-commutative74.3%
sqr-neg74.3%
associate-*r*74.3%
*-commutative74.3%
Simplified74.3%
Taylor expanded in b around inf 65.2%
associate-*r/65.2%
mul-1-neg65.2%
Simplified65.2%
Final simplification67.3%
(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 54.4%
*-commutative54.4%
sqr-neg54.4%
*-commutative54.4%
sqr-neg54.4%
associate-*r*54.4%
*-commutative54.4%
Simplified54.4%
add-cube-cbrt53.6%
pow353.6%
Applied egg-rr27.8%
Taylor expanded in b around -inf 2.4%
Final simplification2.4%
(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 54.4%
*-commutative54.4%
sqr-neg54.4%
*-commutative54.4%
sqr-neg54.4%
associate-*r*54.4%
*-commutative54.4%
Simplified54.4%
Taylor expanded in b around inf 32.6%
Taylor expanded in b around 0 12.6%
Final simplification12.6%
(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 2023283
(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)))