Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Symbolic Computation
in Perl
Mike Friedman
(friedo)
YAPC::NA 2015
Salt Lake City, UT
@friedo
Me:
Mike Friedman
(friedo)
@friedo
http://quire.com/
@quire
The Problem:
The Problem:
We have computers.
The Problem:
We have computers.
But they don't really compute.
The Problem:
We have computers.
But they don't really compute.
The Problem:
We have computers.
But they don't really compute.
==
The Problem:
Native number types in most programming languages
(including Perl)
are ints and floats.
The Problem:
Native number types in most programming languages
(including Perl)
are ints and floats.
Because that's what t...
The Problem:
What about rational numbers?
The Problem:
What about rational numbers?
The Problem:
What about rational numbers?
These can only be approximated
by floating point.
The Problem:
What about irrational numbers?
The Problem:
What about irrational numbers?
Same problem.
The Problem:
What about imaginary and complex numbers?
The Problem:
What about imaginary and complex numbers?
Floats can't even approximate these.
The Solution:
We do not want to calculate with numbers.
The Solution:
We do not want to calculate with numbers.
We want to compute with symbols.
The Solution:
We do not want to calculate with numbers.
We want to compute with symbols.
We do that in software.
The Solution:
>
Example 1
Rational numbers
Example 1
Rational numbers
We start with integers.
Example 1
Rational numbers
We start with integers.
Example 1
For division, we must extend the integers.
Example 1
For division, we must extend the integers.
Example 1
We can think of them as ordered pairs.
Example 1
Rational object as an ordered pair:
Divide by greatest common factor $f to put
in lowest terms.
Example 1
Convenience subs for a, b, c, d terms:
Example 1
Arithmetic operators
Example 1
Stringification operator
Example 1
Let's try it!
Example 2
Complex numbers
Example 2
Rational numbers
We start with the real numbers.
Example 2
Rational numbers
We start with the real numbers.
Example 2
Rational numbers
We start with the real numbers.
Example 2
To solve, we must extend the real numbers.
Example 2
We can think of them as ordered pairs.
Example 2
Complex object as an ordered pair:
Example 2
Convenience subs for a, b, c, d terms:
Remember these?
Example 2
Arithmetic operators
Example 2
Stringification operator
Example 2
Let's try it!
Example 3
Linear equations
Example 3
Linear equations
standard form:
Example 3
Linear equations
standard form:
solution:
Example 3
We can think of them as ordered pairs.
Example 3
Linear object as an ordered pair:
Example 3
Solving algorithm
That's it!
Example 3
Let's try it!
Example 3
What about Rationals?
Changed integer 0 to Rational 0/1.
Overloading handles the rest.
Example 3
Let's try it!
Example 4
Quadratic equations
Example 4
Quadratic equations
standard form:
Example 4
Quadratic equations
standard form:
solution:
Example 4
We can think of them as ordered triplets.
Example 4
Quadratic object as an ordered triplet:
Example 4
Solving algorithm
Example 4
Let's try it!
Now make it work with Complex objects!
Example 4
Let's try it!
Now make it work with Complex objects!
(I'm too lazy.)
Example 5
Polynomials
Example 5
Polynomials
standard form:
Example 5
Polynomials
Example 5
We can think of them as ordered tuples
of size n+1, where n is the degree of the
polynomial.
Example 5
Polynomial object as an ordered tuple:
Example 5
Addition operator:
Example 5
Let's try it!
Example 5
How about derivatives?
Example 5
Derivative operator:
Example 5
Let's try it!
Conclusions
1. Figure out the rules for your thing.
Conclusions
Complex numbers extend the reals.
They have self-consistent rules for
arithmetic.
Conclusions
2. Eliminate extraneous information.
Conclusions
Rationals are just pairs of integers.
Complex are just pairs of reals.
Fraction bars and i are just notation.
Conclusions
3. Find a representation for your thing.
Conclusions
Ordered pairs, triplets, and tuples.
For more interesting things, you'll use
trees.
Thanks!
Symbolic Computation
in Perl
Mike Friedman
(@friedo)
github.com/friedo/perl-symbolic
Upcoming SlideShare
Loading in …5
×

Basic Symbolic Computation in Perl

769 views

Published on

An introduction to basic symbolic computation concepts using Perl.

Published in: Engineering
  • 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 floating 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
  23. 23. Example 1 Rational numbers We start with integers.
  24. 24. Example 1 Rational numbers We start with integers.
  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 Stringification 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 Stringification 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

×