Numeric.SpecFunctions:choose from math-functions-0.1.5.2

Percentage Accurate: 85.0% → 96.4%
Time: 5.1s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{x \cdot \left(y + z\right)}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
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
public static double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
def code(x, y, z):
	return (x * (y + z)) / z
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) / z)
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) / z;
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 85.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x \cdot \left(y + z\right)}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
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
public static double code(double x, double y, double z) {
	return (x * (y + z)) / z;
}
def code(x, y, z):
	return (x * (y + z)) / z
function code(x, y, z)
	return Float64(Float64(x * Float64(y + z)) / z)
end
function tmp = code(x, y, z)
	tmp = (x * (y + z)) / z;
end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}

Alternative 1: 96.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + \frac{x}{\frac{z}{y}} \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (/ x (/ z y))))
double code(double x, double y, double z) {
	return x + (x / (z / y));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + (x / (z / y))
end function
public static double code(double x, double y, double z) {
	return x + (x / (z / y));
}
def code(x, y, z):
	return x + (x / (z / y))
function code(x, y, z)
	return Float64(x + Float64(x / Float64(z / y)))
end
function tmp = code(x, y, z)
	tmp = x + (x / (z / y));
end
code[x_, y_, z_] := N[(x + N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + \frac{x}{\frac{z}{y}}
\end{array}
Derivation
  1. Initial program 87.5%

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Step-by-step derivation
    1. associate-*l/85.0%

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    2. distribute-rgt-in79.4%

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + z \cdot \frac{x}{z}} \]
    3. *-commutative79.4%

      \[\leadsto y \cdot \frac{x}{z} + \color{blue}{\frac{x}{z} \cdot z} \]
    4. associate-/r/94.3%

      \[\leadsto y \cdot \frac{x}{z} + \color{blue}{\frac{x}{\frac{z}{z}}} \]
    5. *-inverses94.3%

      \[\leadsto y \cdot \frac{x}{z} + \frac{x}{\color{blue}{1}} \]
    6. /-rgt-identity94.3%

      \[\leadsto y \cdot \frac{x}{z} + \color{blue}{x} \]
    7. associate-*r/94.4%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} + x \]
    8. *-commutative94.4%

      \[\leadsto \frac{\color{blue}{x \cdot y}}{z} + x \]
    9. associate-*r/95.5%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} + x \]
    10. fma-def95.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
  3. Simplified95.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
  4. Step-by-step derivation
    1. fma-udef95.5%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  5. Applied egg-rr95.5%

    \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  6. Step-by-step derivation
    1. clear-num95.5%

      \[\leadsto x \cdot \color{blue}{\frac{1}{\frac{z}{y}}} + x \]
    2. un-div-inv95.6%

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} + x \]
  7. Applied egg-rr95.6%

    \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} + x \]
  8. Final simplification95.6%

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

Alternative 2: 90.2% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+174}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 1.22 \cdot 10^{+159}:\\
\;\;\;\;\frac{x}{z} \cdot \left(z + y\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -6e174 or 1.22000000000000004e159 < z

    1. Initial program 68.9%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/60.8%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around inf 90.1%

      \[\leadsto \color{blue}{x} \]

    if -6e174 < z < 1.22000000000000004e159

    1. Initial program 93.3%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/92.6%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{+174}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{+159}:\\ \;\;\;\;\frac{x}{z} \cdot \left(z + y\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 3: 70.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+59} \lor \neg \left(y \leq 1.65 \cdot 10^{+63}\right):\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.45e+59) (not (<= y 1.65e+63))) (* x (/ y z)) x))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.45e+59) || !(y <= 1.65e+63)) {
		tmp = x * (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
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 ((y <= (-1.45d+59)) .or. (.not. (y <= 1.65d+63))) then
        tmp = x * (y / z)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.45e+59) || !(y <= 1.65e+63)) {
		tmp = x * (y / z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -1.45e+59) or not (y <= 1.65e+63):
		tmp = x * (y / z)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.45e+59) || !(y <= 1.65e+63))
		tmp = Float64(x * Float64(y / z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.45e+59) || ~((y <= 1.65e+63)))
		tmp = x * (y / z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e+59], N[Not[LessEqual[y, 1.65e+63]], $MachinePrecision]], N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+59} \lor \neg \left(y \leq 1.65 \cdot 10^{+63}\right):\\
