?

Average Error: 10.2 → 0.1
Time: 17.1s
Precision: binary64
Cost: 1928

?

\[\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z} \]
\[\begin{array}{l} t_0 := \left(y - z\right) + 1\\ t_1 := \frac{x \cdot t_0}{z}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+146}:\\ \;\;\;\;\frac{x \cdot \left(y - -1\right)}{z} + \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \frac{x}{z}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (- y z) 1.0)) (t_1 (/ (* x t_0) z)))
   (if (<= t_1 (- INFINITY))
     (* (- (/ y z) 1.0) x)
     (if (<= t_1 5e+146) (+ (/ (* x (- y -1.0)) z) (- x)) (* t_0 (/ x z))))))
double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
	double t_0 = (y - z) + 1.0;
	double t_1 = (x * t_0) / z;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = ((y / z) - 1.0) * x;
	} else if (t_1 <= 5e+146) {
		tmp = ((x * (y - -1.0)) / z) + -x;
	} else {
		tmp = t_0 * (x / z);
	}
	return tmp;
}
public static double code(double x, double y, double z) {
	return (x * ((y - z) + 1.0)) / z;
}
public static double code(double x, double y, double z) {
	double t_0 = (y - z) + 1.0;
	double t_1 = (x * t_0) / z;
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = ((y / z) - 1.0) * x;
	} else if (t_1 <= 5e+146) {
		tmp = ((x * (y - -1.0)) / z) + -x;
	} else {
		tmp = t_0 * (x / z);
	}
	return tmp;
}
def code(x, y, z):
	return (x * ((y - z) + 1.0)) / z
def code(x, y, z):
	t_0 = (y - z) + 1.0
	t_1 = (x * t_0) / z
	tmp = 0
	if t_1 <= -math.inf:
		tmp = ((y / z) - 1.0) * x
	elif t_1 <= 5e+146:
		tmp = ((x * (y - -1.0)) / z) + -x
	else:
		tmp = t_0 * (x / z)
	return tmp
function code(x, y, z)
	return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z)
end
function code(x, y, z)
	t_0 = Float64(Float64(y - z) + 1.0)
	t_1 = Float64(Float64(x * t_0) / z)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(y / z) - 1.0) * x);
	elseif (t_1 <= 5e+146)
		tmp = Float64(Float64(Float64(x * Float64(y - -1.0)) / z) + Float64(-x));
	else
		tmp = Float64(t_0 * Float64(x / z));
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (x * ((y - z) + 1.0)) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = (y - z) + 1.0;
	t_1 = (x * t_0) / z;
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = ((y / z) - 1.0) * x;
	elseif (t_1 <= 5e+146)
		tmp = ((x * (y - -1.0)) / z) + -x;
	else
		tmp = t_0 * (x / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(y / z), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$1, 5e+146], N[(N[(N[(x * N[(y - -1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + (-x)), $MachinePrecision], N[(t$95$0 * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \left(y - z\right) + 1\\
t_1 := \frac{x \cdot t_0}{z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+146}:\\
\;\;\;\;\frac{x \cdot \left(y - -1\right)}{z} + \left(-x\right)\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{x}{z}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.2
Target0.5
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x < -2.71483106713436 \cdot 10^{-162}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \mathbf{elif}\;x < 3.874108816439546 \cdot 10^{-197}:\\ \;\;\;\;\left(x \cdot \left(\left(y - z\right) + 1\right)\right) \cdot \frac{1}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z} - x\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < -inf.0

    1. Initial program 64.0

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

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

      [Start]64.0

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

      rational.json-simplify-49 [=>]0.2

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

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

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

      [Start]22.4

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

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

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

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

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

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

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

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

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

      rational.json-simplify-8 [<=]22.4

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

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

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

      [Start]22.4

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

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

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

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

    if -inf.0 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 4.9999999999999999e146

    1. Initial program 0.2

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

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

      [Start]0.2

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

      rational.json-simplify-49 [=>]11.8

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

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

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

      [Start]0.1

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

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

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

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

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

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

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

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

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

      rational.json-simplify-8 [<=]0.1

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

    if 4.9999999999999999e146 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z)

    1. Initial program 28.3

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

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

      [Start]28.3

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

      rational.json-simplify-49 [=>]0.1

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

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

Alternatives

Alternative 1
Error12.5
Cost1112
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -5.8 \cdot 10^{+83}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.6 \cdot 10^{+32}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq -3100000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 9 \cdot 10^{+24}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+181}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+189}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \end{array} \]
Alternative 2
Error12.2
Cost848
\[\begin{array}{l} t_0 := y \cdot \frac{x}{z}\\ \mathbf{if}\;y \leq -1.4 \cdot 10^{+84}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.75 \cdot 10^{+32}:\\ \;\;\;\;-x\\ \mathbf{elif}\;y \leq -3100000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+22}:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]
Alternative 3
Error0.2
Cost840
\[\begin{array}{l} t_0 := x \cdot \left(-1 + \frac{y - -1}{z}\right)\\ \mathbf{if}\;z \leq -1.02 \cdot 10^{-13}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-46}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error0.2
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -8.1 \cdot 10^{+15}:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{elif}\;z \leq 1.82 \cdot 10^{-40}:\\ \;\;\;\;\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(-1 + \frac{y - -1}{z}\right)\\ \end{array} \]
Alternative 5
Error0.2
Cost840
\[\begin{array}{l} t_0 := x \cdot \left(-1 + \frac{y - -1}{z}\right)\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{-19}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4 \cdot 10^{-43}:\\ \;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error8.8
Cost712
\[\begin{array}{l} t_0 := \frac{x}{z} - x\\ \mathbf{if}\;z \leq -185:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{-8}:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error0.9
Cost712
\[\begin{array}{l} t_0 := \left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{if}\;z \leq -1.6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\left(1 + y\right) \cdot \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error19.1
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -1.6:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 9
Error33.7
Cost128
\[-x \]

Error

Reproduce?

herbie shell --seed 2023064 
(FPCore (x y z)
  :name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))

  (/ (* x (+ (- y z) 1.0)) z))