
(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 7 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 (* a 4.0))) (t_1 (sqrt (- (* b b) t_0))))
(if (<= b -2e+154)
(/ (- b) a)
(if (<= b 1.65e-209)
(/ (- t_1 b) (* a 2.0))
(if (<= b 1.95e-16)
(/ (/ (+ t_0 (- (* b b) (* b b))) (- (- b) t_1)) (* a 2.0))
(/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double t_1 = sqrt(((b * b) - t_0));
double tmp;
if (b <= -2e+154) {
tmp = -b / a;
} else if (b <= 1.65e-209) {
tmp = (t_1 - b) / (a * 2.0);
} else if (b <= 1.95e-16) {
tmp = ((t_0 + ((b * b) - (b * b))) / (-b - t_1)) / (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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = c * (a * 4.0d0)
t_1 = sqrt(((b * b) - t_0))
if (b <= (-2d+154)) then
tmp = -b / a
else if (b <= 1.65d-209) then
tmp = (t_1 - b) / (a * 2.0d0)
else if (b <= 1.95d-16) then
tmp = ((t_0 + ((b * b) - (b * b))) / (-b - t_1)) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = c * (a * 4.0);
double t_1 = Math.sqrt(((b * b) - t_0));
double tmp;
if (b <= -2e+154) {
tmp = -b / a;
} else if (b <= 1.65e-209) {
tmp = (t_1 - b) / (a * 2.0);
} else if (b <= 1.95e-16) {
tmp = ((t_0 + ((b * b) - (b * b))) / (-b - t_1)) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): t_0 = c * (a * 4.0) t_1 = math.sqrt(((b * b) - t_0)) tmp = 0 if b <= -2e+154: tmp = -b / a elif b <= 1.65e-209: tmp = (t_1 - b) / (a * 2.0) elif b <= 1.95e-16: tmp = ((t_0 + ((b * b) - (b * b))) / (-b - t_1)) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) t_0 = Float64(c * Float64(a * 4.0)) t_1 = sqrt(Float64(Float64(b * b) - t_0)) tmp = 0.0 if (b <= -2e+154) tmp = Float64(Float64(-b) / a); elseif (b <= 1.65e-209) tmp = Float64(Float64(t_1 - b) / Float64(a * 2.0)); elseif (b <= 1.95e-16) tmp = Float64(Float64(Float64(t_0 + Float64(Float64(b * b) - Float64(b * b))) / Float64(Float64(-b) - t_1)) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) t_0 = c * (a * 4.0); t_1 = sqrt(((b * b) - t_0)); tmp = 0.0; if (b <= -2e+154) tmp = -b / a; elseif (b <= 1.65e-209) tmp = (t_1 - b) / (a * 2.0); elseif (b <= 1.95e-16) tmp = ((t_0 + ((b * b) - (b * b))) / (-b - t_1)) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2e+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.65e-209], N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.95e-16], N[(N[(N[(t$95$0 + N[(N[(b * b), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot 4\right)\\
t_1 := \sqrt{b \cdot b - t_0}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{-209}:\\
\;\;\;\;\frac{t_1 - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.95 \cdot 10^{-16}:\\
\;\;\;\;\frac{\frac{t_0 + \left(b \cdot b - b \cdot b\right)}{\left(-b\right) - t_1}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.00000000000000007e154Initial program 54.2%
/-rgt-identity54.2%
metadata-eval54.2%
associate-/l*54.2%
associate-*r/54.2%
+-commutative54.2%
unsub-neg54.2%
fma-neg54.2%
*-commutative54.2%
distribute-rgt-neg-in54.2%
associate-*l*54.2%
metadata-eval54.2%
associate-/r*54.2%
metadata-eval54.2%
metadata-eval54.2%
Simplified54.2%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -2.00000000000000007e154 < b < 1.64999999999999987e-209Initial program 91.9%
Taylor expanded in a around 0 91.9%
*-commutative91.9%
associate-*l*91.9%
Simplified91.9%
div-inv91.7%
+-commutative91.7%
*-commutative91.7%
Applied egg-rr91.7%
associate-*r/91.9%
*-rgt-identity91.9%
unsub-neg91.9%
Simplified91.9%
if 1.64999999999999987e-209 < b < 1.94999999999999989e-16Initial program 51.8%
Taylor expanded in a around 0 51.8%
*-commutative51.8%
associate-*l*51.8%
Simplified51.8%
flip-+51.9%
add-sqr-sqrt51.8%
Applied egg-rr51.8%
sqr-neg51.8%
associate-+l-73.7%
Simplified73.7%
if 1.94999999999999989e-16 < b Initial program 10.0%
/-rgt-identity10.0%
metadata-eval10.0%
associate-/l*10.0%
associate-*r/10.0%
+-commutative10.0%
unsub-neg10.0%
fma-neg10.0%
*-commutative10.0%
distribute-rgt-neg-in10.0%
associate-*l*10.0%
metadata-eval10.0%
associate-/r*10.0%
metadata-eval10.0%
metadata-eval10.0%
Simplified10.0%
Taylor expanded in b around inf 98.7%
mul-1-neg98.7%
distribute-neg-frac98.7%
Simplified98.7%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(if (<= b -2e+154)
(/ (- b) a)
(if (<= b 2.75e-108)
(/ (- (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+154) {
tmp = -b / a;
} else if (b <= 2.75e-108) {
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+154)) then
tmp = -b / a
else if (b <= 2.75d-108) 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+154) {
tmp = -b / a;
} else if (b <= 2.75e-108) {
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+154: tmp = -b / a elif b <= 2.75e-108: 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+154) tmp = Float64(Float64(-b) / a); elseif (b <= 2.75e-108) 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+154) tmp = -b / a; elseif (b <= 2.75e-108) 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+154], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.75e-108], 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^{+154}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.75 \cdot 10^{-108}:\\
\;\;\;\;\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 < -2.00000000000000007e154Initial program 54.2%
/-rgt-identity54.2%
metadata-eval54.2%
associate-/l*54.2%
associate-*r/54.2%
+-commutative54.2%
unsub-neg54.2%
fma-neg54.2%
*-commutative54.2%
distribute-rgt-neg-in54.2%
associate-*l*54.2%
metadata-eval54.2%
associate-/r*54.2%
metadata-eval54.2%
metadata-eval54.2%
Simplified54.2%
Taylor expanded in b around -inf 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
if -2.00000000000000007e154 < b < 2.75000000000000016e-108Initial program 88.1%
Taylor expanded in a around 0 88.1%
*-commutative88.1%
associate-*l*88.2%
Simplified88.2%
div-inv88.0%
+-commutative88.0%
*-commutative88.0%
Applied egg-rr88.0%
associate-*r/88.2%
*-rgt-identity88.2%
unsub-neg88.2%
Simplified88.2%
if 2.75000000000000016e-108 < b Initial program 19.1%
/-rgt-identity19.1%
metadata-eval19.1%
associate-/l*19.1%
associate-*r/19.1%
+-commutative19.1%
unsub-neg19.1%
fma-neg19.1%
*-commutative19.1%
distribute-rgt-neg-in19.1%
associate-*l*19.1%
metadata-eval19.1%
associate-/r*19.1%
metadata-eval19.1%
metadata-eval19.1%
Simplified19.1%
Taylor expanded in b around inf 88.6%
mul-1-neg88.6%
distribute-neg-frac88.6%
Simplified88.6%
Final simplification90.2%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (fma 2.0 (/ c (/ b a)) (* b -2.0)) (* a 2.0)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-310) {
tmp = fma(2.0, (c / (b / a)), (b * -2.0)) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -4e-310) tmp = Float64(fma(2.0, Float64(c / Float64(b / a)), Float64(b * -2.0)) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[(N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] + N[(b * -2.0), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, b \cdot -2\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 80.2%
Taylor expanded in a around 0 80.2%
*-commutative80.2%
associate-*l*80.2%
Simplified80.2%
Taylor expanded in b around -inf 79.6%
fma-def79.6%
associate-/l*79.7%
*-commutative79.7%
Simplified79.7%
if -3.999999999999988e-310 < b Initial program 32.6%
/-rgt-identity32.6%
metadata-eval32.6%
associate-/l*32.6%
associate-*r/32.6%
+-commutative32.6%
unsub-neg32.6%
fma-neg32.6%
*-commutative32.6%
distribute-rgt-neg-in32.6%
associate-*l*32.6%
metadata-eval32.6%
associate-/r*32.6%
metadata-eval32.6%
metadata-eval32.6%
Simplified32.6%
Taylor expanded in b around inf 72.2%
mul-1-neg72.2%
distribute-neg-frac72.2%
Simplified72.2%
Final simplification75.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 80.2%
/-rgt-identity80.2%
metadata-eval80.2%
associate-/l*80.2%
associate-*r/80.0%
+-commutative80.0%
unsub-neg80.0%
fma-neg80.0%
*-commutative80.0%
distribute-rgt-neg-in80.0%
associate-*l*80.1%
metadata-eval80.1%
associate-/r*80.1%
metadata-eval80.1%
metadata-eval80.1%
Simplified80.1%
Taylor expanded in b around -inf 79.7%
mul-1-neg79.7%
unsub-neg79.7%
Simplified79.7%
if -3.999999999999988e-310 < b Initial program 32.6%
/-rgt-identity32.6%
metadata-eval32.6%
associate-/l*32.6%
associate-*r/32.6%
+-commutative32.6%
unsub-neg32.6%
fma-neg32.6%
*-commutative32.6%
distribute-rgt-neg-in32.6%
associate-*l*32.6%
metadata-eval32.6%
associate-/r*32.6%
metadata-eval32.6%
metadata-eval32.6%
Simplified32.6%
Taylor expanded in b around inf 72.2%
mul-1-neg72.2%
distribute-neg-frac72.2%
Simplified72.2%
Final simplification75.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 80.2%
/-rgt-identity80.2%
metadata-eval80.2%
associate-/l*80.2%
associate-*r/80.0%
+-commutative80.0%
unsub-neg80.0%
fma-neg80.0%
*-commutative80.0%
distribute-rgt-neg-in80.0%
associate-*l*80.1%
metadata-eval80.1%
associate-/r*80.1%
metadata-eval80.1%
metadata-eval80.1%
Simplified80.1%
Taylor expanded in b around -inf 79.3%
associate-*r/79.3%
mul-1-neg79.3%
Simplified79.3%
if -3.999999999999988e-310 < b Initial program 32.6%
/-rgt-identity32.6%
metadata-eval32.6%
associate-/l*32.6%
associate-*r/32.6%
+-commutative32.6%
unsub-neg32.6%
fma-neg32.6%
*-commutative32.6%
distribute-rgt-neg-in32.6%
associate-*l*32.6%
metadata-eval32.6%
associate-/r*32.6%
metadata-eval32.6%
metadata-eval32.6%
Simplified32.6%
Taylor expanded in b around inf 72.2%
mul-1-neg72.2%
distribute-neg-frac72.2%
Simplified72.2%
Final simplification75.7%
(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(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 56.4%
/-rgt-identity56.4%
metadata-eval56.4%
associate-/l*56.4%
associate-*r/56.3%
+-commutative56.3%
unsub-neg56.3%
fma-neg56.3%
*-commutative56.3%
distribute-rgt-neg-in56.3%
associate-*l*56.3%
metadata-eval56.3%
associate-/r*56.3%
metadata-eval56.3%
metadata-eval56.3%
Simplified56.3%
Taylor expanded in b around -inf 40.7%
associate-*r/40.7%
mul-1-neg40.7%
Simplified40.7%
Final simplification40.7%
(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 56.4%
/-rgt-identity56.4%
metadata-eval56.4%
associate-/l*56.4%
associate-*r/56.3%
+-commutative56.3%
unsub-neg56.3%
fma-neg56.3%
*-commutative56.3%
distribute-rgt-neg-in56.3%
associate-*l*56.3%
metadata-eval56.3%
associate-/r*56.3%
metadata-eval56.3%
metadata-eval56.3%
Simplified56.3%
*-un-lft-identity56.3%
*-un-lft-identity56.3%
prod-diff56.3%
Applied egg-rr23.8%
+-commutative23.8%
associate-+l+23.8%
fma-udef23.8%
*-rgt-identity23.8%
Simplified23.8%
Taylor expanded in b around -inf 2.0%
Final simplification2.0%
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $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 - 4 \cdot \left(a \cdot c\right)}\\
\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 2023278
(FPCore (a b c)
:name "quadp (p42, positive)"
: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)))