Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Translate the math expression to the Forth notation using only stack shuffle.
The first number is an estimated complexity.

Running from command line

    % a b c -- x
    swipl -s stackops -g 'juggle([a,b,c],a*a+b*b+c,X)'
    21,[dup,*,over,rot,*,+,swap,+]
    23,[dup,*,swap,tuck,rot,*,+,swap,+]
    23,[dup,swap,*,over,rot,*,+,swap,+]
    25,[dup,swap,*,swap,tuck,rot,*,+,swap,+]

    % a b c -- x
    swipl -s stackops -g 'juggle([a,b,c],a*a+b*b*2+c,X)'
    25,[dup,*,over,rot,*,2,*,+,swap,+]
    27,[dup,*,swap,tuck,rot,*,2,*,+,swap,+]
    27,[dup,swap,*,over,rot,*,2,*,+,swap,+]
    29,[dup,swap,*,swap,tuck,rot,*,2,*,+,swap,+]

    % a b -- x
    swipl -s stackops -g 'juggle([a,b],a+b*a,X)'
    9,[tuck,*,+]
    11,[swap,over,*,+]
    ...

    % b a -- x
    ?- juggle([b,a],a*b+a*b,X).
    7,[*,dup,+]
    9,[*,dup,swap,+]
    11,[swap,swap,*,dup,+]
    ...

About

Translate math expression to the Forth stack manipulations using only shuffle operations.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages