User Tools

Site Tools


calculator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

calculator [2017/04/19 13:31]
calculator [2017/04/19 13:31] (current)
Line 1: Line 1:
 +=====Polyhedral Calculator=====
 +This page provides examples of how to use the calculator feature in the AlphaZ system.
 +The calculator is simply an interface to the underlying polyhedral libraries.
 +There are a number of commands available in the script interface with prefix "calc_" which stands for calculator commands.
 +(Eclipse has a very good context-sensitive assist feature; the default key binding is ctrl+space)
 +
 +The calculator manipulates Domain and AffineFunction objects that are created by the following commands.  Note that there is no notion of parameter domain in the calculator, so when you manipulate parameterized domains that come form an Alphabets program, and functions you need to add these indices explicitly rather than blind cut-and-paste.
 +===ReadDomain===
 +Parses a domain in alphabets syntax and returns a Domain object.
 +<sxh cs; gutter:true>
 +dom = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +</sxh>
 +===ReadFunction===
 +Parses an affine function in alphabets syntax and returns a AffineFunction object.
 +<sxh cs; gutter:true>
 +func = calc_ReadFunction("(i,j,k->i,j+k)");
 +</sxh>
 +===echo===
 +These objects (and any other objects) can be printed out to the console by the echo command.
 +<sxh cs; gutter:true>
 +dom = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +echo(dom);
 +</sxh>
 +====Domain Operations====
 +===Intersection===
 +Returns the intersection of two domains.
 +<sxh cs; gutter:true>
 +domA = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +domB = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=k<10}");
 +echo(calc_Intersection(domA,domB));
 +</sxh>
 +===Union===
 +Returns the union of two domains.
 +<sxh cs; gutter:true>
 +domA = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +domB = calc_ReadDomain("{i,j,k|2<=i<12 && 5<j<20}");
 +echo(calc_Union(domA,domB));
 +</sxh>
 +===Image===
 +Returns the image of a domain by an affine function.
 +<sxh cs; gutter:true>
 +dom = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +fun = calc_ReadFunction("(i,j,k->i-j,i,j)");
 +echo(calc_Image(fun,dom));
 +</sxh>
 +===PreImage===
 +Returns the pre-image of a domain by an affine function.
 +<sxh cs; gutter:true>
 +dom = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +fun = calc_ReadFunction("(i,j,k->i+k,j,k)");
 +echo(calc_PreImage(fun, dom));
 +</sxh>
 +===Difference===
 +Returns the difference of two domains.
 +<sxh cs; gutter:true>
 +domA = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +domB = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<5}");
 +echo(calc_Difference(domA, domB));
 +</sxh>
 +===IsEmpty===
 +Returns true if the given domain is empty.
 +<sxh cs; gutter:true>
 +dom = calc_ReadDomain("{i|0<=i<10 && i>10}");
 +echo(calc_IsEmpty(dom));
 +</sxh>
 +===IsEquivalent===
 +Returns true if the given domains are equivalent.
 +<sxh cs; gutter:true>
 +dom = calc_ReadDomain("{i,j,k|0<=i<10 && 0<=j<10}");
 +fun = calc_ReadFunction("(i,j,k->i+k,i,j)");
 +domI = calc_Image(fun,dom);
 +domIPI = calc_PreImage(fun,domI);
 +echo(calc_IsEquivalent(dom,domIPI));
 +</sxh>
 +
 +====Function Operations====
 +===Compose===
 +Returns f = f1 o f2.
 +f(z) = f1(f2(z)).
 +<sxh cs; gutter:true>
 +f1 = calc_ReadFunction("(x,y->x,y,x+y)");
 +f2 = calc_ReadFunction("(i,j,k->i,j)");
 +echo(calc_Compose(f1, f2));
 +</sxh>
 +===Inverse===
 +Returns the inverse of an affine function if it exists.
 +<sxh cs; gutter:true>
 +f = calc_ReadFunction("(x,y->x,x+y)");
 +echo(calc_Inverse(f));
 +</sxh>
 +===InverseInContext===
 +Returns the inverse of an affine function in the context of a given domain if it exists.
 +<sxh cs; gutter:true>
 +f = calc_ReadFunction("(x,y->x)");
 +context = calc_ReadDomain("{i,j|i==j}");
 +echo(calc_InverseInContext(context, f));
 +</sxh>
 +===IsEquivalent===
 +Returns true if the given functions are equivalent.
 +<sxh cs; gutter:true>
 +f1 = calc_ReadFunction("(x,y->x,y,x+y)");
 +f2 = calc_ReadFunction("(i,j,k->i,j)");
 +echo(calc_IsEquivalent(calc_Compose(f1, f2), calc_Join(f2, f1)));
 +</sxh>
 +
  
calculator.txt ยท Last modified: 2017/04/19 13:31 (external edit)