ユークリッド幾何学以外における記述法と三角形定理ループの統合
元の記述法と統合することになったんで、まずは三角形定理ループだとかを元の記述法に置き換えてみた。
triangle_lst = [ "△ABC" : ["HAI", "AB", "CBI", "BC", "BCH", "AC"], "△ACD" : ["DAH", "AC", "DCH", "CD", "ADC", "AD"], "△ADH" : ["DAH", "AD", "ADG", "DH", "AHG", "AH"], "△ADI" : ["DAI", "AD", "ADG", "DI", "AIH", "AI"], "△AHI" : ["HAI", "AH", "AHI", "HI", "AIH", "AI"], "△BEI" : ["EBI", "BE", "BEI", "EI", "BIE", "BI"], "△CDE" : ["BCD", "CD", "CDG", "DE", "BEI", "CE"], "△CDG" : ["DCG", "CD", "CDG", "DG", "CGD", "CG"], "△CDH" : ["DCH", "CD", "CDG", "DH", "CHG", "CH"], "△CEF" : ["BCF", "CE", "BEF", "EF", "CFE", "CF"], "△CEG" : ["BCG", "CE", "BEI", "EG", "CGH", "CG"], "△CEH" : ["BCH", "CE", "BEI", "EH", "CHI", "CH"], "△CGH" : ["GCH", "CG", "CGH", "GH", "CHG", "CH"], ]; "AD" == "BC" == "EG" == "CF"; "AB" == "CD" == "EF" == "CG"; "DAI" == "BCD" == "FEI" == "EBI" == "CGD"; "ADC" == "CBI" == "CFE" == "CGH"; "AHG" == "CHI"; "AHI" == "CHG" == "FCH"; "AIH" == "BIE" == "CGG"; "AIE" == "BIH"; "DAH" == "BCH"; "ADG" == "BEI" == "BCF"; "HAI" == "DCH"; "BEF" == "BCG"; "DAH" + "HAI" == "DAI"; "EBI" + "CBI" == 180; "DCG" + "GCH" == "DCH"; "GCH" + "BCH" == "BCG"; "BCH" + "BCF" == "FCH"; "DCH" + "BCH" == "BCD"; "BCG" + "DCG" == "BCD"; "BCG" + "BCF" == "FCG"; "FCH" + "GCH" == "FCG"; "BCD" + "BCF" == "DCF"; "FCG" + "DCG" == "DCF"; "ADG" + "CDG" == "ADC"; "BEI" + "BEF" == "FEI"; "CGD" + "CGH" == 180; "AHG" + "CHG" == 180; "AIH" + "AIE" == 180; "HAI" + "BCH" == "EBI"; "BCG" + "BEI" == "CGD"; "DAH" + "ADG" == "AHI"; "DAI" + "ADG" == "AIE"; "DCG" + "CDG" == "CGH"; "EBI" + "BEI" == "BIH"; "BEI" + "BIE" == "CBI"; "HAI" + "AHI" == "BIH"; "HAI" + "AIH" == "AHG"; "DCH" + "CDG" == "AHG"; "GCH" + "CGH" == "CHI"; "GCH" + "CHG" == "CGD"; "AI" + "BI" == "AB"; "AH" + "CH" == "AC"; "BC" + "BE" == "CE"; "DG" + "EG" == "DE"; "DH" + "EH" == "DE"; "DI" + "EI" == "DE"; "DG" + "GH" == "DH"; "DG" + "GI" == "DI"; "DH" + "HI" == "DI"; "EI" + "GI" == "EG"; "EH" + "GH" == "EG"; "EI" + "HI" == "EH"; "GH" + "HI" == "GI"; def ele1_equal_ele2(ele1, ele2, loop_flg, exe_flg) { if not (ele1 == ele2) { ele1 == ele2; loop_flg := True; exe_flg := True; } return loop_flg, exe_flg; } def isosceles_angle_check(triangle_lst, exe_flg) { loop_flg := True; while loop_flg { loop_flg := False; for tri1 in triangle_lst.values() { for angle1, angle2, side1, side2 in [(tri1[0], tri1[2], tri1[5], tri1[3]), (tri1[2], tri1[4], tri1[1], tri1[5]), (tri1[0], tri1[4], tri1[1], tri1[3])] { if angle_1 == angle_2 { loop_flg, exe_flg := ele1_equal_ele2(side1, side2, loop_flg, exe_flg); } } } } return triangle_lst, exe_flg; } def isosceles_side_check(triangle_lst, exe_flg) { loop_flg := True; while loop_flg { loop_flg := False; for tri1 in triangle_lst.values() { for side1, side2, angle1, angle2 in [(tri1[1], tri1[3], tri1[0], tri1[4]), (tri1[3], tri1[5], tri1[2], tri1[0]), (tri1[1], tri1[5], tri1[2], tri1[4])] { if side1 == side2 { loop_flg, exe_flg := ele1_equal_ele2(angle1, angle2, loop_flg, exe_flg); } } } } return triangle_lst, exe_flg; } def two_angle_check(triangle_lst, exe_flg) { loop_flg := True; while loop_flg { loop_flg := False; for tri1 in triangle_lst.values() { for tri2 in triangle_lst.values() { if tri1 == tri2 { continue; } for angle_1_A, angle_1_B in itertools.combinations([tri1[0], tri1[2], tri1[4]], 2) { for angle_2_A, angle_2_B in itertools.combinations([tri2[0], tri2[2], tri2[4]], 2) { if (angle_1_A, angle_1_B) == (angle_2_A, angle_2_B) { angle_1_C := [A for A in [tri1[0], tri1[2], tri1[4]] if A not in [angle_1_A, angle_1_B]][0]; angle_2_C := [A for A in [tri2[0], tri2[2], tri2[4]] if A not in [angle_2_A, angle_2_B]][0]; loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_C, loop_flg, exe_flg); } } } } } } return triangle_lst, exe_flg; } def angle_side_angle(triangle_lst, exe_flg) { loop_flg := True; while loop_flg { loop_flg := False; for tri1 in triangle_lst.values() { for tri2 in triangle_lst.values() { if tri1 == tri2 { continue; } for angle_1_A, side_1, angle_1_B, side_1_X, angle_1_C, side_1_Y in [(tri1[0], tri1[1], tri1[2], tri1[3], tri1[4], tri1[5]), \ (tri1[2], tri1[3], tri1[4], tri1[5], tri1[0], tri1[1]), \ (tri1[4], tri1[5], tri1[0], tri1[1], tri1[2], tri1[3])] { for angle_2_A, side_2, angle_2_B, side_2_X, angle_2_C, side_2_Y in [(tri2[0], tri2[1], tri2[2], tri2[3], tri2[4], tri2[5]), \ (tri2[2], tri2[3], tri2[4], tri2[5], tri2[0], tri2[1]), \ (tri2[4], tri2[5], tri2[0], tri2[1], tri2[2], tri2[3])] { if side_1 == side_2 && (angle_1_A, angle_1_B) == (angle_2_A, angle_2_B) { loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_C, loop_flg, exe_flg); if angle_1_A == angle_2_A { loop_flg, exe_flg := ele1_equal_ele2(side_1_X, side_2_X, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(side_1_Y, side_2_Y, loop_flg, exe_flg); } else { loop_flg, exe_flg := ele1_equal_ele2(side_1_X, side_2_Y, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(side_1_Y, side_2_X, loop_flg, exe_flg); } } } } } } } return triangle_lst, exe_flg; } def side_angle_side(triangle_lst, exe_flg) { loop_flg := True; while loop_flg { loop_flg := False; for tri1 in triangle_lst.values() { for tri2 in triangle_lst.values() { if tri1 == tri2 { continue; } for side_1_A, angle_1, side_1_B, angle_1_X, side_1_C, angle_1_Y in [(tri1[1], tri1[2], tri1[3], tri1[4], tri1[5], tri1[0]), \ (tri1[3], tri1[4], tri1[5], tri1[0], tri1[1], tri1[2]), \ (tri1[5], tri1[0], tri1[1], tri1[2], tri1[3], tri1[4])] { for side_2_A, angle_2, side_2_B, angle_2_X, side_2_C, angle_2_Y in [(tri2[1], tri2[2], tri2[3], tri2[4], tri2[5], tri2[0]), \ (tri2[3], tri2[4], tri2[5], tri2[0], tri2[1], tri2[2]), \ (tri2[5], tri2[0], tri2[1], tri2[2], tri2[3], tri2[4])] { if angle_1 == angle_2 and (side_1_A, side_1_B) == (side_2_A, side_2_B) { loop_flg, exe_flg := ele1_equal_ele2(side_1_C, side_2_C, loop_flg, exe_flg); if side_1_A == side_2_A { loop_flg, exe_flg := ele1_equal_ele2(angle_1_X, angle_2_X, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_Y, angle_2_Y, loop_flg, exe_flg); } else { loop_flg, exe_flg := ele1_equal_ele2(angle_1_X, angle_2_Y, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_Y, angle_2_X, loop_flg, exe_flg); } } } } } } } return triangle_lst, exe_flg; } def side_side_side(triangle_lst, exe_flg) { loop_flg := True; while loop_flg { loop_flg := False; for tri1 in triangle_lst.values() { for tri2 in triangle_lst.values() { if tri1 == tri2 { continue; } angle_1_A, side_1_A, angle_1_B, side_1_B, angle_1_C, side_1_C := tri1; angle_2_A, side_2_A, angle_2_B, side_2_B, angle_2_C, side_2_C := tri2; if (side_1_A, side_1_B, side_1_C) == (side_2_A, side_2_B, side_2_C) { if side_1_A == side_2_A { if side_1_B == side_2_B { loop_flg, exe_flg := ele1_equal_ele2(angle_1_A, angle_2_A, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_B, angle_2_B, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_C, loop_flg, exe_flg); } elif side_1_B == side_2_C { loop_flg, exe_flg := ele1_equal_ele2(angle_1_A, angle_2_B, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_B, angle_2_A, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_C, loop_flg, exe_flg); } } elif side_1_A == side_2_B { if side_1_B == side_2_A { loop_flg, exe_flg := ele1_equal_ele2(angle_1_A, angle_2_C, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_B, angle_2_B, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_A, loop_flg, exe_flg); } elif side_1_B == side_2_C { loop_flg, exe_flg := ele1_equal_ele2(angle_1_A, angle_2_B, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_B, angle_2_C, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_A, loop_flg, exe_flg); } } elif side_1_A == side_2_C { if side_1_B == side_2_A { loop_flg, exe_flg := ele1_equal_ele2(angle_1_A, angle_2_C, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_B, angle_2_A, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_B, loop_flg, exe_flg); } elif side_1_B == side_2_B { loop_flg, exe_flg := ele1_equal_ele2(angle_1_A, angle_2_A, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_B, angle_2_C, loop_flg, exe_flg); loop_flg, exe_flg := ele1_equal_ele2(angle_1_C, angle_2_B, loop_flg, exe_flg); } } } } } } return triangle_lst, exe_flg; } def triangle_theorem_loop(triangle_lst) { exe_flg := True; while exe_flg: exe_flg := False; triangle_lst, exe_flg := isosceles_angle_check(triangle_lst, exe_flg); triangle_lst, exe_flg := isosceles_side_check(triangle_lst, exe_flg); triangle_lst, exe_flg := two_angle_check(triangle_lst, exe_flg); triangle_lst, exe_flg := angle_side_angle(triangle_lst, exe_flg); triangle_lst, exe_flg := side_angle_side(triangle_lst, exe_flg); triangle_lst, exe_flg := side_side_side(triangle_lst, exe_flg); return triangle_lst; } triangle_lst := triangle_theorem_loop(triangle_lst);