Hi,

I need to write a halving algorithm for the root function. Here's what's given:

Code:global_procedure Root ( alters Natural_Power_2& n, preserves Integer r ); /*! requires r > 0 ensures n^(r) <= #n < (n+1)^(r) !*/ //------------------------------------... procedure_body Root ( alters Natural_Power_2& n, preserves Integer r ) { //Fill in here }

I was thinking of doing something like:

Would that work?Code:object Natural_Power_2 old_self, temp; if (r mod 2 == 1) { self.Copy_To (old_self); } self.Power (r/2); self.Copy_To (temp); self.Divide (temp); if (r mod 2 == 1) { self.Divide (old_self); } }

Thanks!