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,272 @@
1
+ /-
2
+ Copyright (c) 2023 Scott Morrison. All rights reserved.
3
+ Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Scott Morrison
5
+ -/
6
+ import Lean
7
+
8
+ /-!
9
+ Additional functions to deal with `InfoTree`.
10
+ -/
11
+
12
+ open Lean Elab Meta
13
+
14
+ namespace Lean.FileMap
15
+
16
+ /-- Extract the range of a `Syntax` expressed as lines and columns. -/
17
+ -- Extracted from the private declaration `Lean.Elab.formatStxRange`,
18
+ -- in `Lean.Elab.InfoTree.Main`.
19
+ def stxRange (fileMap : FileMap) (stx : Syntax) : Position × Position :=
20
+ let pos := stx.getPos?.getD 0
21
+ let endPos := stx.getTailPos?.getD pos
22
+ (fileMap.toPosition pos, fileMap.toPosition endPos)
23
+
24
+ end Lean.FileMap
25
+
26
+ namespace Lean.Syntax
27
+
28
+ /-- Check if a `Syntax` is an explicit invocation of the `sorry` tactic. -/
29
+ def isSorryTactic (stx : Syntax) : Bool :=
30
+ s!"{stx}" = "(Tactic.tacticSorry \"sorry\")"
31
+
32
+ /-- Check if a `Syntax` is an explicit `sorry` term. -/
33
+ def isSorryTerm (stx : Syntax) : Bool :=
34
+ s!"{stx}" = "(Term.sorry \"sorry\")"
35
+
36
+ end Lean.Syntax
37
+
38
+ namespace Lean.Elab
39
+
40
+ /-- Extract the range of a `Syntax` expressed as lines and columns. -/
41
+ -- Extracted from the private declaration `Lean.Elab.formatStxRange`,
42
+ -- in `Lean.Elab.InfoTree.Main`.
43
+ def stxRange (fileMap : FileMap) (stx : Syntax) : Position × Position :=
44
+ let pos := stx.getPos?.getD 0
45
+ let endPos := stx.getTailPos?.getD pos
46
+ (fileMap.toPosition pos, fileMap.toPosition endPos)
47
+
48
+ end Lean.Elab
49
+
50
+ namespace Lean.Elab.Info
51
+
52
+ /-- The type of a `Lean.Elab.Info`, as a string. -/
53
+ def kind : Info → String
54
+ | .ofTacticInfo _ => "TacticInfo"
55
+ | .ofTermInfo _ => "TermInfo"
56
+ | .ofCommandInfo _ => "CommmandInfo"
57
+ | .ofMacroExpansionInfo _ => "MacroExpansionInfo"
58
+ | .ofOptionInfo _ => "OptionInfo"
59
+ | .ofFieldInfo _ => "FieldInfo"
60
+ | .ofCompletionInfo _ => "CompletionInfo"
61
+ | .ofUserWidgetInfo _ => "UserWidgetInfo"
62
+ | .ofCustomInfo _ => "CustomInfo"
63
+ | .ofFVarAliasInfo _ => "FVarAliasInfo"
64
+ | .ofFieldRedeclInfo _ => "FieldRedeclInfo"
65
+ | .ofOmissionInfo _ => "OmissionInfo"
66
+
67
+ /-- The `Syntax` for a `Lean.Elab.Info`, if there is one. -/
68
+ def stx? : Info → Option Syntax
69
+ | .ofTacticInfo info => info.stx
70
+ | .ofTermInfo info => info.stx
71
+ | .ofCommandInfo info => info.stx
72
+ | .ofMacroExpansionInfo info => info.stx
73
+ | .ofOptionInfo info => info.stx
74
+ | .ofFieldInfo info => info.stx
75
+ | .ofCompletionInfo info => info.stx
76
+ | .ofUserWidgetInfo info => info.stx
77
+ | .ofCustomInfo info => info.stx
78
+ | .ofFVarAliasInfo _ => none
79
+ | .ofFieldRedeclInfo info => info.stx
80
+ | .ofOmissionInfo info => info.stx
81
+
82
+ /-- Is the `Syntax` for this `Lean.Elab.Info` original, or synthetic? -/
83
+ def isOriginal (i : Info) : Bool :=
84
+ match i.stx? with
85
+ | none => true -- Somewhat unclear what to do with `FVarAliasInfo`, so be conservative.
86
+ | some stx => match stx.getHeadInfo with
87
+ | .original .. => true
88
+ | _ => false
89
+
90
+ end Lean.Elab.Info
91
+ namespace Lean.Elab.TacticInfo
92
+
93
+ /-- Find the name for the outermost `Syntax` in this `TacticInfo`. -/
94
+ def name? (t : TacticInfo) : Option Name :=
95
+ match t.stx with
96
+ | Syntax.node _ n _ => some n
97
+ | _ => none
98
+
99
+ /-- Decide whether a tactic is "substantive",
100
+ or is merely a tactic combinator (e.g. `by`, `;`, multiline tactics, parenthesized tactics). -/
101
+ def isSubstantive (t : TacticInfo) : Bool :=
102
+ match t.name? with
103
+ | none => false
104
+ | some `null => false
105
+ | some ``cdot => false
106
+ | some ``cdotTk => false
107
+ | some ``Lean.Parser.Term.byTactic => false
108
+ | some ``Lean.Parser.Tactic.tacticSeq => false
109
+ | some ``Lean.Parser.Tactic.tacticSeq1Indented => false
110
+ | some ``Lean.Parser.Tactic.«tactic_<;>_» => false
111
+ | some ``Lean.Parser.Tactic.paren => false
112
+ | _ => true
113
+
114
+ end Lean.Elab.TacticInfo
115
+
116
+ namespace Lean.Elab.InfoTree
117
+
118
+ /--
119
+ Keep `.node` nodes and `.hole` nodes satisfying predicates.
120
+
121
+ Returns a `List InfoTree`, although in most situations this will be a singleton.
122
+ -/
123
+ partial def filter (p : Info → Bool) (m : MVarId → Bool := fun _ => false) :
124
+ InfoTree → List InfoTree
125
+ | .context ctx tree => tree.filter p m |>.map (.context ctx)
126
+ | .node info children =>
127
+ if p info then
128
+ [.node info (children.toList.map (filter p m)).join.toPArray']
129
+ else
130
+ (children.toList.map (filter p m)).join
131
+ | .hole mvar => if m mvar then [.hole mvar] else []
132
+
133
+ /-- Discard all nodes besides `.context` nodes and `TacticInfo` nodes. -/
134
+ partial def retainTacticInfo (tree : InfoTree) : List InfoTree :=
135
+ tree.filter fun | .ofTacticInfo _ => true | _ => false
136
+
137
+ /-- Retain only nodes with "original" syntax. -/
138
+ partial def retainOriginal (tree : InfoTree) : List InfoTree :=
139
+ tree.filter Info.isOriginal
140
+
141
+ /-- Discard all TacticInfo nodes that are tactic combinators or structuring tactics. -/
142
+ -- There is considerable grey area here: what to do with `classical`?
143
+ partial def retainSubstantive (tree : InfoTree) : List InfoTree :=
144
+ tree.filter fun | .ofTacticInfo i => i.isSubstantive | _ => true
145
+
146
+ /-- Analogue of `Lean.Elab.InfoTree.findInfo?`, but that returns all results. -/
147
+ partial def findAllInfo (t : InfoTree) (ctx? : Option ContextInfo) (p : Info → Bool) :
148
+ List (Info × Option ContextInfo) :=
149
+ match t with
150
+ | context ctx t => t.findAllInfo (ctx.mergeIntoOuter? ctx?) p
151
+ | node i ts =>
152
+ let info := if p i then [(i, ctx?)] else []
153
+ let rest := ts.toList.bind (fun t => t.findAllInfo ctx? p)
154
+ info ++ rest
155
+ | _ => []
156
+
157
+ /-- Return all `TacticInfo` nodes in an `InfoTree` with "original" syntax,
158
+ each equipped with its relevant `ContextInfo`. -/
159
+ def findTacticNodes (t : InfoTree) : List (TacticInfo × ContextInfo) :=
160
+ let infos := t.findAllInfo none fun i => match i with
161
+ | .ofTacticInfo i' => i.isOriginal && i'.isSubstantive
162
+ | _ => false
163
+ infos.filterMap fun p => match p with
164
+ | (.ofTacticInfo i, some ctx) => (i, ctx)
165
+ | _ => none
166
+
167
+ /-- Return all `TacticInfo` nodes in an `InfoTree`
168
+ corresponding to explicit invocations of the `sorry` tactic,
169
+ each equipped with its relevant `ContextInfo`. -/
170
+ def findSorryTacticNodes (t : InfoTree) : List (TacticInfo × ContextInfo) :=
171
+ let infos := t.findAllInfo none fun i => match i with
172
+ | .ofTacticInfo i => i.stx.isSorryTactic && !i.goalsBefore.isEmpty
173
+ | _ => false
174
+ infos.filterMap fun p => match p with
175
+ | (.ofTacticInfo i, some ctx) => (i, ctx)
176
+ | _ => none
177
+
178
+ /-- Return all `TermInfo` nodes in an `InfoTree`
179
+ corresponding to explicit `sorry` terms,
180
+ each equipped with its relevant `ContextInfo`. -/
181
+ def findSorryTermNodes (t : InfoTree) : List (TermInfo × ContextInfo) :=
182
+ let infos := t.findAllInfo none fun i => match i with
183
+ | .ofTermInfo i => i.stx.isSorryTerm
184
+ | _ => false
185
+ infos.filterMap fun p => match p with
186
+ | (.ofTermInfo i, some ctx) => (i, ctx)
187
+ | _ => none
188
+
189
+ inductive SorryType
190
+ | tactic : MVarId → SorryType
191
+ | term : LocalContext → Option Expr → SorryType
192
+ deriving Inhabited
193
+
194
+ /--
195
+ Finds all appearances of `sorry` in an `InfoTree`, reporting
196
+ * the `ContextInfo` at that point,
197
+ * the `MVarId` for a goal that was closed by `sorry`,
198
+ or the `Option Expr` expected type for a term supplied by `sorry`
199
+ * and the start and end positions of the `sorry` in the file.
200
+ -/
201
+ def sorries (t : InfoTree) : List (ContextInfo × SorryType × Position × Position) :=
202
+ (t.findSorryTacticNodes.map fun ⟨i, ctx⟩ =>
203
+ -- HACK: creating a child ngen
204
+ ({ ctx with mctx := i.mctxBefore, ngen := ctx.ngen.mkChild.1 }, .tactic i.goalsBefore.head!,
205
+ stxRange ctx.fileMap i.stx)) ++
206
+ (t.findSorryTermNodes.map fun ⟨i, ctx⟩ =>
207
+ (ctx, .term i.lctx i.expectedType?, stxRange ctx.fileMap i.stx))
208
+
209
+ def tactics (t : InfoTree) : List (ContextInfo × Syntax × List MVarId × Position × Position) :=
210
+ (t.findTacticNodes.map fun ⟨i, ctx⟩ =>
211
+ -- HACK: creating a child ngen
212
+ ({ ctx with mctx := i.mctxBefore, ngen := ctx.ngen.mkChild.1 }, i.stx, i.goalsBefore,
213
+ stxRange ctx.fileMap i.stx))
214
+
215
+
216
+ end Lean.Elab.InfoTree
217
+
218
+ namespace Lean.Elab.TacticInfo
219
+
220
+ /-- Return the range of the tactic, as a pair of file positions. -/
221
+ def range (info : TacticInfo) (ctx : ContextInfo) : Position × Position := ctx.fileMap.stxRange info.stx
222
+
223
+ /-- Pretty print a tactic. -/
224
+ def pp (info : TacticInfo) (ctx : ContextInfo) : IO Format :=
225
+ ctx.runMetaM {} try
226
+ Lean.PrettyPrinter.ppTactic ⟨info.stx⟩
227
+ catch _ =>
228
+ pure "<failed to pretty print>"
229
+
230
+ open Meta
231
+
232
+ /-- Run a tactic on the goals stored in a `TacticInfo`. -/
233
+ def runMetaMGoalsBefore (info : TacticInfo) (ctx : ContextInfo) (x : List MVarId → MetaM α) : IO α := do
234
+ ctx.runMetaM {} <| Meta.withMCtx info.mctxBefore <| x info.goalsBefore
235
+
236
+ /-- Run a tactic on the after goals stored in a `TacticInfo`. -/
237
+ def runMetaMGoalsAfter (info : TacticInfo) (ctx : ContextInfo) (x : List MVarId → MetaM α) : IO α := do
238
+ ctx.runMetaM {} <| Meta.withMCtx info.mctxAfter <| x info.goalsAfter
239
+
240
+ /-- Run a tactic on the main goal stored in a `TacticInfo`. -/
241
+ def runMetaM (info : TacticInfo) (ctx : ContextInfo) (x : MVarId → MetaM α) : IO α := do
242
+ match info.goalsBefore.head? with
243
+ | none => throw <| IO.userError s!"No goals at {← info.pp ctx}"
244
+ | some g => info.runMetaMGoalsBefore ctx fun _ => do g.withContext <| x g
245
+
246
+ def mainGoal (info : TacticInfo) (ctx : ContextInfo) : IO Expr :=
247
+ info.runMetaM ctx (fun g => do instantiateMVars (← g.getType))
248
+
249
+ def formatMainGoal (info : TacticInfo) (ctx : ContextInfo) : IO Format :=
250
+ info.runMetaM ctx (fun g => do ppExpr (← instantiateMVars (← g.getType)))
251
+
252
+ def goalState (info : TacticInfo) (ctx : ContextInfo) : IO (List Format) := do
253
+ info.runMetaMGoalsBefore ctx (fun gs => gs.mapM fun g => do Meta.ppGoal g)
254
+
255
+ def goalStateAfter (info : TacticInfo) (ctx : ContextInfo) : IO (List Format) := do
256
+ info.runMetaMGoalsAfter ctx (fun gs => gs.mapM fun g => do Meta.ppGoal g)
257
+
258
+ def ppExpr (info : TacticInfo) (ctx : ContextInfo) (e : Expr) : IO Format :=
259
+ info.runMetaM ctx (fun _ => do Meta.ppExpr (← instantiateMVars e))
260
+
261
+ end Lean.Elab.TacticInfo
262
+
263
+ namespace Lean.Elab.InfoTree
264
+
265
+ /--
266
+ Finds all tactic invocations in an `InfoTree`,
267
+ ignoring structuring tactics (e.g. `by`, `;`, multiline tactics, parenthesized tactics).
268
+ -/
269
+ def substantiveTactics (t : InfoTree) : List (TacticInfo × ContextInfo) :=
270
+ t.findTacticNodes.filter fun i => i.1.isSubstantive
271
+
272
+ end Lean.Elab.InfoTree
@@ -0,0 +1,323 @@
1
+ /-
2
+ Copyright (c) 2023 Scott Morrison. All rights reserved.
3
+ Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Scott Morrison
5
+ -/
6
+ import REPL.JSON
7
+ import REPL.Frontend
8
+ import REPL.Util.Path
9
+ import REPL.Lean.ContextInfo
10
+ import REPL.Lean.Environment
11
+ import REPL.Lean.InfoTree
12
+ import REPL.Lean.InfoTree.ToJson
13
+ import REPL.Snapshots
14
+
15
+ /-!
16
+ # A REPL for Lean.
17
+
18
+ Communicates via JSON on stdin and stdout. Commands should be separated by blank lines.
19
+
20
+ Commands may be of the form
21
+ ```
22
+ { "cmd" : "import Mathlib.Data.List.Basic\ndef f := 2" }
23
+ ```
24
+ or
25
+ ```
26
+ { "cmd" : "example : f = 2 := rfl", "env" : 3 }
27
+ ```
28
+
29
+ The `env` field, if present,
30
+ must contain a number received in the `env` field of a previous response,
31
+ and causes the command to be run in the existing environment.
32
+
33
+ If there is no `env` field, a new environment is created.
34
+
35
+ You can only use `import` commands when you do not specify the `env` field.
36
+
37
+ You can backtrack simply by using earlier values for `env`.
38
+
39
+ The results are of the form
40
+ ```
41
+ {"sorries":
42
+ [{"pos": {"line": 1, "column": 18},
43
+ "endPos": {"line": 1, "column": 23},
44
+ "goal": "\n⊢ Nat"}],
45
+ "messages":
46
+ [{"severity": "error",
47
+ "pos": {"line": 1, "column": 23},
48
+ "endPos": {"line": 1, "column": 26},
49
+ "data":
50
+ "type mismatch\n rfl\nhas type\n f = f : Prop\nbut is expected to have type\n f = 2 : Prop"}],
51
+ "env": 6}
52
+ ```
53
+ showing any messages generated, or sorries with their goal states.
54
+ Information is generated for tactic mode sorries, but not for term mode sorries.
55
+ -/
56
+
57
+ open Lean Elab
58
+
59
+ namespace REPL
60
+
61
+ /-- The monadic state for the Lean REPL. -/
62
+ structure State where
63
+ /--
64
+ Environment snapshots after complete declarations.
65
+ The user can run a declaration in a given environment using `{"cmd": "def f := 37", "env": 17}`.
66
+ -/
67
+ cmdStates : Array CommandSnapshot := #[]
68
+ /--
69
+ Proof states after individual tactics.
70
+ The user can run a tactic in a given proof state using `{"tactic": "exact 42", "proofState": 5}`.
71
+ Declarations with containing `sorry` record a proof state at each sorry,
72
+ and report the numerical index for the recorded state at each sorry.
73
+ -/
74
+ proofStates : Array ProofSnapshot := #[]
75
+
76
+ /--
77
+ The Lean REPL monad.
78
+
79
+ We only use this with `m := IO`, but it is set up as a monad transformer for flexibility.
80
+ -/
81
+ abbrev M (m : Type → Type) := StateT State m
82
+
83
+ variable [Monad m] [MonadLiftT IO m]
84
+
85
+ /-- Record an `CommandSnapshot` into the REPL state, returning its index for future use. -/
86
+ def recordCommandSnapshot (state : CommandSnapshot) : M m Nat := do
87
+ let id := (← get).cmdStates.size
88
+ modify fun s => { s with cmdStates := s.cmdStates.push state }
89
+ return id
90
+
91
+ /-- Record a `ProofSnapshot` into the REPL state, returning its index for future use. -/
92
+ def recordProofSnapshot (proofState : ProofSnapshot) : M m Nat := do
93
+ let id := (← get).proofStates.size
94
+ modify fun s => { s with proofStates := s.proofStates.push proofState }
95
+ return id
96
+
97
+ def sorries (trees : List InfoTree) (env? : Option Environment) : M m (List Sorry) :=
98
+ trees.bind InfoTree.sorries |>.mapM
99
+ fun ⟨ctx, g, pos, endPos⟩ => do
100
+ let (goal, proofState) ← match g with
101
+ | .tactic g => do
102
+ let s ← ProofSnapshot.create ctx none env? [g]
103
+ pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s)
104
+ | .term lctx (some t) => do
105
+ let s ← ProofSnapshot.create ctx lctx env? [] [t]
106
+ pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s)
107
+ | .term _ none => unreachable!
108
+ let proofStateId ← proofState.mapM recordProofSnapshot
109
+ return Sorry.of goal pos endPos proofStateId
110
+
111
+ def ppTactic (ctx : ContextInfo) (stx : Syntax) : IO Format :=
112
+ ctx.runMetaM {} try
113
+ Lean.PrettyPrinter.ppTactic ⟨stx⟩
114
+ catch _ =>
115
+ pure "<failed to pretty print>"
116
+
117
+ def tactics (trees : List InfoTree) : M m (List Tactic) :=
118
+ trees.bind InfoTree.tactics |>.mapM
119
+ fun ⟨ctx, stx, goals, pos, endPos⟩ => do
120
+ let proofState := some (← ProofSnapshot.create ctx none none goals)
121
+ let goals := s!"{(← ctx.ppGoals goals)}".trim
122
+ let tactic := Format.pretty (← ppTactic ctx stx)
123
+ let proofStateId ← proofState.mapM recordProofSnapshot
124
+ return Tactic.of goals tactic pos endPos proofStateId
125
+
126
+ /-- Record a `ProofSnapshot` and generate a JSON response for it. -/
127
+ def createProofStepReponse (proofState : ProofSnapshot) (old? : Option ProofSnapshot := none) :
128
+ M m ProofStepResponse := do
129
+ let messages := proofState.newMessages old?
130
+ let messages ← messages.mapM fun m => Message.of m
131
+ let traces ← proofState.newTraces old?
132
+ let trees := proofState.newInfoTrees old?
133
+ let trees ← match old? with
134
+ | some old => do
135
+ let (ctx, _) ← old.runMetaM do return { ← CommandContextInfo.save with }
136
+ let ctx := PartialContextInfo.commandCtx ctx
137
+ pure <| trees.map fun t => InfoTree.context ctx t
138
+ | none => pure trees
139
+ -- For debugging purposes, sometimes we print out the trees here:
140
+ -- trees.forM fun t => do IO.println (← t.format)
141
+ let sorries ← sorries trees none
142
+ let id ← recordProofSnapshot proofState
143
+ return {
144
+ proofState := id
145
+ goals := (← proofState.ppGoals).map fun s => s!"{s}"
146
+ messages
147
+ sorries
148
+ traces }
149
+
150
+ /-- Pickle a `CommandSnapshot`, generating a JSON response. -/
151
+ def pickleCommandSnapshot (n : PickleEnvironment) : M m (CommandResponse ⊕ Error) := do
152
+ match (← get).cmdStates[n.env]? with
153
+ | none => return .inr ⟨"Unknown environment."⟩
154
+ | some env =>
155
+ discard <| env.pickle n.pickleTo
156
+ return .inl { env := n.env }
157
+
158
+ /-- Unpickle a `CommandSnapshot`, generating a JSON response. -/
159
+ def unpickleCommandSnapshot (n : UnpickleEnvironment) : M IO CommandResponse := do
160
+ let (env, _) ← CommandSnapshot.unpickle n.unpickleEnvFrom
161
+ let env ← recordCommandSnapshot env
162
+ return { env }
163
+
164
+ /-- Pickle a `ProofSnapshot`, generating a JSON response. -/
165
+ -- This generates a new identifier, which perhaps is not what we want?
166
+ def pickleProofSnapshot (n : PickleProofState) : M m (ProofStepResponse ⊕ Error) := do
167
+ match (← get).proofStates[n.proofState]? with
168
+ | none => return .inr ⟨"Unknown proof State."⟩
169
+ | some proofState =>
170
+ discard <| proofState.pickle n.pickleTo
171
+ return .inl (← createProofStepReponse proofState)
172
+
173
+ /-- Unpickle a `ProofSnapshot`, generating a JSON response. -/
174
+ def unpickleProofSnapshot (n : UnpickleProofState) : M IO (ProofStepResponse ⊕ Error) := do
175
+ let (cmdSnapshot?, notFound) ← do match n.env with
176
+ | none => pure (none, false)
177
+ | some i => do match (← get).cmdStates[i]? with
178
+ | some env => pure (some env, false)
179
+ | none => pure (none, true)
180
+ if notFound then
181
+ return .inr ⟨"Unknown environment."⟩
182
+ let (proofState, _) ← ProofSnapshot.unpickle n.unpickleProofStateFrom cmdSnapshot?
183
+ Sum.inl <$> createProofStepReponse proofState
184
+
185
+ /--
186
+ Run a command, returning the id of the new environment, and any messages and sorries.
187
+ -/
188
+ def runCommand (s : Command) : M IO (CommandResponse ⊕ Error) := do
189
+ let (cmdSnapshot?, notFound) ← do match s.env with
190
+ | none => pure (none, false)
191
+ | some i => do match (← get).cmdStates[i]? with
192
+ | some env => pure (some env, false)
193
+ | none => pure (none, true)
194
+ if notFound then
195
+ return .inr ⟨"Unknown environment."⟩
196
+ let initialCmdState? := cmdSnapshot?.map fun c => c.cmdState
197
+ let (cmdState, messages, trees) ← try
198
+ IO.processInput s.cmd initialCmdState?
199
+ catch ex =>
200
+ return .inr ⟨ex.toString⟩
201
+ let messages ← messages.mapM fun m => Message.of m
202
+ -- For debugging purposes, sometimes we print out the trees here:
203
+ -- trees.forM fun t => do IO.println (← t.format)
204
+ let sorries ← sorries trees (initialCmdState?.map (·.env))
205
+ let tactics ← match s.allTactics with
206
+ | some true => tactics trees
207
+ | _ => pure []
208
+ let cmdSnapshot :=
209
+ { cmdState
210
+ cmdContext := (cmdSnapshot?.map fun c => c.cmdContext).getD
211
+ { fileName := "", fileMap := default, tacticCache? := none } }
212
+ let env ← recordCommandSnapshot cmdSnapshot
213
+ let jsonTrees := match s.infotree with
214
+ | some "full" => trees
215
+ | some "tactics" => trees.bind InfoTree.retainTacticInfo
216
+ | some "original" => trees.bind InfoTree.retainTacticInfo |>.bind InfoTree.retainOriginal
217
+ | some "substantive" => trees.bind InfoTree.retainTacticInfo |>.bind InfoTree.retainSubstantive
218
+ | _ => []
219
+ let infotree := if jsonTrees.isEmpty then
220
+ none
221
+ else
222
+ some <| Json.arr (← jsonTrees.toArray.mapM fun t => t.toJson none)
223
+ return .inl
224
+ { env,
225
+ messages,
226
+ sorries,
227
+ tactics
228
+ infotree }
229
+
230
+ def processFile (s : File) : M IO (CommandResponse ⊕ Error) := do
231
+ try
232
+ let cmd ← IO.FS.readFile s.path
233
+ runCommand { s with env := none, cmd }
234
+ catch e =>
235
+ pure <| .inr ⟨e.toString⟩
236
+
237
+ /--
238
+ Run a single tactic, returning the id of the new proof statement, and the new goals.
239
+ -/
240
+ -- TODO detect sorries?
241
+ def runProofStep (s : ProofStep) : M IO (ProofStepResponse ⊕ Error) := do
242
+ match (← get).proofStates[s.proofState]? with
243
+ | none => return .inr ⟨"Unknown proof state."⟩
244
+ | some proofState =>
245
+ try
246
+ let proofState' ← proofState.runString s.tactic
247
+ return .inl (← createProofStepReponse proofState' proofState)
248
+ catch ex =>
249
+ return .inr ⟨"Lean error:\n" ++ ex.toString⟩
250
+
251
+ end REPL
252
+
253
+ open REPL
254
+
255
+ /-- Get lines from stdin until a blank line is entered. -/
256
+ partial def getLines : IO String := do
257
+ let line ← (← IO.getStdin).getLine
258
+ if line.trim.isEmpty then
259
+ return line
260
+ else
261
+ return line ++ (← getLines)
262
+
263
+ instance [ToJson α] [ToJson β] : ToJson (α ⊕ β) where
264
+ toJson x := match x with
265
+ | .inl a => toJson a
266
+ | .inr b => toJson b
267
+
268
+ /-- Commands accepted by the REPL. -/
269
+ inductive Input
270
+ | command : REPL.Command → Input
271
+ | file : REPL.File → Input
272
+ | proofStep : REPL.ProofStep → Input
273
+ | pickleEnvironment : REPL.PickleEnvironment → Input
274
+ | unpickleEnvironment : REPL.UnpickleEnvironment → Input
275
+ | pickleProofSnapshot : REPL.PickleProofState → Input
276
+ | unpickleProofSnapshot : REPL.UnpickleProofState → Input
277
+
278
+ /-- Parse a user input string to an input command. -/
279
+ def parse (query : String) : IO Input := do
280
+ let json := Json.parse query
281
+ match json with
282
+ | .error e => throw <| IO.userError <| toString <| toJson <|
283
+ (⟨"Could not parse JSON:\n" ++ e⟩ : Error)
284
+ | .ok j => match fromJson? j with
285
+ | .ok (r : REPL.ProofStep) => return .proofStep r
286
+ | .error _ => match fromJson? j with
287
+ | .ok (r : REPL.PickleEnvironment) => return .pickleEnvironment r
288
+ | .error _ => match fromJson? j with
289
+ | .ok (r : REPL.UnpickleEnvironment) => return .unpickleEnvironment r
290
+ | .error _ => match fromJson? j with
291
+ | .ok (r : REPL.PickleProofState) => return .pickleProofSnapshot r
292
+ | .error _ => match fromJson? j with
293
+ | .ok (r : REPL.UnpickleProofState) => return .unpickleProofSnapshot r
294
+ | .error _ => match fromJson? j with
295
+ | .ok (r : REPL.Command) => return .command r
296
+ | .error _ => match fromJson? j with
297
+ | .ok (r : REPL.File) => return .file r
298
+ | .error e => throw <| IO.userError <| toString <| toJson <|
299
+ (⟨"Could not parse as a valid JSON command:\n" ++ e⟩ : Error)
300
+
301
+ /-- Read-eval-print loop for Lean. -/
302
+ unsafe def repl : IO Unit :=
303
+ StateT.run' loop {}
304
+ where loop : M IO Unit := do
305
+ let query ← getLines
306
+ if query = "" then
307
+ return ()
308
+ if query.startsWith "#" || query.startsWith "--" then loop else
309
+ IO.println <| toString <| ← match ← parse query with
310
+ | .command r => return toJson (← runCommand r)
311
+ | .file r => return toJson (← processFile r)
312
+ | .proofStep r => return toJson (← runProofStep r)
313
+ | .pickleEnvironment r => return toJson (← pickleCommandSnapshot r)
314
+ | .unpickleEnvironment r => return toJson (← unpickleCommandSnapshot r)
315
+ | .pickleProofSnapshot r => return toJson (← pickleProofSnapshot r)
316
+ | .unpickleProofSnapshot r => return toJson (← unpickleProofSnapshot r)
317
+ IO.println "" -- easier to parse the output if there are blank lines
318
+ loop
319
+
320
+ /-- Main executable function, run as `lake exe repl`. -/
321
+ unsafe def main (_ : List String) : IO Unit := do
322
+ initSearchPath (← Lean.findSysroot)
323
+ repl