Esempio n. 1
0
def test_sss_isosceles():
  geometry.reset()

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

  A, B, C = map(Point, 'ABC')
  ab, bc, ca = map(Line, 'ab bc ca'.split())
  AB, CA = map(Segment, 'AB CA'.split())

  init_state.add_relations(
      segment_def(AB, A, B) +
      segment_def(CA, C, A) +
      collinear(ab, A, B) +
      collinear(ca, C, A) +
      have_length('1m', AB, CA)
  )

  init_state.add_spatial_relations(
      init_canvas.add_isosceles_triangle(A, B, C, ab, bc, ca))

  state, canvas = init_state.copy(), init_canvas.copy()

  # Original thales + noises
  steps = ['SSS: B A C C A B']

  print('\nRunning SSS isosceles test:')
  state, canvas, action_chain = action_chain_lib.execute_steps(steps, state, canvas)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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']
Esempio n. 5
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))
Esempio n. 6
0
def init_by_thales():
    geometry.reset()
    init_state, init_canvas, _ = init_by_normal_triangle()
    state, canvas = init_state.copy(), init_canvas.copy()

    steps = [
        (theorems.all_theorems['mid'], 'A=A B=B'),  # P1
        (theorems.all_theorems['parallel'], 'A=P1 l=bc'),  # l1
        (theorems.all_theorems['seg_line'], 'l=l1 A=A B=C'),  # P1
        (theorems.all_theorems['parallel'], 'A=C l=ab'),  # l2
        (theorems.all_theorems['line'], 'A=P1 B=C'),  # l3
    ]
    return state, canvas, steps
Esempio n. 7
0
def init_by_debug_001():
    geometry.reset()
    init_state, init_canvas, _ = init_by_normal_triangle()
    state, canvas = init_state.copy(), init_canvas.copy()

    steps = [
        (theorems.all_theorems['parallel'], 'A=B B=ca'),  # l1
        (theorems.all_theorems['bisect'], 'hp1=ab_hp2 hp2=l1_hp1'),  # l2
        (theorems.all_theorems['seg_line'], 'l=l2 A=C B=A'),  # P1
        (theorems.all_theorems['eq'], 'l=l2 l1=l1 l2=ca'),  # l2
        (theorems.all_theorems['mirror'], 'A=P1 B=B'),  # l2
        (theorems.all_theorems['asa'],
         'A=P1 B=A C=B D=B F=P1 de=ab ef=ca'),  # bug??
    ]
    return state, canvas, steps
Esempio n. 8
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
Esempio n. 9
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))
Esempio n. 10
0
def init_by_isosceles_triangle():
    geometry.reset()
    canvas = sketch.Canvas()
    state = State()

    A, B, C = map(Point, 'ABC')
    ab, bc, ca = map(Line, 'ab bc ca'.split())
    AB, BC, CA = map(Segment, 'AB BC CA'.split())

    state.add_relations(
        # [A, B, C, ab, bc, ca, AB, BC, CA] +
        segment_def(AB, A, B) + segment_def(BC, B, C) + segment_def(CA, C, A) +
        collinear(ab, A, B) + collinear(bc, B, C) + collinear(ca, C, A) +
        have_length('1m', AB, CA))

    state.add_spatial_relations(canvas.add_triangle(A, B, C, ab, bc, ca))
    canvas.update_hps(state.line2hps)
    return state, canvas, [(theorems.all_theorems['right'], '')]
Esempio n. 11
0
def test_gelernter_trapezoid():
  geometry.reset()

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

  steps = [
      'trapezoid: ',
      'midp: P1 P3',  # P5 l5
      'midp: P2 P4',  # P6 l6
      'line: P5 P6',  # l7
      'lineXsegment: l7 P1 P4',  # P7
      'line: P3 P6',  # l8
      'ASA: P4 P6 P3 P2 P6',
  ]

  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)
