Ambi Calculator and Programming Language

I have created Ambi Calculator and Programming Language as a result of investigation about the possibility of a Reverse Polish Notation Language.

Ambi operates in both Reverse Polish Notation and Polish Notation for arithmetic expressions.

Ambi 0.4.0 is now released as an online Calculator and Programming Language.

Ambi Functions

Here are a couple of short examples of ambi functions. These may be copied and pasted into the Ambi Calculator. The first is a recursive implementation of Euclid’s algorithm for finding the Greatest Common Divisor:

 

function; gcd;
  // A B gcd ;
  // Euclid's algorithm ;
  ifelse ;
    import $b = import $a = $b 0 == ;
    $a export;
    $b $a $b % gcd export ;
  pass;

 

The second is an iterative function to check if a number is prime.

 

function ; isprime ;
  // N isprime ;
  // returns boolean;
  for ;
    import  $n = true  $isprime = 2 $i =;
    $isprime $i $n sqrt <=  and  ;
    $i ++ ;
    $n $i %  0 !=  $isprime =  ;
  $isprime export;

Ambi RPN Calculator Update and Chrome Extension

I have updated and released a new version of the Ambi RPN Calculator and programming language. Version 0.6.0 includes the following improvements …

  • Complete redesign of UI using browser local storage to preserve state across invocations.
  • Added ‘My Ambi Functions’ which are persistent. UI now auto recalculates as the expression is edited.
  • droppowexp, and inv operators
  • Added extensive error reporting.
  • Added a Virtual Keyboard
  • 9 short lessons on how to use ambi
Also, Ambi is now available in the Chrome Store.  There are two versions.  A full screen app and a popup extension.
David

Ambi Programming Language

Ambi is a programming language generalised from Reverse Polish Notation arithmetic and an extensible RPN Calculator hosted in the browser. I love RPN calculators and decided early in 2009 to try and build a fully programmable language as an extension of RPN. Check out the result – Ambi Programming Language.

Collatz Conjecture and Ambi

Here is the Ambi code to calculate the Collatz sequence including a demonstration for the largish number
99,999,999
.  To run this code simply copy and paste it into the wholly browser based Ambi implementation.


// Collatz Sequence Function;
function; collatz ;
 if;
  import dup $n = 1 neq;
  ifelse;
   $n 2 / floor $n 2 / dup $half = eq;
   $half . collatz export;
   $n 3 * 1 + . collatz export;
   ;
  ;
// Show sequence for a big number ;
99999999 collatz

After TABing or Clicking into the Result box, you should see the 169 term Collatz Sequence for this number (which I won’t bore you with here).

Ambi – streamlined – loses SEQ operator

Ambi is proving to be a great extensible RPN calculator. Applying the ‘zen’ of RPN to programming fun!

Enjoy the new release of Ambi.

This week I have discovered that the seq operator is not necessary.  Initially, I thought that seq would be necessary, however it turns out that the other lambda operators are sufficient.  So we now can write an interative approximator of cuberoot in this way …

function; root3;
  dowhile;
    import dup $n = $guess =;
    $guess $prev = $n $prev sq / $prev + .5 * $guess =;
    $guess $prev - abs .000000001 >;
    $guess export ;
125 root3 .

Not a seq in sight!   And we may rewrite the function as a recursive function this way …

function; inner-root3;
 if;
  import $n = import $prev = $prev $n $prev sq / + .5 * $guess = $guess $prev - abs .000000001 >;
  $guess $n inner-root3 $guess =;
  $guess export;

function; root3;
  import dup inner-root3 export ;

100 root3 .

In addition the current release adds the ++ and increment and decrement operators.

Ambi is now a RPN inspired programming language

Exactly how to generalise RPN calculation style into a programming language is a question that has fascinated me recently.  I am pleased to report that there now exists a programming language that is a natural extension of RPN — Ambi.

A factorial operator may now be defined in Ambi. A new version has been posted today. 

// Factorial Function;
function; ! ;
  seq ; import $n = ; 
  ifelse;
    $n 1 eq;
    1 export;
    $n 1 – ! $n * export;
// Use the function ;
5 ! .

Check it out!

Reverse Polish Notation Language

I love RPN calculators.  My favorite is Hypatia which I use regularly for calculations.  I love being able to order my calculation to avoid brackets and being able to enter a list of numbers and add them up with a single command:

hy 12 23.4 43 94 3 d SUM

Now I am wondering about a full computer language built from the ground up as an RPN language?

A bit of googling led me to RPL or Reverse Polish Lisp which is close.  I wonder if this direction has been explored in other languages.

I am imagining a language where assignment is pretty straight forward (with explanatory pseudocode comment):

1 a = # a = 1

boolean expressions are just regular RPN:

a 1 + b > # a + 1 > b

and an if control structure would look like:

; bf ; bt ; a if # if a then bt else bf;

the meaning of the “;” token is to push following tokens (until the next structural token) unevaluated onto the stack as a single entry.  The if token evaluates the top stack entry (a) and then evaluates either the second (bt) or the third (bf).

A do while loop would look like this:

; b ; a dowhile # do b while a;

The dowhile token evaluates the second stack entry (b) and then the first (a) and repeats until a is false.

A key of RPN expressions is that there are no brackets required – by analogy in a RPN language there would be no nested statements!

Open question.  Can this idea be developed into a usable programming language?