?

Average Error: 10.4 → 0.1
Time: 11.8s
Precision: binary64
Cost: 904

?

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

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.4
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 < -1.5999999999999999e61

    1. Initial program 28.8

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

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

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

      [Start]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-7 [<=]9.2

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

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]9.2

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

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

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

      [Start]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]0.1

      \[ y + y \cdot \color{blue}{\left(-\frac{x}{z}\right)} \]
    6. Applied egg-rr0.1

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

    if -1.5999999999999999e61 < y < 1.6e16

    1. Initial program 0.5

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

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

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

      [Start]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-7 [<=]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]0.1

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

    if 1.6e16 < y

    1. Initial program 24.5

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

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

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

      [Start]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-7 [<=]8.0

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

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]8.0

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

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

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

      [Start]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [<=]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]0.1

      \[ y + y \cdot \color{blue}{\left(-\frac{x}{z}\right)} \]
    6. Applied egg-rr0.1

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

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

Alternatives

Alternative 1
Error0.1
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -4.15 \cdot 10^{+14}:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{elif}\;y \leq 1.36 \cdot 10^{+14}:\\ \;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 2
Error1.4
Cost712
\[\begin{array}{l} t_0 := \left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{+37}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.4
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{+37}:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;y - y \cdot \frac{x}{z}\\ \end{array} \]
Alternative 4
Error0.0
Cost704
\[\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right) \]
Alternative 5
Error20.3
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -7.6 \cdot 10^{-94}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 1.36 \cdot 10^{-21}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 6
Error9.0
Cost320
\[\frac{x}{z} + y \]
Alternative 7
Error31.5
Cost64
\[y \]

Error

Reproduce?

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