2.2. AML-DL Interpreter Command Set

2.2.1. Loading AML-DL command set

The functions and classes of the AML-DL Interpreter are defined in the module aml.amldl. They can be individually imported with the following commands:

from aml.amldl import(
    load_embedding,
    Descriptor,
    ADD, APP, C, CMP, CV, E, EXC, F, HEADER,
    INC, M, R, S, SOME, T, V
)

In this section, it is assumed that they are all imported into the main namespace with:

from aml.amldl import *

2.2.2. Embedding creation

Most functions need to be called from within a Python Context that represents an embedding. An embedding is an instance of the class Descriptor.

with Descriptor() as theEmbedding:
    ...

All examples below are assumed to be executed within such a Python Context. All duples are assigned the region of their embedding at the time they are created. The REGION property of the embedding can be modified at any point.

with Descriptor() as theEmbedding:
theEmbedding.REGION = 5

2.2.3. Constant creation

  • C(name)

    Defines a constant with the given name.

    C('Q')
    
  • CV(name, n)

    Defines a vector of constants with names: name[0], name[1], …, name[n-1].

    CV('Q', 10)
    
  • V([name])

    Defines an empty vector.

    V('Qx')
    APP(F('Qx'), V())
    

2.2.4. Duple creation

  • INC(left term, right term)

    Defines a positive duple \(l \leq h\). \(l\) and \(h\) cannot be duples.

    ADD(INC('U', 'B'))
    
  • EXC(left term, right term)

    Defines a negative duple \(l \nleq h\). \(l\) and \(h\) cannot be duples.

    ADD(EXC('Qx', 'Qy'))
    

2.2.4.1. Term creation and manipulation

  • APP(p, a)

    Appends \(a\) to \(p\), where \(p\) is of type vector. The vector \(p\) is modified in place.

    # Create a vector that contains two empty vectors
    V('Qx')
    APP(F('Qx'), V())
    APP(F('Qx'), V())
    
  • M(p_1, …, p_n)

    Returns \(a\) set containing the \(p_1\) to \(p_n\) elements. If any argument is of type \(tvector\), returns a descriptor of type \(tvector\) whose components are sets.

    M(Qx, Qy, B, U )
    
  • R(p, r)

    Removes \(r\) from the vector \(p\). If \(r\) is an integer, removes the \(r\)-th element of \(p\). Returns a new vector, and \(p\) is not modified.

    b = CV('black', 2)
    w = CV('white', 2)
    wb [0] = M(w, R(b, 0) ) # w [0], w [1], b [1]
    wb [1] = M(w, R(b, 1) ) # w [0], w [1], b [0]
    
  • CMP(p1, p2)

    Declares \(p1\) and \(p2\) as the logical negations of each other. Operates component-wise if \(p1\) and \(p2\) are vectors of the same length. No return value.

    CV('Q', 5)
    CV('E', 5)
    CMP('Q', 'E')
    
  • CMP(p)

    Finds or calculates the complementary of \(p\). Returns a copy of \(p\) where every element is substituted by its complementary.

    CV('Q', 5)
    CV('E', 5)
    CMP('Q', 'E')
    F('E') == CMP('Q')
    
  • T(p [,i])

    Associates an iterator to \(p\), where \(p\) cannot be a duple. The optional parameter \(i\) is an integer that identifies the iterator. Returns a \(tvector\).

    b = CV('black', 2)
    w = CV('white', 2)
    wb = M(w, R(b, T(b)))
    # wb.t[0] = M(w, R(b, 0)) = w[0], w[1], b[1]
    # wb.t[1] = M(w, R(b, 1)) = w[0], w[1], b[0]
    

2.2.4.2. Auxiliary commands

  • F(name [,i])

    Returns the descriptor associated with name. If \(i\) is given and \(p\) is a vector, return the \(i-th\) element of \(p\).

    CV('black', 5)
    b3 = F('black', 3)
    
  • SOME(p, prob [,atLeastOne, notAll]) Randomly chooses items from \(p\) with a probability \(prob\) per element. When set to True, the flags ensure that there is at least one element, and not all have been chosen, respectively. By default, they are set to False.

    CV('black', 5)
    SOME('black', 0.5)
    
  • HEADER(name)

    Guards a section of the embedding that should be read just once. Returns True the first time, False otherwise.

    if HEADER('black constants'):
        CV('black', 5)
    

2.2.4.3. Loading an embedding

The embedding can be wrapped in a function embedding that takes any number of input arguments, that can be used as parameters, and returns the embedding’s output.

def embedding ():
    with Descriptor() as theEmbedding:
        C('A')
        C('B')
        ADD(INC('A', 'B'))

        constantNames = [el.key for el in F(theEmbedding.PEND_TRANSF).r]
        p = F(theEmbedding.INCLUSIONS).r
        n = F(theEmbedding.EXCLUSIONS).r

    return (constantNames, p, n)

From a different script the embedding can be loaded using the load_embedding function.

from aml.amldl import load_embedding
(constantNames, p, n) = dl.load_embedding("path/to/embedding.py")