# Amzi! Prolog + Logic Server

## Embed Logic-Bases in C/C++, Java, the Web and more

## FREE Evaluation Edition

Try our Solaris Edition, version 4.1 (or check our web site, http://www.amzi.com to download the latest version).
Here are the installation instructions. Here is the software. Here is the license agreement. Here is the order form.

To unlock the software, enter these registration details (as described in the installation instructions):

User Name: | Demo User
Organization Name: | Sun Solutions CD
Serial Number: | APVSS-41001-T1JF0-01402
Unlock Code: | R4DH-1D1W-CLRP-MXRM

This Unlock Code will expire on January 1, 2000. If you'd like your own 90-day unlock code, please download the Solaris Evaluation Edition from our web site, http://www.amzi.com

You can view articles, application stories and samples at our web site http://www.amzi.com
For additional information, please contact us at info@amzi.com

Amzi! inc.
5861 Greentree Road
Lebanon, Ohio 45036 U.S.A.
+1 513 425 8050 phone
+1 513 425 8025 fax

Amzi!® Prolog + Logic Server™ makes it easy to integrate rule-based components with Solaris, Windows NT, 95/98, 3.x, DOS, Linux, and other applications (see list below).

### Rule-Based Components Technical support or sales advice with web pages, Configuration rules with installation procedures, Diagnostic rules for process control Integrity-checking rules with databases, Planning and evaluation rules with spreadsheets, Parsing rules for documents, Tuning rules with performance-sensitive applications, Advisory rules with help systems, Business rules with any commercial application.

Amzi! offers plug-in, rule-based services for C, C++, Java, Web Servers, Delphi, Visual Basic, PowerBuilder, Access, Excel and many other tools.

The integration is achieved through the Logic Server API which lets you access a logic-base of rules as easily as you access a database today. The result is a manageable and well-behaved interface that makes it possible to utilize rule-based programming everywhere it is needed (see diagram).

In addition to enabling embedded Prolog applications, the Logic Server API (LSAPI) also lets you extend Amzi! Prolog so Prolog predicates can access your data, calling your code and linking to your other libraries and interfaces.

Prolog components are written, tested and debugged using the Windows-based Interactive Development Environment (IDE) or the command-line tools under Solaris or Windows.

"I've been looking for a Prolog with this kind of API for years ... it is designed to work equally well both ways (embed-dable AND extendable), ... it is small yet seems very complete." Jonas Beckman, MU Data

## Embedding Logic Services

The Logic Server is implemented as a class, and the LSAPI is a collection of member functions for the class LogicServer. The LSAPI is also provided as a pure functional API. You access the Logic Server similar to a database. The LSAPI gives you the ability to load, query and update a Prolog logic-base of rules and data from C/C++ or Java on any supported platform, and, under Windows, from any tool that can call a DLL.

The code boxes (below) illustrate a simple rule-based system that asks the user for a sound, from which it identifies a pet. This same idea can be used to identify problems based on symptoms, tuning parameters based on system configuration, help based on user needs, etc.

The API has 50+ methods/functions that provide both high-level and detailed access to Prolog rules, terms and data. The high-level functions use intuitive string-mapping functions that simulate a Prolog listener (see code boxes below).

The detailed functions let you construct and/or decompose arbitrarily complex Prolog terms and lists. For example, this C code pops all of the elements off a Prolog list and prints them:

    while (lsPopList(e,&Lst,cSTR,S)==OK)
       printf("Popped %s\n", S);

### Calling the Logic Server
    The program examples below implement
    these steps:
       Initialize Logic Server
       Load Pets program
       Get sound from user
       Assert sound to logic-base
       Query pet(X) in logic-base
       Get the value of X
       Display results
       Close Logic Server
### . . . from C
    lsInit(&Eng, "");
    lsLoad(Eng, "pets");
    puts("What sound?");
    gets(Sound);
    lsAssertaStr(Eng,"sound(%s)",Sound);
    lsCallStr(Eng, &term, "pet(X)");
    lsGetArg(Eng, term, 1, cSTR. &Pet);
    printf("The pet is a %s\n", Pet);
    lsClose(Eng);
| ### PETS.PRO
    % 3 Prolog rules for
    % identifying pets based
    % on their sound

    pet(dog) :- sound(woof).
    pet(pig) :- sound(oink).
    pet(duck) :- sound(quack).
### . . . from Delphi
    ls.InitLS('');
    ls.LoadXPL('pets');
    Sound:=InputBox('','What sound?','');
    ls.AssertaPStr('sound('+ Sound +')');
    ls.CallPStr(t, 'pet(X)');
    Pet := ls.GetPStrArg(t, 1);
    ShowMessage('Pet is a ' + Pet);
    ls.Close;
| ### PETS in the Listener
    ?- consult(pets).
    yes
    ?- assert(sound(woof)).
    yes
    ?- pet(X).
    X = dog
### . . . from Visual Basic
    InitLS("")
    LoadLS("pets")
    Sound = InputBox$("What sound?")
    AssertaStrLS("sound(" + Sound + ")")
    tf = CallStrLS(Term, "pet(X)")
    Pet = GetStrArgLS(Term, 1)
    MsgBox "The pet is a " + Pet
    Call CloseLS
### . . . from Java
    ls.Init("");
    ls.Load("pets.xpl");
    Sound.append("sound('");
    System.out.println("What sound?");
    while ((c=System.in.read())!=-1)
        Sound.append((char) c);
    Sound.append("')");
    System.out.println(Sound.toString());
    ls.AssertaStr(Sound.toString());
    Term = ls.ExecStr("pet(X)");
    Pet = ls.GetStrArg(Term, 1);
    System.out.println("Pet is a ");
    System.out.println(Pet);
    ls.Close();

"I was convinced that Amzi!'s approach to interfacing Prolog with procedural languages was the right one ... a Prolog program is fundamentally closer to a database than it is to a sequential program. As such, the API presents an interface that is similar to database interfaces ... In my mind this is as intuitive as one can get in an interface to Prolog ... Amzi! moves you toward a unique view of its positioning in the Prolog market. It aims to be a component of an application written in other languages. ...Solid, commercial grade..ideal for embedding" PC AI Review, Sep/Oct 95

## Extending Prolog

The Logic Server API also makes it easy to implement custom extended predicates for Prolog. These are predicates of your own design that are implemented in a host language. Extended predicates look and behave exactly like the built-in predicates, such as read/1 and write/1, that are part of the core Prolog system.

For example, a tuning application might have its user interface implemented using C++ GUI, which loads and calls tuning rules written in Prolog. Those rules make their decisions based on the state of the machine which is determined by C functions that are called directly by the Prolog program.

Or, you might want your Prolog code to access a network server. You can use the Logic Server API to let Prolog directly access the network's API.

Extended predicates can be implemented in any language that supports the notion of call-back functions. Currently this means C/C++, Java, Delphi and Visual Basic 5(or later) can be used for implementing extended predicates.

"I've been using Amzi! Prolog with an extensive C/C++ interface and provisions for adding Prolog predicates using C(++) code. It's wonderful." Gregg Weismann, Manager of System Software Development, Xircom, Inc.

## Object Oriented Programming

The C++, Java and Delphi versions of the Logic Server API are delivered as class with the LSAPI functions implemented as member functions. This means you can use these classes to derive subclasses for your applications. Those subclasses would then encapsulate the services your application expects from the Prolog portion of the application, hiding the details of the Logic Server inside the class.

For example, the pet identification code example could be encapsulated in a C++ object as illustrated in the box below.

### Accessing a Prolog Logic- Base as a C++ Object
    // derive class from Prolog engine
    class CPets: public CLogicServer {
    public:
         Cpets();
         ~Cpets();
         void id(char *, char *);
    };

    // constructor initializes engine and loads rules
    CPets::CPets { Init(""); Load("pets");}

    // destructor frees Prolog resources
    CPets::~CPets { Close(); }

    // identify the pet
    void CPets::id(char* Sound,char* Pet)
    {
         char  buf[40];
         TERM  term;

         sprintf(buf, "sound(%s)", Sound);
         AssertaStr(buf);
         CallStr(&term, "pet(X)");
         GetArg(term, 1, cSTR, Pet);
    }

         // sample code to use CPets object
         ...
         CPets    aPet;
         cout<<"what sound?";
         cin >> Sound;
         aPet.id(Sound, Pet);
         cout<<"The pet is a "<<Pet;
         ...

## Performance

Performance is key in any application. Amzi! Prolog is a compiled Prolog, so the logic-base you access will usually be compiled. But, Amzi! is flexible as well, so you can intermix dynamically asserted (interpreted) code with the compiled code. In the PETS example (above) the rules are compiled and the sounds are asserted dynamically.

## Open Architecture

All Amzi!-written extensions to Prolog are implemented using the Logic Server API and come with full source. You can use the LSAPI to design and write your own extensions just as easily. You can add your own Prolog-database, Prolog-GUI, Prolog-communications, etc.

Your extensions can be packaged in a special type of dynamic library (DLL) called an LSX (Logic Server eXtension), or they can be part of your program. LSX's are provided as part of the product for the ODBC and Sockets API.

## Database Support

Another Amzi! extension allows Prolog logic-bases to reason over records from any ODBC database. This is a two-level interface, with one part implemented as an LSX that implements extended predicates that directly access ODBC services, and the other part implemented as a Prolog wrapper around the ODBC predicates that allows natural Prolog pattern-matching and backtracking to be used with an ODBC database. Since full source code is provided, the ODBC interface can be readily adapted to other relational databases.

## Internet Support

For building Internet applications, Amzi! includes these features:

- A Logic Server Extension for communicating with clients and servers (e.g. mail, ftp, http) via Sockets.
- A CGI interface that lets you write Prolog scripts that run on web servers. The WebLS product is built using this interface.
- The Java class (described above).

## Multiple Session Support

For building for the Internet, telephony, database and other server applications, you can invoke multiple, simultaneous instances of the Amzi! Logic Server (Prolog runtime). These instance can optionally run each in their own thread. This allows you to create an instance for each user or process accessing a server.

## Unicode Support

Internally, the Amzi! Logic Server is a pure Unicode implementation. Externally, it supports Unicode, ANSI and multi-byte applications. This means you can write Prolog source code using the Unicode character set, and call the Logic Server using Unicode strings.

## Memory Utilization

To work as a component, Prolog is both compact and well-behaved. To allow it to work well within other programming environments, Amzi! does its own memory management within larger chunks which are allocated and deallocated as you start and end the Prolog engine.

"Amzi! offers so much flexibility and, to all intents and purposes, allows mixing of numeric and symbolic computation in a way undreamt of a few short years ago. Well done!" Jim Morrison, Business Reasearch Associate, ZENECA Specialties

## Error Handling

Professional applications require robust error recovery. Amzi! is designed to recognize and come down gracefully in the case of errors. The host program can check for errors at API calls retrieving the error code, message, call stack, read buffer and other information. Programs can use catch/throw (in C++ and Prolog), exception handlers (in Delphi and Java) and a common procedure (in Visual Basic) to capture and report all errors and respond accordingly.

## Ease of Development

Amzi! lets you build your applications a module at a time because compiled and interpreted code can be intermixed in the same program. In fact, compiled and interpreted modules are 100% source compatible and require no changes to move from one to the other. This makes it easy to work on large multi-module applications, with working code compiled and code still under development interpreted.

To get you started quickly, the package includes the Adventure in Prolog tutorial and lots of samples including:

- Hello programs for C, C++, Java, Delphi, Visual Basic, etc.
- A multi-threaded Rubik's Cube Solver.
- Clocksin & Mellish's Predicate Calculus to Prolog translator (using actual symbols for 'exists', etc.)
- A simple Japanese to English translator.
- A genealogical database implemented with ODBC.
- An information request form for a web server.

"Combining Visual Basic and the Logic Server lets you create programs that harness the power of Prolog while Visual Basic does all the work of maintaining the interface ... creating and debugging your Prolog programs is a piece of cake ... Since Amzi!'s version is a standard implementation of Prolog, it works right out of the box with most Prolog code." VB Tech Journal Review, Sept 95

## Development Tools

Amzi! provides the classic Prolog command-line tools for all supported environments, and a full Interactive Developer's Environment (IDE) under Windows that integrates a code editor, listener, debugger, compiler, linker and runtime engine in one intuitive GUI environment (see screen shot below). The IDE supports Prolog Projects that make developing Prolog components

### Amzi! Tools Windows-based Interactive Development Environment (IDE). Full on-line documentation. Standard ?- Listener extended to run both compiled and interpreted code. Compiler. Linker. Box-Model Debugger (as defined by Clocksin & Mellish). Definite Clause Grammar (DCG) support for natural language work). Dynamic (DLL, SO format) Logic Server API Libraries (approximately 350kb code size).

### Prolog Technical Specs `Module' capability for reusable code and `hidden' predicates to prevent name collisions across files. String, floating point, stream i/o and random access binary file support. Full control over the sizes of all heaps, stacks and various other dynamically allocated items. User-extensible error handling. Database references for quicker access to terms. Last call optimization (a more general form of `tail recursion' elimination). First argument indexing for more efficient predicate access. Automatic garbage collection of heaps, stacks and string space for more efficient use of memory.

## Portability

Prolog source and object code developed on one platform will run on any other runtime or API platform (without recompiling or relinking). This is because the Amzi! Logic Server is implemented with a virtual machine architecture similar to Java called a WAM. The Amzi! compiler and linker create binary byte-code files that can be executed by any implemention of the Logic Server.

## Distribution

Amzi! is royalty free.

## Environments & Packaging

Amzi! Prolog + Logic Server 4.0 is a 32-bit only release and runs under Windows '95, NT and Solaris. (Contact us for other platforms). The product includes full HTML documentation, lots of samples, plus the tutorial text, Adventure in Prolog.

Version 4.0 also includes version 3.4. Version 3.4 is for developers who need to develop 16-bit applications or compatible 16 and 32-bit applications under 3.x, `95, NT 3.5x, DOS 3.x (or later). Version 3.4 does not support multiple Logic Server sessions, Unicode or catch/throw error handling.

Amzi! Prolog + Logic Server comes in 2 editions:

Professional Edition
  This includes all of the tools and libraries, and has a unlimited, royalty-free license to distribute applications.
Personal Edition (Windows, Linux only)
  This is the same as the Professional Edition, but does not allow the distribution of applications for commercial, trade or government purposes (and has a small reminder screen to this effect).

Jolt Productivity Award for Components and Libraries "Decision-making software is found in domains from securities trading to air traffic control, where choices are made based on complicated conditions, often in real time. Rule-based systems are a common solution to these types of problems. One of the best languages for creating rule-based applications has always been Prolog. However, in the past it's been difficult to create full-blown applications using it. Amzi! inc. has a solution in the Amzi! Logic Server, an embeddable Prolog rule-base and inference engine that is accessible from C++, Java, Visual Basic, Smalltalk, and other tools. With its Edinburgh-standard implementation of Prolog and cross-platform, royalty-free runtimes, the Amzi! Logic Server should make rule-based programing accessible to anyone who feels the need to make smarter software." Software Development, June 1997

## Subscription Plus Service

Amzi! Prolog is constantly evolving to keep pace with new environments and customer requirements. You can get the latest software as soon as its available with the Subscription Plus service. It provides you with automatic updates for a full year including all program and documentation updates plus beta test releases.

"Contact Amzi! Their Prolog products are `with-it'" from the comp.lang.prolog newsgroup