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.
- itp_interface/__init__.py +0 -0
- itp_interface/agent/__init__.py +0 -0
- itp_interface/agent/simple_proof_agent.py +100 -0
- itp_interface/coq_ser_api/__init__.py +165 -0
- itp_interface/coq_ser_api/contexts.py +283 -0
- itp_interface/coq_ser_api/coq_agent.py +459 -0
- itp_interface/coq_ser_api/coq_backend.py +135 -0
- itp_interface/coq_ser_api/coq_util.py +839 -0
- itp_interface/coq_ser_api/example.py +67 -0
- itp_interface/coq_ser_api/lsp_backend.py +375 -0
- itp_interface/coq_ser_api/py.typed +0 -0
- itp_interface/coq_ser_api/serapi_backend.py +841 -0
- itp_interface/coq_ser_api/util.py +145 -0
- itp_interface/coq_ser_api_old/__init__.py +2583 -0
- itp_interface/coq_ser_api_old/contexts.py +172 -0
- itp_interface/coq_ser_api_old/util.py +146 -0
- itp_interface/lean_server/__init__.py +0 -0
- itp_interface/lean_server/commands.py +484 -0
- itp_interface/lean_server/lean3_search_tool.py +358 -0
- itp_interface/lean_server/lean4_repl_interface.py +151 -0
- itp_interface/lean_server/lean4_utils.py +255 -0
- itp_interface/lean_server/lean_cmd_server.py +111 -0
- itp_interface/lean_server/lean_context.py +60 -0
- itp_interface/lean_server/lean_sync_server.py +174 -0
- itp_interface/lean_server/lean_utils.py +199 -0
- itp_interface/lean_server/py.typed +1 -0
- itp_interface/main/__init__.py +0 -0
- itp_interface/main/config/afp_data_gen.yaml +14 -0
- itp_interface/main/config/benchmark/CompCert.yaml +366 -0
- itp_interface/main/config/benchmark/GeoCoq.yaml +930 -0
- itp_interface/main/config/benchmark/UniMath.yaml +2690 -0
- itp_interface/main/config/benchmark/afp_isabelle.yaml +29200 -0
- itp_interface/main/config/benchmark/agent_proverbot_hard.yaml +247 -0
- itp_interface/main/config/benchmark/category-theory.yaml +470 -0
- itp_interface/main/config/benchmark/compcert_118_subset.yaml +148 -0
- itp_interface/main/config/benchmark/compcert_benchmark.yaml +36 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard.yaml +498 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_1.yaml +55 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_2.yaml +24 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_3.yaml +95 -0
- itp_interface/main/config/benchmark/compcert_benchmark_hard_7_per_cent.yaml +78 -0
- itp_interface/main/config/benchmark/compcert_benchmark_test.yaml +38 -0
- itp_interface/main/config/benchmark/compcert_benchmark_train.yaml +340 -0
- itp_interface/main/config/benchmark/leandojo_novel_premises_test.yaml +2908 -0
- itp_interface/main/config/benchmark/leandojo_novel_premises_train.yaml +98645 -0
- itp_interface/main/config/benchmark/leandojo_novel_premises_val.yaml +2912 -0
- itp_interface/main/config/benchmark/leandojo_random.yaml +2889 -0
- itp_interface/main/config/benchmark/leandojo_random_test.yaml +2421 -0
- itp_interface/main/config/benchmark/leandojo_random_train.yaml +62729 -0
- itp_interface/main/config/benchmark/leandojo_random_val.yaml +2504 -0
- itp_interface/main/config/benchmark/math-comp.yaml +200 -0
- itp_interface/main/config/benchmark/miniF2F_test.yaml +12 -0
- itp_interface/main/config/benchmark/miniF2F_test_aime.yaml +27 -0
- itp_interface/main/config/benchmark/miniF2F_test_algebra.yaml +30 -0
- itp_interface/main/config/benchmark/miniF2F_test_amc12.yaml +57 -0
- itp_interface/main/config/benchmark/miniF2F_test_few_shot_hard.yaml +231 -0
- itp_interface/main/config/benchmark/miniF2F_test_imo.yaml +32 -0
- itp_interface/main/config/benchmark/miniF2F_test_induction.yaml +20 -0
- itp_interface/main/config/benchmark/miniF2F_test_mathd_algebra.yaml +82 -0
- itp_interface/main/config/benchmark/miniF2F_test_mathd_algebra_hard.yaml +72 -0
- itp_interface/main/config/benchmark/miniF2F_test_mathd_numbertheory.yaml +72 -0
- itp_interface/main/config/benchmark/miniF2F_test_numbertheory.yaml +20 -0
- itp_interface/main/config/benchmark/minicompcert_benchmark_1.yaml +14 -0
- itp_interface/main/config/benchmark/proverbot_hard.yaml +104 -0
- itp_interface/main/config/benchmark/re_prover.yaml +66 -0
- itp_interface/main/config/benchmark/re_prover_hard.yaml +41 -0
- itp_interface/main/config/benchmark/re_prover_very_hard.yaml +22 -0
- itp_interface/main/config/benchmark/reprover_with_retrieval.yaml +73 -0
- itp_interface/main/config/benchmark/reprover_with_retrieval_hard.yaml +30 -0
- itp_interface/main/config/benchmark/reprover_with_retrieval_neg.yaml +195 -0
- itp_interface/main/config/benchmark/simple_benchmark_1.yaml +24 -0
- itp_interface/main/config/benchmark/simple_benchmark_8.yaml +50 -0
- itp_interface/main/config/benchmark/simple_benchmark_9.yaml +65 -0
- itp_interface/main/config/benchmark/simple_benchmark_isabelle.yaml +18 -0
- itp_interface/main/config/benchmark/simple_benchmark_lean.yaml +12 -0
- itp_interface/main/config/benchmark/simple_benchmark_lean_training_data.yaml +12 -0
- itp_interface/main/config/benchmark/simple_rl_benchmark_lean.yaml +14 -0
- itp_interface/main/config/benchmark/stack_machine.yaml +13 -0
- itp_interface/main/config/benchmark/stack_machine_hard.yaml +15 -0
- itp_interface/main/config/category_theory_data_gen.yaml +14 -0
- itp_interface/main/config/category_theory_data_gen_random.yaml +16 -0
- itp_interface/main/config/compcert_data_gen_test.yaml +10 -0
- itp_interface/main/config/compcert_data_gen_train.yaml +7 -0
- itp_interface/main/config/env_settings/bm25_retrieval.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_no_dfns.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_only_local_no_dfns.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_with_print.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_with_print_only_local.yaml +2 -0
- itp_interface/main/config/env_settings/bm25_retrieval_with_print_only_local_no_dfns.yaml +2 -0
- itp_interface/main/config/env_settings/no_retrieval.yaml +2 -0
- itp_interface/main/config/experiments.yaml +12 -0
- itp_interface/main/config/geo_coq_data_gen.yaml +14 -0
- itp_interface/main/config/geo_coq_data_gen_random.yaml +16 -0
- itp_interface/main/config/leandojo_random_data_gen.yaml +16 -0
- itp_interface/main/config/math_comp_data_gen.yaml +14 -0
- itp_interface/main/config/math_comp_data_gen_random.yaml +16 -0
- itp_interface/main/config/mathlib_data_gen.yaml +14 -0
- itp_interface/main/config/repo/coq_repos.yaml +191 -0
- itp_interface/main/config/run_settings/default_coq_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/run_settings/default_isabelle_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/run_settings/default_lean4_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/run_settings/default_lean_data_generation_transforms.yaml +24 -0
- itp_interface/main/config/simple_coq_data_gen.yaml +12 -0
- itp_interface/main/config/simple_coq_data_gen_random.yaml +17 -0
- itp_interface/main/config/simple_lean_data_gen.yaml +12 -0
- itp_interface/main/config/simple_rl_lean_data_gen.yaml +12 -0
- itp_interface/main/config/uni_math_data_gen.yaml +14 -0
- itp_interface/main/config.py +192 -0
- itp_interface/main/extract_benchmark_dataset.py +106 -0
- itp_interface/main/filter_dataset.py +107 -0
- itp_interface/main/install.py +92 -0
- itp_interface/main/merge_dataset.py +96 -0
- itp_interface/main/run_tool.py +444 -0
- itp_interface/pisa/.git +1 -0
- itp_interface/pisa/.gitignore +125 -0
- itp_interface/pisa/.idea/.gitignore +8 -0
- itp_interface/pisa/.idea/ClojureProjectResolveSettings.xml +6 -0
- itp_interface/pisa/.idea/codeStyles/Project.xml +7 -0
- itp_interface/pisa/.idea/codeStyles/codeStyleConfig.xml +5 -0
- itp_interface/pisa/.idea/inspectionProfiles/Project_Default.xml +16 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_android_annotations_4_1_1_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_api_grpc_proto_google_common_protos_1_17_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_code_findbugs_jsr305_3_0_2_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_code_gson_gson_2_8_6_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_errorprone_error_prone_annotations_2_3_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_guava_failureaccess_1_0_1_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_guava_guava_30_0_jre_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava_jar.xml +9 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_j2objc_j2objc_annotations_1_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_protobuf_protobuf_java_3_12_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_google_protobuf_protobuf_java_util_3_12_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_fastparse_2_13_2_3_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_geny_2_13_0_6_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_lihaoyi_sourcecode_2_13_0_2_1_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_lenses_2_13_0_10_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_scalapb_runtime_2_13_0_10_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_scalapb_runtime_grpc_2_13_0_10_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thesamet_scalapb_zio_grpc_zio_grpc_core_2_13_0_4_2_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__com_thoughtworks_paranamer_paranamer_2_8_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__commons_io_commons_io_2_8_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__de_unruh_java_patterns_0_1_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__de_unruh_scala_isabelle_2_13_master_SNAPSHOT_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_izumi_reflect_2_13_1_0_0_M9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_izumi_reflect_thirdparty_boopickle_shaded_2_13_1_0_0_M9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_2_13_1_0_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_stacktracer_2_13_1_0_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__dev_zio_zio_streams_2_13_1_0_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_api_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_context_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_core_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_netty_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_protobuf_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_protobuf_lite_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_services_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_grpc_grpc_stub_1_34_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_buffer_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_http2_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_http_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_codec_socks_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_common_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_handler_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_handler_proxy_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_resolver_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_netty_netty_transport_4_1_51_Final_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__io_perfmark_perfmark_api_0_19_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__net_java_dev_jna_jna_5_3_1_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__net_liftweb_lift_json_2_13_3_4_3_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_apache_commons_commons_lang3_3_11_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_apache_commons_commons_text_1_9_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_checkerframework_checker_qual_3_5_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_codehaus_mojo_animal_sniffer_annotations_1_18_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_jetbrains_annotations_20_1_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_jline_jline_3_16_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_log4s_log4s_2_13_1_9_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_modules_scala_collection_compat_2_13_2_1_6_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_modules_scala_xml_2_13_1_3_0_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_compiler_2_13_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_library_2_13_4_jar.xml +23 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scala_reflect_2_13_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scala_lang_scalap_2_13_4_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_scalaz_scalaz_core_2_13_7_3_2_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_slf4j_slf4j_api_1_7_30_jar.xml +13 -0
- itp_interface/pisa/.idea/libraries/sbt__org_slf4j_slf4j_simple_1_7_30_jar.xml +13 -0
- itp_interface/pisa/.idea/misc.xml +7 -0
- itp_interface/pisa/.idea/modules/PISA-build.iml +127 -0
- itp_interface/pisa/.idea/modules/PISA.iml +94 -0
- itp_interface/pisa/.idea/modules.xml +9 -0
- itp_interface/pisa/.idea/other.xml +6 -0
- itp_interface/pisa/.idea/sbt.xml +20 -0
- itp_interface/pisa/.idea/scala_compiler.xml +6 -0
- itp_interface/pisa/.idea/uiDesigner.xml +124 -0
- itp_interface/pisa/.idea/vcs.xml +6 -0
- itp_interface/pisa/.scalafmt.conf +2 -0
- itp_interface/pisa/LICENSE +29 -0
- itp_interface/pisa/README.md +262 -0
- itp_interface/pisa/build.sbt +49 -0
- itp_interface/pisa/build.sh +26 -0
- itp_interface/pisa/command_generation/close_gaps.py +44 -0
- itp_interface/pisa/command_generation/conjecture_normal_order.py +62 -0
- itp_interface/pisa/command_generation/conjecturer_command_generator.py +36 -0
- itp_interface/pisa/command_generation/create_dirs.py +11 -0
- itp_interface/pisa/command_generation/find_std.py +67 -0
- itp_interface/pisa/command_generation/generate_build_commands_afp.py +15 -0
- itp_interface/pisa/command_generation/generate_build_commands_std.py +15 -0
- itp_interface/pisa/command_generation/generate_commands_afp.py +103 -0
- itp_interface/pisa/command_generation/generate_commands_mini.py +73 -0
- itp_interface/pisa/command_generation/generate_commands_std.py +69 -0
- itp_interface/pisa/command_generation/generate_hammer_extraction_text.py +5 -0
- itp_interface/pisa/command_generation/hammer_command_generator.py +40 -0
- itp_interface/pisa/command_generation/hp_search_command_generator.py +63 -0
- itp_interface/pisa/command_generation/oracle_command_generator.py +56 -0
- itp_interface/pisa/command_generation/search_command_generator.py +69 -0
- itp_interface/pisa/command_generation/summarise_problem_names.py +45 -0
- itp_interface/pisa/command_generation/tpu_hp_search.py +75 -0
- itp_interface/pisa/docker/Dockerfile +34 -0
- itp_interface/pisa/docker/docker_tutorial.md +64 -0
- itp_interface/pisa/eval_setup/copy_isabelle.py +42 -0
- itp_interface/pisa/eval_setup/copy_pisa_jars.py +18 -0
- itp_interface/pisa/mesh_transformer_utils/tokenization.py +86 -0
- itp_interface/pisa/project/build.properties +1 -0
- itp_interface/pisa/project/plugins.sbt +5 -0
- itp_interface/pisa/requirements.txt +4 -0
- itp_interface/pisa/scripts/extract_last_k_steps.py +28 -0
- itp_interface/pisa/scripts/extract_proof_corpus.py +26 -0
- itp_interface/pisa/scripts/gather_hammer_results.py +27 -0
- itp_interface/pisa/scripts/length_in_char_stats.py +20 -0
- itp_interface/pisa/scripts/mix.py +127 -0
- itp_interface/pisa/scripts/results_stat.py +52 -0
- itp_interface/pisa/scripts/test_array_job.sh +34 -0
- itp_interface/pisa/setup.sh +25 -0
- itp_interface/pisa/src/main/protobuf/server.proto +60 -0
- itp_interface/pisa/src/main/python/.idea/.gitignore +8 -0
- itp_interface/pisa/src/main/python/.idea/inspectionProfiles/Project_Default.xml +18 -0
- itp_interface/pisa/src/main/python/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- itp_interface/pisa/src/main/python/.idea/misc.xml +4 -0
- itp_interface/pisa/src/main/python/.idea/modules.xml +8 -0
- itp_interface/pisa/src/main/python/.idea/python.iml +12 -0
- itp_interface/pisa/src/main/python/.idea/vcs.xml +6 -0
- itp_interface/pisa/src/main/python/conjecturing_parsing/conjecturer_postprocessing.py +59 -0
- itp_interface/pisa/src/main/python/data_extraction/extract_data.py +184 -0
- itp_interface/pisa/src/main/python/data_extraction/find_premises.py +221 -0
- itp_interface/pisa/src/main/python/data_extraction/process_data.py +129 -0
- itp_interface/pisa/src/main/python/legacy/PisaFlexibleClient.py +167 -0
- itp_interface/pisa/src/main/python/legacy/autof_test.py +74 -0
- itp_interface/pisa/src/main/python/legacy/cmd_client.py +23 -0
- itp_interface/pisa/src/main/python/legacy/convert_scala_dump_to_test_name_jsons.py +14 -0
- itp_interface/pisa/src/main/python/legacy/create_data_txt.py +72 -0
- itp_interface/pisa/src/main/python/legacy/create_finetune_tfrecords.py +311 -0
- itp_interface/pisa/src/main/python/legacy/demo.py +49 -0
- itp_interface/pisa/src/main/python/legacy/evaluate.py +108 -0
- itp_interface/pisa/src/main/python/legacy/extract_first_step.py +25 -0
- itp_interface/pisa/src/main/python/legacy/get_global_facts.py +35 -0
- itp_interface/pisa/src/main/python/legacy/mix_data.py +19 -0
- itp_interface/pisa/src/main/python/legacy/one_stage_extraction.py +111 -0
- itp_interface/pisa/src/main/python/legacy/prepare_episodic_transitions.py +137 -0
- itp_interface/pisa/src/main/python/legacy/prepare_translation_pairs.py +277 -0
- itp_interface/pisa/src/main/python/pisa_client.py +322 -0
- itp_interface/pisa/src/main/python/server_pb2.py +394 -0
- itp_interface/pisa/src/main/python/server_pb2_grpc.py +230 -0
- itp_interface/pisa/src/main/python/test_client.py +17 -0
- itp_interface/pisa/src/main/python/test_client2.py +79 -0
- itp_interface/pisa/src/main/python/utils/filters.py +59 -0
- itp_interface/pisa/src/main/python/utils/pisa_server_control.py +29 -0
- itp_interface/pisa/src/main/scala/pisa/agent/CheckSyntax.scala +257 -0
- itp_interface/pisa/src/main/scala/pisa/agent/DepThms.scala +29 -0
- itp_interface/pisa/src/main/scala/pisa/agent/PisaStat.scala +46 -0
- itp_interface/pisa/src/main/scala/pisa/agent/RefactorTest.scala +40 -0
- itp_interface/pisa/src/main/scala/pisa/agent/RepHammer.scala +95 -0
- itp_interface/pisa/src/main/scala/pisa/server/HammFacts.scala +63 -0
- itp_interface/pisa/src/main/scala/pisa/server/PisaOS.scala +881 -0
- itp_interface/pisa/src/main/scala/pisa/server/PisaOneStage.scala +540 -0
- itp_interface/pisa/src/main/scala/pisa/server/PisaOneStageServers.scala +1048 -0
- itp_interface/pisa/src/main/scala/pisa/utils/TheoryManager.scala +95 -0
- itp_interface/pisa/src/test/python/analyse_debug.py +33 -0
- itp_interface/pisa/src/test/python/extract_test_seq2seq.py +53 -0
- itp_interface/pisa/src/test/python/extract_test_theorem_ground_truth_indices.py +31 -0
- itp_interface/pisa/src/test/python/proof_originality.py +24 -0
- itp_interface/pisa/src/test/python/test_command_generator.py +25 -0
- itp_interface/pisa/src/test/python/test_model_sequence_accuracy.py +70 -0
- itp_interface/pisa/src/test/scala/pisa/Easy.scala +26 -0
- itp_interface/pisa/src/test/scala/pisa/TestCurl.scala +82 -0
- itp_interface/pisa/src/test/scala/pisa/TestIsa.scala +27 -0
- itp_interface/pisa/test.sh +19 -0
- itp_interface/pisa/universal_test_theorems.tar.gz +0 -0
- itp_interface/repo/build.py +78 -0
- itp_interface/repo/clone.py +79 -0
- itp_interface/repo/dataset_discovery.py +99 -0
- itp_interface/retrieval/__init__.py +0 -0
- itp_interface/retrieval/abstraction.py +35 -0
- itp_interface/retrieval/coq_bm25_reranker.py +153 -0
- itp_interface/retrieval/isabelle_bm25_reranker.py +86 -0
- itp_interface/retrieval/lean3_bm25_reranker.py +86 -0
- itp_interface/rl/__init__.py +0 -0
- itp_interface/rl/abstraction.py +168 -0
- itp_interface/rl/proof_action.py +172 -0
- itp_interface/rl/proof_state.py +149 -0
- itp_interface/rl/proof_tree.py +109 -0
- itp_interface/rl/simpl_proof_env_pool.py +16 -0
- itp_interface/rl/simple_proof_env.py +713 -0
- itp_interface/rl/simple_proof_env_pool.py +591 -0
- itp_interface/scripts/setup.sh +228 -0
- itp_interface/tools/__init__.py +0 -0
- itp_interface/tools/basic_utils.py +172 -0
- itp_interface/tools/bin_packing.py +61 -0
- itp_interface/tools/cache.py +93 -0
- itp_interface/tools/coq_build_spec.py +31 -0
- itp_interface/tools/coq_build_tool.py +319 -0
- itp_interface/tools/coq_context_helper.py +354 -0
- itp_interface/tools/coq_executor.py +508 -0
- itp_interface/tools/coq_local_data_generation_transform.py +158 -0
- itp_interface/tools/coq_parse_utils.py +154 -0
- itp_interface/tools/coq_raw_proofs.py +193 -0
- itp_interface/tools/coq_theorem_proof_pair_generation_transform.py +146 -0
- itp_interface/tools/coq_training_data_generator.py +76 -0
- itp_interface/tools/dynamic_coq_proof_exec.py +220 -0
- itp_interface/tools/dynamic_isabelle_proof_exec.py +229 -0
- itp_interface/tools/dynamic_lean4_proof_exec.py +236 -0
- itp_interface/tools/dynamic_lean_proof_exec.py +228 -0
- itp_interface/tools/isabelle_context_helper.py +66 -0
- itp_interface/tools/isabelle_executor.py +862 -0
- itp_interface/tools/isabelle_local_data_generation_transform.py +149 -0
- itp_interface/tools/isabelle_parse_utils.py +131 -0
- itp_interface/tools/isabelle_server.py +106 -0
- itp_interface/tools/lean4_context_helper.py +72 -0
- itp_interface/tools/lean4_local_data_generation_transform.py +122 -0
- itp_interface/tools/lean4_sync_executor.py +1193 -0
- itp_interface/tools/lean_cmd_executor.py +804 -0
- itp_interface/tools/lean_context_helper.py +327 -0
- itp_interface/tools/lean_dojo_data_generation_transform.py +206 -0
- itp_interface/tools/lean_executor.py +687 -0
- itp_interface/tools/lean_local_data_generation_transform.py +136 -0
- itp_interface/tools/lean_parse_utils.py +32 -0
- itp_interface/tools/log_utils.py +20 -0
- itp_interface/tools/proof_exec_callback.py +76 -0
- itp_interface/tools/ray_utils.py +265 -0
- itp_interface/tools/repl/.git +1 -0
- itp_interface/tools/repl/.github/workflows/ci.yml +24 -0
- itp_interface/tools/repl/.gitignore +7 -0
- itp_interface/tools/repl/.vscode/copyright.code-snippets +13 -0
- itp_interface/tools/repl/.vscode/extensions.json +13 -0
- itp_interface/tools/repl/.vscode/module-docstring.code-snippets +35 -0
- itp_interface/tools/repl/.vscode/settings.json +11 -0
- itp_interface/tools/repl/README.md +174 -0
- itp_interface/tools/repl/REPL/Frontend.lean +47 -0
- itp_interface/tools/repl/REPL/JSON.lean +186 -0
- itp_interface/tools/repl/REPL/Lean/ContextInfo.lean +9 -0
- itp_interface/tools/repl/REPL/Lean/Environment.lean +31 -0
- itp_interface/tools/repl/REPL/Lean/InfoTree/ToJson.lean +114 -0
- itp_interface/tools/repl/REPL/Lean/InfoTree.lean +272 -0
- itp_interface/tools/repl/REPL/Main.lean +323 -0
- itp_interface/tools/repl/REPL/Snapshots.lean +306 -0
- itp_interface/tools/repl/REPL/Util/Path.lean +36 -0
- itp_interface/tools/repl/REPL/Util/Pickle.lean +44 -0
- itp_interface/tools/repl/REPL.lean +4 -0
- itp_interface/tools/repl/lake-manifest.json +5 -0
- itp_interface/tools/repl/lakefile.lean +15 -0
- itp_interface/tools/repl/lean-toolchain +1 -0
- itp_interface/tools/repl/test/Mathlib/.gitignore +5 -0
- itp_interface/tools/repl/test/Mathlib/H20231110.sh +2 -0
- itp_interface/tools/repl/test/Mathlib/ReplMathlibTests.lean +1 -0
- itp_interface/tools/repl/test/Mathlib/lake-manifest.json +68 -0
- itp_interface/tools/repl/test/Mathlib/lakefile.lean +11 -0
- itp_interface/tools/repl/test/Mathlib/lean-toolchain +1 -0
- itp_interface/tools/repl/test/Mathlib/test/20240209.expected.out +20 -0
- itp_interface/tools/repl/test/Mathlib/test/20240209.in +3 -0
- itp_interface/tools/repl/test/Mathlib/test/20240209.lean +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231020.expected.out +8 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231020.in +8 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231020.lean +22 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231110.expected.out +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231110.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115.expected.out +19 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115.in +5 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_2.expected.out +18 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_2.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_3.expected.out +10 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231115_3.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231214.in +9 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231214.lean +30 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215.expected.out +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215_2.expected.out +14 -0
- itp_interface/tools/repl/test/Mathlib/test/H20231215_2.in +3 -0
- itp_interface/tools/repl/test/Mathlib/test/exact.expected.out +37 -0
- itp_interface/tools/repl/test/Mathlib/test/exact.in +10 -0
- itp_interface/tools/repl/test/Mathlib/test/import_Mathlib.lean +1 -0
- itp_interface/tools/repl/test/Mathlib/test/induction.expected.out +29 -0
- itp_interface/tools/repl/test/Mathlib/test/induction.in +10 -0
- itp_interface/tools/repl/test/Mathlib/test/induction.lean +6 -0
- itp_interface/tools/repl/test/Mathlib/test/on_goal.expected.out +22 -0
- itp_interface/tools/repl/test/Mathlib/test/on_goal.in +5 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle.expected.out +16 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle.in +6 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle_2.expected.out +4 -0
- itp_interface/tools/repl/test/Mathlib/test/pickle_2.in +4 -0
- itp_interface/tools/repl/test/Mathlib/test.sh +41 -0
- itp_interface/tools/repl/test/all_tactics.expected.out +13 -0
- itp_interface/tools/repl/test/all_tactics.in +1 -0
- itp_interface/tools/repl/test/by_cases.expected.out +25 -0
- itp_interface/tools/repl/test/by_cases.in +8 -0
- itp_interface/tools/repl/test/by_cases.lean +4 -0
- itp_interface/tools/repl/test/calc.expected.out +32 -0
- itp_interface/tools/repl/test/calc.in +1 -0
- itp_interface/tools/repl/test/def_eval.expected.out +9 -0
- itp_interface/tools/repl/test/def_eval.in +3 -0
- itp_interface/tools/repl/test/enableInitializersExecution.expected.out +2 -0
- itp_interface/tools/repl/test/enableInitializersExecution.in +1 -0
- itp_interface/tools/repl/test/file.expected.out +8 -0
- itp_interface/tools/repl/test/file.in +1 -0
- itp_interface/tools/repl/test/file.lean +5 -0
- itp_interface/tools/repl/test/have_by_sorry.expected.out +28 -0
- itp_interface/tools/repl/test/have_by_sorry.in +6 -0
- itp_interface/tools/repl/test/import_lean.in +1 -0
- itp_interface/tools/repl/test/incomplete.expected.out +18 -0
- itp_interface/tools/repl/test/incomplete.in +3 -0
- itp_interface/tools/repl/test/incomplete.lean +0 -0
- itp_interface/tools/repl/test/infotree.expected.out +20 -0
- itp_interface/tools/repl/test/infotree.in +2 -0
- itp_interface/tools/repl/test/invalid_tactic.expected.out +20 -0
- itp_interface/tools/repl/test/invalid_tactic.in +3 -0
- itp_interface/tools/repl/test/name_generator.expected.out +53 -0
- itp_interface/tools/repl/test/name_generator.in +18 -0
- itp_interface/tools/repl/test/no_goal_sorry.expected.out +11 -0
- itp_interface/tools/repl/test/no_goal_sorry.in +1 -0
- itp_interface/tools/repl/test/no_goal_sorry_2.expected.out +12 -0
- itp_interface/tools/repl/test/no_goal_sorry_2.in +1 -0
- itp_interface/tools/repl/test/options.expected.out +17 -0
- itp_interface/tools/repl/test/options.in +6 -0
- itp_interface/tools/repl/test/pickle_environment.expected.out +8 -0
- itp_interface/tools/repl/test/pickle_environment.in +7 -0
- itp_interface/tools/repl/test/pickle_environment_with_imports.expected.out +10 -0
- itp_interface/tools/repl/test/pickle_environment_with_imports.in +9 -0
- itp_interface/tools/repl/test/pickle_open.expected.out +8 -0
- itp_interface/tools/repl/test/pickle_open.in +7 -0
- itp_interface/tools/repl/test/pickle_open_2.expected.out +4 -0
- itp_interface/tools/repl/test/pickle_open_2.in +3 -0
- itp_interface/tools/repl/test/pickle_open_scoped.expected.out +18 -0
- itp_interface/tools/repl/test/pickle_open_scoped.in +8 -0
- itp_interface/tools/repl/test/pickle_open_scoped_2.expected.out +14 -0
- itp_interface/tools/repl/test/pickle_open_scoped_2.in +3 -0
- itp_interface/tools/repl/test/pickle_proof_state_1.expected.out +26 -0
- itp_interface/tools/repl/test/pickle_proof_state_1.in +15 -0
- itp_interface/tools/repl/test/pickle_proof_state_2.expected.out +4 -0
- itp_interface/tools/repl/test/pickle_proof_state_2.in +3 -0
- itp_interface/tools/repl/test/pickle_proof_state_env.expected.out +26 -0
- itp_interface/tools/repl/test/pickle_proof_state_env.in +15 -0
- itp_interface/tools/repl/test/pickle_scoped_notation.in +16 -0
- itp_interface/tools/repl/test/pickle_scoped_notation_2.in +3 -0
- itp_interface/tools/repl/test/proof_step.expected.out +18 -0
- itp_interface/tools/repl/test/proof_step.in +7 -0
- itp_interface/tools/repl/test/readme.expected.out +16 -0
- itp_interface/tools/repl/test/readme.in +5 -0
- itp_interface/tools/repl/test/sorry_hypotheses.expected.out +16 -0
- itp_interface/tools/repl/test/sorry_hypotheses.in +4 -0
- itp_interface/tools/repl/test/synthesize_placeholder.expected.out +7 -0
- itp_interface/tools/repl/test/synthesize_placeholder.in +1 -0
- itp_interface/tools/repl/test/tactic_mode_sorry.expected.out +14 -0
- itp_interface/tools/repl/test/tactic_mode_sorry.in +3 -0
- itp_interface/tools/repl/test/tactic_sorry.expected.out +12 -0
- itp_interface/tools/repl/test/tactic_sorry.in +1 -0
- itp_interface/tools/repl/test/term_sorry.expected.out +12 -0
- itp_interface/tools/repl/test/term_sorry.in +1 -0
- itp_interface/tools/repl/test/trace_simp.expected.out +41 -0
- itp_interface/tools/repl/test/trace_simp.in +15 -0
- itp_interface/tools/repl/test/unfinished_tactic_block.expected.out +11 -0
- itp_interface/tools/repl/test/unfinished_tactic_block.in +1 -0
- itp_interface/tools/repl/test/unknown_environment.expected.out +2 -0
- itp_interface/tools/repl/test/unknown_environment.in +1 -0
- itp_interface/tools/repl/test/unknown_proof_state.expected.out +14 -0
- itp_interface/tools/repl/test/unknown_proof_state.in +3 -0
- itp_interface/tools/repl/test/unknown_tactic.expected.out +14 -0
- itp_interface/tools/repl/test/unknown_tactic.in +3 -0
- itp_interface/tools/repl/test/variables.expected.out +26 -0
- itp_interface/tools/repl/test/variables.in +5 -0
- itp_interface/tools/repl/test.sh +43 -0
- itp_interface/tools/run_data_generation_transforms.py +350 -0
- itp_interface/tools/theorem_details.py +25 -0
- itp_interface/tools/training_data.py +358 -0
- itp_interface/tools/training_data_format.py +599 -0
- itp_interface-1.0.0.dist-info/METADATA +78 -0
- itp_interface-1.0.0.dist-info/RECORD +485 -0
- itp_interface-1.0.0.dist-info/WHEEL +4 -0
- itp_interface-1.0.0.dist-info/entry_points.txt +3 -0
- itp_interface-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
root_dir = f"{__file__.split('itp_interface')[0]}"
|
|
6
|
+
if root_dir not in sys.path:
|
|
7
|
+
sys.path.append(root_dir)
|
|
8
|
+
import copy
|
|
9
|
+
import os
|
|
10
|
+
import logging
|
|
11
|
+
import typing
|
|
12
|
+
import functools
|
|
13
|
+
import random
|
|
14
|
+
import re
|
|
15
|
+
from collections import OrderedDict
|
|
16
|
+
from itp_interface.lean_server.lean_context import Obligation, ProofContext
|
|
17
|
+
from itp_interface.lean_server.lean_utils import Lean3Utils
|
|
18
|
+
from itp_interface.lean_server.lean_sync_server import SyncLeanServer
|
|
19
|
+
from itp_interface.lean_server.commands import Message
|
|
20
|
+
from itp_interface.retrieval.abstraction import ReRanker
|
|
21
|
+
from itp_interface.tools.lean_parse_utils import LeanLineByLineReader
|
|
22
|
+
logger = logging.getLogger()
|
|
23
|
+
|
|
24
|
+
class Lean3Executor(object):
|
|
25
|
+
# Write now this doesn't do the best job of capturing each state changing
|
|
26
|
+
# tactic separately. It relies on the fact the tactics are usually written in an
|
|
27
|
+
# atomic way. For example, if the user writes:
|
|
28
|
+
# intros,
|
|
29
|
+
# split,
|
|
30
|
+
# cases a,...
|
|
31
|
+
# However for a simple REPL doesn't need to capture changes of every state change
|
|
32
|
+
# (which can be done by a tideous character by character comparision of the state on lean --server
|
|
33
|
+
# and the state after running the tactic). Instead, we can just assume that the user is intelligent
|
|
34
|
+
# enough to write tactics in an atomic way. This is a reasonable assumption for a simple REPL.
|
|
35
|
+
# The keywords below are taken from https://github.com/leanprover/lean-mode/blob/master/lean-syntax.el
|
|
36
|
+
keywords = {
|
|
37
|
+
"import", "prelude", "protected", "private", "noncomputable", "definition", "meta", "renaming",
|
|
38
|
+
"hiding", "exposing", "parameter", "parameters", "begin", "constant", "constants",
|
|
39
|
+
"lemma", "variable", "variables", "theorem", "example", "abbreviation",
|
|
40
|
+
"open", "export", "axiom", "axioms", "inductive", "coinductive", "with", "without",
|
|
41
|
+
"structure", "universe", "universes", "hide", "precedence", "reserve", "declare_trace", "add_key_equivalence",
|
|
42
|
+
"match", "infix", "infixl", "infixr", "notation", "postfix", "prefix", "instance",
|
|
43
|
+
"end", "this", "using", "using_well_founded", "namespace", "section",
|
|
44
|
+
"attribute", "local", "set_option", "extends", "include", "omit", "classes", "class",
|
|
45
|
+
"attributes", "raw", "replacing", "calc", "have", "show", "suffices", "by", "in", "at",
|
|
46
|
+
"do", "let", "forall", "Pi", "fun", "exists", "if", "then", "else", "assume", "from", "mutual", "def", "run_cmd",
|
|
47
|
+
# Note that there are UTF-8 characters in the following list
|
|
48
|
+
"#", "@", "!", "$", "->", "∼", "↔", "/", "==", "=", ":=", "<->", "/\\", "\\/", "∧", "∨",
|
|
49
|
+
"≠", "<", ">", "≤", "≥", "¬", "<=", ">=", "⁻¹", "⬝", "▸", "+", "*", "-", "/", "λ",
|
|
50
|
+
"→", "∃", "∀", "∘", "×", "Σ", "Π", "~", "||", "&&", "≃", "≡", "≅",
|
|
51
|
+
"ℕ", "ℤ", "ℚ", "ℝ", "ℂ", "𝔸",
|
|
52
|
+
"⬝e", "⬝i", "⬝o", "⬝op", "⬝po", "⬝h", "⬝v", "⬝hp", "⬝vp", "⬝ph", "⬝pv", "⬝r", "◾", "◾o",
|
|
53
|
+
"∘n", "∘f", "∘fi", "∘nf", "∘fn", "∘n1f", "∘1nf", "∘f1n", "∘fn1",
|
|
54
|
+
"^c", "≃c", "≅c", "×c", "×f", "×n", "+c", "+f", "+n", "ℕ₋₂"
|
|
55
|
+
}
|
|
56
|
+
theorem_regex = r"(((theorem ([\w+|\d+]*))|example)([\S|\s]*?):=[\S|\s]*?)(begin|by|calc)"
|
|
57
|
+
theorem_lemma_search_regex = r"(theorem|lemma) ([\w+|\d+]*) ([\S|\s]*?):="
|
|
58
|
+
proof_context_separator = "⊢"
|
|
59
|
+
proof_context_regex = r"((\d+) goals)*([\s|\S]*?)\n\n"
|
|
60
|
+
goal_regex = rf"([\s|\S]*?){proof_context_separator}([\s|\S]*)"
|
|
61
|
+
theorem_match = re.compile(theorem_regex, re.MULTILINE)
|
|
62
|
+
proof_context_match = re.compile(proof_context_regex, re.MULTILINE)
|
|
63
|
+
goal_match = re.compile(goal_regex, re.MULTILINE)
|
|
64
|
+
proof_context_generation_tactic = "\nend"
|
|
65
|
+
proof_state_running_message = "tactic failed, there are unsolved goals\nstate:"
|
|
66
|
+
bm25_reranker : typing.Optional[ReRanker] = None
|
|
67
|
+
def __init__(self, project_root: str = None, main_file: str = None, use_hammer: bool = False, timeout_in_sec: int = 60, use_human_readable_proof_context: bool = False, proof_step_iter: typing.Iterator[str] = None, suppress_error_log: bool = False, mathlib_root: typing.Optional[str] = None, enable_search: bool = False):
|
|
68
|
+
assert proof_step_iter is None or isinstance(proof_step_iter, typing.Iterator), \
|
|
69
|
+
"proof_step_iter must be an iterator"
|
|
70
|
+
assert main_file is not None or proof_step_iter is not None, \
|
|
71
|
+
"Either main_file or proof_step_iter must be provided"
|
|
72
|
+
assert main_file is None or proof_step_iter is None, \
|
|
73
|
+
"Only one of main_file or proof_step_iter must be provided"
|
|
74
|
+
assert main_file is None or (os.path.exists(main_file) and main_file.endswith(".lean")), \
|
|
75
|
+
"main_file must be a valid path to a '.lean' file"
|
|
76
|
+
assert project_root is None or (os.path.exists(project_root) and os.path.isdir(project_root)), \
|
|
77
|
+
"project_root must be a valid path to a directory"
|
|
78
|
+
assert not use_hammer, "Hammer is not supported for Lean3"
|
|
79
|
+
self.use_human_readable_proof_context = use_human_readable_proof_context
|
|
80
|
+
self.project_root = project_root if project_root is not None else "."
|
|
81
|
+
self.main_file = main_file if main_file is not None else f"temp{random.randint(0, 100000000)}.lean"
|
|
82
|
+
self.use_hammer = use_hammer
|
|
83
|
+
self.timeout_in_sec = min(timeout_in_sec, 120) # Maximum 120s timeout
|
|
84
|
+
self.current_stmt = None
|
|
85
|
+
self.line_num = 0
|
|
86
|
+
self.main_file_iter = proof_step_iter
|
|
87
|
+
self.suppress_error_log = suppress_error_log
|
|
88
|
+
self.lean_server : SyncLeanServer = None
|
|
89
|
+
self.execution_complete = False
|
|
90
|
+
self._max_memory_in_mib = 40000 # 40 GiB is needed for mathlib to work seemlessly
|
|
91
|
+
self._lines_executed = []
|
|
92
|
+
self.proof_context : ProofContext = None
|
|
93
|
+
self.curr_lemma_name : typing.Optional[str] = None
|
|
94
|
+
self.curr_lemma : typing.Optional[str] = None
|
|
95
|
+
self.lean_error_messages : typing.List[Message] = []
|
|
96
|
+
self._proof_running = False
|
|
97
|
+
self._file_content = ""
|
|
98
|
+
self.local_file_lemmas: typing.OrderedDict[str, str] = OrderedDict()
|
|
99
|
+
self.local_theorem_lemma_description: typing.OrderedDict[str, str] = OrderedDict()
|
|
100
|
+
self._proof_start_idx: typing.Optional[int] = None
|
|
101
|
+
self._import_end_idx: typing.Optional[int] = None
|
|
102
|
+
if mathlib_root is not None:
|
|
103
|
+
self._mathlib_root = mathlib_root
|
|
104
|
+
else:
|
|
105
|
+
self._mathlib_root = os.path.join(self.project_root, "_target", "deps", "mathlib")
|
|
106
|
+
self._mathlib_src_root = os.path.join(self._mathlib_root, "src")
|
|
107
|
+
self._enable_search = enable_search
|
|
108
|
+
if self._enable_search:
|
|
109
|
+
Lean3Executor.init_search(self._mathlib_root)
|
|
110
|
+
|
|
111
|
+
def init_search(_mathlib_root: str):
|
|
112
|
+
pass
|
|
113
|
+
|
|
114
|
+
def __enter__(self):
|
|
115
|
+
lean_cmd = f"lean --server --memory={self._max_memory_in_mib}" + (" --quiet" if self.suppress_error_log else "")
|
|
116
|
+
self.lean_server = SyncLeanServer(lean_cmd=lean_cmd, cwd=self.project_root, debug=False, debug_bytes=True)
|
|
117
|
+
self.lean_server.__enter__()
|
|
118
|
+
if self.main_file_iter is None:
|
|
119
|
+
self.main_file_iter = LeanLineByLineReader(self.main_file).instruction_step_generator()
|
|
120
|
+
return self
|
|
121
|
+
|
|
122
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
123
|
+
try:
|
|
124
|
+
self.main_file_iter.close() # Close the file handle
|
|
125
|
+
except:
|
|
126
|
+
pass
|
|
127
|
+
self.lean_server.__exit__(exc_type, exc_value, traceback)
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def token_separator_set(self):
|
|
131
|
+
return set(" ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\")
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def token_separator(self):
|
|
135
|
+
return " ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\"
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def token_separator_regex(self):
|
|
139
|
+
return "\s+|\(|\)|\[|\]|\{|\}|\.|,|;|:|\?|@|#|\$|%|\^|&|\||`|\"|\\\\" +\
|
|
140
|
+
""#"|\+|-|\*|/|=|<|>|!|~"
|
|
141
|
+
|
|
142
|
+
@staticmethod
|
|
143
|
+
def get_token_separator_set():
|
|
144
|
+
return set(" ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\")
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
def get_token_separators():
|
|
148
|
+
return " ()[]{}.,;:+-*/=<>!~?@#$%^&|`\"\\"
|
|
149
|
+
|
|
150
|
+
@staticmethod
|
|
151
|
+
def get_token_separator_regex():
|
|
152
|
+
return "\s+|\(|\)|\[|\]|\{|\}|\.|,|;|:|\?|@|#|\$|%|\^|&|\||`|\"|\\\\" +\
|
|
153
|
+
""#"|\+|-|\*|/|=|<|>|!|~"
|
|
154
|
+
|
|
155
|
+
def is_in_proof_mode(self):
|
|
156
|
+
return True if self.proof_context else False
|
|
157
|
+
|
|
158
|
+
def needs_qed(self):
|
|
159
|
+
return self.proof_context is not None and len(self.proof_context.all_goals) == 0
|
|
160
|
+
|
|
161
|
+
def needs_cut_close(self):
|
|
162
|
+
return self.proof_context is not None and len(self.proof_context.fg_goals) == 0 and len(self.proof_context.all_goals) > 0
|
|
163
|
+
|
|
164
|
+
def run_next(self) -> bool:
|
|
165
|
+
try:
|
|
166
|
+
stmt = next(self.main_file_iter)
|
|
167
|
+
except StopIteration:
|
|
168
|
+
self.execution_complete = True
|
|
169
|
+
return False
|
|
170
|
+
self.current_stmt = stmt
|
|
171
|
+
self.line_num += 1
|
|
172
|
+
try:
|
|
173
|
+
idx = len(self._lines_executed)
|
|
174
|
+
self._run_stmt_on_lean_server(idx, stmt)
|
|
175
|
+
except:
|
|
176
|
+
if not self.suppress_error_log:
|
|
177
|
+
logger.error(f"Got an exception while running '{stmt}' on lean. File name: {self.main_file}")
|
|
178
|
+
logger.exception(f"Exception Log")
|
|
179
|
+
raise
|
|
180
|
+
self._lines_executed.append(stmt)
|
|
181
|
+
return True
|
|
182
|
+
|
|
183
|
+
def run_next_without_exec(self) -> bool:
|
|
184
|
+
try:
|
|
185
|
+
stmt = next(self.main_file_iter)
|
|
186
|
+
except StopIteration:
|
|
187
|
+
self.execution_complete = True
|
|
188
|
+
return False
|
|
189
|
+
self.current_stmt = stmt
|
|
190
|
+
self.line_num += 1
|
|
191
|
+
try:
|
|
192
|
+
self._set_content_to_run(stmt)
|
|
193
|
+
except:
|
|
194
|
+
if not self.suppress_error_log:
|
|
195
|
+
logger.error(f"Got an exception while running '{stmt}' on lean. File name: {self.main_file}")
|
|
196
|
+
logger.exception(f"Exception Log")
|
|
197
|
+
raise
|
|
198
|
+
self._lines_executed.append(stmt)
|
|
199
|
+
return True
|
|
200
|
+
|
|
201
|
+
def run_all_without_exec(self) -> bool:
|
|
202
|
+
next_cmd_ran = self.run_next_without_exec()
|
|
203
|
+
while next_cmd_ran:
|
|
204
|
+
next_cmd_ran = self.run_next_without_exec()
|
|
205
|
+
|
|
206
|
+
def find_all_theorems_names(self) -> typing.List[typing.Tuple[str, str]]:
|
|
207
|
+
theorem_names = []
|
|
208
|
+
matches = Lean3Executor.theorem_match.findall(self._file_content)
|
|
209
|
+
for _, _, _, thm_name, _, _ in matches:
|
|
210
|
+
theorem_names.append(thm_name)
|
|
211
|
+
return theorem_names
|
|
212
|
+
|
|
213
|
+
def get_tokens_in_given_stmt(self, stmt: str, ignore_first_token: bool = False) -> typing.Generator[str, None, None]:
|
|
214
|
+
idx = -1
|
|
215
|
+
for tok in re.split(self.token_separator_regex, stmt):
|
|
216
|
+
idx += 1
|
|
217
|
+
# skip the first token as it is usually a keyword
|
|
218
|
+
if idx == 0 and ignore_first_token:
|
|
219
|
+
continue
|
|
220
|
+
tok1 = tok.strip()
|
|
221
|
+
if len(tok1) > 0:
|
|
222
|
+
yield tok1
|
|
223
|
+
|
|
224
|
+
def tokenize(stmt: str) -> typing.Generator[str, None, None]:
|
|
225
|
+
for tok in re.split(Lean3Executor.get_token_separator_regex(), stmt):
|
|
226
|
+
tok1 = tok.strip()
|
|
227
|
+
if len(tok1) > 0:
|
|
228
|
+
yield tok1
|
|
229
|
+
|
|
230
|
+
# Make this chacheable
|
|
231
|
+
@functools.lru_cache(maxsize=10000)
|
|
232
|
+
def search_type_matching_defns(self, name: str) -> typing.List[typing.Tuple[str, str]]:
|
|
233
|
+
if name in Lean3Executor.keywords:
|
|
234
|
+
return []
|
|
235
|
+
raise NotImplementedError("search_type_matching_defns is not implemented")
|
|
236
|
+
|
|
237
|
+
def get_all_type_matching_defns(self, name: str) -> typing.Generator[typing.Tuple[str, str], None, None]:
|
|
238
|
+
raise NotImplementedError("get_all_type_matching_defns is not implemented")
|
|
239
|
+
|
|
240
|
+
def search_exact(self, name: str) -> typing.List[typing.Tuple[str, str]]:
|
|
241
|
+
raise NotImplementedError("search_exact is not implemented")
|
|
242
|
+
|
|
243
|
+
def search_defn(self, name: str, match_until: typing.Tuple[str], max_search_res: typing.Optional[int] = None) -> typing.List[typing.Tuple[str, str, bool]]:
|
|
244
|
+
raise NotImplementedError("search_defn is not implemented")
|
|
245
|
+
|
|
246
|
+
def run_without_executing(self, stmt: str):
|
|
247
|
+
while True:
|
|
248
|
+
try:
|
|
249
|
+
stmt = next(self.main_file_iter)
|
|
250
|
+
except StopIteration:
|
|
251
|
+
return
|
|
252
|
+
idx = len(self._lines_executed)
|
|
253
|
+
self._set_content_to_run(stmt)
|
|
254
|
+
if stmt.startswith("theorem") and self._import_end_idx is None:
|
|
255
|
+
self._import_end_idx = idx
|
|
256
|
+
self.current_stmt = stmt
|
|
257
|
+
self.line_num += 1
|
|
258
|
+
self._set_content_to_run(stmt)
|
|
259
|
+
self._lines_executed.append(stmt)
|
|
260
|
+
|
|
261
|
+
def run_lemma_without_executing(self):
|
|
262
|
+
while True:
|
|
263
|
+
try:
|
|
264
|
+
stmt = next(self.main_file_iter)
|
|
265
|
+
self.current_stmt = stmt
|
|
266
|
+
self.line_num += 1
|
|
267
|
+
if "Qed." in stmt or "Defined." in stmt or "Admitted." in stmt:
|
|
268
|
+
return True
|
|
269
|
+
except StopIteration:
|
|
270
|
+
return False
|
|
271
|
+
|
|
272
|
+
def rewind_proof_steps(self) -> str:
|
|
273
|
+
raise NotImplementedError("rewind_proof_steps is not implemented")
|
|
274
|
+
|
|
275
|
+
def run_till_next_lemma(self) -> typing.Tuple[bool, typing.Optional[str]]:
|
|
276
|
+
# Run the coq file until the next lemma is found
|
|
277
|
+
next_stmt = None
|
|
278
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
279
|
+
if in_proof_mode or self.execution_complete:
|
|
280
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
281
|
+
return False, next_stmt
|
|
282
|
+
prev_stmt = self.current_stmt
|
|
283
|
+
ran_last_cmd = self.run_next()
|
|
284
|
+
next_stmt = self.current_stmt
|
|
285
|
+
if not ran_last_cmd:
|
|
286
|
+
return False, None
|
|
287
|
+
assigned = False
|
|
288
|
+
while ran_last_cmd and not in_proof_mode:
|
|
289
|
+
if not assigned:
|
|
290
|
+
prev_stmt = next_stmt
|
|
291
|
+
ran_last_cmd = self.run_next()
|
|
292
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
293
|
+
if not assigned:
|
|
294
|
+
next_stmt = self.current_stmt
|
|
295
|
+
if in_proof_mode:
|
|
296
|
+
assigned = True
|
|
297
|
+
lemma_name = next_stmt if next_stmt.startswith("Theorem") or next_stmt.startswith("Lemma") else prev_stmt
|
|
298
|
+
return in_proof_mode, lemma_name
|
|
299
|
+
|
|
300
|
+
def run_till_next_lemma_return_exec_stmt(self) -> typing.Generator[str, None, None]:
|
|
301
|
+
# Run the coq file until the next lemma is found
|
|
302
|
+
next_stmt = None
|
|
303
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
304
|
+
if in_proof_mode or self.execution_complete:
|
|
305
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
306
|
+
yield from []
|
|
307
|
+
else:
|
|
308
|
+
ran_last_cmd = self.run_next()
|
|
309
|
+
next_stmt = self.current_stmt
|
|
310
|
+
if not ran_last_cmd:
|
|
311
|
+
yield from []
|
|
312
|
+
else:
|
|
313
|
+
yield next_stmt
|
|
314
|
+
while ran_last_cmd and not in_proof_mode:
|
|
315
|
+
ran_last_cmd = self.run_next()
|
|
316
|
+
next_stmt = self.current_stmt
|
|
317
|
+
if ran_last_cmd:
|
|
318
|
+
yield next_stmt
|
|
319
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
320
|
+
|
|
321
|
+
def run_to_finish_lemma_return_exec(self) -> typing.Generator[str, None, None]:
|
|
322
|
+
# Run the coq file until the next lemma is found
|
|
323
|
+
next_stmt = None
|
|
324
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
325
|
+
if not in_proof_mode or self.execution_complete:
|
|
326
|
+
# If we are already in proof mode, then we have already found a lemma
|
|
327
|
+
yield from []
|
|
328
|
+
else:
|
|
329
|
+
ran_last_cmd = self.run_next()
|
|
330
|
+
next_stmt = self.current_stmt
|
|
331
|
+
if not ran_last_cmd:
|
|
332
|
+
yield from []
|
|
333
|
+
else:
|
|
334
|
+
yield next_stmt
|
|
335
|
+
while ran_last_cmd and in_proof_mode:
|
|
336
|
+
ran_last_cmd = self.run_next()
|
|
337
|
+
next_stmt = self.current_stmt
|
|
338
|
+
if ran_last_cmd:
|
|
339
|
+
yield next_stmt
|
|
340
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
341
|
+
|
|
342
|
+
def run_to_finish_lemma(self) -> bool:
|
|
343
|
+
# Run the coq file and finish the current lemma
|
|
344
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
345
|
+
if not in_proof_mode or self.execution_complete:
|
|
346
|
+
# If we are not in proof mode, then we are not finishing a lemma
|
|
347
|
+
return False
|
|
348
|
+
ran_last_cmd = self.run_next()
|
|
349
|
+
if not ran_last_cmd:
|
|
350
|
+
return False
|
|
351
|
+
while ran_last_cmd and in_proof_mode:
|
|
352
|
+
ran_last_cmd = self.run_next()
|
|
353
|
+
in_proof_mode = self.is_in_proof_mode()
|
|
354
|
+
return not in_proof_mode
|
|
355
|
+
|
|
356
|
+
def run_till_line_num(self, line_num: int):
|
|
357
|
+
assert line_num >= self.line_num
|
|
358
|
+
ran_last_cmd = True
|
|
359
|
+
while ran_last_cmd and self.line_num < line_num:
|
|
360
|
+
ran_last_cmd = self.run_next()
|
|
361
|
+
return self.line_num
|
|
362
|
+
|
|
363
|
+
def run_to_finish(self):
|
|
364
|
+
ran_last_cmd = True
|
|
365
|
+
while ran_last_cmd:
|
|
366
|
+
ran_last_cmd = self.run_next()
|
|
367
|
+
|
|
368
|
+
def get_lemma_name_if_running(self) -> typing.Optional[str]:
|
|
369
|
+
if not self.is_in_proof_mode():
|
|
370
|
+
return None
|
|
371
|
+
else:
|
|
372
|
+
try:
|
|
373
|
+
return self.curr_lemma_name
|
|
374
|
+
except:
|
|
375
|
+
return None
|
|
376
|
+
|
|
377
|
+
def get_lemma_stmt_if_running(self) -> typing.Optional[str]:
|
|
378
|
+
if not self.is_in_proof_mode():
|
|
379
|
+
return None
|
|
380
|
+
else:
|
|
381
|
+
try:
|
|
382
|
+
return self.local_theorem_lemma_description[self.curr_lemma_name]
|
|
383
|
+
except:
|
|
384
|
+
return None
|
|
385
|
+
|
|
386
|
+
def _set_content_to_run(self, stmt: str) -> str:
|
|
387
|
+
# Now add this new line to the context
|
|
388
|
+
if len(self._file_content) > 0:
|
|
389
|
+
# First create a context of all the lines executed so far
|
|
390
|
+
self._file_content += "\n" + stmt.strip()
|
|
391
|
+
else:
|
|
392
|
+
self._file_content = stmt.strip()
|
|
393
|
+
|
|
394
|
+
def _check_matching_end(self, file_content: str) -> bool:
|
|
395
|
+
# The file_content must end with a matching end
|
|
396
|
+
# TODO: This is a hack, since we are not tokenizing if there are variables which have suffix or prefix
|
|
397
|
+
# of begin or end, then this won't be correct. But this is a rare case, so we can ignore it for now
|
|
398
|
+
if not file_content.endswith("end"):
|
|
399
|
+
return False # no need to check if we are no where near a closing of a proof
|
|
400
|
+
return file_content.count("begin") == file_content.count("end")
|
|
401
|
+
|
|
402
|
+
def _run_stmt_on_lean_server(self, idx : int, stmt: str):
|
|
403
|
+
self._set_content_to_run(stmt)
|
|
404
|
+
content = self._file_content
|
|
405
|
+
if (stmt.startswith("theorem") or stmt.startswith("lemma")) and self._import_end_idx is None:
|
|
406
|
+
self._import_end_idx = idx - 1
|
|
407
|
+
if not self._proof_running:
|
|
408
|
+
last_thm_details = Lean3Executor.theorem_match.findall(content)
|
|
409
|
+
else:
|
|
410
|
+
last_thm_details = []
|
|
411
|
+
if last_thm_details:
|
|
412
|
+
# We might have found a new theorem
|
|
413
|
+
full_thm_stmt, _, _, thm_name, thm_value, _ = last_thm_details[-1]
|
|
414
|
+
full_thm_stmt = full_thm_stmt.strip()
|
|
415
|
+
thm_name = thm_name.strip()
|
|
416
|
+
thm_value = thm_value.strip()
|
|
417
|
+
thm_value = thm_value.lstrip(":")
|
|
418
|
+
if thm_name in self.local_file_lemmas:
|
|
419
|
+
# We have already discovered this theorem
|
|
420
|
+
# The state got added probably because of the end of a proof
|
|
421
|
+
# So we need to remove the state
|
|
422
|
+
self.proof_context = None
|
|
423
|
+
self._proof_running = False
|
|
424
|
+
self.curr_lemma_name, self.curr_lemma = None, None
|
|
425
|
+
self._proof_start_idx = None
|
|
426
|
+
else:
|
|
427
|
+
self.local_theorem_lemma_description[thm_name] = full_thm_stmt
|
|
428
|
+
self.local_file_lemmas[thm_name] = thm_value
|
|
429
|
+
self._proof_running = True
|
|
430
|
+
self.curr_lemma_name, self.curr_lemma = thm_name, thm_value
|
|
431
|
+
self._proof_start_idx = idx
|
|
432
|
+
if self._proof_running:
|
|
433
|
+
content = content.rstrip()
|
|
434
|
+
assert self._proof_start_idx is not None
|
|
435
|
+
matching_end = self._check_matching_end(content)
|
|
436
|
+
if not matching_end:
|
|
437
|
+
content += Lean3Executor.proof_context_generation_tactic
|
|
438
|
+
col = len(stmt)
|
|
439
|
+
idx += 1
|
|
440
|
+
self.lean_server.full_sync(self.main_file, content)
|
|
441
|
+
next_proof_context_str = self.lean_server.state(self.main_file, idx, col)
|
|
442
|
+
prev_proof_context = self.proof_context
|
|
443
|
+
self.proof_context = self._parse_proof_context(next_proof_context_str)
|
|
444
|
+
relevant_messages = []
|
|
445
|
+
for msg in self.lean_server.messages:
|
|
446
|
+
if msg.text.startswith(Lean3Executor.proof_state_running_message):
|
|
447
|
+
# This is a case when there more subgoals to be solved
|
|
448
|
+
new_proof_context = self._parse_proof_context(msg.text[len(Lean3Executor.proof_state_running_message):])
|
|
449
|
+
if self.proof_context == ProofContext.empty():
|
|
450
|
+
# But this is not focussed goal
|
|
451
|
+
self.proof_context = ProofContext(
|
|
452
|
+
fg_goals=[],
|
|
453
|
+
bg_goals=new_proof_context.fg_goals,
|
|
454
|
+
shelved_goals=new_proof_context.shelved_goals,
|
|
455
|
+
given_up_goals=new_proof_context.given_up_goals
|
|
456
|
+
)
|
|
457
|
+
else:
|
|
458
|
+
self.proof_context = new_proof_context
|
|
459
|
+
else:
|
|
460
|
+
relevant_messages.append(msg)
|
|
461
|
+
|
|
462
|
+
if len(relevant_messages) > 0:
|
|
463
|
+
# There might be some errors on the current line
|
|
464
|
+
self.lean_error_messages = copy.deepcopy(relevant_messages)
|
|
465
|
+
else:
|
|
466
|
+
self.lean_error_messages = []
|
|
467
|
+
# This can simply happen because the we are not pointing at the end of an atomic unit of tactic execution
|
|
468
|
+
if self.proof_context is None and prev_proof_context is not None:
|
|
469
|
+
# Only focus on messages related to the current lemma
|
|
470
|
+
if len(self.lean_server.messages) > 0 and not matching_end:
|
|
471
|
+
# We might be in the middle of an atomic unit
|
|
472
|
+
# So we don't need to give up proof context
|
|
473
|
+
self.proof_context = prev_proof_context
|
|
474
|
+
if prev_proof_context is not None and self.proof_context is None:
|
|
475
|
+
# We have finished a proof
|
|
476
|
+
self._proof_running = False
|
|
477
|
+
self.curr_lemma_name, self.curr_lemma = None, None
|
|
478
|
+
self._proof_start_idx = None
|
|
479
|
+
pass
|
|
480
|
+
|
|
481
|
+
def _skip_to_theorem(self, theorem: str):
|
|
482
|
+
found_thm = False
|
|
483
|
+
while not found_thm:
|
|
484
|
+
try:
|
|
485
|
+
stmt = next(self.main_file_iter)
|
|
486
|
+
except StopIteration:
|
|
487
|
+
if not self.suppress_error_log:
|
|
488
|
+
logger.error(f"Could not find theorem '{theorem}' in the file '{self.main_file}'")
|
|
489
|
+
raise Exception(f"Could not find theorem '{theorem}' in the file '{self.main_file}'")
|
|
490
|
+
return
|
|
491
|
+
self.current_stmt = stmt
|
|
492
|
+
self.line_num += 1
|
|
493
|
+
idx = len(self._lines_executed)
|
|
494
|
+
if stmt.startswith("theorem") and self._import_end_idx is None:
|
|
495
|
+
self._import_end_idx = idx - 1
|
|
496
|
+
file_content = self._file_content
|
|
497
|
+
# Now add this new line to the context
|
|
498
|
+
if len(file_content) > 0:
|
|
499
|
+
# First create a context of all the lines executed so far
|
|
500
|
+
file_content += "\n" + stmt.strip()
|
|
501
|
+
else:
|
|
502
|
+
file_content = stmt.strip()
|
|
503
|
+
last_thm_details = Lean3Executor.theorem_match.findall(file_content)
|
|
504
|
+
if last_thm_details:
|
|
505
|
+
# We might have found a new theorem
|
|
506
|
+
full_thm_stmt, _, _, thm_name, thm_value, _ = last_thm_details[-1]
|
|
507
|
+
full_thm_stmt = full_thm_stmt.strip()
|
|
508
|
+
thm_name = thm_name.strip()
|
|
509
|
+
thm_value = thm_value.strip()
|
|
510
|
+
thm_value = thm_value.lstrip(":")
|
|
511
|
+
if thm_name not in self.local_file_lemmas:
|
|
512
|
+
if theorem != thm_name:
|
|
513
|
+
self.local_theorem_lemma_description[thm_name] = full_thm_stmt
|
|
514
|
+
self.local_file_lemmas[thm_name] = thm_value
|
|
515
|
+
else:
|
|
516
|
+
found_thm = True
|
|
517
|
+
if found_thm:
|
|
518
|
+
# Capture the proof context
|
|
519
|
+
assert self._import_end_idx is not None
|
|
520
|
+
# Remove all the theorems before the current theorem
|
|
521
|
+
self._lines_executed = self._lines_executed[:self._import_end_idx + 1]
|
|
522
|
+
full_thm_stmts = full_thm_stmt.split("\n")
|
|
523
|
+
self._lines_executed.extend(full_thm_stmts)
|
|
524
|
+
# Reset the file content to completely ignore the previous theorems
|
|
525
|
+
self._file_content = '\n'.join(self._lines_executed)
|
|
526
|
+
# Now change the idx
|
|
527
|
+
idx = len(self._lines_executed)
|
|
528
|
+
self.line_num = idx
|
|
529
|
+
# Remove all the theorems discovered before the current theorem
|
|
530
|
+
self.local_file_lemmas.clear()
|
|
531
|
+
self.local_theorem_lemma_description.clear()
|
|
532
|
+
self._run_stmt_on_lean_server(idx, stmt)
|
|
533
|
+
self._lines_executed.append(stmt)
|
|
534
|
+
self.line_num += 1 # This needs to be reset because the begin was ignored
|
|
535
|
+
else:
|
|
536
|
+
# Now run the lines till the theorem is found
|
|
537
|
+
self._set_content_to_run(stmt)
|
|
538
|
+
self._lines_executed.append(stmt)
|
|
539
|
+
pass
|
|
540
|
+
|
|
541
|
+
def get_all_theorems(self) -> typing.List[str]:
|
|
542
|
+
self.run_without_executing()
|
|
543
|
+
|
|
544
|
+
def _parse_proof_context(self, proof_context_str: str) -> ProofContext:
|
|
545
|
+
if self.use_human_readable_proof_context:
|
|
546
|
+
return Lean3Utils.parse_proof_context_human_readable(proof_context_str)
|
|
547
|
+
# return self._parse_proof_context_human_readable(proof_context_str)
|
|
548
|
+
else:
|
|
549
|
+
raise NotImplementedError("Parsing of non-human readable proof context is not implemented")
|
|
550
|
+
|
|
551
|
+
def _parse_proof_context_human_readable(self, proof_context_str: str) -> ProofContext:
|
|
552
|
+
if len(proof_context_str) == 0 and Lean3Executor.proof_context_separator not in proof_context_str:
|
|
553
|
+
return None
|
|
554
|
+
if proof_context_str == "no goals":
|
|
555
|
+
return ProofContext.empty()
|
|
556
|
+
proof_context_str = proof_context_str.strip()
|
|
557
|
+
proof_context_str += "\n\n"
|
|
558
|
+
all_matches = re.findall(Lean3Executor.proof_context_regex, proof_context_str, re.MULTILINE)
|
|
559
|
+
goal_strs = []
|
|
560
|
+
total_goal_cnt = 0
|
|
561
|
+
for _, goal_cnt, goal_str in all_matches:
|
|
562
|
+
if len(goal_cnt) > 0:
|
|
563
|
+
total_goal_cnt = int(goal_cnt)
|
|
564
|
+
goal_str = goal_str.strip()
|
|
565
|
+
goal_strs.append(goal_str)
|
|
566
|
+
if total_goal_cnt > 0:
|
|
567
|
+
assert len(goal_strs) == total_goal_cnt, f"Total goal count {total_goal_cnt} does not match the number of goals {len(goal_strs)}"
|
|
568
|
+
else:
|
|
569
|
+
assert len(goal_strs) == 1, f"Total goal count {total_goal_cnt} does not match the number of goals {len(goal_strs)}"
|
|
570
|
+
total_goal_cnt = 1
|
|
571
|
+
assert len(goal_strs) == total_goal_cnt, f"Total goal count {total_goal_cnt} does not match the number of goals {len(goal_strs)}"
|
|
572
|
+
goals = []
|
|
573
|
+
for goal_str in goal_strs:
|
|
574
|
+
goal = self._parse_goal(goal_str)
|
|
575
|
+
goals.append(goal)
|
|
576
|
+
return ProofContext(goals, [], [], [])
|
|
577
|
+
|
|
578
|
+
def _parse_goal(self, goal_str: str):
|
|
579
|
+
goal_str = goal_str.strip()
|
|
580
|
+
goal = ""
|
|
581
|
+
hyps_goals = re.findall(Lean3Executor.goal_regex, goal_str, re.MULTILINE)
|
|
582
|
+
assert len(hyps_goals) == 1, f"Found more than one goal in the goal string: {goal_str}"
|
|
583
|
+
hypotheses_str, goal = hyps_goals[0]
|
|
584
|
+
hypotheses_str = hypotheses_str.strip()
|
|
585
|
+
goal = goal.strip()
|
|
586
|
+
hypotheses = [hyp.rstrip(',') for hyp in hypotheses_str.split("\n")]
|
|
587
|
+
goal = Obligation(hypotheses, goal)
|
|
588
|
+
return goal
|
|
589
|
+
|
|
590
|
+
class LeanStdInOutExecutor:
|
|
591
|
+
def __init__(self):
|
|
592
|
+
self.lean_stdin_reader = LeanLineByLineReader()
|
|
593
|
+
self.lean_exec : Lean3Executor = Lean3Executor(
|
|
594
|
+
use_human_readable_proof_context=True,
|
|
595
|
+
proof_step_iter=self.lean_stdin_reader.instruction_step_generator())
|
|
596
|
+
|
|
597
|
+
def __enter__(self):
|
|
598
|
+
self.lean_exec.__enter__()
|
|
599
|
+
return self
|
|
600
|
+
|
|
601
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
602
|
+
self.lean_exec.__exit__(exc_type, exc_value, traceback)
|
|
603
|
+
|
|
604
|
+
def run_in_loop(self):
|
|
605
|
+
print("In> ", end="")
|
|
606
|
+
while True:
|
|
607
|
+
try:
|
|
608
|
+
cmd_ran = self.lean_exec.run_next()
|
|
609
|
+
if not cmd_ran:
|
|
610
|
+
break
|
|
611
|
+
print(f"Lean> {self.lean_exec.current_stmt}")
|
|
612
|
+
print(f"{self.lean_exec.lean_server.proof_context}")
|
|
613
|
+
print("In> ", end="")
|
|
614
|
+
except:
|
|
615
|
+
pass
|
|
616
|
+
pass
|
|
617
|
+
|
|
618
|
+
class LeanCustomFileExec:
|
|
619
|
+
def __init__(self, file_path: str, project_root: str = '.'):
|
|
620
|
+
self.lean_stdin_reader = LeanLineByLineReader(file_path)
|
|
621
|
+
self.lean_exec : Lean3Executor = Lean3Executor(
|
|
622
|
+
project_root=project_root,
|
|
623
|
+
use_human_readable_proof_context=True,
|
|
624
|
+
proof_step_iter=self.lean_stdin_reader.instruction_step_generator())
|
|
625
|
+
|
|
626
|
+
def __enter__(self):
|
|
627
|
+
self.lean_exec.__enter__()
|
|
628
|
+
return self
|
|
629
|
+
|
|
630
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
|
631
|
+
self.lean_exec.__exit__(exc_type, exc_value, traceback)
|
|
632
|
+
|
|
633
|
+
def run_in_loop(self, opt: str = None):
|
|
634
|
+
print("In> Press 'Enter' for running next line, \n" +
|
|
635
|
+
"'c' + 'Enter' to cancel the last command and 're-run', \n" +
|
|
636
|
+
"'e' + 'Enter' to run over all lines one-by-one. ", end="")
|
|
637
|
+
last_stmt = None
|
|
638
|
+
run_all = False
|
|
639
|
+
while True:
|
|
640
|
+
try:
|
|
641
|
+
if not run_all:
|
|
642
|
+
if opt is None or opt != "e":
|
|
643
|
+
opt = input()
|
|
644
|
+
if opt == "e":
|
|
645
|
+
run_all = True
|
|
646
|
+
print("Running all lines one-by-one")
|
|
647
|
+
elif opt == "c" and last_stmt is not None:
|
|
648
|
+
if self.lean_exec.is_in_proof_mode():
|
|
649
|
+
print(f"Goals before cancelling")
|
|
650
|
+
print(self.lean_exec.proof_context.all_goals)
|
|
651
|
+
else:
|
|
652
|
+
print("No goals before cancelling")
|
|
653
|
+
self.lean_exec.lean_server.cancel_last()
|
|
654
|
+
if self.lean_exec.is_in_proof_mode():
|
|
655
|
+
print(f"Goals after cancelling")
|
|
656
|
+
print(self.lean_exec.proof_context.all_goals)
|
|
657
|
+
else:
|
|
658
|
+
print("No goals after cancelling")
|
|
659
|
+
print(f"Canceled last statement: {last_stmt}")
|
|
660
|
+
print(f"Re-running: {last_stmt}")
|
|
661
|
+
self.lean_exec.lean_server.run_stmt(last_stmt)
|
|
662
|
+
print(f"Lean> Ran {last_stmt} again")
|
|
663
|
+
continue
|
|
664
|
+
cmd_ran = self.lean_exec.run_next()
|
|
665
|
+
last_stmt = self.lean_exec.current_stmt
|
|
666
|
+
print(f"Lean> {self.lean_exec.current_stmt}")
|
|
667
|
+
if self.lean_exec.is_in_proof_mode():
|
|
668
|
+
print(f"Goals after running {last_stmt}")
|
|
669
|
+
print(self.lean_exec.proof_context.all_goals)
|
|
670
|
+
if self.lean_exec.lean_error_messages:
|
|
671
|
+
for msg_idx, lean_msgs in enumerate(self.lean_exec.lean_error_messages):
|
|
672
|
+
print(f"Lean [Message {msg_idx}]> {lean_msgs.text}")
|
|
673
|
+
if not cmd_ran:
|
|
674
|
+
break
|
|
675
|
+
# print(f"{self.lean_exec.proof_context}")
|
|
676
|
+
print("In> ", end="")
|
|
677
|
+
except:
|
|
678
|
+
pass
|
|
679
|
+
pass
|
|
680
|
+
|
|
681
|
+
if __name__ == "__main__":
|
|
682
|
+
logging.basicConfig(filename='lean_executor.log', filemode='w', level=logging.INFO)
|
|
683
|
+
os.chdir(root_dir)
|
|
684
|
+
project = "data/benchmarks/miniF2F"
|
|
685
|
+
file = "data/benchmarks/miniF2F/lean/src/temp.lean"
|
|
686
|
+
with LeanCustomFileExec(file, project) as lean_exec:
|
|
687
|
+
lean_exec.run_in_loop()
|