SlideShare uma empresa Scribd logo
1 de 30
Pythonic Mathematics Kirby Urner EuroPython 2005 Göteborg, Sweden
Principal Themes ,[object Object],[object Object],[object Object],[object Object]
Math Through Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Math Through Storytelling © USPS
Beyond Flatland
Curriculum as Network: Typical Urner-style graph of inter- connecting topics
OO, Functions, More OO ,[object Object],[object Object]
From a class for home schoolers, taught by me @ Free Geek in PDX See:  http://www.4dsolutions.net/ocn/pygeom.html
OO & Data Structures ,[object Object],[object Object],[object Object],[object Object],[object Object]
New Hybrid: CS + Mathematics ,[object Object],[object Object],[object Object],[object Object],[object Object]
Python plays well with others The prospect of getting to do computer graphics is a motivational incentive to tackle “the hard stuff.”  The promise:  we’ll take you somewhere fun.
Types of Graphics with sample apps & libraries From presentation given at OSCON in 2004. See: http://www.4dsolutions.net/oscon2004/ POV-Ray VPython PyOpenGL POV-Ray Tk wxWidgets PyGame PIL Spatial Flat Still Moving
Python + POV-Ray
Jython + POV-Ray + QuickHull3D
Python + VRML + Qhull
Python + PIL http://www.4dsolutions.net/ocn/fractals.html
Python + Tk Cellular Automata ala Wolfram generated using graphics.py by John Zelle
Python + VPython
Functions and Figurate Numbers def   tri (n):  return  n * (n + 1) // 2 >>>  [tri(x)  for  x  in   range (1, 10)] [1, 3, 6, 10, 15, 21, 28, 36, 45] Front cover: The Book of Numbers by Conway & Guy
Sequence Generators >>>   def  tritet():   term = trinum = tetranum = 1   while   True :   yield  (term, trinum, tetranum)   term += 1   trinum += term   tetranum += trinum   >>>  gen = tritet() >>>  [gen.next()  for  i  in   range (6)] [(1, 1, 1), (2, 3, 4), (3, 6, 10),  (4, 10, 20), (5, 15, 35), (6, 21, 56)] from  Synergetics by RBF w/ EJA
Polyhedral Numbers Animation:  growing cuboctahedron >>>  gen = cubocta() >>>  [gen.next()  for  i  in   range (6)] [(1, 1, 1), (2, 12, 13), (3, 42, 55),  (4, 92, 147), (5, 162, 309), (6, 252, 561)]
Cubocta Shell = Icosa Shell def   cubocta (): freq = shell = cubonum = 1 while   True : yield  (freq, shell, cubonum) shell = 10 * freq**2 + 2 cubonum += shell freq += 1 From Synergetics Java +  POV-Ray
Pascal’s Triangle def   pascal (): row = [1] while  True :   yield  row   this = [0] + row   next = row + [0]   row = [a+b  for  a,b  in  zip(this, next)] >>>  gen = pascal() >>>  gen.next() [1] >>>  gen.next() [1, 1] >>>  gen.next() [1, 2, 1]
Fermat’s Little Theorem def   gcd (a,b): """Euclidean Algorithm""" while  b: a, b = b, a % b return  abs(a) if  isprime(p)  and  gcd(b,p) == 1: try: assert  pow(b, p - 1, p) == 1 except: raise  Exception,   'Houston, we’ve got a problem.'
Euler’s Theorem def   tots (n):  return  [i  for  i  in   range (1,n)  if  gcd(i, n)==1] def   phi (n): return len(tots(n)) if  gcd(b,n) == 1: try: assert  pow(b, phi(n), n) == 1 except: raise  Exception,  'Houston, we’ve got a problem.'
RSA def   demo (): """ Abbreviated from more complete version at:  http://www.4dsolutions.net/satacad/sa6299/rsa.py """ plaintext =  "hello world" m = txt2n(plaintext) p,q = getf(20), getf(20)  # two big primes N = p*q phiN = (p-1)*(q-1) e = 3 s,t,g = eea(e, phiN)  # Extended Euclidean Algorithm d = s % phiN c = encrypt(m,N)  # pow(m, e, N) w/ booster newm = decrypt(c,d,N)  # pow(c, e*d, N) plaintext = n2txt(newm) return  plaintext
Math Objects: grab from the library  and/or build your own >>>  mypoly = Poly([ (7,0), (2,1), (3,3), (-4,10) ] ) >>>  mypoly (7) + (2*x) + (3*x**3) + (-4*x**10) >>>  int1, int2 = M(3, 12), M(5, 12)  # used in crypto >>>  int1 * int2  # operator overloading 3 >>>  int1 – int2 10 >>>  tetra = rbf.Tetra() >>>  bigtetra = tetra * 3  # volume increases 27-fold >>>  bigtetra.render()
Example:  Build A Rational Number Type ,[object Object],def   cf2 (terms): """ Recursive approach to continued fractions, returns Rat object >>> cf2([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) (4181/2584) >>> cf2([1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]) (665857/470832) >>> (665857./470832) 1.4142135623746899 """ if  len(terms)==1: return  terms.pop() else: return  Rat(terms.pop(0),1) + Rat(1, cf2(terms))
Conclusions ,[object Object],[object Object],[object Object],[object Object]
Thank You! And now… HyperToon demo + Q&A Presentations repository: http://www.4dsolutions.net/presentations/

