Average Error: 0.0 → 0.0
Time: 3.8s
Precision: binary64
Cost: 448
\[\left(1 - x\right) \cdot y + x \cdot z \]
\[y + \left(z - y\right) \cdot x \]
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
(FPCore (x y z) :precision binary64 (+ y (* (- z y) x)))
double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
double code(double x, double y, double z) {
	return y + ((z - y) * x);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = ((1.0d0 - x) * y) + (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 = y + ((z - y) * x)
end function
public static double code(double x, double y, double z) {
	return ((1.0 - x) * y) + (x * z);
}
public static double code(double x, double y, double z) {
	return y + ((z - y) * x);
}
def code(x, y, z):
	return ((1.0 - x) * y) + (x * z)
def code(x, y, z):
	return y + ((z - y) * x)
function code(x, y, z)
	return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z))
end
function code(x, y, z)
	return Float64(y + Float64(Float64(z - y) * x))
end
function tmp = code(x, y, z)
	tmp = ((1.0 - x) * y) + (x * z);
end
function tmp = code(x, y, z)
	tmp = y + ((z - y) * x);
end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(y + N[(N[(z - y), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\left(1 - x\right) \cdot y + x \cdot z
y + \left(z - y\right) \cdot x

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.0
Target0.0
Herbie0.0
\[y - x \cdot \left(y - z\right) \]

Derivation

  1. Initial program 0.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, z - y, y\right)} \]
    Proof
    (fma.f64 x (-.f64 z y) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= unsub-neg_binary64 (+.f64 z (neg.f64 y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 z (Rewrite=> neg-mul-1_binary64 (*.f64 -1 y))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (+.f64 z (Rewrite<= *-commutative_binary64 (*.f64 y -1))) y): 0 points increase in error, 0 points decrease in error
    (fma.f64 x (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 y -1) z)) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (+.f64 (*.f64 y -1) z)) y)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 x (*.f64 y -1)) (*.f64 x z))) y): 0 points increase in error, 1 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y -1) x)) (*.f64 x z)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 -1 x))) (*.f64 x z)) y): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 y (Rewrite<= neg-mul-1_binary64 (neg.f64 x))) (*.f64 x z)) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 y (+.f64 (*.f64 y (neg.f64 x)) (*.f64 x z)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 y (*.f64 y (neg.f64 x))) (*.f64 x z))): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (Rewrite<= *-rgt-identity_binary64 (*.f64 y 1)) (*.f64 y (neg.f64 x))) (*.f64 x z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> distribute-lft-out_binary64 (*.f64 y (+.f64 1 (neg.f64 x)))) (*.f64 x z)): 3 points increase in error, 0 points decrease in error
    (+.f64 (*.f64 y (Rewrite<= sub-neg_binary64 (-.f64 1 x))) (*.f64 x z)): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 1 x) y)) (*.f64 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(z - y\right) \cdot x + y} \]
  4. Final simplification0.0

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

Alternatives

Alternative 1
Error24.0
Cost1312
\[\begin{array}{l} t_0 := x \cdot \left(-y\right)\\ \mathbf{if}\;x \leq -3.2 \cdot 10^{+165}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{+134}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -6.507492726819882 \cdot 10^{-27}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 6.861536268463632 \cdot 10^{-155}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 4.268102414692296 \cdot 10^{-135}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 2.651360217175154 \cdot 10^{-28}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+67}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 10^{+270}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 2
Error11.9
Cost784
\[\begin{array}{l} t_0 := y + z \cdot x\\ t_1 := x \cdot \left(-y\right)\\ \mathbf{if}\;x \leq -3.2 \cdot 10^{+165}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -5.8 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{+67}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{+270}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 3
Error24.0
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -6.507492726819882 \cdot 10^{-27}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 6.861536268463632 \cdot 10^{-155}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \leq 4.268102414692296 \cdot 10^{-135}:\\ \;\;\;\;z \cdot x\\ \mathbf{elif}\;x \leq 2.651360217175154 \cdot 10^{-28}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;z \cdot x\\ \end{array} \]
Alternative 4
Error8.2
Cost584
\[\begin{array}{l} t_0 := y + z \cdot x\\ \mathbf{if}\;z \leq -2.7251465681942692 \cdot 10^{-235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.895946965129719 \cdot 10^{-147}:\\ \;\;\;\;y - y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error0.8
Cost584
\[\begin{array}{l} t_0 := \left(z - y\right) \cdot x\\ \mathbf{if}\;x \leq -7.452802723478858:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5.319254274332656 \cdot 10^{-5}:\\ \;\;\;\;y + z \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error34.8
Cost64
\[y \]

Error

Reproduce

herbie shell --seed 2022291 
(FPCore (x y z)
  :name "Diagrams.Color.HSV:lerp  from diagrams-contrib-1.3.0.5"
  :precision binary64

  :herbie-target
  (- y (* x (- y z)))

  (+ (* (- 1.0 x) y) (* x z)))