POPCORN for OpenMath

Introduction

This is slightly outdated, for a detailed overview see The Popcorn OpenMath Representation.

Whenever you come to manually typing OpenMath (which appears to happen rather frequently in the SCIEnce-Project), it’s rather annoying. On the other hand, there is a widly used kind of syntax for mathematical expressions known from computer-algebra-systems as Maple or MuPAD. The idea of popcorn is to use a derivation of this intuitive syntax and write a converter that creates Openmath from it.
So, e.g., POPCORN translates 1+#a to

<OMA><OMS cd="arith1" name="plus" /><OMI>1</OMI><OMV name="a" /></OMA>

 

transforming something small into something huge — which partly motivates the name. On the other Hand, POPCORN is an acronym for Possibly Only Practicable Convenient OpenMath Replacement Notation.

Important Information

POPCORN is by no means meant to replace OpenMath — it merely offers the possibility to type-the-way-you-think and get syntactically valid OpenMath with the desired meaning. So, it is mainly a rewrite-engine.

Syntax

  • OMI and OMF — Integers and Floats: For integers and floats, POPCORN uses the naive syntax: simply type them: 
    POPCORN OpenMath
    13 <OMI>13</OMI>
    1.234e10 <OMF dec=”1.234E10″ />
    (-2413) <OMI>-2413</OMI>
    (-1.234e-10) <OMF dec=”-1.234E10″ />

    Please note, that currently all negative numbers need to be paranthesized

  • OMSTR — Strings: Strings are encoded by putting them into ” or ‘, currently there is no support for escaping characters:
  • POPCORN OpenMath
    “HALLO” <OMSTR>HALLO</OMSTR>
    ‘Hello World!’ <OMSTR>Hello World!</OMSTR>
  • OMS — Symbols: for the symbols POPCORN uses a C-struct-accessor-inspired syntax: cdname.symbolname:
    POPCORN OpenMath
    arith1.plus <OMS cd=”arith1″ name=”plus” />
    stransc1.sin <OMS cd=”transc1″ name=”sin” />

    Please note, that POPCORN does not ensure, that the cd or the symbol exist in some CD.

  • OMV — Variables: for variables POPCORN uses the # prefix:
  • POPCORN OpenMath
    $X <OMR href=”X” />
    #FunnyVarName <OMV name=”FunnyVarName” />
  • OMR and id — References and id: to encode References, POPCORN uses the $-prefix, to actually set the id of some object, it uses a :id-postfix:
    POPCORN OpenMath
    13:X <OMI id=”X” >13</OMI>
    #X <OMV name=”X” />
    arith1.plus:reff <OMS cd=”arith1″ name=”plus” id=”reff” />
    $reff <OMV name=”reff” />

    Please note, that POPCORN does not validate the existence or uniqueness of references . Neither does it check for circular references.

  • OMA — Application: to encode the application of a symbol to some objects, POPCORN uses the usual f(x)-kind-of-syntax:
    POPCORN OpenMath
    transc1.sin(3.14) <OMA>
    <OMS cd=”transc1″ name=”sin” />
    <OMF dec=”3.14″ /&gt
    </OMA>
    arith1.plus(1,2) <OMA>
    <OMS cd=”arith1″ name=”plus” />
    <OMI>1</OMI>
    <OMI>2</OMI>
    </OMA>
  • OMBIND — Binding: to encode the binding, POPCORN uses the syntax: symbol[va1, ..., varn -> expr]:
    POPCORN OpenMath
    fns1.lambda[#x -> #x + 1] <OMBIND>
    <OMS cd=”fns1″ name=”lambda” />
    <OMBVAR>
    <OMV name=”x” />
    </OMBVAR>
    <OMA>
    <OMS cd=”arith1″ name=”plus” />
    <OMV name=”x” />
    <OMI>1</OMI>
    </OMA>
    </OMBIND>
    fns1.lambda[#x, #y -> #x*#y] <OMBIND>
    <OMS cd=”fns1″ name=”lambda” />
    <OMBVAR>
    <OMV name=”x” />
    <OMV name=”y” />
    </OMBVAR>
    <OMA>
    <OMS cd=”arith1″ name=”times” />
    <OMV name=”x” />
    <OMV name=”y” />
    </OMA>
    </OMBIND>
  • OMATTR — Attribution: to encode the attribution of some expressions, POPCORN uses the syntax: expr{k1 -> v1, ..., kn -> vn}:
    POPCORN OpenMath
    1{‘a’ -> 1} <OMATTR>
    <OMATP>
    <OMSTR>a</OMSTR>
    <OMI>1</OMI>
    </OMATP>
    <OMI>1</OMI>
    </OMATTR>
    (tr1.sin(3.14)){ann.appr -> 0} <OMATTR>
    <OMATP>
    <OMS cd=”ann” name=”appr” />
    <OMI>0</OMI>
    </OMATP>
    <OMA><OMS cd=”tr1″ name=”sin” />
    <OMF dec=”3.14″ /></OMA>
    </OMATTR>
  • Infix-Notation:
    For the assignment-operator :=, the relations <, >, <=, >=, !=, <>, =, and the operators +, -, *, /, ^ there is also an infix-notation available, that maps to the appropriate symbols. in prog1, relation1, and arith1 respectively (the usual operator precedence is used):

    POPCORN OpenMath
    1+2 <OMA><OMS cd=”arith1″ name=”plus” /><OMI>1</OMI><OMI>2</OMI></OMA>
    1<#a <OMA>
    <OMS cd=”relation1″ name=”lt” />
    <OMI>1</OMI>
    <OMV name=”a” />
    </OMA>
    #b := 2 <OMA>
    <OMS cd=”prog1″ name=”assign” />
    <OMV name=”b” />
    <OMI>2</OMI>
    </OMA>
  • Blocks: if you seperate different POPCORN-expressions by ;, they will be wrapped into an prog1.block:
    POPCORN OpenMath
    1+2;
    #a:=2;
    “hello”
    <OMA>
    <OMS cd=”prog1″ name=”block” />
    <OMA><
    OMS cd=”arith1″ name=”plus” />
    <OMI>1</OMI>
    <OMI>2</OMI>
    </OMA>
    <OMA>
    <OMS cd=”prog1″ name=”assign” />
    <OMV name=”a” />
    <OMI>2</OMI>
    </OMA>
    <OMSTR>hello</OMSTR>
    </OMA>
  • Syntactic sugar: if, while, procdef: This is easiest explained by examples:
    POPCORN OpenMath
    if #a <1 then
    “hello”
    else
    “bye”
    endif
    <OMA>
    <OMS cd=”prog1″ name=”if” />
    <OMA>
    <OMS cd=”relation1″ name=”lt” />
    <OMV name=”a” />
    <OMI>1</OMI>
    </OMA>
    <OMSTR>hello</OMSTR>
    <OMSTR>bye</OMSTR>
    </OMA>
    while #a<10 do
    #a := #a + 1
    endwhile
    <OMA>
    <OMS cd=”prog1″ name=”while” />
    <OMA><OMS cd=”relation1″ name=”lt” />
    <OMV name=”a” />
    <OMI>10</OMI>
    </OMA>
    <OMA><OMS cd=”prog1″ name=”assign” />
    <OMV name=”a” />
    <OMA>
    <OMS cd=”arith1″ name=”plus” />
    <OMV name=”a” />
    <OMI>1</OMI>
    </OMA>
    </OMA>
    </OMA>
    procdef #f(#x)
    local #y
    begin
    #y := #x
    endproc
    <OMA>
    <OMS cd=”prog1″ name=”procedure_definition” />
    <OMV name=”f” />
    <OMA>
    <OMS cd=”prog1″ name=”def_arguments” />
    <OMV name=”x” />
    </OMA><
    OMA>
    <OMS cd=”prog1″ name=”procedure_block” />
    <OMA>
    <OMS cd=”prog1″ name=”local_var” />
    <OMV name=”y” />
    </OMA>
    < OMA>
    <OMS cd=”prog1″ name=”assign” />
    <OMV name=”y” />
    <OMV name=”x” />
    </OMA>
    </OMA>
    </OMA>

Introduction

Download

The current version is available for download here as a jar. then you can get things like this:

# java -jar popcorn20080414.jar
Tester for POPCORN (Possibly Only Practicable Convenient OpenMath Replacement Notation)

Enter your POPCORN-Code and type Enter and EOF when done (in general, this is ^D):
>1=2:a+$a-#v/2*8-this.that[#r{animals1.dog->'woof', animals1.cow->'mooh'} -> funnnycd1.symboll(#r+1-#v)]+2
^D
OpenMath:
<OMA>
  <OMS cd="relation1" name="eq"/>
  <OMI>1</OMI>
  <OMA>
    <OMS cd="arith1" name="plus"/>
    <OMI id="a">2</OMI>
    <OMR href="a"/>
    <OMA>
      <OMS cd="arith1" name="unary_minus"/>
      <OMA>
        <OMS cd="arith1" name="times"/>
        <OMV name="v"/>
        <OMA>
          <OMS cd="arith2" name="inverse"/>
          <OMI>2</OMI>
        </OMA>
        <OMI>8</OMI>
      </OMA>
    </OMA>
    <OMA>
      <OMS cd="arith1" name="unary_minus"/>
      <OMBIND>
        <OMS cd="this" name="that"/>
        <OMBVAR>
          <OMATTR>
            <OMATP>
              <OMS cd="animals1" name="dog"/>
              <OMSTR>woof</OMSTR>
              <OMS cd="animals1" name="cow"/>
              <OMSTR>mooh</OMSTR>
            </OMATP>
            <OMV name="r"/>
          </OMATTR>
        </OMBVAR>
        <OMA>
          <OMS cd="funnnycd1" name="symboll"/>
          <OMA>
            <OMS cd="arith1" name="plus"/>
            <OMV name="r"/>
            <OMI>1</OMI>
            <OMA>
              <OMS cd="arith1" name="unary_minus"/>
              <OMV name="v"/>
            </OMA>
          </OMA>
        </OMA>
      </OMBIND>
    </OMA>
    <OMI>2</OMI>
  </OMA>
</OMA>

and off you go… ;) (the indentation was added later to make things clearer).

If you have any questions or concerns, don’t hesitate to contact me.