\;\;\;\;x \cdot \frac{y}{z}\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.44999999999999995e59 or 1.6500000000000001e63 < y

    1. Initial program 87.3%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/92.6%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around 0 76.2%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    5. Step-by-step derivation
      1. *-commutative76.2%

        \[\leadsto \frac{\color{blue}{x \cdot y}}{z} \]
      2. associate-*r/70.7%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    6. Simplified70.7%

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

    if -1.44999999999999995e59 < y < 1.6500000000000001e63

    1. Initial program 87.6%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/80.3%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around inf 79.0%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{+59} \lor \neg \left(y \leq 1.65 \cdot 10^{+63}\right):\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 4: 72.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+57} \lor \neg \left(y \leq 2.7 \cdot 10^{+14}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -4.9e+57) (not (<= y 2.7e+14))) (* y (/ x z)) x))
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -4.9e+57) || !(y <= 2.7e+14)) {
		tmp = y * (x / z);
	} else {
		tmp = x;
	}
	return tmp;
}
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 ((y <= (-4.9d+57)) .or. (.not. (y <= 2.7d+14))) then
        tmp = y * (x / z)
    else
        tmp = x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -4.9e+57) || !(y <= 2.7e+14)) {
		tmp = y * (x / z);
	} else {
		tmp = x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (y <= -4.9e+57) or not (y <= 2.7e+14):
		tmp = y * (x / z)
	else:
		tmp = x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((y <= -4.9e+57) || !(y <= 2.7e+14))
		tmp = Float64(y * Float64(x / z));
	else
		tmp = x;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -4.9e+57) || ~((y <= 2.7e+14)))
		tmp = y * (x / z);
	else
		tmp = x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.9e+57], N[Not[LessEqual[y, 2.7e+14]], $MachinePrecision]], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{+57} \lor \neg \left(y \leq 2.7 \cdot 10^{+14}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -4.8999999999999999e57 or 2.7e14 < y

    1. Initial program 88.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/92.8%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around 0 72.9%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    5. Step-by-step derivation
      1. associate-*r/72.4%

        \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
    6. Simplified72.4%

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

    if -4.8999999999999999e57 < y < 2.7e14

    1. Initial program 86.9%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/78.7%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around inf 82.1%

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.9 \cdot 10^{+57} \lor \neg \left(y \leq 2.7 \cdot 10^{+14}\right):\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternative 5: 72.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{+56}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\

\mathbf{elif}\;y \leq 2.45 \cdot 10^{+14}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.94999999999999997e56

    1. Initial program 84.1%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/93.7%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around 0 70.1%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    5. Step-by-step derivation
      1. *-commutative70.1%

        \[\leadsto \frac{\color{blue}{x \cdot y}}{z} \]
      2. associate-*r/65.1%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    6. Simplified65.1%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    7. Step-by-step derivation
      1. *-commutative65.1%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      2. associate-/r/74.2%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
    8. Applied egg-rr74.2%

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

    if -1.94999999999999997e56 < y < 2.45e14

    1. Initial program 86.9%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/78.7%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around inf 82.1%

      \[\leadsto \color{blue}{x} \]

    if 2.45e14 < y

    1. Initial program 91.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/92.2%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around 0 74.9%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    5. Step-by-step derivation
      1. associate-*r/71.2%

        \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
    6. Simplified71.2%

      \[\leadsto \color{blue}{y \cdot \frac{x}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification77.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{+56}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+14}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternative 6: 72.9% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+57}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\

\mathbf{elif}\;y \leq 6.5 \cdot 10^{+15}:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.8999999999999999e57

    1. Initial program 84.1%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/93.7%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around 0 70.1%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
    5. Step-by-step derivation
      1. *-commutative70.1%

        \[\leadsto \frac{\color{blue}{x \cdot y}}{z} \]
      2. associate-*r/65.1%

        \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    6. Simplified65.1%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} \]
    7. Step-by-step derivation
      1. *-commutative65.1%

        \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]
      2. associate-/r/74.2%

        \[\leadsto \color{blue}{\frac{y}{\frac{z}{x}}} \]
    8. Applied egg-rr74.2%

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

    if -1.8999999999999999e57 < y < 6.5e15

    1. Initial program 86.9%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/78.7%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around inf 82.1%

      \[\leadsto \color{blue}{x} \]

    if 6.5e15 < y

    1. Initial program 91.2%

      \[\frac{x \cdot \left(y + z\right)}{z} \]
    2. Step-by-step derivation
      1. associate-*l/92.2%

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

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    4. Taylor expanded in z around 0 74.9%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{+57}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{+15}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{z}\\ \end{array} \]

