Average Error: 10.0 → 0.2
Time: 5.7s
Precision: binary64
Cost: 968
\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\begin{array}{l} t_0 := y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{if}\;y \leq -4.0069046279066546 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.430956139408038 \cdot 10^{+23}:\\ \;\;\;\;\frac{x}{z} + \frac{y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* y (- 1.0 (/ x z)))))
   (if (<= y -4.0069046279066546e+45)
     t_0
     (if (<= y 6.430956139408038e+23) (+ (/ x z) (/ (* y (- z x)) z)) t_0))))
double code(double x, double y, double z) {
	return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
	double t_0 = y * (1.0 - (x / z));
	double tmp;
	if (y <= -4.0069046279066546e+45) {
		tmp = t_0;
	} else if (y <= 6.430956139408038e+23) {
		tmp = (x / z) + ((y * (z - x)) / 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 - 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) :: t_0
    real(8) :: tmp
    t_0 = y * (1.0d0 - (x / z))
    if (y <= (-4.0069046279066546d+45)) then
        tmp = t_0
    else if (y <= 6.430956139408038d+23) then
        tmp = (x / z) + ((y * (z - x)) / 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 - x))) / z;
}
public static double code(double x, double y, double z) {
	double t_0 = y * (1.0 - (x / z));
	double tmp;
	if (y <= -4.0069046279066546e+45) {
		tmp = t_0;
	} else if (y <= 6.430956139408038e+23) {
		tmp = (x / z) + ((y * (z - x)) / z);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
def code(x, y, z):
	t_0 = y * (1.0 - (x / z))
	tmp = 0
	if y <= -4.0069046279066546e+45:
		tmp = t_0
	elif y <= 6.430956139408038e+23:
		tmp = (x / z) + ((y * (z - x)) / z)
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	return Float64(Float64(x + Float64(y * Float64(z - x))) / z)
end
function code(x, y, z)
	t_0 = Float64(y * Float64(1.0 - Float64(x / z)))
	tmp = 0.0
	if (y <= -4.0069046279066546e+45)
		tmp = t_0;
	elseif (y <= 6.430956139408038e+23)
		tmp = Float64(Float64(x / z) + Float64(Float64(y * Float64(z - x)) / z));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x + (y * (z - x))) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = y * (1.0 - (x / z));
	tmp = 0.0;
	if (y <= -4.0069046279066546e+45)
		tmp = t_0;
	elseif (y <= 6.430956139408038e+23)
		tmp = (x / z) + ((y * (z - x)) / z);
	else
		tmp = t_0;
	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_] := Block[{t$95$0 = N[(y * N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.0069046279066546e+45], t$95$0, If[LessEqual[y, 6.430956139408038e+23], N[(N[(x / z), $MachinePrecision] + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
t_0 := y \cdot \left(1 - \frac{x}{z}\right)\\
\mathbf{if}\;y \leq -4.0069046279066546 \cdot 10^{+45}:\\
\;\;\;\;t_0\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if y < -4.0069046279066546e45 or 6.4309561394080384e23 < y

    1. Initial program 25.4

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

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

      \[\leadsto \color{blue}{y \cdot \left(1 - \frac{x}{z}\right)} \]
      Proof
      (*.f64 y (-.f64 1 (/.f64 x z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 1 y) (*.f64 (/.f64 x z) y))): 1 points increase in error, 2 points decrease in error
      (-.f64 (*.f64 1 y) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 x y) z))): 37 points increase in error, 12 points decrease in error
      (-.f64 (*.f64 1 y) (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y x)) z)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> fma-neg_binary64 (fma.f64 1 y (neg.f64 (/.f64 (*.f64 y x) z)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= *-inverses_binary64 (/.f64 z z)) y (neg.f64 (/.f64 (*.f64 y x) z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 (/.f64 z z) y) (/.f64 (*.f64 y x) z))): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= associate-/r/_binary64 (/.f64 z (/.f64 z y))) (/.f64 (*.f64 y x) z)): 43 points increase in error, 17 points decrease in error
      (-.f64 (/.f64 z (/.f64 z y)) (/.f64 (Rewrite=> *-commutative_binary64 (*.f64 x y)) z)): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 z (/.f64 z y)) (Rewrite=> associate-/l*_binary64 (/.f64 x (/.f64 z y)))): 26 points increase in error, 48 points decrease in error
      (Rewrite<= div-sub_binary64 (/.f64 (-.f64 z x) (/.f64 z y))): 2 points increase in error, 3 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (-.f64 z x) y) z)): 92 points increase in error, 65 points decrease in error
      (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 y (-.f64 z x))) z): 0 points increase in error, 0 points decrease in error

    if -4.0069046279066546e45 < y < 6.4309561394080384e23

    1. Initial program 0.3

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(y, z - x, x\right)}{z}} \]
      Proof
      (/.f64 (fma.f64 y (-.f64 z x) x) z): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (-.f64 z x)) x)) z): 1 points increase in error, 1 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 x (*.f64 y (-.f64 z x)))) z): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in y around inf 0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.0069046279066546 \cdot 10^{+45}:\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{elif}\;y \leq 6.430956139408038 \cdot 10^{+23}:\\ \;\;\;\;\frac{x}{z} + \frac{y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(1 - \frac{x}{z}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error7.8
Cost976
\[\begin{array}{l} t_0 := y + \frac{x}{z}\\ \mathbf{if}\;z \leq -2.1 \cdot 10^{-42}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-56}:\\ \;\;\;\;\frac{x}{\frac{z}{1 - y}}\\ \mathbf{elif}\;z \leq -2.15 \cdot 10^{-206}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.06 \cdot 10^{-228}:\\ \;\;\;\;\frac{x - y \cdot x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.2
Cost840
\[\begin{array}{l} t_0 := y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{if}\;y \leq -4.0069046279066546 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.430956139408038 \cdot 10^{+23}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.4
Cost712
\[\begin{array}{l} t_0 := y \cdot \left(1 - \frac{x}{z}\right)\\ \mathbf{if}\;y \leq -4.0069046279066546 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.0028:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error8.0
Cost580
\[\begin{array}{l} \mathbf{if}\;x \leq 2.2 \cdot 10^{+144}:\\ \;\;\;\;y + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{1 - y}}\\ \end{array} \]
Alternative 5
Error19.4
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.2773767041079875 \cdot 10^{-46}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.2764160985278215 \cdot 10^{-15}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 6
Error8.6
Cost320
\[y + \frac{x}{z} \]
Alternative 7
Error31.7
Cost64
\[y \]

Error

Reproduce

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