?

Average Error: 3.5 → 0.5
Time: 9.4s
Precision: binary64
Cost: 841

?

\[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -8 \cdot 10^{+58} \lor \neg \left(z \leq 0.0042\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z \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 (or (<= z -8e+58) (not (<= z 0.0042)))
   (* (* z x) (+ y -1.0))
   (+ x (* x (* z (+ 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 <= -8e+58) || !(z <= 0.0042)) {
		tmp = (z * x) * (y + -1.0);
	} else {
		tmp = x + (x * (z * (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 <= (-8d+58)) .or. (.not. (z <= 0.0042d0))) then
        tmp = (z * x) * (y + (-1.0d0))
    else
        tmp = x + (x * (z * (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 <= -8e+58) || !(z <= 0.0042)) {
		tmp = (z * x) * (y + -1.0);
	} else {
		tmp = x + (x * (z * (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 <= -8e+58) or not (z <= 0.0042):
		tmp = (z * x) * (y + -1.0)
	else:
		tmp = x + (x * (z * (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 <= -8e+58) || !(z <= 0.0042))
		tmp = Float64(Float64(z * x) * Float64(y + -1.0));
	else
		tmp = Float64(x + Float64(x * Float64(z * 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 <= -8e+58) || ~((z <= 0.0042)))
		tmp = (z * x) * (y + -1.0);
	else
		tmp = x + (x * (z * (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[Or[LessEqual[z, -8e+58], N[Not[LessEqual[z, 0.0042]], $MachinePrecision]], N[(N[(z * x), $MachinePrecision] * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(z * 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 -8 \cdot 10^{+58} \lor \neg \left(z \leq 0.0042\right):\\
\;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\

\mathbf{else}:\\
\;\;\;\;x + x \cdot \left(z \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.5
Target0.2
Herbie0.5
\[\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 2 regimes
  2. if z < -7.99999999999999955e58 or 0.00419999999999999974 < z

    1. Initial program 9.4

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Taylor expanded in z around inf 0.9

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

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

      [Start]0.9

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

      *-commutative [=>]0.9

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

      associate-*r* [=>]0.9

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

      sub-neg [=>]0.9

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

      metadata-eval [=>]0.9

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

    if -7.99999999999999955e58 < z < 0.00419999999999999974

    1. Initial program 0.3

      \[x \cdot \left(1 - \left(1 - y\right) \cdot z\right) \]
    2. Taylor expanded in x around 0 0.3

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

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

      [Start]0.3

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

      *-commutative [=>]0.3

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

      *-commutative [<=]0.3

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

      distribute-rgt-out-- [<=]0.3

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

      *-lft-identity [=>]0.3

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

      *-commutative [=>]0.3

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

      *-commutative [=>]0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -8 \cdot 10^{+58} \lor \neg \left(z \leq 0.0042\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z \cdot \left(y + -1\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error20.8
Cost1112
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := \left(z \cdot x\right) \cdot y\\ \mathbf{if}\;z \leq -4.9 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-116}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-107}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;z \leq 2.36 \cdot 10^{-26}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+55}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error9.5
Cost976
\[\begin{array}{l} t_0 := x - z \cdot x\\ t_1 := \left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{if}\;z \leq -5.4 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-116}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-107}:\\ \;\;\;\;x \cdot \left(z \cdot y\right)\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error20.6
Cost848
\[\begin{array}{l} t_0 := z \cdot \left(-x\right)\\ t_1 := \left(z \cdot x\right) \cdot y\\ \mathbf{if}\;z \leq -4.8 \cdot 10^{+36}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -1.26 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{-26}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.5
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+60} \lor \neg \left(z \leq 0.0042\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + z \cdot \left(y + -1\right)\right)\\ \end{array} \]
Alternative 5
Error1.0
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \lor \neg \left(z \leq 0.0042\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 + z \cdot y\right)\\ \end{array} \]
Alternative 6
Error1.0
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.05 \lor \neg \left(z \leq 0.0042\right):\\ \;\;\;\;\left(z \cdot x\right) \cdot \left(y + -1\right)\\ \mathbf{else}:\\ \;\;\;\;x + x \cdot \left(z \cdot y\right)\\ \end{array} \]
Alternative 7
Error11.9
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{+163}:\\ \;\;\;\;z \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 1.2 \cdot 10^{+39}:\\ \;\;\;\;x - z \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot x\right) \cdot y\\ \end{array} \]
Alternative 8
Error19.9
Cost521
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\ \;\;\;\;z \cdot \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error33.8
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023060 
(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))))