?

Average Error: 11.3 → 6.3
Time: 4.5s
Precision: binary64
Cost: 1488

?

\[\frac{a1 \cdot a2}{b1 \cdot b2} \]
\[\begin{array}{l} t_0 := a1 \cdot \frac{a2}{b1 \cdot b2}\\ t_1 := \frac{\frac{a2}{b2} \cdot a1}{b1}\\ \mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \cdot b2 \leq -1 \cdot 10^{-125}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 10^{-321}:\\ \;\;\;\;\frac{\frac{a2}{\frac{b1}{a1}}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+118}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* a1 (/ a2 (* b1 b2)))) (t_1 (/ (* (/ a2 b2) a1) b1)))
   (if (<= (* b1 b2) -1e+152)
     t_1
     (if (<= (* b1 b2) -1e-125)
       t_0
       (if (<= (* b1 b2) 1e-321)
         (/ (/ a2 (/ b1 a1)) b2)
         (if (<= (* b1 b2) 2e+118) t_0 t_1))))))
double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
double code(double a1, double a2, double b1, double b2) {
	double t_0 = a1 * (a2 / (b1 * b2));
	double t_1 = ((a2 / b2) * a1) / b1;
	double tmp;
	if ((b1 * b2) <= -1e+152) {
		tmp = t_1;
	} else if ((b1 * b2) <= -1e-125) {
		tmp = t_0;
	} else if ((b1 * b2) <= 1e-321) {
		tmp = (a2 / (b1 / a1)) / b2;
	} else if ((b1 * b2) <= 2e+118) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    code = (a1 * a2) / (b1 * b2)
end function
real(8) function code(a1, a2, b1, b2)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = a1 * (a2 / (b1 * b2))
    t_1 = ((a2 / b2) * a1) / b1
    if ((b1 * b2) <= (-1d+152)) then
        tmp = t_1
    else if ((b1 * b2) <= (-1d-125)) then
        tmp = t_0
    else if ((b1 * b2) <= 1d-321) then
        tmp = (a2 / (b1 / a1)) / b2
    else if ((b1 * b2) <= 2d+118) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = a1 * (a2 / (b1 * b2));
	double t_1 = ((a2 / b2) * a1) / b1;
	double tmp;
	if ((b1 * b2) <= -1e+152) {
		tmp = t_1;
	} else if ((b1 * b2) <= -1e-125) {
		tmp = t_0;
	} else if ((b1 * b2) <= 1e-321) {
		tmp = (a2 / (b1 / a1)) / b2;
	} else if ((b1 * b2) <= 2e+118) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	return (a1 * a2) / (b1 * b2)
def code(a1, a2, b1, b2):
	t_0 = a1 * (a2 / (b1 * b2))
	t_1 = ((a2 / b2) * a1) / b1
	tmp = 0
	if (b1 * b2) <= -1e+152:
		tmp = t_1
	elif (b1 * b2) <= -1e-125:
		tmp = t_0
	elif (b1 * b2) <= 1e-321:
		tmp = (a2 / (b1 / a1)) / b2
	elif (b1 * b2) <= 2e+118:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 * a2) / Float64(b1 * b2))
end
function code(a1, a2, b1, b2)
	t_0 = Float64(a1 * Float64(a2 / Float64(b1 * b2)))
	t_1 = Float64(Float64(Float64(a2 / b2) * a1) / b1)
	tmp = 0.0
	if (Float64(b1 * b2) <= -1e+152)
		tmp = t_1;
	elseif (Float64(b1 * b2) <= -1e-125)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= 1e-321)
		tmp = Float64(Float64(a2 / Float64(b1 / a1)) / b2);
	elseif (Float64(b1 * b2) <= 2e+118)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 * a2) / (b1 * b2);
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = a1 * (a2 / (b1 * b2));
	t_1 = ((a2 / b2) * a1) / b1;
	tmp = 0.0;
	if ((b1 * b2) <= -1e+152)
		tmp = t_1;
	elseif ((b1 * b2) <= -1e-125)
		tmp = t_0;
	elseif ((b1 * b2) <= 1e-321)
		tmp = (a2 / (b1 / a1)) / b2;
	elseif ((b1 * b2) <= 2e+118)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a1 * N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(a2 / b2), $MachinePrecision] * a1), $MachinePrecision] / b1), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -1e+152], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -1e-125], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 1e-321], N[(N[(a2 / N[(b1 / a1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+118], t$95$0, t$95$1]]]]]]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := a1 \cdot \frac{a2}{b1 \cdot b2}\\
