?

Average Error: 19.24% → 3.53%
Time: 5.5s
Precision: binary64
Cost: 712

?

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

\mathbf{elif}\;x \leq 0.00016:\\
\;\;\;\;x + y \cdot \frac{x}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y + z}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.24%
Target4.85%
Herbie3.53%
\[\frac{x}{\frac{z}{y + z}} \]

Derivation?

  1. Split input into 3 regimes
  2. if x < -8.0000000000000004e-168

    1. Initial program 22.27

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Simplified3.05

      \[\leadsto \color{blue}{x \cdot \frac{y + z}{z}} \]
      Proof

      [Start]22.27

      \[ \frac{x \cdot \left(y + z\right)}{z} \]

      associate-*r/ [<=]3.05

      \[ \color{blue}{x \cdot \frac{y + z}{z}} \]
    3. Taylor expanded in x around 0 22.27

      \[\leadsto \color{blue}{\frac{\left(y + z\right) \cdot x}{z}} \]
    4. Simplified3.03

      \[\leadsto \color{blue}{x + \frac{y}{z} \cdot x} \]
      Proof

      [Start]22.27

      \[ \frac{\left(y + z\right) \cdot x}{z} \]

      associate-*l/ [<=]3.05

      \[ \color{blue}{\frac{y + z}{z} \cdot x} \]

      *-lft-identity [<=]3.05

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

      associate-*l/ [<=]3.24

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

      distribute-lft-in [=>]3.23

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

      lft-mult-inverse [=>]3.09

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

      distribute-rgt1-in [<=]3.08

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

      associate-*l/ [=>]3.03

      \[ x + \color{blue}{\frac{1 \cdot y}{z}} \cdot x \]

      *-lft-identity [=>]3.03

      \[ x + \frac{\color{blue}{y}}{z} \cdot x \]

    if -8.0000000000000004e-168 < x < 1.60000000000000013e-4

    1. Initial program 9.21

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Simplified9.13

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + z}}} \]
      Proof

      [Start]9.21

      \[ \frac{x \cdot \left(y + z\right)}{z} \]

      associate-/l* [=>]9.13

      \[ \color{blue}{\frac{x}{\frac{z}{y + z}}} \]
    3. Taylor expanded in z around 0 5.07

      \[\leadsto \color{blue}{\frac{y \cdot x}{z} + x} \]
    4. Simplified5.66

      \[\leadsto \color{blue}{x + y \cdot \frac{x}{z}} \]
      Proof

      [Start]5.07

      \[ \frac{y \cdot x}{z} + x \]

      +-commutative [=>]5.07

      \[ \color{blue}{x + \frac{y \cdot x}{z}} \]

      associate-*r/ [<=]5.66

      \[ x + \color{blue}{y \cdot \frac{x}{z}} \]

    if 1.60000000000000013e-4 < x

    1. Initial program 33.99

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Simplified0.15

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y + z}}} \]
      Proof

      [Start]33.99

      \[ \frac{x \cdot \left(y + z\right)}{z} \]

      associate-/l* [=>]0.15

      \[ \color{blue}{\frac{x}{\frac{z}{y + z}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification3.53

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8 \cdot 10^{-168}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;x \leq 0.00016:\\ \;\;\;\;x + y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y + z}}\\ \end{array} \]

Alternatives

Alternative 1
Error34.75%
Cost1114
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{-70}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-83} \lor \neg \left(z \leq -4.6 \cdot 10^{-201}\right) \land \left(z \leq 6 \cdot 10^{-122} \lor \neg \left(z \leq 2.4 \cdot 10^{-22}\right) \land z \leq 1.5 \cdot 10^{+33}\right):\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error34.41%
Cost1113
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{-40}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -3 \cdot 10^{-82}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{-202}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-119} \lor \neg \left(z \leq 5.3 \cdot 10^{-21}\right) \land z \leq 1.5 \cdot 10^{+33}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error32.66%
Cost1112
\[\begin{array}{l} t_0 := \frac{x \cdot y}{z}\\ \mathbf{if}\;z \leq -2.85 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-188}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{-116}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-23}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+33}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error3.54%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-167} \lor \neg \left(x \leq 2000000000\right):\\ \;\;\;\;x \cdot \frac{y + z}{z}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 5
Error3.53%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -7.4 \cdot 10^{-168} \lor \neg \left(x \leq 10000000\right):\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 6
Error5.3%
Cost448
\[x \cdot \frac{y + z}{z} \]
Alternative 7
Error40.77%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023088 
(FPCore (x y z)
  :name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (/ x (/ z (+ y z)))

  (/ (* x (+ y z)) z))