| Alternative 1 | |
|---|---|
| Error | 4.7 |
| Cost | 3533 |
(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 (/ y t)) (/ a (/ t y))))
(if (or (<= t_1 -1e-243) (not (<= t_1 0.0)))
(+ x (- y (/ y (/ (- a t) (- z t)))))
(- x (/ y (/ t (- a 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 t_1 = (x + y) + ((y * (t - z)) / (a - t));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = x + ((z * (y / t)) - (a / (t / y)));
} else if ((t_1 <= -1e-243) || !(t_1 <= 0.0)) {
tmp = x + (y - (y / ((a - t) / (z - t))));
} else {
tmp = x - (y / (t / (a - z)));
}
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 * (y / t)) - (a / (t / y)));
} else if ((t_1 <= -1e-243) || !(t_1 <= 0.0)) {
tmp = x + (y - (y / ((a - t) / (z - t))));
} else {
tmp = x - (y / (t / (a - 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): t_1 = (x + y) + ((y * (t - z)) / (a - t)) tmp = 0 if t_1 <= -math.inf: tmp = x + ((z * (y / t)) - (a / (t / y))) elif (t_1 <= -1e-243) or not (t_1 <= 0.0): tmp = x + (y - (y / ((a - t) / (z - t)))) else: tmp = x - (y / (t / (a - 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) 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 * Float64(y / t)) - Float64(a / Float64(t / y)))); elseif ((t_1 <= -1e-243) || !(t_1 <= 0.0)) tmp = Float64(x + Float64(y - Float64(y / Float64(Float64(a - t) / Float64(z - t))))); else tmp = Float64(x - Float64(y / Float64(t / Float64(a - 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) t_1 = (x + y) + ((y * (t - z)) / (a - t)); tmp = 0.0; if (t_1 <= -Inf) tmp = x + ((z * (y / t)) - (a / (t / y))); elseif ((t_1 <= -1e-243) || ~((t_1 <= 0.0))) tmp = x + (y - (y / ((a - t) / (z - t)))); else tmp = x - (y / (t / (a - 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_] := 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 * N[(y / t), $MachinePrecision]), $MachinePrecision] - N[(a / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$1, -1e-243], 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[(y / N[(t / N[(a - z), $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 + \left(z \cdot \frac{y}{t} - \frac{a}{\frac{t}{y}}\right)\\
\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-243} \lor \neg \left(t_1 \leq 0\right):\\
\;\;\;\;x + \left(y - \frac{y}{\frac{a - t}{z - t}}\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{\frac{t}{a - z}}\\
\end{array}
Results
| Original | 16.6 |
|---|---|
| Target | 8.6 |
| Herbie | 4.7 |
if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -inf.0Initial program 64.0
Simplified30.0
[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)}
\] |
distribute-neg-frac [=>]64.0 | \[ x + \left(\color{blue}{\frac{-\left(z - t\right) \cdot y}{a - t}} + y\right)
\] |
distribute-rgt-neg-in [=>]64.0 | \[ x + \left(\frac{\color{blue}{\left(z - t\right) \cdot \left(-y\right)}}{a - t} + y\right)
\] |
associate-*r/ [<=]20.9 | \[ x + \left(\color{blue}{\left(z - t\right) \cdot \frac{-y}{a - t}} + y\right)
\] |
mul-1-neg [<=]20.9 | \[ x + \left(\left(z - t\right) \cdot \frac{\color{blue}{-1 \cdot y}}{a - t} + y\right)
\] |
associate-*r/ [<=]20.9 | \[ x + \left(\left(z - t\right) \cdot \color{blue}{\left(-1 \cdot \frac{y}{a - t}\right)} + y\right)
\] |
fma-def [=>]30.0 | \[ x + \color{blue}{\mathsf{fma}\left(z - t, -1 \cdot \frac{y}{a - t}, y\right)}
\] |
Taylor expanded in t around inf 53.0
Simplified17.6
[Start]53.0 | \[ -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+ [=>]57.9 | \[ \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+ [=>]57.9 | \[ \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+ [=>]49.5 | \[ \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+ [<=]44.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 [=>]44.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 [=>]44.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 [=>]44.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 [=>]44.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+ [=>]38.8 | \[ \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* [=>]27.5 | \[ \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/ [=>]26.8 | \[ \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 [=>]26.8 | \[ \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 [=>]26.8 | \[ \left(\left(\frac{y}{t} \cdot z + \color{blue}{0} \cdot y\right) - \frac{a \cdot y}{t}\right) + x
\] |
mul0-lft [=>]26.8 | \[ \left(\left(\frac{y}{t} \cdot z + \color{blue}{0}\right) - \frac{a \cdot y}{t}\right) + x
\] |
associate-/l* [=>]17.6 | \[ \left(\left(\frac{y}{t} \cdot z + 0\right) - \color{blue}{\frac{a}{\frac{t}{y}}}\right) + x
\] |
if -inf.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -9.99999999999999995e-244 or 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) Initial program 7.9
Simplified3.8
[Start]7.9 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]7.9 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]7.9 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]7.8 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]7.8 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]7.8 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]3.8 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
if -9.99999999999999995e-244 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 0.0Initial program 59.1
Simplified34.1
[Start]59.1 | \[ \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
|---|---|
+-rgt-identity [<=]59.1 | \[ \color{blue}{\left(\left(x + y\right) + 0\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+l+ [=>]59.1 | \[ \color{blue}{\left(x + \left(y + 0\right)\right)} - \frac{\left(z - t\right) \cdot y}{a - t}
\] |
associate-+r- [<=]34.2 | \[ \color{blue}{x + \left(\left(y + 0\right) - \frac{\left(z - t\right) \cdot y}{a - t}\right)}
\] |
+-rgt-identity [=>]34.2 | \[ x + \left(\color{blue}{y} - \frac{\left(z - t\right) \cdot y}{a - t}\right)
\] |
*-commutative [=>]34.2 | \[ x + \left(y - \frac{\color{blue}{y \cdot \left(z - t\right)}}{a - t}\right)
\] |
associate-/l* [=>]34.1 | \[ x + \left(y - \color{blue}{\frac{y}{\frac{a - t}{z - t}}}\right)
\] |
Taylor expanded in t around inf 0.9
Simplified0.9
[Start]0.9 | \[ x + \frac{-1 \cdot \left(a \cdot y\right) - -1 \cdot \left(y \cdot z\right)}{t}
\] |
|---|---|
*-commutative [<=]0.9 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot a\right)} - -1 \cdot \left(y \cdot z\right)}{t}
\] |
distribute-lft-out-- [=>]0.9 | \[ x + \frac{\color{blue}{-1 \cdot \left(y \cdot a - y \cdot z\right)}}{t}
\] |
distribute-lft-out-- [=>]0.9 | \[ x + \frac{-1 \cdot \color{blue}{\left(y \cdot \left(a - z\right)\right)}}{t}
\] |
associate-*r* [=>]0.9 | \[ x + \frac{\color{blue}{\left(-1 \cdot y\right) \cdot \left(a - z\right)}}{t}
\] |
neg-mul-1 [<=]0.9 | \[ x + \frac{\color{blue}{\left(-y\right)} \cdot \left(a - z\right)}{t}
\] |
Taylor expanded in x around 0 0.9
Simplified1.1
[Start]0.9 | \[ -1 \cdot \frac{y \cdot \left(a - z\right)}{t} + x
\] |
|---|---|
+-commutative [=>]0.9 | \[ \color{blue}{x + -1 \cdot \frac{y \cdot \left(a - z\right)}{t}}
\] |
metadata-eval [<=]0.9 | \[ x + \color{blue}{\left(-1\right)} \cdot \frac{y \cdot \left(a - z\right)}{t}
\] |
associate-*r/ [<=]1.1 | \[ x + \left(-1\right) \cdot \color{blue}{\left(y \cdot \frac{a - z}{t}\right)}
\] |
cancel-sign-sub-inv [<=]1.1 | \[ \color{blue}{x - 1 \cdot \left(y \cdot \frac{a - z}{t}\right)}
\] |
*-lft-identity [=>]1.1 | \[ x - \color{blue}{y \cdot \frac{a - z}{t}}
\] |
associate-*r/ [=>]0.9 | \[ x - \color{blue}{\frac{y \cdot \left(a - z\right)}{t}}
\] |
associate-/l* [=>]1.1 | \[ x - \color{blue}{\frac{y}{\frac{t}{a - z}}}
\] |
Final simplification4.7
| Alternative 1 | |
|---|---|
| Error | 4.7 |
| Cost | 3533 |
| Alternative 2 | |
|---|---|
| Error | 14.9 |
| Cost | 1240 |
| Alternative 3 | |
|---|---|
| Error | 14.9 |
| Cost | 1240 |
| Alternative 4 | |
|---|---|
| Error | 14.9 |
| Cost | 1108 |
| Alternative 5 | |
|---|---|
| Error | 11.4 |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Error | 7.3 |
| Cost | 968 |
| Alternative 7 | |
|---|---|
| Error | 11.4 |
| Cost | 841 |
| Alternative 8 | |
|---|---|
| Error | 10.8 |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 22.7 |
| Cost | 716 |
| Alternative 10 | |
|---|---|
| Error | 22.7 |
| Cost | 716 |
| Alternative 11 | |
|---|---|
| Error | 14.5 |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Error | 27.1 |
| Cost | 460 |
| Alternative 13 | |
|---|---|
| Error | 20.1 |
| Cost | 456 |
| Alternative 14 | |
|---|---|
| Error | 28.9 |
| Cost | 64 |
herbie shell --seed 2023060
(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))))