| Alternative 1 | |
|---|---|
| Error | 7.1 |
| Cost | 9804 |
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y x) (- z t)) (- a t))))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ x (/ (* (- y x) (- z t)) (- a t)))))
(if (<= t_1 (- INFINITY))
(+ y (* (/ (- y x) t) (- a z)))
(if (<= t_1 -4e-291)
t_1
(if (<= t_1 5e-306)
(+ y (/ (* (- y x) (- a z)) t))
(if (<= t_1 1e+261) t_1 (- x (* (- z t) (/ (- x y) (- a t))))))))))double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
double t_1 = x + (((y - x) * (z - t)) / (a - t));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = y + (((y - x) / t) * (a - z));
} else if (t_1 <= -4e-291) {
tmp = t_1;
} else if (t_1 <= 5e-306) {
tmp = y + (((y - x) * (a - z)) / t);
} else if (t_1 <= 1e+261) {
tmp = t_1;
} else {
tmp = x - ((z - t) * ((x - y) / (a - t)));
}
return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
return x + (((y - x) * (z - t)) / (a - t));
}
public static double code(double x, double y, double z, double t, double a) {
double t_1 = x + (((y - x) * (z - t)) / (a - t));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = y + (((y - x) / t) * (a - z));
} else if (t_1 <= -4e-291) {
tmp = t_1;
} else if (t_1 <= 5e-306) {
tmp = y + (((y - x) * (a - z)) / t);
} else if (t_1 <= 1e+261) {
tmp = t_1;
} else {
tmp = x - ((z - t) * ((x - y) / (a - t)));
}
return tmp;
}
def code(x, y, z, t, a): return x + (((y - x) * (z - t)) / (a - t))
def code(x, y, z, t, a): t_1 = x + (((y - x) * (z - t)) / (a - t)) tmp = 0 if t_1 <= -math.inf: tmp = y + (((y - x) / t) * (a - z)) elif t_1 <= -4e-291: tmp = t_1 elif t_1 <= 5e-306: tmp = y + (((y - x) * (a - z)) / t) elif t_1 <= 1e+261: tmp = t_1 else: tmp = x - ((z - t) * ((x - y) / (a - t))) return tmp
function code(x, y, z, t, a) return Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t))) end
function code(x, y, z, t, a) t_1 = Float64(x + Float64(Float64(Float64(y - x) * Float64(z - t)) / Float64(a - t))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(y + Float64(Float64(Float64(y - x) / t) * Float64(a - z))); elseif (t_1 <= -4e-291) tmp = t_1; elseif (t_1 <= 5e-306) tmp = Float64(y + Float64(Float64(Float64(y - x) * Float64(a - z)) / t)); elseif (t_1 <= 1e+261) tmp = t_1; else tmp = Float64(x - Float64(Float64(z - t) * Float64(Float64(x - y) / Float64(a - t)))); end return tmp end
function tmp = code(x, y, z, t, a) tmp = x + (((y - x) * (z - t)) / (a - t)); end
function tmp_2 = code(x, y, z, t, a) t_1 = x + (((y - x) * (z - t)) / (a - t)); tmp = 0.0; if (t_1 <= -Inf) tmp = y + (((y - x) / t) * (a - z)); elseif (t_1 <= -4e-291) tmp = t_1; elseif (t_1 <= 5e-306) tmp = y + (((y - x) * (a - z)) / t); elseif (t_1 <= 1e+261) tmp = t_1; else tmp = x - ((z - t) * ((x - y) / (a - t))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(y + N[(N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] * N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -4e-291], t$95$1, If[LessEqual[t$95$1, 5e-306], N[(y + N[(N[(N[(y - x), $MachinePrecision] * N[(a - z), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+261], t$95$1, N[(x - N[(N[(z - t), $MachinePrecision] * N[(N[(x - y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\begin{array}{l}
t_1 := x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;y + \frac{y - x}{t} \cdot \left(a - z\right)\\
\mathbf{elif}\;t_1 \leq -4 \cdot 10^{-291}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-306}:\\
\;\;\;\;y + \frac{\left(y - x\right) \cdot \left(a - z\right)}{t}\\
\mathbf{elif}\;t_1 \leq 10^{+261}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x - \left(z - t\right) \cdot \frac{x - y}{a - t}\\
\end{array}
Results
| Original | 24.9 |
|---|---|
| Target | 9.3 |
| Herbie | 7.3 |
if (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -inf.0Initial program 64.0
Simplified17.4
[Start]64.0 | \[ x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\] |
|---|---|
+-commutative [=>]64.0 | \[ \color{blue}{\frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} + x}
\] |
associate-*r/ [<=]17.4 | \[ \color{blue}{\left(y - x\right) \cdot \frac{z - t}{a - t}} + x
\] |
*-commutative [<=]17.4 | \[ \color{blue}{\frac{z - t}{a - t} \cdot \left(y - x\right)} + x
\] |
fma-def [=>]17.4 | \[ \color{blue}{\mathsf{fma}\left(\frac{z - t}{a - t}, y - x, x\right)}
\] |
Taylor expanded in t around inf 41.4
Simplified20.5
[Start]41.4 | \[ y + \frac{\left(-1 \cdot z - -1 \cdot a\right) \cdot \left(y - x\right)}{t}
\] |
|---|---|
distribute-lft-out-- [=>]41.4 | \[ y + \frac{\color{blue}{\left(-1 \cdot \left(z - a\right)\right)} \cdot \left(y - x\right)}{t}
\] |
associate-*r* [<=]41.4 | \[ y + \frac{\color{blue}{-1 \cdot \left(\left(z - a\right) \cdot \left(y - x\right)\right)}}{t}
\] |
*-commutative [<=]41.4 | \[ y + \frac{-1 \cdot \color{blue}{\left(\left(y - x\right) \cdot \left(z - a\right)\right)}}{t}
\] |
associate-*r/ [<=]41.4 | \[ y + \color{blue}{-1 \cdot \frac{\left(y - x\right) \cdot \left(z - a\right)}{t}}
\] |
mul-1-neg [=>]41.4 | \[ y + \color{blue}{\left(-\frac{\left(y - x\right) \cdot \left(z - a\right)}{t}\right)}
\] |
unsub-neg [=>]41.4 | \[ \color{blue}{y - \frac{\left(y - x\right) \cdot \left(z - a\right)}{t}}
\] |
associate-/l* [=>]21.4 | \[ y - \color{blue}{\frac{y - x}{\frac{t}{z - a}}}
\] |
associate-/r/ [=>]20.5 | \[ y - \color{blue}{\frac{y - x}{t} \cdot \left(z - a\right)}
\] |
if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -3.99999999999999985e-291 or 4.99999999999999998e-306 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < 9.9999999999999993e260Initial program 2.0
if -3.99999999999999985e-291 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < 4.99999999999999998e-306Initial program 59.5
Simplified59.6
[Start]59.5 | \[ x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\] |
|---|---|
+-commutative [=>]59.5 | \[ \color{blue}{\frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} + x}
\] |
associate-*l/ [<=]59.7 | \[ \color{blue}{\frac{y - x}{a - t} \cdot \left(z - t\right)} + x
\] |
fma-def [=>]59.6 | \[ \color{blue}{\mathsf{fma}\left(\frac{y - x}{a - t}, z - t, x\right)}
\] |
Taylor expanded in t around -inf 1.8
Simplified1.8
[Start]1.8 | \[ y + -1 \cdot \frac{-1 \cdot \left(a \cdot \left(y - x\right)\right) + z \cdot \left(y - x\right)}{t}
\] |
|---|---|
mul-1-neg [=>]1.8 | \[ y + \color{blue}{\left(-\frac{-1 \cdot \left(a \cdot \left(y - x\right)\right) + z \cdot \left(y - x\right)}{t}\right)}
\] |
unsub-neg [=>]1.8 | \[ \color{blue}{y - \frac{-1 \cdot \left(a \cdot \left(y - x\right)\right) + z \cdot \left(y - x\right)}{t}}
\] |
associate-*r* [=>]1.8 | \[ y - \frac{\color{blue}{\left(-1 \cdot a\right) \cdot \left(y - x\right)} + z \cdot \left(y - x\right)}{t}
\] |
distribute-rgt-out [=>]1.8 | \[ y - \frac{\color{blue}{\left(y - x\right) \cdot \left(-1 \cdot a + z\right)}}{t}
\] |
+-commutative [<=]1.8 | \[ y - \frac{\left(y - x\right) \cdot \color{blue}{\left(z + -1 \cdot a\right)}}{t}
\] |
mul-1-neg [=>]1.8 | \[ y - \frac{\left(y - x\right) \cdot \left(z + \color{blue}{\left(-a\right)}\right)}{t}
\] |
if 9.9999999999999993e260 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) Initial program 54.9
Simplified17.2
[Start]54.9 | \[ x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\] |
|---|---|
associate-*l/ [<=]17.2 | \[ x + \color{blue}{\frac{y - x}{a - t} \cdot \left(z - t\right)}
\] |
Final simplification7.3
| Alternative 1 | |
|---|---|
| Error | 7.1 |
| Cost | 9804 |
| Alternative 2 | |
|---|---|
| Error | 7.1 |
| Cost | 3532 |
| Alternative 3 | |
|---|---|
| Error | 7.1 |
| Cost | 3532 |
| Alternative 4 | |
|---|---|
| Error | 31.6 |
| Cost | 1700 |
| Alternative 5 | |
|---|---|
| Error | 31.1 |
| Cost | 1436 |
| Alternative 6 | |
|---|---|
| Error | 36.2 |
| Cost | 1372 |
| Alternative 7 | |
|---|---|
| Error | 25.7 |
| Cost | 1368 |
| Alternative 8 | |
|---|---|
| Error | 24.5 |
| Cost | 1368 |
| Alternative 9 | |
|---|---|
| Error | 24.4 |
| Cost | 1368 |
| Alternative 10 | |
|---|---|
| Error | 25.5 |
| Cost | 1368 |
| Alternative 11 | |
|---|---|
| Error | 31.3 |
| Cost | 1304 |
| Alternative 12 | |
|---|---|
| Error | 36.5 |
| Cost | 1244 |
| Alternative 13 | |
|---|---|
| Error | 31.8 |
| Cost | 1240 |
| Alternative 14 | |
|---|---|
| Error | 31.9 |
| Cost | 1240 |
| Alternative 15 | |
|---|---|
| Error | 31.7 |
| Cost | 1240 |
| Alternative 16 | |
|---|---|
| Error | 19.3 |
| Cost | 1232 |
| Alternative 17 | |
|---|---|
| Error | 19.0 |
| Cost | 1232 |
| Alternative 18 | |
|---|---|
| Error | 21.7 |
| Cost | 1104 |
| Alternative 19 | |
|---|---|
| Error | 10.1 |
| Cost | 1096 |
| Alternative 20 | |
|---|---|
| Error | 36.4 |
| Cost | 980 |
| Alternative 21 | |
|---|---|
| Error | 21.6 |
| Cost | 972 |
| Alternative 22 | |
|---|---|
| Error | 36.3 |
| Cost | 716 |
| Alternative 23 | |
|---|---|
| Error | 35.8 |
| Cost | 328 |
| Alternative 24 | |
|---|---|
| Error | 45.9 |
| Cost | 64 |
herbie shell --seed 2023016
(FPCore (x y z t a)
:name "Graphics.Rendering.Chart.Axis.Types:linMap from Chart-1.5.3"
:precision binary64
:herbie-target
(if (< a -1.6153062845442575e-142) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t)))) (if (< a 3.774403170083174e-182) (- y (* (/ z t) (- y x))) (+ x (* (/ (- y x) 1.0) (/ (- z t) (- a t))))))
(+ x (/ (* (- y x) (- z t)) (- a t))))