Esempio n. 12
0
def test_asa_isosceles():
  geometry.reset()

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

  A, B, C = map(Point, 'ABC')
  ab, bc, ca = map(Line, 'ab bc ca'.split())
  ab_hp, bc_hp, ca_hp = map(HalfPlane, 'ab_hp bc_hp ca_hp'.split())
  d_ab, d_bc, d_ca = LineDirection('d_ab'), LineDirection('d_bc'), LineDirection('d_ca')

  B_xx, B_xo, B_def = fangle_def(d_ab, d_bc)
  C_xx, C_xo, C_def = fangle_def(d_ca, d_bc)

  init_state.add_relations(
      collinear(ab, A, B) +
      collinear(bc, B, C) +
      collinear(ca, C, A) +
      divides_halfplanes(ab, ab_hp, p1=C) +
      divides_halfplanes(ca, ca_hp, p1=B) +
      divides_halfplanes(bc, bc_hp, p1=A) +
      have_direction(d_ab, ab) +
      have_direction(d_ca, ca) +
      have_direction(d_bc, bc) +
      B_def + C_def
  )

  line2points = init_canvas.add_isosceles_triangle(A, B, C, ab, bc, ca)
  init_state.add_spatial_relations(line2points)
  init_canvas.update_hps(init_state.line2hps)

  B_angle = B_xx if ab_hp.sign == bc_hp.sign else B_xo
  C_angle = C_xx if ca_hp.sign == bc_hp.sign else C_xo

  init_state.add_relations(
      have_measure('m1', B_angle, C_angle))

  state, canvas = init_state.copy(), init_canvas.copy()

  # Original thales + noises
  steps = ['ASA: C B A B C ab ca']

  print('\nRunning ASA isosceles test:')
  action_chain_lib.execute_steps(steps, state, canvas)
Esempio n. 13
0
def test_ang_isos_outer_bisect_parallel_to_base():
  geometry.reset()

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

  steps = [
      'ang_isos:',
      'angle_bisect: l1_hp hp3'
  ]

  print('\nRunning test_ang_isos_outer_bisect_parallel_to_base:')
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)

  assert len([v for v in state.val2valrel 
              if isinstance(v, LineDirection)]) == 3
  assert len([v for v in state.val2valrel 
              if isinstance(v, AngleMeasure)]) == 2
Esempio n. 14
0
def test_angle_bisect_isosceles():
  geometry.reset()

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

  A, B, C = map(Point, 'ABC')
  ab, bc, ca = map(Line, 'ab bc ca'.split())
  AB, CA = map(Segment, 'AB CA'.split())

  ab_hp, ca_hp = map(HalfPlane, 'ab_hp ca_hp'.split())

  init_state.add_relations(
      distinct(A, B, C) +
      distinct(ab, ca) + 
      segment_def(AB, A, B) +
      segment_def(CA, C, A) +
      divides_halfplanes(ab, ab_hp, p1=C) +
      divides_halfplanes(ca, ca_hp, p1=B) +
      collinear(ab, A, B) +
      collinear(ca, C, A) +
      have_length('1m', AB, CA)
  )

  line2points = init_canvas.add_isosceles_triangle(A, B, C, ab, bc, ca)
  init_state.add_spatial_relations(line2points)
  init_canvas.update_hps(init_state.line2hps)

  state, canvas = init_state.copy(), init_canvas.copy()

  # Original thales + noises
  steps = [
      'angle_bisect: ab_hp ca_hp',
      'lineXsegment: l1 B C',
      'SAS: A B P1 A C P1'
  ]

  print('\nRunning test_angle_bisect_isosceles:')
  state, canvas, action_chain = action_chain_lib.execute_steps(steps, state, canvas)
Esempio n. 15
0
def test_ang_isos_perp_base_is_bisect():
  geometry.reset()

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

  steps = [
      'ang_isos:',
      'midp: P2 P3',  # -> P4
      'perp: P4 l2',  # l4
  ]

  print('Running test_ang_isos_perp_base_is_bisect')
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)
  
  measures = [v for v in state.val2valrel 
              if isinstance(v, AngleMeasure)]
  assert len(measures) == 5

  l14xx, l14xo = state.angle_between('l1', 'l4')
  l34xx, l34xo = state.angle_between('l3', 'l4')
  assert state.is_equal(l14xx, l34xx) and state.is_equal(l14xo, l34xo)
