Mathematical expressions are input as they would be written in Prolog, which is similar to other programming language formats. These are valid Prolog mathematical expressions.
c = sqrt(a**2 + b**2) 2 * y / 4 * z apples + oranges / (pears + cherries)The only Prolog wrinkle is terms beginning with upper case letters must be quoted.
'X' **2 + 'Y' ** 2 = 'R' ** 2 'Speed' = 'Distance' / 'Time'Fun examples exercise the recursive aspects of the program.
tree = 1/1/1/1/1/1/1 sqrt( sqrt( sqrt( 2**2**2**2 )))Delphi is used for both the front and back ends of this application. On the front end it provides the user interface. On the back end it provides extensions to Prolog for drawing on the screen.
Amzi! is used for the heart of the application, taking the programmatic version of the mathematical expression and recursively breaking it down for display, computing the right position and size for each element of the expression, based on the other elements of the expression. For example, the line dividing two halfs of a fraction must be slightly longer than the larger of the numerator and denominator, and the numerator and denominator must be positioned above and below that line.
Application Architecture - Details on the implementation, including annotated source code.
www.amzi.com - Additional demos, articles, freeware, evaluation copies and information about Amzi! Prolog + Logic Server.
We welcome any and all comments about this demo. Contact us at www.amzi.com
If the mathematical equation is not a legal Prolog term, you will get an error indicating as much. Simply edit the expression and try again.
If you use an unquoted uppercase letter, you will get an error indicating as much.
User Interface - Delphi controls the form and Windows interface. It passes the mathematical expression to Prolog for generation of graphic display commands, and notifies Prolog when the Delphi canvas needs redrawing. These functions illustrate how Delphi communicates with an embedded Prolog logic base using the Amzi! Logic Server.
Delphi/Prolog Extensions for Graphics - It is easy to customize Amzi! Prolog with extended predicates written in other languages. In this example, graphics predicates are implemented as Delphi functions, giving Prolog the ability to directly draw on a Delphi canvas.
This Delphi unit implements a number of extended predicates that Prolog can use for graphic display. While simple mappings of Delphi are possible, as for example in the draw_lineto/3 predicate, Amzi! lets you implement predicates that behave as Prolog expects. For example, the draw_font/4 predicate either sets or retrieves font properties depending on whether the Prolog arguments are bound or not.
Prolog Logic for Layout - Prolog is used to generate a list of graphics commands for displaying a given mathematical expression. That list is executed whenever the canvas needs to be redrawn, which, of course, includes the first time the mathematical expression is entered.
The predicate grapheq/6 does all of the work. It generates a list of Prolog goals that, when executed, displays the equation in the Delphi paint box. The list of goals is saved in the Prolog dynamic database so it can be used again if the paint box needs repainting, for example when another window overlaps it and is then removed.
Copyright ©1996-2000 Amzi! inc. All Rights Reserved.