Proektsoftbg / Calcpad

Free and open source software for mathematical and engineering calculations.
https://calcpad.eu
MIT License
341 stars 42 forks source link

Another problem with Mathcad and (not anymore) with Calcpad #131

Closed Proektsoftbg closed 1 year ago

Proektsoftbg commented 1 year ago

If found that Mathcad calculates this expression wrong:

image

The first result is incorrect, but the second one is correct. Then I tried the same with Calcpad and it showed similar results. I became curious about that and did some research. Finally, I found why this happened and fixed it in Calcpad:

image

This error appear for really large sums (n > 50 000 000) but it can be easily avoided by applying proper summation algorithm. So now, besides several times faster, Calcpad becomes also more precise and reliable. :)

I will include the new algorithm in the next release.

idealkindom commented 1 year ago

Yes, I tested it in Calcpad 5.9.5, found the results are diferent between the two calculations.

However, I am amazed that Calcpad do this much fast then Maxima.

Proektsoftbg commented 1 year ago

Yes, it is. Now I implemented (https://github.com/Proektsoftbg/Calcpad/commit/a08676e0021a8698847e7b2f29ab20d8c77c11e8) the Kahan summation algorithm and the results in Calcpad are already correct as displayed above.

I will issue a new release tomorrow.

And yes, thank you! Calcpad is now much faster than most of the other math software. I only did not compared to MATLAB. This is because the efficient compiler that was implemented recently.

And there is still potential for further optimizations like automatic parallelization, SIMD vectorization, using CUDA Cores, etc.

It is also interested what will Maxima calculate for the above sum. Can you please test it? :)

idealkindom commented 1 year ago

Yes, I tested it in Calcpad 5.9.5, found the results are diferent between the two calculations.

However, I am amazed that Calcpad do this much fast then Maxima.

I tried from n=10^6 to n=10^7 to 10^8,it's very strange that Maxima get stuck for like one minute before it output the answer,which is right.

As for this problem, Calcpad is very sprint. I hope Calcpad could introduce list calculation, maybe this is also a part of matrix calculation, of which I remember you said you are working on.

idealkindom commented 1 year ago

When I say Maxima get stuck I mean especially when I do the summation with n=10^8.

Proektsoftbg commented 1 year ago

The updated version with the Kahan summation formula is released as v5.9.6:

https://github.com/Proektsoftbg/Calcpad/releases/tag/v5.9.6

You can download it now and test it. It must give the correct answer already. On my computer, it takes about 6s to finish for n = 10^8. MathCAD takes 3-4 times more. I tried also with SMath and after 17 min I canceled it.

image

It is good that the Maxima's result is correct. Probably it uses the correct summation algorithm or performs some fractional arithmetic, symbolic calculations or high-precision arithmetic to avoid errors. In these cases, it is normal to work much slower than using directly the internal CPU's floating point instructions.

idealkindom commented 1 year ago

If found that Mathcad calculates this expression wrong:

image

The first result is incorrect, but the second one is correct. Then I tried the same with Calcpad and it showed similar results. I became curious about that and did some research. Finally, I found why this happened and fixed it in Calcpad:

image

This error appear for really large sums (n > 50 000 000) but it can be easily avoided by applying proper summation algorithm. So now, besides several times faster, Calcpad becomes also more precise and reliable. :)

I will include the new algorithm in the next release.

Hi, Ned. Why not promote Calcpad on the page of MathCAD of the website "Alternatives to":https://alternativeto.net/browse/search/?q=MathCAD Since MathCAD has a large user group, this will help more people know about Calcpad.

idealkindom commented 1 year ago

If found that Mathcad calculates this expression wrong:

image

The first result is incorrect, but the second one is correct. Then I tried the same with Calcpad and it showed similar results. I became curious about that and did some research. Finally, I found why this happened and fixed it in Calcpad:

image

This error appear for really large sums (n > 50 000 000) but it can be easily avoided by applying proper summation algorithm. So now, besides several times faster, Calcpad becomes also more precise and reliable. :)

I will include the new algorithm in the next release.

I'm suprised to find Calcpad listed on Alternative to Maple on the website of "Alternative to", in fact Calcpad is different from Maple in concept.

Proektsoftbg commented 1 year ago

Hi, thank you for your suggestion, but I think that Calcpad is already listed. Probably some likes or feedback could help.

Calcpad is different from both MathCAD and Maple, but at the end, you can make engineering calculations on all of them. Acutally, Maple Flow is quite similar to Mathcad: https://www.maplesoft.com/products/mapleflow/.