Exemplo n.º 1
0
def test_thales():
  geometry.reset()

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

  print('\nRunning test_thales:')

  steps = [
      'triangle:',  # P1 P2 P3
      'midp: P1 P2',  # -> P4
      'parallel: P4 l2',  # -> l4
      'lineXlineD: l4 l3',  # -> P5
      'parallel: P3 l1',  # -> l5
      'line: P4 P3',  # -> l6
      'ASA: P4 P3 P2 P3 P4',  # -> P6
      'ASA: P1 P4 P5 P3 P6'  # 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)
  all_target_goals = ['7.P5P4 == 7.P5P6', '7.P1P5 == 7.P3P5']
  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['7.P1P5 == 7.P3P5']
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)
  
  assert proof_steps == [4, 5, 6, 7], proof_steps
  P1P5 = problem.segment_between('P1', 'P5')
  P3P5 = problem.segment_between('P3', 'P5')
  assert not problem.is_equal(P1P5, P3P5)

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

  steps = [
      'parallel: P3 l1',  # --> l7
      'line: P4 P3',
      'ASA: P4 P3 P2 P3 P4',  # --> P7
      'ASA: P1 P4 P5 P3 P7',
  ]
  print('Proof execution:')
  proved_problem, _, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)
  assert proved_problem.is_equal(P1P5, P3P5)
Exemplo n.º 2
0
def test_thales_noise_shuffle():
  geometry.reset()

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

  print('\nRunning test_thales_noise_shuffle:')

  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',  # -> P7
      'ASA: P1 P4 P6 P3 P7'  # 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)
  all_target_goals = ['9.P6P4 == 9.P6P7', '9.P1P6 == 9.P3P6']
  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['9.P1P6 == 9.P3P6']
  problem, problem_canvas, proof_steps = whittle(
      state, state_queue, proof_queue, action_chain,
      init_state, init_canvas, canvas)
  
  assert proof_steps == [2, 4, 8, 9]
  P1P6 = problem.segment_between('P1', 'P6')
  P3P6 = problem.segment_between('P3', 'P6')
  assert not problem.is_equal(P1P6, P3P6)

  steps = [
      'parallel: P3 l1',  # --> l8
      'line: P4 P3',  # --> l9
      'ASA: P4 P3 P2 P3 P4',  # --> P8
      'ASA: P1 P4 P6 P3 P8',
  ]
  print('Proof execution:')
  proved_problem, _, action_chain = action_chain_lib.execute_steps(
      steps, problem, problem_canvas)
  assert proved_problem.is_equal(P1P6, P3P6)
Exemplo n.º 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']
Exemplo n.º 4
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))
Exemplo n.º 5
0
def test_gelernter_equidistance():
  geometry.reset()

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

  X = Point()
  l1, l2 = Line(), Line()
  hp11, hp12, hp21, hp22 = map(HalfPlane, 'hp11 hp12 hp21 hp22'.split())

  init_state.add_relations(
      divides_halfplanes(l1, hp11, hp12) +
      divides_halfplanes(l2, hp21, hp22) +
      collinear(l1, X) +
      collinear(l2, X) +
      distinct(l1, l2)
  )

  info = init_canvas.add_random_angle(X, l1, l2)
  init_state.add_spatial_relations(info)
  init_canvas.update_hps(init_state.line2hps)

  steps = [
      'angle_bisect: hp11 hp21',  # l3
      'free_p_on_l: l3',
      'perp: P2 l1',
      'perp: P2 l2',
      'ASA:'
  ]

  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)

  all_target_goals = ['4.P1P3 == 4.P1P4', '4.P3P2 == 4.P4P2']

  for goal 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)
    assert proof_steps == [4], proof_steps
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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']