Ms Primitive Recursive

Embed Size (px)

Citation preview

  • 8/10/2019 Ms Primitive Recursive

    1/13

    1

  • 8/10/2019 Ms Primitive Recursive

    2/13

    The domain of apartial functionon set A contains the subset of A.

    The domain of a total functionon set A contains the entire set A.

    Apartial functionfis called partially computable if thereis some program that computes it. Another term for suchfunctions partial recursive.

    Similarly, a function fis called computable if it is bothtotalandpartially computable. Another term for suchfunction is recursive.

    2

  • 8/10/2019 Ms Primitive Recursive

    3/13

    Let f: A B and g: B C

    Composition of f and g can then be expressed as:

    g f : A C

    (g f)(x) = g(f(x))

    h(x) = g(f(x))

    NB: In general composition is not commutative:

    ( g f )(x) ( f g )(x)

    3

  • 8/10/2019 Ms Primitive Recursive

    4/13

    Definition: Let gbe a function containing kvariables and f1 ...fkbefunctions of nvariables, so the composition of g and f is defined as:

    h(0) = k Base step

    h( x1, ... , xn) = g( f1(x1,..., xn), , fk(x1,..., xn) ) Inductive step

    Example: h(x , y) = g( f1(x , y), f2(x , y), f3(x , y) )

    his obtained from gand f1... fkby composition.

    If gand f1...fkare (partially) computable, then his(partially) computable. (Proof by construction)

    4

  • 8/10/2019 Ms Primitive Recursive

    5/13

    From programming experience we know that recursionrefers to a function calling upon itself within its owndefinition.

    Definition: Let gbe a function containing kvariablesthen his obtained through recursion as follows:

    h(x1 , , xn) = g( , h(x1 , , xn) )

    Example: x + yf( x , 0 ) = x (1)

    f(x , y+1 ) = f( x , y ) + 1 (2)

    Input: f ( 3, 2 ) => f ( 3 , 1 ) + 1 => ( f ( 3 , 0 ) + 1 ) + 1 => ( 3 + 1 ) + 1 =>55

  • 8/10/2019 Ms Primitive Recursive

    6/13

    Primitive Recursively Closed (PRC) class of functions.

    Initial functions:

    Example of a projection function:u2( x1, x2, x3, x4, x5) = x2

    Definition:A class of total functions Cis called PRC class if:

    The initial functions belong to C. Function obtained from functions belonging to Cby

    either composition or recursion belongs to C.

    6

    s(x) = x + 1

    n(x) = 0ui(x1 , , xn) = xi

  • 8/10/2019 Ms Primitive Recursive

    7/13

    There exists a class of computable functionsthat is a PRC class.

    Definition: Function is considered primitive recursive if it

    can be obtained from initial functions and through finitenumber of composition and recursion steps.

    Theorem: A function is primitive recursive iffit belongs tothe PRC class. (see proof in chapter 3)

    Corollary: Every primitive recursive function is computable.

    7

  • 8/10/2019 Ms Primitive Recursive

    8/13

    We have already seen the addition function,which can be rewritten in LRR as follows:

    sum( x, succ(y) ) => succ( sum( x , y)) ;

    sum( x , 0 ) => x ;

    Example:sum(succ(0),succ(succ(succ(0)))) =>

    succ(sum(succ(0),succ(succ(0)))) => succ(succ(sum(succ(0),succ(0)))) =>succ(succ(succ(sum(succ(0),0) => succ(succ(succ(succ(0))) =>succ(succ(succ(1))) => succ(succ(2)) => succ(3) => 4

    8

    NB: To prove that a function is primitive recursive you need show that itcan be obtained from the initial functions using only concatenation andrecursion.

  • 8/10/2019 Ms Primitive Recursive

    9/13

    h( x , 0 ) = 0

    h( x , y + 1) = h( x , y ) + x

    In LRR this can be written as:

    mult(x,0) => 0 ;mult(x,succ(y)) => sum(mult(x,y),x) ;

    What would happen on the following input?

    mult(succ(succ(0)),succ(succ(0)))

    9

  • 8/10/2019 Ms Primitive Recursive

    10/13

    0! = 1

    ( x + 1 ) ! = x ! * s( x )

    LRR implementation would be as follows:

    fact(0) => succ(null(0)) ;fact(succ(x)) => mult(fact(x),succ(x)) ;

    Output for the following? fact(succ(succ(null(0))))

    10

  • 8/10/2019 Ms Primitive Recursive

    11/13

    11

    xx=x

    =x

    y+y *

    1

    1

    0

    In LRR the power function canbe expressed as follows:

    pow(x,0) => succ(null(0)) ;

    pow(x,succ(y)) => mult(pow(x,y),x) ;

    p (0) = 0p ( t + 1 ) = t

    Power function

    Predecessorfunction

    In LRR the predecessor is as follows:

    pred(1) => 0 ;pred(succ(x)) => x ;

  • 8/10/2019 Ms Primitive Recursive

    12/13

    x 0 = x

    x ( t + 1) = p( x t )

    12

    | xy | = ( x y ) + ( y x )

    (x) = 1 x

    dotsub(x,x) => 0 ;dotsub(x,succ(y)) => pred(dotsub(x,y)) ;

    abs(x,y) => sum(dotsub(x,y),dotsub(y,x)) ;

    (x) => dotsub(1,x) ;

    What would be the output? dotsub(succ(succ(succ(0))),succ(0))

    Output for the following? a(succ(succ(0))) a(null(0))

    0

    0

    1)(

    x

    otherwise

    ifx

  • 8/10/2019 Ms Primitive Recursive

    13/13

    13

    x + y f( x , 0 ) = xf( x , y + 1 ) = f( x , y ) + 1

    x * y h( x , 0 ) = 0h( x , y + 1 ) = h( x , y ) + x

    x! 0! = 1

    ( x + 1 )! = x! * s(x)

    x^y x^0 = 1x^( y + 1 ) = x^y * x

    p(x) p( 0 ) = 0p( x + 1 ) = x

    x yif x y then x y = x y; else x y = 0

    x 0 = xx ( t + 1) = p( x t )

    | xy | | xy | = ( x y ) + ( y x )

    (x) (x) = 1 x