| Alternative 1 | |
|---|---|
| Error | 9.56% |
| Cost | 8004 |
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ (+ x y) (/ (* y (- t z)) (- a t)))))
(if (<= t_1 (- INFINITY))
(+ x (/ y (/ t (- z a))))
(if (<= t_1 -2e-298)
t_1
(if (<= t_1 0.0)
(+ x (/ (* y (- z a)) t))
(+ x (- y (/ y (/ (- a t) (- z t))))))))))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 t_1 = (x + y) + ((y * (t - z)) / (a - t));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = x + (y / (t / (z - a)));
} else if (t_1 <= -2e-298) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = x + ((y * (z - a)) / t);
} else {
tmp = x + (y - (y / ((a - t) / (z - t))));
}
return tmp;
}
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 t_1 = (x + y) + ((y * (t - z)) / (a - t));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = x + (y / (t / (z - a)));
} else if (t_1 <= -2e-298) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = x + ((y * (z - a)) / t);
} else {
tmp = x + (y - (y / ((a - t) / (z - t))));
}
return tmp;
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
def code(x, y, z, t, a): t_1 = (x + y) + ((y * (t - z)) / (a - t)) tmp = 0 if t_1 <= -math.inf: tmp = x + (y / (t / (z - a))) elif t_1 <= -2e-298: tmp = t_1 elif t_1 <= 0.0: tmp = x + ((y * (z - a)) / t) else: tmp = x + (y - (y / ((a - t) / (z - t)))) 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) t_1 = Float64(Float64(x + y) + Float64(Float64(y * Float64(t - z)) / Float64(a - t))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(x + Float64(y / Float64(t / Float64(z - a)))); elseif (t_1 <= -2e-298) tmp = t_1; elseif (t_1 <= 0.0) tmp = Float64(x + Float64(Float64(y * Float64(z - a)) / t)); else tmp = Float64(x + Float64(y - Float64(y / Float64(Float64(a - t) / Float64(z - t))))); 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) t_1 = (x + y) + ((y * (t - z)) / (a - t)); tmp = 0.0; if (t_1 <= -Inf) tmp = x + (y / (t / (z - a))); elseif (t_1 <= -2e-298) tmp = t_1; elseif (t_1 <= 0.0) tmp = x + ((y * (z - a)) / t); else tmp = x + (y - (y / ((a - t) / (z - t)))); 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_] := Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(x + N[(y / N[(t / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e-298], t$95$1, If[LessEqual[t$95$1, 0.0], N[(x + N[(N[(y * N[(z - a), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(y - N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := \left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;x + \frac{y}{\frac{t}{z - a}}\\
\mathbf{elif}\;t_1 \leq -2 \cdot 10^{-298}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;x + \frac{y \cdot \left(z - a\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)\\
\end{array}
Results
| Original | 25.92% |
|---|---|
| Target | 13.5% |
| Herbie | 7.5% |
if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -inf.0Initial program 100
Simplified29.99
[Start]100 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]100 | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
sub-neg [=>]100 | \[ x + \color{blue}{\left(y + \left(-\frac{\left(z - t\right) \cdot y}{a - t}\right)\right)}
\] |
+-commutative [=>]100 | \[ x + \color{blue}{\left(\left(-\frac{\left(z - t\right) \cdot y}{a - t}\right) + y\right)}
\] |
neg-mul-1 [=>]100 | \[ x + \left(\color{blue}{-1 \cdot \frac{\left(z - t\right) \cdot y}{a - t}} + y\right)
\] |
associate-*l/ [<=]29.99 | \[ x + \left(-1 \cdot \color{blue}{\left(\frac{z - t}{a - t} \cdot y\right)} + y\right)
\] |
associate-*r* [=>]29.99 | \[ x + \left(\color{blue}{\left(-1 \cdot \frac{z - t}{a - t}\right) \cdot y} + y\right)
\] |
fma-def [=>]29.99 | \[ x + \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{z - t}{a - t}, y, y\right)}
\] |
mul-1-neg [=>]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{-\frac{z - t}{a - t}}, y, y\right)
\] |
neg-sub0 [=>]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{0 - \frac{z - t}{a - t}}, y, y\right)
\] |
div-sub [=>]29.99 | \[ x + \mathsf{fma}\left(0 - \color{blue}{\left(\frac{z}{a - t} - \frac{t}{a - t}\right)}, y, y\right)
\] |
associate--r- [=>]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{\left(0 - \frac{z}{a - t}\right) + \frac{t}{a - t}}, y, y\right)
\] |
neg-sub0 [<=]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{\left(-\frac{z}{a - t}\right)} + \frac{t}{a - t}, y, y\right)
\] |
+-commutative [=>]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{\frac{t}{a - t} + \left(-\frac{z}{a - t}\right)}, y, y\right)
\] |
sub-neg [<=]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{\frac{t}{a - t} - \frac{z}{a - t}}, y, y\right)
\] |
div-sub [<=]29.99 | \[ x + \mathsf{fma}\left(\color{blue}{\frac{t - z}{a - t}}, y, y\right)
\] |
Taylor expanded in t around inf 77.94
Simplified33.3
[Start]77.94 | \[ x + \left(y + \left(\frac{y \cdot \left(z - a\right)}{t} + -1 \cdot y\right)\right)
\] |
|---|---|
+-commutative [=>]77.94 | \[ x + \color{blue}{\left(\left(\frac{y \cdot \left(z - a\right)}{t} + -1 \cdot y\right) + y\right)}
\] |
associate-+l+ [=>]62.78 | \[ x + \color{blue}{\left(\frac{y \cdot \left(z - a\right)}{t} + \left(-1 \cdot y + y\right)\right)}
\] |
associate-/l* [=>]33.3 | \[ x + \left(\color{blue}{\frac{y}{\frac{t}{z - a}}} + \left(-1 \cdot y + y\right)\right)
\] |
distribute-lft1-in [=>]33.3 | \[ x + \left(\frac{y}{\frac{t}{z - a}} + \color{blue}{\left(-1 + 1\right) \cdot y}\right)
\] |
metadata-eval [=>]33.3 | \[ x + \left(\frac{y}{\frac{t}{z - a}} + \color{blue}{0} \cdot y\right)
\] |
mul0-lft [=>]33.3 | \[ x + \left(\frac{y}{\frac{t}{z - a}} + \color{blue}{0}\right)
\] |
if -inf.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -1.99999999999999982e-298Initial program 2.42
if -1.99999999999999982e-298 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 0.0Initial program 95.76
Simplified58.11
[Start]95.76 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]95.76 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]95.76 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]58.11 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]58.11 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]58.11 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]58.11 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
Taylor expanded in t around inf 0.39
Simplified0.4
[Start]0.39 | \[ x + \frac{-1 \cdot \left(a \cdot y\right) - -1 \cdot \left(y \cdot z\right)}{t}
\] |
|---|---|
*-commutative [<=]0.39 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot a\right)} - -1 \cdot \left(y \cdot z\right)}{t}
\] |
distribute-lft-out-- [=>]0.39 | \[ x + \frac{\color{blue}{-1 \cdot \left(y \cdot a - y \cdot z\right)}}{t}
\] |
distribute-lft-out-- [=>]0.4 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot \left(a - z\right)\right)}}{t}
\] |
associate-*r* [=>]0.4 | \[ x + \frac{\color{blue}{\left(-1 \cdot y\right) \cdot \left(a - z\right)}}{t}
\] |
neg-mul-1 [<=]0.4 | \[ x + \frac{\color{blue}{\left(-y\right)} \cdot \left(a - z\right)}{t}
\] |
if 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) Initial program 18.95
Simplified7.93
[Start]18.95 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]18.95 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]18.95 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]18.72 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]18.72 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]18.72 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]7.93 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
Final simplification7.5
| Alternative 1 | |
|---|---|
| Error | 9.56% |
| Cost | 8004 |
| Alternative 2 | |
|---|---|
| Error | 9.56% |
| Cost | 2632 |
| Alternative 3 | |
|---|---|
| Error | 28% |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Error | 26.9% |
| Cost | 1240 |
| Alternative 5 | |
|---|---|
| Error | 10.32% |
| Cost | 1097 |
| Alternative 6 | |
|---|---|
| Error | 15.33% |
| Cost | 841 |
| Alternative 7 | |
|---|---|
| Error | 16.82% |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Error | 17.88% |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 32.73% |
| Cost | 780 |
| Alternative 10 | |
|---|---|
| Error | 32.75% |
| Cost | 780 |
| Alternative 11 | |
|---|---|
| Error | 24.16% |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Error | 31.16% |
| Cost | 456 |
| Alternative 13 | |
|---|---|
| Error | 42.02% |
| Cost | 328 |
| Alternative 14 | |
|---|---|
| Error | 45.06% |
| Cost | 64 |
herbie shell --seed 2023088
(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))))