Mais conteúdo relacionado

Mais procurados

The Elements of Machine Learning
The Elements of Machine LearningThe Elements of Machine Learning
The Elements of Machine LearningAlexander Jung
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviEnthought, Inc.
 
Recommendation System --Theory and Practice
Recommendation System --Theory and PracticeRecommendation System --Theory and Practice
Recommendation System --Theory and PracticeKimikazu Kato
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaDonghwi Cha
 
論文紹介 Fast imagetagging
論文紹介 Fast imagetagging論文紹介 Fast imagetagging
論文紹介 Fast imagetaggingTakashi Abe
 
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...Pooyan Jamshidi
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from..."PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...Edge AI and Vision Alliance
 
2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차Moonki Choi
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorchJun Young Park
 
TensorFlow In 10 Minutes | Deep Learning & TensorFlow | Edureka
TensorFlow In 10 Minutes | Deep Learning & TensorFlow | EdurekaTensorFlow In 10 Minutes | Deep Learning & TensorFlow | Edureka
TensorFlow In 10 Minutes | Deep Learning & TensorFlow | EdurekaEdureka!
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanWei-Yuan Chang
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpyFaraz Ahmed
 
Tokyo webmining 2017-10-28
Tokyo webmining 2017-10-28Tokyo webmining 2017-10-28
Tokyo webmining 2017-10-28Kimikazu Kato
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowAndrew Ferlitsch
 
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via RandomizationICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via RandomizationHidekazu Oiwa
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Namgee Lee
 

Mais procurados (19)

NumPy/SciPy Statistics
NumPy/SciPy StatisticsNumPy/SciPy Statistics
NumPy/SciPy Statistics
 
The Elements of Machine Learning
The Elements of Machine LearningThe Elements of Machine Learning
The Elements of Machine Learning
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
 
Ada boosting2
Ada boosting2Ada boosting2
Ada boosting2
 
Recommendation System --Theory and Practice
Recommendation System --Theory and PracticeRecommendation System --Theory and Practice
Recommendation System --Theory and Practice
 
Tensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi chaTensorflow in practice by Engineer - donghwi cha
Tensorflow in practice by Engineer - donghwi cha
 
論文紹介 Fast imagetagging
論文紹介 Fast imagetagging論文紹介 Fast imagetagging
論文紹介 Fast imagetagging
 
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
Ensembles of Many Diverse Weak Defenses can be Strong: Defending Deep Neural ...
 
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from..."PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
"PyTorch Deep Learning Framework: Status and Directions," a Presentation from...
 
2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차2020 1학기 정기스터디 1주차
2020 1학기 정기스터디 1주차
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorch
 