t_1 := \frac{\frac{a2}{b2} \cdot a1}{b1}\\
\mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+152}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b1 \cdot b2 \leq -1 \cdot 10^{-125}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b1 \cdot b2 \leq 10^{-321}:\\
\;\;\;\;\frac{\frac{a2}{\frac{b1}{a1}}}{b2}\\

\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+118}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.3
Target11.2
Herbie6.3
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation?

  1. Split input into 3 regimes
  2. if (*.f64 b1 b2) < -1e152 or 1.99999999999999993e118 < (*.f64 b1 b2)

    1. Initial program 13.3

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified13.1

      \[\leadsto \color{blue}{a2 \cdot \frac{a1}{b1 \cdot b2}} \]
      Proof

      [Start]13.3

      \[ \frac{a1 \cdot a2}{b1 \cdot b2} \]

      associate-*l/ [<=]13.1

      \[ \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]

      *-commutative [=>]13.1

      \[ \color{blue}{a2 \cdot \frac{a1}{b1 \cdot b2}} \]
    3. Applied egg-rr6.2

      \[\leadsto \color{blue}{\frac{\frac{a2}{b2} \cdot a1}{b1}} \]

    if -1e152 < (*.f64 b1 b2) < -1.00000000000000001e-125 or 9.98013e-322 < (*.f64 b1 b2) < 1.99999999999999993e118

    1. Initial program 4.5

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied egg-rr4.7

      \[\leadsto \color{blue}{\frac{a2}{b1 \cdot b2} \cdot a1} \]

    if -1.00000000000000001e-125 < (*.f64 b1 b2) < 9.98013e-322

    1. Initial program 31.5

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified12.2

      \[\leadsto \color{blue}{\frac{\frac{a2}{\frac{b1}{a1}}}{b2}} \]
      Proof

      [Start]31.5

      \[ \frac{a1 \cdot a2}{b1 \cdot b2} \]

      associate-/r* [=>]17.3

      \[ \color{blue}{\frac{\frac{a1 \cdot a2}{b1}}{b2}} \]

      *-commutative [=>]17.3

      \[ \frac{\frac{\color{blue}{a2 \cdot a1}}{b1}}{b2} \]

      associate-/l* [=>]12.2

      \[ \frac{\color{blue}{\frac{a2}{\frac{b1}{a1}}}}{b2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification6.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+152}:\\ \;\;\;\;\frac{\frac{a2}{b2} \cdot a1}{b1}\\ \mathbf{elif}\;b1 \cdot b2 \leq -1 \cdot 10^{-125}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 10^{-321}:\\ \;\;\;\;\frac{\frac{a2}{\frac{b1}{a1}}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+118}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2} \cdot a1}{b1}\\ \end{array} \]

Alternatives

Alternative 1
Error3.8
Cost2513
\[\begin{array}{l} t_0 := \frac{a2 \cdot a1}{b1 \cdot b2}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+136}:\\ \;\;\;\;a2 \cdot \frac{\frac{a1}{b1}}{b2}\\ \mathbf{elif}\;t_0 \leq -4 \cdot 10^{-290} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 10^{+298}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \end{array} \]
Alternative 2
Error5.5
Cost1490
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -5 \cdot 10^{+209} \lor \neg \left(b1 \cdot b2 \leq -1 \cdot 10^{-240}\right) \land \left(b1 \cdot b2 \leq 5 \cdot 10^{-176} \lor \neg \left(b1 \cdot b2 \leq 2 \cdot 10^{+220}\right)\right):\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \end{array} \]
Alternative 3
Error5.9
Cost1490
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -\infty \lor \neg \left(b1 \cdot b2 \leq -5 \cdot 10^{-228} \lor \neg \left(b1 \cdot b2 \leq 10^{-321}\right) \land b1 \cdot b2 \leq 2 \cdot 10^{+118}\right):\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{else}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \end{array} \]
Alternative 4
Error11.4
Cost448
\[a2 \cdot \frac{a1}{b1 \cdot b2} \]

Error

Reproduce?

herbie shell --seed 2023045 
(FPCore (a1 a2 b1 b2)
  :name "Quotient of products"
  :precision binary64

  :herbie-target
  (* (/ a1 b1) (/ a2 b2))

  (/ (* a1 a2) (* b1 b2)))