?

Average Error: 0.0 → 0.0
Time: 3.6s
Precision: binary64
Cost: 448

?

\[x \cdot y + \left(1 - x\right) \cdot z \]
\[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
z + \left(y - z\right) \cdot x

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 0.0

    \[x \cdot y + \left(1 - x\right) \cdot z \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y - z, z\right)} \]
    Proof

    [Start]0.0

    \[ x \cdot y + \left(1 - x\right) \cdot z \]

    +-commutative [=>]0.0

    \[ \color{blue}{\left(1 - x\right) \cdot z + x \cdot y} \]

    *-commutative [=>]0.0

    \[ \color{blue}{z \cdot \left(1 - x\right)} + x \cdot y \]

    sub-neg [=>]0.0

    \[ z \cdot \color{blue}{\left(1 + \left(-x\right)\right)} + x \cdot y \]

    distribute-rgt-in [=>]0.0

    \[ \color{blue}{\left(1 \cdot z + \left(-x\right) \cdot z\right)} + x \cdot y \]

    associate-+l+ [=>]0.0

    \[ \color{blue}{1 \cdot z + \left(\left(-x\right) \cdot z + x \cdot y\right)} \]

    *-lft-identity [=>]0.0

    \[ \color{blue}{z} + \left(\left(-x\right) \cdot z + x \cdot y\right) \]

    +-commutative [=>]0.0

    \[ \color{blue}{\left(\left(-x\right) \cdot z + x \cdot y\right) + z} \]

    *-commutative [=>]0.0

    \[ \left(\color{blue}{z \cdot \left(-x\right)} + x \cdot y\right) + z \]

    neg-mul-1 [=>]0.0

    \[ \left(z \cdot \color{blue}{\left(-1 \cdot x\right)} + x \cdot y\right) + z \]

    associate-*r* [=>]0.0

    \[ \left(\color{blue}{\left(z \cdot -1\right) \cdot x} + x \cdot y\right) + z \]

    *-commutative [=>]0.0

    \[ \left(\left(z \cdot -1\right) \cdot x + \color{blue}{y \cdot x}\right) + z \]

    distribute-rgt-out [=>]0.0

    \[ \color{blue}{x \cdot \left(z \cdot -1 + y\right)} + z \]

    fma-def [=>]0.0

    \[ \color{blue}{\mathsf{fma}\left(x, z \cdot -1 + y, z\right)} \]

    +-commutative [=>]0.0

    \[ \mathsf{fma}\left(x, \color{blue}{y + z \cdot -1}, z\right) \]

    *-commutative [=>]0.0

    \[ \mathsf{fma}\left(x, y + \color{blue}{-1 \cdot z}, z\right) \]

    metadata-eval [<=]0.0

    \[ \mathsf{fma}\left(x, y + \color{blue}{\left(-1\right)} \cdot z, z\right) \]

    cancel-sign-sub-inv [<=]0.0

    \[ \mathsf{fma}\left(x, \color{blue}{y - 1 \cdot z}, z\right) \]

    *-lft-identity [=>]0.0

    \[ \mathsf{fma}\left(x, y - \color{blue}{z}, z\right) \]
  3. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{\left(y - z\right) \cdot x + z} \]
  4. Final simplification0.0

    \[\leadsto z + \left(y - z\right) \cdot x \]

Alternatives

Alternative 1
Error25.7
Cost720
\[\begin{array}{l} \mathbf{if}\;z \leq -12000000000:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 1.01 \cdot 10^{-156}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{-99}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-28}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 2
Error12.8
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{-97} \lor \neg \left(x \leq 6.8 \cdot 10^{-10}\right):\\ \;\;\;\;\left(y - z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
Alternative 3
Error0.9
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.7 \cdot 10^{-7}\right):\\ \;\;\;\;\left(y - z\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;z + y \cdot x\\ \end{array} \]
Alternative 4
Error34.6
Cost64
\[z \]

Error

Reproduce?

herbie shell --seed 2023073 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
  :precision binary64
  (+ (* x y) (* (- 1.0 x) z)))