TensorFlow In 10 Minutes | Deep Learning & TensorFlow | Edureka
TensorFlow In 10 Minutes | Deep Learning & TensorFlow | EdurekaTensorFlow In 10 Minutes | Deep Learning & TensorFlow | Edureka
TensorFlow In 10 Minutes | Deep Learning & TensorFlow | Edureka
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
Tokyo webmining 2017-10-28
Tokyo webmining 2017-10-28Tokyo webmining 2017-10-28
Tokyo webmining 2017-10-28
 
Machine Learning - Introduction to Tensorflow
Machine Learning - Introduction to TensorflowMachine Learning - Introduction to Tensorflow
Machine Learning - Introduction to Tensorflow
 
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via RandomizationICML2013読み会 Large-Scale Learning with Less RAM via Randomization
ICML2013読み会 Large-Scale Learning with Less RAM via Randomization
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
 

Destaque

(Sin anotaciones) - En busca de la Física
(Sin anotaciones) - En busca de la Física(Sin anotaciones) - En busca de la Física
(Sin anotaciones) - En busca de la FísicaFernando Salamero
 
Programación de Videojuegos con Python y Pilas (III)
Programación de Videojuegos con Python y Pilas (III)Programación de Videojuegos con Python y Pilas (III)
Programación de Videojuegos con Python y Pilas (III)Fernando Salamero
 
Programación de Videojuegos con Python y Pilas (I)
Programación de Videojuegos con Python y Pilas (I)Programación de Videojuegos con Python y Pilas (I)
Programación de Videojuegos con Python y Pilas (I)Fernando Salamero
 
Programación de Videojuegos con Python y Pilas (II)
Programación de Videojuegos con Python y Pilas (II)Programación de Videojuegos con Python y Pilas (II)
Programación de Videojuegos con Python y Pilas (II)Fernando Salamero
 
Programación con Pygame VIII
Programación con Pygame VIIIProgramación con Pygame VIII
Programación con Pygame VIIIFernando Salamero
 
Programación con Pygame III
Programación con Pygame IIIProgramación con Pygame III
Programación con Pygame IIIFernando Salamero
 
Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014
Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014
Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014Fernando Salamero
 
Curso Programacion de Juego Introducion IA
Curso Programacion de Juego Introducion IACurso Programacion de Juego Introducion IA
Curso Programacion de Juego Introducion IARicardo Daniel Quiroga
 
Programación de Videojuegos con Python y Pilas (VI)
Programación de Videojuegos con Python y Pilas (VI)Programación de Videojuegos con Python y Pilas (VI)
Programación de Videojuegos con Python y Pilas (VI)Fernando Salamero
 

Destaque (18)

(Sin anotaciones) - En busca de la Física
(Sin anotaciones) - En busca de la Física(Sin anotaciones) - En busca de la Física
(Sin anotaciones) - En busca de la Física
 
Programación de Videojuegos con Python y Pilas (III)
Programación de Videojuegos con Python y Pilas (III)Programación de Videojuegos con Python y Pilas (III)
Programación de Videojuegos con Python y Pilas (III)
 
Programación de Videojuegos con Python y Pilas (I)
Programación de Videojuegos con Python y Pilas (I)Programación de Videojuegos con Python y Pilas (I)
Programación de Videojuegos con Python y Pilas (I)
 
Programación de Videojuegos con Python y Pilas (II)
Programación de Videojuegos con Python y Pilas (II)Programación de Videojuegos con Python y Pilas (II)
Programación de Videojuegos con Python y Pilas (II)
 
Python básico II
Python básico IIPython básico II
Python básico II
 
Intro Pygame Capitulo 6
Intro Pygame Capitulo 6Intro Pygame Capitulo 6
Intro Pygame Capitulo 6
 
Programación con Pygame VIII
Programación con Pygame VIIIProgramación con Pygame VIII
Programación con Pygame VIII
 
Programación con Pygame III
Programación con Pygame IIIProgramación con Pygame III
Programación con Pygame III
 
