itp-interface 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (485) hide show
  1. itp_interface/__init__.py +0 -0
  2. itp_interface/agent/__init__.py +0 -0
  3. itp_interface/agent/simple_proof_agent.py +100 -0
  4. itp_interface/coq_ser_api/__init__.py +165 -0
  5. itp_interface/coq_ser_api/contexts.py +283 -0
  6. itp_interface/coq_ser_api/coq_agent.py +459 -0
  7. itp_interface/coq_ser_api/coq_backend.py +135 -0
  8. itp_interface/coq_ser_api/coq_util.py +839 -0
  9. itp_interface/coq_ser_api/example.py +67 -0
  10. itp_interface/coq_ser_api/lsp_backend.py +375 -0
  11. itp_interface/coq_ser_api/py.typed +0 -0
  12. itp_interface/coq_ser_api/serapi_backend.py +841 -0
  13. itp_interface/coq_ser_api/util.py +145 -0
  14. itp_interface/coq_ser_api_old/__init__.py +2583 -0
  15. itp_interface/coq_ser_api_old/contexts.py +172 -0
  16. itp_interface/coq_ser_api_old/util.py +146 -0
  17. itp_interface/lean_server/__init__.py +0 -0
  18. itp_interface/lean_server/commands.py +484 -0
  19. itp_interface/lean_server/lean3_search_tool.py +358 -0
  20. itp_interface/lean_server/lean4_repl_interface.py +151 -0
  21. itp_interface/lean_server/lean4_utils.py +255 -0
  22. itp_interface/lean_server/lean_cmd_server.py +111 -0
  23. itp_interface/lean_server/lean_context.py +60 -0
  24. itp_interface/lean_server/lean_sync_server.py +174 -0
  25. itp_interface/lean_server/lean_utils.py +199 -0
  26. itp_interface/lean_server/py.typed +1 -0
  27. itp_interface/main/__init__.py +0 -0
  28. itp_interface/main/config/afp_data_gen.yaml +14 -0
  29. itp_interface/main/config/benchmark/CompCert.yaml +366 -0
  30. itp_interface/main/config/benchmark/GeoCoq.yaml +930 -0
  31. itp_interface/main/config/benchmark/UniMath.yaml +2690 -0
  32. itp_interface/main/config/benchmark/afp_isabelle.yaml +29200 -0
  33. itp_interface/main/config/benchmark/agent_proverbot_hard.yaml +247 -0
  34. itp_interface/main/config/benchmark/category-theory.yaml +470 -0
  35. itp_interface/main/config/benchmark/compcert_118_subset.yaml +148 -0
  36. itp_interface/main/config/benchmark/compcert_benchmark.yaml +36 -0
  37. itp_interface/main/config/benchmark/compcert_benchmark_hard.yaml +498 -0
  38. itp_interface/main/config/benchmark/compcert_benchmark_hard_1.yaml +55 -0
  39. itp_interface/main/config/benchmark/compcert_benchmark_hard_2.yaml +24 -0
  40. itp_interface/main/config/benchmark/compcert_benchmark_hard_3.yaml +95 -0
  41. itp_interface/main/config/benchmark/compcert_benchmark_hard_7_per_cent.yaml +78 -0
  42. itp_interface/main/config/benchmark/compcert_benchmark_test.yaml +38 -0
  43. itp_interface/main/config/benchmark/compcert_benchmark_train.yaml +340 -0
  44. itp_interface/main/config/benchmark/leandojo_novel_premises_test.yaml +2908 -0
  45. itp_interface/main/config/benchmark/leandojo_novel_premises_train.yaml +98645 -0
  46. itp_interface/main/config/benchmark/leandojo_novel_premises_val.yaml +2912 -0
  47. itp_interface/main/config/benchmark/leandojo_random.yaml +2889 -0
  48. itp_interface/main/config/benchmark/leandojo_random_test.yaml +2421 -0
  49. itp_interface/main/config/benchmark/leandojo_random_train.yaml +62729 -0
  50. itp_interface/main/config/benchmark/leandojo_random_val.yaml +2504 -0
  51. itp_interface/main/config/benchmark/math-comp.yaml +200 -0
  52. itp_interface/main/config/benchmark/miniF2F_test.yaml +12 -0
  53. itp_interface/main/config/benchmark/miniF2F_test_aime.yaml +27 -0
  54. itp_interface/main/config/benchmark/miniF2F_test_algebra.yaml +30 -0
  55. itp_interface/main/config/benchmark/miniF2F_test_amc12.yaml +57 -0
  56. itp_interface/main/config/benchmark/miniF2F_test_few_shot_hard.yaml +231 -0
  57. itp_interface/main/config/benchmark/miniF2F_test_imo.yaml +32 -0
  58. itp_interface/main/config/benchmark/miniF2F_test_induction.yaml +20 -0
  59. itp_interface/main/config/benchmark/miniF2F_test_mathd_algebra.yaml +82 -0
  60. itp_interface/main/config/benchmark/miniF2F_test_mathd_algebra_hard.yaml +72 -0
  61. itp_interface/main/config/benchmark/miniF2F_test_mathd_numbertheory.yaml +72 -0
  62. itp_interface/main/config/benchmark/miniF2F_test_numbertheory.yaml +20 -0
  63. itp_interface/main/config/benchmark/minicompcert_benchmark_1.yaml +14 -0
  64. itp_interface/main/config/benchmark/proverbot_hard.yaml +104 -0
  65. itp_interface/main/config/benchmark/re_prover.yaml +66 -0
  66. itp_interface/main/config/benchmark/re_prover_hard.yaml +41 -0
  67. itp_interface/main/config/benchmark/re_prover_very_hard.yaml +22 -0
  68. itp_interface/main/config/benchmark/reprover_with_retrieval.yaml +73 -0
  69. itp_interface/main/config/benchmark/reprover_with_retrieval_hard.yaml +30 -0
  70. itp_interface/main/config/benchmark/reprover_with_retrieval_neg.yaml +195 -0
  71. itp_interface/main/config/benchmark/simple_benchmark_1.yaml +24 -0
  72. itp_interface/main/config/benchmark/simple_benchmark_8.yaml +50 -0
  73. itp_interface/main/config/benchmark/simple_benchmark_9.yaml +65 -0
  74. itp_interface/main/config/benchmark/simple_benchmark_isabelle.yaml +18 -0
  75. itp_interface/main/config/benchmark/simple_benchmark_lean.yaml +12 -0
  76. itp_interface/main/config/benchmark/simple_benchmark_lean_training_data.yaml +12 -0
  77. itp_interface/main/config/benchmark/simple_rl_benchmark_lean.yaml +14 -0
  78. itp_interface/main/config/benchmark/stack_machine.yaml +13 -0
  79. itp_interface/main/config/benchmark/stack_machine_hard.yaml +15 -0
  80. itp_interface/main/config/category_theory_data_gen.yaml +14 -0
  81. itp_interface/main/config/category_theory_data_gen_random.yaml +16 -0
  82. itp_interface/main/config/compcert_data_gen_test.yaml +10 -0
  83. itp_interface/main/config/compcert_data_gen_train.yaml +7 -0
  84. itp_interface/main/config/env_settings/bm25_retrieval.yaml +2 -0
  85. itp_interface/main/config/env_settings/bm25_retrieval_no_dfns.yaml +2 -0
  86. itp_interface/main/config/env_settings/bm25_retrieval_only_local_no_dfns.yaml +2 -0
  87. itp_interface/main/config/env_settings/bm25_retrieval_with_print.yaml +2 -0
  88. itp_interface/main/config/env_settings/bm25_retrieval_with_print_only_local.yaml +2 -0
  89. itp_interface/main/config/env_settings/bm25_retrieval_with_print_only_local_no_dfns.yaml +2 -0
  90. itp_interface/main/config/env_settings/no_retrieval.yaml +2 -0
  91. itp_interface/main/config/experiments.yaml +12 -0
  92. itp_interface/main/config/geo_coq_data_gen.yaml +14 -0
  93. itp_interface/main/config/geo_coq_data_gen_random.yaml +16 -0
  94. itp_interface/main/config/leandojo_random_data_gen.yaml +16 -0
  95. itp_interface/main/config/math_comp_data_gen.yaml +14 -0
  96. itp_interface/main/config/math_comp_data_gen_random.yaml +16 -0
  97. itp_interface/main/config/mathlib_data_gen.yaml +14 -0
  98. itp_interface/main/config/repo/coq_repos.yaml +191 -0
  99. itp_interface/main/config/run_settings/default_coq_data_generation_transforms.yaml +24 -0
  100. itp_interface/main/config/run_settings/default_isabelle_data_generation_transforms.yaml +24 -0
  101. itp_interface/main/config/run_settings/default_lean4_data_generation_transforms.yaml +24 -0
  102. itp_interface/main/config/run_settings/default_lean_data_generation_transforms.yaml +24 -0
  103. itp_interface/main/config/simple_coq_data_gen.yaml +12 -0
  104. itp_interface/main/config/simple_coq_data_gen_random.yaml +17 -0
  105. itp_interface/main/config/simple_lean_data_gen.yaml +12 -0
  106. itp_interface/main/config/simple_rl_lean_data_gen.yaml +12 -0
  107. itp_interface/main/config/uni_math_data_gen.yaml +14 -0
  108. itp_interface/main/config.py +192 -0
  109. itp_interface/main/extract_benchmark_dataset.py +106 -0
  110. itp_interface/main/filter_dataset.py +107 -0
  111. itp_interface/main/install.py +92 -0
  112. itp_interface/main/merge_dataset.py +96 -0
  113. itp_interface/main/run_tool.py +444 -0
  114. itp_interface/pisa/.git +1 -0
  115. itp_interface/pisa/.gitignore +125 -0
  116. itp_interface/pisa/.idea/.gitignore +8 -0
  117. itp_interface/pisa/.idea/ClojureProjectResolveSettings.xml +6 -0
  118. itp_interface/pisa/.idea/codeStyles/Project.xml +7 -0
  119. itp_interface/pisa/.idea/codeStyles/codeStyleConfig.xml +5 -0
  120. itp_interface/pisa/.idea/inspectionProfiles/Project_Default.xml +16 -0
  121. itp_interface/pisa/.idea/libraries/sbt__com_google_android_annotations_4_1_1_4_jar.xml +13 -0
  122. itp_interface/pisa/.idea/libraries/sbt__com_google_api_grpc_proto_google_common_protos_1_17_0_jar.xml +13 -0
  123. itp_interface/pisa/.idea/libraries/sbt__com_google_code_findbugs_jsr305_3_0_2_jar.xml +13 -0
  124. itp_interface/pisa/.idea/libraries/sbt__com_google_code_gson_gson_2_8_6_jar.xml +13 -0
  125. itp_interface/pisa/.idea/libraries/sbt__com_google_errorprone_error_prone_annotations_2_3_4_jar.xml +13 -0
  126. itp_interface/pisa/.idea/libraries/sbt__com_google_guava_failureaccess_1_0_1_jar.xml +13 -0
  127. itp_interface/pisa/.idea/libraries/sbt__com_google_guava_guava_30_0_jre_jar.xml +13 -0
  128. itp_interface/pisa/.idea/libraries/sbt__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava_jar.xml +9 -0
  129. itp_interface/pisa/.idea/libraries/sbt__com_google_j2objc_j2objc_annotations_1_3_jar.xml +13 -0
  130. itp_interface/pisa/.idea/libraries/sbt__com_google_protobuf_protobuf_java_3_12_0_jar.xml +13 -0
  131. itp_interface/pisa/.idea/libraries/sbt__com_google_protobuf_protobuf_java_util_3_12_0_jar.xml +13 -0
  132. itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_fastparse_2_13_2_3_0_jar.xml +13 -0
  133. itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_geny_2_13_0_6_0_jar.xml +13 -0
  134. itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_sourcecode_2_13_0_2_1_jar.xml +13 -0
  135. itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_lenses_2_13_0_10_9_jar.xml +13 -0
  136. itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_scalapb_runtime_2_13_0_10_9_jar.xml +13 -0
  137. itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_scalapb_runtime_grpc_2_13_0_10_9_jar.xml +13 -0
  138. itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_zio_grpc_zio_grpc_core_2_13_0_4_2_jar.xml +13 -0
  139. itp_interface/pisa/.idea/libraries/sbt__com_thoughtworks_paranamer_paranamer_2_8_jar.xml +13 -0
  140. itp_interface/pisa/.idea/libraries/sbt__commons_io_commons_io_2_8_0_jar.xml +13 -0
  141. itp_interface/pisa/.idea/libraries/sbt__de_unruh_java_patterns_0_1_0_jar.xml +13 -0
  142. itp_interface/pisa/.idea/libraries/sbt__de_unruh_scala_isabelle_2_13_master_SNAPSHOT_jar.xml +13 -0
  143. itp_interface/pisa/.idea/libraries/sbt__dev_zio_izumi_reflect_2_13_1_0_0_M9_jar.xml +13 -0
  144. itp_interface/pisa/.idea/libraries/sbt__dev_zio_izumi_reflect_thirdparty_boopickle_shaded_2_13_1_0_0_M9_jar.xml +13 -0
  145. itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_2_13_1_0_3_jar.xml +13 -0
  146. itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_stacktracer_2_13_1_0_3_jar.xml +13 -0
  147. itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_streams_2_13_1_0_3_jar.xml +13 -0
  148. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_api_1_34_0_jar.xml +13 -0
  149. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_context_1_34_0_jar.xml +13 -0
  150. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_core_1_34_0_jar.xml +13 -0
  151. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_netty_1_34_0_jar.xml +13 -0
  152. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_protobuf_1_34_0_jar.xml +13 -0
  153. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_protobuf_lite_1_34_0_jar.xml +13 -0
  154. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_services_1_34_0_jar.xml +13 -0
  155. itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_stub_1_34_0_jar.xml +13 -0
  156. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_buffer_4_1_51_Final_jar.xml +13 -0
  157. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_4_1_51_Final_jar.xml +13 -0
  158. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_http2_4_1_51_Final_jar.xml +13 -0
  159. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_http_4_1_51_Final_jar.xml +13 -0
  160. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_socks_4_1_51_Final_jar.xml +13 -0
  161. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_common_4_1_51_Final_jar.xml +13 -0
  162. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_handler_4_1_51_Final_jar.xml +13 -0
  163. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_handler_proxy_4_1_51_Final_jar.xml +13 -0
  164. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_resolver_4_1_51_Final_jar.xml +13 -0
  165. itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_transport_4_1_51_Final_jar.xml +13 -0
  166. itp_interface/pisa/.idea/libraries/sbt__io_perfmark_perfmark_api_0_19_0_jar.xml +13 -0
  167. itp_interface/pisa/.idea/libraries/sbt__net_java_dev_jna_jna_5_3_1_jar.xml +13 -0
  168. itp_interface/pisa/.idea/libraries/sbt__net_liftweb_lift_json_2_13_3_4_3_jar.xml +13 -0
  169. itp_interface/pisa/.idea/libraries/sbt__org_apache_commons_commons_lang3_3_11_jar.xml +13 -0
  170. itp_interface/pisa/.idea/libraries/sbt__org_apache_commons_commons_text_1_9_jar.xml +13 -0
  171. itp_interface/pisa/.idea/libraries/sbt__org_checkerframework_checker_qual_3_5_0_jar.xml +13 -0
  172. itp_interface/pisa/.idea/libraries/sbt__org_codehaus_mojo_animal_sniffer_annotations_1_18_jar.xml +13 -0
  173. itp_interface/pisa/.idea/libraries/sbt__org_jetbrains_annotations_20_1_0_jar.xml +13 -0
  174. itp_interface/pisa/.idea/libraries/sbt__org_jline_jline_3_16_0_jar.xml +13 -0
  175. itp_interface/pisa/.idea/libraries/sbt__org_log4s_log4s_2_13_1_9_0_jar.xml +13 -0
  176. itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_modules_scala_collection_compat_2_13_2_1_6_jar.xml +13 -0
  177. itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_modules_scala_xml_2_13_1_3_0_jar.xml +13 -0
  178. itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_compiler_2_13_4_jar.xml +13 -0
  179. itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_4_jar.xml +23 -0
  180. itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_reflect_2_13_4_jar.xml +13 -0
  181. itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scalap_2_13_4_jar.xml +13 -0
  182. itp_interface/pisa/.idea/libraries/sbt__org_scalaz_scalaz_core_2_13_7_3_2_jar.xml +13 -0
  183. itp_interface/pisa/.idea/libraries/sbt__org_slf4j_slf4j_api_1_7_30_jar.xml +13 -0
  184. itp_interface/pisa/.idea/libraries/sbt__org_slf4j_slf4j_simple_1_7_30_jar.xml +13 -0
  185. itp_interface/pisa/.idea/misc.xml +7 -0
  186. itp_interface/pisa/.idea/modules/PISA-build.iml +127 -0
  187. itp_interface/pisa/.idea/modules/PISA.iml +94 -0
  188. itp_interface/pisa/.idea/modules.xml +9 -0
  189. itp_interface/pisa/.idea/other.xml +6 -0
  190. itp_interface/pisa/.idea/sbt.xml +20 -0
  191. itp_interface/pisa/.idea/scala_compiler.xml +6 -0
  192. itp_interface/pisa/.idea/uiDesigner.xml +124 -0
  193. itp_interface/pisa/.idea/vcs.xml +6 -0
  194. itp_interface/pisa/.scalafmt.conf +2 -0
  195. itp_interface/pisa/LICENSE +29 -0
  196. itp_interface/pisa/README.md +262 -0
  197. itp_interface/pisa/build.sbt +49 -0
  198. itp_interface/pisa/build.sh +26 -0
  199. itp_interface/pisa/command_generation/close_gaps.py +44 -0
  200. itp_interface/pisa/command_generation/conjecture_normal_order.py +62 -0
  201. itp_interface/pisa/command_generation/conjecturer_command_generator.py +36 -0
  202. itp_interface/pisa/command_generation/create_dirs.py +11 -0
  203. itp_interface/pisa/command_generation/find_std.py +67 -0
  204. itp_interface/pisa/command_generation/generate_build_commands_afp.py +15 -0
  205. itp_interface/pisa/command_generation/generate_build_commands_std.py +15 -0
  206. itp_interface/pisa/command_generation/generate_commands_afp.py +103 -0
  207. itp_interface/pisa/command_generation/generate_commands_mini.py +73 -0
  208. itp_interface/pisa/command_generation/generate_commands_std.py +69 -0
  209. itp_interface/pisa/command_generation/generate_hammer_extraction_text.py +5 -0
  210. itp_interface/pisa/command_generation/hammer_command_generator.py +40 -0
  211. itp_interface/pisa/command_generation/hp_search_command_generator.py +63 -0
  212. itp_interface/pisa/command_generation/oracle_command_generator.py +56 -0
  213. itp_interface/pisa/command_generation/search_command_generator.py +69 -0
  214. itp_interface/pisa/command_generation/summarise_problem_names.py +45 -0
  215. itp_interface/pisa/command_generation/tpu_hp_search.py +75 -0
  216. itp_interface/pisa/docker/Dockerfile +34 -0
  217. itp_interface/pisa/docker/docker_tutorial.md +64 -0
  218. itp_interface/pisa/eval_setup/copy_isabelle.py +42 -0
  219. itp_interface/pisa/eval_setup/copy_pisa_jars.py +18 -0
  220. itp_interface/pisa/mesh_transformer_utils/tokenization.py +86 -0
  221. itp_interface/pisa/project/build.properties +1 -0
  222. itp_interface/pisa/project/plugins.sbt +5 -0
  223. itp_interface/pisa/requirements.txt +4 -0
  224. itp_interface/pisa/scripts/extract_last_k_steps.py +28 -0
  225. itp_interface/pisa/scripts/extract_proof_corpus.py +26 -0
  226. itp_interface/pisa/scripts/gather_hammer_results.py +27 -0
  227. itp_interface/pisa/scripts/length_in_char_stats.py +20 -0
  228. itp_interface/pisa/scripts/mix.py +127 -0
  229. itp_interface/pisa/scripts/results_stat.py +52 -0
  230. itp_interface/pisa/scripts/test_array_job.sh +34 -0
  231. itp_interface/pisa/setup.sh +25 -0
  232. itp_interface/pisa/src/main/protobuf/server.proto +60 -0
  233. itp_interface/pisa/src/main/python/.idea/.gitignore +8 -0
  234. itp_interface/pisa/src/main/python/.idea/inspectionProfiles/Project_Default.xml +18 -0
  235. itp_interface/pisa/src/main/python/.idea/inspectionProfiles/profiles_settings.xml +6 -0
  236. itp_interface/pisa/src/main/python/.idea/misc.xml +4 -0
  237. itp_interface/pisa/src/main/python/.idea/modules.xml +8 -0
  238. itp_interface/pisa/src/main/python/.idea/python.iml +12 -0
  239. itp_interface/pisa/src/main/python/.idea/vcs.xml +6 -0
  240. itp_interface/pisa/src/main/python/conjecturing_parsing/conjecturer_postprocessing.py +59 -0
  241. itp_interface/pisa/src/main/python/data_extraction/extract_data.py +184 -0
  242. itp_interface/pisa/src/main/python/data_extraction/find_premises.py +221 -0
  243. itp_interface/pisa/src/main/python/data_extraction/process_data.py +129 -0
  244. itp_interface/pisa/src/main/python/legacy/PisaFlexibleClient.py +167 -0
  245. itp_interface/pisa/src/main/python/legacy/autof_test.py +74 -0
  246. itp_interface/pisa/src/main/python/legacy/cmd_client.py +23 -0
  247. itp_interface/pisa/src/main/python/legacy/convert_scala_dump_to_test_name_jsons.py +14 -0
  248. itp_interface/pisa/src/main/python/legacy/create_data_txt.py +72 -0
  249. itp_interface/pisa/src/main/python/legacy/create_finetune_tfrecords.py +311 -0
  250. itp_interface/pisa/src/main/python/legacy/demo.py +49 -0
  251. itp_interface/pisa/src/main/python/legacy/evaluate.py +108 -0
  252. itp_interface/pisa/src/main/python/legacy/extract_first_step.py +25 -0
  253. itp_interface/pisa/src/main/python/legacy/get_global_facts.py +35 -0
  254. itp_interface/pisa/src/main/python/legacy/mix_data.py +19 -0
  255. itp_interface/pisa/src/main/python/legacy/one_stage_extraction.py +111 -0
  256. itp_interface/pisa/src/main/python/legacy/prepare_episodic_transitions.py +137 -0
  257. itp_interface/pisa/src/main/python/legacy/prepare_translation_pairs.py +277 -0
  258. itp_interface/pisa/src/main/python/pisa_client.py +322 -0
  259. itp_interface/pisa/src/main/python/server_pb2.py +394 -0
  260. itp_interface/pisa/src/main/python/server_pb2_grpc.py +230 -0
  261. itp_interface/pisa/src/main/python/test_client.py +17 -0
  262. itp_interface/pisa/src/main/python/test_client2.py +79 -0
  263. itp_interface/pisa/src/main/python/utils/filters.py +59 -0
  264. itp_interface/pisa/src/main/python/utils/pisa_server_control.py +29 -0
  265. itp_interface/pisa/src/main/scala/pisa/agent/CheckSyntax.scala +257 -0
  266. itp_interface/pisa/src/main/scala/pisa/agent/DepThms.scala +29 -0
  267. itp_interface/pisa/src/main/scala/pisa/agent/PisaStat.scala +46 -0
  268. itp_interface/pisa/src/main/scala/pisa/agent/RefactorTest.scala +40 -0
  269. itp_interface/pisa/src/main/scala/pisa/agent/RepHammer.scala +95 -0
  270. itp_interface/pisa/src/main/scala/pisa/server/HammFacts.scala +63 -0
  271. itp_interface/pisa/src/main/scala/pisa/server/PisaOS.scala +881 -0
  272. itp_interface/pisa/src/main/scala/pisa/server/PisaOneStage.scala +540 -0
  273. itp_interface/pisa/src/main/scala/pisa/server/PisaOneStageServers.scala +1048 -0
  274. itp_interface/pisa/src/main/scala/pisa/utils/TheoryManager.scala +95 -0
  275. itp_interface/pisa/src/test/python/analyse_debug.py +33 -0
  276. itp_interface/pisa/src/test/python/extract_test_seq2seq.py +53 -0
  277. itp_interface/pisa/src/test/python/extract_test_theorem_ground_truth_indices.py +31 -0
  278. itp_interface/pisa/src/test/python/proof_originality.py +24 -0
  279. itp_interface/pisa/src/test/python/test_command_generator.py +25 -0
  280. itp_interface/pisa/src/test/python/test_model_sequence_accuracy.py +70 -0
  281. itp_interface/pisa/src/test/scala/pisa/Easy.scala +26 -0
  282. itp_interface/pisa/src/test/scala/pisa/TestCurl.scala +82 -0
  283. itp_interface/pisa/src/test/scala/pisa/TestIsa.scala +27 -0
  284. itp_interface/pisa/test.sh +19 -0
  285. itp_interface/pisa/universal_test_theorems.tar.gz +0 -0
  286. itp_interface/repo/build.py +78 -0
  287. itp_interface/repo/clone.py +79 -0
  288. itp_interface/repo/dataset_discovery.py +99 -0
  289. itp_interface/retrieval/__init__.py +0 -0
  290. itp_interface/retrieval/abstraction.py +35 -0
  291. itp_interface/retrieval/coq_bm25_reranker.py +153 -0
  292. itp_interface/retrieval/isabelle_bm25_reranker.py +86 -0
  293. itp_interface/retrieval/lean3_bm25_reranker.py +86 -0
  294. itp_interface/rl/__init__.py +0 -0
  295. itp_interface/rl/abstraction.py +168 -0
  296. itp_interface/rl/proof_action.py +172 -0
  297. itp_interface/rl/proof_state.py +149 -0
  298. itp_interface/rl/proof_tree.py +109 -0
  299. itp_interface/rl/simpl_proof_env_pool.py +16 -0
  300. itp_interface/rl/simple_proof_env.py +713 -0
  301. itp_interface/rl/simple_proof_env_pool.py +591 -0
  302. itp_interface/scripts/setup.sh +228 -0
  303. itp_interface/tools/__init__.py +0 -0
  304. itp_interface/tools/basic_utils.py +172 -0
  305. itp_interface/tools/bin_packing.py +61 -0
  306. itp_interface/tools/cache.py +93 -0
  307. itp_interface/tools/coq_build_spec.py +31 -0
  308. itp_interface/tools/coq_build_tool.py +319 -0
  309. itp_interface/tools/coq_context_helper.py +354 -0
  310. itp_interface/tools/coq_executor.py +508 -0
  311. itp_interface/tools/coq_local_data_generation_transform.py +158 -0
  312. itp_interface/tools/coq_parse_utils.py +154 -0
  313. itp_interface/tools/coq_raw_proofs.py +193 -0
  314. itp_interface/tools/coq_theorem_proof_pair_generation_transform.py +146 -0
  315. itp_interface/tools/coq_training_data_generator.py +76 -0
  316. itp_interface/tools/dynamic_coq_proof_exec.py +220 -0
  317. itp_interface/tools/dynamic_isabelle_proof_exec.py +229 -0
  318. itp_interface/tools/dynamic_lean4_proof_exec.py +236 -0
  319. itp_interface/tools/dynamic_lean_proof_exec.py +228 -0
  320. itp_interface/tools/isabelle_context_helper.py +66 -0
  321. itp_interface/tools/isabelle_executor.py +862 -0
  322. itp_interface/tools/isabelle_local_data_generation_transform.py +149 -0
  323. itp_interface/tools/isabelle_parse_utils.py +131 -0
  324. itp_interface/tools/isabelle_server.py +106 -0
  325. itp_interface/tools/lean4_context_helper.py +72 -0
  326. itp_interface/tools/lean4_local_data_generation_transform.py +122 -0
  327. itp_interface/tools/lean4_sync_executor.py +1193 -0
  328. itp_interface/tools/lean_cmd_executor.py +804 -0
  329. itp_interface/tools/lean_context_helper.py +327 -0
  330. itp_interface/tools/lean_dojo_data_generation_transform.py +206 -0
  331. itp_interface/tools/lean_executor.py +687 -0
  332. itp_interface/tools/lean_local_data_generation_transform.py +136 -0
  333. itp_interface/tools/lean_parse_utils.py +32 -0
  334. itp_interface/tools/log_utils.py +20 -0
  335. itp_interface/tools/proof_exec_callback.py +76 -0
  336. itp_interface/tools/ray_utils.py +265 -0
  337. itp_interface/tools/repl/.git +1 -0
  338. itp_interface/tools/repl/.github/workflows/ci.yml +24 -0
  339. itp_interface/tools/repl/.gitignore +7 -0
  340. itp_interface/tools/repl/.vscode/copyright.code-snippets +13 -0
  341. itp_interface/tools/repl/.vscode/extensions.json +13 -0
  342. itp_interface/tools/repl/.vscode/module-docstring.code-snippets +35 -0
  343. itp_interface/tools/repl/.vscode/settings.json +11 -0
  344. itp_interface/tools/repl/README.md +174 -0
  345. itp_interface/tools/repl/REPL/Frontend.lean +47 -0
  346. itp_interface/tools/repl/REPL/JSON.lean +186 -0
  347. itp_interface/tools/repl/REPL/Lean/ContextInfo.lean +9 -0
  348. itp_interface/tools/repl/REPL/Lean/Environment.lean +31 -0
  349. itp_interface/tools/repl/REPL/Lean/InfoTree/ToJson.lean +114 -0
  350. itp_interface/tools/repl/REPL/Lean/InfoTree.lean +272 -0
  351. itp_interface/tools/repl/REPL/Main.lean +323 -0
  352. itp_interface/tools/repl/REPL/Snapshots.lean +306 -0
  353. itp_interface/tools/repl/REPL/Util/Path.lean +36 -0
  354. itp_interface/tools/repl/REPL/Util/Pickle.lean +44 -0
  355. itp_interface/tools/repl/REPL.lean +4 -0
  356. itp_interface/tools/repl/lake-manifest.json +5 -0
  357. itp_interface/tools/repl/lakefile.lean +15 -0
  358. itp_interface/tools/repl/lean-toolchain +1 -0
  359. itp_interface/tools/repl/test/Mathlib/.gitignore +5 -0
  360. itp_interface/tools/repl/test/Mathlib/H20231110.sh +2 -0
  361. itp_interface/tools/repl/test/Mathlib/ReplMathlibTests.lean +1 -0
  362. itp_interface/tools/repl/test/Mathlib/lake-manifest.json +68 -0
  363. itp_interface/tools/repl/test/Mathlib/lakefile.lean +11 -0
  364. itp_interface/tools/repl/test/Mathlib/lean-toolchain +1 -0
  365. itp_interface/tools/repl/test/Mathlib/test/20240209.expected.out +20 -0
  366. itp_interface/tools/repl/test/Mathlib/test/20240209.in +3 -0
  367. itp_interface/tools/repl/test/Mathlib/test/20240209.lean +4 -0
  368. itp_interface/tools/repl/test/Mathlib/test/H20231020.expected.out +8 -0
  369. itp_interface/tools/repl/test/Mathlib/test/H20231020.in +8 -0
  370. itp_interface/tools/repl/test/Mathlib/test/H20231020.lean +22 -0
  371. itp_interface/tools/repl/test/Mathlib/test/H20231110.expected.out +4 -0
  372. itp_interface/tools/repl/test/Mathlib/test/H20231110.in +4 -0
  373. itp_interface/tools/repl/test/Mathlib/test/H20231115.expected.out +19 -0
  374. itp_interface/tools/repl/test/Mathlib/test/H20231115.in +5 -0
  375. itp_interface/tools/repl/test/Mathlib/test/H20231115_2.expected.out +18 -0
  376. itp_interface/tools/repl/test/Mathlib/test/H20231115_2.in +4 -0
  377. itp_interface/tools/repl/test/Mathlib/test/H20231115_3.expected.out +10 -0
  378. itp_interface/tools/repl/test/Mathlib/test/H20231115_3.in +4 -0
  379. itp_interface/tools/repl/test/Mathlib/test/H20231214.in +9 -0
  380. itp_interface/tools/repl/test/Mathlib/test/H20231214.lean +30 -0
  381. itp_interface/tools/repl/test/Mathlib/test/H20231215.expected.out +4 -0
  382. itp_interface/tools/repl/test/Mathlib/test/H20231215.in +4 -0
  383. itp_interface/tools/repl/test/Mathlib/test/H20231215_2.expected.out +14 -0
  384. itp_interface/tools/repl/test/Mathlib/test/H20231215_2.in +3 -0
  385. itp_interface/tools/repl/test/Mathlib/test/exact.expected.out +37 -0
  386. itp_interface/tools/repl/test/Mathlib/test/exact.in +10 -0
  387. itp_interface/tools/repl/test/Mathlib/test/import_Mathlib.lean +1 -0
  388. itp_interface/tools/repl/test/Mathlib/test/induction.expected.out +29 -0
  389. itp_interface/tools/repl/test/Mathlib/test/induction.in +10 -0
  390. itp_interface/tools/repl/test/Mathlib/test/induction.lean +6 -0
  391. itp_interface/tools/repl/test/Mathlib/test/on_goal.expected.out +22 -0
  392. itp_interface/tools/repl/test/Mathlib/test/on_goal.in +5 -0
  393. itp_interface/tools/repl/test/Mathlib/test/pickle.expected.out +16 -0
  394. itp_interface/tools/repl/test/Mathlib/test/pickle.in +6 -0
  395. itp_interface/tools/repl/test/Mathlib/test/pickle_2.expected.out +4 -0
  396. itp_interface/tools/repl/test/Mathlib/test/pickle_2.in +4 -0
  397. itp_interface/tools/repl/test/Mathlib/test.sh +41 -0
  398. itp_interface/tools/repl/test/all_tactics.expected.out +13 -0
  399. itp_interface/tools/repl/test/all_tactics.in +1 -0
  400. itp_interface/tools/repl/test/by_cases.expected.out +25 -0
  401. itp_interface/tools/repl/test/by_cases.in +8 -0
  402. itp_interface/tools/repl/test/by_cases.lean +4 -0
  403. itp_interface/tools/repl/test/calc.expected.out +32 -0
  404. itp_interface/tools/repl/test/calc.in +1 -0
  405. itp_interface/tools/repl/test/def_eval.expected.out +9 -0
  406. itp_interface/tools/repl/test/def_eval.in +3 -0
  407. itp_interface/tools/repl/test/enableInitializersExecution.expected.out +2 -0
  408. itp_interface/tools/repl/test/enableInitializersExecution.in +1 -0
  409. itp_interface/tools/repl/test/file.expected.out +8 -0
  410. itp_interface/tools/repl/test/file.in +1 -0
  411. itp_interface/tools/repl/test/file.lean +5 -0
  412. itp_interface/tools/repl/test/have_by_sorry.expected.out +28 -0
  413. itp_interface/tools/repl/test/have_by_sorry.in +6 -0
  414. itp_interface/tools/repl/test/import_lean.in +1 -0
  415. itp_interface/tools/repl/test/incomplete.expected.out +18 -0
  416. itp_interface/tools/repl/test/incomplete.in +3 -0
  417. itp_interface/tools/repl/test/incomplete.lean +0 -0
  418. itp_interface/tools/repl/test/infotree.expected.out +20 -0
  419. itp_interface/tools/repl/test/infotree.in +2 -0
  420. itp_interface/tools/repl/test/invalid_tactic.expected.out +20 -0
  421. itp_interface/tools/repl/test/invalid_tactic.in +3 -0
  422. itp_interface/tools/repl/test/name_generator.expected.out +53 -0
  423. itp_interface/tools/repl/test/name_generator.in +18 -0
  424. itp_interface/tools/repl/test/no_goal_sorry.expected.out +11 -0
  425. itp_interface/tools/repl/test/no_goal_sorry.in +1 -0
  426. itp_interface/tools/repl/test/no_goal_sorry_2.expected.out +12 -0
  427. itp_interface/tools/repl/test/no_goal_sorry_2.in +1 -0
  428. itp_interface/tools/repl/test/options.expected.out +17 -0
  429. itp_interface/tools/repl/test/options.in +6 -0
  430. itp_interface/tools/repl/test/pickle_environment.expected.out +8 -0
  431. itp_interface/tools/repl/test/pickle_environment.in +7 -0
  432. itp_interface/tools/repl/test/pickle_environment_with_imports.expected.out +10 -0
  433. itp_interface/tools/repl/test/pickle_environment_with_imports.in +9 -0
  434. itp_interface/tools/repl/test/pickle_open.expected.out +8 -0
  435. itp_interface/tools/repl/test/pickle_open.in +7 -0
  436. itp_interface/tools/repl/test/pickle_open_2.expected.out +4 -0
  437. itp_interface/tools/repl/test/pickle_open_2.in +3 -0
  438. itp_interface/tools/repl/test/pickle_open_scoped.expected.out +18 -0
  439. itp_interface/tools/repl/test/pickle_open_scoped.in +8 -0
  440. itp_interface/tools/repl/test/pickle_open_scoped_2.expected.out +14 -0
  441. itp_interface/tools/repl/test/pickle_open_scoped_2.in +3 -0
  442. itp_interface/tools/repl/test/pickle_proof_state_1.expected.out +26 -0
  443. itp_interface/tools/repl/test/pickle_proof_state_1.in +15 -0
  444. itp_interface/tools/repl/test/pickle_proof_state_2.expected.out +4 -0
  445. itp_interface/tools/repl/test/pickle_proof_state_2.in +3 -0
  446. itp_interface/tools/repl/test/pickle_proof_state_env.expected.out +26 -0
  447. itp_interface/tools/repl/test/pickle_proof_state_env.in +15 -0
  448. itp_interface/tools/repl/test/pickle_scoped_notation.in +16 -0
  449. itp_interface/tools/repl/test/pickle_scoped_notation_2.in +3 -0
  450. itp_interface/tools/repl/test/proof_step.expected.out +18 -0
  451. itp_interface/tools/repl/test/proof_step.in +7 -0
  452. itp_interface/tools/repl/test/readme.expected.out +16 -0
  453. itp_interface/tools/repl/test/readme.in +5 -0
  454. itp_interface/tools/repl/test/sorry_hypotheses.expected.out +16 -0
  455. itp_interface/tools/repl/test/sorry_hypotheses.in +4 -0
  456. itp_interface/tools/repl/test/synthesize_placeholder.expected.out +7 -0
  457. itp_interface/tools/repl/test/synthesize_placeholder.in +1 -0
  458. itp_interface/tools/repl/test/tactic_mode_sorry.expected.out +14 -0
  459. itp_interface/tools/repl/test/tactic_mode_sorry.in +3 -0
  460. itp_interface/tools/repl/test/tactic_sorry.expected.out +12 -0
  461. itp_interface/tools/repl/test/tactic_sorry.in +1 -0
  462. itp_interface/tools/repl/test/term_sorry.expected.out +12 -0
  463. itp_interface/tools/repl/test/term_sorry.in +1 -0
  464. itp_interface/tools/repl/test/trace_simp.expected.out +41 -0
  465. itp_interface/tools/repl/test/trace_simp.in +15 -0
  466. itp_interface/tools/repl/test/unfinished_tactic_block.expected.out +11 -0
  467. itp_interface/tools/repl/test/unfinished_tactic_block.in +1 -0
  468. itp_interface/tools/repl/test/unknown_environment.expected.out +2 -0
  469. itp_interface/tools/repl/test/unknown_environment.in +1 -0
  470. itp_interface/tools/repl/test/unknown_proof_state.expected.out +14 -0
  471. itp_interface/tools/repl/test/unknown_proof_state.in +3 -0
  472. itp_interface/tools/repl/test/unknown_tactic.expected.out +14 -0
  473. itp_interface/tools/repl/test/unknown_tactic.in +3 -0
  474. itp_interface/tools/repl/test/variables.expected.out +26 -0
  475. itp_interface/tools/repl/test/variables.in +5 -0
  476. itp_interface/tools/repl/test.sh +43 -0
  477. itp_interface/tools/run_data_generation_transforms.py +350 -0
  478. itp_interface/tools/theorem_details.py +25 -0
  479. itp_interface/tools/training_data.py +358 -0
  480. itp_interface/tools/training_data_format.py +599 -0
  481. itp_interface-1.0.0.dist-info/METADATA +78 -0
  482. itp_interface-1.0.0.dist-info/RECORD +485 -0
  483. itp_interface-1.0.0.dist-info/WHEEL +4 -0
  484. itp_interface-1.0.0.dist-info/entry_points.txt +3 -0
  485. itp_interface-1.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,839 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import re