Alternative 7: 96.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x + x \cdot \frac{y}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (* x (/ y z))))
double code(double x, double y, double z) {
	return x + (x * (y / z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + (x * (y / z))
end function
public static double code(double x, double y, double z) {
	return x + (x * (y / z));
}
def code(x, y, z):
	return x + (x * (y / z))
function code(x, y, z)
	return Float64(x + Float64(x * Float64(y / z)))
end
function tmp = code(x, y, z)
	tmp = x + (x * (y / z));
end
code[x_, y_, z_] := N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + x \cdot \frac{y}{z}
\end{array}
Derivation
  1. Initial program 87.5%

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Step-by-step derivation
    1. associate-*l/85.0%

      \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
    2. distribute-rgt-in79.4%

      \[\leadsto \color{blue}{y \cdot \frac{x}{z} + z \cdot \frac{x}{z}} \]
    3. *-commutative79.4%

      \[\leadsto y \cdot \frac{x}{z} + \color{blue}{\frac{x}{z} \cdot z} \]
    4. associate-/r/94.3%

      \[\leadsto y \cdot \frac{x}{z} + \color{blue}{\frac{x}{\frac{z}{z}}} \]
    5. *-inverses94.3%

      \[\leadsto y \cdot \frac{x}{z} + \frac{x}{\color{blue}{1}} \]
    6. /-rgt-identity94.3%

      \[\leadsto y \cdot \frac{x}{z} + \color{blue}{x} \]
    7. associate-*r/94.4%

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} + x \]
    8. *-commutative94.4%

      \[\leadsto \frac{\color{blue}{x \cdot y}}{z} + x \]
    9. associate-*r/95.5%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z}} + x \]
    10. fma-def95.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
  3. Simplified95.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{z}, x\right)} \]
  4. Step-by-step derivation
    1. fma-udef95.5%

      \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  5. Applied egg-rr95.5%

    \[\leadsto \color{blue}{x \cdot \frac{y}{z} + x} \]
  6. Final simplification95.5%

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

Alternative 8: 51.4% accurate, 7.0× speedup?

\[\begin{array}{l} \\ x \end{array} \]
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
	return x;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x
end function
public static double code(double x, double y, double z) {
	return x;
}
def code(x, y, z):
	return x
function code(x, y, z)
	return x
end
function tmp = code(x, y, z)
	tmp = x;
end
code[x_, y_, z_] := x
\begin{array}{l}

\\
x
\end{array}
Derivation
  1. Initial program 87.5%

    \[\frac{x \cdot \left(y + z\right)}{z} \]
  2. Step-by-step derivation
    1. associate-*l/85.0%

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

    \[\leadsto \color{blue}{\frac{x}{z} \cdot \left(y + z\right)} \]
  4. Taylor expanded in z around inf 56.1%

    \[\leadsto \color{blue}{x} \]
  5. Final simplification56.1%

    \[\leadsto x \]

Developer target: 96.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x}{\frac{z}{y + z}} \end{array} \]
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
	return x / (z / (y + z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x / (z / (y + z))
end function
public static double code(double x, double y, double z) {
	return x / (z / (y + z));
}
def code(x, y, z):
	return x / (z / (y + z))
function code(x, y, z)
	return Float64(x / Float64(z / Float64(y + z)))
end
function tmp = code(x, y, z)
	tmp = x / (z / (y + z));
end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{\frac{z}{y + z}}
\end{array}

Reproduce

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