Presents some basic reasons computers do not give results that you would expect. Also, include some miscellaneous topics including Friday 13th, Fibonacci, Golden Ratio, Chaos, Founding Fathers and Math, Statistics, Music, Magic Squares.
8. dc & bc
●
dc – Desktop calculator
–
–
–
–
●
Stack based calculator for Unixes
dc was bc ( Before C ) and before bc
Arbitrary Precision
Integer arithmetic with decimal point shift
bc – basic/bench calculator
–
–
–
–
C like syntax
Originally piped through dc
'bc -l' adds math library and scale=20 digits
Sine, Cosine, Arctan, ln, exp, Bessel fcn
pde1d.blogspot.com
9. High Precision Libraries
GMP – Gnu Multiple Precision
● MPFR – Gnu Multiple Precision
floating-point with rounding
●
–
MPC – Complex numbers
DD, QD – 32 and 64 digit
accuracy
● PARI/GP – Algebra C library +
shell
●
pde1d.blogspot.com
10. Floating Point Numbers
●
EPSILON
–
Smallest number such that
1.0 + ϵ != 1.0
or, if δ<ϵ 1.0 + δ = 1.0
●
Floating Point numbers
–
IEEE 754 - 2008
●
●
–
–
FLT_EPSILON = 1.19209e-07
DBL_EPSILON = 2.22045e-16
CPU registers may use higher precision
Detailed definitions vary by factor of ~2
pde1d.blogspot.com
11. Precision Loss
●
Rapidly varying functions
o
arccos( 0.99999999984769129011 ) = 0.001
o
arccos( 0.99999999939076516049 ) = 0.002
th
Change in 10 place doubles result
● Subtraction of nearly equal numbers
3.14159292035xxx
3.14159265359xxx
0.00000026676xxx
12 place accuracy reduced to 5 places
pde1d.blogspot.com
12. Quadratic Formula
−b± √ b −4 a c
X=
2a
2
2
a X +b X +c=0
●
2
What if
b ≈ 4ac
√
or
2
2
b ≫ ∣4 a c∣ or b ≪ ∣4 a c∣
1
EPSILON ⇒ Loss of digits
2
pde1d.blogspot.com
13. Quadratic Equation Examples
Traditional and alternate solution formulations*
●
2
Enter a,b,c: 1 -2 0.9999999999999996
X = 1.00000002107342 , 0.999999978926576
Err: 0 , -1.11022e-16
Alt. sol. X = 1.00000002107342 , 0.999999978926576
Err: 0 , 0
2
Enter a,b,c: 1 -2000000 1
X = 1999999.9999995 , 5.00003807246685e-07
Err: -0.000240445 , -7.61449e-06
Alt. sol. X = 1999999.9999995 , 5.00000000000125e-07
Err: -0.000240445 , 0
b ≈ 4ac
b ≫ 4ac
2
b ≪ 4ac
Enter a,b,c: 10000 1 -10000
X = 0.99995000125 , -1.00005000125
Err: -1.81899e-12 , 0
Alt. sol. X = -1.00005000125 , 0.99995000125
Err: 0 , 0
*Acton, Forman S., “REAL Computing Made Real”,pp 5-6, Dover, 2005/ Princeton Press 1996
pde1d.blogspot.com
14. It's About Time
Not the 1966 TV show
● The value of time is inversely
proportional to the amount remaining
● Example, 50 times slower
●
–
–
●
1 millisecond computation
4 day computation
Some times for 500X500 grid
–
Python ~30 min, numpy ~30sec, f2py ~2 sec
“Numerical Computing with SAGE”, pg 18, Aug 15, 2013
pde1d.blogspot.com
15. Time Cost of Precision
Double(15) – baseline gotoBLAS
● DD(32) – 11 to 312 X
● QD(64) – 109 to 3060 X
● GMP(77) – 132 to 3700 X
● GMP(154) – 197 to 5900 X
● MPFR(154) – 405 to 11500 X
●
Times/speeds from MPACK
http://www.slideshare.net/NakataMaho/the-mpack-multiple-precision-version-of-blas-and-lapack
pde1d.blogspot.com
16. Pick 3 Digits Calculation
●
●
●
●
●
●
Pick 3 ordered digits ( 1 2 3 )
Enter twice ( 123123 )
Divide by 11
Divide by 7
Divide by original 3 digit number
- Result >bc -l
123123
last/11
last/7
last/123
>dc
123123
11 /
7/
123 /
p
pde1d.blogspot.com
17. Paraskevidekatriaphobia
th
Fear of Friday the 13
● Today is the first Friday the
Thirteenth of 2013
● In Thirteen weeks the next Friday
th
the 13
● Triskaidekaphobia
●
–
Fear of the number 13
pde1d.blogspot.com
18. 13
A prime number
● Is the smallest emirp
●
–
●
A happy number
–
●
12 + 32 = 10 → 12 + 02 = 1
Wilson prime ( 3 known – 5, 13, 563 )
–
●
31 and 13 are both prime
( (13-1)! + 1 ) % 132 = 0
A Fibonacci number
–
1 , 1, 2, 3, 5, 8, 13, 21, 34, …
pde1d.blogspot.com
19. What is the smartest
mammal ?
●
Rabbits
–
●
*
they can multiply very fast
Fibonacci
–
–
–
–
Leonardo Pisano Bigollo of Pisa
Illustrated rabbit breeding in 1202 “Liber Abaci”
F(n+1) = Fn + F(n-1) , F1 = 1 , F2 = 1
F(n+1) = number of possible arrangements of long
and short items
n
* http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibnat.html
pde1d.blogspot.com
20. Fibonacci Spiral
8
Chris 73 / Wikimedia Commons
13
1
2
1
5
Appears in Nature
- Sunflower seed spirals
Spiral with equal packing
- Sea Shells ( not csh )
3
pde1d.blogspot.com
21. Fibonacci &
Golden Ratio
a
F n+1
→ ϕ
F n n→∞
b
b
a+b
ϕ =
=
a
b
●
b
a
Beautiful
Proportion
φ, Phi symbol after Phidias
– Greek sculpture used and studied
pde1d.blogspot.com
22. Golden Ratio Uses
●
Penrose Tiles
–
–
Non-repeating pattern
Phi ratio of tiles
1
●
φ
1
Φ
2011 Nobel Prize
–
–
Quasicrystals
3D Non-repeating
Sir Roger Penrose
Solorflare100
Wikimedia Commons
1
2π
o
ϕ = 2 cos( 5 ) = 2 cos(72 ) = Φ
pde1d.blogspot.com
23. Calculating Golden Ratio
1
ϕ = 1+
1
1+
1
1+
1+. . .
ϕ =
Golde
n Mea
n
Divin
e P ro
portio
n
Gold
en Se
c ti o n
√1+ √1+ √ 1+ √ 1+ √1+...
1+ √ 5
ϕ =
2
Do you like stand-up comedians?
pde1d.blogspot.com
24. One Liners for Gloden Ratio
●
Continued fraction
–
–
●
Continued squareroot
–
–
●
echo “67k 1[dsb1r/1+pdlb!=c]dscxq” | dc
163 iterations
dc -e “67k1[dsb1+vpdlb!=c]dscxq”
133 iterations
Fibonacci
–
–
echo "67k1sa1d[sclardsa+dla/pdlc!=b]dsbx" | dc
163 iterations
pde1d.blogspot.com
25. Golden Ratio by dc
●
Equation - 67k5v1+2/p
Actions
67 Push '67'
Stack
67
k
Pop → set precision
5
Push '5'
5
v
Pop → Sqrt → Push
2.236...
1
Push '1'
1 ; 2.236...
+
Pop 2 → add → Push
3.236...
2
Push '2'
2 ; 3.236...
/
Pop 2 → divide → Push
1.618...
p
Pop → print → Push
1.618...
pde1d.blogspot.com
26. More dc
echo 67k5v1+2/dd*rd1r/[0]Ppsapsapq | dc
0.6180339887498948482045868343656381177203091798057628621354486227052
1.6180339887498948482045868343656381177203091798057628621354486227052
2.6180339887498948482045868343656381177203091798057628621354486227050
0.816033...6227052
1.816033...6227052
2.816033...6227050
1
ϕ = Φ = ϕ−1
2
ϕ = ϕ+1
pde1d.blogspot.com
28. Irrational Number Power
●
Can an irrational number to an
irrational power give a rational result ?
√(2) √(2)
(( √2) )
= 2
> python
>>> from decimal import *
>>> getcontext().prec=67
>>> s = Decimal(2).sqrt()
>>> print (s**s), "**", s
1.6325269194381528447734... ** 1.4142135623730950488016...
>>> print (s**s)**s
2.000000000000000000000000000000000000000000000000000
000000000000002
pde1d.blogspot.com
29. Chaos
●
Maxwell Smart's arch nemesis
–
●
●
Lorenz's Strange Attractor
Wikimedia commons
Butterfly effect
–
●
KAOS
Small initial difference yield a large impact
Non-periodic behavior
Example recurrence relations
–
Logistics equation
x n+1 = r x n (1−x n )
–
, 3.82843 < r ≤ 4 , 0 < x < 1
or
2
n
x n+1=x − 2
, −2 < x < 2
pde1d.blogspot.com
31. 2
n
Recurrence Relation x n+1 = x − 2
●
An infinite number of initial values
end with x = 2
–
x 0 = √ 2 , x 1=0 , x 2 =−2 , x 3=2 , x 4 =2 , . . .
2
n
x n+1 = x − 2
x=0
for( i=1; i<30; i++) {
x= sqrt(x+2)
print i, " ", x, "n"
x= - sqrt(x+2)
print i, " ", x, "n"
}
→
x n−1 = ± √ x n + 2
27 .6180339887498950...
27 -1.6180339887498949...
28 .6180339887498947...
28 -1.6180339887498948...
29 .6180339887498948...
29 -1.6180339887498948520...
±ϕ → Φ → −ϕ → Φ → −ϕ → . . .
pde1d.blogspot.com
32. ●
I know I am not
good at math,
but if I can get
95% of
problems right,
who cares
about the other
10%
pde1d.blogspot.com
33. Founding Fathers & Mathematics
●
Thomas Jefferson
–
Kept good numerical records
●
–
–
U.S. Currency
Mathematics to U.S. Universities
●
●
–
University of Virginia
West Point
Statistics to guide laws
●
–
Corrected Newton's Math
Limited duration laws ( 20 Yrs )
Concerning distribution of Representatives by state
●
Any law should “reduces the apportionment always
to an arithmetic operation, about which no two men
can ever possibly differ.”
Cohen, I.B.,”The Triumph of Numbers, How Counting Shaped Modern Life”,
W.W.Norton & Company, New York, 2005
pde1d.blogspot.com
34. Eliminate Soldier's Helmets ?
Britain almost stopped issuing steal
helmets in WW I
● generals began to call for their
removal as they increased incidences
of headwounds twelvefold and
doubled total casualties
● A fatality was not a casualty
●
http://tvtropes.org/pmwiki/pmwiki.php/Main/LiesDamnedLiesAndStatistics
pde1d.blogspot.com
35. Flue Shot ?
●
●
●
Based on three studies, getting
the flu shot
reduces chance of getting the flu by
5%
73% effective at preventing the flu
http://blog.minitab.com/blog/adventures-in-statistics/how-effective-are-flu-shots
pde1d.blogspot.com
36. Founding Fathers & Numbers
●
Benjamin Franklin
–
Inventor
●
●
●
–
Founder
●
●
●
–
–
–
Lightening Rod
Franklin Stove
Bifocals
Public Library
Fire Company
Police Service
Post Office
Electricity
Magic Squares
http://www.math.wichita.edu/~richardson/
pde1d.blogspot.com
37. Magic Squares
Sum of numbers in rows, columns
8 1 6
and diagonals are equal
3 5 7
● Unique number per cell
4 9 2
● Pattern for odd number squares
●
B
C
D
2
=H3+1
=B3+1
=C3+1
3
=H4+1
=B4+1
=C4+1
4
=H5+1
=B5+1
5
=H6+1
6
E
1
F
G
H
=E3+1
=F3+1
=G3+1
=D4+1
=E4+1
=F4+1
=H2+1
=D3+1
=D5+1
=E5+1
=F5+1
=G5+1
=B6+1
=C6+1
=D6+1
=E6+1
=G4+1
=G6+1
=H7+1
=C5+1
=C7+1
=D7+1
=E7+1
=F7+1
=G7+1
7
=H8+1
=B8+1
=C8+1
=D8+1
=F6+1
=F8+1
=G8+1
8
=B7+1
=B2+1
=C2+1
=D2+1
=E2+1
=F2+1
=G2+1
pde1d.blogspot.com
38. 11 X 11 Magic Square – by Spreadsheet
pde1d.blogspot.com
39. 4x4
Half Rows = Half Sum
–
–
Ben's Bent Diagonals
●
2056
http://www.math.wichita.edu/~richardson/
pde1d.blogspot.com
40. Music is About Fractions
●
Not just quarter
note, eight note
but tuning scales
1
Step =
2
12
√2
frequency ( A# )
12
= √ 2 ∗ frequency ( A )
●
Independent of
base note
1
Fraction Error
1.0595
1.1225 ≈ 9/8
-0.0023
1.1892 ≈ 6/5
-0.0091
1.2599 ≈ 5/4
0.0079
1.3348 ≈ 4/3
0.0011
1.4142 ≈ 7/5
0.0101
1.4983 ≈ 3/2
-0.0011
1.5874 ≈ 8/5
-0.0079
1.6818 ≈ 5/3
0.0090
1.7818 ≈ 7/4
0.0178
1.8877 ≈ 15/8
0.0068
2
pde1d.blogspot.com
42. A Golden Ratio Scale
FREQUENCY
STEP
1
8*Φ4
1
1.16718
1.167184
2*Φ
1.23607
1.059017
φ2/2
1.30902
1.059017
4*Φ2
1.52786
1.167184
φ
1.61803
1.059017
8*Φ3
1.88854
1.167184
2
1.059017
2
Fractions
within 1%
7
6
13
8
15
8
pde1d.blogspot.com
43. Golden Ratio Intervals
3
1.059017... = φ / 4
● 12
√2 = 1.059463... → 0.04%
● 4 each octave
●
4
1.167184... = 8*Φ
● Can be factored into 3 'half' steps
●
–
–
1.059017... * 1.059017... * 1.040719...
3 each octave
How many total intervals(steps) per octave ?
pde1d.blogspot.com