
(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 -2e+123)
(- (/ c b) (/ b a))
(if (<= b 5.8e-162)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+123) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-162) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} 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 <= (-2d+123)) then
tmp = (c / b) - (b / a)
else if (b <= 5.8d-162) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e+123) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-162) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+123: tmp = (c / b) - (b / a) elif b <= 5.8e-162: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+123) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.8e-162) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2e+123) tmp = (c / b) - (b / a); elseif (b <= 5.8e-162) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+123], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-162], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+123}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-162}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.99999999999999996e123Initial program 58.4%
/-rgt-identity58.4%
metadata-eval58.4%
associate-/l*58.4%
associate-*r/58.3%
+-commutative58.3%
unsub-neg58.3%
fma-neg58.3%
associate-*l*58.3%
*-commutative58.3%
distribute-rgt-neg-in58.3%
metadata-eval58.3%
associate-/r*58.3%
metadata-eval58.3%
metadata-eval58.3%
Simplified58.3%
Taylor expanded in b around -inf 95.2%
mul-1-neg95.2%
unsub-neg95.2%
Simplified95.2%
if -1.99999999999999996e123 < b < 5.8000000000000002e-162Initial program 85.1%
if 5.8000000000000002e-162 < b Initial program 22.2%
/-rgt-identity22.2%
metadata-eval22.2%
associate-/l*22.2%
associate-*r/22.1%
+-commutative22.1%
unsub-neg22.1%
fma-neg22.1%
associate-*l*22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
metadata-eval22.1%
associate-/r*22.1%
metadata-eval22.1%
metadata-eval22.1%
Simplified22.1%
Taylor expanded in b around inf 76.3%
mul-1-neg76.3%
distribute-neg-frac76.3%
Simplified76.3%
Final simplification83.8%
(FPCore (a b c)
:precision binary64
(if (<= b -3.7e-39)
(- (/ c b) (/ b a))
(if (<= b 5.8e-162)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-39) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-162) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} 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 <= (-3.7d-39)) then
tmp = (c / b) - (b / a)
else if (b <= 5.8d-162) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.7e-39) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-162) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.7e-39: tmp = (c / b) - (b / a) elif b <= 5.8e-162: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.7e-39) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.8e-162) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.7e-39) tmp = (c / b) - (b / a); elseif (b <= 5.8e-162) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.7e-39], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-162], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.7 \cdot 10^{-39}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-162}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.70000000000000015e-39Initial program 71.5%
/-rgt-identity71.5%
metadata-eval71.5%
associate-/l*71.5%
associate-*r/71.2%
+-commutative71.2%
unsub-neg71.2%
fma-neg71.2%
associate-*l*71.2%
*-commutative71.2%
distribute-rgt-neg-in71.2%
metadata-eval71.2%
associate-/r*71.2%
metadata-eval71.2%
metadata-eval71.2%
Simplified71.2%
Taylor expanded in b around -inf 90.7%
mul-1-neg90.7%
unsub-neg90.7%
Simplified90.7%
if -3.70000000000000015e-39 < b < 5.8000000000000002e-162Initial program 80.4%
*-un-lft-identity80.4%
prod-diff80.0%
Applied egg-rr80.0%
+-commutative80.0%
fma-udef80.0%
*-rgt-identity80.0%
*-rgt-identity80.0%
distribute-lft-out80.1%
fma-def80.0%
distribute-lft-out80.0%
metadata-eval80.0%
*-rgt-identity80.0%
associate-*r*79.9%
distribute-rgt-neg-in79.9%
metadata-eval79.9%
*-commutative79.9%
associate-*l*80.0%
Simplified80.0%
Taylor expanded in b around 0 70.2%
mul-1-neg70.2%
unsub-neg70.2%
distribute-rgt-out70.7%
*-commutative70.7%
metadata-eval70.7%
associate-*r*70.7%
Simplified70.7%
if 5.8000000000000002e-162 < b Initial program 22.2%
/-rgt-identity22.2%
metadata-eval22.2%
associate-/l*22.2%
associate-*r/22.1%
+-commutative22.1%
unsub-neg22.1%
fma-neg22.1%
associate-*l*22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
metadata-eval22.1%
associate-/r*22.1%
metadata-eval22.1%
metadata-eval22.1%
Simplified22.1%
Taylor expanded in b around inf 76.3%
mul-1-neg76.3%
distribute-neg-frac76.3%
Simplified76.3%
Final simplification80.0%
(FPCore (a b c) :precision binary64 (if (<= b -2.35e-39) (- (/ c b) (/ b a)) (if (<= b 5.8e-162) (* 0.5 (/ (sqrt (* a (* c -4.0))) a)) (/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.35e-39) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-162) {
tmp = 0.5 * (sqrt((a * (c * -4.0))) / 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 <= (-2.35d-39)) then
tmp = (c / b) - (b / a)
else if (b <= 5.8d-162) then
tmp = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / 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 <= -2.35e-39) {
tmp = (c / b) - (b / a);
} else if (b <= 5.8e-162) {
tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.35e-39: tmp = (c / b) - (b / a) elif b <= 5.8e-162: tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.35e-39) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5.8e-162) tmp = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.35e-39) tmp = (c / b) - (b / a); elseif (b <= 5.8e-162) tmp = 0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.35e-39], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.8e-162], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.35 \cdot 10^{-39}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5.8 \cdot 10^{-162}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.3500000000000001e-39Initial program 71.5%
/-rgt-identity71.5%
metadata-eval71.5%
associate-/l*71.5%
associate-*r/71.2%
+-commutative71.2%
unsub-neg71.2%
fma-neg71.2%
associate-*l*71.2%
*-commutative71.2%
distribute-rgt-neg-in71.2%
metadata-eval71.2%
associate-/r*71.2%
metadata-eval71.2%
metadata-eval71.2%
Simplified71.2%
Taylor expanded in b around -inf 90.7%
mul-1-neg90.7%
unsub-neg90.7%
Simplified90.7%
if -2.3500000000000001e-39 < b < 5.8000000000000002e-162Initial program 80.4%
*-un-lft-identity80.4%
prod-diff80.0%
Applied egg-rr80.0%
+-commutative80.0%
fma-udef80.0%
*-rgt-identity80.0%
*-rgt-identity80.0%
distribute-lft-out80.1%
fma-def80.0%
distribute-lft-out80.0%
metadata-eval80.0%
*-rgt-identity80.0%
associate-*r*79.9%
distribute-rgt-neg-in79.9%
metadata-eval79.9%
*-commutative79.9%
associate-*l*80.0%
Simplified80.0%
Taylor expanded in b around 0 68.4%
associate-*l/68.5%
*-lft-identity68.5%
distribute-rgt-out69.0%
*-commutative69.0%
metadata-eval69.0%
associate-*r*69.0%
Simplified69.0%
if 5.8000000000000002e-162 < b Initial program 22.2%
/-rgt-identity22.2%
metadata-eval22.2%
associate-/l*22.2%
associate-*r/22.1%
+-commutative22.1%
unsub-neg22.1%
fma-neg22.1%
associate-*l*22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
metadata-eval22.1%
associate-/r*22.1%
metadata-eval22.1%
metadata-eval22.1%
Simplified22.1%
Taylor expanded in b around inf 76.3%
mul-1-neg76.3%
distribute-neg-frac76.3%
Simplified76.3%
Final simplification79.5%
(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 75.6%
/-rgt-identity75.6%
metadata-eval75.6%
associate-/l*75.6%
associate-*r/75.5%
+-commutative75.5%
unsub-neg75.5%
fma-neg75.5%
associate-*l*75.4%
*-commutative75.4%
distribute-rgt-neg-in75.4%
metadata-eval75.4%
associate-/r*75.4%
metadata-eval75.4%
metadata-eval75.4%
Simplified75.4%
Taylor expanded in b around -inf 66.0%
mul-1-neg66.0%
unsub-neg66.0%
Simplified66.0%
if -4.999999999999985e-310 < b Initial program 27.9%
/-rgt-identity27.9%
metadata-eval27.9%
associate-/l*27.9%
associate-*r/27.8%
+-commutative27.8%
unsub-neg27.8%
fma-neg27.8%
associate-*l*27.8%
*-commutative27.8%
distribute-rgt-neg-in27.8%
metadata-eval27.8%
associate-/r*27.8%
metadata-eval27.8%
metadata-eval27.8%
Simplified27.8%
Taylor expanded in b around inf 67.7%
mul-1-neg67.7%
distribute-neg-frac67.7%
Simplified67.7%
Final simplification66.8%
(FPCore (a b c) :precision binary64 (if (<= b 4.4e-26) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.4e-26) {
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 <= 4.4d-26) 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 <= 4.4e-26) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.4e-26: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.4e-26) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4.4e-26) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.4e-26], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.4 \cdot 10^{-26}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 4.4000000000000002e-26Initial program 68.9%
/-rgt-identity68.9%
metadata-eval68.9%
associate-/l*68.9%
associate-*r/68.7%
+-commutative68.7%
unsub-neg68.7%
fma-neg68.7%
associate-*l*68.7%
*-commutative68.7%
distribute-rgt-neg-in68.7%
metadata-eval68.7%
associate-/r*68.7%
metadata-eval68.7%
metadata-eval68.7%
Simplified68.7%
Taylor expanded in b around -inf 50.1%
associate-*r/50.1%
mul-1-neg50.1%
Simplified50.1%
if 4.4000000000000002e-26 < b Initial program 15.3%
/-rgt-identity15.3%
metadata-eval15.3%
associate-/l*15.3%
associate-*r/15.3%
+-commutative15.3%
unsub-neg15.3%
fma-neg15.3%
associate-*l*15.3%
*-commutative15.3%
distribute-rgt-neg-in15.3%
metadata-eval15.3%
associate-/r*15.3%
metadata-eval15.3%
metadata-eval15.3%
Simplified15.3%
Taylor expanded in b around -inf 2.3%
mul-1-neg2.3%
unsub-neg2.3%
associate-*r/2.3%
Simplified2.3%
Taylor expanded in c around inf 34.6%
Final simplification45.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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 <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 75.6%
/-rgt-identity75.6%
metadata-eval75.6%
associate-/l*75.6%
associate-*r/75.5%
+-commutative75.5%
unsub-neg75.5%
fma-neg75.5%
associate-*l*75.4%
*-commutative75.4%
distribute-rgt-neg-in75.4%
metadata-eval75.4%
associate-/r*75.4%
metadata-eval75.4%
metadata-eval75.4%
Simplified75.4%
Taylor expanded in b around -inf 65.5%
associate-*r/65.5%
mul-1-neg65.5%
Simplified65.5%
if -4.999999999999985e-310 < b Initial program 27.9%
/-rgt-identity27.9%
metadata-eval27.9%
associate-/l*27.9%
associate-*r/27.8%
+-commutative27.8%
unsub-neg27.8%
fma-neg27.8%
associate-*l*27.8%
*-commutative27.8%
distribute-rgt-neg-in27.8%
metadata-eval27.8%
associate-/r*27.8%
metadata-eval27.8%
metadata-eval27.8%
Simplified27.8%
Taylor expanded in b around inf 67.7%
mul-1-neg67.7%
distribute-neg-frac67.7%
Simplified67.7%
Final simplification66.5%
(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 53.8%
/-rgt-identity53.8%
metadata-eval53.8%
associate-/l*53.8%
associate-*r/53.7%
+-commutative53.7%
unsub-neg53.7%
fma-neg53.7%
associate-*l*53.7%
*-commutative53.7%
distribute-rgt-neg-in53.7%
metadata-eval53.7%
associate-/r*53.7%
metadata-eval53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in b around -inf 36.2%
mul-1-neg36.2%
unsub-neg36.2%
associate-*r/36.2%
Simplified36.2%
expm1-log1p-u19.0%
expm1-udef16.4%
Applied egg-rr2.7%
expm1-def1.5%
expm1-log1p2.2%
associate-+l+2.2%
*-commutative2.2%
associate-*r/2.2%
associate-/l*2.2%
count-22.2%
distribute-lft-out2.2%
associate-/l*2.2%
*-commutative2.2%
Simplified2.2%
Taylor expanded in a around 0 2.3%
Final simplification2.3%
(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 53.8%
/-rgt-identity53.8%
metadata-eval53.8%
associate-/l*53.8%
associate-*r/53.7%
+-commutative53.7%
unsub-neg53.7%
fma-neg53.7%
associate-*l*53.7%
*-commutative53.7%
distribute-rgt-neg-in53.7%
metadata-eval53.7%
associate-/r*53.7%
metadata-eval53.7%
metadata-eval53.7%
Simplified53.7%
Taylor expanded in b around -inf 36.2%
mul-1-neg36.2%
unsub-neg36.2%
associate-*r/36.2%
Simplified36.2%
Taylor expanded in c around inf 12.1%
Final simplification12.1%
herbie shell --seed 2023189
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))