Skip to content

Releases: oplS15projects/Lambda

Final Code Turn-in

01 May 21:21

Choose a tag to compare

Lambda

ShuddaWuddaCdr

Authors

  • Brian Carlson
  • Joshua Caravetta
  • Norman Mutunga

Overview

The goal was to create a core mathematical engine that is simple, powerful and easy to build upon. Simple in terms that it allowed the user to enter their equation to evaluate in infix notation, along with English keywords to further define operations on the equation. The power of Lambda will comes from the ease at which the mathematical engine backend can be expanded on to add new functionality.

After demoing the project, we discovered that we effectively created our own language on top of Racket, where any user can add in their own keyword procedures with our backend abstraction. These procedures aren't limited to mathematical operations and can do anything the user wants. The argument of the keyword is simply a string and can be manipulated in almost anyway desirable.

Concepts Demonstrated

  • Abstraction - The backend uses a method of KeyPairs to create a database of keywords with a paired procedure. An abstraction barrier is made between the database and the user, so one can simply add a key and paired procedure to the database with add-keyword.
  • Lexical Parsing - exp-lexer uses lexical parsing tools, along with regex to tag input data strings. read-arith uses regex to re-organize infix notation equations into prefix notation equations. Finally, the main-parser uses the power of the exp-lexer to extract keywords and format equations for evaluation in the backend.
  • Key Procedures - These procedures were added and constructed with ease to read in mind. Each procedure is placed in its own racket source file, and included into the Keyword Definitions. The calls to these procedures in their KeyPair definitions are simple and abstracted from the low level source code.
  • GUI Strategies - The windowing toolbox is used to provide the basic building block for the frame which is a top level window ,textfields ,editor-canvas and pasteboard are all defined in the frame which is the parent. On this platform the Input textfield takes in expressions and hands them over to the abstracted main-parser in the backend. The solution is sent to the Output textfield if its just a text result, while graphical outputs are also sent to the canvas.

External Technology and Libraries

  • Plot - This library was used to create plots in Lambda's GUI canvas with use of the plot keyword.
  • GUI - This library was used to create Lambda's GUI.
  • Parser - This library was used to create the exp-lexer, that extracts and tags all data types from the user input string.

How to Download and Run

  1. Download the latest release .zip.
  2. Open and run Lambda.rkt.
  3. Input expression is typed into the Input, using syntax: keyword equation.
  4. Output is seen in the Output or lower canvas depending on keywords used.

Working keywords: eval, plot, deriv, simplify. All procedures only work with variable x.

  • eval - evaluation of basic equations with any combination of the following operators: -,+,/,*,^.
  • plot - makes a plot of basic equations with any combination of the following operators: -,+,/,*,^.
  • deriv - produces the derivative of a given equation. currently only works with operators: +,*,^.
  • simplify - simplifies the given equation. currently only works with operators: +,*.

As a heads up, there are many cases that simplify and deriv can be broken

Example Inputs

Example 1: eval

  • eval is the default keyword if no keyword is entered.
  • eval 1+2*3^4 or 1+2*3^4 will both evaluate to: 163.
  • If eval is used on an equation with a variable, such as x+2, it will return cannot evaluate: x+2 since there is a variable.

Example 2: plot

  • plot x^2+x+3
  • This will plot x+2*x+3 in the lower canvas field

Example 3: deriv

  • deriv 6*x + 30*x will output 36 .
  • deriv x + 2 will output 1 .

Example 4: simplify

  • simplify x+x+4 will output 2x+4 .

Adding Your Own Keyword

Here is where Lambda becomes its own language, where we can add our own keywords and procedures. To add your own keyword to Lambda simply:

  1. Open KeywordDefinitions.rkt in Procedures/.
  2. Scroll to the bottom of the file and insert (add-keyword 'your-keyword (lambda(x) _your-procedure-body_))
  3. The argument x to the lambda is in the form of a string. (It contains anything after the keyword from the Input field)
  4. The return type of the keyword procedure must be a string to be printed to the Output field of Lambda.

For example, during our demo, Roy asked how he could add his own keyword to Lambda. He wanted to implement increment as a keyword, so we quickly instantiated it in Lambda by adding the following to KeywordDefinitions.rkt.

(add-keyword `inc (lambda(x) 
                    (number->string (+ (string->number x) 1)))
             )

Now if when you run Lambda and input inc 10, you will get 11 in the output box. It is that simple!

Demo Release

27 Apr 13:25

Choose a tag to compare

Lambda Demo Release

How to Download and Run

  1. Download and unpack the .zip file
  2. Open and run Lambda.rkt
  3. Input expression is typed into the Input, using syntax: keyword equation
  4. Output is seen in the Output or lower canvas depending on keywords used.

Example 1: eval

  • eval is the default keyword if no keyword is entered.
  • eval 1+2*3^4 or 1+2*3^4 will both evaluate to: 163.
  • If eval is used on an equation with a variable, such as x+2, it will return cannot evaluate: x+2 since there is a variable.

Example 2: plot

  • plot x^2+x+3 - support for only one variable x is currently available.
  • This will plot x+2*x+3 in the lower canvas field

Example 3: deriv

  • deriv 6*x + 30*x will output 36 .
  • deriv of x + 2 will output 1 .

Milestone 2

22 Apr 03:03

Choose a tag to compare

Current Project Status:

  • Working frontend GUI with input and output fields.
  • Working general expression parser and infix->prefix parser that handles precedence.
  • High and Low level abstracted backend that forms a dynamic database of keys & pairs for additional procedures.
  • Evaluation of basic equations with any combination of the following operators: -,+,/,*.

In Progress/ Problems:

(Josh)
Current state of simplify:
I am running into issues of matching patterns. My current thought is to break out each postfix list into the larger list before performing any simplifications. This would allow for larger scale simplification. I am not sure if this method is going to work. We have also decided to limit the number of variables to one.

(Brian)
Current state of plot:
The syntax of (plot) requires a function as its first argument. Currently, the user's input is in the form of a string and there seems to be no way of forming it into a workable function for plot to take in. We have tried numerous 'hacks' or workarounds but they haven't worked thus far. There is no file/function currently implemented yet, but it has been attempted.
(norman)
Doing research on a suitable derivative function.

How to use Lambda:

  1. Run Lambda.rkt
  2. Type in any numeric equation into the Input field (only integers).
  3. Hit enter, and the evaluated result of the equation will be presented in the Output field.

(If a variable is seen in the input, Lambda will return it cannot currently evaluate the input.)

Example input:

Input: 1+2*4+5
Output: evaluated to: 14

Milestone 1

14 Apr 02:00

Choose a tag to compare

Milestone 1 Pre-release
Pre-release

We have the parser linked to the key pair.

Test this by using (main-parser exp)

example:

(main-parser "simplify x+2x+3")