Average Error: 10.6 → 0.1
Time: 6.2s
Precision: binary64
Cost: 841
\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{+28} \lor \neg \left(y \leq 6.5 \cdot 10^{+54}\right):\\ \;\;\;\;y \cdot \frac{z - x}{z}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{\frac{z}{1 - y}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.5e+28) (not (<= y 6.5e+54)))
   (* y (/ (- z x) z))
   (+ y (/ x (/ z (- 1.0 y))))))
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 ((y <= -1.5e+28) || !(y <= 6.5e+54)) {
		tmp = y * ((z - x) / z);
	} else {
		tmp = y + (x / (z / (1.0 - y)));
	}
	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 ((y <= (-1.5d+28)) .or. (.not. (y <= 6.5d+54))) then
        tmp = y * ((z - x) / z)
    else
        tmp = y + (x / (z / (1.0d0 - y)))
    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 ((y <= -1.5e+28) || !(y <= 6.5e+54)) {
		tmp = y * ((z - x) / z);
	} else {
		tmp = y + (x / (z / (1.0 - y)));
	}
	return tmp;
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
def code(x, y, z):
	tmp = 0
	if (y <= -1.5e+28) or not (y <= 6.5e+54):
		tmp = y * ((z - x) / z)
	else:
		tmp = y + (x / (z / (1.0 - y)))
	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 ((y <= -1.5e+28) || !(y <= 6.5e+54))
		tmp = Float64(y * Float64(Float64(z - x) / z));
	else
		tmp = Float64(y + Float64(x / Float64(z / Float64(1.0 - y))));
	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 ((y <= -1.5e+28) || ~((y <= 6.5e+54)))
		tmp = y * ((z - x) / z);
	else
		tmp = y + (x / (z / (1.0 - y)));
	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[y, -1.5e+28], N[Not[LessEqual[y, 6.5e+54]], $MachinePrecision]], N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y + N[(x / N[(z / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+28} \lor \neg \left(y \leq 6.5 \cdot 10^{+54}\right):\\
\;\;\;\;y \cdot \frac{z - x}{z}\\

\mathbf{else}:\\
\;\;\;\;y + \frac{x}{\frac{z}{1 - y}}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.6
Target0.0
Herbie0.1
\[\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}} \]

Derivation

  1. Split input into 2 regimes
  2. if y < -1.5e28 or 6.5e54 < y

    1. Initial program 26.8

      \[\frac{x + y \cdot \left(z - x\right)}{z} \]
    2. Simplified26.8

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
      Proof

      [Start]26.8

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

      +-commutative [=>]26.8

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

      fma-def [=>]26.8

      \[ \frac{\color{blue}{\mathsf{fma}\left(y, z - x, x\right)}}{z} \]
    3. Taylor expanded in y around inf 26.8

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

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

      [Start]26.8

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

      *-commutative [=>]26.8

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

      associate-/l* [=>]8.1

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

      associate-/r/ [=>]0.1

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

      remove-double-neg [<=]0.1

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

      neg-mul-1 [=>]0.1

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

      *-commutative [=>]0.1

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

      distribute-rgt-neg-in [=>]0.1

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

      metadata-eval [=>]0.1

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

      associate-*r/ [<=]0.2

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

      unpow-1 [<=]0.2

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

      *-commutative [<=]0.2

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

      unpow-1 [=>]0.2

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

      associate-*r/ [=>]0.1

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

      metadata-eval [<=]0.1

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

      distribute-rgt-neg-in [<=]0.1

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

      *-commutative [<=]0.1

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

      neg-mul-1 [<=]0.1

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

      remove-double-neg [=>]0.1

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

    if -1.5e28 < y < 6.5e54

    1. Initial program 0.6

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

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

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

      [Start]0.2

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

      *-commutative [=>]0.2

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

      associate-/l* [=>]0.1

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

      mul-1-neg [=>]0.1

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

      unsub-neg [=>]0.1

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

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

Alternatives

Alternative 1
Error0.7
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.8 \cdot 10^{-5}\right):\\ \;\;\;\;y \cdot \frac{z - x}{z}\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 2
Error19.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-49}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-43}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 3
Error8.6
Cost320
\[y + \frac{x}{z} \]
Alternative 4
Error31.3
Cost64
\[y \]

Error

Reproduce

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