?

Average Error: 10.1 → 0.3
Time: 8.5s
Precision: binary64
Cost: 1032

?

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

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.1
Target0.4
Herbie0.3
\[\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 2 regimes
  2. if x < -9.9999999999999993e44 or 2.5000000000000001e-59 < x

    1. Initial program 24.4

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

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

      [Start]24.4

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]24.4

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]24.4

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]24.4

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]24.4

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

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

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

      [Start]8.3

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.3

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]8.3

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.3

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

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]8.3

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

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

    if -9.9999999999999993e44 < x < 2.5000000000000001e-59

    1. Initial program 0.4

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

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

      [Start]0.4

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

      rational_best_oopsla_all_46_json_45_simplify-37 [=>]0.4

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.4

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

      rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.4

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.4

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

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

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

      [Start]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2

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

      rational_best_oopsla_all_46_json_45_simplify-94 [<=]0.2

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

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

Alternatives

Alternative 1
Error0.3
Cost968
\[\begin{array}{l} t_0 := \left(\left(\frac{1}{z} + \frac{y}{z}\right) - 1\right) \cdot x\\ \mathbf{if}\;x \leq -8.6 \cdot 10^{+43}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 10^{-60}:\\ \;\;\;\;\frac{x + x \cdot y}{z} + \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.1
Cost904
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+15}:\\ \;\;\;\;\frac{y}{z} \cdot x - x\\ \mathbf{elif}\;z \leq 10^{+16}:\\ \;\;\;\;\frac{x + x \cdot y}{z} + \left(-x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \end{array} \]
Alternative 3
Error12.2
Cost848
\[\begin{array}{l} t_0 := \frac{y \cdot x}{z}\\ t_1 := \frac{x}{z} - x\\ \mathbf{if}\;y \leq -2.35 \cdot 10^{+33}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8.5 \cdot 10^{+137}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.45 \cdot 10^{+178}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.0
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -125:\\ \;\;\;\;\frac{y}{z} \cdot x - x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{y \cdot x}{z} + \frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \end{array} \]
Alternative 5
Error0.1
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+16}:\\ \;\;\;\;\frac{y}{z} \cdot x - x\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{+15}:\\ \;\;\;\;\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \end{array} \]
Alternative 6
Error0.1
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+16}:\\ \;\;\;\;\frac{y}{z} \cdot x - x\\ \mathbf{elif}\;z \leq 8 \cdot 10^{+15}:\\ \;\;\;\;\frac{x + x \cdot \left(y - z\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \end{array} \]
Alternative 7
Error4.3
Cost712
\[\begin{array}{l} t_0 := \left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{if}\;y \leq -950000000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 0.0014:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error4.3
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -950000000000:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \mathbf{elif}\;y \leq 0.0014:\\ \;\;\;\;\frac{x}{z} - x\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot x - x\\ \end{array} \]
Alternative 9
Error1.0
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -125:\\ \;\;\;\;\frac{y}{z} \cdot x - x\\ \mathbf{elif}\;z \leq 1:\\ \;\;\;\;\frac{y \cdot x + x}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\ \end{array} \]
Alternative 10
Error19.5
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -0.009:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 50000:\\ \;\;\;\;\frac{x}{z}\\ \mathbf{else}:\\ \;\;\;\;-x\\ \end{array} \]
Alternative 11
Error18.7
Cost320
\[\frac{x}{z} - x \]
Alternative 12
Error33.7
Cost128
\[-x \]

Error

Reproduce?

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