Categorical Formalization of Program Modification

Yasutaka HIGA

Categorical Formalization of Program Modification

Yasutaka HIGA

Concurrency Reliance Laboratory (Kono lab)
Department of Information Engineering
University of the Ryukyus

Verification of Program

  • A bug in software occurs fatal problem in medical front, hardware industry, and more.
  • Therefore, Reliability of program is very important.
  • Verification of program improves reliability of software.
  • A method of verification is model checking which verifies specification is fit to actual implementation.
  • On the other hand, There is a method which proves properties of the program.

Modification of program

  • Reliability is represented by properties which guarantee specific behavior(e.g. Deadlock free, terminate, etc).
  • Properties can compute from exploring states of programs exhaustive.
  • Model checking is a tool which checks properties of the program.
  • However, Properties changed by modification of the program.
  • We formalize modification of programs for propose software development methods which guarantee properties.

Definitions of Program

  • A program is a typed lambda calculus
  • lambda term
    • variables : x,y
    • lambda : \x -> f x
    • function applications : f x
  • type
    • type of variable : A, B
    • functional type : A -> B

Every lambda term has a type

    y   :: B
    f   :: A -> B
    f x = y
  • = is a function definition
  • f x is a application function f
  • f x has type B

Category and Lambda Calculus

  • We use Monad to formalize modification of program.
  • Monad is notion of Category Theory.
  • Category Theory discusses mathematical structure(e.g. like group theory, topology, set theory etc).
  • Typed lambda calculus has correspondence with category through the Curry-Howard Isomorphism.

Monad in Typed Lambda Calculus

  • Monad in Typed Lambda Calculus is one to one mapping between normal computation and meta computation.
  • Meta computation means computation for implements computation (e.g. like OS, library).
  • In pure functional programming language Haskell uses Monad for some meta computations(e.g. nondeterminism, side-effects, exceptions).
  • It means normal computation can be extend to computation with meta one.

Modification of Program as Monad

  • We define Delta Monad represents modification of program.
  • Modifications of values are stored as a list like structure.
  • Deltarepresents simple modification only monotonic increase versioning (exclude branching and merging) and program has consistent type in all versions.
  • We can execute multi versions simultaneously using this Monad.

Simple program : version 1

f :: Double -> Double
f x = 42 + x
  • Function f takes one argument.
  • f return a value plus 42 and x
  • This program can be safe any Numbers.

Simple program : version 2

f :: Double -> Double
f x = 42 / x
  • We change operation in f
  • If x is zero, program is not unsafe.

Simple program : version 1 and 2 using Delta

f :: Double -> Delta Double
f x = Delta (42 + x)
            (Mono (42 / x))
  • Programs contain two versions using Monad are shown.
  • This program can be execute two operations simultaneously.

Merits of Delta Monad

  • Transition of properties of the program can be compare.
  • We can execute programs which compatible with older versions.
  • We can develop software which guarantee properties on each modification.

Conclusion and Future works

  • Formalization of program modifications using Monad is proposed.
  • We define Delta Monad contains all modifications like list structure.
  • We prove Delta is compatible with Monad-laws by Proof Assistant Language Agda.
  • We will extend Delta for non-monotonic modifications.
  • We will apply Delta for actual programming language(e.g. Haskell, CbC)