Average Error: 14.6 → 1.2
Time: 4.8s
Precision: binary64
Cost: 2640
\[ \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 := \frac{\frac{y}{z} \cdot t}{t}\\ t_2 := \frac{1}{\frac{z}{y \cdot x}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+192}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -1 \cdot 10^{-145}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-168}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+190}:\\ \;\;\;\;t_1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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 z) t) t)) (t_2 (/ 1.0 (/ z (* y x)))))
   (if (<= t_1 -2e+192)
     t_2
     (if (<= t_1 -1e-145)
       (/ x (/ z y))
       (if (<= t_1 2e-168)
         (* y (/ x z))
         (if (<= t_1 5e+190) (* t_1 x) t_2))))))
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 / z) * t) / t;
	double t_2 = 1.0 / (z / (y * x));
	double tmp;
	if (t_1 <= -2e+192) {
		tmp = t_2;
	} else if (t_1 <= -1e-145) {
		tmp = x / (z / y);
	} else if (t_1 <= 2e-168) {
		tmp = y * (x / z);
	} else if (t_1 <= 5e+190) {
		tmp = t_1 * x;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = x * (((y / z) * t) / t)
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = ((y / z) * t) / t
    t_2 = 1.0d0 / (z / (y * x))
    if (t_1 <= (-2d+192)) then
        tmp = t_2
    else if (t_1 <= (-1d-145)) then
        tmp = x / (z / y)
    else if (t_1 <= 2d-168) then
        tmp = y * (x / z)
    else if (t_1 <= 5d+190) then
        tmp = t_1 * x
    else
        tmp = t_2
    end if
    code = tmp
end function
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 / z) * t) / t;
	double t_2 = 1.0 / (z / (y * x));
	double tmp;
	if (t_1 <= -2e+192) {
		tmp = t_2;
	} else if (t_1 <= -1e-145) {
		tmp = x / (z / y);
	} else if (t_1 <= 2e-168) {
		tmp = y * (x / z);
	} else if (t_1 <= 5e+190) {
		tmp = t_1 * x;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t):
	return x * (((y / z) * t) / t)
def code(x, y, z, t):
	t_1 = ((y / z) * t) / t
	t_2 = 1.0 / (z / (y * x))
	tmp = 0
	if t_1 <= -2e+192:
		tmp = t_2
	elif t_1 <= -1e-145:
		tmp = x / (z / y)
	elif t_1 <= 2e-168:
		tmp = y * (x / z)
	elif t_1 <= 5e+190:
		tmp = t_1 * x
	else:
		tmp = t_2
	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(Float64(Float64(y / z) * t) / t)
	t_2 = Float64(1.0 / Float64(z / Float64(y * x)))
	tmp = 0.0
	if (t_1 <= -2e+192)
		tmp = t_2;
	elseif (t_1 <= -1e-145)
		tmp = Float64(x / Float64(z / y));
	elseif (t_1 <= 2e-168)
		tmp = Float64(y * Float64(x / z));
	elseif (t_1 <= 5e+190)
		tmp = Float64(t_1 * x);
	else
		tmp = t_2;
	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 / z) * t) / t;
	t_2 = 1.0 / (z / (y * x));
	tmp = 0.0;
	if (t_1 <= -2e+192)
		tmp = t_2;
	elseif (t_1 <= -1e-145)
		tmp = x / (z / y);
	elseif (t_1 <= 2e-168)
		tmp = y * (x / z);
	elseif (t_1 <= 5e+190)
		tmp = t_1 * x;
	else
		tmp = t_2;
	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[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(z / N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+192], t$95$2, If[LessEqual[t$95$1, -1e-145], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-168], N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+190], N[(t$95$1 * x), $MachinePrecision], t$95$2]]]]]]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}
t_1 := \frac{\frac{y}{z} \cdot t}{t}\\
t_2 := \frac{1}{\frac{z}{y \cdot x}}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+192}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-145}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-168}:\\
\;\;\;\;y \cdot \frac{x}{z}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+190}:\\
\;\;\;\;t_1 \cdot x\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.6
Target1.5
Herbie1.2
\[\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 (*.f64 (/.f64 y z) t) t) < -2.00000000000000008e192 or 5.00000000000000036e190 < (/.f64 (*.f64 (/.f64 y z) t) t)

    1. Initial program 45.2

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
    2. Simplified18.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)): 47 points increase in error, 65 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 55 points increase in error, 47 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))): 40 points increase in error, 1 points decrease in error
    3. Applied egg-rr3.1

      \[\leadsto \color{blue}{\frac{1}{z} \cdot \frac{x}{\frac{1}{y}}} \]
    4. Applied egg-rr3.0

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

    if -2.00000000000000008e192 < (/.f64 (*.f64 (/.f64 y z) t) t) < -9.99999999999999915e-146

    1. Initial program 0.8

      \[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)): 47 points increase in error, 65 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 55 points increase in error, 47 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))): 40 points increase in error, 1 points decrease in error

    if -9.99999999999999915e-146 < (/.f64 (*.f64 (/.f64 y z) t) t) < 2.0000000000000001e-168

    1. Initial program 18.7

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

      \[\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)): 47 points increase in error, 65 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 x (/.f64 y z))): 55 points increase in error, 47 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))): 40 points increase in error, 1 points decrease in error
    3. Applied egg-rr1.5

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

    if 2.0000000000000001e-168 < (/.f64 (*.f64 (/.f64 y z) t) t) < 5.00000000000000036e190

    1. Initial program 0.5

      \[x \cdot \frac{\frac{y}{z} \cdot t}{t} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\frac{y}{z} \cdot t}{t} \leq -2 \cdot 10^{+192}:\\ \;\;\;\;\frac{1}{\frac{z}{y \cdot x}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} \leq -1 \cdot 10^{-145}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} \leq 2 \cdot 10^{-168}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;\frac{\frac{y}{z} \cdot t}{t} \leq 5 \cdot 10^{+190}:\\ \;\;\;\;\frac{\frac{y}{z} \cdot t}{t} \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{z}{y \cdot x}}\\ \end{array} \]

Alternatives

Alternative 1
Error6.3
Cost716
\[\begin{array}{l} t_1 := y \cdot \frac{x}{z}\\ t_2 := \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -4.77363749036325 \cdot 10^{+157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{-175}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.341277899411328 \cdot 10^{+160}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error6.3
Cost716
\[\begin{array}{l} \mathbf{if}\;z \leq -4.77363749036325 \cdot 10^{+157}:\\ \;\;\;\;y \cdot \frac{x}{z}\\ \mathbf{elif}\;z \leq 10^{-175}:\\ \;\;\;\;\frac{y \cdot x}{z}\\ \mathbf{elif}\;z \leq 8.810553934504197 \cdot 10^{+167}:\\ \;\;\;\;\frac{y}{\frac{z}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{z}{y}}\\ \end{array} \]
Alternative 3
Error6.8
Cost320
\[y \cdot \frac{x}{z} \]

Error

Reproduce

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