?

Average Error: 3.3 → 0.1
Time: 10.3s
Precision: binary64
Cost: 840

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -1.42 \cdot 10^{-5}:\\ \;\;\;\;x - \frac{z \cdot x}{\frac{1}{1 - y}}\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-25}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.42e-5)
   (- x (/ (* z x) (/ 1.0 (- 1.0 y))))
   (if (<= z 2e-25)
     (* x (+ 1.0 (* z (+ y -1.0))))
     (+ x (* z (* x (+ y -1.0)))))))
double code(double x, double y, double z) {
	return x * (1.0 - ((1.0 - y) * z));
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.42e-5) {
		tmp = x - ((z * x) / (1.0 / (1.0 - y)));
	} else if (z <= 2e-25) {
		tmp = x * (1.0 + (z * (y + -1.0)));
	} else {
		tmp = x + (z * (x * (y + -1.0)));
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - ((1.0d0 - y) * 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
    real(8) :: tmp
    if (z <= (-1.42d-5)) then
        tmp = x - ((z * x) / (1.0d0 / (1.0d0 - y)))
    else if (z <= 2d-25) then
        tmp = x * (1.0d0 + (z * (y + (-1.0d0))))
    else
        tmp = x + (z * (x * (y + (-1.0d0))))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - ((1.0 - y) * z));
}
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.42e-5) {
		tmp = x - ((z * x) / (1.0 / (1.0 - y)));
	} else if (z <= 2e-25) {
		tmp = x * (1.0 + (z * (y + -1.0)));
	} else {
		tmp = x + (z * (x * (y + -1.0)));
	}
	return tmp;
}
def code(x, y, z):
	return x * (1.0 - ((1.0 - y) * z))