Intro PyGame Capitulo 0
Intro PyGame Capitulo 0Intro PyGame Capitulo 0
Intro PyGame Capitulo 0
 
Intro PyGame Capitulo 1
Intro PyGame Capitulo 1Intro PyGame Capitulo 1
Intro PyGame Capitulo 1
 
Programación con Pygame IV
Programación con Pygame IVProgramación con Pygame IV
Programación con Pygame IV
 
Programación con Pygame IX
Programación con Pygame IXProgramación con Pygame IX
Programación con Pygame IX
 
Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014
Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014
Taller de Pilas Engine, un motor de juegos en Python - PyConES 2014
 
Curso Programacion de Juego Introducion IA
Curso Programacion de Juego Introducion IACurso Programacion de Juego Introducion IA
Curso Programacion de Juego Introducion IA
 
Intro PyGame Capitulo 5
Intro PyGame Capitulo 5Intro PyGame Capitulo 5
Intro PyGame Capitulo 5
 
Iniciación a python
Iniciación a pythonIniciación a python
Iniciación a python
 
Programación de Videojuegos con Python y Pilas (VI)
Programación de Videojuegos con Python y Pilas (VI)Programación de Videojuegos con Python y Pilas (VI)
Programación de Videojuegos con Python y Pilas (VI)
 
Programación con Pygame I
Programación con Pygame IProgramación con Pygame I
Programación con Pygame I
 

Semelhante a Pythonic Math

Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysisDr. Rajdeep Chatterjee
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonPython Ireland
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
Machine Learning With R
Machine Learning With RMachine Learning With R
Machine Learning With RDavid Chiu
 
PyCon 2011 talk - ngram assembly with Bloom filters
PyCon 2011 talk - ngram assembly with Bloom filtersPyCon 2011 talk - ngram assembly with Bloom filters
PyCon 2011 talk - ngram assembly with Bloom filtersc.titus.brown
 
Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)c.titus.brown
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to ErlangGabriele Lana
 
Intelligent Ruby + Machine Learning
Intelligent Ruby + Machine LearningIntelligent Ruby + Machine Learning
Intelligent Ruby + Machine LearningIlya Grigorik
 
Python Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all departmentPython Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all departmentNazeer Wahab
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingEelco Visser
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxAbhishek Tirkey
 

Semelhante a Pythonic Math (20)

C#, What Is Next?
C#, What Is Next?C#, What Is Next?
C#, What Is Next?
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Object Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in PythonObject Orientation vs. Functional Programming in Python
Object Orientation vs. Functional Programming in Python
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Function Approx2009
Function Approx2009Function Approx2009
Function Approx2009
 
Machine Learning With R
Machine Learning With RMachine Learning With R
Machine Learning With R
 
Matlab Nn Intro
Matlab Nn IntroMatlab Nn Intro
Matlab Nn Intro
 
PyCon 2011 talk - ngram assembly with Bloom filters
PyCon 2011 talk - ngram assembly with Bloom filtersPyCon 2011 talk - ngram assembly with Bloom filters
PyCon 2011 talk - ngram assembly with Bloom filters
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
 
Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)Pycon 2011 talk (may not be final, note)
Pycon 2011 talk (may not be final, note)
 
Writing Faster Python 3
Writing Faster Python 3Writing Faster Python 3
Writing Faster Python 3
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Intelligent Ruby + Machine Learning
Intelligent Ruby + Machine LearningIntelligent Ruby + Machine Learning
Intelligent Ruby + Machine Learning
 
Python Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all departmentPython Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all department
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Groovy
GroovyGroovy
Groovy
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
 

