| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 1864 |
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* x y) (* y z))))
(if (<= t_1 -1e+283)
(* (- x z) (* y t))
(if (<= t_1 2e+231)
(fma (* y (- x z)) t (* t (fma y (- z) (* y z))))
(* y (* (- x z) t))))))double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
double code(double x, double y, double z, double t) {
double t_1 = (x * y) - (y * z);
double tmp;
if (t_1 <= -1e+283) {
tmp = (x - z) * (y * t);
} else if (t_1 <= 2e+231) {
tmp = fma((y * (x - z)), t, (t * fma(y, -z, (y * z))));
} else {
tmp = y * ((x - z) * t);
}
return tmp;
}
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function code(x, y, z, t) t_1 = Float64(Float64(x * y) - Float64(y * z)) tmp = 0.0 if (t_1 <= -1e+283) tmp = Float64(Float64(x - z) * Float64(y * t)); elseif (t_1 <= 2e+231) tmp = fma(Float64(y * Float64(x - z)), t, Float64(t * fma(y, Float64(-z), Float64(y * z)))); else tmp = Float64(y * Float64(Float64(x - z) * t)); end return tmp end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+283], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+231], N[(N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] * t + N[(t * N[(y * (-z) + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
t_1 := x \cdot y - y \cdot z\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+283}:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+231}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left(x - z\right), t, t \cdot \mathsf{fma}\left(y, -z, y \cdot z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\
\end{array}
| Original | 89.0% |
|---|---|
| Target | 94.7% |
| Herbie | 97.9% |
if (-.f64 (*.f64 x y) (*.f64 z y)) < -9.99999999999999955e282Initial program 19.3%
Taylor expanded in x around 0 99.5%
Simplified99.6%
[Start]99.5 | \[ y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
|---|---|
associate-*r* [=>]99.6 | \[ \color{blue}{\left(y \cdot t\right) \cdot x} + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
*-commutative [<=]99.6 | \[ \color{blue}{\left(t \cdot y\right)} \cdot x + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
mul-1-neg [=>]99.6 | \[ \left(t \cdot y\right) \cdot x + \color{blue}{\left(-y \cdot \left(t \cdot z\right)\right)}
\] |
associate-*r* [=>]99.6 | \[ \left(t \cdot y\right) \cdot x + \left(-\color{blue}{\left(y \cdot t\right) \cdot z}\right)
\] |
*-commutative [<=]99.6 | \[ \left(t \cdot y\right) \cdot x + \left(-\color{blue}{\left(t \cdot y\right)} \cdot z\right)
\] |
distribute-rgt-neg-in [=>]99.6 | \[ \left(t \cdot y\right) \cdot x + \color{blue}{\left(t \cdot y\right) \cdot \left(-z\right)}
\] |
distribute-lft-in [<=]99.6 | \[ \color{blue}{\left(t \cdot y\right) \cdot \left(x + \left(-z\right)\right)}
\] |
sub-neg [<=]99.6 | \[ \left(t \cdot y\right) \cdot \color{blue}{\left(x - z\right)}
\] |
*-commutative [=>]99.6 | \[ \color{blue}{\left(x - z\right) \cdot \left(t \cdot y\right)}
\] |
*-commutative [=>]99.6 | \[ \left(x - z\right) \cdot \color{blue}{\left(y \cdot t\right)}
\] |
if -9.99999999999999955e282 < (-.f64 (*.f64 x y) (*.f64 z y)) < 2.0000000000000001e231Initial program 97.5%
Applied egg-rr97.7%
[Start]97.5 | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
*-commutative [=>]97.5 | \[ \color{blue}{t \cdot \left(x \cdot y - z \cdot y\right)}
\] |
prod-diff [=>]97.5 | \[ t \cdot \color{blue}{\left(\mathsf{fma}\left(x, y, -y \cdot z\right) + \mathsf{fma}\left(-y, z, y \cdot z\right)\right)}
\] |
*-commutative [<=]97.5 | \[ t \cdot \left(\mathsf{fma}\left(x, y, -\color{blue}{z \cdot y}\right) + \mathsf{fma}\left(-y, z, y \cdot z\right)\right)
\] |
fma-neg [<=]97.5 | \[ t \cdot \left(\color{blue}{\left(x \cdot y - z \cdot y\right)} + \mathsf{fma}\left(-y, z, y \cdot z\right)\right)
\] |
distribute-rgt-in [=>]97.6 | \[ \color{blue}{\left(x \cdot y - z \cdot y\right) \cdot t + \mathsf{fma}\left(-y, z, y \cdot z\right) \cdot t}
\] |
fma-def [=>]97.7 | \[ \color{blue}{\mathsf{fma}\left(x \cdot y - z \cdot y, t, \mathsf{fma}\left(-y, z, y \cdot z\right) \cdot t\right)}
\] |
distribute-rgt-out-- [=>]97.7 | \[ \mathsf{fma}\left(\color{blue}{y \cdot \left(x - z\right)}, t, \mathsf{fma}\left(-y, z, y \cdot z\right) \cdot t\right)
\] |
*-commutative [<=]97.7 | \[ \mathsf{fma}\left(y \cdot \left(x - z\right), t, \mathsf{fma}\left(-y, z, \color{blue}{z \cdot y}\right) \cdot t\right)
\] |
fma-udef [=>]97.5 | \[ \mathsf{fma}\left(y \cdot \left(x - z\right), t, \color{blue}{\left(\left(-y\right) \cdot z + z \cdot y\right)} \cdot t\right)
\] |
distribute-lft-neg-in [<=]97.5 | \[ \mathsf{fma}\left(y \cdot \left(x - z\right), t, \left(\color{blue}{\left(-y \cdot z\right)} + z \cdot y\right) \cdot t\right)
\] |
distribute-rgt-neg-in [=>]97.5 | \[ \mathsf{fma}\left(y \cdot \left(x - z\right), t, \left(\color{blue}{y \cdot \left(-z\right)} + z \cdot y\right) \cdot t\right)
\] |
fma-def [=>]97.7 | \[ \mathsf{fma}\left(y \cdot \left(x - z\right), t, \color{blue}{\mathsf{fma}\left(y, -z, z \cdot y\right)} \cdot t\right)
\] |
*-commutative [=>]97.7 | \[ \mathsf{fma}\left(y \cdot \left(x - z\right), t, \mathsf{fma}\left(y, -z, \color{blue}{y \cdot z}\right) \cdot t\right)
\] |
if 2.0000000000000001e231 < (-.f64 (*.f64 x y) (*.f64 z y)) Initial program 44.2%
Simplified98.2%
[Start]44.2 | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]44.2 | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
associate-*l* [=>]98.2 | \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)}
\] |
Final simplification97.9%
| Alternative 1 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 1864 |
| Alternative 2 | |
|---|---|
| Accuracy | 68.6% |
| Cost | 1176 |
| Alternative 3 | |
|---|---|
| Accuracy | 68.9% |
| Cost | 912 |
| Alternative 4 | |
|---|---|
| Accuracy | 68.9% |
| Cost | 912 |
| Alternative 5 | |
|---|---|
| Accuracy | 87.5% |
| Cost | 648 |
| Alternative 6 | |
|---|---|
| Accuracy | 95.8% |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Accuracy | 55.0% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 53.5% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 51.2% |
| Cost | 320 |
herbie shell --seed 2023151
(FPCore (x y z t)
:name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t)))
(* (- (* x y) (* z y)) t))