?

Average Error: 15.49% → 0.33%
Time: 6.1s
Precision: binary64
Cost: 841

?

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

\mathbf{else}:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.49%
Target0.07%
Herbie0.33%
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation?

  1. Split input into 2 regimes
  2. if z < -6e16 or 1.5000000000000001e-90 < z

    1. Initial program 23.26

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
    2. Taylor expanded in x around inf 8.04

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

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

      [Start]8.04

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

      *-commutative [=>]8.04

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

      associate-/l* [=>]0.4

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

      mul-1-neg [=>]0.4

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

      unsub-neg [=>]0.4

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

    if -6e16 < z < 1.5000000000000001e-90

    1. Initial program 0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{+16} \lor \neg \left(z \leq 1.5 \cdot 10^{-90}\right):\\ \;\;\;\;y + \frac{x}{\frac{z}{1 - y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error0.29%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -6 \cdot 10^{+68} \lor \neg \left(y \leq 9800000\right):\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{\frac{z}{1 - y}}\\ \end{array} \]
Alternative 2
Error33.23%
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.5 \cdot 10^{-51}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{-138}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-67}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 3
Error12.65%
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -5.2 \cdot 10^{-151} \lor \neg \left(z \leq 2.15 \cdot 10^{-169}\right):\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - y\right) \cdot \frac{x}{z}\\ \end{array} \]
Alternative 4
Error1.08%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.24\right):\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 5
Error14.55%
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -7.8 \cdot 10^{+115}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{+97}:\\ \;\;\;\;y \cdot \frac{x}{-z}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 6
Error14.57%
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{+116}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -1.12 \cdot 10^{+97}:\\ \;\;\;\;\frac{y}{\frac{-z}{x}}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 7
Error14.09%
Cost320
\[y + \frac{x}{z} \]
Alternative 8
Error50.24%
Cost64
\[y \]

Error

Reproduce?

herbie shell --seed 2023088 
(FPCore (x y z)
  :name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
  :precision binary64

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

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