| Alternative 1 | |
|---|---|
| Accuracy | 90.6% |
| Cost | 1096 |

(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
(FPCore (x y z t a)
:precision binary64
(if (<= t -2.5e+118)
(- x (* z (/ y (- a t))))
(if (<= t 1.95e+179)
(+ x (+ y (/ (- t z) (/ (- a t) y))))
(+ (- x (/ y (/ t a))) (/ y (/ t z))))))double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -2.5e+118) {
tmp = x - (z * (y / (a - t)));
} else if (t <= 1.95e+179) {
tmp = x + (y + ((t - z) / ((a - t) / y)));
} else {
tmp = (x - (y / (t / a))) + (y / (t / z));
}
return tmp;
}
real(8) function code(x, y, z, t, a)
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
code = (x + y) - (((z - t) * y) / (a - t))
end function
real(8) function code(x, y, z, t, a)
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) :: tmp
if (t <= (-2.5d+118)) then
tmp = x - (z * (y / (a - t)))
else if (t <= 1.95d+179) then
tmp = x + (y + ((t - z) / ((a - t) / y)))
else
tmp = (x - (y / (t / a))) + (y / (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -2.5e+118) {
tmp = x - (z * (y / (a - t)));
} else if (t <= 1.95e+179) {
tmp = x + (y + ((t - z) / ((a - t) / y)));
} else {
tmp = (x - (y / (t / a))) + (y / (t / z));
}
return tmp;
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
def code(x, y, z, t, a): tmp = 0 if t <= -2.5e+118: tmp = x - (z * (y / (a - t))) elif t <= 1.95e+179: tmp = x + (y + ((t - z) / ((a - t) / y))) else: tmp = (x - (y / (t / a))) + (y / (t / z)) return tmp
function code(x, y, z, t, a) return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) end
function code(x, y, z, t, a) tmp = 0.0 if (t <= -2.5e+118) tmp = Float64(x - Float64(z * Float64(y / Float64(a - t)))); elseif (t <= 1.95e+179) tmp = Float64(x + Float64(y + Float64(Float64(t - z) / Float64(Float64(a - t) / y)))); else tmp = Float64(Float64(x - Float64(y / Float64(t / a))) + Float64(y / Float64(t / z))); end return tmp end
function tmp = code(x, y, z, t, a) tmp = (x + y) - (((z - t) * y) / (a - t)); end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= -2.5e+118) tmp = x - (z * (y / (a - t))); elseif (t <= 1.95e+179) tmp = x + (y + ((t - z) / ((a - t) / y))); else tmp = (x - (y / (t / a))) + (y / (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -2.5e+118], N[(x - N[(z * N[(y / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.95e+179], N[(x + N[(y + N[(N[(t - z), $MachinePrecision] / N[(N[(a - t), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - N[(y / N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
\mathbf{if}\;t \leq -2.5 \cdot 10^{+118}:\\
\;\;\;\;x - z \cdot \frac{y}{a - t}\\
\mathbf{elif}\;t \leq 1.95 \cdot 10^{+179}:\\
\;\;\;\;x + \left(y + \frac{t - z}{\frac{a - t}{y}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x - \frac{y}{\frac{t}{a}}\right) + \frac{y}{\frac{t}{z}}\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 77.8% |
|---|---|
| Target | 88.2% |
| Herbie | 90.6% |
if t < -2.49999999999999986e118Initial program 48.1%
Simplified85.1%
[Start]48.1% | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]55.8% | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
sub-neg [=>]55.8% | \[ x + \color{blue}{\left(y + \left(-\frac{\left(z - t\right) \cdot y}{a - t}\right)\right)}
\] |
+-commutative [=>]55.8% | \[ x + \color{blue}{\left(\left(-\frac{\left(z - t\right) \cdot y}{a - t}\right) + y\right)}
\] |
associate-/l* [=>]67.6% | \[ x + \left(\left(-\color{blue}{\frac{z - t}{\frac{a - t}{y}}}\right) + y\right)
\] |
distribute-neg-frac [=>]67.6% | \[ x + \left(\color{blue}{\frac{-\left(z - t\right)}{\frac{a - t}{y}}} + y\right)
\] |
associate-/r/ [=>]85.1% | \[ x + \left(\color{blue}{\frac{-\left(z - t\right)}{a - t} \cdot y} + y\right)
\] |
fma-def [=>]85.1% | \[ x + \color{blue}{\mathsf{fma}\left(\frac{-\left(z - t\right)}{a - t}, y, y\right)}
\] |
sub-neg [=>]85.1% | \[ x + \mathsf{fma}\left(\frac{-\color{blue}{\left(z + \left(-t\right)\right)}}{a - t}, y, y\right)
\] |
+-commutative [=>]85.1% | \[ x + \mathsf{fma}\left(\frac{-\color{blue}{\left(\left(-t\right) + z\right)}}{a - t}, y, y\right)
\] |
distribute-neg-in [=>]85.1% | \[ x + \mathsf{fma}\left(\frac{\color{blue}{\left(-\left(-t\right)\right) + \left(-z\right)}}{a - t}, y, y\right)
\] |
unsub-neg [=>]85.1% | \[ x + \mathsf{fma}\left(\frac{\color{blue}{\left(-\left(-t\right)\right) - z}}{a - t}, y, y\right)
\] |
remove-double-neg [=>]85.1% | \[ x + \mathsf{fma}\left(\frac{\color{blue}{t} - z}{a - t}, y, y\right)
\] |
Taylor expanded in z around inf 81.2%
Simplified94.0%
[Start]81.2% | \[ x + -1 \cdot \frac{y \cdot z}{a - t}
\] |
|---|---|
mul-1-neg [=>]81.2% | \[ x + \color{blue}{\left(-\frac{y \cdot z}{a - t}\right)}
\] |
*-commutative [=>]81.2% | \[ x + \left(-\frac{\color{blue}{z \cdot y}}{a - t}\right)
\] |
associate-*r/ [<=]94.0% | \[ x + \left(-\color{blue}{z \cdot \frac{y}{a - t}}\right)
\] |
distribute-lft-neg-in [=>]94.0% | \[ x + \color{blue}{\left(-z\right) \cdot \frac{y}{a - t}}
\] |
if -2.49999999999999986e118 < t < 1.94999999999999987e179Initial program 86.3%
Simplified91.6%
[Start]86.3% | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]87.5% | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
associate-/l* [=>]91.6% | \[ x + \left(y - \color{blue}{\frac{z - t}{\frac{a - t}{y}}}\right)
\] |
if 1.94999999999999987e179 < t Initial program 33.5%
Simplified38.2%
[Start]33.5% | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate-*l/ [<=]38.2% | \[ \left(x + y\right) - \color{blue}{\frac{z - t}{a - t} \cdot y}
\] |
Taylor expanded in t around inf 84.6%
Simplified96.0%
[Start]84.6% | \[ \left(-1 \cdot \frac{y \cdot a}{t} + x\right) - -1 \cdot \frac{y \cdot z}{t}
\] |
|---|---|
sub-neg [=>]84.6% | \[ \color{blue}{\left(-1 \cdot \frac{y \cdot a}{t} + x\right) + \left(--1 \cdot \frac{y \cdot z}{t}\right)}
\] |
+-commutative [=>]84.6% | \[ \color{blue}{\left(x + -1 \cdot \frac{y \cdot a}{t}\right)} + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
mul-1-neg [=>]84.6% | \[ \left(x + \color{blue}{\left(-\frac{y \cdot a}{t}\right)}\right) + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
unsub-neg [=>]84.6% | \[ \color{blue}{\left(x - \frac{y \cdot a}{t}\right)} + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
associate-/l* [=>]88.5% | \[ \left(x - \color{blue}{\frac{y}{\frac{t}{a}}}\right) + \left(--1 \cdot \frac{y \cdot z}{t}\right)
\] |
mul-1-neg [=>]88.5% | \[ \left(x - \frac{y}{\frac{t}{a}}\right) + \left(-\color{blue}{\left(-\frac{y \cdot z}{t}\right)}\right)
\] |
remove-double-neg [=>]88.5% | \[ \left(x - \frac{y}{\frac{t}{a}}\right) + \color{blue}{\frac{y \cdot z}{t}}
\] |
associate-/l* [=>]96.0% | \[ \left(x - \frac{y}{\frac{t}{a}}\right) + \color{blue}{\frac{y}{\frac{t}{z}}}
\] |
Final simplification92.5%
| Alternative 1 | |
|---|---|
| Accuracy | 90.6% |
| Cost | 1096 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 1096 |
| Alternative 3 | |
|---|---|
| Accuracy | 81.7% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Accuracy | 82.7% |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Accuracy | 84.0% |
| Cost | 841 |
| Alternative 7 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Accuracy | 77.9% |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Accuracy | 77.2% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Accuracy | 77.7% |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Accuracy | 63.9% |
| Cost | 456 |
| Alternative 12 | |
|---|---|
| Accuracy | 51.0% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"
:precision binary64
:herbie-target
(if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-7) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))
(- (+ x y) (/ (* (- z t) y) (- a t))))