// symb ::= 'a' | 't' | 'c' | 'g' // input : nat -> char -> type // output : nat -> char -> type // dist : nat -> nat -> nat -> type // dist(i,o,cost) means the edit distance between // input from position i to the end and // output from position o to the end // is cost // insert costs 100 // delete costs 10 // modify costs 1 dist(?i, ?o, 0) :- inputdone(?i), outputdone(?o). dist(?i,?o,?c) :- dist(?i,succ(?o),?cost), ADD(?cost, 100, ?c). dist(?i,?o,?c) :- dist(succ(?i),?o,?cost), ADD(?cost, 10, ?c). dist(?i,?o,?c) :- dist(succ(?i),succ(?o),?cost), input(?i,?ichar), output(?o,?ochar), ?ichar != ?ochar, ADD(?cost,1,?c). dist(?i,?o,?c) :- dist(succ(?i),succ(?o),?c), input(?i,?char), output(?o,?char). // ---------------------------------------------------------------------- input(zero(),'a'). input(succ(zero()),'t'). input(succ(succ(zero())),'c'). output(zero(),'a'). output(succ(zero()),'g'). output(succ(succ(zero())),'c'). output(succ(succ(succ(zero()))),'t'). // identifies the end of the input and output strings (should be equal to the length) outputdone(succ(succ(succ(succ(zero()))))). inputdone(succ(succ(succ(zero())))). // (101) (102) (103) (211) (210) (212) (320) (321) (430) ?- dist(zero(),zero(),?c).