Successfully reported this slideshow.
Upcoming SlideShare
×

# Basic Symbolic Computation in Perl

769 views

Published on

An introduction to basic symbolic computation concepts using Perl.

Published in: Engineering
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### Basic Symbolic Computation in Perl

1. 1. Symbolic Computation in Perl Mike Friedman (friedo) YAPC::NA 2015 Salt Lake City, UT @friedo
2. 2. Me: Mike Friedman (friedo) @friedo
3. 3. http://quire.com/ @quire
4. 4. The Problem:
5. 5. The Problem: We have computers.
6. 6. The Problem: We have computers. But they don't really compute.
7. 7. The Problem: We have computers. But they don't really compute.
8. 8. The Problem: We have computers. But they don't really compute. ==
9. 9. The Problem: Native number types in most programming languages (including Perl) are ints and floats.
10. 10. The Problem: Native number types in most programming languages (including Perl) are ints and floats. Because that's what the microprocessor can do.
11. 11. The Problem: What about rational numbers?
12. 12. The Problem: What about rational numbers?
13. 13. The Problem: What about rational numbers? These can only be approximated by ﬂoating point.
14. 14. The Problem: What about irrational numbers?
15. 15. The Problem: What about irrational numbers? Same problem.
16. 16. The Problem: What about imaginary and complex numbers?
17. 17. The Problem: What about imaginary and complex numbers? Floats can't even approximate these.
18. 18. The Solution: We do not want to calculate with numbers.
19. 19. The Solution: We do not want to calculate with numbers. We want to compute with symbols.
20. 20. The Solution: We do not want to calculate with numbers. We want to compute with symbols. We do that in software.
21. 21. The Solution: >
22. 22. Example 1 Rational numbers
25. 25. Example 1 For division, we must extend the integers.
26. 26. Example 1 For division, we must extend the integers.
27. 27. Example 1 We can think of them as ordered pairs.
28. 28. Example 1 Rational object as an ordered pair: Divide by greatest common factor \$f to put in lowest terms.
29. 29. Example 1 Convenience subs for a, b, c, d terms:
30. 30. Example 1 Arithmetic operators
31. 31. Example 1 Stringiﬁcation operator
32. 32. Example 1 Let's try it!
33. 33. Example 2 Complex numbers
34. 34. Example 2 Rational numbers We start with the real numbers.
35. 35. Example 2 Rational numbers We start with the real numbers.
36. 36. Example 2 Rational numbers We start with the real numbers.
37. 37. Example 2 To solve, we must extend the real numbers.
38. 38. Example 2 We can think of them as ordered pairs.
39. 39. Example 2 Complex object as an ordered pair:
40. 40. Example 2 Convenience subs for a, b, c, d terms: Remember these?
41. 41. Example 2 Arithmetic operators
42. 42. Example 2 Stringiﬁcation operator
43. 43. Example 2 Let's try it!
44. 44. Example 3 Linear equations
45. 45. Example 3 Linear equations standard form:
46. 46. Example 3 Linear equations standard form: solution:
47. 47. Example 3 We can think of them as ordered pairs.
48. 48. Example 3 Linear object as an ordered pair:
49. 49. Example 3 Solving algorithm That's it!
50. 50. Example 3 Let's try it!
51. 51. Example 3 What about Rationals? Changed integer 0 to Rational 0/1. Overloading handles the rest.
52. 52. Example 3 Let's try it!
53. 53. Example 4 Quadratic equations
54. 54. Example 4 Quadratic equations standard form:
55. 55. Example 4 Quadratic equations standard form: solution:
56. 56. Example 4 We can think of them as ordered triplets.
57. 57. Example 4 Quadratic object as an ordered triplet:
58. 58. Example 4 Solving algorithm
59. 59. Example 4 Let's try it! Now make it work with Complex objects!
60. 60. Example 4 Let's try it! Now make it work with Complex objects! (I'm too lazy.)
61. 61. Example 5 Polynomials
62. 62. Example 5 Polynomials standard form:
63. 63. Example 5 Polynomials
64. 64. Example 5 We can think of them as ordered tuples of size n+1, where n is the degree of the polynomial.
65. 65. Example 5 Polynomial object as an ordered tuple:
66. 66. Example 5 Addition operator:
67. 67. Example 5 Let's try it!
68. 68. Example 5 How about derivatives?
69. 69. Example 5 Derivative operator:
70. 70. Example 5 Let's try it!
71. 71. Conclusions 1. Figure out the rules for your thing.
72. 72. Conclusions Complex numbers extend the reals. They have self-consistent rules for arithmetic.
73. 73. Conclusions 2. Eliminate extraneous information.
74. 74. Conclusions Rationals are just pairs of integers. Complex are just pairs of reals. Fraction bars and i are just notation.
75. 75. Conclusions 3. Find a representation for your thing.
76. 76. Conclusions Ordered pairs, triplets, and tuples. For more interesting things, you'll use trees.
77. 77. Thanks! Symbolic Computation in Perl Mike Friedman (@friedo) github.com/friedo/perl-symbolic