Implementing a Feature With TDD

A few days ago, I heard somebody ask “How do I start developing a functionality with TDD?” and I thought immediately that it would be a good idea to write about it.

A History

Suppose you are really popular, with thousands of friends in the Facebook, everybody in your neighborhood knows you and enjoys your company. In fact everyone in your city does.

Continue reading “Implementing a Feature With TDD”

Grammars and Parsers

Let’s build a parser to math expressions. It’s better start the job in very a simple way: process addition expressions like ‘1 + 1’.

Well… As the old Chinese saying goes, “a journey of one thousand miles begins with one tiny step”.

A Little Bit About Parsers

According to Grune and Jacobs[1]:

“Parsing is the process of structuring a linear representation in accordance with a given grammar. [..] This ‘linear representation’ may be a sentence, a computer program, [..]  in short any linear sequence in which the preceding elements in some way restrict the next element”[1, p. 3].

Example of Parsing
Image via Wikipedia

“To a computer scientist ‘1 + 2 * 3’ is a sentence in the language of ‘arithmetics on single digits’ [..], its structure can be shown, for instance, by inserting parentheses: (1 + (2 * 3)) and its semantics [i.e. its meaning] is probably 7”[1, p. 7].

We use a parser to build an expression tree. This tree contains the elements of a sentence according with the structure of a given grammar and in the correct order (afterwards we will need an interpreter that uses the tree to extract the semantic of the sentence).

And in order to implement a parser, we have to:

Continue reading “Grammars and Parsers”

Developing an Interpreter to Math Expressions

Developing an Interpreter to Math Expressions
The support vote symbol redrawn in the SVG format.
Image via Wikipedia

We’ll start slowly, only dealing with the four binary basic operations: addition, subtraction, multiplication and division. Even though we defined a concise set of operations, I need to be even more humble in order to achieve our goals, and that’s why I’ll choose one of these operations to get started with the fun.

How about we begin with the addition operation? Sounds easy good to me. Doing that will lead the way to the remainder operations (I mean subtraction, multiplication and division operations). We can represent our math expression with a limited context-free grammar like this:

MathExp -> VariableExp | Constant | AddExp | '(' MathExp ')'
AddExp -> MathExp + MathExp
VariableExp -> a | b | ... | z
Constant -> 0 | 1 | ... | 9

Let’s write a test first (using JUnit 4): if an ordinary ‘a + b’ expression with ‘a = 2’ and ‘b = 4’ must be solved, one could think in the following API (specially if you read about the GoF Interpreter pattern):

Continue reading “Developing an Interpreter to Math Expressions”

Pteco – A Prototype of Modeling Tool

Pteco is a software intended for mathematical modeling. Anyone can use it or collaborate with its development.

The mathematical modeling objective is to understand, and even to foresee, system behaviors, being used in a broad spectrum of human knowledge areas, like physics, engineering, chemistry, biology, meteorology, administration, economy, and others.

Linear RegressionNon-linear Regression








This project is divided in two parts:

  • the core system, responsible for the execution of the mathematical algorithms;
  • the GUI (graphical user interface), that deals with data input from diverse sources and the output of modeling results.

This separation is important to allow the core system to be reused in others softwares, and to make possible the separation of interests: some people enjoy GUI development, while others prefer to research mathematical algorithms.

Currently, Pteco can do only linear and non-linear regression. Your development began at FATEC – JD.

An Example of Use

A company could use Pteco to try to find some relation between a product’s price and its market-share. The relationship between this two variables could indicate that sales increase when the product’s price decreases and vice-versa, providing valuable information to define the company’s marketing strategy.

The Future…

We plan to implement more algorithms for mathematical modeling in the core system, like Multiple Linear Regression, non-Linear Regression, Logistic Regression, Diffuse Logic, among others.

The GUI will provide charts, capacity to import/export data to spreadsheet softwares and it will count on more complete reports about the constructed mathematical models.

Involving Yourself

You can access the source code and start coding.