
/* TODO remove these! defined in yacasapi now. */
/* Some operators for the current math engine... */
/* Function("=",{aLeft,aRight}) Equals(aLeft,aRight);  */
/* Function("Not",{aLeft}) MathNot(aLeft); */

/* Operator versions of internal functions. */
/* Function("<",{aLeft,aRight}) LessThan(aLeft,aRight);    */
/* Function(">",{aLeft,aRight}) GreaterThan(aLeft,aRight);  */

Function("<=",{aLeft,aRight}) aLeft<aRight Or aLeft = aRight;  
Function(">=",{aLeft,aRight}) aLeft>aRight Or aLeft = aRight;  
Function("!=",{aLeft,aRight}) Not(aLeft=aRight);      

/* Shifting operators */
RuleBase("<<",{n,m});
Rule("<<",2,0,IsInteger(n) And IsInteger(m)) ShiftLeft(n,m);

RuleBase(">>",{n,m});
Rule(">>",2,0,IsInteger(n) And IsInteger(m)) ShiftRight(n,m);



RuleBase("Sqrt",{x});
Rule("Sqrt",1,1,IsNumber(x) And x>=0 And Numeric) MathSqrt(x);
Rule("Sqrt",1,1,IsNumber(x) And x<0 And Numeric) Complex(0,MathSqrt(-x));

/* Rulebases put here because they may be used by univar */
RuleBase("Div",{n,m});
RuleBase("Mod",{n,m});
RuleBase("Gcd",{n,m});

/* Integer divisions */
Rule("Div",2,0,IsInteger(n) And IsInteger(m)) MathDiv(n,m);

Rule("Mod",2,0,IsInteger(n) And IsInteger(m)) MathMod(n,m);

Rule("Div",2,1,True)
  NormalForm(Div(MakeUni(n),MakeUni(m)));

Rule("Mod",2,1,True)
  NormalForm(Mod(MakeUni(n),MakeUni(m)));

Rule("Gcd",2,1,IsInteger(n) And IsInteger(m)) MathGcd(n,m);
Rule("Gcd",2,100,True)
[
   NormalForm(Gcd(MakeUni(n),MakeUni(m)));
];

RuleBase("Gcd",{list});

Rule("Gcd",1,1,IsList(list) And Length(list) > 2)
[
  Local(first);
  first:=Gcd(list[[1]],list[[2]]);
  Gcd(first:Tail(Tail(list)));
];

Rule("Gcd",1,2,IsList(list) And Length(list) = 2) Gcd(list[[1]],list[[2]]);



Function("Expand",{expression})
[
  NormalForm(MakeUni(expression));
];

Function("Expand",{expression,var})
[
  NormalForm(MakeUni(expression,var));
];


RuleBase("Object",{pred,x});
Rule("Object",2,0,Apply(pred,{x})=True) x;

/*TODO move to math */
Rule("Gcd",2,100,True)
    [
     NormalForm(Gcd(MakeUni(n),MakeUni(m)));
     ];

