SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

February 24th, 2018, 4:26 pm

Is this a rant or does it have a point?

http://yosefk.com/c++fqa/defective.html
With all statements we should not only consider the contents, the author and the context in which the statements are applicable.

Interesting to note that lack of support for modules is not mentioned. 
Quite true! Every evaluator of a language views the language through the lens of their own experiences and requirements.

One can never be sure whether a bias for or against a language is self-serving or truthfully derived from the objective properties of the language. The causal arrow is omnidirectional.
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

March 8th, 2018, 4:38 pm

Let [$]F[$] be the set of files (in some format) and the mapping [$]f, g[$] be compression and encrypt operators from [$]F[$] onto [$]F[$], respectively. Is

[$]f^{2} = f[$]
[$]fg = gf[$]
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

March 8th, 2018, 4:58 pm

Let [$]F[$] be the set of files (in some format) and the mapping [$]f, g[$] be compression and encrypt operators from [$]F[$] onto [$]F[$], respectively. Is

[$]f^{2} = f[$]
[$]fg = gf[$]
Neither are true as can be seen with simple counterexamples.

If [$]f[$], for example, analyzes [$]F[$] for duplication of substrings, creates a table of high-frequency substrings, and rewrites [$]F[$] with compact substitutes for the duplicated substrings, then the output will consist of the substitution table and the rewritten files. Running [$]f[$] a second time might find no further compression opportunities in the rewritten strings but it might find them in substitution table that must accompany the rewritten files. Moreover, the substitution table for [$]f^{2}[$] will be different from the substitution table for [$]f[$]. Unless [$]f[$] does pre-check to see if [$]F[$] is really [$]f(F)[$], the output of the second [$]f[$] will be different from the first.

For any decent [$]g[$], [$]fg[$] will be a much larger object than [$]gf[$] because [$]g[$] will destroy the repetition of patterns in [$]F[$], creating an output with no structure to compress. (Note: there were some amusing examples of poorly designed [$]g[$] that if you ran them on an image, they would create a file that when displayed as an image showed a recognizable ghost of the original image.)
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 11th, 2018, 9:58 am

 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

April 11th, 2018, 3:02 pm

Interesting... It claims to avoid internal overflows.

So what does it return given hypot(0.7*LDBL_MAX.,0.7*LDBL_MAX)? (It should return about 0.98994949*LDBL_MAX)
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 11th, 2018, 4:18 pm

Interesting... It claims to avoid internal overflows.

So what does it return given hypot(0.7*LDBL_MAX.,0.7*LDBL_MAX)?  (It should return about 0.98994949*LDBL_MAX)
0.989949493661165 * LDBL_MAX
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

April 11th, 2018, 4:31 pm

Interesting... It claims to avoid internal overflows.

So what does it return given hypot(0.7*LDBL_MAX.,0.7*LDBL_MAX)?  (It should return about 0.98994949*LDBL_MAX)
0.989949493661165 * LDBL_MAX
Nice! (I wonder what trickery they use to compute the squared long double without overflow.)
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 11th, 2018, 4:57 pm

Interesting... It claims to avoid internal overflows.

So what does it return given hypot(0.7*LDBL_MAX.,0.7*LDBL_MAX)?  (It should return about 0.98994949*LDBL_MAX)
0.989949493661165 * LDBL_MAX
Nice!  (I wonder what trickery they use to compute the squared long double without overflow.)
Probably cunning stunts.

I only was informed of hypot yesterday.
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

April 11th, 2018, 8:30 pm

0.989949493661165 * LDBL_MAX
Nice!  (I wonder what trickery they use to compute the squared long double without overflow.)
Probably cunning stunts.

I only was informed of hypot yesterday.
That's fine. It's only a tangential development, what?
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 12th, 2018, 10:22 am

Nice!  (I wonder what trickery they use to compute the squared long double without overflow.)
Probably cunning stunts.

I only was informed of hypot yesterday.
That's fine.  It's only a tangential development, what?
BTW what triggered your original question? Where (which language) does it not work?
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

April 12th, 2018, 12:57 pm

Probably cunning stunts.

I only was informed of hypot yesterday.
That's fine.  It's only a tangential development, what?
BTW what triggered your original question? Where (which language) does it not work?
Well if you just use the plain-jane formula, squaring 0.7*LDBL_MAX blows up, no?
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 12th, 2018, 1:39 pm

That's fine.  It's only a tangential development, what?
BTW what triggered your original question? Where (which language) does it not work?
Well if you just use the plain-jane formula, squaring 0.7*LDBL_MAX blows up, no?
It gives INFINITY indeed. 
In the current case the 'intermediate' value blows up but the final outcome is finite. How do they do it?
// Pity C+11 did not go the whole hog and do a hypot in n-dimensional geometry.
 
User avatar
Traden4Alpha
Posts: 23951
Joined: September 20th, 2002, 8:30 pm

Re: C++ quiz - Maths and acccuracy

April 12th, 2018, 2:14 pm

BTW what triggered your original question? Where (which language) does it not work?
Well if you just use the plain-jane formula, squaring 0.7*LDBL_MAX blows up, no?
It gives INFINITY indeed. 
In the current case the 'intermediate' value blows up but the final outcome is finite. How do they do it?
// Pity C+11 did not go the whole hog and do a hypot in n-dimensional geometry.
One way to do would be to normalize the two values by the larger of the two:

c = MAX(ABS(a),ABS(b))

hypot = c*SQRT((a/c)^2 + (b/c)^2)

Of course the above code might fail if both a and b are denormal numbers (https://en.wikipedia.org/wiki/Denormal_number)
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 12th, 2018, 3:38 pm

I used complex [$]x^2 + y^2 = (x + iy)*(x-iy)[$] and it worked the option [$]sqrt(x+iy)*sqrt(x-iy)[$]. The other one  not.
 
User avatar
Cuchulainn
Topic Author
Posts: 59932
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Re: C++ quiz - Maths and acccuracy

April 13th, 2018, 8:55 am

Of course, std::hypot is too slow I reckon for graphics/CAD apps (sqrt?).In some case a cubic accuracy Taylor expansion will work.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On