Average Error: 0.0 → 0.0
Time: 5.2s
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
    (fma.f64 x (-.f64 y z) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= unsub-neg_binary64 (+.f64 y (neg.f64 z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 y (Rewrite=> neg-mul-1_binary64 (*.f64 -1 z))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 y (Rewrite<= *-commutative_binary64 (*.f64 z -1))) z): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 z -1) y)) z): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 (*.f64 z -1) y)) z)): 1 points increase in error, 1 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x (*.f64 z -1)) (*.f64 x y))) z): 1 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 z -1) x)) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 z (*.f64 -1 x))) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 z (Rewrite<= neg-mul-1_binary64 (neg.f64 x))) (*.f64 x y)) z): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-+l+_binary64 (+.f64 (*.f64 z (neg.f64 x)) (+.f64 (*.f64 x y) z))): 1 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 (+.f64 (*.f64 x y) z) (*.f64 z (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+r+_binary64 (+.f64 (*.f64 x y) (+.f64 z (*.f64 z (neg.f64 x))))): 0 points increase in error, 1 points decrease in error
    (+.f64 (*.f64 x y) (+.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 z 1)) (*.f64 z (neg.f64 x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite=> distribute-lft-out_binary64 (*.f64 z (+.f64 1 (neg.f64 x))))): 2 points increase in error, 1 points decrease in error
    (+.f64 (*.f64 x y) (*.f64 z (Rewrite<= sub-neg_binary64 (-.f64 1 x)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 x y) (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 x) z))): 0 points increase in error, 0 points decrease in error
  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
Error16.4
Cost584
\[\begin{array}{l} t_0 := z - z \cdot x\\ \mathbf{if}\;z \leq -2.794700044604555 \cdot 10^{-168}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.4749610311898457 \cdot 10^{-169}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error8.5
Cost584
\[\begin{array}{l} t_0 := z - z \cdot x\\ \mathbf{if}\;z \leq -9.331122644302201 \cdot 10^{+55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.5952343217733636 \cdot 10^{-9}:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.0
Cost584
\[\begin{array}{l} t_0 := \left(y - z\right) \cdot x\\ \mathbf{if}\;x \leq -966.3580826460436:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.782499448674103 \cdot 10^{-5}:\\ \;\;\;\;z + y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error22.9
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.0023786088959848 \cdot 10^{-27}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \leq 9.191320262236147 \cdot 10^{-13}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
Alternative 5
Error34.2
Cost64
\[z \]

Error

Reproduce

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