?

Average Error: 10.2 → 0.1
Time: 11.0s
Precision: binary64
Cost: 1864

?

\[\frac{x + y \cdot \left(z - x\right)}{z} \]
\[\begin{array}{l} t_0 := \frac{x + y \cdot \left(z - x\right)}{z}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;y + \frac{x \cdot \left(1 - y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;y + \left(-\frac{y}{z}\right) \cdot x\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (+ x (* y (- z x))) z)))
   (if (<= t_0 (- INFINITY))
     (* (- 1.0 (/ x z)) y)
     (if (<= t_0 2e+307)
       (+ y (/ (* x (- 1.0 y)) z))
       (+ y (* (- (/ y 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 t_0 = (x + (y * (z - x))) / z;
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = (1.0 - (x / z)) * y;
	} else if (t_0 <= 2e+307) {
		tmp = y + ((x * (1.0 - y)) / z);
	} else {
		tmp = y + (-(y / z) * x);
	}
	return tmp;
}
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 = (x + (y * (z - x))) / z;
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = (1.0 - (x / z)) * y;
	} else if (t_0 <= 2e+307) {
		tmp = y + ((x * (1.0 - y)) / z);
	} else {
		tmp = y + (-(y / z) * x);
	}
	return tmp;
}
def code(x, y, z):
	return (x + (y * (z - x))) / z
def code(x, y, z):
	t_0 = (x + (y * (z - x))) / z
	tmp = 0
	if t_0 <= -math.inf:
		tmp = (1.0 - (x / z)) * y
	elif t_0 <= 2e+307:
		tmp = y + ((x * (1.0 - y)) / z)
	else:
		tmp = y + (-(y / 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)
	t_0 = Float64(Float64(x + Float64(y * Float64(z - x))) / z)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(1.0 - Float64(x / z)) * y);
	elseif (t_0 <= 2e+307)
		tmp = Float64(y + Float64(Float64(x * Float64(1.0 - y)) / z));
	else
		tmp = Float64(y + Float64(Float64(-Float64(y / 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)
	t_0 = (x + (y * (z - x))) / z;
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = (1.0 - (x / z)) * y;
	elseif (t_0 <= 2e+307)
		tmp = y + ((x * (1.0 - y)) / z);
	else
		tmp = y + (-(y / 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_] := Block[{t$95$0 = N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 2e+307], N[(y + N[(N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y + N[((-N[(y / z), $MachinePrecision]) * x), $MachinePrecision]), $MachinePrecision]]]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
t_0 := \frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+307}:\\
\;\;\;\;y + \frac{x \cdot \left(1 - y\right)}{z}\\

\mathbf{else}:\\
\;\;\;\;y + \left(-\frac{y}{z}\right) \cdot 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 (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(z - x\right)}{z}} \]
    3. Taylor expanded in z around 0 21.2

      \[\leadsto \color{blue}{-1 \cdot \frac{y \cdot x}{z} + y} \]
    4. Simplified21.2

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

      [Start]21.2

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

      rational.json-simplify-1 [=>]21.2

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

      rational.json-simplify-2 [=>]21.2

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

      rational.json-simplify-9 [=>]21.2

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

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

    if -inf.0 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < 1.99999999999999997e307

    1. Initial program 0.1

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

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

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

      [Start]0.0

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

      rational.json-simplify-2 [=>]0.0

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

      rational.json-simplify-17 [=>]0.0

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

      rational.json-simplify-2 [=>]0.0

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

      rational.json-simplify-9 [=>]0.0

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

      rational.json-simplify-12 [=>]0.0

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

      rational.json-simplify-42 [=>]0.0

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

      metadata-eval [=>]0.0

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

    if 1.99999999999999997e307 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z)

    1. Initial program 63.7

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

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

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

      [Start]21.5

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

      rational.json-simplify-2 [=>]21.5

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

      rational.json-simplify-17 [=>]21.5

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

      rational.json-simplify-2 [=>]21.5

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

      rational.json-simplify-9 [=>]21.5

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

      rational.json-simplify-12 [=>]21.5

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

      rational.json-simplify-42 [=>]21.5

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

      metadata-eval [=>]21.5

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

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

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

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

      [Start]0.5

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

      rational.json-simplify-2 [=>]0.5

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

      rational.json-simplify-9 [=>]0.5

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

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

Alternatives

Alternative 1
Error20.9
Cost720
\[\begin{array}{l} \mathbf{if}\;y \leq -2.2 \cdot 10^{-39}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq -5.1 \cdot 10^{-117}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-148}:\\ \;\;\;\;y\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-39}:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 2
Error0.8
Cost712
\[\begin{array}{l} t_0 := \left(1 - \frac{x}{z}\right) \cdot y\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.0
Cost704
\[\frac{x}{z} + y \cdot \left(1 - \frac{x}{z}\right) \]
Alternative 4
Error9.6
Cost648
\[\begin{array}{l} \mathbf{if}\;y \leq 2.2 \cdot 10^{+18}:\\ \;\;\;\;\frac{x}{z} + y\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{+76}:\\ \;\;\;\;\left(-\frac{y}{z}\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]
Alternative 5
Error9.0
Cost320
\[\frac{x}{z} + y \]
Alternative 6
Error31.6
Cost64
\[y \]

Error

Reproduce?

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