Primitive Integration Rules

Int[a_,x_Symbol] :=
   a*x /;
FreeQ[a,x]

Int[u_,x_Symbol] :=
  Map[Function[Int[#,x]],u] /;
Head[u]===Plus

Int[a_*u_,x_Symbol] :=
  Dist[a,Int[u,x]] /;
FreeQ[a,x] && Not[MatchQ[u,b_*v_. /; FreeQ[b,x]]]

Int[x_^n_.,x_Symbol] :=
  x^(n+1)/(n+1) /;
RationalQ[n] && n≠-1

Utility Functions

SumQ[u_] :=
  Head[u]===Plus

ProductQ[u_] :=
  Head[u]===Times

RationalQ[u_] :=
  If[ListQ[u],
    Catch[Scan[Function[If[Not[RationalQ[#]],Throw[False]]],u]; True],
  IntegerQ[u] || Head[u]===Rational]

(* RealNumericQ[u] returns True if u is a real numeric quantity, else returns False. *)
RealNumericQ[u_] := NumericQ[u] && PossibleZeroQ[Im[N[u]]]

(* PositiveQ[u] returns True if u is a positive numeric quantity, else returns False. *)
PositiveQ[u_] :=
  Module[{v=Together[u]},
  RealNumericQ[v] && Re[N[v]]>0]

(* NegativeQ[u] returns True if u is a negative numeric quantity, else returns False. *)
NegativeQ[u_] :=
  Module[{v=Together[u]},
  RealNumericQ[v] && Re[N[v]]<0]

(* ZeroQ[u] returns True if u is any 0; else returns False *)
ZeroQ[u_] := PossibleZeroQ[u]

(* NonzeroQ[u] returns True if u is not any 0, else it returns False. *)
NonzeroQ[u_] := Not[PossibleZeroQ[u]]

(* Dist[u,v] distributes u over the terms of v. *) 
Dist[u_,v_] := 
  If[SumQ[v],
    Map[Function[Dist[u,#]],v],
  u*v]

Rt[u_,n_Integer] := u^(1/n)

(* If u is not 0 and has a positive form, PosQ[u] returns True, else it returns False. *)
PosQ[u_] :=
  If[RationalQ[u],
    u>0,
  If[NumberQ[u],
    If[PossibleZeroQ[Re[u]],
      Im[u]>0,
    Re[u]>0],
  If[NumericQ[u],
    Module[{v=N[u]},
    If[PossibleZeroQ[Re[v]],
      Im[v]>0,
    Re[v]>0]],
  If[ProductQ[u],
    If[PosQ[First[u]],
      PosQ[Rest[u]],
    NegQ[Rest[u]]],
  If[SumQ[u],
    Module[{v=Together[u]},
    If[SumQ[v],
      PosQ[First[v]],
    PosQ[v]]],
  True]]]]]

NegQ[u_] :=
  If[PossibleZeroQ[u],
    False,
  Not[PosQ[u]]]

Sim[u_] := Together[u];

Sim[u_,x_] := 
  If[SumQ[u],
    Module[{tmp1=0,tmp2=0,lst},
    Scan[Function[lst=SplitFreeFactors[#,x];If[lst[[2]]===1,tmp1+=#,tmp2=tmp2+Together[lst[[1]]]*lst[[2]]]],u];
    Together[tmp1]+tmp2],
  Module[{lst=SplitFreeFactors[u,x]},
  Together[lst[[1]]]*lst[[2]]]]

(* SplitFreeFactors[u,x] returns the list {v,w} where v is the product of the factors of u free of x
	and w is the product of the other factors. *)
SplitFreeFactors[u_,x_Symbol] :=
  If[ProductQ[u],
    Map[Function[If[FreeQ[#,x],{#,1},{1,#}]],u],
  If[FreeQ[u,x],
    {u,1},
  {1,u}]]