Average Error: 14.8 → 1.3
Time: 3.6s
Precision: binary64
Cost: 1360
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
\[\begin{array}{l} t_1 := y \cdot \frac{x}{z}\\ \mathbf{if}\;\frac{y}{z} \leq -\infty:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} \leq -4 \cdot 10^{-78}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{-131}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{+228}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* y (/ x z))))
   (if (<= (/ y z) (- INFINITY))
     (/ (* y x) z)
     (if (<= (/ y z) -4e-78)
       (* (/ y z) x)
       (if (<= (/ y z) 1e-131)
         t_1
         (if (<= (/ y z) 5e+228) (/ x (/ z y)) t_1))))))
double code(double x, double y, double z, double t) {
	return x * (((y / z) * t) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = y * (x / z);
	double tmp;
	if ((y / z) <= -((double) INFINITY)) {
		tmp = (y * x) / z;
	} else if ((y / z) <= -4e-78) {
		tmp = (y / z) * x;
	} else if ((y / z) <= 1e-131) {
		tmp = t_1;
	} else if ((y / z) <= 5e+228) {
		tmp = x / (z / y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t) {
	return x * (((y / z) * t) / t);
}
public static double code(double x, double y, double z, double t) {
	double t_1 = y * (x / z);
	double tmp;
	if ((y / z) <= -Double.POSITIVE_INFINITY) {
		tmp = (y * x) / z;
	} else if ((y / z) <= -4e-78) {
		tmp = (y / z) * x;
	} else if ((y / z) <= 1e-131) {
		tmp = t_1;
	} else if ((y / z) <= 5e+228) {
		tmp = x / (z / y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return x * (((y / z) * t) / t)
def code(x, y, z, t):
	t_1 = y * (x / z)
	tmp = 0
	if (y / z) <= -math.inf:
		tmp = (y * x) / z
	elif (y / z) <= -4e-78:
		tmp = (y / z) * x
	elif (y / z) <= 1e-131:
		tmp = t_1
	elif (y / z) <= 5e+228:
		tmp = x / (z / y)
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	return Float64(x * Float64(Float64(Float64(y / z) * t) / t))
end
function code(x, y, z, t)
	t_1 = Float64(y * Float64(x / z))
	tmp = 0.0
	if (Float64(y / z) <= Float64(-Inf))
		tmp = Float64(Float64(y * x) / z);
	elseif (Float64(y / z) <= -4e-78)
		tmp = Float64(Float64(y / z) * x);
	elseif (Float64(y / z) <= 1e-131)
		tmp = t_1;
	elseif (Float64(y / z) <= 5e+228)
		tmp = Float64(x / Float64(z / y));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x * (((y / z) * t) / t);
end
function tmp_2 = code(x, y, z, t)
	t_1 = y * (x / z);
	tmp = 0.0;
	if ((y / z) <= -Inf)
		tmp = (y * x) / z;
	elseif ((y / z) <= -4e-78)
		tmp = (y / z) * x;
	elseif ((y / z) <= 1e-131)
		tmp = t_1;
	elseif ((y / z) <= 5e+228)
		tmp = x / (z / y);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y / z), $MachinePrecision], (-Infinity)], N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], -4e-78], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 1e-131], t$95$1, If[LessEqual[N[(y / z), $MachinePrecision], 5e+228], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}
t_1 := y \cdot \frac{x}{z}\\
\mathbf{if}\;\frac{y}{z} \leq -\infty:\\
\;\;\;\;\frac{y \cdot x}{z}\\

\mathbf{elif}\;\frac{y}{z} \leq -4 \cdot 10^{-78}:\\
\;\;\;\;\frac{y}{z} \cdot x\\

\mathbf{elif}\;\frac{y}{z} \leq 10^{-131}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{+228}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.8
Target1.6
Herbie1.3
\[\begin{array}{l} \mathbf{if}\;\frac{\frac{y}{z} \cdot t}{t} < -1.20672205123045 \cdot 10^{+245}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < -5.907522236933906 \cdot 10^{-275}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 5.658954423153415 \cdot 10^{-65}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} < 2.0087180502407133 \cdot 10^{+217}:\\ \;\;\;\;x \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 y z) < -inf.0

    1. Initial program 64.0

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified57.8

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 50 points increase in error, 69 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 64 points increase in error, 46 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 46 points increase in error, 3 points decrease in error
    3. Taylor expanded in x around 0 0.3

      \[\leadsto \color{blue}{\frac{y \cdot x}{z}} \]

    if -inf.0 < (/.f64 y z) < -4e-78

    1. Initial program 10.1

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified0.2

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 50 points increase in error, 69 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 64 points increase in error, 46 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 46 points increase in error, 3 points decrease in error
    3. Applied egg-rr0.3

      \[\leadsto \color{blue}{\frac{y}{z} \cdot x} \]

    if -4e-78 < (/.f64 y z) < 9.9999999999999999e-132 or 5e228 < (/.f64 y z)

    1. Initial program 18.2

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified9.6

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 50 points increase in error, 69 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 64 points increase in error, 46 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 46 points increase in error, 3 points decrease in error
    3. Applied egg-rr2.4

      \[\leadsto \color{blue}{\frac{x}{z} \cdot y} \]

    if 9.9999999999999999e-132 < (/.f64 y z) < 5e228

    1. Initial program 8.2

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified0.3

      \[\leadsto \color{blue}{\frac{x}{\frac{z}{y}}} \]
      Proof
      (/.f64 x (/.f64 z y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 x y) z)): 50 points increase in error, 69 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 64 points increase in error, 46 points decrease in error
      (*.f64 x (Rewrite<= /-rgt-identity_binary64 (/.f64 (/.f64 y z) 1))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (/.f64 (/.f64 y z) (Rewrite<= *-inverses_binary64 (/.f64 t t)))): 0 points increase in error, 0 points decrease in error
      (*.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 (/.f64 y z) t) t))): 46 points increase in error, 3 points decrease in error
  3. Recombined 4 regimes into one program.
  4. Final simplification1.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{y}{z} \leq -\infty:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} \leq -4 \cdot 10^{-78}:\\ \;\;\;\;\frac{y}{z} \cdot x\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{-131}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{+228}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost1360
\[\begin{array}{l} t_1 := \frac{y}{z} \cdot x\\ t_2 := \frac{y \cdot x}{z}\\ \mathbf{if}\;\frac{y}{z} \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq -5 \cdot 10^{-160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{y}{z} \leq 2 \cdot 10^{-318}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq 5 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error1.4
Cost1360
\[\begin{array}{l} t_1 := \frac{y}{z} \cdot x\\ t_2 := y \cdot \frac{x}{z}\\ \mathbf{if}\;\frac{y}{z} \leq -\infty:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;\frac{y}{z} \leq -4 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{-131}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\frac{y}{z} \leq 10^{+167}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error6.2
Cost320
\[\frac{y}{z} \cdot x \]

Error

Reproduce

herbie shell --seed 2022300 
(FPCore (x y z t)
  :name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
  :precision binary64

  :herbie-target
  (if (< (/ (* (/ y z) t) t) -1.20672205123045e+245) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) -5.907522236933906e-275) (* x (/ y z)) (if (< (/ (* (/ y z) t) t) 5.658954423153415e-65) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) 2.0087180502407133e+217) (* x (/ y z)) (/ (* y x) z)))))

  (* x (/ (* (/ y z) t) t)))