Mathematics with Python and Ruby

Introduction

The languages Python and Ruby have the following in common:

  1. They are free software (i.e., The source code can be easily accessed, and the interpreter that we will use for each language is written in the language itself);
  2. They both support Object-Oriented Programming. (Python is actually Multi-Paradigm)
  3. They are distributed with lightweight interactive consoles (IDLE for Python, irb (interactive Ruby) for Ruby)

Therefore, it is worthwhile to explore these two languages to solve mathematical problems. In this book, we shall enumerate what they bring to the teaching of mathematics and algorithms. In particular, we will study how certain mathematical structures are managed by these two languages.

Note:
Some features of Python 3.2 will be used here (for example, the fact that division is exact by default and not integer division, the presence of print, the fact that the fraction object is available in Python 3.2...).

Two methods have been used to write the Python scripts below:

  1. Run the code directly in the interactive IDLE console, which is itself written in Python;
  2. Create a script file test.py, and run that from the console using python test.py or python3.2 test.py, as the context requires.


For Ruby, version 1.9.1 will be used. Here too, two methods have been used:

  1. Run the code in the interpreter irb (Interactive Ruby) which is itself written in Ruby, so its source code is human-readable;
  2. Create a script file test.rb, and run it using the console command ruby test.rb.
  3. The FreeRide program is a lightweight, easy-to-use code editor that works well with Ruby. FreeRide can execute the Ruby program in the active window without having to leave the editor by simply clicking Run. One may prefer NetBeans for its more extensive feature set and integration with Java, but NetBeans requires more system resources. Both programs are available for Windows, Mac OS X, and Linux, and both can handle Ruby projects, which may include multiple (related) text files containing Ruby programs. Anyway, for this book, geany has been used, mainly because it handles both Python and Ruby (amongst many others), and is rather lightweight.

Note:
Even though this feature has not been used here, there are online interpreters for both Ruby and Python, so you can do Python or Ruby programming in a web browser without having to install any additional software. The online interpreter for Ruby can be accessed by following the link: . To see an equivalent for Python, with some extensions for working with mathematical structures, see SAGE).

Mathematics with Python

Mathematics with Ruby

Category:Subject:Python programming language/all books Category:Subject:Computer programming languages/all books Category:Subject:Computer programming/all books Category:Subject:Computer science/all books Category:Subject:Computing/all books Category:Subject:Books by subject/all books Category:Subject:Computing/all books Category:Subject:Books by subject/all books Category:Subject:Ruby programming language#Mathematics%20with%20Python%20and%20Ruby Category:Subject:Ruby programming language/all books Category:Subject:Computer programming languages/all books Category:Subject:Computer programming/all books Category:Subject:Computer science/all books Category:Subject:Computing/all books Category:Subject:Books by subject/all books Category:Subject:Computing/all books Category:Subject:Books by subject/all books Category:Subject:Mathematics#Mathematics%20with%20Python%20and%20Ruby Category:Subject:Mathematics/all books Category:Subject:Books by subject/all books Category:Book:Mathematics with Python and Ruby#%20 Category:Book:Wikibooks Stacks/Books#Mathematics%20with%20Python%20and%20RubyCategory:Shelf:Python programming language Category:Shelf:Python programming language/all books Category:Shelf:Computer programming/all books#Computer%20programming Category:Shelf:Computer programming languages/all books#Computer%20programming%20languages Category:Shelf:Computer science/all books#Computer%20science Category:Department:Computing/all books#ComputingCategory:Shelf:Ruby programming language Category:Shelf:Ruby programming language/all books Category:Shelf:Computer programming/all books#Computer%20programming Category:Shelf:Computer programming languages/all books#Computer%20programming%20languages Category:Shelf:Computer science/all books#Computer%20science Category:Department:Computing/all books#ComputingCategory:Shelf:Mathematics Category:Shelf:Mathematics/all books Category:Department:Mathematics/all books#Mathematics Category:Alphabetical/M Category:Partly developed booksCategory:Books by completion status/all books
Category:Alphabetical/M Category:Book:Mathematics with Python and Ruby Category:Book:Wikibooks Stacks/Books Category:Books by completion status/all books Category:Department:Computing/all books Category:Department:Mathematics/all books Category:Partly developed books Category:Shelf:Computer programming/all books Category:Shelf:Computer programming languages/all books Category:Shelf:Computer science/all books Category:Shelf:Mathematics Category:Shelf:Mathematics/all books Category:Shelf:Python programming language Category:Shelf:Python programming language/all books Category:Shelf:Ruby programming language Category:Shelf:Ruby programming language/all books Category:Subject:Books by subject/all books Category:Subject:Computer programming/all books Category:Subject:Computer programming languages/all books Category:Subject:Computer science/all books Category:Subject:Computing/all books Category:Subject:Mathematics Category:Subject:Mathematics/all books Category:Subject:Python programming language Category:Subject:Python programming language/all books Category:Subject:Ruby programming language Category:Subject:Ruby programming language/all books