Re: operator overloading



Mark Thornton wrote :
Wojtek wrote:
Patricia Shanahan wrote :
The challenge I presented earlier in this thread is a *very* simple
example of a mathematical formula:

"Consider calculating the sum of the first n terms of an arithmetic
series, given its first term, a1, and common difference, d.
http://en.wikipedia.org/wiki/Arithmetic_progression#Sum_.28arithmetic_series.29


Infix arithmetic operator version: (n * (2*a1 + (n-1)*d))/2."

Can you produce a descriptive method name form of this expression that
is as obviously equivalent to the original formula?

Ok, this appears to be used as a utility method, therefore I would make it static with the method returning the result of the formulae calculation. The class could be named MyMath. So:

BigInteger seriesSum = MyMath.getProgressionSeriesSum( startTerm, termLimit, difference);


I think you have missed the point. It is just a fragment of code and we don't want to turn every such fragment into a method of its own. It is also on the very simple end of mathematical expressions.

Also to Patricia,

The series sum is a pure math operation, and would not need operator overloading.

And yes, I WOULD create a library with these types of calls. It makes using them in multiple places consistent. I would encase it even for a single use as it makes cleaner code at the point of usage.

What the formula is like in the method is up to the author. Black box testing should prove that the formula implementation is correct. If you do not have trust in the author, then extend the library class and override the method with your own implementation.

But that is always the risk in using someone elses library for everything from high math formula to common string operations. The assumption is that it works until proven false. If you are using the library for mission critical use (life critical, million dollar critical) then you would perform extensive testing before it was trusted.

Maybe I am missing the point with this series sum formula. It just seems obvious to me to encase it in a method, prove it, then just use it.

And how it relates to operator overloading mistifies me.

--
Wojtek :-)


.



Relevant Pages

  • Re: operator overloading
    ... "Consider calculating the sum of the first n terms of an arithmetic ... series, given its first term, a1, and common difference, d. ...
    (comp.lang.java.programmer)
  • Re: operator overloading
    ... series, given its first term, a1, and common difference, d. ... The series sum is a pure math operation, and would not need operator overloading. ... I think that James Gosling has observed that people who are not mathematicians/engineers almost invariably miss the point with regard to the desireability of operator overloading at least for complex arithmetic. ... Others have said that the language of mathematicians is not English/French/German or any other natural language but symbolic with centuries of history. ...
    (comp.lang.java.programmer)
  • Need help on Roundup
    ... be calculating to the 3rd decimal which is making my totals unacceptable. ... formatting in the cells are for 2 decimal places. ... Hi,You can use the following array formula. ... The sum is still rounding up from the 3rd decimal. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Need help on Roundup
    ... be calculating to the 3rd decimal which is making my totals unacceptable. ... formatting in the cells are for 2 decimal places. ... Hi,You can use the following array formula. ... The sum is still rounding up from the 3rd decimal. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Another vectorization problem..
    ... compare the results of your nested for-loop method with the most recent ... to handling the first row in a special way. ... calculating a, b, and c.) ... The sum that you asked about is done inherently in the matrix ...
    (comp.soft-sys.matlab)