Clearly it's not all the code because didn't even put in what is in context of the error message --
Undefined function or variable 'd1'.
Error in Type1 (line 5) f=(1+d1())^a+(1+d2())^b+(1+d3())^g;
Your problem is that in the above line there is no d1 in context. You need that definition first. One then presumes you'll move on to d2 and d3 in turn.
What are these intended to be and what are the empty paren's trying to indicate? If the various d are functions w/ no arguments then the () are superfluous and if they're arrays they're missing a subscript expression.