Noether: Symmetry in Programming Language Design
Total Page:16
File Type:pdf, Size:1020Kb
Noether: Symmetry in Programming Language Design What problems am I trying to solve with this language? Symmetry Expressiveness Coherence he sublanguages, in order of decreasing symmetry $long the way we%ll tal& brie#ly about how to implement transactions efficiently' (onus slides: )e*ected features How to program gigantic computers? +''' as the power o# available machines grew by a #actor of more than a thousand! society’s ambition to apply these machines grew in proportion, and it was the poor programmer who found [their- job in this exploded #ield of tension between ends and means. he increased power of the har"ware! together with the perhaps even more dramatic increase in its reliability! made solutions #easible that the programmer had not dared to dream about a few years be#ore. And now, a few years later! ,they] had to "ream about them and! even worse! ,they] had to transform such dreams into reality. Is it a wonder that we found ourselves in a software crisis?/ 0 Edsger W. Di*&stra, The Humble Programmer (EWD2345! $C6 uring Lecture 789: How to program gigantic computers? Source: Wi&ime"ia Commons user Wgsimon! license CC (<=S$ 2'4' Data #rom English Wi&ipe"ia: ransistor count' How to program gigantic computers? Historical Cost of Computer Memory and Storage (not inflation-adjusted) Extrapolated US$ for M! Date Source: *cmit'com! © :447! :472 ?ohn C' 6cCallum 1+<ou can use the material here' Please ac&nowle"ge the source'/5 he problem Languages an" tools have improved greatly over that time! but have they improve" enough? The +So#tware Crisis/ is still here: Programs are too large! complex! and "i##icult to maintain' @o=one &nows how to write correct! secure! or reliable programs' @o=one &nows how to review a given program #or correctness, security, an" reliability! with economical e##ort' Correctness! security! an" reliability are three sides o# the same coin' Some techniAues! e'g' pure #unctional programming or (in di##erent ways) ob*ect programming, seem to help' ;ow "o they help? Symmetry Thesis: many programming language techniAues/disciplines help by imposing symmetries, which aid reasoning about programs' $ symmetry gives a set of possible transformations that do not change a given property' In Geometry: translation (e'g' of an in#inite lattice5D rotationD reflection' In Physics: time- and location=invariance in (e.g'5 general relativityD CP symmetry' In Programming (all of these are language=dependent): Confluence: in a pure language! evaluating in "if#erent or"ers pro"uces the same result' 6oving a call o# a pure #unction to a "if#erent time, or tas&! "oes not change its result' )eflexive/symmetric/associative operators and #unctions' $lpha renaming' $""ing an" removing parallelism annotationsD maybe other annotations' Expansion and abstraction o# E#unctions! macros! mo"ules! type synonyms! '''F' Common subexpression elimination. $""ing an" removing staging' rait #lattening' )epresentation changes' $""ing an" removing "ead co"e. Comments and #ormatting' Inter#ering features Many programming language featuresBproperties interfere with symmetries we'd li&e to have' Some are essential features: Side effectsD localBtas& state Hailure handling Concurrency Some are not: Dynamic scoping Iverloading Implicit coercion Introspection (stac&! local variables! function code, objects! .''5 +Jnhygienic/ or textual macros $nything that violates memory safety $nything that violates Actor locality Colliding namespaces Clobal stateD modes (e'g' floating point modeBstate) $ design wart in a feature (e'g' module or macro system5 can stop it having desired symmetries' With care, similar or better expressiveness can be achieved without problematic features! or with restricted variations on them''' but what do we do about the essential ones? Symmetry “breaking/ We want the strongest symmetries possible #or any given expressiveness' Solution: strati#ied languages' @ot a new idea (e'g' Erlang! Oz! Haskell5! but Noether ta&es it #urther' $t each level, we a"" one or more #eatures an" brea& a symmetry. Some symmetries are so use#ul that they should be preserved globally 1#or example: memory sa#ety and Actor locality laws5' ThereGs a tra"e=o## between optimizing the symmetry=expressiveness pro#ile! and &eeping the number o# levels small to reduce complexity. If we start by "esigning with one level per bro&en symmetry, we can always collapse levels together later. The sublanguages don't have to be neste"! but we ma&e them nested: #or simplicity o# understan"ing an" teaching the #ull languageD #or simplicity o# in#erring which sublanguage weGre in and conveying that to the programmerD to ma&e the design problem of which #eatures depend on others tractable' We coul" relax this constraint i# it was important, but havenGt nee"e" to #or Noether' Coherence Getting strong symmetries when a whole program is in a small sublanguage isnGt enough' @ontrivial programs are inten"e" to be a mixture o# subprograms at "i##erent levels' We need to &now whether symmetry properties are maintained when mixing levels' $nother physical analogy: Sublanguage with strong symmetries ⬄ highly ordered phase of matter! e.g' a solid' Sublanguage with weaker symmetries ⬄ less ordered phase of matter! e.g' a fluid. $ material is coherent if it maintains its phase when moved within a less ordered phase' Example: most solids maintain their phase and shape when moved in a fluid''' L unless! say, the fluid corrodes the solid. $ sublanguage is coherent if code in that sublanguage maintains its symmetry properties when used anywhere within a larger language' Example: a pure function can be executed anywhere in an impure program without losing symmetry (confluence within the function! determinism! etc'5''' L unless! say, the impure language has reflective features that break opaqueness of pure functions' Noether programming language Ibject=capability, type", parallel and concurrent! potentially highly optimizable' Strati#ied sublanguages of increasing expressiveness and "ecreasing symmetry. This tal& consi"ers mainly semantics rather than syntax' Why a new language? #ewer constraints on optimizing symmetryMexpressiveness profile' existing languages have features (e'g' exception handling! concurrency5 that we want to specify an" combine in different ways' address previously unsolved or solved-only-as=research problems: precise resource control! partial failure, flow control in asynchronous message passing! etc' security + expressiveness + speed is already very har"D adding a requirement for compatibility with some existing language would make it impossible. ( he problem is running existing programs with expected performance'5 compatibility is overrated; familiarity is more important. +a language really defines its own universe, and that a language designer has the power to control what can or cannot happen within that universe./ M Tom Van Cutsem Programming language design is fun! Emmy Noether 6athematician an" theoretical physicist! ?ewish, expelle" #rom @azi Germany in 7822' Einstein in 782P: +In the *u"gement of the most competent living mathematicians, HrQulein @oether was the most signi#icant creative mathematical genius thus #ar produce" since the higher e"ucation o# women began' In the realm of algebra! in which the most gi#te" mathematicians have been busy #or centuries, she "iscovere" metho"s which have prove" of importance in the "evelopment o# the present="ay younger generations of mathematicians. Pure mathematics is, in its way! the poetry of logical i"eas' Ine seeks the most general ideas o# operation which will bring together in simple, logical and uni#ied #orm the largest possible circle o# #ormal relations' In this e##ort toward logical beauty spiritual #ormulas are "iscovere" necessary #or the "eeper presentation into the laws of nature'/ $ppropriate #or Noether-0 because it can be viewe" as a @oetherian 1terminating) rewriting system. Some o# Emmy @oether%s other work on abstract algebra is in"irectly relevant! an" we can use analogies with physical symmetry properties to explain the language' ;ard to believe this name hasn%t already been snapped up #or a programming language. (Google says not5 Symmetry properties (ecause Noether is in general nondeterministic ! we nee" to be particularly careful in how we "efine properties such as referential transparency! confluence, etc' We mo"el evaluation as a rewriting system 1�! ⊳5! where � is a set o# terms an" ⊳ is an irreflexive binary relation on �' Hor Noether! let � R � ∪ � ∪ � ∪ E ⊥ F! where � is the set o# reducible terms 1i.e. that can be rewritten by ⊳5! � is the set o# #ailure terms! � the set o# success terms! and ⊥ a special term "enoting nontermination. Each #ailure term is associated with a reason which is always a success term' $ Noether term other than ⊥ can be represented as a program #ragment and a +store/! which maps locations to other program #ragments' @otation: T is terminating under ⊳! written T stops! iff there are no infinite ⊳-chains starting from T' When this is true for all T in �! (�, ⊳5 is noetherian' → ≝ ⊵S ↔ ≝ 1⊴ ∪ ⊵5S T ⇥ U ≝ T → U ∧ U ∉ � [U is a normal form o# T- T⤓ ≝ { U : T ⇥ U }! i# T stops ≝ { U : T ⇥ U } ∪ { ⊥ F! otherwise T fails ≝ T⤓ ⊆ � S ≋ T ≝ S⤓ = T⤓ T ⤞ U ≝ T⤓ \ � = { U } Symmetry properties hese symmetries always hold: $dding unused bin"ings to a store $lpha-renaming of locations $lpha-renaming of bound variables Other definitions relating to pure functional languages: hurch-!osser: S ↔ T ⇒ ∃ U 1 S → U ∧ T → U ) Fail-stop deterministic: U T⤓ \ � | ≤ 1 Fail-stop definite: T stops ∧ | T⤓ \ � | ≤ 1 StracheyGs definition of referential transparency: “if we wish to find the value of an expression which contains a sub-expression! the only thing we need to know about the sub-expression is its value./ his is a bit unsatisfactoryD see ,SVndergaar" and Sestoft 1984- for details' !eferential transparency: S ≋ T ⊢ # ,S- ≋ # ,T- 1if two expressions are equivalent, substituting them at the same point in a containing expression preserves eAuivalence)' Unfoldability: de# f 1 x 5 = # ,x- ⊢ S ≋ T ⇒ # ( S ) ≋ # ,T- Noether-0 is Church=)osser! fail=stop definite! referentially transparent, and unfoldable.