Esempio n. 16
0
def test_base_bisect_sss_isosceles():
  geometry.reset()

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

  A, B, C = map(Point, 'ABC')
  ab, bc, ca = map(Line, 'ab bc ca'.split())
  AB, CA = map(Segment, 'AB CA'.split())

  init_state.add_relations(
      # [A, B, C, AB, BC, CA, ab, bc, ca] +
      distinct(A, B, C) +
      segment_def(AB, A, B) +
      segment_def(CA, C, A) +
      collinear(ab, A, B) +
      collinear(bc, B, C) +
      collinear(ca, C, A) +
      have_length('1m', AB, CA)
  )

  line2points = init_canvas.add_isosceles_triangle(A, B, C, ab, bc, ca)
  init_state.add_spatial_relations(line2points)
  init_canvas.update_hps(init_state.line2hps)

  init_canvas.add_free_points(bc, B, C)

  state, canvas = init_state.copy(), init_canvas.copy()

  steps = [
      'midp: B C',  # -> P1
      'line: A P1',
      'SSS: B A P1 C A P1'
  ]

  print('\nRunning test_base_bisect_sss_isosceles:')
  action_chain_lib.execute_steps(steps, state, canvas)
Esempio n. 17
0
def test_ang_isos_bisect_is_perp():
  geometry.reset()

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

  steps = [
      'ang_isos:',
      # hp = halfplane
      'angle_bisect: hp1 hp3'  # -> l4
  ]

  print('\nRunning test_ang_isos_bisect_is_perp:')
  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, init_state, init_canvas)

  assert len([v for v in state.val2valrel 
              if isinstance(v, LineDirection)]) == 4

  print([v.name for v in state.val2valrel 
              if isinstance(v, AngleMeasure)])

  assert len([v for v in state.val2valrel 
              if isinstance(v, AngleMeasure)]) == 5
  
  # test that halfpi is amongst the list of angles created.
  halfpi, _ = geometry.get_constant_angles(0.5)
  assert any([halfpi in state.obj2valrel])
  mhalfpi = state.obj2valrel[halfpi].init_list[1]
  assert len(state.val2valrel[mhalfpi]) == 3

  # Test that we cannot create perp line from P1 to l2
  # because l4 has already been figured out that it is perp to l2.
  theorem, mapping = action_chain_lib.extract_theorem_mapping('perp: P1 l2', state)
  action_gen = theorem.match_from_input_mapping(
      state, mapping, randomize=False, canvas=canvas)
  assert len(list(action_gen)) == 0

  steps = [
      'lineXlineA: l4 l2',
      'ASA: P1 P5'
  ]

  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, state, canvas, init_action_chain=action_chain)

  # import pdb; pdb.set_trace()
  assert len([v for v in state.val2valrel 
              if isinstance(v, SegmentLength)]) == 2
  
  # undo asa and lineXline and bisector
  state, canvas, action_chain = rewind(action_chain, 3)
  steps = [
      'perp: P1 l2',  # l5 P6
      'ASA: P1 None None None P6 None None'
  ]

  state, canvas, action_chain = action_chain_lib.execute_steps(
      steps, state, canvas, init_action_chain=action_chain)

  assert len([v for v in state.val2valrel 
              if isinstance(v, LineDirection)]) == 4
  assert len([v for v in state.val2valrel 
              if isinstance(v, AngleMeasure)]) == 5
  assert len([v for v in state.val2valrel 
              if isinstance(v, SegmentLength)]) == 2

  # test that halfpi is amongst the list of angles created.
  halfpi, _ = geometry.get_constant_angles(0.5)
  assert any([halfpi in state.obj2valrel])
  mhalfpi = state.obj2valrel[halfpi].init_list[1]
  assert len(state.val2valrel[mhalfpi]) == 3
Esempio n. 18
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))
Esempio n. 19
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))
Esempio n. 20
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']