axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] Re: [Aldor-l] Functions and Expression trees


From: root
Subject: [Axiom-developer] Re: [Aldor-l] Functions and Expression trees
Date: Sat, 6 May 2006 09:14:01 -0400

> my current work involves converting aldor objects to and from OpenMath
> format, via. the ExpressionTree type (from the algebra lib.). I'm a bit
> stuck when it comes to function objects, I don't seem to be able to get a
> handle on anything, the signatures of the functions or the body of the
> function.
>
> It would be really nice to have an extree(f) function [...]

Within the Axiom interpreter it is possible to get this information
although it would take some knowledge of the inner workings of the
system. The key function is called pf2Sex (parse form to s-expression). 

(The input expression to pf2Sex below indicated by the "1>" is the
result of a novel research parser by Bill Burge. This parser, which
he called a "zipper" parser constructs a form which consists of the
input string and its symbols. Every symbol in the parse contains the
original input string, the position of the symbol in that string and
the parse of the string from that position. It is of the form

  type "inputstringobject" . position . parse

as in 

 -type     ((|id| (|posn| 
 -input      (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
               1 
               1 
               "strings")
 -position    . 4)) 
 -parse      . |Integer|))

This novel parsing method has never been documented. Bill Burge
used Axiom as a research platform for parsing methods.)

The output of pf2Sex (shown at "<1" below) contains the DEF
structure (which is Axiom's equivalent of lisp DEFUN) and
contains the symbols, the types, and the parsed expression.

Thus all of the information you could possibly want about an
expression exists and it would be possible to implement a
package in Axiom that would return the original expression, 
any part of its parse tree, and the final result of the parse.


It knows what the current line is:

(2) -> )lisp (trace |pf2Sex|)

Value = (|pf2Sex|)
(2) -> g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)


  1> (|pf2Sex| 
      (|Definition| 
       (|listOf| 
        (|Typed| 
         ((|id| (|posn| 
          (0 
          "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
          1 
          1 
          "strings") 
         . 0)) 
        . |g|)
          (|nothing|)))
        (|Lambda| 
         (|listOf| 
          (|Typed| 
           ((|id| (|posn| 
             (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
               1 
               1 
               "strings")
              . 2)) 
             . |a|)
           ((|id| (|posn| 
             (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
               1 
               1 
               "strings")
              . 4)) 
             . |Integer|))
          (|Typed| 
           ((|id| (|posn| 
             (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
               1 
               1 
               "strings") 
              . 12))
             . |b|)
           ((|id| (|posn| 
             (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
               1 
               1
               "strings") 
              . 14)) 
             . |Integer|)))
         ((|id| (|posn| 
           (0 
             "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
             1 
             1 
             "strings") 
            . 23)) 
           . |Integer|)
         (|Application| 
          ((|id| (|posn| 
           (0 
            "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
            1 
            1 
            "strings") 
           . 44)) 
          . +)
          (|Tuple| 
           (|listOf| 
            (|Application| 
             ((|id| (|posn| 
              (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                1 
                1 
                "strings") 
               . 38)) 
              . +)
             (|Tuple| 
              (|listOf| 
               ((|id| (|posn| 
                (0 
                 "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                 1 
                 1 
                 "strings") 
                . 36)) 
               . |a|)
               (|Application| 
                ((|id| (|posn| 
                 (0 
                  "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                  1 
                  1 
                  "strings") 
                 . 41)) 
                . *) 
                (|Tuple| 
                 (|listOf| 
                  ((|integer| (|posn| 
                   (0 
                    "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                    1 
                    1 
                    "strings") 
                   . 40)) 
                  . "4")
                  ((|id| (|posn| 
                   (0 
                    "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                    1 
                    1 
                    "strings") 
                   . 42)) 
                  . |b|)))))))
            (|Application| 
             ((|id| (|posn| 
              (0 
               "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
               1 
               1 
               "strings") 
              . 47)) 
             . *)
             (|Tuple| 
              (|listOf| 
               ((|id| (|posn| 
                (0 
                 "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                 1 
                 1 
                 "strings") 
                . 46)) 
               . |a|)
               ((|id| (|posn| 
                 (0 
                  "g(a:Integer,b:Integer):Integer == ( a + 4*b + a*b)" 
                  1 
                  1 
                  "strings") 
                 . 48)) 
                . |b|))))))))))

  <1 (|pf2Sex| 
       (DEF 
        (|g| |a| |b|) 
        (|Integer| |Integer| |Integer|) 
        (NIL NIL NIL) 
        (+ (+ |a| (* 4 |b|)) (* |a| |b|))))

   Function declaration g : (Integer,Integer) -> Integer has been added
      to workspace.
                                                                   Type: Void




reply via email to

[Prev in Thread] Current Thread [Next in Thread]