Average Error: 12.6 → 0.8
Time: 6.2s
Precision: binary64
Cost: 2512
\[\frac{x \cdot \left(y + z\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(y + z\right)}{z}\\ t_1 := x + x \cdot \frac{y}{z}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+300}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -1000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+33}:\\ \;\;\;\;x \cdot \left(\frac{y}{z} + 1\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+230}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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)) (t_1 (+ x (* x (/ y z)))))
   (if (<= t_0 -5e+300)
     t_1
     (if (<= t_0 -1000000.0)
       t_0
       (if (<= t_0 2e+33)
         (* x (+ (/ y z) 1.0))
         (if (<= t_0 5e+230) t_0 t_1))))))
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 t_1 = x + (x * (y / z));
	double tmp;
	if (t_0 <= -5e+300) {
		tmp = t_1;
	} else if (t_0 <= -1000000.0) {
		tmp = t_0;
	} else if (t_0 <= 2e+33) {
		tmp = x * ((y / z) + 1.0);
	} else if (t_0 <= 5e+230) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_0 = (x * (y + z)) / z
    t_1 = x + (x * (y / z))
    if (t_0 <= (-5d+300)) then
        tmp = t_1
    else if (t_0 <= (-1000000.0d0)) then
        tmp = t_0
    else if (t_0 <= 2d+33) then
        tmp = x * ((y / z) + 1.0d0)
    else if (t_0 <= 5d+230) then
        tmp = t_0
    else
        tmp = t_1
    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 t_1 = x + (x * (y / z));
	double tmp;
	if (t_0 <= -5e+300) {
		tmp = t_1;
	} else if (t_0 <= -1000000.0) {
		tmp = t_0;
	} else if (t_0 <= 2e+33) {
		tmp = x * ((y / z) + 1.0);
	} else if (t_0 <= 5e+230) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z):
	return (x * (y + z)) / z
def code(x, y, z):
	t_0 = (x * (y + z)) / z
	t_1 = x + (x * (y / z))
	tmp = 0
	if t_0 <= -5e+300:
		tmp = t_1
	elif t_0 <= -1000000.0:
		tmp = t_0
	elif t_0 <= 2e+33:
		tmp = x * ((y / z) + 1.0)
	elif t_0 <= 5e+230:
		tmp = t_0
	else:
		tmp = t_1
	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)
	t_1 = Float64(x + Float64(x * Float64(y / z)))
	tmp = 0.0
	if (t_0 <= -5e+300)
		tmp = t_1;
	elseif (t_0 <= -1000000.0)
		tmp = t_0;
	elseif (t_0 <= 2e+33)
		tmp = Float64(x * Float64(Float64(y / z) + 1.0));
	elseif (t_0 <= 5e+230)
		tmp = t_0;
	else
		tmp = t_1;
	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;
	t_1 = x + (x * (y / z));
	tmp = 0.0;
	if (t_0 <= -5e+300)
		tmp = t_1;
	elseif (t_0 <= -1000000.0)
		tmp = t_0;
	elseif (t_0 <= 2e+33)
		tmp = x * ((y / z) + 1.0);
	elseif (t_0 <= 5e+230)
		tmp = t_0;
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+300], t$95$1, If[LessEqual[t$95$0, -1000000.0], t$95$0, If[LessEqual[t$95$0, 2e+33], N[(x * N[(N[(y / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+230], t$95$0, t$95$1]]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
t_1 := x + x \cdot \frac{y}{z}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+300}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -1000000:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+230}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original12.6
Target3.0
Herbie0.8
\[\frac{x}{\frac{z}{y + z}} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -5.00000000000000026e300 or 5.0000000000000003e230 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 49.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
      Proof
      (fma.f64 x (/.f64 y z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 y z)) x)): 0 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 32 points increase in error, 28 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 40 points increase in error, 29 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (/.f64 x (Rewrite<= *-inverses_binary64 (/.f64 z z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 x z) z))): 53 points increase in error, 5 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 66 points increase in error, 76 points decrease in error
    3. Taylor expanded in x around 0 3.3

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

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

    if -5.00000000000000026e300 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1e6 or 1.9999999999999999e33 < (/.f64 (*.f64 x (+.f64 y z)) z) < 5.0000000000000003e230

    1. Initial program 0.2

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

    if -1e6 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.9999999999999999e33

    1. Initial program 6.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
      Proof
      (fma.f64 x (/.f64 y z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 y z)) x)): 0 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 x y) z)) x): 32 points increase in error, 28 points decrease in error
      (+.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 x z) y)) x): 40 points increase in error, 29 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite<= /-rgt-identity_binary64 (/.f64 x 1))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (/.f64 x (Rewrite<= *-inverses_binary64 (/.f64 z z)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (/.f64 x z) y) (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 x z) z))): 53 points increase in error, 5 points decrease in error
      (Rewrite<= distribute-lft-in_binary64 (*.f64 (/.f64 x z) (+.f64 y z))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x (+.f64 y z)) z)): 66 points increase in error, 76 points decrease in error
    3. Taylor expanded in x around 0 0.1

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

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

Alternatives

Alternative 1
Error19.7
Cost848
\[\begin{array}{l} t_0 := \frac{y}{\frac{z}{x}}\\ \mathbf{if}\;z \leq -3.8 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-196}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -4 \cdot 10^{-258}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-60}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error19.7
Cost848
\[\begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq -5.2 \cdot 10^{-196}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq -4 \cdot 10^{-258}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-60}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error3.6
Cost712
\[\begin{array}{l} t_0 := x + x \cdot \frac{y}{z}\\ \mathbf{if}\;y \leq 10^{+200}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+261}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error19.5
Cost584
\[\begin{array}{l} t_0 := \frac{x \cdot y}{z}\\ \mathbf{if}\;y \leq -2.5 \cdot 10^{+69}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{+144}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error25.2
Cost64
\[x \]

Error

Reproduce

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