set
play

Set A Language for Set Theory Heather Preslier - PowerPoint PPT Presentation

Set A Language for Set Theory Heather Preslier Introduction/Motivation Language based in C Compiled down to LLVM Goals: Simplify the formulation of complex algorithms by creating a concise language that mirrors set


  1. Set A Language for Set Theory Heather Preslier

  2. Introduction/Motivation Language based in C ● Compiled down to LLVM ● Goals: ● Simplify the formulation of complex algorithms by creating a concise language ○ that mirrors set notation Simplify the handling and manipulating of sets ○ Remove the need for type declarations ○ Maintain functionality for basic programming ○

  3. Syntax Syntax inspired by set theoretic notation ● Full type inference ● Built-in functionality for the manipulation and operation of sets ● Overloaded operators ● def remove_duplicates(a){ b = []; (0<=i<#a | a[i]?b == false) b = b + [a[i]]; print(b); /* print the new set */ return b; }

  4. Syntax Syntax inspired by set theoretic notation ● Full type inference ● Built-in functionality for the manipulation and operation of sets ● Overloaded operators ● Type inference def remove_duplicates(a){ Function inference b = []; Built-in set operators (0<=i<#a | a[i]?b == false) Type inference b = b + [a[i]]; Set Theoretic Iterator overloaded operators Comments print(b); /* print the new set */ StdLib Function return b; }

  5. example1.sc: Syntax 1 a = “setc”; /* global */ 2 File extension: .sc ● 3 def main(){ 4 b = 3; /* initialization */ Required main function ● 5 c = []; Types: bools, ints, floats, strings, sets 6 c = c + [b]; /* c -> int */ ● 7 d = func(c); Initialization by assignment ● 8 print(d); /* true */ 9 Inferred types are bound after initialization ○ 10 def func(a) { Empty set types are bound after first use ○ a[0] = 5; 11 Functions ● return true; 12 13 } Need only be preceded by the keyword def ○ Functions types and parameters are inferred ○ Sets are pass by reference ○

  6. example2.sc: Special Features 1 def main(){ 2 a = [1,2,3]; Optimizations of functions ● 3 b = [1,4,2]; 4 a * b; /* [1,2] */ Some functions will not be semantically ○ 5 a + b; /* [1,2,3,1,4,2]*/ checked and code will not be generated 6 a & b; /* [1,2,3,4] */ Standard Library/Built-In Functionality ● a - b; /* [3] */ 7 a[1:3]; /* [2,3] */ 8 Print functionality for all types ○ 2?a; /* true */ 9 Intersection (*), union (&), difference(-), ○ a[1:3]; /* [2,3] */ 10 append(+), slice(:), set, in(?), cardinality(#) #a; /* 3 */ 11 print(a); /* 1 2 3 */ operations for sets 12 c = “hello world”; 13 Split function: string -> set ○ d = split(c, “ “); 14 File I/O: open, close, read, write ○ /* d -> set */ 15

  7. Tasks Code Generation: Semantics: Sets ● Constraints ● Pointer implementation ○ Precedence ○ Length: compile time vs. runtime ○ Overloading operators and ● decision functions Considering the IR ○ Testing: Type Inference algorithm ● Unit and Integration testing ● Third time's the charm ○ 102 tests total ● Sets/empty set ● Type inference of an empty set ○ Compile time vs. runtime decision ○

  8. Lessons Learned Need to consider the IR more when making design and ● implementation choices for the language

  9. Demos Demo 1: Basic functionality ○ Bubble Sort Algorithm Demo 2: Function inference ○ GCD algorithm ○ Euler’s phi function ○ Coprimality of sets Demo 3: Algorithm ○ Perceptron Learning Algorithm

Recommend


More recommend