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_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. 3
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. 4
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. 5
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. 6
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)