| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
\[z + \left(y - z\right) \cdot x
\]

(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
(FPCore (x y z) :precision binary64 (+ z (* (- y z) x)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
double code(double x, double y, double z) {
return z + ((y - z) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * y) + ((1.0d0 - x) * z)
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((y - z) * x)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
public static double code(double x, double y, double z) {
return z + ((y - z) * x);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
def code(x, y, z): return z + ((y - z) * x)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function code(x, y, z) return Float64(z + Float64(Float64(y - z) * x)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
function tmp = code(x, y, z) tmp = z + ((y - z) * x); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(z + N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
x \cdot y + \left(1 - x\right) \cdot z
\begin{array}{l}
\\
z + \left(y - z\right) \cdot x
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 98.4%
Simplified100.0%
[Start]98.4% | \[ x \cdot y + \left(1 - x\right) \cdot z
\] |
|---|---|
sub-neg [=>]98.4% | \[ x \cdot y + \color{blue}{\left(1 + \left(-x\right)\right)} \cdot z
\] |
+-commutative [=>]98.4% | \[ x \cdot y + \color{blue}{\left(\left(-x\right) + 1\right)} \cdot z
\] |
distribute-lft1-in [<=]98.4% | \[ x \cdot y + \color{blue}{\left(\left(-x\right) \cdot z + z\right)}
\] |
associate-+r+ [=>]98.4% | \[ \color{blue}{\left(x \cdot y + \left(-x\right) \cdot z\right) + z}
\] |
+-commutative [<=]98.4% | \[ \color{blue}{\left(\left(-x\right) \cdot z + x \cdot y\right)} + z
\] |
*-commutative [=>]98.4% | \[ \left(\color{blue}{z \cdot \left(-x\right)} + x \cdot y\right) + z
\] |
neg-mul-1 [=>]98.4% | \[ \left(z \cdot \color{blue}{\left(-1 \cdot x\right)} + x \cdot y\right) + z
\] |
associate-*r* [=>]98.4% | \[ \left(\color{blue}{\left(z \cdot -1\right) \cdot x} + x \cdot y\right) + z
\] |
*-commutative [=>]98.4% | \[ \left(\left(z \cdot -1\right) \cdot x + \color{blue}{y \cdot x}\right) + z
\] |
distribute-rgt-out [=>]100.0% | \[ \color{blue}{x \cdot \left(z \cdot -1 + y\right)} + z
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, z \cdot -1 + y, z\right)}
\] |
+-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{y + z \cdot -1}, z\right)
\] |
*-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, y + \color{blue}{-1 \cdot z}, z\right)
\] |
neg-mul-1 [<=]100.0% | \[ \mathsf{fma}\left(x, y + \color{blue}{\left(-z\right)}, z\right)
\] |
unsub-neg [=>]100.0% | \[ \mathsf{fma}\left(x, \color{blue}{y - z}, z\right)
\] |
Taylor expanded in x around 0 100.0%
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 448 |
| Alternative 2 | |
|---|---|
| Accuracy | 61.9% |
| Cost | 784 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.5% |
| Cost | 585 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 585 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.1% |
| Cost | 584 |
| Alternative 6 | |
|---|---|
| Accuracy | 62.0% |
| Cost | 456 |
| Alternative 7 | |
|---|---|
| Accuracy | 36.4% |
| Cost | 64 |
herbie shell --seed 2023167
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))