
(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 -7e+69)
(- (/ c b) (/ b a))
(if (<= b 5e+130)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(* (/ 0.5 a) (- b b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7e+69) {
tmp = (c / b) - (b / a);
} else if (b <= 5e+130) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (0.5 / a) * (b - 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 <= (-7d+69)) then
tmp = (c / b) - (b / a)
else if (b <= 5d+130) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = (0.5d0 / a) * (b - b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7e+69) {
tmp = (c / b) - (b / a);
} else if (b <= 5e+130) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = (0.5 / a) * (b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7e+69: tmp = (c / b) - (b / a) elif b <= 5e+130: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = (0.5 / a) * (b - b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7e+69) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 5e+130) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(0.5 / a) * Float64(b - b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -7e+69) tmp = (c / b) - (b / a); elseif (b <= 5e+130) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = (0.5 / a) * (b - b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7e+69], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e+130], 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[(N[(0.5 / a), $MachinePrecision] * N[(b - b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{+69}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+130}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\
\end{array}
\end{array}
if b < -6.99999999999999974e69Initial program 58.2%
*-commutative58.2%
Simplified58.2%
Taylor expanded in b around -inf 94.2%
+-commutative94.2%
mul-1-neg94.2%
unsub-neg94.2%
Simplified94.2%
if -6.99999999999999974e69 < b < 4.9999999999999996e130Initial program 88.2%
if 4.9999999999999996e130 < b Initial program 3.9%
*-commutative3.9%
Simplified3.9%
Applied egg-rr3.2%
sub-neg3.2%
distribute-rgt-out--3.9%
Simplified3.9%
Taylor expanded in a around 0 95.6%
Final simplification90.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))))
(if (<= b -1.1e-19)
(- (/ c b) (/ b a))
(if (<= b -1.12e-38)
t_0
(if (<= b -8.2e-102)
(/ b (- a))
(if (<= b 8.5e-88) t_0 (* (/ 0.5 a) (- b b))))))))
double code(double a, double b, double c) {
double t_0 = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.1e-19) {
tmp = (c / b) - (b / a);
} else if (b <= -1.12e-38) {
tmp = t_0;
} else if (b <= -8.2e-102) {
tmp = b / -a;
} else if (b <= 8.5e-88) {
tmp = t_0;
} else {
tmp = (0.5 / a) * (b - 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) :: tmp
t_0 = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-1.1d-19)) then
tmp = (c / b) - (b / a)
else if (b <= (-1.12d-38)) then
tmp = t_0
else if (b <= (-8.2d-102)) then
tmp = b / -a
else if (b <= 8.5d-88) then
tmp = t_0
else
tmp = (0.5d0 / a) * (b - b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -1.1e-19) {
tmp = (c / b) - (b / a);
} else if (b <= -1.12e-38) {
tmp = t_0;
} else if (b <= -8.2e-102) {
tmp = b / -a;
} else if (b <= 8.5e-88) {
tmp = t_0;
} else {
tmp = (0.5 / a) * (b - b);
}
return tmp;
}
def code(a, b, c): t_0 = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) tmp = 0 if b <= -1.1e-19: tmp = (c / b) - (b / a) elif b <= -1.12e-38: tmp = t_0 elif b <= -8.2e-102: tmp = b / -a elif b <= 8.5e-88: tmp = t_0 else: tmp = (0.5 / a) * (b - b) return tmp
function code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -1.1e-19) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= -1.12e-38) tmp = t_0; elseif (b <= -8.2e-102) tmp = Float64(b / Float64(-a)); elseif (b <= 8.5e-88) tmp = t_0; else tmp = Float64(Float64(0.5 / a) * Float64(b - b)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); tmp = 0.0; if (b <= -1.1e-19) tmp = (c / b) - (b / a); elseif (b <= -1.12e-38) tmp = t_0; elseif (b <= -8.2e-102) tmp = b / -a; elseif (b <= 8.5e-88) tmp = t_0; else tmp = (0.5 / a) * (b - b); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.1e-19], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.12e-38], t$95$0, If[LessEqual[b, -8.2e-102], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 8.5e-88], t$95$0, N[(N[(0.5 / a), $MachinePrecision] * N[(b - b), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.1 \cdot 10^{-19}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq -1.12 \cdot 10^{-38}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -8.2 \cdot 10^{-102}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{-88}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\
\end{array}
\end{array}
if b < -1.0999999999999999e-19Initial program 69.5%
*-commutative69.5%
Simplified69.5%
Taylor expanded in b around -inf 89.9%
+-commutative89.9%
mul-1-neg89.9%
unsub-neg89.9%
Simplified89.9%
if -1.0999999999999999e-19 < b < -1.1200000000000001e-38 or -8.2000000000000005e-102 < b < 8.4999999999999996e-88Initial program 85.3%
*-commutative85.3%
Simplified85.3%
Taylor expanded in b around 0 76.0%
*-commutative76.0%
associate-*r*76.0%
Simplified76.0%
if -1.1200000000000001e-38 < b < -8.2000000000000005e-102Initial program 99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in b around -inf 76.7%
associate-*r/76.7%
mul-1-neg76.7%
Simplified76.7%
if 8.4999999999999996e-88 < b Initial program 39.4%
*-commutative39.4%
Simplified39.4%
Applied egg-rr34.0%
sub-neg34.0%
distribute-rgt-out--39.4%
Simplified39.4%
Taylor expanded in a around 0 87.7%
Final simplification84.6%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ b (- a)) (* (/ 0.5 a) (- b b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = b / -a;
} else {
tmp = (0.5 / a) * (b - 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 = (0.5d0 / a) * (b - 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 = (0.5 / a) * (b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = b / -a else: tmp = (0.5 / a) * (b - b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(b / Float64(-a)); else tmp = Float64(Float64(0.5 / a) * Float64(b - b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = b / -a; else tmp = (0.5 / a) * (b - b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(b / (-a)), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[(b - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in b around -inf 69.9%
associate-*r/69.9%
mul-1-neg69.9%
Simplified69.9%
if -4.999999999999985e-310 < b Initial program 53.8%
*-commutative53.8%
Simplified53.8%
Applied egg-rr50.4%
sub-neg50.4%
distribute-rgt-out--53.9%
Simplified53.9%
Taylor expanded in a around 0 62.3%
Final simplification66.2%
(FPCore (a b c) :precision binary64 (if (<= b -2.2e-231) (- (/ c b) (/ b a)) (* (/ 0.5 a) (- b b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e-231) {
tmp = (c / b) - (b / a);
} else {
tmp = (0.5 / a) * (b - 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.2d-231)) then
tmp = (c / b) - (b / a)
else
tmp = (0.5d0 / a) * (b - b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.2e-231) {
tmp = (c / b) - (b / a);
} else {
tmp = (0.5 / a) * (b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.2e-231: tmp = (c / b) - (b / a) else: tmp = (0.5 / a) * (b - b) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.2e-231) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(0.5 / a) * Float64(b - b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.2e-231) tmp = (c / b) - (b / a); else tmp = (0.5 / a) * (b - b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.2e-231], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[(b - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.2 \cdot 10^{-231}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(b - b\right)\\
\end{array}
\end{array}
if b < -2.20000000000000009e-231Initial program 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in b around -inf 74.8%
+-commutative74.8%
mul-1-neg74.8%
unsub-neg74.8%
Simplified74.8%
if -2.20000000000000009e-231 < b Initial program 57.0%
*-commutative57.0%
Simplified57.0%
Applied egg-rr53.7%
sub-neg53.7%
distribute-rgt-out--57.0%
Simplified57.0%
Taylor expanded in a around 0 58.3%
Final simplification66.3%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ b (- a)) (/ -1.0 (/ b c))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
tmp = b / -a;
} else {
tmp = -1.0 / (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 = b / -a
else
tmp = (-1.0d0) / (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 = b / -a;
} else {
tmp = -1.0 / (b / c);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = b / -a else: tmp = -1.0 / (b / c) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) tmp = Float64(b / Float64(-a)); else tmp = Float64(-1.0 / Float64(b / c)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e-310) tmp = b / -a; else tmp = -1.0 / (b / c); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[(b / (-a)), $MachinePrecision], N[(-1.0 / N[(b / c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{b}{c}}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in b around -inf 69.9%
associate-*r/69.9%
mul-1-neg69.9%
Simplified69.9%
if -4.999999999999985e-310 < b Initial program 53.8%
*-commutative53.8%
Simplified53.8%
Taylor expanded in b around inf 35.2%
add-cbrt-cube49.1%
pow1/346.6%
pow346.6%
*-commutative46.6%
times-frac46.6%
metadata-eval46.6%
associate-/l*45.5%
Applied egg-rr45.5%
unpow1/348.1%
rem-cbrt-cube34.2%
clear-num34.5%
un-div-inv34.5%
*-un-lft-identity34.5%
*-commutative34.5%
times-frac26.2%
clear-num26.2%
Applied egg-rr26.2%
*-inverses26.2%
associate-/r*26.2%
/-rgt-identity26.2%
Simplified26.2%
Final simplification48.9%
(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(b / Float64(-a)); else tmp = Float64(c / Float64(-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 77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in b around -inf 69.9%
associate-*r/69.9%
mul-1-neg69.9%
Simplified69.9%
if -4.999999999999985e-310 < b Initial program 53.8%
*-commutative53.8%
Simplified53.8%
Taylor expanded in b around inf 25.6%
mul-1-neg25.6%
distribute-neg-frac225.6%
Simplified25.6%
Final simplification48.6%
(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 / Float64(-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 66.2%
*-commutative66.2%
Simplified66.2%
Taylor expanded in b around inf 13.5%
mul-1-neg13.5%
distribute-neg-frac213.5%
Simplified13.5%
Final simplification13.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 66.2%
*-commutative66.2%
Simplified66.2%
*-un-lft-identity66.2%
*-un-lft-identity66.2%
prod-diff66.2%
*-commutative66.2%
*-un-lft-identity66.2%
fma-define66.2%
*-un-lft-identity66.2%
+-commutative66.2%
add-sqr-sqrt40.3%
sqrt-unprod52.9%
sqr-neg52.9%
sqrt-prod12.6%
add-sqr-sqrt32.8%
pow232.8%
add-sqr-sqrt20.9%
sqrt-unprod32.8%
sqr-neg32.8%
sqrt-prod12.6%
add-sqr-sqrt32.4%
*-commutative32.4%
*-un-lft-identity32.4%
Applied egg-rr32.4%
+-commutative32.4%
associate-+l+32.4%
fma-undefine32.4%
*-rgt-identity32.4%
Simplified32.4%
Taylor expanded in b around -inf 2.4%
Final simplification2.4%
(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 2024046
(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)))