| Alternative 1 | |
|---|---|
| Error | 10.2 |
| Cost | 7624 |
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (sqrt (+ (* b b) (* (* a c) -4.0))) b) (* a 2.0))))
(if (<= b -8e+143)
(/ (- b) a)
(if (<= b 1.2e-181)
t_0
(if (<= b 9.5e-117)
(*
0.5
(/ (- (pow (exp (* 0.25 (+ (log c) (log (* a -4.0))))) 2.0) b) a))
(if (<= b 1.7e-26) t_0 (/ (- c) b)))))))double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a);
}
double code(double a, double b, double c) {
double t_0 = (sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -8e+143) {
tmp = -b / a;
} else if (b <= 1.2e-181) {
tmp = t_0;
} else if (b <= 9.5e-117) {
tmp = 0.5 * ((pow(exp((0.25 * (log(c) + log((a * -4.0))))), 2.0) - b) / a);
} else if (b <= 1.7e-26) {
tmp = t_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
code = (-b + sqrt(((b * b) - (4.0d0 * (a * c))))) / (2.0d0 * a)
end function
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) + ((a * c) * (-4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-8d+143)) then
tmp = -b / a
else if (b <= 1.2d-181) then
tmp = t_0
else if (b <= 9.5d-117) then
tmp = 0.5d0 * (((exp((0.25d0 * (log(c) + log((a * (-4.0d0)))))) ** 2.0d0) - b) / a)
else if (b <= 1.7d-26) then
tmp = t_0
else
tmp = -c / b
end if
code = tmp
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);
}
public static double code(double a, double b, double c) {
double t_0 = (Math.sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0);
double tmp;
if (b <= -8e+143) {
tmp = -b / a;
} else if (b <= 1.2e-181) {
tmp = t_0;
} else if (b <= 9.5e-117) {
tmp = 0.5 * ((Math.pow(Math.exp((0.25 * (Math.log(c) + Math.log((a * -4.0))))), 2.0) - b) / a);
} else if (b <= 1.7e-26) {
tmp = t_0;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a)
def code(a, b, c): t_0 = (math.sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0) tmp = 0 if b <= -8e+143: tmp = -b / a elif b <= 1.2e-181: tmp = t_0 elif b <= 9.5e-117: tmp = 0.5 * ((math.pow(math.exp((0.25 * (math.log(c) + math.log((a * -4.0))))), 2.0) - b) / a) elif b <= 1.7e-26: tmp = t_0 else: tmp = -c / b return tmp
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 code(a, b, c) t_0 = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(Float64(a * c) * -4.0))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -8e+143) tmp = Float64(Float64(-b) / a); elseif (b <= 1.2e-181) tmp = t_0; elseif (b <= 9.5e-117) tmp = Float64(0.5 * Float64(Float64((exp(Float64(0.25 * Float64(log(c) + log(Float64(a * -4.0))))) ^ 2.0) - b) / a)); elseif (b <= 1.7e-26) tmp = t_0; else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - (4.0 * (a * c))))) / (2.0 * a); end
function tmp_2 = code(a, b, c) t_0 = (sqrt(((b * b) + ((a * c) * -4.0))) - b) / (a * 2.0); tmp = 0.0; if (b <= -8e+143) tmp = -b / a; elseif (b <= 1.2e-181) tmp = t_0; elseif (b <= 9.5e-117) tmp = 0.5 * (((exp((0.25 * (log(c) + log((a * -4.0))))) ^ 2.0) - b) / a); elseif (b <= 1.7e-26) tmp = t_0; else tmp = -c / b; end tmp_2 = tmp; 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]
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -8e+143], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.2e-181], t$95$0, If[LessEqual[b, 9.5e-117], N[(0.5 * N[(N[(N[Power[N[Exp[N[(0.25 * N[(N[Log[c], $MachinePrecision] + N[Log[N[(a * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.7e-26], t$95$0, N[((-c) / b), $MachinePrecision]]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{\sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -8 \cdot 10^{+143}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-181}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 9.5 \cdot 10^{-117}:\\
\;\;\;\;0.5 \cdot \frac{{\left(e^{0.25 \cdot \left(\log c + \log \left(a \cdot -4\right)\right)}\right)}^{2} - b}{a}\\
\mathbf{elif}\;b \leq 1.7 \cdot 10^{-26}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
Results
| Original | 34.3 |
|---|---|
| Target | 21.3 |
| Herbie | 11.0 |
if b < -8.0000000000000002e143Initial program 60.3
Simplified60.3
[Start]60.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]60.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]60.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]60.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]60.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]60.3 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{--1}{2}}{a}}
\] |
associate-*r/ [<=]60.3 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
/-rgt-identity [<=]60.3 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [<=]60.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Taylor expanded in b around -inf 3.0
Simplified3.0
[Start]3.0 | \[ -1 \cdot \frac{b}{a}
\] |
|---|---|
associate-*r/ [=>]3.0 | \[ \color{blue}{\frac{-1 \cdot b}{a}}
\] |
mul-1-neg [=>]3.0 | \[ \frac{\color{blue}{-b}}{a}
\] |
if -8.0000000000000002e143 < b < 1.2000000000000001e-181 or 9.5000000000000004e-117 < b < 1.70000000000000007e-26Initial program 13.5
if 1.2000000000000001e-181 < b < 9.5000000000000004e-117Initial program 22.3
Simplified22.3
[Start]22.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]22.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{2 \cdot a}{1}}}
\] |
metadata-eval [<=]22.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{2 \cdot a}{\color{blue}{--1}}}
\] |
*-commutative [=>]22.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\frac{\color{blue}{a \cdot 2}}{--1}}
\] |
associate-/l* [=>]22.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{\frac{a}{\frac{--1}{2}}}}
\] |
associate-/l* [<=]22.3 | \[ \color{blue}{\frac{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{--1}{2}}{a}}
\] |
associate-*r/ [<=]22.3 | \[ \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{\frac{--1}{2}}{a}}
\] |
/-rgt-identity [<=]22.3 | \[ \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
metadata-eval [<=]22.3 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{\color{blue}{--1}} \cdot \frac{\frac{--1}{2}}{a}
\] |
Applied egg-rr22.4
Taylor expanded in b around 0 23.1
Simplified23.1
[Start]23.1 | \[ \left({\left({\left(-4 \cdot \left(c \cdot a\right)\right)}^{0.25}\right)}^{2} - b\right) \cdot \frac{0.5}{a}
\] |
|---|---|
*-commutative [=>]23.1 | \[ \left({\left({\color{blue}{\left(\left(c \cdot a\right) \cdot -4\right)}}^{0.25}\right)}^{2} - b\right) \cdot \frac{0.5}{a}
\] |
*-commutative [=>]23.1 | \[ \left({\left({\left(\color{blue}{\left(a \cdot c\right)} \cdot -4\right)}^{0.25}\right)}^{2} - b\right) \cdot \frac{0.5}{a}
\] |
associate-*r* [<=]23.1 | \[ \left({\left({\color{blue}{\left(a \cdot \left(c \cdot -4\right)\right)}}^{0.25}\right)}^{2} - b\right) \cdot \frac{0.5}{a}
\] |
Taylor expanded in c around 0 42.9
if 1.70000000000000007e-26 < b Initial program 54.5
Taylor expanded in b around inf 6.6
Simplified6.6
[Start]6.6 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
associate-*r/ [=>]6.6 | \[ \color{blue}{\frac{-1 \cdot c}{b}}
\] |
neg-mul-1 [<=]6.6 | \[ \frac{\color{blue}{-c}}{b}
\] |
Final simplification11.0
| Alternative 1 | |
|---|---|
| Error | 10.2 |
| Cost | 7624 |
| Alternative 2 | |
|---|---|
| Error | 10.2 |
| Cost | 7624 |
| Alternative 3 | |
|---|---|
| Error | 13.8 |
| Cost | 7368 |
| Alternative 4 | |
|---|---|
| Error | 13.8 |
| Cost | 7368 |
| Alternative 5 | |
|---|---|
| Error | 39.2 |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Error | 22.3 |
| Cost | 388 |
| Alternative 7 | |
|---|---|
| Error | 56.4 |
| Cost | 64 |
herbie shell --seed 2023056
(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)))