4
+ import os
5
+ import subprocess
6
+ import argparse
7
+ import sys
8
+ from re import Pattern, Match
9
+
10
+ from typing import List, Tuple, Dict, Optional, Union
11
+ from pathlib import Path
12
+
13
+ from sexpdata import Symbol, dumps
14
+ from tqdm import tqdm
15
+
16
+ from .contexts import ProofContext, Obligation, ScrapedTactic
17
+ from .util import split_by_char_outside_matching, unwrap, mybarfmt, eprint
18
+
19
+ def kill_comments(string: str) -> str:
20
+ result = ""
21
+ depth = 0
22
+ in_quote = False
23
+ for i in range(len(string)):
24
+ if in_quote:
25
+ if depth == 0:
26
+ result += string[i]
27
+ if string[i] == '"' and string[i-1] != '\\':
28
+ in_quote = False
29
+ else:
30
+ if string[i:i+2] == '(*':
31
+ depth += 1
32
+ if depth == 0:
33
+ result += string[i]
34
+ if string[i-1:i+1] == '*)' and depth > 0:
35
+ depth -= 1
36
+ if string[i] == '"' and string[i-1] != '\\':
37
+ in_quote = True
38
+ return result
39
+
40
+ def preprocess_command(cmd: str) -> List[str]:
41
+ coq_import_match = re.fullmatch(r"\s*Require\s+Import\s+Coq\.([\w\.'])", cmd)
42
+ if coq_import_match:
43
+ return [f"Require Import {coq_import_match.group(1)}"]
44
+
45
+ return [cmd]
46
+
47
+
48
+ def get_stem(tactic: str) -> str:
49
+ return split_tactic(tactic)[0]
50
+
51
+
52
+ def split_tactic(tactic: str) -> Tuple[str, str]:
53
+ tactic = kill_comments(tactic).strip()
54
+ if not tactic:
55
+ return ("", "")
56
+ outer_parens_match = re.fullmatch(r"\((.*)\)\.", tactic)
57
+ if outer_parens_match:
58
+ return split_tactic(outer_parens_match.group(1) + ".")
59
+ if re.match(r"^\s*[-+*\{\}]+\s*$", tactic):
60
+ stripped = tactic.strip()
61
+ return stripped[:-1], stripped[-1]
62
+ if split_by_char_outside_matching(r"\(", r"\)", ";", tactic):
63
+ return tactic, ""
64
+ for prefix in ["try", "now", "repeat", "decide"]:
65
+ prefix_match = re.match(rf"{prefix}\s+(.*)", tactic)
66
+ if prefix_match:
67
+ rest_stem, rest_rest = split_tactic(prefix_match.group(1))
68
+ return prefix + " " + rest_stem, rest_rest
69
+ for special_stem in ["rewrite <-", "rewrite !",
70
+ "intros until", "simpl in"]:
71
+ special_match = re.match(rf"{special_stem}(:?(:?\s+(.*))|(\.))", tactic)
72
+ if special_match:
73
+ return special_stem, special_match.group(1)
74
+ match = re.match(r"^\(?([\w']+)(\W+.*)?", tactic)
75
+ if not match:
76
+ return tactic, ""
77
+ stem, rest = match.group(1, 2)
78
+ if not rest:
79
+ rest = ""
80
+ return stem, rest
81
+
82
+
83
+ def parse_hyps(hyps_str: str) -> List[str]:
84
+ lets_killed = kill_nested(r"\Wlet\s", r"\sin\s", hyps_str)
85
+ funs_killed = kill_nested(r"\Wfun\s", "=>", lets_killed)
86
+ foralls_killed = kill_nested(r"\Wforall\s", ",", funs_killed)
87
+ fixs_killed = kill_nested(r"\Wfix\s", ":=", foralls_killed)
88
+ structs_killed = kill_nested(r"\W\{\|\s", r"\|\}", fixs_killed)
89
+ hyps_replaced = re.sub(":=.*?:(?!=)", ":", structs_killed, flags=re.DOTALL)
90
+ var_terms = re.findall(r"(\S+(?:, \S+)*) (?::=.*?)?:(?!=)\s.*?",
91
+ hyps_replaced, flags=re.DOTALL)
92
+ if len(var_terms) == 0:
93
+ return []
94
+ rest_hyps_str = hyps_str
95
+ hyps_list = []
96
+ # Assumes hypothesis are printed in reverse order, because for
97
+ # whatever reason they seem to be.
98
+ for next_term in reversed(var_terms[1:]):
99
+ next_match = rest_hyps_str.rfind(" " + next_term + " :")
100
+ hyp = rest_hyps_str[next_match:].strip()
101
+ rest_hyps_str = rest_hyps_str[:next_match].strip()
102
+ hyps_list.append(hyp)
103
+ hyps_list.append(rest_hyps_str)
104
+ for hyp in hyps_list:
105
+ assert re.search(":(?!=)", hyp) is not None, \
106
+ f"hyp: {hyp}, hyps_str: {hyps_str}\n"\
107
+ f"hyps_list: {hyps_list}\nvar_terms: {var_terms}"
108
+ return hyps_list
109
+
110
+
111
+ def kill_nested(start_string: str, end_string: str, hyps: str) \
112
+ -> str:
113
+ def searchpos(pattern: str, hyps: str, end: bool = False):
114
+ match = re.search(pattern, hyps, flags=re.DOTALL)
115
+ if match:
116
+ if end:
117
+ return match.end()
118
+ return match.start()
119
+ return float("Inf")
120
+ next_forall_pos = searchpos(start_string, hyps)
121
+ next_comma_pos = searchpos(end_string, hyps, end=True)
122
+ forall_depth = 0
123
+ last_forall_position = -1
124
+ cur_position = 0
125
+ while (next_forall_pos != float("Inf") or
126
+ (next_comma_pos != float("Inf") and forall_depth > 0)):
127
+ old_forall_depth = forall_depth
128
+ if next_forall_pos < next_comma_pos:
129
+ cur_position = next_forall_pos
130
+ if forall_depth == 0:
131
+ last_forall_position = next_forall_pos
132
+ forall_depth += 1
133
+ else:
134
+ if forall_depth == 1:
135
+ hyps = hyps[:last_forall_position] + hyps[next_comma_pos:]
136
+ cur_position = last_forall_position
137
+ last_forall_position = -1
138
+ else:
139
+ cur_position = next_comma_pos
140
+ if forall_depth > 0:
141
+ forall_depth -= 1
142
+
143
+ new_next_forall_pos = \
144
+ searchpos(start_string, hyps[cur_position+1:]) + cur_position + 1
145
+ new_next_comma_pos = \
146
+ searchpos(end_string, hyps[cur_position+1:], end=True) + \
147
+ cur_position + 1
148
+ assert new_next_forall_pos != next_forall_pos or \
149
+ new_next_comma_pos != next_comma_pos or \
150
+ forall_depth != old_forall_depth, \
151
+ "old start pos was {}, new start pos is {}, old end pos was {},"\
152
+ "new end pos is {}, cur_position is {}"\
153
+ .format(next_forall_pos, new_next_forall_pos, next_comma_pos,
154
+ new_next_comma_pos, cur_position)
155
+ next_forall_pos = new_next_forall_pos
156
+ next_comma_pos = new_next_comma_pos
157
+ return hyps
158
+
159
+
160
+ def get_var_term_in_hyp(hyp: str) -> str:
161
+ return hyp.partition(":")[0].strip()
162
+
163
+
164
+ hypcolon_regex = re.compile(":(?!=)")
165
+
166
+
167
+ def get_hyp_type(hyp: str) -> str:
168
+ splits = hypcolon_regex.split(hyp, maxsplit=1)
169
+ if len(splits) == 1:
170
+ return ""
171
+ return splits[1].strip()
172
+
173
+
174
+ def get_vars_in_hyps(hyps: List[str]) -> List[str]:
175
+ var_terms = [get_var_term_in_hyp(hyp) for hyp in hyps]
176
+ var_names = [name.strip() for term in var_terms
177
+ for name in term.split(",")]
178
+ return var_names
179
+
180
+
181
+ def get_indexed_vars_in_hyps(hyps: List[str]) -> List[Tuple[str, int]]:
182
+ var_terms = [get_var_term_in_hyp(hyp) for hyp in hyps]
183
+ var_names = [(name.strip(), hyp_idx)
184
+ for hyp_idx, term in enumerate(var_terms)
185
+ for name in term.split(",")]
186
+ return var_names
187
+
188
+
189
+ def get_indexed_vars_dict(hyps: List[str]) -> Dict[str, int]:
190
+ result = {}
191
+ for hyp_var, hyp_idx in get_indexed_vars_in_hyps(hyps):
192
+ if hyp_var not in result:
193
+ result[hyp_var] = hyp_idx
194
+ return result
195
+
196
+
197
+ def get_first_var_in_hyp(hyp: str) -> str:
198
+ return get_var_term_in_hyp(hyp).split(",")[0].strip()
199
+
200
+
201
+
202
+ def tacticTakesHypArgs(stem: str) -> bool:
203
+ now_match = re.match(r"\s*now\s+(.*)", stem)
204
+ if now_match:
205
+ return tacticTakesHypArgs(now_match.group(1))
206
+ try_match = re.match(r"\s*try\s+(.*)", stem)
207
+ if try_match:
208
+ return tacticTakesHypArgs(try_match.group(1))
209
+ repeat_match = re.match(r"\s*repeat\s+(.*)", stem)
210
+ if repeat_match:
211
+ return tacticTakesHypArgs(repeat_match.group(1))
212
+ return (
213
+ stem in [
214
+ "apply", "eapply", "eexploit", "exploit",
215
+ "erewrite", "rewrite", "erewrite !", "rewrite !",
216
+ "erewrite <-", "rewrite <-", "destruct", "elim",
217
+ "eelim", "inversion", "monadInv", "pattern",
218
+ "revert", "exact", "eexact", "simpl in",
219
+ "fold", "generalize", "exists", "case",
220
+ "inv", "subst", "specialize"]
221
+ )
222
+
223
+
224
+ def tacticTakesBinderArgs(stem: str) -> bool:
225
+ return stem == "induction"
226
+
227
+
228
+ def tacticTakesIdentifierArg(stem: str) -> bool:
229
+ return stem == "unfold"
230
+
231
+ normal_lemma_starting_patterns = [
232
+ r"(?:Program\s+)?(?:Polymorphic\s+)?Lemma",
233
+ "Coercion",
234
+ r"(?:Polymorphic\s+)?Theorem",
235
+ "Remark",
236
+ "Proposition",
237
+ r"(?:Polymorphic\s+)?Definition",
238
+ r"Program\s+Definition",
239
+ "Example",
240
+ "Fixpoint",
241
+ "Corollary",
242
+ "Let",
243
+ r"(?<!Declare\s)(?:Polymorphic\s+)?Instance",
244
+ "Function",
245
+ "Property",
246
+ "Fact",
247
+ r"Equations(?:\??)"]
248
+ special_lemma_starting_patterns = [
249
+ "Derive",
250
+ "Goal",
251
+ "Add Morphism",
252
+ "Next Obligation",
253
+ r"Obligation\s+\d+",
254
+ "Add Parametric Morphism"]
255
+
256
+ lemma_starting_patterns = \
257
+ normal_lemma_starting_patterns + special_lemma_starting_patterns
258
+
259
+
260
+ def lemma_name_from_statement(stmt: str) -> str:
261
+ if ("Goal" in stmt or "Obligation" in stmt or "Morphism" in stmt):
262
+ return ""
263
+ stripped_stmt = kill_comments(stmt).strip()
264
+ derive_match = re.fullmatch(
265
+ r"\s*Derive\s+([\w'_]+)\s+SuchThat\s+(.*)\s+As\s+([\w']+)\.\s*",
266
+ stripped_stmt, flags=re.DOTALL)
267
+ if derive_match:
268
+ return derive_match.group(3)
269
+ program_match = re.match(
270
+ r"\s*(?:#\[[^\]]*\]\s*)?Program(?:\s+Instance)?(?:\s+Definition)?\s+"
271
+ r"([\w'\.]*)(.*)",
272
+ stripped_stmt,
273
+ flags=re.DOTALL)
274
+ if program_match:
275
+ return program_match.group(1)
276
+ lemma_match = re.match(
277
+ r"\s*(?:#\[[^\]]*\]\s*)?(?:(?:Local|Global)\s+)?(?:" +
278
+ "|".join(normal_lemma_starting_patterns) +
279
+ r")\s+([\w'\.]*)(.*)",
280
+ stripped_stmt,
281
+ flags=re.DOTALL)
282
+ assert lemma_match, (stripped_stmt, stmt)
283
+ lemma_name = lemma_match.group(1)
284
+ assert ":" not in lemma_name, stripped_stmt
285
+ return lemma_name
286
+
287
+ symbols_regexp = (r',|(?::>)|(?::(?!=))|(?::=)|\)|\(|;|@\{|~|\+{1,2}|\*{1,2}'
288
+ r'|&&|\|\||(?<!\\)/(?!\\)|/\\|\\/|(?<![<*+-/|&])=(?!>)|%|'
289
+ r'(?<!<)-(?!>)|<-|->|<=|>=|<>|\^|\[|\]|(?<!\|)\}|\{(?!\|)')
290
+
291
+
292
+ def get_words(string: str) -> List[str]:
293
+ return [word for word in re.sub(
294
+ r'(\.+|' + symbols_regexp + ')',
295
+ r' \1 ',
296
+ string).split()
297
+ if word.strip() != '']
298
+
299
+
300
+ def get_binder_var(goal: str, binder_idx: int) -> Optional[str]:
301
+ paren_depth = 0
302
+ binders_passed = 0
303
+ skip = False
304
+ forall_match = re.match(r"forall\s+", goal.strip())
305
+ if not forall_match:
306
+ return None
307
+ rest_goal = goal[forall_match.end():]
308
+ for w in get_words(rest_goal):
309
+ if w == "(":
310
+ paren_depth += 1
311
+ elif w == ")":
312
+ paren_depth -= 1
313
+ if paren_depth == 1 or paren_depth == 0:
314
+ skip = False
315
+ elif (paren_depth == 1 or paren_depth == 0) and not skip:
316
+ if w == ":":
317
+ skip = True
318
+ else:
319
+ binders_passed += 1
320
+ if binders_passed == binder_idx:
321
+ return w
322
+ return None
323
+
324
+
325
+ def normalizeNumericArgs(datum: ScrapedTactic) -> ScrapedTactic:
326
+ numerical_induction_match = re.match(
327
+ r"\s*(induction|destruct)\s+(\d+)\s*\.",
328
+ kill_comments(datum.tactic).strip())
329
+ if numerical_induction_match:
330
+ stem = numerical_induction_match.group(1)
331
+ binder_idx = int(numerical_induction_match.group(2))
332
+ binder_var = get_binder_var(datum.context.fg_goals[0].goal, binder_idx)
333
+ if binder_var:
334
+ newtac = stem + " " + binder_var + "."
335
+ return ScrapedTactic(datum.prev_tactics,
336
+ datum.relevant_lemmas,
337
+ datum.context, newtac)
338
+ return datum
339
+
340
+
341
+ def parsePPSubgoal(substr: str) -> Obligation:
342
+ split = re.split("\n====+\n", substr)
343
+ assert len(split) == 2, substr
344
+ hypsstr, goal = split
345
+ return Obligation(parse_hyps(hypsstr), goal)
346
+
347
+ def summarizeObligation(obl: Obligation) -> str:
348
+ hyps_str = ",".join(get_first_var_in_hyp(hyp)
349
+ for hyp in obl.hypotheses)
350
+ goal_str = re.sub("\n", "\\n", obl.goal)[:100]
351
+ return f"{hyps_str} -> {goal_str}"
352
+
353
+ def summarizeContext(context: ProofContext,
354
+ include_background: bool = False,
355
+ include_all: bool = False) -> None:
356
+ eprint("Foreground:")
357
+ for i, subgoal in enumerate(context.fg_goals):
358
+ eprint(f"S{i}: {summarizeObligation(subgoal)}")
359
+ if not include_background and not include_all:
360
+ return
361
+ if len(context.bg_goals) > 0:
362
+ eprint("Background:")
363
+ for i, subgoal in enumerate(context.bg_goals):
364
+ eprint(f"S{i}: {summarizeObligation(subgoal)}")
365
+ if not include_all:
366
+ return
367
+ if len(context.shelved_goals) > 0:
368
+ eprint("Shelved:")
369
+ for i, subgoal in enumerate(context.shelved_goals):
370
+ eprint(f"S{i}: {summarizeObligation(subgoal)}")
371
+ if len(context.given_up_goals) > 0:
372
+ eprint("Given Up:")
373
+ for i, subgoal in enumerate(context.given_up_goals):
374
+ eprint(f"S{i}: {summarizeObligation(subgoal)}")
375
+
376
+
377
+ def isValidCommand(command: str) -> bool:
378
+ command = kill_comments(command)
379
+ goal_selector_match = re.fullmatch(r"\s*\d+\s*:(.*)", command,
380
+ flags=re.DOTALL)
381
+ if goal_selector_match:
382
+ return isValidCommand(goal_selector_match.group(1))
383
+ return ((command.strip()[-1] == "."
384
+ and not re.match(r"\s*{", command))
385
+ or re.fullmatch(r"\s*[-+*{}]*\s*", command) is not None) \
386
+ and (command.count('(') == command.count(')'))
387
+
388
+
389
+ def load_commands_preserve(args: argparse.Namespace, file_idx: int,
390
+ filename: str) -> List[str]:
391
+ try:
392
+ should_show = args.progress
393
+ except AttributeError:
394
+ should_show = False
395
+ try:
396
+ should_show = should_show or args.read_progress
397
+ except AttributeError:
398
+ pass
399
+
400
+ try:
401
+ command_limit = args.command_limit
402
+ except AttributeError:
403
+ command_limit = None
404
+ try:
405
+ text_encoding = args.text_encoding
406
+ except AttributeError:
407
+ text_encoding = 'utf-8'
408
+ return load_commands(filename, max_commands=command_limit,
409
+ progress_bar=should_show,
410
+ progress_bar_offset=file_idx * 2,
411
+ encoding=text_encoding)
412
+
413
+
414
+ def load_commands(filename: str,
415
+ max_commands: Optional[int] = None,
416
+ progress_bar: bool = False,
417
+ progress_bar_offset: Optional[int] = None,
418
+ encoding: str = 'utf-8') -> List[str]:
419
+ with open(filename, 'r', encoding=encoding) as fin:
420
+ contents = fin.read()
421
+ return read_commands(contents,
422
+ max_commands=max_commands,
423
+ progress_bar=progress_bar,
424
+ progress_bar_offset=progress_bar_offset)
425
+
426
+
427
+ def read_commands(contents: str,
428
+ max_commands: Optional[int] = None,
429
+ progress_bar: bool = False,
430
+ progress_bar_offset: Optional[int] = None) -> List[str]:
431
+ result: List[str] = []
432
+ cur_command = ""
433
+ comment_depth = 0
434
+ in_quote = False
435
+ curPos = 0
436
+
437
+ def search_pat(pat: Pattern) -> Tuple[Optional[Match], int]:
438
+ match = pat.search(contents, curPos)
439
+ return match, match.end() if match else len(contents) + 1
440
+
441
+ with tqdm(total=len(contents)+1, file=sys.stdout,
442
+ disable=(not progress_bar),
443
+ position=progress_bar_offset,
444
+ desc="Reading file", leave=False,
445
+ dynamic_ncols=True, bar_format=mybarfmt) as pbar:
446
+ while curPos < len(contents) and (max_commands is None or
447
+ len(result) < max_commands):
448
+ _, next_quote = search_pat(re.compile(r"\""))
449
+ _, next_open_comment = search_pat(re.compile(r"\(\*"))
450
+ _, next_close_comment = search_pat(re.compile(r"\*\)"))
451
+ _, next_bracket = search_pat(re.compile(r"[\{\}]"))
452
+ next_bullet_match, next_bullet = search_pat(
453
+ re.compile(r"[\+\-\*]+(?![\)\+\-\*])"))
454
+ _, next_period = search_pat(
455
+ re.compile(r"(?<!\.)\.($|\s)|\.\.\.($|\s)"))
456
+ nextPos = min(next_quote,
457
+ next_open_comment, next_close_comment,
458
+ next_bracket,
459
+ next_bullet, next_period)
460
+ assert curPos < nextPos
461
+ next_chunk = contents[curPos:nextPos]
462
+ cur_command += next_chunk
463
+ pbar.update(nextPos - curPos)
464
+ if nextPos == next_quote:
465
+ if comment_depth == 0:
466
+ in_quote = not in_quote
467
+ elif nextPos == next_open_comment:
468
+ if not in_quote:
469
+ comment_depth += 1
470
+ elif nextPos == next_close_comment:
471
+ if not in_quote and comment_depth > 0:
472
+ comment_depth -= 1
473
+ elif nextPos == next_bracket:
474
+ if not in_quote and comment_depth == 0 and \
475
+ re.match(r"\s*(?:\d+\s*:)?\s*$",
476
+ kill_comments(cur_command[:-1])):
477
+ result.append(cur_command)
478
+ cur_command = ""
479
+ elif nextPos == next_bullet:
480
+ assert next_bullet_match
481
+ match_length = next_bullet_match.end() - \
482
+ next_bullet_match.start()
483
+ if not in_quote and comment_depth == 0 and \
484
+ re.match(r"\s*$",
485
+ kill_comments(cur_command[:-match_length])):
486
+ result.append(cur_command)
487
+ cur_command = ""
488
+ assert next_bullet_match.end() >= nextPos
489
+ elif nextPos == next_period:
490
+ if not in_quote and comment_depth == 0:
491
+ result.append(cur_command)
492
+ cur_command = ""
493
+ curPos = nextPos
494
+ assert kill_comments(cur_command).strip() == "", \
495
+ "Couldn't parse command list! Are you sure you didn't forget an ending period?" + \
496
+ (contents if len(contents) < 64 else \
497
+ "[too long to print]")
498
+ return result
499
+
500
+ def get_module_from_filename(filename: Union[Path, str]) -> str:
501
+ return Path(filename).stem
502
+
503
+
504
+ def symbol_matches(full_symbol: str, shorthand_symbol: str) -> bool:
505
+ if full_symbol == shorthand_symbol:
506
+ return True
507
+ return full_symbol.split(".")[-1] == shorthand_symbol
508
+
509
+
510
+ def subgoalSurjective(newsub: Obligation, oldsub: Obligation) -> bool:
511
+ oldhyp_terms = [get_hyp_type(hyp) for hyp in oldsub.hypotheses]
512
+ for newhyp_term in [get_hyp_type(hyp) for hyp in newsub.hypotheses]:
513
+ if newhyp_term not in oldhyp_terms:
514
+ return False
515
+ return newsub.goal == oldsub.goal
516
+
517
+
518
+ def contextSurjective(newcontext: ProofContext, oldcontext: ProofContext):
519
+ for oldsub in oldcontext.all_goals:
520
+ if not any((subgoalSurjective(newsub, oldsub)
521
+ for newsub in newcontext.all_goals)):
522
+ return False
523
+ return len(newcontext.all_goals) >= len(oldcontext.all_goals)
524
+
525
+
526
+ def lemmas_in_file(filename: str, cmds: List[str],
527
+ include_proof_relevant: bool = False,
528
+ disambiguate_goal_stmts: bool = False) \
529
+ -> List[Tuple[str, str]]:
530
+ lemmas: Dict[Tuple[int, str], Optional[str]] = {}
531
+ proof_relevant = False
532
+ in_proof = False
533
+ save_name = None
534
+ for cmd_idx, cmd in reversed(list(enumerate(cmds))):
535
+ if in_proof and possibly_starting_proof(cmd):
536
+ in_proof = False
537
+ proof_relevant = proof_relevant or \
538
+ cmd.strip().startswith("Derive") or \
539
+ cmd.strip().startswith("Equations")
540
+ if not proof_relevant or include_proof_relevant:
541
+ lemmas[(cmd_idx,cmd)] = save_name
542
+ if ending_proof(cmd):
543
+ in_proof = True
544
+ proof_relevant = cmd.strip().rstrip(".") == "Defined"
545
+ named_ending_match = re.match("(?:Save|Defined)\s+(\w+)\.", cmd.strip())
546
+ if named_ending_match:
547
+ save_name = named_ending_match.group(1)
548
+ else:
549
+ save_name = None
550
+ sm_stack = initial_sm_stack(filename)
551
+ full_lemmas = []
552
+ obl_num = 0
553
+ unnamed_goal_num = 0
554
+ last_program_statement = ""
555
+ for cmd_idx, cmd in enumerate(cmds):
556
+ scmd = kill_comments(cmd).strip()
557
+ sm_stack = update_sm_stack(sm_stack, cmd)
558
+ goal_match = re.match(r"\s*Goal\s+(.*)\.$", scmd)
559
+ if re.match(r"\s*Next\s+Obligation\s*\.\s*",
560
+ scmd):
561
+ assert last_program_statement != ""
562
+ unique_lemma_statement = f"{last_program_statement} Obligation {obl_num}."
563
+ obl_num += 1
564
+ elif goal_match and disambiguate_goal_stmts:
565
+ save_name = lemmas.get((cmd_idx, cmd), None)
566
+ if save_name:
567
+ unique_lemma_statement = f"Theorem {save_name}: {goal_match.group(1)}."
568
+ else:
569
+ if unnamed_goal_num == 0:
570
+ postfix = ""
571
+ else:
572
+ postfix = str(unnamed_goal_num-1)
573
+ unique_lemma_statement = \
574
+ f"Theorem Unnamed_thm{postfix}: {goal_match.group(1)}."
575
+ unnamed_goal_num += 1
576
+ else:
577
+ unique_lemma_statement = cmd
578
+ if re.match(r"\s*(?:(?:Local|Global)\s+)?Program\s+.*", scmd):
579
+ last_program_statement = cmd
580
+ obl_num = 0
581
+ if (cmd_idx, cmd) in lemmas:
582
+ full_lemmas.append((sm_prefix_from_stack(
583
+ sm_stack), unique_lemma_statement))
584
+ return full_lemmas
585
+
586
+
587
+ def let_to_hyp(let_cmd: str) -> str:
588
+ let_match = re.match(r"\s*Let(?:\s+Fixpoint)?\s+(.*)\.\s*$",
589
+ let_cmd,
590
+ flags=re.DOTALL)
591
+ assert let_match, "Command passed in isn't a Let!"
592
+ split = split_by_char_outside_matching(r"\(", r"\)", ":=",
593
+ let_match.group(1))
594
+ if split:
595
+ name_and_type, _body = split
596
+ else:
597
+ name_and_type = let_match.group(1)
598
+
599
+ name_and_prebinders, ty = \
600
+ unwrap(split_by_char_outside_matching(r"\(", r"\)", ":",
601
+ name_and_type))
602
+ prebinders_match = re.match(
603
+ r"\s*([\w']*)(.*)",
604
+ name_and_prebinders,
605
+ flags=re.DOTALL)
606
+ assert prebinders_match, \
607
+ f"{name_and_prebinders} doesn't match prebinders pattern"
608
+ name = prebinders_match.group(1)
609
+ prebinders = prebinders_match.group(2)
610
+ if prebinders.strip() != "":
611
+ prebinders = f"forall {prebinders},"
612
+
613
+ return f"{name} : {prebinders} {ty[1:]}."
614
+
615
+
616
+ def admit_proof_cmds(lemma_statement: str, ending_statement: str) -> List[str]:
617
+ lemma_statement = kill_comments(lemma_statement)
618
+ let_match = re.fullmatch(r"\s*Let(?:\s+Fixpoint)?\s+(.*)\.\s*$",
619
+ lemma_statement,
620
+ flags=re.DOTALL)
621
+ if let_match and ":=" not in lemma_statement:
622
+ admitted_defn = f"Hypothesis {let_to_hyp(lemma_statement)}"
623
+ return ["Abort.", admitted_defn]
624
+ save_match = re.fullmatch(r"\s*Save\s+(.*)\.\s*$",
625
+ kill_comments(ending_statement),
626
+ flags=re.DOTALL)
627
+ if save_match:
628
+ goal_match = re.fullmatch(r"\s*Goal\s+(.*)\.\s*$",
629
+ lemma_statement, flags=re.DOTALL)
630
+ assert goal_match, f"Didn't start with 'Goal'! lemma_statement is {lemma_statement}"
631
+
632
+ admitted_defn = f"Axiom {save_match.group(1)} : {goal_match.group(1)}."
633
+ return ["Abort.", admitted_defn]
634
+ return ["Admitted."]
635
+
636
+
637
+ def set_switch(switch: str) -> None:
638
+ env_string = subprocess.run(f"opam env --switch={switch} --set-switch",
639
+ shell=True, stdout=subprocess.PIPE, text=True,
640
+ check=True).stdout
641
+
642
+ _setup_opam_env_from_str(env_string)
643
+
644
+ def setup_opam_env(env_string: str = None) -> None:
645
+ if env_string is None:
646
+ env_string = subprocess.run("opam env", shell=True, stdout=subprocess.PIPE,
647
+ check=True, text=True).stdout
648
+ _setup_opam_env_from_str(env_string)
649
+
650
+
651
+ def _setup_opam_env_from_str(env_string: str) -> None:
652
+ for env_line in env_string.splitlines():
653
+ linematch = re.fullmatch(r"(\w*)='([^;]*)'; export (\w*);", env_line)
654
+ assert linematch, env_line
655
+ envvar = linematch.group(1)
656
+ assert envvar == linematch.group(3)
657
+ envval = linematch.group(2)
658
+ os.environ[envvar] = envval
659
+
660
+ def module_prefix_from_stack(sm_stack: List[Tuple[str, bool]]) -> str:
661
+ return "".join([sm[0] + "." for sm in sm_stack if not sm[1]])
662
+
663
+ def sm_prefix_from_stack(sm_stack: List[Tuple[str, bool]]) -> str:
664
+ return "".join([sm[0] + "." for sm in sm_stack])
665
+
666
+ def possibly_starting_proof(command: str) -> bool:
667
+ stripped_command = kill_comments(command).strip()
668
+ pattern = r"(?:#\[(?:.*)\]\s+)?(?:(?:Local|Global)\s+)?(" + "|".join(lemma_starting_patterns) + r")\s*"
669
+ return bool(re.match(pattern,
670
+ stripped_command, flags=re.DOTALL))
671
+
672
+
673
+ def ending_proof(command: str) -> bool:
674
+ stripped_command = kill_comments(command).strip()
675
+ return (re.match(r"(?:Time\s+)?Qed\s*\.", stripped_command) or
676
+ re.match(r"Defined\s*(?:\S*)?\.", stripped_command) or
677
+ re.match(r"Admitted\s*\.", stripped_command) or
678
+ stripped_command == "Abort." or
679
+ "Save" in stripped_command or
680
+ (re.match(r"\s*Proof\s+\S+\s*", stripped_command) is not None and
681
+ re.match(r"\s*Proof\s+with", stripped_command) is None and
682
+ re.match(r"\s*Proof\s+using", stripped_command) is None))
683
+
684
+
685
+ def initial_sm_stack(filename: str) -> List[Tuple[str, bool]]:
686
+ return [(get_module_from_filename(filename), False)]
687
+
688
+ def cancel_update_sm_stack(sm_stack: List[Tuple[str, bool]],
689
+ cmd: str, cmds_before: List[str]) -> List[Tuple[str, bool]]:
690
+ new_stack = list(sm_stack)
691
+ stripped_cmd = kill_comments(cmd).strip()
692
+ module_start_match = re.match(
693
+ r"Module\s+(?:(?:Import|Export)\s+)?(?:Type\s+)?([\w']*)", stripped_cmd)
694
+ if stripped_cmd.count(":=") > stripped_cmd.count("with"):
695
+ module_start_match = None
696
+ section_start_match = re.match(r"Section\s+([\w']*)(?!.*:=)",
697
+ stripped_cmd)
698
+ end_match = re.match(r"End\s+([\w']*)\.", stripped_cmd)
699
+ if module_start_match:
700
+ if new_stack and new_stack[-1][0] == module_start_match.group(1):
701
+ new_stack.pop()
702
+ else:
703
+ assert False, \
704
+ f"Unrecognized cancelled Module \"{cmd}\", " \
705
+ f"top of module stack is {new_stack[-1]}"
706
+ elif section_start_match:
707
+ if new_stack and new_stack[-1][0] == section_start_match.group(1):
708
+ new_stack.pop()
709
+ else:
710
+ assert False, \
711
+ f"Unrecognized cancelled Section \"{cmd}\", " \
712
+ f"top of module stack is {new_stack[-1]}"
713
+ elif end_match:
714
+ new_stack = stack_from_commands(sm_stack[0][0] + ".v", cmds_before)
715
+ return new_stack
716
+
717
+ def update_sm_stack(sm_stack: List[Tuple[str, bool]],
718
+ cmd: str) -> List[Tuple[str, bool]]:
719
+ new_stack = list(sm_stack)
720
+ stripped_cmd = kill_comments(cmd).strip()
721
+ module_start_match = re.match(
722
+ r"Module\s+(?:(?:Import|Export)\s+)?(?:Type\s+)?([\w']*)", stripped_cmd)
723
+ if stripped_cmd.count(":=") > stripped_cmd.count("with"):
724
+ module_start_match = None
725
+ section_start_match = re.match(r"Section\s+([\w']*)(?!.*:=)",
726
+ stripped_cmd)
727
+ end_match = re.match(r"End\s+([\w']*)\.", stripped_cmd)
728
+ reset_match = re.match(r"Reset\s+([\w']*)\.", stripped_cmd)
729
+ if module_start_match:
730
+ new_stack.append((module_start_match.group(1), False))
731
+ elif section_start_match:
732
+ new_stack.append((section_start_match.group(1), True))
733
+ elif end_match:
734
+ if new_stack and new_stack[-1][0] == end_match.group(1):
735
+ new_stack.pop()
736
+ else:
737
+ assert False, \
738
+ f"Unrecognized End \"{cmd}\", " \
739
+ f"module stack is {new_stack}"
740
+ elif reset_match:
741
+ if new_stack and any((item[0] == reset_match.group(1)
742
+ for item in new_stack)):
743
+ while new_stack[-1][0] != reset_match.group(1):
744
+ new_stack.pop()
745
+ new_stack.pop()
746
+ return new_stack
747
+
748
+ def stack_from_commands(filename: str, cmds: List[str]) -> List[Tuple[str, bool]]:
749
+ stack = initial_sm_stack(filename)
750
+ for cmd in cmds:
751
+ stack = update_sm_stack(stack, cmd)
752
+ return stack
753
+
754
+ def update_local_lemmas(local_lemmas: List[Tuple[List[Tuple[str, bool]], str, bool]],
755
+ sm_stack: List[Tuple[str, bool]], cmd: str) \
756
+ -> List[Tuple[List[Tuple[str, bool]], str, bool]]:
757
+ new_local_lemmas = list(local_lemmas)
758
+ lemmas = lemmas_defined_by_stmt(cmd)
759
+ is_section = "Let" in cmd
760
+ for lemma in lemmas:
761
+ new_local_lemmas.append((sm_stack, lemma, is_section))
762
+ reset_match = re.match(r"Reset\s+(.*)\.", cmd)
763
+ if reset_match:
764
+ reseted_lemma_name = module_prefix + reset_match.group(1)
765
+ for (lemma_sm_stack, lemma, is_section) in list(new_local_lemmas):
766
+ if lemma == ":":
767
+ continue
768
+ lemma_match = re.match(r"\s*([\w'\.]+)\s*:", lemma)
769
+ assert lemma_match, f"{lemma} doesnt match!"
770
+ lemma_name = lemma_match.group(1)
771
+ if lemma_name == reseted_lemma_name:
772
+ new_local_lemmas.remove((lemma_sm_stack, lemma, is_section))
773
+ abort_match = re.match(r"\s*Abort", cmd)
774
+ if abort_match:
775
+ new_local_lemmas.pop()
776
+ end_match = re.match(r"End\s+(.*)\.", cmd)
777
+ if end_match:
778
+ new_local_lemmas = [(lemma_sm_stack, lemma, is_section) for (lemma_sm_stack, lemma, is_section)
779
+ in new_local_lemmas if not is_section]
780
+ return new_local_lemmas
781
+
782
+ def lemmas_from_cmds(filename: str, cmds: List[str]) -> List[Tuple[str, bool]]:
783
+ stack = initial_sm_stack(filename)
784
+ lemmas: List[Tuple[List[Tuple[str, bool]], str, bool]] = []
785
+ for cmd in cmds:
786
+ stack = update_sm_stack(stack, cmd)
787
+ lemmas = update_local_lemmas(lemmas, stack, cmd)
788
+ return lemmas
789
+
790
+
791
+ def lemmas_defined_by_stmt(cmd: str) -> List[str]:
792
+ cmd = kill_comments(cmd)
793
+ normal_lemma_match = re.match(
794
+ r"\s*(?:(?:Local|Global)\s+)?(?:" +
795
+ "|".join(normal_lemma_starting_patterns) +
796
+ r")\s+([\w']*)(.*)",
797
+ cmd,
798
+ flags=re.DOTALL)
799
+
800
+ if normal_lemma_match:
801
+ lemma_name = normal_lemma_match.group(1)
802
+ binders, body = unwrap(split_by_char_outside_matching(
803
+ r"\(", r"\)", ":", normal_lemma_match.group(2)))
804
+ if binders.strip():
805
+ lemma_statement = (lemma_name +
806
+ " : forall " + binders + ", " + body[1:])
807
+ else:
808
+ lemma_statement = lemma_name + " " + body
809
+ return [lemma_statement]
810
+
811
+ goal_match = re.match(r"\s*(?:Goal)\s+(.*)", cmd, flags=re.DOTALL)
812
+
813
+ if goal_match:
814
+ return [": " + goal_match.group(1)]
815
+
816
+ morphism_match = re.match(
817
+ r"\s*Add\s+(?:Parametric\s+)?Morphism.*"
818
+ r"with signature(.*)\s+as\s+(\w*)\.",
819
+ cmd, flags=re.DOTALL)
820
+ if morphism_match:
821
+ return [morphism_match.group(2) + " : " + morphism_match.group(1)]
822
+
823
+ proposition_match = re.match(r".*Inductive\s*\w+\s*:.*Prop\s*:=(.*)",
824
+ cmd, flags=re.DOTALL)
825
+ if proposition_match:
826
+ case_matches = re.finditer(r"\|\s*(\w+\s*:[^|]*)",
827
+ proposition_match.group(1))
828
+ constructor_lemmas = [case_match.group(1)
829
+ for case_match in
830
+ case_matches]
831
+ return constructor_lemmas
832
+ obligation_match = re.match(".*Obligation", cmd, flags=re.DOTALL)
833
+ if obligation_match:
834
+ return [":"]
835
+
836
+ return []
837
+
838
+ def raise_(ex):
839
+ raise ex