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

(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 -1e-266)
(fma (/ (- z t) (- a t)) (- y x) x)
(if (<= t_1 0.0)
(+ y (/ (- x y) (/ t (- z a))))
(+ x (/ (- y x) (/ (- a t) (- z 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 <= -1e-266) {
tmp = fma(((z - t) / (a - t)), (y - x), x);
} else if (t_1 <= 0.0) {
tmp = y + ((x - y) / (t / (z - a)));
} else {
tmp = x + ((y - x) / ((a - t) / (z - 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 <= -1e-266) tmp = fma(Float64(Float64(z - t) / Float64(a - t)), Float64(y - x), x); elseif (t_1 <= 0.0) tmp = Float64(y + Float64(Float64(x - y) / Float64(t / Float64(z - a)))); else tmp = Float64(x + Float64(Float64(y - x) / Float64(Float64(a - t) / Float64(z - t)))); end return 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, -1e-266], N[(N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * N[(y - x), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(y + N[(N[(x - y), $MachinePrecision] / N[(t / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y - x), $MachinePrecision] / N[(N[(a - t), $MachinePrecision] / N[(z - 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 -1 \cdot 10^{-266}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{a - t}, y - x, x\right)\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;y + \frac{x - y}{\frac{t}{z - a}}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y - x}{\frac{a - t}{z - t}}\\
\end{array}
Herbie found 18 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 67.4% |
|---|---|
| Target | 86.3% |
| Herbie | 90.3% |
if (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < -9.9999999999999998e-267Initial program 75.2%
Simplified89.2%
[Start]75.2% | \[ x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\] |
|---|---|
+-commutative [=>]75.2% | \[ \color{blue}{\frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} + x}
\] |
associate-*r/ [<=]89.2% | \[ \color{blue}{\left(y - x\right) \cdot \frac{z - t}{a - t}} + x
\] |
*-commutative [<=]89.2% | \[ \color{blue}{\frac{z - t}{a - t} \cdot \left(y - x\right)} + x
\] |
fma-def [=>]89.2% | \[ \color{blue}{\mathsf{fma}\left(\frac{z - t}{a - t}, y - x, x\right)}
\] |
if -9.9999999999999998e-267 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) < 0.0Initial program 3.8%
Simplified3.8%
[Start]3.8% | \[ x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\] |
|---|---|
+-commutative [=>]3.8% | \[ \color{blue}{\frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t} + x}
\] |
associate-*r/ [<=]3.8% | \[ \color{blue}{\left(y - x\right) \cdot \frac{z - t}{a - t}} + x
\] |
*-commutative [<=]3.8% | \[ \color{blue}{\frac{z - t}{a - t} \cdot \left(y - x\right)} + x
\] |
fma-def [=>]3.8% | \[ \color{blue}{\mathsf{fma}\left(\frac{z - t}{a - t}, y - x, x\right)}
\] |
Taylor expanded in t around inf 99.9%
Simplified99.9%
[Start]99.9% | \[ y + \frac{\left(-1 \cdot z - -1 \cdot a\right) \cdot \left(y - x\right)}{t}
\] |
|---|---|
*-commutative [<=]99.9% | \[ y + \frac{\color{blue}{\left(y - x\right) \cdot \left(-1 \cdot z - -1 \cdot a\right)}}{t}
\] |
cancel-sign-sub-inv [=>]99.9% | \[ y + \frac{\left(y - x\right) \cdot \color{blue}{\left(-1 \cdot z + \left(--1\right) \cdot a\right)}}{t}
\] |
metadata-eval [=>]99.9% | \[ y + \frac{\left(y - x\right) \cdot \left(-1 \cdot z + \color{blue}{1} \cdot a\right)}{t}
\] |
*-lft-identity [=>]99.9% | \[ y + \frac{\left(y - x\right) \cdot \left(-1 \cdot z + \color{blue}{a}\right)}{t}
\] |
distribute-lft-in [=>]99.9% | \[ y + \frac{\color{blue}{\left(y - x\right) \cdot \left(-1 \cdot z\right) + \left(y - x\right) \cdot a}}{t}
\] |
mul-1-neg [=>]99.9% | \[ y + \frac{\left(y - x\right) \cdot \color{blue}{\left(-z\right)} + \left(y - x\right) \cdot a}{t}
\] |
distribute-rgt-neg-in [<=]99.9% | \[ y + \frac{\color{blue}{\left(-\left(y - x\right) \cdot z\right)} + \left(y - x\right) \cdot a}{t}
\] |
mul-1-neg [<=]99.9% | \[ y + \frac{\color{blue}{-1 \cdot \left(\left(y - x\right) \cdot z\right)} + \left(y - x\right) \cdot a}{t}
\] |
*-commutative [<=]99.9% | \[ y + \frac{-1 \cdot \left(\left(y - x\right) \cdot z\right) + \color{blue}{a \cdot \left(y - x\right)}}{t}
\] |
cancel-sign-sub [<=]99.9% | \[ y + \frac{\color{blue}{-1 \cdot \left(\left(y - x\right) \cdot z\right) - \left(-a\right) \cdot \left(y - x\right)}}{t}
\] |
mul-1-neg [<=]99.9% | \[ y + \frac{-1 \cdot \left(\left(y - x\right) \cdot z\right) - \color{blue}{\left(-1 \cdot a\right)} \cdot \left(y - x\right)}{t}
\] |
associate-*r* [<=]99.9% | \[ y + \frac{-1 \cdot \left(\left(y - x\right) \cdot z\right) - \color{blue}{-1 \cdot \left(a \cdot \left(y - x\right)\right)}}{t}
\] |
distribute-lft-out-- [=>]99.9% | \[ y + \frac{\color{blue}{-1 \cdot \left(\left(y - x\right) \cdot z - a \cdot \left(y - x\right)\right)}}{t}
\] |
associate-*r/ [<=]99.9% | \[ y + \color{blue}{-1 \cdot \frac{\left(y - x\right) \cdot z - a \cdot \left(y - x\right)}{t}}
\] |
mul-1-neg [=>]99.9% | \[ y + \color{blue}{\left(-\frac{\left(y - x\right) \cdot z - a \cdot \left(y - x\right)}{t}\right)}
\] |
if 0.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) (-.f64 z t)) (-.f64 a t))) Initial program 67.2%
Simplified91.5%
[Start]67.2% | \[ x + \frac{\left(y - x\right) \cdot \left(z - t\right)}{a - t}
\] |
|---|---|
associate-/l* [=>]91.5% | \[ x + \color{blue}{\frac{y - x}{\frac{a - t}{z - t}}}
\] |
Final simplification91.2%
| Alternative 1 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 8004 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.4% |
| Cost | 2633 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 2632 |
| Alternative 4 | |
|---|---|
| Accuracy | 46.0% |
| Cost | 1504 |
| Alternative 5 | |
|---|---|
| Accuracy | 46.3% |
| Cost | 1504 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.9% |
| Cost | 1369 |
| Alternative 7 | |
|---|---|
| Accuracy | 37.9% |
| Cost | 1244 |
| Alternative 8 | |
|---|---|
| Accuracy | 39.9% |
| Cost | 1240 |
| Alternative 9 | |
|---|---|
| Accuracy | 47.6% |
| Cost | 1240 |
| Alternative 10 | |
|---|---|
| Accuracy | 72.9% |
| Cost | 1234 |
| Alternative 11 | |
|---|---|
| Accuracy | 56.3% |
| Cost | 1104 |
| Alternative 12 | |
|---|---|
| Accuracy | 38.7% |
| Cost | 980 |
| Alternative 13 | |
|---|---|
| Accuracy | 49.4% |
| Cost | 976 |
| Alternative 14 | |
|---|---|
| Accuracy | 66.3% |
| Cost | 972 |
| Alternative 15 | |
|---|---|
| Accuracy | 78.9% |
| Cost | 969 |
| Alternative 16 | |
|---|---|
| Accuracy | 37.9% |
| Cost | 328 |
| Alternative 17 | |
|---|---|
| Accuracy | 2.8% |
| Cost | 64 |
| Alternative 18 | |
|---|---|
| Accuracy | 25.3% |
| Cost | 64 |
herbie shell --seed 2023272
(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))))