?

Average Error: 19.34% → 2.53%
Time: 7.5s
Precision: binary64
Cost: 2514

?

\[\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 -4 \cdot 10^{+306} \lor \neg \left(t_0 \leq -2 \cdot 10^{+183}\right) \land \left(t_0 \leq 10^{-125} \lor \neg \left(t_0 \leq 2 \cdot 10^{+221}\right)\right):\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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 (or (<= t_0 -4e+306)
           (and (not (<= t_0 -2e+183))
                (or (<= t_0 1e-125) (not (<= t_0 2e+221)))))
     (+ x (* x (/ y z)))
     t_0)))
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 <= -4e+306) || (!(t_0 <= -2e+183) && ((t_0 <= 1e-125) || !(t_0 <= 2e+221)))) {
		tmp = x + (x * (y / z));
	} else {
		tmp = t_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 * (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 <= (-4d+306)) .or. (.not. (t_0 <= (-2d+183))) .and. (t_0 <= 1d-125) .or. (.not. (t_0 <= 2d+221))) then
        tmp = x + (x * (y / z))
    else
        tmp = t_0
    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 <= -4e+306) || (!(t_0 <= -2e+183) && ((t_0 <= 1e-125) || !(t_0 <= 2e+221)))) {
		tmp = x + (x * (y / z));
	} else {
		tmp = t_0;
	}
	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 <= -4e+306) or (not (t_0 <= -2e+183) and ((t_0 <= 1e-125) or not (t_0 <= 2e+221))):
		tmp = x + (x * (y / z))
	else:
		tmp = t_0
	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 <= -4e+306) || (!(t_0 <= -2e+183) && ((t_0 <= 1e-125) || !(t_0 <= 2e+221))))
		tmp = Float64(x + Float64(x * Float64(y / z)));
	else
		tmp = t_0;
	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 <= -4e+306) || (~((t_0 <= -2e+183)) && ((t_0 <= 1e-125) || ~((t_0 <= 2e+221)))))
		tmp = x + (x * (y / z));
	else
		tmp = t_0;
	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[Or[LessEqual[t$95$0, -4e+306], And[N[Not[LessEqual[t$95$0, -2e+183]], $MachinePrecision], Or[LessEqual[t$95$0, 1e-125], N[Not[LessEqual[t$95$0, 2e+221]], $MachinePrecision]]]], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\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 -4 \cdot 10^{+306} \lor \neg \left(t_0 \leq -2 \cdot 10^{+183}\right) \land \left(t_0 \leq 10^{-125} \lor \neg \left(t_0 \leq 2 \cdot 10^{+221}\right)\right):\\
\;\;\;\;x + x \cdot \frac{y}{z}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.34%
Target5.17%
Herbie2.53%
\[\frac{x}{\frac{z}{y + z}} \]

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 x (+.f64 y z)) z) < -4.00000000000000007e306 or -1.99999999999999989e183 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.00000000000000001e-125 or 2.0000000000000001e221 < (/.f64 (*.f64 x (+.f64 y z)) z)

    1. Initial program 28.85

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

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

      [Start]28.85

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

      associate-*r/ [<=]3.64

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

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

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

      [Start]28.85

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

      associate-*l/ [<=]3.64

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

      *-lft-identity [<=]3.64

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

      associate-*l/ [<=]3.83

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

      distribute-lft-in [=>]3.83

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

      lft-mult-inverse [=>]3.67

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

      distribute-rgt1-in [<=]3.66

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

      associate-*l/ [=>]3.62

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

      *-lft-identity [=>]3.62

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

    if -4.00000000000000007e306 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1.99999999999999989e183 or 1.00000000000000001e-125 < (/.f64 (*.f64 x (+.f64 y z)) z) < 2.0000000000000001e221

    1. Initial program 0.37

      \[\frac{x \cdot \left(y + z\right)}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.53

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot \left(y + z\right)}{z} \leq -4 \cdot 10^{+306} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \leq -2 \cdot 10^{+183}\right) \land \left(\frac{x \cdot \left(y + z\right)}{z} \leq 10^{-125} \lor \neg \left(\frac{x \cdot \left(y + z\right)}{z} \leq 2 \cdot 10^{+221}\right)\right):\\ \;\;\;\;x + x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(y + z\right)}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error31.31%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.8 \cdot 10^{-44} \lor \neg \left(y \leq 1.1 \cdot 10^{-50}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error5.8%
Cost448
\[x \cdot \frac{y + z}{z} \]
Alternative 3
Error5.78%
Cost448
\[x + x \cdot \frac{y}{z} \]
Alternative 4
Error5.17%
Cost448
\[\frac{x}{\frac{z}{y + z}} \]
Alternative 5
Error40.66%
Cost64
\[x \]

Error

Reproduce?

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