Beispiel #1
0
def test_thales_noise_shuffle_merge_goal2():
  geometry.reset()

  init_canvas = sketch.Canvas()
  init_state = State()

  print('\nRunning test_thales_noise_shuffle_merge_goal2:')

  steps = [
      'triangle:',  # P1 P2 P3
      'parallel: P1 l2',  # -> l4
      'parallel: P3 l1',  # -> l5
      'midp: P1 P2',  # -> P4
      'line: P4 P3',  # -> l6
      'parallel: P4 l2',  # -> l7
      'midp: P2 P3',  # -> P5
      'lineXlineD: l7 l3',  # -> P6
      'ASA: P4 P3 P2 P3 P4 l5 l7',  # -> P7
      'midp: P1 P3',  # -> P8
      'parallel: P8 l2',  # l8
      'ASA: P1 P4 P6 P3 P7 l3 l7',  # P7 == P5
  ]

  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)

  prev_state = action_chain[-1].state
  proof_goals = list(whittling.extract_all_proof_goals(action_chain, state))
  
  # Check if all the goals are here:
  name2goals = extract_name2goals(proof_goals, state, prev_state)
  
  state_queue, proof_queue = name2goals['l8{P4}']
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)
  
  assert proof_steps == [2, 4, 5, 7, 8, 11]
  l8 = problem.name2obj['l8']
  P4 = problem.name2obj['P4']
  assert not problem.has_relation(LineContainsPoint(l8, P4))

  steps = [
      'parallel: P3 l1',  # --> l9
      'line: P4 P3',  # --> l10
      'parallel: P4 l2',  # l11
      'lineXlineD: l11 l3',  # P9
      'ASA: P4 P3 P2 P3 P4',  # --> P10
      'ASA: P1 P4 P9 P3 P10',
  ]
  print('Proof execution:')
  proved_problem, proved_canvas, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)
  assert proved_problem.has_relation(LineContainsPoint(l8, P4))
Beispiel #2
0
def test_isos_merge_lines():
  geometry.reset()

  canvas = sketch.Canvas()
  state = State()

  print('\nRunning Isos Merge test:')

  steps = [
      'ang_isos:',
      'angle_bisect: hp1 hp3',  # -> l4
      'lineXlineA: l4 l2',  # -> P4
      'midp: P2 P3',  # -> P5
      'perp: P5 l2',  # -> l5
  ]
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, state, canvas)

  halfpi, _ = geometry.get_constant_angles(0.5)
  assert any([halfpi in state.obj2valrel])
  mhalfpi = state.obj2valrel[halfpi].init_list[1]

  state.print_all_equal_angles()
  measure2angles = state.all_equal_angles()
  state.print_all_equal_angles()
  assert len(measure2angles[mhalfpi]) == 9, len(measure2angles[mhalfpi])
  # exit()

  d4 = state.name2obj['d4']
  assert len(state.val2valrel[d4]) == 2

  l5 = state.name2obj['l5']
  P1 = state.name2obj['P1']
  assert not state.has_relation(LineContainsPoint(l5, P1))

  steps = [
      'ASA: P4 P1',
  ]
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, state, canvas, init_action_chain=action_chain)
  
  assert len(state.val2valrel[d4]) == 1

  measure2angles = state.all_equal_angles()
  assert len(measure2angles[mhalfpi]) == 5

  assert state.has_relation(LineContainsPoint(l5, P1))
Beispiel #3
0
def test_isos_merge_whittle_goal2():
  geometry.reset()

  init_canvas = sketch.Canvas()
  init_state = State()

  print('\nRunning Isos Merge whittle goal2 test:')

  steps = [
      'ang_isos:',
      'angle_bisect: hp1 hp3',  # -> l4
      'lineXlineA: l4 l2',  # -> P4
      'midp: P2 P3',  # -> P5
      'perp: P5 l2',  # -> l5
      'ASA: P4 P1',  # -> Now l5 contains P1, l4 contains P5
  ]
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)

  # state.print_all_equal_segments()
  prev_state = action_chain[-1].state

  proof_goals = list(whittling.extract_all_proof_goals(action_chain, state))
  
  # Check if all the goals are here:
  name2goals = extract_name2goals(proof_goals, state, prev_state)

  all_target_goals = [
      'l5{P4}', 'P4[P5P3', 'P4[P5P2', 
      'l4{P5}', 'l5/l4_hp1', 'l5/l4_hp2', 
      'l5{P1}', 'l4/l5_hp2', 'l4/l5_hp1']
  for goal in all_target_goals:
    assert goal in name2goals, goal
  
  state_queue, proof_queue = name2goals['l4{P5}']
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)

  assert proof_steps == [2, 5]

  steps = [
      'lineXlineA: l4 l2',  # -> P6
      'ASA: P6 P1',  # -> Now l6 contains P1
  ]
  print('Proof execution:')
  proved_problem, _, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)

  l4 = proved_problem.name2obj['l4']
  P5 = proved_problem.name2obj['P5']
  assert proved_problem.has_relation(LineContainsPoint(l4, P5))

  last_state = action_chain[-1].state
  P6 = last_state.name2obj['P6']
  assert P6 in P5.merge_graph[proved_problem]['equivalents']
