Exemple #1
0
 def test_file(f, stats):
     stats['total'] += 1
     file_failed_count = 0
     error_diff = ''
     content = open(f).read()
     sections = content.split('++++')
     for section in sections:
         code, tokens_target = map(strip, section.split('----'))
         tokens_actual = prettyprint(code).strip()
         if tokens_actual != tokens_target:
             file_failed_count = 1
             error_diff += get_error_diff(tokens_target, tokens_actual)
     
     stats['failed'] += file_failed_count
     return not bool(file_failed_count), error_diff
Exemple #2
0
 def accept_tests(files):
     for f in files:
         corrected_content = ''
         content = open(f).read()
         sections = content.split('++++')
         i = 0
         for section in sections:
             if i>0:
                 corrected_content += "\n++++\n"
             code, _unused = map(strip, section.split('----'))
             tokens_actual = prettyprint(code).strip()
             corrected_content += "%s\n----\n%s" % (code, tokens_actual)
             i += 1
         
         open(f, 'w').write(corrected_content)
         print colored("Accepted %s" % f, 'green')
#!/usr/bin/python

from functions_proof import *
from prettyprint import prettyprint

print basic_definitions()
print

for f in config.functions:
    print f.definition_intro()
    print prettyprint(f.definition())
    print
    print
    if f.name=='bitslice':
        print """Assume you want to define a primitive recursive relation r(x) like this:
r(0) = expression returning 0 or 1
r(x) = expression returning 0 or 1 using r(a), r(b) where a,b < x

This cannot be done with the primitive recursion scheme where
r(x+1,...) is defined only in terms of r(x,...) - not some r(y,...) (y < x).

This can be solved by defining a primitive recursive h(x)
so that r(x) <-> bit x of h(x) is set. h(x) "codes" the information of r(y)
for all values y <= x:
h(0) = expression returning r(0) - which is 0 or 1
h(x+1) = h(x) + f(x+1,h(x))*(2**(x+1))
recursive_r(y,x) = bitset(y,x)
f(x,y) = expression returning r(x) using recursive_r(y,a) where a < x
"""

        print """Assume you want to define a primitive recursive function r(x) like this: