Average Error: 12.8 → 2.2
Time: 5.7s
Precision: binary64
Cost: 1480
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{+88}:\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{elif}\;t_0 \leq 10^{+255}:\\ \;\;\;\;t_0\\ \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
 (let* ((t_0 (/ (* x (+ y z)) z)))
   (if (<= t_0 5e+88)
     (+ x (* x (/ y z)))
     (if (<= t_0 1e+255) t_0 (/ 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 t_0 = (x * (y + z)) / z;
	double tmp;
	if (t_0 <= 5e+88) {
		tmp = x + (x * (y / z));
	} else if (t_0 <= 1e+255) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = (x * (y + z)) / z
    if (t_0 <= 5d+88) then
        tmp = x + (x * (y / z))
    else if (t_0 <= 1d+255) then
        tmp = t_0
    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 t_0 = (x * (y + z)) / z;
	double tmp;
	if (t_0 <= 5e+88) {
		tmp = x + (x * (y / z));
	} else if (t_0 <= 1e+255) {
		tmp = t_0;
	} else {
		tmp = x / (z / (y + z));
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y + z)) / z
def code(x, y, z):
	t_0 = (x * (y + z)) / z
	tmp = 0
	if t_0 <= 5e+88:
		tmp = x + (x * (y / z))
	elif t_0 <= 1e+255:
		tmp = t_0
	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)
	t_0 = Float64(Float64(x * Float64(y + z)) / z)
	tmp = 0.0
	if (t_0 <= 5e+88)
		tmp = Float64(x + Float64(x * Float64(y / z)));
	elseif (t_0 <= 1e+255)
		tmp = t_0;
	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)
	t_0 = (x * (y + z)) / z;
	tmp = 0.0;
	if (t_0 <= 5e+88)
		tmp = x + (x * (y / z));
	elseif (t_0 <= 1e+255)
		tmp = t_0;
	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_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+88], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+255], t$95$0, N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t_0 \leq 5 \cdot 10^{+88}:\\
\;\;\;\;x + x \cdot \frac{y}{z}\\

\mathbf{elif}\;t_0 \leq 10^{+255}:\\
\;\;\;\;t_0\\

\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

Original12.8
Target3.0
Herbie2.2
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < 4.99999999999999997e88

    1. Initial program 10.1

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

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

      [Start]10.1

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

      associate-*r/ [<=]2.4

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

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

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

      [Start]10.1

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

      associate-*l/ [<=]2.4

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

      *-lft-identity [<=]2.4

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

      associate-*l/ [<=]2.5

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

      distribute-lft-in [=>]2.5

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

      lft-mult-inverse [=>]2.4

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

      distribute-rgt1-in [<=]2.4

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

      associate-*l/ [=>]2.3

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

      *-lft-identity [=>]2.3

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

    if 4.99999999999999997e88 < (/.f64 (*.f64 x (+.f64 y z)) z) < 9.99999999999999988e254

    1. Initial program 0.2

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

    if 9.99999999999999988e254 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 47.6

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

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

      [Start]47.6

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

      associate-/l* [=>]3.7

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

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

Alternatives

Alternative 1
Error21.2
Cost849
\[\begin{array}{l} \mathbf{if}\;z \leq -1.6 \cdot 10^{+31}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{-149} \lor \neg \left(z \leq 4.6 \cdot 10^{-50}\right) \land z \leq 1.8 \cdot 10^{+49}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error21.4
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+31}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.55 \cdot 10^{-154}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{-50}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{+59}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error18.8
Cost848
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -4.6 \cdot 10^{-5}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.1 \cdot 10^{-100}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 3.65 \cdot 10^{+40}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.1
Cost848
\[\begin{array}{l} \mathbf{if}\;y \leq -4.5 \cdot 10^{-5}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-84}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1.1 \cdot 10^{-100}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{+40}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 5
Error3.3
Cost448
\[x \cdot \frac{y + z}{z} \]
Alternative 6
Error3.2
Cost448
\[x + x \cdot \frac{y}{z} \]
Alternative 7
Error3.0
Cost448
\[\frac{x}{\frac{z}{y + z}} \]
Alternative 8
Error25.4
Cost64
\[x \]

Error

Reproduce

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