Concept and Design of Functional Programming for Interactive Art Polyphonic Jump!*

Concept and Design of Functional Programming for Interactive Art Polyphonic Jump!*

Transactions of the Institute of Systems, Control and Information Engineers, Vol. 33, No. 9, pp. 253–258, 2020 253 Paper Concept and Design of Functional Programming for Interactive Art Polyphonic Jump!* Ichiroh Kanaya† This article presents the mathematical background of general interactive systems. The first principle of designing a large system is “divide and rule,” which implies that we could possibly reduce human error if we divided a large system in smaller subsystems. Interactive systems are, however, often composed of many subsystems that are organically connected to one another and thus extremely difficult to divide. In other words, we cannot apply a traditional mechanism of mathematical functions to the programming of interactive systems. We, however, can overcome this difficulty by applying a framework of category theory to the programming, but this requires highly abstract mathematics, which is not very popular. In this article we introduce the fundamental idea of the category theory using only λ-calculus, and then demonstrate how it can be used in the practical design of an interactive system. Finally, we mention how this discussion relates to Kleisli category in mathematics. 1. Introduction cannot be divided into smaller λ-calculus expressions. The Oxford English Dictionary (OED) defines the He explained that this was due to the mismatch of word “function” as 1 an activity that is natural to or types of input and output in the λ-calculus and sug- the purpose of a person or thing: ‘bridges perform gested that this gap could be overcome by regarding the function of providing access across water’; ‘bodily an interactive system as a morph of a function to an functions’. 2 [Mathematics] a relation or expression action[4]. involving one or more variables: ‘the function (bx + Moggi’s theory uses highly abstract mathematics c).’ and is generally difficult for average-level computer As defined by the OED, the word function has (at scientists to understand. However, Moggi’s concept least) a double meaning: activity (the first meaning) is understandable without a deep understanding of and relation (the second meaning). The relation is Kleisli’s category theory. often referred to as a mapping in mathematics, which In this paper we first interpret Moggi’s discussion typically implies referential transparency. without using the category theory and then explain Conversely, λ-calculus is identical to a mapping how this theory can be applied to our interactive art in mathematics, and also to a Turing Machine. This called Polyphonic Jump![5]. Finally, we provide rigid means that every program (computer code) can be proof of our discussion by following Moggi’s original represented by the λ-calculus[1,2]. proposal. However, there are often difficulties in regarding 2. Equation of Interaction interactive systems as a mapping. Moggi tackled this problem and found a unique solution: he applied Kleisli Let x and y be an input to and an output from category and regarded a function as a morph, which a certain system, respectively. Generally neither x is a more abstract concept of an ordinary mapping[3]. nor y are scalars. Hereafter, we assume that all func- Moggi discovered that these interactive systems tions are referentially transparent except for ones we ∗ explicitly denoted. Manuscript Received Date: July 29, 2019 Interactive systems can be classified as one of the ∗ The material of this paper was partially presented at following four classes: A class 0 system outputs a the 63rd Annual Conference of the Institute of Systems, constant value, while class 1 outputs a value that is Control and Information Engineers (SCI’19) which was a function of time. A class 2 system outputs a value held in May, 2019. † that is a function of arbitrary inputs (including time). School of Information and Data Sciences, Nagasaki Uni- A class 3 system outputs a value that is a function of versity; 1-14 Bunkyomachi, Nagasaki 852-8521, JAPAN an arbitrary input and its internal status. Key Words: interactive art, functional programming, Class 0: output y is constant, that is, y = c, where c referential transparency, category theory, monad in is a constant value. programming. –1– 254 Trans. of ISCIE, Vol. 33, No. 9 (2020) Class 1: output y is a function of time τ.1 We de- y =bindf(injectx). (9) note this function as f, and call it the transfer function. Assume that all functions used in this Equation (9) of a Class 3 system corresponds with paper are curried and left-associative, which we equation (2) of a Class 2 system. are familiar to. The equation for class 1 is Next we introduce several symbols to facilitate hu- man readability. The † symbol denotes the injection y = fτ. (1) operator and is given by Class 2: output y is a function of an arbitrary value x† ≡ injectx. (10) x. Thus, the equation is The symbol denotes the binding operator and is y = fx. (2) given by Class 3: output y is a function of an arbitrary input f m ≡ bindfm. (11) x andaninternalstatuss. If we allowed referen- tial opacity of function f, we would obtain the Equation (9) can be simplified by these operators as following equation: follows: y = f x†. (12) y = f!sx, (3) The binding operator is defined as where function f! changes its behavior based on its internal status s, and rewrites the value of f m ≡\s → fxs where [x,s]=ms, (13) s whenever the function is evaluated. Because rewriting any variables is not allowed in this dis- where the keyword where declares local variables, cussion, we must forget this disruptive function which can be easily translated in ordinary λ-calculus. f!. Since almost all of practical programming languages One well-known method for retaining referential provide syntax for declaring local variables, we follow transparency is placing the internal status outside the popular programming-language style and use let...in box. For example, instead of where: [y,t]=f [x,s](4)f m ≡\s → let[x,s]=ms in fxs (14) is a referentially transparent equation. Here function where “let...in” is defined as f returns a pair of output y and a new internal sta- ≡ \ → tus t. To match the types of input and output, the leta = b in c ( a c)b. (15) argument is also a pair. 3. Composition of Transfer Functions Assume we have function named “inject” given by Assume that transfer function f is the composi- injectx ≡\s → [x,s](5)tion of two different transfer functions g and h;that is, where \ denotes λ-calculus. The function “inject” abstracts the internal status s, andthuswecancall f = h•g, (16) injectx as an input with context. Because we wish to apply transfer function f to where input x, output y should be b•a ≡\z → b(az). (17) y = inject(fx). (6) Let x be the input to the system, and m be a contex- Although Equation (6) is perfectly correct, it is not tual version of x. Thus m is given by practical because output y is with context while input m ≡ x†. (18) x is without context. A practical transfer function, say F, should be something looked like Furthermore, let y = F (injectx). (7) n ≡ gm (19) Let us extract transfer function f as a parameter of where function F as n = \s → let[x,s]=ms in gxs. (20) F =bindf (8) Now we can expand hn as so that we can obtain hn = \t → let[x,s]=mt,[y,t]=gxs in hyt,(21) 1 Rich Hickey, a language designer of Clojure figured which leads to out difficulty of modeling time itself[9]. –2– Kanaya: Concept and Design of Functional Programming for Interactive Art Polyphonic Jump! 255 Fig. 1 Polyphonic Jump! (Mayuko Kanazawa, Masataka Imura, and Ichi Kanaya) Fig. 2 System structure of Polyphonic Jump! hgx† = \s → let [x,s]=x†s,[ ,s]=gxs For seamless integration of the physical painting, in (h•g)xs. (22) which presents true reality and computer-generated animation that moves dynamically and interacts with As seen above, transfer functions can be combined us- the audience, we have incorporated real-time 3D mod- ing a binding operator. Composition through a bind- eling and projection technology in this artwork (see ing operator keeps the context as shown in equation Figure 1). (22), and also maintains the order of evaluation of the As shown in Figure 2, Polyphonic Jump! has the functions because the operator follows equation (17). following subunits: (A) clock generator, (B) image Now we use another operator denoting quick capturing unit, (C) animation frame database, (D) composition of transfer functions. We can think of motion sensor, (E) animation generator, and (F) ren- applying non-contextual function fNC to contextual derer. The authors use white for trivial referentially m as transparent units, and gray for non-trivial referen- † tially transparent units. Arrows show the flow of in- fNC m ≡ (fNCx) where\s → [x,s ]=ms. (23) formation. Operator gives context to function fNC, and is known (A) The clock generator synchronizes all units by as a functor as discussed later. controlling the renderer (F). (B) The image capturing unit captures a figure in 4. An Example: Polyphonic Jump! the audience. Polyphonic Jump! is a system that allows humans (C) The animation frame database retrieves each frame to be immersed in a fantasy world in which many of animations. creatures create a polyphonic chorus. The audience (D) The motion sensor returns True if a member of stands in front of a huge canvas on which a picture of the audience is jumping, otherwise False. a forest has been painted in oils, and individuals jump (E) The animation synthesizer unit, referring to the to interact with oil-painted animals on the canvas as motion sensor (D), generates frame information if they were also on the canvas.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us