
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -2.8e+139)
(/ (- b) a)
(if (<= b 1.2e-50)
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0))
(/ 1.0 (- (/ a b) (/ b c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+139) {
tmp = -b / a;
} else if (b <= 1.2e-50) {
tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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.8d+139)) then
tmp = -b / a
else if (b <= 1.2d-50) then
tmp = (sqrt(((b * b) - ((a * 4.0d0) * c))) - b) / (a * 2.0d0)
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.8e+139) {
tmp = -b / a;
} else if (b <= 1.2e-50) {
tmp = (Math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.8e+139: tmp = -b / a elif b <= 1.2e-50: tmp = (math.sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0) else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.8e+139) tmp = Float64(Float64(-b) / a); elseif (b <= 1.2e-50) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.8e+139) tmp = -b / a; elseif (b <= 1.2e-50) tmp = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0); else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.8e+139], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.2e-50], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.8 \cdot 10^{+139}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-50}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -2.7999999999999998e139Initial program 41.9%
*-commutative41.9%
Simplified41.9%
Taylor expanded in b around -inf 94.9%
associate-*r/94.9%
mul-1-neg94.9%
Simplified94.9%
if -2.7999999999999998e139 < b < 1.20000000000000001e-50Initial program 81.0%
if 1.20000000000000001e-50 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
prod-diff15.8%
*-commutative15.8%
fma-def15.8%
associate-+l+15.8%
pow215.8%
distribute-lft-neg-in15.8%
*-commutative15.8%
distribute-rgt-neg-in15.8%
metadata-eval15.8%
associate-*r*15.8%
*-commutative15.8%
*-commutative15.8%
fma-udef15.8%
Applied egg-rr15.8%
+-commutative15.8%
associate-+r+15.8%
associate-+l+15.8%
associate-*r*15.8%
associate-*r*15.8%
distribute-lft-out15.8%
metadata-eval15.8%
+-commutative15.8%
unpow215.8%
fma-udef15.8%
associate-*l*15.8%
*-commutative15.8%
Simplified15.8%
associate-*l*15.8%
fma-def15.8%
Applied egg-rr15.8%
clear-num15.8%
inv-pow15.8%
neg-mul-115.8%
fma-def15.8%
Applied egg-rr15.8%
unpow-115.8%
*-lft-identity15.8%
times-frac15.8%
/-rgt-identity15.8%
fma-udef15.8%
*-commutative15.8%
fma-def15.8%
fma-def15.8%
associate-*r*15.8%
*-commutative15.8%
fma-udef15.8%
unpow215.8%
associate-*r*15.8%
*-commutative15.8%
*-commutative15.8%
+-commutative15.8%
Simplified16.1%
Taylor expanded in b around inf 83.0%
+-commutative83.0%
mul-1-neg83.0%
unsub-neg83.0%
Simplified83.0%
Final simplification83.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a)))
(t_1 (/ (- (sqrt (* c (* a -4.0))) b) (* a 2.0))))
(if (<= b -1.18e+80)
t_0
(if (<= b -7.2e+14)
t_1
(if (<= b -2.1e-8)
t_0
(if (<= b 2.8e-53) t_1 (/ 1.0 (- (/ a b) (/ b c)))))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (sqrt((c * (a * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.18e+80) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -2.1e-8) {
tmp = t_0;
} else if (b <= 2.8e-53) {
tmp = t_1;
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = (sqrt((c * (a * (-4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-1.18d+80)) then
tmp = t_0
else if (b <= (-7.2d+14)) then
tmp = t_1
else if (b <= (-2.1d-8)) then
tmp = t_0
else if (b <= 2.8d-53) then
tmp = t_1
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = (Math.sqrt((c * (a * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.18e+80) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -2.1e-8) {
tmp = t_0;
} else if (b <= 2.8e-53) {
tmp = t_1;
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = (math.sqrt((c * (a * -4.0))) - b) / (a * 2.0) tmp = 0 if b <= -1.18e+80: tmp = t_0 elif b <= -7.2e+14: tmp = t_1 elif b <= -2.1e-8: tmp = t_0 elif b <= 2.8e-53: tmp = t_1 else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(Float64(sqrt(Float64(c * Float64(a * -4.0))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -1.18e+80) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -2.1e-8) tmp = t_0; elseif (b <= 2.8e-53) tmp = t_1; else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = (sqrt((c * (a * -4.0))) - b) / (a * 2.0); tmp = 0.0; if (b <= -1.18e+80) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -2.1e-8) tmp = t_0; elseif (b <= 2.8e-53) tmp = t_1; else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.18e+80], t$95$0, If[LessEqual[b, -7.2e+14], t$95$1, If[LessEqual[b, -2.1e-8], t$95$0, If[LessEqual[b, 2.8e-53], t$95$1, N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := \frac{\sqrt{c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.18 \cdot 10^{+80}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -7.2 \cdot 10^{+14}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -2.1 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-53}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -1.18e80 or -7.2e14 < b < -2.09999999999999994e-8Initial program 60.9%
*-commutative60.9%
Simplified60.9%
Taylor expanded in b around -inf 94.8%
+-commutative94.8%
mul-1-neg94.8%
unsub-neg94.8%
Simplified94.8%
if -1.18e80 < b < -7.2e14 or -2.09999999999999994e-8 < b < 2.79999999999999985e-53Initial program 78.2%
*-commutative78.2%
Simplified78.2%
prod-diff78.0%
*-commutative78.0%
fma-def78.0%
associate-+l+78.0%
pow278.0%
distribute-lft-neg-in78.0%
*-commutative78.0%
distribute-rgt-neg-in78.0%
metadata-eval78.0%
associate-*r*78.0%
*-commutative78.0%
*-commutative78.0%
fma-udef78.0%
Applied egg-rr78.0%
+-commutative78.0%
associate-+r+78.0%
associate-+l+78.0%
associate-*r*78.0%
associate-*r*78.0%
distribute-lft-out78.0%
metadata-eval78.0%
+-commutative78.0%
unpow278.0%
fma-udef78.0%
associate-*l*78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in b around 0 70.0%
mul-1-neg70.0%
unsub-neg70.0%
associate-*r*70.0%
associate-*r*70.0%
distribute-rgt-in70.2%
distribute-rgt-out70.2%
metadata-eval70.2%
Simplified70.2%
if 2.79999999999999985e-53 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
prod-diff15.8%
*-commutative15.8%
fma-def15.8%
associate-+l+15.8%
pow215.8%
distribute-lft-neg-in15.8%
*-commutative15.8%
distribute-rgt-neg-in15.8%
metadata-eval15.8%
associate-*r*15.8%
*-commutative15.8%
*-commutative15.8%
fma-udef15.8%
Applied egg-rr15.8%
+-commutative15.8%
associate-+r+15.8%
associate-+l+15.8%
associate-*r*15.8%
associate-*r*15.8%
distribute-lft-out15.8%
metadata-eval15.8%
+-commutative15.8%
unpow215.8%
fma-udef15.8%
associate-*l*15.8%
*-commutative15.8%
Simplified15.8%
associate-*l*15.8%
fma-def15.8%
Applied egg-rr15.8%
clear-num15.8%
inv-pow15.8%
neg-mul-115.8%
fma-def15.8%
Applied egg-rr15.8%
unpow-115.8%
*-lft-identity15.8%
times-frac15.8%
/-rgt-identity15.8%
fma-udef15.8%
*-commutative15.8%
fma-def15.8%
fma-def15.8%
associate-*r*15.8%
*-commutative15.8%
fma-udef15.8%
unpow215.8%
associate-*r*15.8%
*-commutative15.8%
*-commutative15.8%
+-commutative15.8%
Simplified16.1%
Taylor expanded in b around inf 83.0%
+-commutative83.0%
mul-1-neg83.0%
unsub-neg83.0%
Simplified83.0%
Final simplification80.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (/ c b) (/ b a))) (t_1 (* 0.5 (/ (sqrt (* c (* a -4.0))) a))))
(if (<= b -8.6e+38)
t_0
(if (<= b -7.2e+14)
t_1
(if (<= b -1.3e-8)
t_0
(if (<= b 2.55e-51) t_1 (/ 1.0 (- (/ a b) (/ b c)))))))))
double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = 0.5 * (sqrt((c * (a * -4.0))) / a);
double tmp;
if (b <= -8.6e+38) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -1.3e-8) {
tmp = t_0;
} else if (b <= 2.55e-51) {
tmp = t_1;
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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) :: t_1
real(8) :: tmp
t_0 = (c / b) - (b / a)
t_1 = 0.5d0 * (sqrt((c * (a * (-4.0d0)))) / a)
if (b <= (-8.6d+38)) then
tmp = t_0
else if (b <= (-7.2d+14)) then
tmp = t_1
else if (b <= (-1.3d-8)) then
tmp = t_0
else if (b <= 2.55d-51) then
tmp = t_1
else
tmp = 1.0d0 / ((a / b) - (b / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (c / b) - (b / a);
double t_1 = 0.5 * (Math.sqrt((c * (a * -4.0))) / a);
double tmp;
if (b <= -8.6e+38) {
tmp = t_0;
} else if (b <= -7.2e+14) {
tmp = t_1;
} else if (b <= -1.3e-8) {
tmp = t_0;
} else if (b <= 2.55e-51) {
tmp = t_1;
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): t_0 = (c / b) - (b / a) t_1 = 0.5 * (math.sqrt((c * (a * -4.0))) / a) tmp = 0 if b <= -8.6e+38: tmp = t_0 elif b <= -7.2e+14: tmp = t_1 elif b <= -1.3e-8: tmp = t_0 elif b <= 2.55e-51: tmp = t_1 else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) t_0 = Float64(Float64(c / b) - Float64(b / a)) t_1 = Float64(0.5 * Float64(sqrt(Float64(c * Float64(a * -4.0))) / a)) tmp = 0.0 if (b <= -8.6e+38) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -1.3e-8) tmp = t_0; elseif (b <= 2.55e-51) tmp = t_1; else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (c / b) - (b / a); t_1 = 0.5 * (sqrt((c * (a * -4.0))) / a); tmp = 0.0; if (b <= -8.6e+38) tmp = t_0; elseif (b <= -7.2e+14) tmp = t_1; elseif (b <= -1.3e-8) tmp = t_0; elseif (b <= 2.55e-51) tmp = t_1; else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -8.6e+38], t$95$0, If[LessEqual[b, -7.2e+14], t$95$1, If[LessEqual[b, -1.3e-8], t$95$0, If[LessEqual[b, 2.55e-51], t$95$1, N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{b} - \frac{b}{a}\\
t_1 := 0.5 \cdot \frac{\sqrt{c \cdot \left(a \cdot -4\right)}}{a}\\
\mathbf{if}\;b \leq -8.6 \cdot 10^{+38}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq -7.2 \cdot 10^{+14}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq -1.3 \cdot 10^{-8}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 2.55 \cdot 10^{-51}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -8.5999999999999994e38 or -7.2e14 < b < -1.3000000000000001e-8Initial program 64.1%
*-commutative64.1%
Simplified64.1%
Taylor expanded in b around -inf 92.2%
+-commutative92.2%
mul-1-neg92.2%
unsub-neg92.2%
Simplified92.2%
if -8.5999999999999994e38 < b < -7.2e14 or -1.3000000000000001e-8 < b < 2.5499999999999999e-51Initial program 77.2%
*-commutative77.2%
Simplified77.2%
prod-diff76.9%
*-commutative76.9%
fma-def76.9%
associate-+l+76.9%
pow276.9%
distribute-lft-neg-in76.9%
*-commutative76.9%
distribute-rgt-neg-in76.9%
metadata-eval76.9%
associate-*r*76.9%
*-commutative76.9%
*-commutative76.9%
fma-udef76.9%
Applied egg-rr76.9%
+-commutative76.9%
associate-+r+76.9%
associate-+l+76.9%
associate-*r*76.9%
associate-*r*76.9%
distribute-lft-out76.9%
metadata-eval76.9%
+-commutative76.9%
unpow276.9%
fma-udef76.9%
associate-*l*76.9%
*-commutative76.9%
Simplified76.9%
Taylor expanded in b around 0 68.1%
associate-*l/68.3%
*-lft-identity68.3%
associate-*r*68.3%
associate-*r*68.3%
distribute-rgt-in68.6%
distribute-rgt-out68.6%
metadata-eval68.6%
Simplified68.6%
if 2.5499999999999999e-51 < b Initial program 16.1%
*-commutative16.1%
Simplified16.1%
prod-diff15.8%
*-commutative15.8%
fma-def15.8%
associate-+l+15.8%
pow215.8%
distribute-lft-neg-in15.8%
*-commutative15.8%
distribute-rgt-neg-in15.8%
metadata-eval15.8%
associate-*r*15.8%
*-commutative15.8%
*-commutative15.8%
fma-udef15.8%
Applied egg-rr15.8%
+-commutative15.8%
associate-+r+15.8%
associate-+l+15.8%
associate-*r*15.8%
associate-*r*15.8%
distribute-lft-out15.8%
metadata-eval15.8%
+-commutative15.8%
unpow215.8%
fma-udef15.8%
associate-*l*15.8%
*-commutative15.8%
Simplified15.8%
associate-*l*15.8%
fma-def15.8%
Applied egg-rr15.8%
clear-num15.8%
inv-pow15.8%
neg-mul-115.8%
fma-def15.8%
Applied egg-rr15.8%
unpow-115.8%
*-lft-identity15.8%
times-frac15.8%
/-rgt-identity15.8%
fma-udef15.8%
*-commutative15.8%
fma-def15.8%
fma-def15.8%
associate-*r*15.8%
*-commutative15.8%
fma-udef15.8%
unpow215.8%
associate-*r*15.8%
*-commutative15.8%
*-commutative15.8%
+-commutative15.8%
Simplified16.1%
Taylor expanded in b around inf 83.0%
+-commutative83.0%
mul-1-neg83.0%
unsub-neg83.0%
Simplified83.0%
Final simplification79.6%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ 1.0 (- (/ a b) (/ b c)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
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) - (b / a)
else
tmp = 1.0d0 / ((a / b) - (b / c))
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) - (b / a);
} else {
tmp = 1.0 / ((a / b) - (b / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = 1.0 / ((a / b) - (b / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(1.0 / Float64(Float64(a / b) - Float64(b / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = 1.0 / ((a / b) - (b / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(a / b), $MachinePrecision] - N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 62.3%
+-commutative62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
if -4.999999999999985e-310 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
prod-diff33.2%
*-commutative33.2%
fma-def33.2%
associate-+l+33.2%
pow233.2%
distribute-lft-neg-in33.2%
*-commutative33.2%
distribute-rgt-neg-in33.2%
metadata-eval33.2%
associate-*r*33.2%
*-commutative33.2%
*-commutative33.2%
fma-udef33.2%
Applied egg-rr33.2%
+-commutative33.2%
associate-+r+33.2%
associate-+l+33.2%
associate-*r*33.2%
associate-*r*33.2%
distribute-lft-out33.2%
metadata-eval33.2%
+-commutative33.2%
unpow233.2%
fma-udef33.2%
associate-*l*33.2%
*-commutative33.2%
Simplified33.2%
associate-*l*33.2%
fma-def33.2%
Applied egg-rr33.2%
clear-num33.1%
inv-pow33.1%
neg-mul-133.1%
fma-def33.1%
Applied egg-rr33.1%
unpow-133.1%
*-lft-identity33.1%
times-frac33.1%
/-rgt-identity33.1%
fma-udef33.1%
*-commutative33.1%
fma-def33.1%
fma-def33.2%
associate-*r*33.2%
*-commutative33.2%
fma-udef33.1%
unpow233.1%
associate-*r*33.1%
*-commutative33.1%
*-commutative33.1%
+-commutative33.1%
Simplified33.5%
Taylor expanded in b around inf 63.4%
+-commutative63.4%
mul-1-neg63.4%
unsub-neg63.4%
Simplified63.4%
Final simplification62.9%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-5d-310)) then
tmp = (c / b) - (b / a)
else
tmp = -c / b
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) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 62.3%
+-commutative62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
if -4.999999999999985e-310 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
Taylor expanded in b around inf 63.2%
mul-1-neg63.2%
distribute-neg-frac63.2%
Simplified63.2%
Final simplification62.8%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = 0.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) :: tmp
if (b <= (-5d-310)) then
tmp = -b / a
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = -b / a;
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = -b / a; else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 74.5%
*-commutative74.5%
Simplified74.5%
Taylor expanded in b around -inf 62.0%
associate-*r/62.0%
mul-1-neg62.0%
Simplified62.0%
if -4.999999999999985e-310 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
prod-diff33.2%
*-commutative33.2%
fma-def33.2%
associate-+l+33.2%
pow233.2%
distribute-lft-neg-in33.2%
*-commutative33.2%
distribute-rgt-neg-in33.2%
metadata-eval33.2%
associate-*r*33.2%
*-commutative33.2%
*-commutative33.2%
fma-udef33.2%
Applied egg-rr33.2%
+-commutative33.2%
associate-+r+33.2%
associate-+l+33.2%
associate-*r*33.2%
associate-*r*33.2%
distribute-lft-out33.2%
metadata-eval33.2%
+-commutative33.2%
unpow233.2%
fma-udef33.2%
associate-*l*33.2%
*-commutative33.2%
Simplified33.2%
associate-*l*33.2%
fma-def33.2%
Applied egg-rr33.2%
clear-num33.1%
inv-pow33.1%
neg-mul-133.1%
fma-def33.1%
Applied egg-rr33.1%
unpow-133.1%
*-lft-identity33.1%
times-frac33.1%
/-rgt-identity33.1%
fma-udef33.1%
*-commutative33.1%
fma-def33.1%
fma-def33.2%
associate-*r*33.2%
*-commutative33.2%
fma-udef33.1%
unpow233.1%
associate-*r*33.1%
*-commutative33.1%
*-commutative33.1%
+-commutative33.1%
Simplified33.5%
Taylor expanded in a around 0 16.1%
associate-*r/16.1%
distribute-rgt1-in16.1%
metadata-eval16.1%
mul0-lft16.1%
metadata-eval16.1%
Simplified16.1%
Final simplification35.8%
(FPCore (a b c) :precision binary64 (if (<= b 1.35e-290) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.35e-290) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 1.35d-290) then
tmp = -b / a
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 1.35e-290) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.35e-290: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.35e-290) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 1.35e-290) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.35e-290], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.35 \cdot 10^{-290}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.34999999999999999e-290Initial program 74.3%
*-commutative74.3%
Simplified74.3%
Taylor expanded in b around -inf 60.5%
associate-*r/60.5%
mul-1-neg60.5%
Simplified60.5%
if 1.34999999999999999e-290 < b Initial program 32.9%
*-commutative32.9%
Simplified32.9%
Taylor expanded in b around inf 64.5%
mul-1-neg64.5%
distribute-neg-frac64.5%
Simplified64.5%
Final simplification62.7%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 51.2%
*-commutative51.2%
Simplified51.2%
prod-diff50.9%
*-commutative50.9%
fma-def50.9%
associate-+l+50.9%
pow250.9%
distribute-lft-neg-in50.9%
*-commutative50.9%
distribute-rgt-neg-in50.9%
metadata-eval50.9%
associate-*r*50.9%
*-commutative50.9%
*-commutative50.9%
fma-udef50.9%
Applied egg-rr50.9%
+-commutative50.9%
associate-+r+50.9%
associate-+l+50.9%
associate-*r*50.9%
associate-*r*50.9%
distribute-lft-out50.9%
metadata-eval50.9%
+-commutative50.9%
unpow250.9%
fma-udef50.9%
associate-*l*50.9%
*-commutative50.9%
Simplified50.9%
associate-*l*50.9%
fma-def50.9%
Applied egg-rr50.9%
clear-num50.7%
inv-pow50.7%
neg-mul-150.7%
fma-def50.7%
Applied egg-rr50.7%
unpow-150.7%
*-lft-identity50.7%
times-frac50.7%
/-rgt-identity50.7%
fma-udef50.7%
*-commutative50.7%
fma-def50.7%
fma-def50.7%
associate-*r*50.7%
*-commutative50.7%
fma-udef50.7%
unpow250.7%
associate-*r*50.7%
*-commutative50.7%
*-commutative50.7%
+-commutative50.7%
Simplified51.0%
Taylor expanded in a around 0 10.3%
associate-*r/10.3%
distribute-rgt1-in10.3%
metadata-eval10.3%
mul0-lft10.3%
metadata-eval10.3%
Simplified10.3%
Final simplification10.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c)))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2024019
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))