The problem we have now is an operation that consists only of addition, multiplication, and division.
double c,m,d1,d2;
/* value each*/
doublex=(c*m+(d1+1.0/d2)/2.0);
That's the formula.Throw this expression to Maxima
double x=(c*m+0.5*(d1+1.0/d2)/(c+1.0);
will be transformed into .Organizing the expressions
doublex=(2.0*c*d2*m+d1*d2+1.0)/(2.0*c+2.0)*d2);
appears in
If you type it as it is, you won't get the formula wrong
Considering the calculation error, if the formula is modified,
Is the error due to division and multiplication large?
Is the error due to addition and subtraction large?
I felt it was necessary to think
Which operator is less likely to cause calculation errors?
Additional information
The book "Common sense of numerical calculation" lists examples of how errors can be avoided by expression deformation, but does not specifically describe how the deformation of the expression leads to reduction of errors (especially for division multiplication).
Instead of expecting a more detailed explanation of multiple-length operations and addition algorithms,
This question asks how it would be desirable to modify it if it could be mitigated by formula transformation.
I think it's good to study terms related to calculation errors such as rounding error, missing digits, and missing information in your own way.
"As for the book, I think the calculation error was detailed in ""common sense of numerical calculation"" by Masao Iri and others."
Also, in the web documentation, the here page is relatively well organized
In terms of calculation errors, the four operations are not very relevant (although multiplication and division certainly have a greater impact).
It depends on how many digits the error can be allowed.
Eventually, using the double
type will result in errors.
double value=0.1;
Even does not have strictly 0.1
(because it cannot be expressed in binary).
I think it's common to change the scale depending on how many digits you want to guarantee and calculate using an integer type.
For example, if you want to guarantee up to four decimal places,
0.1
is treated as 1000
, dividing 10000
into the final operation results, and then substituting the double
type for the first time.
Does the Maxima
big float take into account this area?
For your reference, here is the next page on computational calculations.
...
If the formula is programmed as it is, the computer's real-number valid number is infinite, it should produce the correct result, but it is actually finite, so there is an error occurs.This is called a round error.
...
The problem of floating-point rounding error appears in many places, but the accuracy is especially reduced when subtracting a similar number (or subtracting a number whose absolute value is close and whose sign is opposite).
...
In the financial sector, even a small calculation error can be a big problem, so many things have been devised.
Error but digit loss will only result in addition and subtraction.
It is only when the absolute value of a±b is many digits closer to zero than the absolute value of a and b.
So, for example, if c,m,d1,d2 above are all positive, none of the three above will result in digits.
For this expression only,
c is supposed to be divided by c+1 and when calculating this c+1 you must align the digits, that is, the floating-point exponents, and the valid digits are lost.
The farther away c is from 1, the less significant the effective digits are.
It's not a good expression for computing on a computer.If you have another solution, why don't you try it?
If you don't need a strict warranty, you can change the formula
Consider reducing the number of .
Understanding How Deforming an Expression Can Reduce Errors
Which operator is less likely to cause calculation errors?
The formula transformation used in "common sense of numerical calculation" is done by intentionally transforming a variable called error compensation (compensating errors) to appear more than once.
Therefore, it is more difficult to make errors in more conditions than in less conditions.
Finally, if you choose one of the examples, c appears twice and d2 appears three times.
doublex=(2.0*c*d2*m+d1*d2+1.0)/(2.0*c+2.0)*d2);
Is the error due to division and multiplication large?
Is the error due to addition and subtraction large?
I can't tell which one is larger, but you can usually estimate the relative error in division and multiplication by adding up the absolute error in addition and subtraction.
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
624 Uncaught (inpromise) Error on Electron: An object could not be cloned
577 Who developed the "avformat-59.dll" that comes with FFmpeg?
574 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.