| Alternative 1 | |
|---|---|
| Accuracy | 94.7% |
| Cost | 8004 |

(FPCore (x y z t a) :precision binary64 (+ x (* (- y z) (/ (- t x) (- a z)))))
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (+ x (* (- y z) (/ (- t x) (- a z))))))
(if (<= t_1 -2e-253)
(fma (- t x) (/ (- y z) (- a z)) x)
(if (<= t_1 0.0)
(- (/ a (/ z (- t x))) (- (* (- t x) (/ y z)) t))
(+ x (/ (- t x) (/ (- a z) (- y z))))))))double code(double x, double y, double z, double t, double a) {
return x + ((y - z) * ((t - x) / (a - z)));
}
double code(double x, double y, double z, double t, double a) {
double t_1 = x + ((y - z) * ((t - x) / (a - z)));
double tmp;
if (t_1 <= -2e-253) {
tmp = fma((t - x), ((y - z) / (a - z)), x);
} else if (t_1 <= 0.0) {
tmp = (a / (z / (t - x))) - (((t - x) * (y / z)) - t);
} else {
tmp = x + ((t - x) / ((a - z) / (y - z)));
}
return tmp;
}
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) end
function code(x, y, z, t, a) t_1 = Float64(x + Float64(Float64(y - z) * Float64(Float64(t - x) / Float64(a - z)))) tmp = 0.0 if (t_1 <= -2e-253) tmp = fma(Float64(t - x), Float64(Float64(y - z) / Float64(a - z)), x); elseif (t_1 <= 0.0) tmp = Float64(Float64(a / Float64(z / Float64(t - x))) - Float64(Float64(Float64(t - x) * Float64(y / z)) - t)); else tmp = Float64(x + Float64(Float64(t - x) / Float64(Float64(a - z) / Float64(y - z)))); end return tmp end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(y - z), $MachinePrecision] * N[(N[(t - x), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-253], N[(N[(t - x), $MachinePrecision] * N[(N[(y - z), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(N[(a / N[(z / N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(t - x), $MachinePrecision] * N[(y / z), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(t - x), $MachinePrecision] / N[(N[(a - z), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\begin{array}{l}
t_1 := x + \left(y - z\right) \cdot \frac{t - x}{a - z}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{-253}:\\
\;\;\;\;\mathsf{fma}\left(t - x, \frac{y - z}{a - z}, x\right)\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\frac{a}{\frac{z}{t - x}} - \left(\left(t - x\right) \cdot \frac{y}{z} - t\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{t - x}{\frac{a - z}{y - z}}\\
\end{array}
Herbie found 18 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < -2.0000000000000001e-253Initial program 94.9%
Simplified97.3%
[Start]94.9% | \[ x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\] |
|---|---|
+-commutative [=>]94.9% | \[ \color{blue}{\left(y - z\right) \cdot \frac{t - x}{a - z} + x}
\] |
associate-*r/ [=>]72.8% | \[ \color{blue}{\frac{\left(y - z\right) \cdot \left(t - x\right)}{a - z}} + x
\] |
*-commutative [=>]72.8% | \[ \frac{\color{blue}{\left(t - x\right) \cdot \left(y - z\right)}}{a - z} + x
\] |
associate-*r/ [<=]97.2% | \[ \color{blue}{\left(t - x\right) \cdot \frac{y - z}{a - z}} + x
\] |
fma-def [=>]97.3% | \[ \color{blue}{\mathsf{fma}\left(t - x, \frac{y - z}{a - z}, x\right)}
\] |
if -2.0000000000000001e-253 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) < 0.0Initial program 3.6%
Applied egg-rr6.5%
[Start]3.6% | \[ x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\] |
|---|---|
*-commutative [=>]3.6% | \[ x + \color{blue}{\frac{t - x}{a - z} \cdot \left(y - z\right)}
\] |
associate-*l/ [=>]5.8% | \[ x + \color{blue}{\frac{\left(t - x\right) \cdot \left(y - z\right)}{a - z}}
\] |
associate-*r/ [<=]6.5% | \[ x + \color{blue}{\left(t - x\right) \cdot \frac{y - z}{a - z}}
\] |
clear-num [=>]6.5% | \[ x + \left(t - x\right) \cdot \color{blue}{\frac{1}{\frac{a - z}{y - z}}}
\] |
un-div-inv [=>]6.5% | \[ x + \color{blue}{\frac{t - x}{\frac{a - z}{y - z}}}
\] |
Taylor expanded in z around inf 87.9%
Simplified99.8%
[Start]87.9% | \[ \left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) - -1 \cdot \frac{a \cdot \left(t - x\right)}{z}
\] |
|---|---|
sub-neg [=>]87.9% | \[ \color{blue}{\left(-1 \cdot \frac{y \cdot \left(t - x\right)}{z} + t\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)}
\] |
+-commutative [=>]87.9% | \[ \color{blue}{\left(t + -1 \cdot \frac{y \cdot \left(t - x\right)}{z}\right)} + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
mul-1-neg [=>]87.9% | \[ \left(t + \color{blue}{\left(-\frac{y \cdot \left(t - x\right)}{z}\right)}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
unsub-neg [=>]87.9% | \[ \color{blue}{\left(t - \frac{y \cdot \left(t - x\right)}{z}\right)} + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
associate-/l* [=>]94.0% | \[ \left(t - \color{blue}{\frac{y}{\frac{z}{t - x}}}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
associate-/r/ [=>]93.9% | \[ \left(t - \color{blue}{\frac{y}{z} \cdot \left(t - x\right)}\right) + \left(--1 \cdot \frac{a \cdot \left(t - x\right)}{z}\right)
\] |
mul-1-neg [=>]93.9% | \[ \left(t - \frac{y}{z} \cdot \left(t - x\right)\right) + \left(-\color{blue}{\left(-\frac{a \cdot \left(t - x\right)}{z}\right)}\right)
\] |
remove-double-neg [=>]93.9% | \[ \left(t - \frac{y}{z} \cdot \left(t - x\right)\right) + \color{blue}{\frac{a \cdot \left(t - x\right)}{z}}
\] |
associate-/l* [=>]99.8% | \[ \left(t - \frac{y}{z} \cdot \left(t - x\right)\right) + \color{blue}{\frac{a}{\frac{z}{t - x}}}
\] |
if 0.0 < (+.f64 x (*.f64 (-.f64 y z) (/.f64 (-.f64 t x) (-.f64 a z)))) Initial program 88.5%
Applied egg-rr92.4%
[Start]88.5% | \[ x + \left(y - z\right) \cdot \frac{t - x}{a - z}
\] |
|---|---|
*-commutative [=>]88.5% | \[ x + \color{blue}{\frac{t - x}{a - z} \cdot \left(y - z\right)}
\] |
associate-*l/ [=>]83.1% | \[ x + \color{blue}{\frac{\left(t - x\right) \cdot \left(y - z\right)}{a - z}}
\] |
associate-*r/ [<=]91.7% | \[ x + \color{blue}{\left(t - x\right) \cdot \frac{y - z}{a - z}}
\] |
clear-num [=>]91.7% | \[ x + \left(t - x\right) \cdot \color{blue}{\frac{1}{\frac{a - z}{y - z}}}
\] |
un-div-inv [=>]92.4% | \[ x + \color{blue}{\frac{t - x}{\frac{a - z}{y - z}}}
\] |
Final simplification95.6%
| Alternative 1 | |
|---|---|
| Accuracy | 94.7% |
| Cost | 8004 |
| Alternative 2 | |
|---|---|
| Accuracy | 94.7% |
| Cost | 2889 |
| Alternative 3 | |
|---|---|
| Accuracy | 89.5% |
| Cost | 2633 |
| Alternative 4 | |
|---|---|
| Accuracy | 93.2% |
| Cost | 2633 |
| Alternative 5 | |
|---|---|
| Accuracy | 69.2% |
| Cost | 1364 |
| Alternative 6 | |
|---|---|
| Accuracy | 55.1% |
| Cost | 1304 |
| Alternative 7 | |
|---|---|
| Accuracy | 47.3% |
| Cost | 1241 |
| Alternative 8 | |
|---|---|
| Accuracy | 47.3% |
| Cost | 1241 |
| Alternative 9 | |
|---|---|
| Accuracy | 62.8% |
| Cost | 1234 |
| Alternative 10 | |
|---|---|
| Accuracy | 38.1% |
| Cost | 1108 |
| Alternative 11 | |
|---|---|
| Accuracy | 41.6% |
| Cost | 1108 |
| Alternative 12 | |
|---|---|
| Accuracy | 39.6% |
| Cost | 1108 |
| Alternative 13 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 1104 |
| Alternative 14 | |
|---|---|
| Accuracy | 62.0% |
| Cost | 841 |
| Alternative 15 | |
|---|---|
| Accuracy | 62.6% |
| Cost | 841 |
| Alternative 16 | |
|---|---|
| Accuracy | 39.1% |
| Cost | 716 |
| Alternative 17 | |
|---|---|
| Accuracy | 39.3% |
| Cost | 328 |
| Alternative 18 | |
|---|---|
| Accuracy | 25.2% |
| Cost | 64 |
herbie shell --seed 2023263
(FPCore (x y z t a)
:name "Numeric.Signal:interpolate from hsignal-0.2.7.1"
:precision binary64
(+ x (* (- y z) (/ (- t x) (- a z)))))