diff --git a/alignments_singletrack.gap b/alignments_singletrack.gap index a2870e7..3ef6a5a 100644 --- a/alignments_singletrack.gap +++ b/alignments_singletrack.gap @@ -233,9 +233,11 @@ algebra alg_pretty implements sig_alignments(alphabet=char, answer=typ_ali) { } } -// a special pretty print algebra that uses the same symbol '-' for all types of gapc -// this illustrates semantic ambiguity and is e.g. used as the introductory example -// in the lecture slides. +/* +a special pretty print algebra that uses the same symbol '-' for all types of gapc +this illustrates semantic ambiguity and is e.g. used as the introductory example +in the lecture slides. +*/ algebra alg_pretty_onegap extends alg_pretty { typ_ali Region(Rope afirst, typ_ali x) { typ_ali res; @@ -309,8 +311,10 @@ algebra alg_pretty_onegap extends alg_pretty { } } -// an algebra that computes a Trace representation of an Alignment, -// i.e. we arbitraily say that Insertions cannot preceed Deletions (could be vice versa) +/* +an algebra that computes a Trace representation of an Alignment, +i.e. we arbitraily say that Insertions cannot preceed Deletions (could be vice versa) +*/ algebra alg_editops implements sig_alignments(alphabet=char, answer=Rope) { Rope Ins(alphabet a, Rope x) { Rope res; @@ -392,9 +396,9 @@ algebra alg_editops implements sig_alignments(alphabet=char, answer=Rope) { } } - - -// pair-wise global alignment +/* +pair-wise global alignment +*/ grammar gra_needlemanwunsch uses sig_alignments(axiom=A) { A = Ins(CHAR, A) | Del(A, CHAR) @@ -403,11 +407,12 @@ grammar gra_needlemanwunsch uses sig_alignments(axiom=A) { # h; } -/* a grammar that enumerates all traces but not all alignments - difference: X- and -X are two different alignments, but the same trace - -Y Y- - this is because there is no evidence that could tell us if deletion came before insertion - or vice versa. +/* +a grammar that enumerates all traces but not all alignments +difference: X- and -X are two different alignments, but the same trace + -Y Y- +this is because there is no evidence that could tell us if deletion came before insertion +or vice versa. */ grammar gra_traces uses sig_alignments(axiom=A) { A = Ins(CHAR, I) @@ -429,7 +434,9 @@ grammar gra_traces uses sig_alignments(axiom=A) { # h; } -// pair-wise semiglobal alignment, i.e. long in short +/* +pair-wise semiglobal alignment, i.e. long in short +*/ grammar gra_semiglobal uses sig_alignments(axiom=S) { S = Region(ROPE0, A) # h; @@ -444,7 +451,9 @@ grammar gra_semiglobal uses sig_alignments(axiom=S) { # h; } -// pair-wise end-gap-free alignment, e.g. for assembly +/* +pair-wise end-gap-free alignment, e.g. for assembly +*/ grammar gra_endgapfree uses sig_alignments(axiom=S) { S = Region_Pr(ROPE0, A) # h; @@ -459,7 +468,9 @@ grammar gra_endgapfree uses sig_alignments(axiom=S) { # h; } -// pair-wise local alignment, e.g. BLAST +/* +pair-wise local alignment, e.g. BLAST +*/ grammar gra_smithwaterman uses sig_alignments(axiom=S) { S = Region(ROPE0, T) # h; @@ -480,7 +491,9 @@ grammar gra_smithwaterman uses sig_alignments(axiom=S) { # h; } -// pair-wise global alignment with affine gap costs +/* +pair-wise global alignment with affine gap costs +*/ grammar gra_gotoh uses sig_alignments(axiom=A) { A = Ins(CHAR, xIns) | Del(xDel, CHAR) @@ -497,6 +510,9 @@ grammar gra_gotoh uses sig_alignments(axiom=A) { # h; } +/* +example inputs: ZEITGEIST@TIEZIERF +*/ instance ins_needlemanwunsch_count = gra_needlemanwunsch(alg_count); instance ins_semiglobal_count = gra_semiglobal(alg_count); instance ins_endgapfree_count = gra_endgapfree(alg_count); diff --git a/binary_search_tree.gap b/binary_search_tree.gap index 97c7bcf..c4a7d02 100644 --- a/binary_search_tree.gap +++ b/binary_search_tree.gap @@ -13,14 +13,16 @@ algebra alg_enum auto enum; algebra alg_count auto count; algebra alg_tikz auto tikz; -// It is not trivial to see why this computation works. -// You should first draw out an example tree and compute the mean access time by hand. -// The idea is, that you need to know the "depth" of an element within the tree. -// You can than compute the mean access time as the sum of key probabilities * key depth -// In ADP, you construct the trees buttom up, i.e. you don't know the depth!! -// The trick is, that whenever you go one level up, you repreat addition of the "yield" -// seen so far to the regular mean access time from left and right components plus the new key -// AND you need to update the yield. Thus, we need a tuple as answer type. +/* +It is not trivial to see why this computation works. +You should first draw out an example tree and compute the mean access time by hand. +The idea is, that you need to know the "depth" of an element within the tree. +You can than compute the mean access time as the sum of key probabilities * key depth +In ADP, you construct the trees buttom up, i.e. you don't know the depth!! +The trick is, that whenever you go one level up, you repreat addition of the "yield" +seen so far to the regular mean access time from left and right components plus the new key +AND you need to update the yield. Thus, we need a tuple as answer type. +*/ algebra alg_mean_access_time implements sig_bst(alphabet=char, answer=typ_access) { typ_access branch(typ_access left, typ_access entry, typ_access right) { typ_access res; @@ -48,8 +50,10 @@ algebra alg_mean_access_time implements sig_bst(alphabet=char, answer=typ_access } } -// note that branch(nil, X, nil) and leaf(X) both collapse to the -// pretty print: "(X)", i.e. they are semantically ambiguous! +/* +note that branch(nil, X, nil) and leaf(X) both collapse to the +pretty print: "(X)", i.e. they are semantically ambiguous! +*/ algebra alg_pretty implements sig_bst(alphabet=char, answer=Rope) { Rope branch(Rope left, Rope x, Rope right) { Rope res; @@ -96,23 +100,25 @@ grammar gra_bst uses sig_bst(axiom = bstree) { entry = keypair(INT, CHAR(':'), FLOAT, CHAR(',')) # h; } +/* +example inputs: 1:0.22,3:0.18,4:0.2,8:0.05,10:0.25,11:0.02,15:0.08, +*/ +/* +note the trailing , at the end of each input! +the example input above corresponds to the following table: +key prob +1 0.22 +3 0.18 +4 0.2 +8 0.05 +10 0.25 +11 0.02 +15 0.08 +*/ + instance enum = gra_bst(alg_enum); instance count = gra_bst(alg_count); instance matpp = gra_bst(alg_mean_access_time * alg_pretty); instance ppmat = gra_bst(alg_pretty * alg_mean_access_time); instance ppcount = gra_bst(alg_pretty * alg_count); instance matppcount = gra_bst(alg_mean_access_time * alg_pretty * alg_count); - -/* example input (note the trailing , at the end of each input!) - "1:0.22,3:0.18,4:0.2,8:0.05,10:0.25,11:0.02,15:0.08," - - corresponds to the following table: - key prob - 1 0.22 - 3 0.18 - 4 0.2 - 8 0.05 - 10 0.25 - 11 0.02 - 15 0.08 -*/ diff --git a/genefinder.gap b/genefinder.gap index 6a2eab2..fbd3a41 100644 --- a/genefinder.gap +++ b/genefinder.gap @@ -160,10 +160,12 @@ grammar gra_genefinder uses sig_genefinder(axiom = start) { # h; } +/* +example inputs: AAUAUGUCUGUUAAUGCAAUGGCGGCGAUUGAGUUUUCCAAGUAGAAUGAGGAUG +*/ + instance ins_aa = gra_genefinder(alg_translate); instance ins_aacount = gra_genefinder(alg_translate * alg_count); instance ins_scoreaa = gra_genefinder(alg_score * alg_translate); instance ins_aascore = gra_genefinder(alg_translate * alg_score); instance ins_count = gra_genefinder(alg_count); - -// example input "AAUAUGUCUGUUAAUGCAAUGGCGGCGAUUGAGUUUUCCAAGUAGAAUGAGGAUG" diff --git a/hmm_casino.gap b/hmm_casino.gap index 56a3998..a9ba490 100644 --- a/hmm_casino.gap +++ b/hmm_casino.gap @@ -410,6 +410,10 @@ grammar gra_casino uses sig_casino(axiom=start) { # h; } +/* +example inputs: 15626 +*/ + instance enum = gra_casino(alg_enum); instance viterbistatesmult = gra_casino(alg_viterbi * alg_states * alg_mult); instance fwd = gra_casino(alg_fwd); diff --git a/hmm_cpg.gap b/hmm_cpg.gap index 14e7c59..102afba 100644 --- a/hmm_cpg.gap +++ b/hmm_cpg.gap @@ -353,6 +353,10 @@ grammar gra_cpg uses sig_cpg(axiom=start) { # h; } +/* +example inputs: GCGGCCGA +*/ + instance enum = gra_cpg(alg_enum); instance viterbistatesmult = gra_cpg(alg_viterbi * alg_states * alg_mult); instance fwd = gra_cpg(alg_fwd); diff --git a/hmm_markovchain.gap b/hmm_markovchain.gap index 0e73276..49cf8f5 100644 --- a/hmm_markovchain.gap +++ b/hmm_markovchain.gap @@ -87,4 +87,8 @@ grammar gra_dinuc uses sig_dinuc(axiom=state_init) { state_end = nil(EMPTY); } +/* +example inputs: ACCT +*/ + instance ins_ppprobenum = gra_dinuc(alg_pretty * alg_prob * alg_enum); diff --git a/hmm_sonneregen.gap b/hmm_sonneregen.gap index 5124423..c43d4b1 100644 --- a/hmm_sonneregen.gap +++ b/hmm_sonneregen.gap @@ -299,6 +299,10 @@ grammar gra_weather uses sig_weather(axiom=start) { # h; } +/* +example inputs: SSRR +*/ + instance enum = gra_weather(alg_enum); instance viterbistatesmult = gra_weather(alg_viterbi * alg_states * alg_mult); instance fwd = gra_weather(alg_fwd); diff --git a/hmm_transmembrane.gap b/hmm_transmembrane.gap index 96b598e..5fa103c 100644 --- a/hmm_transmembrane.gap +++ b/hmm_transmembrane.gap @@ -87,7 +87,9 @@ algebra alg_structure implements sig_transmembrane(alphabet=char, answer=Rope) { } } -//st_ short for state, em_ short for emission +/* +st_ short for state, em_ short for emission +*/ grammar gra_transmembrane uses sig_transmembrane(axiom=st_init) { st_init = transition(CONST_FLOAT(0.89), CONST_CHAR('e'), em_ext, st_ext) | transition(CONST_FLOAT(0.01), CONST_CHAR('T'), em_trans, st_trans) @@ -135,4 +137,8 @@ grammar gra_transmembrane uses sig_transmembrane(axiom=st_init) { # h; } +/* +example inputs: GCGGCCGA +*/ + instance test = gra_transmembrane(alg_states); diff --git a/matrix_chain_multiplication.gap b/matrix_chain_multiplication.gap index 132033e..5619981 100644 --- a/matrix_chain_multiplication.gap +++ b/matrix_chain_multiplication.gap @@ -92,20 +92,24 @@ algebra alg_kdepth extends alg_depth { } +/* +note: right now, we "accept" impossible matrix chains, + i.e. left.cols is not enforced to be right.rows +*/ grammar gra_matmult uses sig_matmult(axiom = formula) { - // note: right now, we "accept" impossible matrix chains, - // i.e. left.cols is not enforced to be right.rows formula = single(CHAR('('), INT, CHAR('x'), INT, CHAR(')')) | mult(formula, CHAR('*'), formula) # h; } +/* +take care when applying the assertMatchingDimensions: +1) instance must contain alg_minmult +2) parenthesis become important in algebra products: alg_minmult * alg_enum * alg_count implicitly is + (alg_minmult * alg_enum) * alg_count, which will fail to compile + use explicit parenthesis like: alg_minmult * (alg_enum * alg_count) +*/ grammar gra_matmult_assert uses sig_matmult(axiom = formula) { - // take care when applying the assertMatchingDimensions: - // 1) instance must contain alg_minmult - // 2) parenthesis become important in algebra products: alg_minmult * alg_enum * alg_count implicitly is - // (alg_minmult * alg_enum) * alg_count, which will fail to compile - // use explicit parenthesis like: alg_minmult * (alg_enum * alg_count) formula = single(CHAR('('), INT, CHAR('x'), INT, CHAR(')')) | mult(formula, CHAR('*'), formula) suchthat_overlay assertMatchingDimension # h; diff --git a/palindromes.gap b/palindromes.gap index 97891a4..92eac1c 100644 --- a/palindromes.gap +++ b/palindromes.gap @@ -99,6 +99,9 @@ grammar gra_palloc uses sig_palindrome(axiom = skip_l) { # h; } +/* +example inputs: abbabaabba +*/ instance enum = gra_palindrome(alg_enum); instance loc = gra_palloc(alg_palScore * alg_pretty); diff --git a/rnafolding.gap b/rnafolding.gap index 4433eef..74c1b4d 100644 --- a/rnafolding.gap +++ b/rnafolding.gap @@ -54,9 +54,12 @@ algebra alg_dotBracket implements sig_rna(alphabet=char, answer=string) { return candidates; } } -// a second version of the dot Bracket algebra, -// but here identical representations get collapsed -// through the application of "unique" + +/* +a second version of the dot Bracket algebra, +but here identical representations get collapsed +through the application of "unique" +*/ algebra alg_dotBracketUnique extends alg_dotBracket { choice [string] h([string] candidates) { return unique(candidates); @@ -87,23 +90,24 @@ algebra alg_bpmax implements sig_rna(alphabet=char, answer=int) { } } -/* DE04: "Evaluation of several lightweight stochastic context-free grammars for RNA secondary structure prediction" - Robin D Dowell and Sean R Eddy - BMC Bioinformatics 2004 - https://doi.org/10.1186/1471-2105-5-71 - RR09: "Ambiguity Analysis of RNA SecondaryStructure Prediction Grammars" - Raphael Reitzig - Bachelor's thesis 2009 - http://reitzig.github.io/assets/pdf/ambiguity-analysis-of-RNA-grammars.pdf - +/* +DE04: "Evaluation of several lightweight stochastic context-free grammars for RNA secondary structure prediction" +Robin D Dowell and Sean R Eddy + BMC Bioinformatics 2004 + https://doi.org/10.1186/1471-2105-5-71 +RR09: "Ambiguity Analysis of RNA SecondaryStructure Prediction Grammars" + Raphael Reitzig + Bachelor's thesis 2009 + http://reitzig.github.io/assets/pdf/ambiguity-analysis-of-RNA-grammars.pdf */ -/* DE04: "We first implemented two structurally ambiguous grammars G1 and G2" - "any S =>e derivation in a parse tree could also be S => SS => eS => ee" - Definition of Ruth Nussinov 1978 - Prototype grammar of Infernal - - --> ambiguous +/* +DE04: "We first implemented two structurally ambiguous grammars G1 and G2" + "any S =>e derivation in a parse tree could also be S => SS => eS => ee" +Definition of Ruth Nussinov 1978 +Prototype grammar of Infernal + +--> ambiguous */ grammar gra_g1 uses sig_rna(axiom=S) { S = pair(BASE, S, BASE) with basepairing @@ -114,8 +118,9 @@ grammar gra_g1 uses sig_rna(axiom=S) { # h; } -/* DE04 "G2 extends [G1] to include base pair stacking parameters." - --> ambiguous +/* +DE04 "G2 extends [G1] to include base pair stacking parameters." +--> ambiguous */ grammar gra_g2 uses sig_rna(axiom=S) { S = pair(BASE, P, BASE) with stackpairing @@ -130,13 +135,14 @@ grammar gra_g2 uses sig_rna(axiom=S) { # h; } -/* DE04 "Four unambiguous grammars: G3, G4, G5, G6" - "Each of the four grammars was conjectured to be unambiguous by inspection. Each one also passed the empirical test for ambiguity described in Methods, using the test set of 2455 Rfam sequences" - "G3 was developed by RDD" - "G3 imposes a minimum hairpin loop length of one nucleotide," - "G3 and G6 can not emit an empty string" - RR08 "it is proven that G3 is unambiguous with regards to secondary structures - --> un-ambiguous +/* +DE04 "Four unambiguous grammars: G3, G4, G5, G6" + "Each of the four grammars was conjectured to be unambiguous by inspection. Each one also passed the empirical test for ambiguity described in Methods, using the test set of 2455 Rfam sequences" + "G3 was developed by RDD" + "G3 imposes a minimum hairpin loop length of one nucleotide," + "G3 and G6 can not emit an empty string" +RR08 "it is proven that G3 is unambiguous with regards to secondary structures +--> un-ambiguous */ grammar gra_g3 uses sig_rna(axiom=S) { S = pair(BASE, S, BASE) with basepairing @@ -154,11 +160,12 @@ grammar gra_g3 uses sig_rna(axiom=S) { # h; } -/* DE04 "We challenged Graeme Mitchison to make a smaller one, and he produced G4" - "G4 and G5 do not impose mini-mum hairpin loop lengths" - "G4 and G5 can emit empty strings" - RR09 "G4 is unambiguous with regards to secondary structures" - --> un-ambiguous +/* +DE04 "We challenged Graeme Mitchison to make a smaller one, and he produced G4" + "G4 and G5 do not impose mini-mum hairpin loop lengths" + "G4 and G5 can emit empty strings" +RR09 "G4 is unambiguous with regards to secondary structures" +--> un-ambiguous */ grammar gra_g4 uses sig_rna(axiom=S) { S = sadd(BASE, S) @@ -176,11 +183,12 @@ grammar gra_g4 uses sig_rna(axiom=S) { # h; } -/* DE04 "The ultracompact G5 grammar is from Ivo Hofacker" - "G4 and G5 do not impose mini-mum hairpin loop lengths" - "G4 and G5 can emit empty strings" - RR09 "proving G5 to be unambiguous withregards to secondary structures" - --> un-ambiguous +/* +DE04 "The ultracompact G5 grammar is from Ivo Hofacker" + "G4 and G5 do not impose mini-mum hairpin loop lengths" + "G4 and G5 can emit empty strings" +RR09 "proving G5 to be unambiguous withregards to secondary structures" +--> un-ambiguous */ grammar gra_g5 uses sig_rna(axiom=S) { S = sadd(BASE, S) @@ -190,11 +198,12 @@ grammar gra_g5 uses sig_rna(axiom=S) { # h; } -/* DE04 "G6 is the Knudsen/Hein grammar utilized in the Pfold package" - "G6 has aminimum of two" (unpaired bases in each hairpin loop) - "G3 and G6 can not emit an empty string" - RR09 "G6 is unambiguous with regards to secondary structures" - --> un-ambiguous +/* +DE04 "G6 is the Knudsen/Hein grammar utilized in the Pfold package" + "G6 has aminimum of two" (unpaired bases in each hairpin loop) + "G3 and G6 can not emit an empty string" +RR09 "G6 is unambiguous with regards to secondary structures" +--> un-ambiguous */ grammar gra_g6 uses sig_rna(axiom=S) { S = fork(L,S) @@ -211,9 +220,9 @@ grammar gra_g6 uses sig_rna(axiom=S) { } /* - Comparing carefully with original recurrences, g5 is Ruth Nussinov's original grammar! - Somehow, the additional rule adds(S, BASE) sneaked into text book versions of her grammar, - making it ambiguous! +Comparing carefully with original recurrences, g5 is Ruth Nussinov's original grammar! +Somehow, the additional rule adds(S, BASE) sneaked into text book versions of her grammar, +making it ambiguous! */ grammar gra_nussinov uses sig_rna(axiom=S) { S = sadd(BASE, S) @@ -223,6 +232,10 @@ grammar gra_nussinov uses sig_rna(axiom=S) { # h; } +/* +example inputs: CCAGACUGAAGAUCUGGAG +*/ + instance ins_g1_count = gra_g1(alg_count); instance ins_g2_count = gra_g2(alg_count); instance ins_g3_count = gra_g3(alg_count); diff --git a/satisfiability.gap b/satisfiability.gap index 1bddcfc..c78e6b3 100644 --- a/satisfiability.gap +++ b/satisfiability.gap @@ -16,18 +16,21 @@ algebra alg_count auto count; algebra alg_enum auto enum; algebra alg_tikz auto tikz; -/* This algebra removes all candidates from the search space that do not - satisfy the SAT formula. The formula is satisfied if all clauses are - satisfied. A clause is satisfied if there is at least one assigntrue - with a positive literal or a assignfalse with a negative literal. It - does not assure that the assigned byte vectors for all clauses are - equal. To assure this too, use the product algebra (alg_sat * alg_eqa) but - not (alg_eqa * alg_sat) due to slightly different definition of * in - Bellman's GAP, compared to Haskell ADP +/* +This algebra removes all candidates from the search space that do not +satisfy the SAT formula. The formula is satisfied if all clauses are +satisfied. A clause is satisfied if there is at least one assigntrue +with a positive literal or a assignfalse with a negative literal. It +does not assure that the assigned byte vectors for all clauses are +equal. To assure this too, use the product algebra (alg_sat * alg_eqa) but +not (alg_eqa * alg_sat) due to slightly different definition of * in +Bellman's GAP, compared to Haskell ADP +*/ +/* +Unfortunately, we cannot use data type bool, since this would result +in a conflict in the generated code between testing for is_empty of +a candidate and assigning the value "false". */ -// Unfortunately, we cannot use data type bool, since this would result -// in a conflict in the generated code between testing for is_empty of -// a candidate and assigning the value "false". algebra alg_sat implements sig_sat(alphabet=char, answer=int) { int addliteral(int l, int c) { if ((l > 0) || (c > 0)) { @@ -73,9 +76,10 @@ algebra alg_sat implements sig_sat(alphabet=char, answer=int) { } } -/* assures that the assignments are equal for all clauses. This algebra - only assures that the assigned byte vectors for all clauses are equal - completely independent of the satisfyability of the formula. +/* +assures that the assignments are equal for all clauses. This algebra +only assures that the assigned byte vectors for all clauses are equal +completely independent of the satisfyability of the formula. */ algebra alg_eqa implements sig_sat(alphabet=char, answer=Rope) { Rope addliteral(Rope l, Rope c) { @@ -176,9 +180,12 @@ grammar gra_sat uses sig_sat(axiom=selection) { ; // no choice, since Bellman's principle is violated } +/* +example inputs: PP-&-NP +*/ + instance ins_enum = gra_sat(alg_enum); instance ins_pp = gra_sat(alg_pretty); instance ins_sateqapp = gra_sat(alg_sat * alg_eqa * alg_pretty); -// example input "PP-&-NP" diff --git a/skatgame.gap b/skatgame.gap index 2689919..aab3554 100644 --- a/skatgame.gap +++ b/skatgame.gap @@ -124,9 +124,14 @@ grammar gra_skat uses sig_skat(axiom=Deal) { # h; } +/* +Unfortunately, we cannot use Unicode characters for suits, thus we need to encode +those as single characters. An example input string would look like: +*/ +/* +example inputs: d10s7dJsJh8dAdQd7c7cAhAhJd8hQh7s8cJh10c8sKhKs9c9dKsQs10d9cQcKh9c10sA +*/ + instance pp = gra_skat(alg_pretty); instance count = gra_skat(alg_count); -// Unfortunately, we cannot use Unicode characters for suits, thus we need to encode -// those as single characters. An example input string would look like: -// "d10s7dJsJh8dAdQd7c7cAhAhJd8hQh7s8cJh10c8sKhKs9c9dKsQs10d9cQcKh9c10sA"