/* PROCEDURES THAT IMPLEMENT TASKS FOR EXPANDING EXPRESSIONS */

/* An "expand" task is represented using the following predicate:
		expand(priority,expression)
  */


/* ACCESS TO PARTS */

priority( expand(Priority,_), Priority).


/* PROCEDURES FOR DOING EXPAND TASK */

do( expand(Priority,Expr) ) :-
  /* first add a "bind" task to bind all vars in the existing expression */
   add_task( bind(3,Expr,1,0) ),
   /* now get each expression, substitute it in, and add a new expand
      task for the newly expanded expression */
   expression(E),
   subst_first(var,E,Expr,New_Expr),
   add_task( expand(2,New_Expr) ),
   fail.


/* all possible expansions ... */

expression( -var ).
expression( sin(var) ).

expression( var+var ).
expression( var*var ).
