Skip to content

Commit 6661d02

Browse files
thtrieucopybara-github
authored andcommitted
Initial open source code for Nature research paper AlphaGeometry.
PiperOrigin-RevId: 592527496 Change-Id: I3ff16080f01cecafe54088e87bb9f2884466367c
1 parent 3d86172 commit 6661d02

40 files changed

+16547
-16
lines changed

README.md

+418-16
Large diffs are not rendered by default.

alphageometry.py

+645
Large diffs are not rendered by default.

alphageometry_test.py

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
16+
"""Unit tests for alphageometry.py."""
17+
18+
import unittest
19+
20+
from absl.testing import absltest
21+
import alphageometry
22+
23+
24+
class AlphaGeometryTest(unittest.TestCase):
25+
26+
def test_translate_constrained_to_constructive(self):
27+
self.assertEqual(
28+
alphageometry.translate_constrained_to_constructive(
29+
'd', 'T', list('addb')
30+
),
31+
('on_dia', ['d', 'b', 'a']),
32+
)
33+
self.assertEqual(
34+
alphageometry.translate_constrained_to_constructive(
35+
'd', 'T', list('adbc')
36+
),
37+
('on_tline', ['d', 'a', 'b', 'c']),
38+
)
39+
self.assertEqual(
40+
alphageometry.translate_constrained_to_constructive(
41+
'd', 'P', list('bcda')
42+
),
43+
('on_pline', ['d', 'a', 'b', 'c']),
44+
)
45+
self.assertEqual(
46+
alphageometry.translate_constrained_to_constructive(
47+
'd', 'D', list('bdcd')
48+
),
49+
('on_bline', ['d', 'c', 'b']),
50+
)
51+
self.assertEqual(
52+
alphageometry.translate_constrained_to_constructive(
53+
'd', 'D', list('bdcb')
54+
),
55+
('on_circle', ['d', 'b', 'c']),
56+
)
57+
self.assertEqual(
58+
alphageometry.translate_constrained_to_constructive(
59+
'd', 'D', list('bacd')
60+
),
61+
('eqdistance', ['d', 'c', 'b', 'a']),
62+
)
63+
self.assertEqual(
64+
alphageometry.translate_constrained_to_constructive(
65+
'd', 'C', list('bad')
66+
),
67+
('on_line', ['d', 'b', 'a']),
68+
)
69+
self.assertEqual(
70+
alphageometry.translate_constrained_to_constructive(
71+
'd', 'C', list('bad')
72+
),
73+
('on_line', ['d', 'b', 'a']),
74+
)
75+
self.assertEqual(
76+
alphageometry.translate_constrained_to_constructive(
77+
'd', 'O', list('abcd')
78+
),
79+
('on_circum', ['d', 'a', 'b', 'c']),
80+
)
81+
82+
def test_insert_aux_to_premise(self):
83+
pstring = 'a b c = triangle a b c; d = on_tline d b a c, on_tline d c a b ? perp a d b c' # pylint: disable=line-too-long
84+
auxstring = 'e = on_line e a c, on_line e b d'
85+
86+
target = 'a b c = triangle a b c; d = on_tline d b a c, on_tline d c a b; e = on_line e a c, on_line e b d ? perp a d b c' # pylint: disable=line-too-long
87+
self.assertEqual(
88+
alphageometry.insert_aux_to_premise(pstring, auxstring), target
89+
)
90+
91+
def test_beam_queue(self):
92+
beam_queue = alphageometry.BeamQueue(max_size=2)
93+
94+
beam_queue.add('a', 1)
95+
beam_queue.add('b', 2)
96+
beam_queue.add('c', 3)
97+
98+
beam_queue = list(beam_queue)
99+
self.assertEqual(beam_queue, [(3, 'c'), (2, 'b')])
100+
101+
102+
if __name__ == '__main__':
103+
absltest.main()

0 commit comments

Comments
 (0)