| Alternative 1 | |
|---|---|
| Error | 3.8 |
| Cost | 8260 |
(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 (* (- z a) (/ y t)))
(if (or (<= t_1 -5e-175) (not (<= t_1 0.0)))
(+ x (- y (/ y (/ (- a t) (- z t)))))
(+ x (/ (* y (- z a)) 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 + ((z - a) * (y / t));
} else if ((t_1 <= -5e-175) || !(t_1 <= 0.0)) {
tmp = x + (y - (y / ((a - t) / (z - t))));
} else {
tmp = x + ((y * (z - a)) / 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 + ((z - a) * (y / t));
} else if ((t_1 <= -5e-175) || !(t_1 <= 0.0)) {
tmp = x + (y - (y / ((a - t) / (z - t))));
} else {
tmp = x + ((y * (z - a)) / 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 + ((z - a) * (y / t)) elif (t_1 <= -5e-175) or not (t_1 <= 0.0): tmp = x + (y - (y / ((a - t) / (z - t)))) else: tmp = x + ((y * (z - a)) / 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(Float64(z - a) * Float64(y / t))); elseif ((t_1 <= -5e-175) || !(t_1 <= 0.0)) tmp = Float64(x + Float64(y - Float64(y / Float64(Float64(a - t) / Float64(z - t))))); else tmp = Float64(x + Float64(Float64(y * Float64(z - a)) / 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 + ((z - a) * (y / t)); elseif ((t_1 <= -5e-175) || ~((t_1 <= 0.0))) tmp = x + (y - (y / ((a - t) / (z - t)))); else tmp = x + ((y * (z - a)) / 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[(N[(z - a), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$1, -5e-175], N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision]], N[(x + N[(y - N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y * N[(z - a), $MachinePrecision]), $MachinePrecision] / t), $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 + \left(z - a\right) \cdot \frac{y}{t}\\
\mathbf{elif}\;t_1 \leq -5 \cdot 10^{-175} \lor \neg \left(t_1 \leq 0\right):\\
\;\;\;\;x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y \cdot \left(z - a\right)}{t}\\
\end{array}
Results
| Original | 16.2 |
|---|---|
| Target | 8.0 |
| Herbie | 5.2 |
if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -inf.0Initial program 64.0
Simplified17.8
[Start]64.0 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]64.0 | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
sub-neg [=>]64.0 | \[ x + \color{blue}{\left(y + \left(-\frac{\left(z - t\right) \cdot y}{a - t}\right)\right)}
\] |
+-commutative [=>]64.0 | \[ x + \color{blue}{\left(\left(-\frac{\left(z - t\right) \cdot y}{a - t}\right) + y\right)}
\] |
neg-mul-1 [=>]64.0 | \[ x + \left(\color{blue}{-1 \cdot \frac{\left(z - t\right) \cdot y}{a - t}} + y\right)
\] |
associate-*l/ [<=]17.9 | \[ x + \left(-1 \cdot \color{blue}{\left(\frac{z - t}{a - t} \cdot y\right)} + y\right)
\] |
associate-*r* [=>]17.9 | \[ x + \left(\color{blue}{\left(-1 \cdot \frac{z - t}{a - t}\right) \cdot y} + y\right)
\] |
fma-def [=>]17.8 | \[ x + \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{z - t}{a - t}, y, y\right)}
\] |
mul-1-neg [=>]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{-\frac{z - t}{a - t}}, y, y\right)
\] |
neg-sub0 [=>]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{0 - \frac{z - t}{a - t}}, y, y\right)
\] |
div-sub [=>]17.8 | \[ x + \mathsf{fma}\left(0 - \color{blue}{\left(\frac{z}{a - t} - \frac{t}{a - t}\right)}, y, y\right)
\] |
associate--r- [=>]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{\left(0 - \frac{z}{a - t}\right) + \frac{t}{a - t}}, y, y\right)
\] |
neg-sub0 [<=]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{\left(-\frac{z}{a - t}\right)} + \frac{t}{a - t}, y, y\right)
\] |
+-commutative [=>]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{\frac{t}{a - t} + \left(-\frac{z}{a - t}\right)}, y, y\right)
\] |
sub-neg [<=]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{\frac{t}{a - t} - \frac{z}{a - t}}, y, y\right)
\] |
div-sub [<=]17.8 | \[ x + \mathsf{fma}\left(\color{blue}{\frac{t - z}{a - t}}, y, y\right)
\] |
Taylor expanded in t around inf 58.6
Simplified20.6
[Start]58.6 | \[ y + \left(\frac{y \cdot \left(z - a\right)}{t} + \left(-1 \cdot y + x\right)\right)
\] |
|---|---|
+-commutative [=>]58.6 | \[ \color{blue}{\left(\frac{y \cdot \left(z - a\right)}{t} + \left(-1 \cdot y + x\right)\right) + y}
\] |
associate-+l+ [=>]49.0 | \[ \color{blue}{\frac{y \cdot \left(z - a\right)}{t} + \left(\left(-1 \cdot y + x\right) + y\right)}
\] |
associate-/l* [=>]31.1 | \[ \color{blue}{\frac{y}{\frac{t}{z - a}}} + \left(\left(-1 \cdot y + x\right) + y\right)
\] |
associate-/r/ [=>]29.8 | \[ \color{blue}{\frac{y}{t} \cdot \left(z - a\right)} + \left(\left(-1 \cdot y + x\right) + y\right)
\] |
+-commutative [<=]29.8 | \[ \frac{y}{t} \cdot \left(z - a\right) + \color{blue}{\left(y + \left(-1 \cdot y + x\right)\right)}
\] |
associate-+r+ [=>]20.6 | \[ \frac{y}{t} \cdot \left(z - a\right) + \color{blue}{\left(\left(y + -1 \cdot y\right) + x\right)}
\] |
+-commutative [=>]20.6 | \[ \frac{y}{t} \cdot \left(z - a\right) + \color{blue}{\left(x + \left(y + -1 \cdot y\right)\right)}
\] |
distribute-rgt1-in [=>]20.6 | \[ \frac{y}{t} \cdot \left(z - a\right) + \left(x + \color{blue}{\left(-1 + 1\right) \cdot y}\right)
\] |
metadata-eval [=>]20.6 | \[ \frac{y}{t} \cdot \left(z - a\right) + \left(x + \color{blue}{0} \cdot y\right)
\] |
mul0-lft [=>]20.6 | \[ \frac{y}{t} \cdot \left(z - a\right) + \left(x + \color{blue}{0}\right)
\] |
if -inf.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -5e-175 or 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) Initial program 7.7
Simplified3.7
[Start]7.7 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]7.7 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]7.7 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]7.5 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]7.5 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]7.5 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]3.7 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
if -5e-175 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 0.0Initial program 51.3
Simplified52.3
[Start]51.3 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
associate--l+ [=>]28.7 | \[ \color{blue}{x + \left(y - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
sub-neg [=>]28.7 | \[ x + \color{blue}{\left(y + \left(-\frac{\left(z - t\right) \cdot y}{a - t}\right)\right)}
\] |
+-commutative [=>]28.7 | \[ x + \color{blue}{\left(\left(-\frac{\left(z - t\right) \cdot y}{a - t}\right) + y\right)}
\] |
distribute-neg-frac [=>]28.7 | \[ x + \left(\color{blue}{\frac{-\left(z - t\right) \cdot y}{a - t}} + y\right)
\] |
distribute-rgt-neg-in [=>]28.7 | \[ x + \left(\frac{\color{blue}{\left(z - t\right) \cdot \left(-y\right)}}{a - t} + y\right)
\] |
associate-*r/ [<=]39.2 | \[ x + \left(\color{blue}{\left(z - t\right) \cdot \frac{-y}{a - t}} + y\right)
\] |
mul-1-neg [<=]39.2 | \[ x + \left(\left(z - t\right) \cdot \frac{\color{blue}{-1 \cdot y}}{a - t} + y\right)
\] |
associate-*r/ [<=]39.2 | \[ x + \left(\left(z - t\right) \cdot \color{blue}{\left(-1 \cdot \frac{y}{a - t}\right)} + y\right)
\] |
fma-def [=>]52.3 | \[ x + \color{blue}{\mathsf{fma}\left(z - t, -1 \cdot \frac{y}{a - t}, y\right)}
\] |
Taylor expanded in t around inf 42.5
Simplified9.1
[Start]42.5 | \[ -1 \cdot \frac{a \cdot y}{t} + \left(y + \left(\frac{y \cdot z}{t} + \left(-1 \cdot y + x\right)\right)\right)
\] |
|---|---|
associate-+r+ [=>]56.4 | \[ \color{blue}{\left(-1 \cdot \frac{a \cdot y}{t} + y\right) + \left(\frac{y \cdot z}{t} + \left(-1 \cdot y + x\right)\right)}
\] |
associate-+r+ [=>]56.4 | \[ \left(-1 \cdot \frac{a \cdot y}{t} + y\right) + \color{blue}{\left(\left(\frac{y \cdot z}{t} + -1 \cdot y\right) + x\right)}
\] |
associate-+r+ [=>]33.7 | \[ \color{blue}{\left(\left(-1 \cdot \frac{a \cdot y}{t} + y\right) + \left(\frac{y \cdot z}{t} + -1 \cdot y\right)\right) + x}
\] |
associate-+r+ [<=]19.3 | \[ \color{blue}{\left(-1 \cdot \frac{a \cdot y}{t} + \left(y + \left(\frac{y \cdot z}{t} + -1 \cdot y\right)\right)\right)} + x
\] |
+-commutative [=>]19.3 | \[ \color{blue}{\left(\left(y + \left(\frac{y \cdot z}{t} + -1 \cdot y\right)\right) + -1 \cdot \frac{a \cdot y}{t}\right)} + x
\] |
mul-1-neg [=>]19.3 | \[ \left(\left(y + \left(\frac{y \cdot z}{t} + -1 \cdot y\right)\right) + \color{blue}{\left(-\frac{a \cdot y}{t}\right)}\right) + x
\] |
unsub-neg [=>]19.3 | \[ \color{blue}{\left(\left(y + \left(\frac{y \cdot z}{t} + -1 \cdot y\right)\right) - \frac{a \cdot y}{t}\right)} + x
\] |
+-commutative [=>]19.3 | \[ \left(\color{blue}{\left(\left(\frac{y \cdot z}{t} + -1 \cdot y\right) + y\right)} - \frac{a \cdot y}{t}\right) + x
\] |
associate-+l+ [=>]5.7 | \[ \left(\color{blue}{\left(\frac{y \cdot z}{t} + \left(-1 \cdot y + y\right)\right)} - \frac{a \cdot y}{t}\right) + x
\] |
associate-/l* [=>]5.6 | \[ \left(\left(\color{blue}{\frac{y}{\frac{t}{z}}} + \left(-1 \cdot y + y\right)\right) - \frac{a \cdot y}{t}\right) + x
\] |
associate-/r/ [=>]9.0 | \[ \left(\left(\color{blue}{\frac{y}{t} \cdot z} + \left(-1 \cdot y + y\right)\right) - \frac{a \cdot y}{t}\right) + x
\] |
distribute-lft1-in [=>]9.0 | \[ \left(\left(\frac{y}{t} \cdot z + \color{blue}{\left(-1 + 1\right) \cdot y}\right) - \frac{a \cdot y}{t}\right) + x
\] |
metadata-eval [=>]9.0 | \[ \left(\left(\frac{y}{t} \cdot z + \color{blue}{0} \cdot y\right) - \frac{a \cdot y}{t}\right) + x
\] |
mul0-lft [=>]9.0 | \[ \left(\left(\frac{y}{t} \cdot z + \color{blue}{0}\right) - \frac{a \cdot y}{t}\right) + x
\] |
associate-/l* [=>]9.8 | \[ \left(\left(\frac{y}{t} \cdot z + 0\right) - \color{blue}{\frac{a}{\frac{t}{y}}}\right) + x
\] |
associate-/r/ [=>]9.1 | \[ \left(\left(\frac{y}{t} \cdot z + 0\right) - \color{blue}{\frac{a}{t} \cdot y}\right) + x
\] |
Taylor expanded in t around 0 5.7
Simplified5.7
[Start]5.7 | \[ \frac{y \cdot z - a \cdot y}{t} + x
\] |
|---|---|
*-commutative [=>]5.7 | \[ \frac{y \cdot z - \color{blue}{y \cdot a}}{t} + x
\] |
distribute-lft-out-- [=>]5.7 | \[ \frac{\color{blue}{y \cdot \left(z - a\right)}}{t} + x
\] |
Final simplification5.2
| Alternative 1 | |
|---|---|
| Error | 3.8 |
| Cost | 8260 |
| Alternative 2 | |
|---|---|
| Error | 12.4 |
| Cost | 972 |
| Alternative 3 | |
|---|---|
| Error | 8.0 |
| Cost | 969 |
| Alternative 4 | |
|---|---|
| Error | 9.5 |
| Cost | 841 |
| Alternative 5 | |
|---|---|
| Error | 11.4 |
| Cost | 840 |
| Alternative 6 | |
|---|---|
| Error | 9.7 |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Error | 20.1 |
| Cost | 720 |
| Alternative 8 | |
|---|---|
| Error | 15.4 |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Error | 27.1 |
| Cost | 592 |
| Alternative 10 | |
|---|---|
| Error | 19.8 |
| Cost | 456 |
| Alternative 11 | |
|---|---|
| Error | 28.5 |
| Cost | 64 |
herbie shell --seed 2023039
(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))))