Beispiel #4
0
def get_or_add_line(state, canvas, line_name, p1_name, p2_name):
    p1 = state.name2obj[p1_name]
    p2 = state.name2obj[p2_name]

    line2points = ddict(lambda: [])
    for rel in state.type2rel[LineContainsPoint]:
        line, point = rel.init_list
        line2points[line].append(point)

    for line, points in line2points.items():
        if p1 in points and p2 in points:
            return line

    # print('Create new line {}'.format(line_name))
    line = Line(line_name)
    state.add_one(LineContainsPoint(line, p1))
    state.add_one(LineContainsPoint(line, p2))
    state.add_spatial_relations(canvas.add_line(line, p1, p2))
    return line
Beispiel #5
0
def collinear(l, *point_list):
  return [LineContainsPoint(l, p) for p in list(point_list)]
Beispiel #6
0
def test_isos_merge_whittle_v3():
  geometry.reset()

  init_canvas = sketch.Canvas()
  init_state = State()

  print('\nRunning Isos Merge whittle v3 test:')

  steps = [
      'ang_isos:',
      'midp: P2 P3',  # -> P4
      'perp: P4 l2',  # -> l4
      'lineXlineA: l4 l1',  # -> P5
  ]
  state3, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)
  steps = [
      'ASA: P2 P4',  # -> Now l5 contains P1, l4 contains P5
  ]
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, state3, canvas, init_action_chain=action_chain)

  prev_state = action_chain[-1].state
  proof_goals = list(whittling.extract_all_proof_goals(action_chain, state))
  
  # Check if all the goals are here:
  name2goals = extract_name2goals(proof_goals, state, prev_state)

  l3 = state.name2obj['l3']
  P5 = state.name2obj['P5']
  assert state.has_relation(LineContainsPoint(l3, P5))

  all_target_goals = ['l3{P5}', '4.P2P5 == 4.P3P5', 'l4{P1}']
  for goal in all_target_goals:
    assert goal in name2goals, goal
    state_queue, proof_queue = name2goals[goal]
    problem, problem_canvas, proof_steps = whittle(
        state, state_queue, proof_queue, action_chain,
        init_state, init_canvas, canvas, verbose=False)
  
  state_queue, proof_queue = name2goals['l3{P5}']
  # there will be fragments of 1. construct angle bisector
  # in the whittled problem, but that's okay
  # what we care is the aggregated problem, not its construction
  # on the other hand, proof construction is what we really
  # have to care about.
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)

  assert not problem.has_relation(LineContainsPoint(l3, P5))
  assert proof_steps == [4], proof_steps

  steps = [
      'ASA: P4',
  ]
  print('Proof execution:')
  proved_problem, _, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)

  P5_equivs = P5.merge_graph[proved_problem]['equivalents']
  P5_equivs_name = map(lambda x: x.name, P5_equivs)
  assert set(P5_equivs_name) == {'P1', 'P7'}
  assert proved_problem.has_relation(LineContainsPoint(l3, P5))
