def test_condition_io9(t_pre: Place, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists3(Place, Place, bool)( lambda t1, t2, value: (random_bool_io(t_pre, value, t1) and Implies( value, conditionally_terminating_io(t1, value, t2)) and no_op_io( t1, t2) and no_op_io(t2, t_post)))
def test_io(t_pre: Place, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists6( Place, Place, Place, Place, Place, int)(lambda t2, t3, t4, t5, t6, res: (no_op_io(t_pre, t2) and split_io( t2, t3, t4) and set_var_io(t4, 1, res, t5) and join_io(t3, t5, t6) and no_op_io(t6, t_post)))
def test_gap_io7(t_pre: Place, value: bool, t_post: Place = Result()) -> bool: Terminates(value) TerminationMeasure(2) return IOExists2( Place, Place)(lambda t1, t2: (no_op_io(t_pre, t1) and Implies(not value, gap_io(t1, t2)) and no_op_io(t1, t2) and no_op_io(t2, t_post)))
def test_condition_io7(t_pre: Place, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists3(Place, Place, bool)( lambda t1, t2, value: ( random_bool_io(t_pre, value, t1) and #:: ExpectedOutput(termination_check.failed:child_termination.not_implied) Implies(not value, non_terminating_io(t1, t2)) and no_op_io( t1, t2) and no_op_io(t2, t_post)))
def test_gap_io9(t_pre: Place, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists3(Place, Place, bool)( lambda t1, t2, value: ( random_bool_io(t_pre, value, t1) and #:: ExpectedOutput(termination_check.failed:gap.enabled) Implies(value, gap_io(t1, t2)) and no_op_io(t1, t2) and no_op_io( t2, t_post)))
def tee_io(t_pre: Place, t_post: Place = Result()) -> bool: return IOExists4( str, bool, Place, Place)(lambda c, success, t_read, t_out: (read_char_io(t_pre, stdin, c, success, t_read) and ((tee_out_io(t_read, c, t_out) and tee_io(t_out, t_post)) if success else (no_op_io(t_read, t_post)))))
def ensure_dir_exists_io( t_pre: Place, path: str, result: bool = Result(), t_post: Place = Result()) -> bool: """Ensure that directory exists IO. Should force the implementation to handle exceptions because the methods that throw exceptions should not be able to set the ``result``. """ Terminates(True) TerminationMeasure(2) return IOExists4(OSErrorWrapper, OSErrorWrapper, Place, bool)( lambda ex1, ex2, t2, is_dir_res: ( mkdir_io(t_pre, path, ex1, t2) and ( ( no_op_io(t2, t_post) and result == True ) if ex1 is None else ( is_dir_io(t2, path, ex2, is_dir_res, t_post) and Implies(ex2 is None, result == is_dir_res) and Implies(ex2 is not None, result == False) ) ) ) )
def brackets_io( t_read1: Place, read1: str, read5: str = Result(), valid: bool = Result(), t_read5: Place = Result()) -> bool: return IOExists11( bool, bool, bool, bool, str, str, str, str, Place, Place, Place)( lambda success1, success2, subvalid1, subvalid2, read2, read3, read4, read5, t_read2, t_read3, t_read4: ( ( read_char_io(t_read1, stdin, read2, success1, t_read2) and brackets_io(t_read2, read2, read3, subvalid1, t_read3) and read_char_io(t_read3, stdin, read4, success2, t_read4) and brackets_io(t_read4, read4, read5, subvalid2, t_read5) and valid == (subvalid1 and read3 is ')' and subvalid2) ) if read1 is '(' else ( no_op_io(t_read1, t_read5) and read5 is read1 and valid == (read1 is None or read1 is ')') ) ) )
def print_unary_io(t_pre: Place, number: int, t_end: Place = Result()) -> bool: Terminates(True) TerminationMeasure(number + 2 if number >= 1 else 2) return IOExists2(Place, bool)(lambda t2, success: ( (write_char_io(t_pre, stdout, '1', success, t2) and print_unary_io( t2, number - 1, t_end)) if number >= 1 else (no_op_io(t_pre, t_end))))
def test_condition_io4(t_pre: Place, value: bool, t_post: Place = Result()) -> bool: Terminates(value) TerminationMeasure(2) #:: ExpectedOutput(termination_check.failed:child_termination.not_implied) return (Implies(value, non_terminating_io(t_pre, t_post)) and no_op_io(t_pre, t_post))
def test_measure_decreasing_io3(t_pre: Place, value: int, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(max(value + 2, 2)) return (test_measure_decreasing_io3(t_pre, value - 1, t_post) if value > 0 else no_op_io(t_pre, t_post))
def test_measure_io3_non_basic(t_pre: Place, value: int, t_post: Place = Result()) -> bool: Terminates(True) #:: ExpectedOutput(termination_check.failed:termination_measure.non_positive) TerminationMeasure(value) #:: ExpectedOutput(carbon)(termination_check.failed:measure.non_decreasing) return no_op_io(t_pre, t_post)
def main(t1: Place) -> Place: IOExists1(Place)(lambda t2: ( Requires(token(t1) and main_io(t1, t2)), Ensures(token(t2) and t2 == Result()), )) t2 = GetGhostOutput(main_io(t1), 't_post') # type: Place Open(main_io(t1)) success = True t_loop = t1 while success: Invariant( token(t_loop, 1) and tee_io(t_loop, t2) if success else token(t_loop) and no_op_io(t_loop, t2)) Open(tee_io(t_loop)) c, success, t_loop = getchar(t_loop) if success: t_loop = tee_out(t_loop, c) return NoOp(t_loop)
def output_io( t_pre: Place, client_socket: Socket, data: str, t_post: Place = Result()) -> bool: Terminates(True) TerminationMeasure(2) return IOExists4(Place, Place, Place, Place)( lambda t1, t2, t3, t4: ( ( split_io(t_pre, t1, t2) and send_io(t1, client_socket, data, t3) and print_io(t2, get_address(client_socket), t4) and join_io(t3, t4, t_post) ) if data is not None else no_op_io(t_pre, t_post) ) )
def ensure_dir_exists_io2( t_pre: Place, path: str, exception: OSErrorWrapper = Result(), t_post: Place = Result() ) -> bool: """Ensure that directory exists IO. This IO allows the implementation to propagate exceptions. However, it strictly specifies which exceptions can be propagated (in this case only ``ex1``). """ Terminates(True) TerminationMeasure(2) return IOExists4(OSErrorWrapper, OSErrorWrapper, Place, bool)( lambda ex1, ex2, t2, is_dir_res: (mkdir_io(t_pre, path, ex1, t2) and ( (no_op_io(t2, t_post) and exception is None) if ex1 is None else (is_dir_io(t2, path, ex2, is_dir_res, t_post) and ((Implies(is_dir_res, exception is None) and Implies( not is_dir_res, exception is ex1)) if ex2 is None else (exception == ex1))))))
def test_measure_io2_non_basic(t_pre: Place, value: int, t_post: Place = Result()) -> bool: TerminationMeasure(value) return no_op_io(t_pre, t_post)
def matching_brackets(t1: Place, t2: Place = Result()) -> bool: return no_op_io(t1, t2) and matching_brackets_helper(t1, t2)
def test_condition_io5(t_pre: Place, value: bool, t_post: Place = Result()) -> bool: Terminates(value) TerminationMeasure(2) return (Implies(not value, non_terminating_io(t_pre, t_post)) and no_op_io(t_pre, t_post))
def test_gap_io4(t_pre: Place, value: bool, t_post: Place = Result()) -> bool: Terminates(value) TerminationMeasure(2) return (Implies(not value, gap_io(t_pre, t_post)) and no_op_io(t_pre, t_post))
def test_gap_io6(t_pre: Place, value: bool, t_post: Place = Result()) -> bool: Terminates(value) TerminationMeasure(2) return gap_io(t_pre, t_post) if not value else no_op_io(t_pre, t_post)
def test_gap_io5(t_pre: Place, value: bool, t_post: Place = Result()) -> bool: Terminates(value) TerminationMeasure(2) #:: ExpectedOutput(termination_check.failed:gap.enabled) return gap_io(t_pre, t_post) if value else no_op_io(t_pre, t_post)