| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 2512 |
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* t (* y (- x z)))) (t_2 (- (* x y) (* y z))))
(if (<= t_2 (- INFINITY))
(* (- x z) (* y t))
(if (<= t_2 -1e-102)
t_1
(if (<= t_2 1e-146)
(fma y (* x t) (* z (* y (- t))))
(if (<= t_2 1e+164) t_1 (* 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 = t * (y * (x - z));
double t_2 = (x * y) - (y * z);
double tmp;
if (t_2 <= -((double) INFINITY)) {
tmp = (x - z) * (y * t);
} else if (t_2 <= -1e-102) {
tmp = t_1;
} else if (t_2 <= 1e-146) {
tmp = fma(y, (x * t), (z * (y * -t)));
} else if (t_2 <= 1e+164) {
tmp = t_1;
} 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(t * Float64(y * Float64(x - z))) t_2 = Float64(Float64(x * y) - Float64(y * z)) tmp = 0.0 if (t_2 <= Float64(-Inf)) tmp = Float64(Float64(x - z) * Float64(y * t)); elseif (t_2 <= -1e-102) tmp = t_1; elseif (t_2 <= 1e-146) tmp = fma(y, Float64(x * t), Float64(z * Float64(y * Float64(-t)))); elseif (t_2 <= 1e+164) tmp = t_1; 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[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -1e-102], t$95$1, If[LessEqual[t$95$2, 1e-146], N[(y * N[(x * t), $MachinePrecision] + N[(z * N[(y * (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+164], t$95$1, 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 := t \cdot \left(y \cdot \left(x - z\right)\right)\\
t_2 := x \cdot y - y \cdot z\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-102}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq 10^{-146}:\\
\;\;\;\;\mathsf{fma}\left(y, x \cdot t, z \cdot \left(y \cdot \left(-t\right)\right)\right)\\
\mathbf{elif}\;t_2 \leq 10^{+164}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\
\end{array}
| Original | 7.0 |
|---|---|
| Target | 3.4 |
| Herbie | 1.1 |
if (-.f64 (*.f64 x y) (*.f64 z y)) < -inf.0Initial program 64.0
Simplified0.3
[Start]64.0 | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]64.0 | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
associate-*l* [=>]0.3 | \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)}
\] |
*-commutative [=>]0.3 | \[ y \cdot \color{blue}{\left(t \cdot \left(x - z\right)\right)}
\] |
Taylor expanded in x around 0 0.3
Simplified0.3
[Start]0.3 | \[ y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
|---|---|
mul-1-neg [=>]0.3 | \[ y \cdot \left(t \cdot x\right) + \color{blue}{\left(-y \cdot \left(t \cdot z\right)\right)}
\] |
associate-*r* [=>]0.3 | \[ \color{blue}{\left(y \cdot t\right) \cdot x} + \left(-y \cdot \left(t \cdot z\right)\right)
\] |
associate-*r* [=>]0.3 | \[ \left(y \cdot t\right) \cdot x + \left(-\color{blue}{\left(y \cdot t\right) \cdot z}\right)
\] |
distribute-rgt-neg-out [<=]0.3 | \[ \left(y \cdot t\right) \cdot x + \color{blue}{\left(y \cdot t\right) \cdot \left(-z\right)}
\] |
distribute-lft-in [<=]0.3 | \[ \color{blue}{\left(y \cdot t\right) \cdot \left(x + \left(-z\right)\right)}
\] |
sub-neg [<=]0.3 | \[ \left(y \cdot t\right) \cdot \color{blue}{\left(x - z\right)}
\] |
*-commutative [=>]0.3 | \[ \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)}
\] |
if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z y)) < -9.99999999999999933e-103 or 1.00000000000000003e-146 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1e164Initial program 0.2
Simplified0.2
[Start]0.2 | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]0.2 | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
if -9.99999999999999933e-103 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1.00000000000000003e-146Initial program 5.4
Simplified2.7
[Start]5.4 | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]5.4 | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
associate-*l* [=>]2.7 | \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)}
\] |
*-commutative [=>]2.7 | \[ y \cdot \color{blue}{\left(t \cdot \left(x - z\right)\right)}
\] |
Taylor expanded in x around 0 2.7
Simplified2.8
[Start]2.7 | \[ y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
|---|---|
mul-1-neg [=>]2.7 | \[ y \cdot \left(t \cdot x\right) + \color{blue}{\left(-y \cdot \left(t \cdot z\right)\right)}
\] |
associate-*r* [=>]3.2 | \[ \color{blue}{\left(y \cdot t\right) \cdot x} + \left(-y \cdot \left(t \cdot z\right)\right)
\] |
associate-*r* [=>]2.8 | \[ \left(y \cdot t\right) \cdot x + \left(-\color{blue}{\left(y \cdot t\right) \cdot z}\right)
\] |
distribute-rgt-neg-out [<=]2.8 | \[ \left(y \cdot t\right) \cdot x + \color{blue}{\left(y \cdot t\right) \cdot \left(-z\right)}
\] |
distribute-lft-in [<=]2.8 | \[ \color{blue}{\left(y \cdot t\right) \cdot \left(x + \left(-z\right)\right)}
\] |
sub-neg [<=]2.8 | \[ \left(y \cdot t\right) \cdot \color{blue}{\left(x - z\right)}
\] |
*-commutative [=>]2.8 | \[ \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)}
\] |
Taylor expanded in x around 0 2.7
Simplified2.9
[Start]2.7 | \[ y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)
\] |
|---|---|
mul-1-neg [=>]2.7 | \[ y \cdot \left(t \cdot x\right) + \color{blue}{\left(-y \cdot \left(t \cdot z\right)\right)}
\] |
associate-*r* [=>]2.9 | \[ y \cdot \left(t \cdot x\right) + \left(-\color{blue}{\left(y \cdot t\right) \cdot z}\right)
\] |
distribute-rgt-neg-out [<=]2.9 | \[ y \cdot \left(t \cdot x\right) + \color{blue}{\left(y \cdot t\right) \cdot \left(-z\right)}
\] |
*-lft-identity [<=]2.9 | \[ y \cdot \left(t \cdot x\right) + \color{blue}{1 \cdot \left(\left(y \cdot t\right) \cdot \left(-z\right)\right)}
\] |
*-commutative [<=]2.9 | \[ y \cdot \left(t \cdot x\right) + \color{blue}{\left(\left(y \cdot t\right) \cdot \left(-z\right)\right) \cdot 1}
\] |
fma-def [=>]2.9 | \[ \color{blue}{\mathsf{fma}\left(y, t \cdot x, \left(\left(y \cdot t\right) \cdot \left(-z\right)\right) \cdot 1\right)}
\] |
*-commutative [=>]2.9 | \[ \mathsf{fma}\left(y, t \cdot x, \color{blue}{1 \cdot \left(\left(y \cdot t\right) \cdot \left(-z\right)\right)}\right)
\] |
*-lft-identity [=>]2.9 | \[ \mathsf{fma}\left(y, t \cdot x, \color{blue}{\left(y \cdot t\right) \cdot \left(-z\right)}\right)
\] |
if 1e164 < (-.f64 (*.f64 x y) (*.f64 z y)) Initial program 24.0
Simplified2.3
[Start]24.0 | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]24.0 | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
associate-*l* [=>]2.3 | \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)}
\] |
*-commutative [=>]2.3 | \[ y \cdot \color{blue}{\left(t \cdot \left(x - z\right)\right)}
\] |
Final simplification1.1
| Alternative 1 | |
|---|---|
| Error | 0.6 |
| Cost | 2512 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 2512 |
| Alternative 3 | |
|---|---|
| Error | 20.2 |
| Cost | 912 |
| Alternative 4 | |
|---|---|
| Error | 19.8 |
| Cost | 649 |
| Alternative 5 | |
|---|---|
| Error | 2.7 |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Error | 2.7 |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Error | 29.8 |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Error | 7.3 |
| Cost | 448 |
| Alternative 9 | |
|---|---|
| Error | 31.9 |
| Cost | 320 |
herbie shell --seed 2023060
(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))