?

Average Error: 11.2 → 3.8
Time: 4.5s
Precision: binary64
Cost: 2512

?

\[\frac{a1 \cdot a2}{b1 \cdot b2} \]
\[\begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+287}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;t_0 \leq -4 \cdot 10^{-288}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{\frac{a2}{\frac{b1}{a1}}}{b2}\\ \mathbf{elif}\;t_0 \leq 10^{+272}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \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))))
   (if (<= t_0 -1e+287)
     (* a2 (/ a1 (* b1 b2)))
     (if (<= t_0 -4e-288)
       t_0
       (if (<= t_0 0.0)
         (/ (/ a2 (/ b1 a1)) b2)
         (if (<= t_0 1e+272) t_0 (/ (/ a2 b2) (/ b1 a1))))))))
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 tmp;
	if (t_0 <= -1e+287) {
		tmp = a2 * (a1 / (b1 * b2));
	} else if (t_0 <= -4e-288) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = (a2 / (b1 / a1)) / b2;
	} else if (t_0 <= 1e+272) {
		tmp = t_0;
	} else {
		tmp = (a2 / b2) / (b1 / a1);
	}
	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) :: tmp
    t_0 = (a1 * a2) / (b1 * b2)
    if (t_0 <= (-1d+287)) then
        tmp = a2 * (a1 / (b1 * b2))
    else if (t_0 <= (-4d-288)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = (a2 / (b1 / a1)) / b2
    else if (t_0 <= 1d+272) then
        tmp = t_0
    else
        tmp = (a2 / b2) / (b1 / a1)
    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 tmp;
	if (t_0 <= -1e+287) {
		tmp = a2 * (a1 / (b1 * b2));
	} else if (t_0 <= -4e-288) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = (a2 / (b1 / a1)) / b2;
	} else if (t_0 <= 1e+272) {
		tmp = t_0;
	} else {
		tmp = (a2 / b2) / (b1 / a1);
	}
	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)
	tmp = 0
	if t_0 <= -1e+287:
		tmp = a2 * (a1 / (b1 * b2))
	elif t_0 <= -4e-288:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = (a2 / (b1 / a1)) / b2
	elif t_0 <= 1e+272:
		tmp = t_0
	else:
		tmp = (a2 / b2) / (b1 / a1)
	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(Float64(a1 * a2) / Float64(b1 * b2))
	tmp = 0.0
	if (t_0 <= -1e+287)
		tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2)));
	elseif (t_0 <= -4e-288)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(Float64(a2 / Float64(b1 / a1)) / b2);
	elseif (t_0 <= 1e+272)
		tmp = t_0;
	else
		tmp = Float64(Float64(a2 / b2) / Float64(b1 / a1));
	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);
	tmp = 0.0;
	if (t_0 <= -1e+287)
		tmp = a2 * (a1 / (b1 * b2));
	elseif (t_0 <= -4e-288)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = (a2 / (b1 / a1)) / b2;
	elseif (t_0 <= 1e+272)
		tmp = t_0;
	else
		tmp = (a2 / b2) / (b1 / a1);
	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[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+287], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -4e-288], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(a2 / N[(b1 / a1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[t$95$0, 1e+272], t$95$0, N[(N[(a2 / b2), $MachinePrecision] / N[(b1 / a1), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+287}:\\
\;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\

\mathbf{elif}\;t_0 \leq -4 \cdot 10^{-288}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{\frac{a2}{\frac{b1}{a1}}}{b2}\\

\mathbf{elif}\;t_0 \leq 10^{+272}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.2
Target11.7
Herbie3.8
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation?

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.0000000000000001e287

    1. Initial program 53.8

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

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

      [Start]53.8

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

      associate-*l/ [<=]29.4

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

      *-commutative [=>]29.4

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

    if -1.0000000000000001e287 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.00000000000000023e-288 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e272

    1. Initial program 0.8

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

    if -4.00000000000000023e-288 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0

    1. Initial program 12.5

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

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

      [Start]12.5

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

      associate-/r* [=>]6.2

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

      *-commutative [=>]6.2

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

      associate-/l* [=>]4.2

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

    if 1.0000000000000001e272 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 55.4

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

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

      [Start]55.4

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

      times-frac [=>]9.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -1 \cdot 10^{+287}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -4 \cdot 10^{-288}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{\frac{a2}{\frac{b1}{a1}}}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 10^{+272}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \end{array} \]

Alternatives

Alternative 1
Error3.2
Cost2513
\[\begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+287}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-307} \lor \neg \left(t_0 \leq 0\right) \land t_0 \leq 5 \cdot 10^{+280}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \end{array} \]
Alternative 2
Error3.5
Cost2512
\[\begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+287}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b2}}{b1}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+280}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \end{array} \]
Alternative 3
Error3.5
Cost2512
\[\begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+287}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b2}}{b1}\\ \mathbf{elif}\;t_0 \leq 10^{+272}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \end{array} \]
Alternative 4
Error5.8
Cost1490
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+301} \lor \neg \left(b1 \cdot b2 \leq -1 \cdot 10^{-88} \lor \neg \left(b1 \cdot b2 \leq 10^{-244}\right) \land b1 \cdot b2 \leq 5 \cdot 10^{+278}\right):\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \end{array} \]
Alternative 5
Error11.0
Cost448
\[a2 \cdot \frac{a1}{b1 \cdot b2} \]

Error

Reproduce?

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

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

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