Pythonic Math

  • 1. Pythonic Mathematics Kirby Urner EuroPython 2005 Göteborg, Sweden
  • 2.
  • 3.
  • 6. Curriculum as Network: Typical Urner-style graph of inter- connecting topics
  • 7.
  • 8. From a class for home schoolers, taught by me @ Free Geek in PDX See: http://www.4dsolutions.net/ocn/pygeom.html
  • 9.
  • 10.
  • 11. Python plays well with others The prospect of getting to do computer graphics is a motivational incentive to tackle “the hard stuff.” The promise: we’ll take you somewhere fun.
  • 12. Types of Graphics with sample apps & libraries From presentation given at OSCON in 2004. See: http://www.4dsolutions.net/oscon2004/ POV-Ray VPython PyOpenGL POV-Ray Tk wxWidgets PyGame PIL Spatial Flat Still Moving
  • 14. Jython + POV-Ray + QuickHull3D
  • 15. Python + VRML + Qhull
  • 16. Python + PIL http://www.4dsolutions.net/ocn/fractals.html
  • 17. Python + Tk Cellular Automata ala Wolfram generated using graphics.py by John Zelle
  • 19. Functions and Figurate Numbers def tri (n): return n * (n + 1) // 2 >>> [tri(x) for x in range (1, 10)] [1, 3, 6, 10, 15, 21, 28, 36, 45] Front cover: The Book of Numbers by Conway & Guy
  • 20. Sequence Generators >>> def tritet(): term = trinum = tetranum = 1 while True : yield (term, trinum, tetranum) term += 1 trinum += term tetranum += trinum >>> gen = tritet() >>> [gen.next() for i in range (6)] [(1, 1, 1), (2, 3, 4), (3, 6, 10), (4, 10, 20), (5, 15, 35), (6, 21, 56)] from Synergetics by RBF w/ EJA
  • 21. Polyhedral Numbers Animation: growing cuboctahedron >>> gen = cubocta() >>> [gen.next() for i in range (6)] [(1, 1, 1), (2, 12, 13), (3, 42, 55), (4, 92, 147), (5, 162, 309), (6, 252, 561)]
  • 22. Cubocta Shell = Icosa Shell def cubocta (): freq = shell = cubonum = 1 while True : yield (freq, shell, cubonum) shell = 10 * freq**2 + 2 cubonum += shell freq += 1 From Synergetics Java + POV-Ray
  • 23. Pascal’s Triangle def pascal (): row = [1] while True : yield row this = [0] + row next = row + [0] row = [a+b for a,b in zip(this, next)] >>> gen = pascal() >>> gen.next() [1] >>> gen.next() [1, 1] >>> gen.next() [1, 2, 1]
  • 24. Fermat’s Little Theorem def gcd (a,b): """Euclidean Algorithm""" while b: a, b = b, a % b return abs(a) if isprime(p) and gcd(b,p) == 1: try: assert pow(b, p - 1, p) == 1 except: raise Exception, 'Houston, we’ve got a problem.'
  • 25. Euler’s Theorem def tots (n): return [i for i in range (1,n) if gcd(i, n)==1] def phi (n): return len(tots(n)) if gcd(b,n) == 1: try: assert pow(b, phi(n), n) == 1 except: raise Exception, 'Houston, we’ve got a problem.'
  • 26. RSA def demo (): """ Abbreviated from more complete version at: http://www.4dsolutions.net/satacad/sa6299/rsa.py """ plaintext = "hello world" m = txt2n(plaintext) p,q = getf(20), getf(20) # two big primes N = p*q phiN = (p-1)*(q-1) e = 3 s,t,g = eea(e, phiN) # Extended Euclidean Algorithm d = s % phiN c = encrypt(m,N) # pow(m, e, N) w/ booster newm = decrypt(c,d,N) # pow(c, e*d, N) plaintext = n2txt(newm) return plaintext
  • 27. Math Objects: grab from the library and/or build your own >>> mypoly = Poly([ (7,0), (2,1), (3,3), (-4,10) ] ) >>> mypoly (7) + (2*x) + (3*x**3) + (-4*x**10) >>> int1, int2 = M(3, 12), M(5, 12) # used in crypto >>> int1 * int2 # operator overloading 3 >>> int1 – int2 10 >>> tetra = rbf.Tetra() >>> bigtetra = tetra * 3 # volume increases 27-fold >>> bigtetra.render()
  • 28.
  • 29.
  • 30. Thank You! And now… HyperToon demo + Q&A Presentations repository: http://www.4dsolutions.net/presentations/