?

Average Error: 10.2 → 0.1
Time: 8.5s
Precision: binary64
Cost: 840

?

\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -2.05 \cdot 10^{+16}:\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+14}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y -2.05e+16)
   (* y (- 1.0 (/ x z)))
   (if (<= y 9.5e+14) (/ (+ x (* y (- z x))) z) (/ y (/ z (- z x))))))
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 <= -2.05e+16) {
		tmp = y * (1.0 - (x / z));
	} else if (y <= 9.5e+14) {
		tmp = (x + (y * (z - x))) / z;
	} else {
		tmp = y / (z / (z - 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
    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 <= (-2.05d+16)) then
        tmp = y * (1.0d0 - (x / z))
    else if (y <= 9.5d+14) then
        tmp = (x + (y * (z - x))) / z
    else
        tmp = y / (z / (z - x))
    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 <= -2.05e+16) {
		tmp = y * (1.0 - (x / z));
	} else if (y <= 9.5e+14) {
		tmp = (x + (y * (z - x))) / z;
	} else {
		tmp = y / (z / (z - x));
	}
	return tmp;
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
def code(x, y, z):
	tmp = 0
	if y <= -2.05e+16:
		tmp = y * (1.0 - (x / z))
	elif y <= 9.5e+14:
		tmp = (x + (y * (z - x))) / z
	else:
		tmp = y / (z / (z - x))
	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 <= -2.05e+16)
		tmp = Float64(y * Float64(1.0 - Float64(x / z)));
	elseif (y <= 9.5e+14)
		tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z);
	else
		tmp = Float64(y / Float64(z / Float64(z - x)));
	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 <= -2.05e+16)
		tmp = y * (1.0 - (x / z));
	elseif (y <= 9.5e+14)
		tmp = (x + (y * (z - x))) / z;
	else
		tmp = y / (z / (z - x));
	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[LessEqual[y, -2.05e+16], N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.5e+14], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(y / N[(z / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
\mathbf{if}\;y \leq -2.05 \cdot 10^{+16}:\\
\;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 3 regimes
  2. if y < -2.05e16

    1. Initial program 24.6

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

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

      [Start]24.6

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

      +-commutative [=>]24.6

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

      fma-def [=>]24.6

      \[ \frac{\color{blue}{\mathsf{fma}\left(y, z - x, x\right)}}{z} \]
    3. Applied egg-rr50.1

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - x\right)}{z} + -1 \cdot \frac{\left(x - z\right) \cdot x}{\left(z - x\right) \cdot z}} \]
    5. Taylor expanded in y around inf 0.1

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

    if -2.05e16 < y < 9.5e14

    1. Initial program 0.1

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

    if 9.5e14 < y

    1. Initial program 24.3

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

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

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

      [Start]24.3

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

      associate-/l* [=>]0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.05 \cdot 10^{+16}:\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+14}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]

Alternatives

Alternative 1
Error1.3
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -3.8 \cdot 10^{+103}:\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{-37}:\\ \;\;\;\;y + \frac{x}{\frac{z}{1 - y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
Alternative 2
Error1.6
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -45000000 \lor \neg \left(y \leq 1.42 \cdot 10^{-37}\right):\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;y + \frac{x}{z}\\ \end{array} \]
Alternative 3
Error1.6
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -45000000:\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{elif}\;y \leq 1.42 \cdot 10^{-37}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{z}{z - x}}\\ \end{array} \]
Alternative 4
Error10.0
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq 7 \cdot 10^{+34}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 2.55 \cdot 10^{+122}:\\ \;\;\;\;\frac{-x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error9.9
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq 1.25 \cdot 10^{+34}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{elif}\;y \leq 9.4 \cdot 10^{+123}:\\ \;\;\;\;\frac{-y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 6
Error19.4
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{-44}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 3.7 \cdot 10^{-38}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 7
Error8.6
Cost320
\[y + \frac{x}{z} \]
Alternative 8
Error31.7
Cost64
\[y \]

Error

Reproduce?

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