Beispiel #7
0
def test_isos_merge_whittle_v2():
  geometry.reset()

  init_canvas = sketch.Canvas()
  init_state = State()

  print('\nRunning Isos Merge whittle v2 test:')

  steps = [
      'ang_isos:',
      'angle_bisect: hp1 hp3',  # -> l4
      'lineXlineA: l4 l2',  # -> P4
      'midp: P2 P3',  # -> P5
      'perp: P5 l2',  # -> l5
      'lineXlineA: l5 l1',  # -> P6
      'ASA: P4 P1',  # -> Now l5 contains P1, l4 contains P5
  ]
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)

  # state.print_all_equal_segments()
  prev_state = action_chain[-1].state

  proof_goals = list(whittling.extract_all_proof_goals(action_chain, state))
  
  # Check if all the goals are here:
  name2goals = extract_name2goals(proof_goals, state, prev_state)

  all_target_goals = [
      'l4{P6}', 'l3{P6}',
      'l5{P4}', 'P4[P5P3', 'P4[P5P2', 
      'l4{P5}', 'l5/l4_hp1', 'l5/l4_hp2', 
      'l5{P1}', 'l4/l5_hp2', 'l4/l5_hp1']
  for goal in all_target_goals:
    assert goal in name2goals, goal
    state_queue, proof_queue = name2goals[goal]
    problem, problem_canvas, proof_steps = whittle(
        state, state_queue, proof_queue, action_chain,
        init_state, init_canvas, canvas, verbose=False)
  
  state_queue, proof_queue = name2goals['l3{P6}']
  # there will be fragments of 1. construct angle bisector
  # in the whittled problem, but that's okay
  # what we care is the aggregated problem, not its construction
  # on the other hand, proof construction is what we really
  # have to care about.
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)

  l3 = problem.name2obj['l3']
  P6 = problem.name2obj['P6']
  assert not problem.has_relation(LineContainsPoint(l3, P6))

  assert proof_steps == [1, 2, 6], proof_steps

  steps = [
      'angle_bisect: hp1 hp3',  # -> l6
      'lineXlineA: l6 l2',  # -> P7
      'ASA: P7 P1',  # -> Now l5 contains P1, l4 contains P5
  ]
  print('Proof execution:')
  proved_problem, _, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)

  assert proved_problem.has_relation(LineContainsPoint(l3, P6))
Beispiel #8
0
def test_isos_merge_whittle_goal1():
  geometry.reset()

  init_canvas = sketch.Canvas()
  init_state = State()

  print('\nRunning Isos Merge Whittle goal1 test:')

  steps = [
      'ang_isos:',
      'angle_bisect: hp1 hp3',  # -> l4
      'lineXlineA: l4 l2',  # -> P4
      'midp: P2 P3',  # -> P5
      'perp: P5 l2',  # -> l5
      'ASA: P4 P1',  # -> Now l5 contains P1
  ]
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)

  # state.print_all_equal_segments()
  prev_state = action_chain[-1].state

  l5 = state.name2obj['l4']
  P1 = state.name2obj['P1']
  assert state.has_relation(LineContainsPoint(l5, P1))

  proof_goals = list(whittling.extract_all_proof_goals(action_chain, state))
  
  # Check if all the goals are here:
  name2goals = extract_name2goals(proof_goals, state, prev_state)

  all_target_goals = [
      ('l5{P4}', [5]), 
      ('P4[P5P3', [5]), 
      ('P4[P5P2', [5]), 
      ('l4{P5}', [2, 5]), 
      ('l5/l4_hp1', [2, 5]), 
      ('l5/l4_hp2', [2, 5]), 
      ('l5{P1}', [1, 2, 5]), 
      ('l4/l5_hp2', [2, 5]), 
      ('l4/l5_hp1', [2, 5])
  ]
  for goal, correct_proof_steps in all_target_goals:
    assert goal in name2goals, goal
    state_queue, proof_queue = name2goals[goal]
    _, _, proof_steps = whittle(
        state, state_queue, proof_queue, action_chain,
        init_state, init_canvas, canvas, verbose=False)
    print('check whittle({}) = {}'.format(goal, correct_proof_steps))
    assert correct_proof_steps == proof_steps
  
  state_queue, proof_queue = name2goals['l5{P1}']
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)

  assert proof_steps == [1, 2, 5]
  steps = [
      'angle_bisect: hp1 hp3',  # -> l6
      'lineXlineA: l6 l2',  # -> P6
      'ASA: P6 P1',  # -> Now l6 contains P1
  ]
  print('Proof execution:')
  proved_problem, _, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)

  l5 = proved_problem.name2obj['l5']
  P1 = proved_problem.name2obj['P1']
  assert proved_problem.has_relation(LineContainsPoint(l5, P1))

  last_state = action_chain[-1].state
  l6 = last_state.name2obj['l6']
  assert l6 in l5.merge_graph[proved_problem]['equivalents']