def code(x, y, z):
	tmp = 0
	if z <= -1.42e-5:
		tmp = x - ((z * x) / (1.0 / (1.0 - y)))
	elif z <= 2e-25:
		tmp = x * (1.0 + (z * (y + -1.0)))
	else:
		tmp = x + (z * (x * (y + -1.0)))
	return tmp
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z)))
end
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.42e-5)
		tmp = Float64(x - Float64(Float64(z * x) / Float64(1.0 / Float64(1.0 - y))));
	elseif (z <= 2e-25)
		tmp = Float64(x * Float64(1.0 + Float64(z * Float64(y + -1.0))));
	else
		tmp = Float64(x + Float64(z * Float64(x * Float64(y + -1.0))));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - ((1.0 - y) * z));
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.42e-5)
		tmp = x - ((z * x) / (1.0 / (1.0 - y)));
	elseif (z <= 2e-25)
		tmp = x * (1.0 + (z * (y + -1.0)));
	else
		tmp = x + (z * (x * (y + -1.0)));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[z, -1.42e-5], N[(x - N[(N[(z * x), $MachinePrecision] / N[(1.0 / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e-25], N[(x * N[(1.0 + N[(z * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\begin{array}{l}
\mathbf{if}\;z \leq -1.42 \cdot 10^{-5}:\\
\;\;\;\;x - \frac{z \cdot x}{\frac{1}{1 - y}}\\

\mathbf{elif}\;z \leq 2 \cdot 10^{-25}:\\
\;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.3
Target0.2
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) < -1.618195973607049 \cdot 10^{+50}:\\ \;\;\;\;x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \mathbf{elif}\;x \cdot \left(1 - \left(1 - y\right) \cdot z\right) < 3.892237649663903 \cdot 10^{+134}:\\ \;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -1.42e-5

    1. Initial program 7.9

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Simplified7.9

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

      [Start]7.9

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

      *-commutative [=>]7.9

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

      sub-neg [=>]7.9

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

      distribute-rgt-in [=>]7.9

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

      associate--r+ [=>]7.9

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

      *-lft-identity [=>]7.9

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

      sub-neg [=>]7.9

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

      distribute-lft-out-- [<=]7.9

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

      distribute-lft-in [=>]7.9

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

      *-rgt-identity [=>]7.9

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

      +-commutative [=>]7.9

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

      associate-+r- [<=]7.9

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

      *-commutative [=>]7.9

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

      cancel-sign-sub-inv [=>]7.9

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

      distribute-rgt-neg-in [=>]7.9

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

      distribute-rgt1-in [=>]7.9

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

      *-commutative [=>]7.9

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

      +-commutative [=>]7.9

      \[ \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right) + x \cdot \left(-z\right)} \]
    3. Taylor expanded in z around -inf 0.1

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

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

      [Start]0.1

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

      +-commutative [=>]0.1

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

      mul-1-neg [=>]0.1

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

      unsub-neg [=>]0.1

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

      associate-*r* [=>]7.9

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

      *-commutative [=>]7.9

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

      associate-*l* [=>]0.1

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

      mul-1-neg [=>]0.1

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

      unsub-neg [=>]0.1

      \[ x - z \cdot \left(\color{blue}{\left(1 - y\right)} \cdot x\right) \]
    5. Applied egg-rr0.2

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

    if -1.42e-5 < z < 2.00000000000000008e-25

    1. Initial program 0.1

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

    if 2.00000000000000008e-25 < z

    1. Initial program 7.4

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Simplified7.4

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

      [Start]7.4

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

      *-commutative [=>]7.4

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

      sub-neg [=>]7.4

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

      distribute-rgt-in [=>]7.4

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

      associate--r+ [=>]7.4

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

      *-lft-identity [=>]7.4

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

      sub-neg [=>]7.4

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

      distribute-lft-out-- [<=]7.4

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

      distribute-lft-in [=>]7.4

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

      *-rgt-identity [=>]7.4

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

      +-commutative [=>]7.4

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

      associate-+r- [<=]7.4

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

      *-commutative [=>]7.4

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

      cancel-sign-sub-inv [=>]7.4

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

      distribute-rgt-neg-in [=>]7.4

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

      distribute-rgt1-in [=>]7.4

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

      *-commutative [=>]7.4

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

      +-commutative [=>]7.4

      \[ \color{blue}{x \cdot \left(\left(-y\right) \cdot \left(-z\right) + 1\right) + x \cdot \left(-z\right)} \]
    3. Taylor expanded in z around -inf 0.1

      \[\leadsto \color{blue}{-1 \cdot \left(\left(1 + -1 \cdot y\right) \cdot \left(z \cdot x\right)\right) + x} \]
    4. Simplified0.3

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

      [Start]0.1

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

      +-commutative [=>]0.1

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

      mul-1-neg [=>]0.1

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

      unsub-neg [=>]0.1

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

      associate-*r* [=>]7.4

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

      *-commutative [=>]7.4

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

      associate-*l* [=>]0.3

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

      mul-1-neg [=>]0.3

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

      unsub-neg [=>]0.3

      \[ x - z \cdot \left(\color{blue}{\left(1 - y\right)} \cdot x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.42 \cdot 10^{-5}:\\ \;\;\;\;x - \frac{z \cdot x}{\frac{1}{1 - y}}\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-25}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.1
Cost1352
\[\begin{array}{l} t_0 := z \cdot \left(1 - y\right)\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+249}:\\ \;\;\;\;z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+194}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \end{array} \]
Alternative 2
Error0.1
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1.42 \cdot 10^{-5} \lor \neg \left(z \leq 3 \cdot 10^{-22}\right):\\ \;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \end{array} \]
Alternative 3
Error0.1
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{+18}:\\ \;\;\;\;\frac{z \cdot x}{\frac{1}{y + -1}}\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-23}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array} \]
Alternative 4
Error12.4
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{-14} \lor \neg \left(z \leq 22\right):\\ \;\;\;\;x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot x\\ \end{array} \]
Alternative 5
Error9.2
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{-17} \lor \neg \left(z \leq 14\right):\\ \;\;\;\;z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x - z \cdot x\\ \end{array} \]
Alternative 6
Error0.9
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z \cdot y\right)\\ \end{array} \]
Alternative 7
Error0.9
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7:\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x + x \cdot \left(z \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(x \cdot \left(y + -1\right)\right)\\ \end{array} \]
Alternative 8
Error19.4
Cost652
\[\begin{array}{l} t_0 := -z \cdot x\\ \mathbf{if}\;z \leq -9.5 \cdot 10^{+40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7.6 \cdot 10^{-14}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error19.4
Cost652
\[\begin{array}{l} t_0 := -z \cdot x\\ \mathbf{if}\;z \leq -7.2 \cdot 10^{+40}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-14}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error12.2
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+129}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{+31}:\\ \;\;\;\;x \cdot \left(1 - z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y\\ \end{array} \]
Alternative 11
Error12.2
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{+129}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 4.9 \cdot 10^{+30}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y\\ \end{array} \]
Alternative 12
Error19.7
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -3500000000 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;-z \cdot x\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error33.3
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023059 
(FPCore (x y z)
  :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
  :precision binary64

  :herbie-target
  (if (< (* x (- 1.0 (* (- 1.0 y) z))) -1.618195973607049e+50) (+ x (* (- 1.0 y) (* (- z) x))) (if (< (* x (- 1.0 (* (- 1.0 y) z))) 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1.0 y) (* (- z) x)))))

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