| Alternative 1 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 33480 |
(FPCore (x y z t a b) :precision binary64 (/ (* x (exp (- (+ (* y (log z)) (* (- t 1.0) (log a))) b))) y))
(FPCore (x y z t a b)
:precision binary64
(let* ((t_1 (* (+ t -1.0) (log a))))
(if (<= t_1 -20000000.0)
(/ (* (pow a (+ t -1.0)) x) y)
(if (<= t_1 -440.0)
(/ x (* a (* y (+ 1.0 (+ b (* 0.5 (* b b)))))))
(/ (* x (exp (- (+ t_1 (* y (log z))) b))) y)))))double code(double x, double y, double z, double t, double a, double b) {
return (x * exp((((y * log(z)) + ((t - 1.0) * log(a))) - b))) / y;
}
double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (t + -1.0) * log(a);
double tmp;
if (t_1 <= -20000000.0) {
tmp = (pow(a, (t + -1.0)) * x) / y;
} else if (t_1 <= -440.0) {
tmp = x / (a * (y * (1.0 + (b + (0.5 * (b * b))))));
} else {
tmp = (x * exp(((t_1 + (y * log(z))) - b))) / y;
}
return tmp;
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (x * exp((((y * log(z)) + ((t - 1.0d0) * log(a))) - b))) / y
end function
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_1
real(8) :: tmp
t_1 = (t + (-1.0d0)) * log(a)
if (t_1 <= (-20000000.0d0)) then
tmp = ((a ** (t + (-1.0d0))) * x) / y
else if (t_1 <= (-440.0d0)) then
tmp = x / (a * (y * (1.0d0 + (b + (0.5d0 * (b * b))))))
else
tmp = (x * exp(((t_1 + (y * log(z))) - b))) / y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x * Math.exp((((y * Math.log(z)) + ((t - 1.0) * Math.log(a))) - b))) / y;
}
public static double code(double x, double y, double z, double t, double a, double b) {
double t_1 = (t + -1.0) * Math.log(a);
double tmp;
if (t_1 <= -20000000.0) {
tmp = (Math.pow(a, (t + -1.0)) * x) / y;
} else if (t_1 <= -440.0) {
tmp = x / (a * (y * (1.0 + (b + (0.5 * (b * b))))));
} else {
tmp = (x * Math.exp(((t_1 + (y * Math.log(z))) - b))) / y;
}
return tmp;
}
def code(x, y, z, t, a, b): return (x * math.exp((((y * math.log(z)) + ((t - 1.0) * math.log(a))) - b))) / y
def code(x, y, z, t, a, b): t_1 = (t + -1.0) * math.log(a) tmp = 0 if t_1 <= -20000000.0: tmp = (math.pow(a, (t + -1.0)) * x) / y elif t_1 <= -440.0: tmp = x / (a * (y * (1.0 + (b + (0.5 * (b * b)))))) else: tmp = (x * math.exp(((t_1 + (y * math.log(z))) - b))) / y return tmp
function code(x, y, z, t, a, b) return Float64(Float64(x * exp(Float64(Float64(Float64(y * log(z)) + Float64(Float64(t - 1.0) * log(a))) - b))) / y) end
function code(x, y, z, t, a, b) t_1 = Float64(Float64(t + -1.0) * log(a)) tmp = 0.0 if (t_1 <= -20000000.0) tmp = Float64(Float64((a ^ Float64(t + -1.0)) * x) / y); elseif (t_1 <= -440.0) tmp = Float64(x / Float64(a * Float64(y * Float64(1.0 + Float64(b + Float64(0.5 * Float64(b * b))))))); else tmp = Float64(Float64(x * exp(Float64(Float64(t_1 + Float64(y * log(z))) - b))) / y); end return tmp end
function tmp = code(x, y, z, t, a, b) tmp = (x * exp((((y * log(z)) + ((t - 1.0) * log(a))) - b))) / y; end
function tmp_2 = code(x, y, z, t, a, b) t_1 = (t + -1.0) * log(a); tmp = 0.0; if (t_1 <= -20000000.0) tmp = ((a ^ (t + -1.0)) * x) / y; elseif (t_1 <= -440.0) tmp = x / (a * (y * (1.0 + (b + (0.5 * (b * b)))))); else tmp = (x * exp(((t_1 + (y * log(z))) - b))) / y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * N[Exp[N[(N[(N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision] + N[(N[(t - 1.0), $MachinePrecision] * N[Log[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(t + -1.0), $MachinePrecision] * N[Log[a], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -20000000.0], N[(N[(N[Power[a, N[(t + -1.0), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[t$95$1, -440.0], N[(x / N[(a * N[(y * N[(1.0 + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Exp[N[(N[(t$95$1 + N[(y * N[Log[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]]]
\frac{x \cdot e^{\left(y \cdot \log z + \left(t - 1\right) \cdot \log a\right) - b}}{y}
\begin{array}{l}
t_1 := \left(t + -1\right) \cdot \log a\\
\mathbf{if}\;t_1 \leq -20000000:\\
\;\;\;\;\frac{{a}^{\left(t + -1\right)} \cdot x}{y}\\
\mathbf{elif}\;t_1 \leq -440:\\
\;\;\;\;\frac{x}{a \cdot \left(y \cdot \left(1 + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot e^{\left(t_1 + y \cdot \log z\right) - b}}{y}\\
\end{array}
Results
| Original | 96.9% |
|---|---|
| Target | 82.6% |
| Herbie | 97.0% |
if (*.f64 (-.f64 t 1) (log.f64 a)) < -2e7Initial program 100.0%
Taylor expanded in y around 0 98.8%
Taylor expanded in b around 0 100.0%
if -2e7 < (*.f64 (-.f64 t 1) (log.f64 a)) < -440Initial program 88.7%
Simplified91.0%
[Start]88.7 | \[ \frac{x \cdot e^{\left(y \cdot \log z + \left(t - 1\right) \cdot \log a\right) - b}}{y}
\] |
|---|---|
associate-*r/ [<=]96.5 | \[ \color{blue}{x \cdot \frac{e^{\left(y \cdot \log z + \left(t - 1\right) \cdot \log a\right) - b}}{y}}
\] |
sub-neg [=>]96.5 | \[ x \cdot \frac{e^{\color{blue}{\left(y \cdot \log z + \left(t - 1\right) \cdot \log a\right) + \left(-b\right)}}}{y}
\] |
exp-sum [=>]88.0 | \[ x \cdot \frac{\color{blue}{e^{y \cdot \log z + \left(t - 1\right) \cdot \log a} \cdot e^{-b}}}{y}
\] |
associate-/l* [=>]88.0 | \[ x \cdot \color{blue}{\frac{e^{y \cdot \log z + \left(t - 1\right) \cdot \log a}}{\frac{y}{e^{-b}}}}
\] |
associate-/r/ [=>]88.0 | \[ x \cdot \color{blue}{\left(\frac{e^{y \cdot \log z + \left(t - 1\right) \cdot \log a}}{y} \cdot e^{-b}\right)}
\] |
exp-neg [=>]88.0 | \[ x \cdot \left(\frac{e^{y \cdot \log z + \left(t - 1\right) \cdot \log a}}{y} \cdot \color{blue}{\frac{1}{e^{b}}}\right)
\] |
associate-*r/ [=>]88.0 | \[ x \cdot \color{blue}{\frac{\frac{e^{y \cdot \log z + \left(t - 1\right) \cdot \log a}}{y} \cdot 1}{e^{b}}}
\] |
Taylor expanded in y around 0 92.3%
Simplified92.3%
[Start]92.3 | \[ x \cdot \frac{\frac{{a}^{t}}{y \cdot a}}{e^{b}}
\] |
|---|---|
*-commutative [=>]92.3 | \[ x \cdot \frac{\frac{{a}^{t}}{\color{blue}{a \cdot y}}}{e^{b}}
\] |
associate-/r* [=>]92.3 | \[ x \cdot \frac{\color{blue}{\frac{\frac{{a}^{t}}{a}}{y}}}{e^{b}}
\] |
Taylor expanded in t around 0 89.6%
Simplified89.6%
[Start]89.6 | \[ \frac{x}{y \cdot \left(a \cdot e^{b}\right)}
\] |
|---|---|
*-commutative [=>]89.6 | \[ \frac{x}{\color{blue}{\left(a \cdot e^{b}\right) \cdot y}}
\] |
associate-*r* [<=]89.6 | \[ \frac{x}{\color{blue}{a \cdot \left(e^{b} \cdot y\right)}}
\] |
*-commutative [<=]89.6 | \[ \frac{x}{a \cdot \color{blue}{\left(y \cdot e^{b}\right)}}
\] |
Taylor expanded in b around 0 83.3%
Simplified87.2%
[Start]83.3 | \[ \frac{x}{0.5 \cdot \left(y \cdot \left(a \cdot {b}^{2}\right)\right) + \left(a \cdot y + a \cdot \left(y \cdot b\right)\right)}
\] |
|---|---|
+-commutative [=>]83.3 | \[ \frac{x}{\color{blue}{\left(a \cdot y + a \cdot \left(y \cdot b\right)\right) + 0.5 \cdot \left(y \cdot \left(a \cdot {b}^{2}\right)\right)}}
\] |
distribute-lft-out [=>]87.5 | \[ \frac{x}{\color{blue}{a \cdot \left(y + y \cdot b\right)} + 0.5 \cdot \left(y \cdot \left(a \cdot {b}^{2}\right)\right)}
\] |
*-commutative [=>]87.5 | \[ \frac{x}{\color{blue}{\left(y + y \cdot b\right) \cdot a} + 0.5 \cdot \left(y \cdot \left(a \cdot {b}^{2}\right)\right)}
\] |
associate-*r* [=>]87.5 | \[ \frac{x}{\left(y + y \cdot b\right) \cdot a + \color{blue}{\left(0.5 \cdot y\right) \cdot \left(a \cdot {b}^{2}\right)}}
\] |
*-commutative [=>]87.5 | \[ \frac{x}{\left(y + y \cdot b\right) \cdot a + \left(0.5 \cdot y\right) \cdot \color{blue}{\left({b}^{2} \cdot a\right)}}
\] |
associate-*r* [=>]85.2 | \[ \frac{x}{\left(y + y \cdot b\right) \cdot a + \color{blue}{\left(\left(0.5 \cdot y\right) \cdot {b}^{2}\right) \cdot a}}
\] |
distribute-rgt-out [=>]87.2 | \[ \frac{x}{\color{blue}{a \cdot \left(\left(y + y \cdot b\right) + \left(0.5 \cdot y\right) \cdot {b}^{2}\right)}}
\] |
*-commutative [=>]87.2 | \[ \frac{x}{a \cdot \left(\left(y + y \cdot b\right) + \color{blue}{\left(y \cdot 0.5\right)} \cdot {b}^{2}\right)}
\] |
unpow2 [=>]87.2 | \[ \frac{x}{a \cdot \left(\left(y + y \cdot b\right) + \left(y \cdot 0.5\right) \cdot \color{blue}{\left(b \cdot b\right)}\right)}
\] |
Taylor expanded in y around 0 89.4%
Simplified89.4%
[Start]89.4 | \[ \frac{x}{a \cdot \left(y \cdot \left(1 + \left(b + 0.5 \cdot {b}^{2}\right)\right)\right)}
\] |
|---|---|
unpow2 [=>]89.4 | \[ \frac{x}{a \cdot \left(y \cdot \left(1 + \left(b + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}\right)\right)\right)}
\] |
if -440 < (*.f64 (-.f64 t 1) (log.f64 a)) Initial program 96.6%
Final simplification97.0%
| Alternative 1 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 33480 |
| Alternative 2 | |
|---|---|
| Accuracy | 89.9% |
| Cost | 27016 |
| Alternative 3 | |
|---|---|
| Accuracy | 82.9% |
| Cost | 13836 |
| Alternative 4 | |
|---|---|
| Accuracy | 81.9% |
| Cost | 13836 |
| Alternative 5 | |
|---|---|
| Accuracy | 70.5% |
| Cost | 7640 |
| Alternative 6 | |
|---|---|
| Accuracy | 80.6% |
| Cost | 7308 |
| Alternative 7 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 7308 |
| Alternative 8 | |
|---|---|
| Accuracy | 81.2% |
| Cost | 7308 |
| Alternative 9 | |
|---|---|
| Accuracy | 80.9% |
| Cost | 7044 |
| Alternative 10 | |
|---|---|
| Accuracy | 62.5% |
| Cost | 1496 |
| Alternative 11 | |
|---|---|
| Accuracy | 62.5% |
| Cost | 1496 |
| Alternative 12 | |
|---|---|
| Accuracy | 59.4% |
| Cost | 1364 |
| Alternative 13 | |
|---|---|
| Accuracy | 61.9% |
| Cost | 1364 |
| Alternative 14 | |
|---|---|
| Accuracy | 61.9% |
| Cost | 1364 |
| Alternative 15 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 1236 |
| Alternative 16 | |
|---|---|
| Accuracy | 50.1% |
| Cost | 1106 |
| Alternative 17 | |
|---|---|
| Accuracy | 39.1% |
| Cost | 908 |
| Alternative 18 | |
|---|---|
| Accuracy | 55.4% |
| Cost | 841 |
| Alternative 19 | |
|---|---|
| Accuracy | 40.0% |
| Cost | 452 |
| Alternative 20 | |
|---|---|
| Accuracy | 34.9% |
| Cost | 320 |
herbie shell --seed 2023147
(FPCore (x y z t a b)
:name "Numeric.SpecFunctions:incompleteBetaWorker from math-functions-0.1.5.2, A"
:precision binary64
:herbie-target
(if (< t -0.8845848504127471) (/ (* x (/ (pow a (- t 1.0)) y)) (- (+ b 1.0) (* y (log z)))) (if (< t 852031.2288374073) (/ (* (/ x y) (pow a (- t 1.0))) (exp (- b (* (log z) y)))) (/ (* x (/ (pow a (- t 1.0)) y)) (- (+ b 1.0) (* y (log z))))))
(/ (* x (exp (- (+ (* y (log z)) (* (- t 1.0) (log a))) b))) y))