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,881 @@
|
|
|
1
|
+
package pisa.server
|
|
2
|
+
|
|
3
|
+
import util.control.Breaks
|
|
4
|
+
import scala.collection.mutable.ListBuffer
|
|
5
|
+
import scala.concurrent.{
|
|
6
|
+
Await,
|
|
7
|
+
ExecutionContext,
|
|
8
|
+
Future,
|
|
9
|
+
TimeoutException,
|
|
10
|
+
blocking
|
|
11
|
+
}
|
|
12
|
+
import scala.concurrent.duration.Duration
|
|
13
|
+
import scala.util.{Success, Failure}
|
|
14
|
+
import sys.process._
|
|
15
|
+
import _root_.java.nio.file.{Files, Path}
|
|
16
|
+
import _root_.java.io.File
|
|
17
|
+
|
|
18
|
+
import de.unruh.isabelle.control.Isabelle
|
|
19
|
+
import de.unruh.isabelle.mlvalue.{
|
|
20
|
+
AdHocConverter,
|
|
21
|
+
MLFunction,
|
|
22
|
+
MLFunction0,
|
|
23
|
+
MLFunction2,
|
|
24
|
+
MLFunction3,
|
|
25
|
+
MLFunction4,
|
|
26
|
+
MLValue,
|
|
27
|
+
MLValueWrapper
|
|
28
|
+
}
|
|
29
|
+
import de.unruh.isabelle.mlvalue.MLValue.{
|
|
30
|
+
compileFunction,
|
|
31
|
+
compileFunction0,
|
|
32
|
+
compileValue
|
|
33
|
+
}
|
|
34
|
+
import de.unruh.isabelle.pure.{
|
|
35
|
+
Context,
|
|
36
|
+
Position,
|
|
37
|
+
Theory,
|
|
38
|
+
TheoryHeader,
|
|
39
|
+
ToplevelState
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
import pisa.utils.TheoryManager
|
|
43
|
+
import pisa.utils.TheoryManager.{Ops, Source, Text}
|
|
44
|
+
// Implicits
|
|
45
|
+
import de.unruh.isabelle.mlvalue.Implicits._
|
|
46
|
+
import de.unruh.isabelle.pure.Implicits._
|
|
47
|
+
import de.unruh.isabelle.control.IsabelleMLException
|
|
48
|
+
|
|
49
|
+
object Transition extends AdHocConverter("Toplevel.transition")
|
|
50
|
+
object ProofState extends AdHocConverter("Proof.state")
|
|
51
|
+
object RuntimeError extends AdHocConverter("Runtime.error")
|
|
52
|
+
object Pretty extends AdHocConverter("Pretty.T")
|
|
53
|
+
object ProofContext extends AdHocConverter("Proof_Context.T")
|
|
54
|
+
|
|
55
|
+
class PisaOS(
|
|
56
|
+
var path_to_isa_bin: String,
|
|
57
|
+
var path_to_file: String,
|
|
58
|
+
var working_directory: String,
|
|
59
|
+
var use_Sledgehammer: Boolean = false,
|
|
60
|
+
var debug: Boolean = false
|
|
61
|
+
) {
|
|
62
|
+
if (debug) println("Checkpoint 1")
|
|
63
|
+
val currentTheoryName: String =
|
|
64
|
+
path_to_file.split("/").last.replace(".thy", "")
|
|
65
|
+
val currentProjectName: String = {
|
|
66
|
+
if (path_to_file.contains("afp")) {
|
|
67
|
+
working_directory
|
|
68
|
+
.slice(working_directory.indexOf("thys/") + 5, working_directory.length)
|
|
69
|
+
.split("/")
|
|
70
|
+
.head
|
|
71
|
+
} else if (
|
|
72
|
+
path_to_file.contains("Isabelle") && path_to_file.contains("/src/")
|
|
73
|
+
) {
|
|
74
|
+
// The theory file could be /Applications/Isabelle2021.app/Isabelle/src/HOL/Analysis/ex
|
|
75
|
+
// The correct project name for it is HOL-Analysis-ex
|
|
76
|
+
val relative_working_directory =
|
|
77
|
+
working_directory
|
|
78
|
+
.slice(
|
|
79
|
+
working_directory.indexOf("/src/") + 5,
|
|
80
|
+
working_directory.length
|
|
81
|
+
)
|
|
82
|
+
.split("/")
|
|
83
|
+
relative_working_directory.mkString("-")
|
|
84
|
+
} else if (path_to_file.contains("miniF2F")) {
|
|
85
|
+
// working_directory.split("/").last
|
|
86
|
+
"HOL"
|
|
87
|
+
} else {
|
|
88
|
+
"This is not supported at the moment"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (debug) println("Checkpoint 2")
|
|
92
|
+
// Figure out the session roots information and import the correct libraries
|
|
93
|
+
val sessionRoots: Seq[Path] = {
|
|
94
|
+
if (path_to_file.contains("afp")) {
|
|
95
|
+
Seq(
|
|
96
|
+
Path.of(
|
|
97
|
+
working_directory.slice(-1, working_directory.indexOf("thys/") + 4)
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
} else if (
|
|
101
|
+
path_to_file.contains("Isabelle") && path_to_file.contains("/src/")
|
|
102
|
+
) {
|
|
103
|
+
val src_index: Int = working_directory.indexOf("/src/") + 5
|
|
104
|
+
val session_root_path_string: String =
|
|
105
|
+
working_directory.slice(0, src_index) +
|
|
106
|
+
working_directory
|
|
107
|
+
.slice(src_index, working_directory.length)
|
|
108
|
+
.split("/")
|
|
109
|
+
.head
|
|
110
|
+
Seq(Path.of(session_root_path_string))
|
|
111
|
+
} else if (path_to_file.contains("miniF2F")) {
|
|
112
|
+
Seq()
|
|
113
|
+
} else {
|
|
114
|
+
Seq(Path.of("This is not supported at the moment"))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (debug) println("Checkpoint 3")
|
|
118
|
+
// Prepare setup config and the implicit Isabelle context
|
|
119
|
+
val setup: Isabelle.Setup = Isabelle.Setup(
|
|
120
|
+
isabelleHome = Path.of(path_to_isa_bin),
|
|
121
|
+
sessionRoots = sessionRoots,
|
|
122
|
+
userDir = None,
|
|
123
|
+
logic = currentProjectName,
|
|
124
|
+
workingDirectory = Path.of(working_directory),
|
|
125
|
+
build = false
|
|
126
|
+
)
|
|
127
|
+
implicit val isabelle: Isabelle = new Isabelle(setup)
|
|
128
|
+
implicit val ec: ExecutionContext = ExecutionContext.global
|
|
129
|
+
if (debug) println("Checkpoint 4")
|
|
130
|
+
|
|
131
|
+
// Complie useful ML functions
|
|
132
|
+
val script_thy: MLFunction2[String, Theory, Theory] =
|
|
133
|
+
compileFunction[String, Theory, Theory](
|
|
134
|
+
"fn (str,thy) => Thy_Info.script_thy Position.none str thy"
|
|
135
|
+
)
|
|
136
|
+
val init_toplevel: MLFunction0[ToplevelState] =
|
|
137
|
+
compileFunction0[ToplevelState]("Toplevel.init_toplevel")
|
|
138
|
+
val is_proof: MLFunction[ToplevelState, Boolean] =
|
|
139
|
+
compileFunction[ToplevelState, Boolean]("Toplevel.is_proof")
|
|
140
|
+
val is_skipped_proof: MLFunction[ToplevelState, Boolean] =
|
|
141
|
+
compileFunction[ToplevelState, Boolean]("Toplevel.is_skipped_proof")
|
|
142
|
+
val proof_level: MLFunction[ToplevelState, Int] =
|
|
143
|
+
compileFunction[ToplevelState, Int]("Toplevel.level")
|
|
144
|
+
val proof_of: MLFunction[ToplevelState, ProofState.T] =
|
|
145
|
+
compileFunction[ToplevelState, ProofState.T]("Toplevel.proof_of")
|
|
146
|
+
val command_exception
|
|
147
|
+
: MLFunction3[Boolean, Transition.T, ToplevelState, ToplevelState] =
|
|
148
|
+
compileFunction[Boolean, Transition.T, ToplevelState, ToplevelState](
|
|
149
|
+
"fn (int, tr, st) => Toplevel.command_exception int tr st"
|
|
150
|
+
)
|
|
151
|
+
val command_exception_with_10s_timeout
|
|
152
|
+
: MLFunction3[Boolean, Transition.T, ToplevelState, ToplevelState] =
|
|
153
|
+
compileFunction[Boolean, Transition.T, ToplevelState, ToplevelState](
|
|
154
|
+
"""fn (int, tr, st) => let
|
|
155
|
+
| fun go_run (a, b, c) = Toplevel.command_exception a b c
|
|
156
|
+
| in Timeout.apply (Time.fromSeconds 10) go_run (int, tr, st) end""".stripMargin
|
|
157
|
+
)
|
|
158
|
+
val command_errors: MLFunction3[
|
|
159
|
+
Boolean,
|
|
160
|
+
Transition.T,
|
|
161
|
+
ToplevelState,
|
|
162
|
+
(List[RuntimeError.T], Option[ToplevelState])
|
|
163
|
+
] = compileFunction[
|
|
164
|
+
Boolean,
|
|
165
|
+
Transition.T,
|
|
166
|
+
ToplevelState,
|
|
167
|
+
(List[RuntimeError.T], Option[ToplevelState])
|
|
168
|
+
]("fn (int, tr, st) => Toplevel.command_errors int tr st")
|
|
169
|
+
val toplevel_end_theory: MLFunction[ToplevelState, Theory] =
|
|
170
|
+
compileFunction[ToplevelState, Theory]("Toplevel.end_theory Position.none")
|
|
171
|
+
val theory_of_state: MLFunction[ToplevelState, Theory] =
|
|
172
|
+
compileFunction[ToplevelState, Theory]("Toplevel.theory_of")
|
|
173
|
+
val context_of_state: MLFunction[ToplevelState, Context] =
|
|
174
|
+
compileFunction[ToplevelState, Context]("Toplevel.context_of")
|
|
175
|
+
val name_of_transition: MLFunction[Transition.T, String] =
|
|
176
|
+
compileFunction[Transition.T, String]("Toplevel.name_of")
|
|
177
|
+
val parse_text: MLFunction2[Theory, String, List[(Transition.T, String)]] =
|
|
178
|
+
compileFunction[Theory, String, List[(Transition.T, String)]]("""fn (thy, text) => let
|
|
179
|
+
| val transitions = Outer_Syntax.parse_text thy (K thy) Position.start text
|
|
180
|
+
| fun addtext symbols [tr] =
|
|
181
|
+
| [(tr, implode symbols)]
|
|
182
|
+
| | addtext _ [] = []
|
|
183
|
+
| | addtext symbols (tr::nextTr::trs) = let
|
|
184
|
+
| val (this,rest) = Library.chop (Position.distance_of (Toplevel.pos_of tr, Toplevel.pos_of nextTr) |> Option.valOf) symbols
|
|
185
|
+
| in (tr, implode this) :: addtext rest (nextTr::trs) end
|
|
186
|
+
| in addtext (Symbol.explode text) transitions end""".stripMargin)
|
|
187
|
+
val theoryName: MLFunction2[Boolean, Theory, String] =
|
|
188
|
+
compileFunction[Boolean, Theory, String](
|
|
189
|
+
"fn (long, thy) => Context.theory_name' {long=long} thy"
|
|
190
|
+
)
|
|
191
|
+
val ancestorsNamesOfTheory: MLFunction[Theory, List[String]] =
|
|
192
|
+
compileFunction[Theory, List[String]](
|
|
193
|
+
"fn (thy) => map Context.theory_name (Context.ancestors_of thy)"
|
|
194
|
+
)
|
|
195
|
+
val toplevel_string_of_state: MLFunction[ToplevelState, String] =
|
|
196
|
+
compileFunction[ToplevelState, String](
|
|
197
|
+
"fn (s) => YXML.content_of (Toplevel.string_of_state s)"
|
|
198
|
+
)
|
|
199
|
+
val pretty_local_facts: MLFunction2[ToplevelState, Boolean, List[Pretty.T]] =
|
|
200
|
+
compileFunction[ToplevelState, Boolean, List[Pretty.T]](
|
|
201
|
+
"fn (tls, b) => Proof_Context.pretty_local_facts b (Toplevel.context_of tls)"
|
|
202
|
+
)
|
|
203
|
+
val make_pretty_list_string_list: MLFunction[List[Pretty.T], List[String]] =
|
|
204
|
+
compileFunction[List[Pretty.T], List[String]](
|
|
205
|
+
"fn (pretty_list) => map Pretty.unformatted_string_of pretty_list"
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
val local_facts_and_defs: MLFunction[ToplevelState, List[(String, String)]] =
|
|
209
|
+
compileFunction[ToplevelState, List[(String, String)]](
|
|
210
|
+
"""fn tls =>
|
|
211
|
+
| let val ctxt = Toplevel.context_of tls;
|
|
212
|
+
| val facts = Proof_Context.facts_of ctxt;
|
|
213
|
+
| val props = map #1 (Facts.props facts);
|
|
214
|
+
| val local_facts =
|
|
215
|
+
| (if null props then [] else [("unnamed", props)]) @
|
|
216
|
+
| Facts.dest_static true [Global_Theory.facts_of (Proof_Context.theory_of ctxt)] facts;
|
|
217
|
+
| val thms = (
|
|
218
|
+
| if null local_facts then []
|
|
219
|
+
| else
|
|
220
|
+
| (map (fn e => #2 (#2 e)) (sort_by (#1 o #2) (map (`(Proof_Context.pretty_fact ctxt)) local_facts))));
|
|
221
|
+
| val condensed_thms = fold (fn x => fn y => (x @ y)) thms [];
|
|
222
|
+
| in
|
|
223
|
+
| map (fn thm => (
|
|
224
|
+
| Thm.get_name_hint thm,
|
|
225
|
+
| YXML.content_of (Pretty.unformatted_string_of (Element.pretty_statement ctxt "" thm))))
|
|
226
|
+
| condensed_thms
|
|
227
|
+
| end""".stripMargin
|
|
228
|
+
)
|
|
229
|
+
val global_facts_and_defs: MLFunction[ToplevelState, List[(String, String)]] =
|
|
230
|
+
compileFunction[ToplevelState, List[(String, String)]](
|
|
231
|
+
"""fn tls =>
|
|
232
|
+
| map (fn tup => (#1 tup, YXML.content_of (Pretty.unformatted_string_of (Element.pretty_statement (Toplevel.context_of tls) "test" (#2 tup)))))
|
|
233
|
+
| (Global_Theory.all_thms_of (Proof_Context.theory_of (Toplevel.context_of tls)) false)
|
|
234
|
+
""".stripMargin
|
|
235
|
+
)
|
|
236
|
+
val fact_definition: MLFunction2[ToplevelState, String, String] =
|
|
237
|
+
compileFunction[ToplevelState, String, String](
|
|
238
|
+
"""fn (tls, name) =>
|
|
239
|
+
| let val ctxt = Toplevel.context_of tls;
|
|
240
|
+
| val thm = Global_Theory.get_thms (Proof_Context.theory_of ctxt) name;
|
|
241
|
+
| in
|
|
242
|
+
| YXML.content_of (Pretty.unformatted_string_of (Element.pretty_statement ctxt "" (hd thm)))
|
|
243
|
+
| end""".stripMargin
|
|
244
|
+
)
|
|
245
|
+
def fact_definition(
|
|
246
|
+
tls_name: String,
|
|
247
|
+
theorem_name: String
|
|
248
|
+
): String = {
|
|
249
|
+
val toplevel_state = retrieve_tls(tls_name)
|
|
250
|
+
fact_definition(toplevel_state, theorem_name).force.retrieveNow
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
val get_dependent_thms: MLFunction2[ToplevelState, String, List[String]] =
|
|
254
|
+
compileFunction[ToplevelState, String, List[String]](
|
|
255
|
+
"""fn (tls, name) =>
|
|
256
|
+
| let val thy = Toplevel.theory_of tls;
|
|
257
|
+
| val thm = Global_Theory.get_thms thy name;
|
|
258
|
+
| in
|
|
259
|
+
| map (fn x => (#1 (#2 x))) (Thm_Deps.thm_deps thy thm)
|
|
260
|
+
| end""".stripMargin
|
|
261
|
+
)
|
|
262
|
+
def get_dependent_theorems(
|
|
263
|
+
tls_name: String,
|
|
264
|
+
theorem_name: String
|
|
265
|
+
): List[String] = {
|
|
266
|
+
val toplevel_state = retrieve_tls(tls_name)
|
|
267
|
+
// println("Retrieved top level")
|
|
268
|
+
try {
|
|
269
|
+
val dependent_thms = get_dependent_thms(toplevel_state, theorem_name).force.retrieveNow
|
|
270
|
+
return dependent_thms
|
|
271
|
+
} catch {
|
|
272
|
+
case e: IsabelleMLException => {println("Name not found. Trying locales.")}
|
|
273
|
+
case o: Throwable => {println(o)}
|
|
274
|
+
}
|
|
275
|
+
val relevant_locales = locales_defined_in_file(toplevel_state)
|
|
276
|
+
// println(relevant_locales)
|
|
277
|
+
|
|
278
|
+
var dep_thms: List[String] = List()
|
|
279
|
+
|
|
280
|
+
Breaks.breakable {
|
|
281
|
+
for (relevant_locale <- relevant_locales) {
|
|
282
|
+
println("Trying locale: " + relevant_locale)
|
|
283
|
+
val full_name = relevant_locale.trim + '.' + theorem_name
|
|
284
|
+
// println(s"Trying out full name: ${full_name}")
|
|
285
|
+
try {
|
|
286
|
+
val dependent_thms = get_dependent_thms(toplevel_state, full_name).force.retrieveNow
|
|
287
|
+
dep_thms = dependent_thms
|
|
288
|
+
println("This locale works: " + relevant_locale)
|
|
289
|
+
Breaks.break
|
|
290
|
+
} catch {
|
|
291
|
+
case e: Throwable => {println(e)}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
dep_thms
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
val get_used_consts: MLFunction2[ToplevelState, String, List[String]] =
|
|
300
|
+
compileFunction[ToplevelState, String, List[String]](
|
|
301
|
+
"""fn(tls, inner_syntax) =>
|
|
302
|
+
|let
|
|
303
|
+
| val term_to_list = fn te =>
|
|
304
|
+
| let
|
|
305
|
+
| fun leaves (left $ right) = (leaves left) @ (leaves right)
|
|
306
|
+
| | leaves t = [t];
|
|
307
|
+
| fun filter_out (Const ("_type_constraint_", _)) = false
|
|
308
|
+
| | filter_out (Const _) = true
|
|
309
|
+
| | filter_out _ = false;
|
|
310
|
+
| val all_leaves = leaves te;
|
|
311
|
+
| val filtered_leaves = filter filter_out all_leaves;
|
|
312
|
+
| fun remove(_, []) = []
|
|
313
|
+
| | remove(x, y::l) =
|
|
314
|
+
| if x = y then
|
|
315
|
+
| remove(x, l)
|
|
316
|
+
| else
|
|
317
|
+
| y::remove(x, l);
|
|
318
|
+
| fun removeDup [] = []
|
|
319
|
+
| | removeDup(x::l) = x::removeDup(remove(x, l));
|
|
320
|
+
| fun string_of_term (Const (s, _)) = s
|
|
321
|
+
| | string_of_term _ = "";
|
|
322
|
+
| in
|
|
323
|
+
| removeDup (map string_of_term filtered_leaves)
|
|
324
|
+
| end;
|
|
325
|
+
|
|
|
326
|
+
| val type_to_list = fn ty =>
|
|
327
|
+
| let
|
|
328
|
+
| fun type_t (Type ty) = [#1 ty] @ (flat (map type_t (#2 ty)))
|
|
329
|
+
| | type_t (TFree _) = []
|
|
330
|
+
| | type_t (TVar _) = [];
|
|
331
|
+
| fun filter_out_universal_type_symbols symbol =
|
|
332
|
+
| case symbol of
|
|
333
|
+
| "fun" => false
|
|
334
|
+
| | "prop" => false
|
|
335
|
+
| | "itself" => false
|
|
336
|
+
| | "dummy" => false
|
|
337
|
+
| | "proof" => false
|
|
338
|
+
| | "Pure.proof" => false
|
|
339
|
+
| | _ => true;
|
|
340
|
+
| in
|
|
341
|
+
| filter filter_out_universal_type_symbols (type_t ty)
|
|
342
|
+
| end;
|
|
343
|
+
| val ctxt = Toplevel.context_of tls;
|
|
344
|
+
| val flex = fn str =>
|
|
345
|
+
| (type_to_list (Syntax.parse_typ ctxt str))
|
|
346
|
+
| handle _ => (term_to_list (Syntax.parse_term ctxt str));
|
|
347
|
+
|in
|
|
348
|
+
| flex inner_syntax
|
|
349
|
+
|end""".stripMargin
|
|
350
|
+
)
|
|
351
|
+
def get_all_definitions(
|
|
352
|
+
tls_name: String,
|
|
353
|
+
theorem_string: String
|
|
354
|
+
): List[String] = {
|
|
355
|
+
val toplevel_state = retrieve_tls(tls_name)
|
|
356
|
+
val quotation_split: List[String] = theorem_string.split('"').toList
|
|
357
|
+
val all_inner_syntax = quotation_split.indices
|
|
358
|
+
.collect { case i if i % 2 == 1 => quotation_split(i) }
|
|
359
|
+
.filter(x => x.nonEmpty)
|
|
360
|
+
.toList
|
|
361
|
+
val all_defs = all_inner_syntax.map(x =>
|
|
362
|
+
get_used_consts(toplevel_state, x).force.retrieveNow
|
|
363
|
+
)
|
|
364
|
+
val deduplicated_all_defs: List[String] = all_defs.flatten
|
|
365
|
+
deduplicated_all_defs.distinct
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Nasty locales
|
|
369
|
+
val locales_opened_for_state: MLFunction[ToplevelState, List[String]] = compileFunction[ToplevelState, List[String]](
|
|
370
|
+
"""fn (tls) => Locale.get_locales (Toplevel.theory_of tls)""".stripMargin
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
def locales_defined_in_file(tls: ToplevelState): List[String] = {
|
|
374
|
+
val locales_opened: List[String] = locales_opened_for_state(tls).force.retrieveNow
|
|
375
|
+
locales_opened.filter(_.startsWith(currentTheoryName))
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
def local_facts_and_defs_string(tls: ToplevelState): String =
|
|
379
|
+
local_facts_and_defs(tls).force.retrieveNow.distinct
|
|
380
|
+
.map(x => x._1 + "<DEF>" + x._2)
|
|
381
|
+
.mkString("<SEP>")
|
|
382
|
+
def local_facts_and_defs_string(tls_name: String): String = {
|
|
383
|
+
val tls = retrieve_tls(tls_name)
|
|
384
|
+
try {
|
|
385
|
+
local_facts_and_defs_string(tls)
|
|
386
|
+
} catch {
|
|
387
|
+
case e: Throwable => e.toString
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
def global_facts_and_defs_string(tls: ToplevelState): String =
|
|
391
|
+
global_facts_and_defs(tls).force.retrieveNow.distinct
|
|
392
|
+
.map(x => x._1 + "<DEF>" + x._2)
|
|
393
|
+
.mkString("<SEP>")
|
|
394
|
+
def global_facts_and_defs_string(tls_name: String): String = {
|
|
395
|
+
val tls = retrieve_tls(tls_name)
|
|
396
|
+
try {
|
|
397
|
+
global_facts_and_defs_string(tls)
|
|
398
|
+
} catch {
|
|
399
|
+
case e: Throwable => e.toString
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
def total_facts_and_defs_string(tls: ToplevelState): String = {
|
|
403
|
+
val local_facts = local_facts_and_defs(tls).force.retrieveNow
|
|
404
|
+
val global_facts = global_facts_and_defs(tls).force.retrieveNow
|
|
405
|
+
(local_facts ++ global_facts).distinct
|
|
406
|
+
.map(x => x._1 + "<DEF>" + x._2)
|
|
407
|
+
.mkString("<SEP>")
|
|
408
|
+
}
|
|
409
|
+
def total_facts_and_defs_string(tls_name: String): String = {
|
|
410
|
+
val tls = retrieve_tls(tls_name)
|
|
411
|
+
total_facts_and_defs_string(tls)
|
|
412
|
+
}
|
|
413
|
+
if (debug) println("Checkpoint 4")
|
|
414
|
+
val header_read: MLFunction2[String, Position, TheoryHeader] =
|
|
415
|
+
compileFunction[String, Position, TheoryHeader](
|
|
416
|
+
"fn (text,pos) => Thy_Header.read pos text"
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
def get_theory_ancestors_names(theory: Theory): List[String] =
|
|
420
|
+
ancestorsNamesOfTheory(theory).force.retrieveNow
|
|
421
|
+
|
|
422
|
+
def beginTheory(
|
|
423
|
+
source: Source
|
|
424
|
+
)(implicit isabelle: Isabelle, ec: ExecutionContext): Theory = {
|
|
425
|
+
if (debug) println("Checkpoint 9_1")
|
|
426
|
+
val header = getHeader(source)
|
|
427
|
+
if (debug) println("Checkpoint 9_2")
|
|
428
|
+
val masterDir = source.path
|
|
429
|
+
if (debug) println("Checkpoint 9_3")
|
|
430
|
+
val registers: ListBuffer[String] = new ListBuffer[String]()
|
|
431
|
+
if (debug) println("Checkpoint 9_4")
|
|
432
|
+
val theoryNamesPost = "Complex_Main" :: "HOL-Library.Sum_of_Squares" :: header.imports
|
|
433
|
+
println("Imports: " + theoryNamesPost)
|
|
434
|
+
for (theory_name <- theoryNamesPost) {
|
|
435
|
+
// var treated_name = theory_name.trim
|
|
436
|
+
// if (treated_name.startsWith("..")) {
|
|
437
|
+
// val filedir_chunks = path_to_file.split("/").dropRight(1)
|
|
438
|
+
// var imported_dir_chunks = filedir_chunks
|
|
439
|
+
// var treated_chunks = treated_name.split("/")
|
|
440
|
+
// while (treated_chunks.head == "..") {
|
|
441
|
+
// imported_dir_chunks = imported_dir_chunks.dropRight(1)
|
|
442
|
+
// treated_chunks = treated_chunks.drop(1)
|
|
443
|
+
// }
|
|
444
|
+
// imported_dir_chunks = imported_dir_chunks ++ treated_chunks
|
|
445
|
+
// imported_dir_chunks = imported_dir_chunks.dropWhile(_!=currentProjectName)
|
|
446
|
+
// val imported_dir = imported_dir_chunks.mkString(".")
|
|
447
|
+
// registers += imported_dir
|
|
448
|
+
// } else
|
|
449
|
+
if (importMap.contains(theory_name)) {
|
|
450
|
+
registers += s"${currentProjectName}.${importMap(theory_name)}"
|
|
451
|
+
} else registers += theory_name
|
|
452
|
+
}
|
|
453
|
+
if (debug) println("Checkpoint 9_5")
|
|
454
|
+
|
|
455
|
+
if (debug) {
|
|
456
|
+
println(masterDir)
|
|
457
|
+
println(header)
|
|
458
|
+
println(registers.toList)
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
Ops
|
|
462
|
+
.begin_theory(masterDir, header, registers.toList.map(Theory.apply)).force.retrieveNow
|
|
463
|
+
}
|
|
464
|
+
if (debug) println("Checkpoint 5")
|
|
465
|
+
def getHeader(
|
|
466
|
+
source: Source
|
|
467
|
+
)(implicit isabelle: Isabelle, ec: ExecutionContext): TheoryHeader =
|
|
468
|
+
source match {
|
|
469
|
+
case Text(text, path, position) =>
|
|
470
|
+
Ops.header_read(text, position).retrieveNow
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Find out about the starter string
|
|
474
|
+
private val fileContent: String = Files.readString(Path.of(path_to_file))
|
|
475
|
+
val fileContentCopy: String = fileContent
|
|
476
|
+
if (debug) println("Checkpoint 6")
|
|
477
|
+
private def getStarterString: String = {
|
|
478
|
+
val decoyThy: Theory = Theory("Main")
|
|
479
|
+
for (
|
|
480
|
+
(transition, text) <- parse_text(decoyThy, fileContent).force.retrieveNow
|
|
481
|
+
) {
|
|
482
|
+
if (
|
|
483
|
+
text.contains("theory") && text.contains(currentTheoryName) && text
|
|
484
|
+
.contains("begin")
|
|
485
|
+
) {
|
|
486
|
+
return text
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
"This is wrong!!!"
|
|
490
|
+
}
|
|
491
|
+
if (debug) println("Checkpoint 7")
|
|
492
|
+
val starter_string: String = getStarterString.trim.replaceAll("\n", " ").trim
|
|
493
|
+
|
|
494
|
+
// Find out what to import from the current directory
|
|
495
|
+
def getListOfTheoryFiles(dir: File): List[File] = {
|
|
496
|
+
if (dir.exists && dir.isDirectory) {
|
|
497
|
+
var listOfFilesBuffer: ListBuffer[File] = new ListBuffer[File]
|
|
498
|
+
for (f <- dir.listFiles()) {
|
|
499
|
+
if (f.isDirectory) {
|
|
500
|
+
listOfFilesBuffer = listOfFilesBuffer ++ getListOfTheoryFiles(f)
|
|
501
|
+
} else if (f.toString.endsWith(".thy")) {
|
|
502
|
+
listOfFilesBuffer += f
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
listOfFilesBuffer.toList
|
|
506
|
+
} else {
|
|
507
|
+
List[File]()
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
def sanitiseInDirectoryName(fileName: String): String = {
|
|
512
|
+
fileName.replace("\"", "").split("/").last.split(".thy").head
|
|
513
|
+
}
|
|
514
|
+
if (debug) println("Checkpoint 8")
|
|
515
|
+
// Figure out what theories to import
|
|
516
|
+
val available_files: List[File] = getListOfTheoryFiles(
|
|
517
|
+
new File(working_directory)
|
|
518
|
+
)
|
|
519
|
+
var available_imports_buffer: ListBuffer[String] = new ListBuffer[String]
|
|
520
|
+
for (file_name <- available_files) {
|
|
521
|
+
if (file_name.getName().endsWith(".thy")) {
|
|
522
|
+
available_imports_buffer =
|
|
523
|
+
available_imports_buffer += file_name.getName().split(".thy")(0)
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
var available_imports: Set[String] = available_imports_buffer.toSet
|
|
527
|
+
val theoryNames: List[String] = starter_string
|
|
528
|
+
.split("imports")(1)
|
|
529
|
+
.split("begin")(0)
|
|
530
|
+
.split(" ")
|
|
531
|
+
.map(_.trim)
|
|
532
|
+
.filter(_.nonEmpty)
|
|
533
|
+
.toList
|
|
534
|
+
var importMap: Map[String, String] = Map()
|
|
535
|
+
for (theory_name <- theoryNames) {
|
|
536
|
+
val sanitisedName = sanitiseInDirectoryName(theory_name)
|
|
537
|
+
if (available_imports(sanitisedName)) {
|
|
538
|
+
importMap += (theory_name.replace("\"", "") -> sanitisedName)
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
var top_level_state_map: Map[String, MLValue[ToplevelState]] = Map()
|
|
543
|
+
val theoryStarter: TheoryManager.Text =
|
|
544
|
+
TheoryManager.Text(starter_string, setup.workingDirectory.resolve(""))
|
|
545
|
+
if (debug) println("Checkpoint 9")
|
|
546
|
+
var thy1: Theory = beginTheory(theoryStarter)
|
|
547
|
+
if (debug) println("Checkpoint 9_6")
|
|
548
|
+
thy1.await
|
|
549
|
+
if (debug) println("Checkpoint 10")
|
|
550
|
+
|
|
551
|
+
// setting up Sledgehammer
|
|
552
|
+
// val thy_for_sledgehammer: Theory = Theory("HOL.List")
|
|
553
|
+
val thy_for_sledgehammer = thy1
|
|
554
|
+
val Sledgehammer: String =
|
|
555
|
+
thy_for_sledgehammer.importMLStructureNow("Sledgehammer")
|
|
556
|
+
val Sledgehammer_Commands: String =
|
|
557
|
+
thy_for_sledgehammer.importMLStructureNow("Sledgehammer_Commands")
|
|
558
|
+
val Sledgehammer_Prover: String =
|
|
559
|
+
thy_for_sledgehammer.importMLStructureNow("Sledgehammer_Prover")
|
|
560
|
+
|
|
561
|
+
// prove_with_Sledgehammer is mostly identical to check_with_Sledgehammer except for that when the returned Boolean is true, it will
|
|
562
|
+
// also return a non-empty list of Strings, each of which contains executable commands to close the top subgoal. We might need to chop part of
|
|
563
|
+
// the string to get the actual tactic. For example, one of the string may look like "Try this: by blast (0.5 ms)".
|
|
564
|
+
if (debug) println("Checkpoint 11")
|
|
565
|
+
val normal_with_Sledgehammer: MLFunction4[ToplevelState, Theory, List[
|
|
566
|
+
String
|
|
567
|
+
], List[String], (Boolean, (String, List[String]))] =
|
|
568
|
+
compileFunction[ToplevelState, Theory, List[String], List[
|
|
569
|
+
String
|
|
570
|
+
], (Boolean, (String, List[String]))](
|
|
571
|
+
s""" fn (state, thy, adds, dels) =>
|
|
572
|
+
| let
|
|
573
|
+
| fun get_refs_and_token_lists (name) = (Facts.named name, []);
|
|
574
|
+
| val adds_refs_and_token_lists = map get_refs_and_token_lists adds;
|
|
575
|
+
| val dels_refs_and_token_lists = map get_refs_and_token_lists dels;
|
|
576
|
+
| val override = {add=adds_refs_and_token_lists,del=dels_refs_and_token_lists,only=false};
|
|
577
|
+
| fun go_run (state, thy) =
|
|
578
|
+
| let
|
|
579
|
+
| val p_state = Toplevel.proof_of state;
|
|
580
|
+
| val ctxt = Proof.context_of p_state;
|
|
581
|
+
| val params = ${Sledgehammer_Commands}.default_params thy
|
|
582
|
+
| [("provers", "cvc5 vampire verit e spass z3 zipperposition"),("timeout","120"),("verbose","true")];
|
|
583
|
+
| val results = ${Sledgehammer}.run_sledgehammer params ${Sledgehammer_Prover}.Normal NONE 1 override p_state;
|
|
584
|
+
| val (result, (outcome, step)) = results;
|
|
585
|
+
| in
|
|
586
|
+
| (result, (${Sledgehammer}.short_string_of_sledgehammer_outcome outcome, [YXML.content_of step]))
|
|
587
|
+
| end;
|
|
588
|
+
| in
|
|
589
|
+
| Timeout.apply (Time.fromSeconds 240) go_run (state, thy) end
|
|
590
|
+
|""".stripMargin
|
|
591
|
+
)
|
|
592
|
+
|
|
593
|
+
var toplevel: ToplevelState = init_toplevel().force.retrieveNow
|
|
594
|
+
if (debug) println("Checkpoint 12")
|
|
595
|
+
def reset_map(): Unit = {
|
|
596
|
+
top_level_state_map = Map()
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
def reset_prob(): Unit = {
|
|
600
|
+
thy1 = beginTheory(theoryStarter)
|
|
601
|
+
toplevel = init_toplevel().force.retrieveNow
|
|
602
|
+
reset_map()
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
def getFacts(stateString: String): String = {
|
|
606
|
+
var facts: String = ""
|
|
607
|
+
if (stateString.trim.nonEmpty) {
|
|
608
|
+
// Limit the maximum number of local facts to be 5
|
|
609
|
+
for (
|
|
610
|
+
fact <- make_pretty_list_string_list(
|
|
611
|
+
pretty_local_facts(toplevel, false)
|
|
612
|
+
).retrieveNow.takeRight(5)
|
|
613
|
+
) {
|
|
614
|
+
facts = facts + fact + "<\\PISASEP>"
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
facts
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
def getStateString(top_level_state: ToplevelState): String =
|
|
621
|
+
toplevel_string_of_state(top_level_state).force.retrieveNow
|
|
622
|
+
|
|
623
|
+
def getStateString: String = getStateString(toplevel)
|
|
624
|
+
|
|
625
|
+
def is_done(top_level_state: ToplevelState): Boolean = {
|
|
626
|
+
getProofLevel(top_level_state) == 0
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
def getProofLevel(top_level_state: ToplevelState): Int =
|
|
630
|
+
proof_level(top_level_state).retrieveNow
|
|
631
|
+
|
|
632
|
+
def getProofLevel: Int = getProofLevel(toplevel)
|
|
633
|
+
|
|
634
|
+
def singleTransitionWith10sTimeout(
|
|
635
|
+
single_transition: Transition.T,
|
|
636
|
+
top_level_state: ToplevelState
|
|
637
|
+
): ToplevelState = {
|
|
638
|
+
command_exception_with_10s_timeout(
|
|
639
|
+
true,
|
|
640
|
+
single_transition,
|
|
641
|
+
top_level_state
|
|
642
|
+
).retrieveNow.force
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
def singleTransition(
|
|
646
|
+
single_transition: Transition.T,
|
|
647
|
+
top_level_state: ToplevelState
|
|
648
|
+
): ToplevelState = {
|
|
649
|
+
command_exception(
|
|
650
|
+
true,
|
|
651
|
+
single_transition,
|
|
652
|
+
top_level_state
|
|
653
|
+
).retrieveNow.force
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
def singleTransition(singTransition: Transition.T): String = {
|
|
657
|
+
// TODO: inlcude global facts
|
|
658
|
+
toplevel = singleTransition(singTransition, toplevel)
|
|
659
|
+
getStateString
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
def parseStateAction(isarString: String): String = {
|
|
663
|
+
// Here we directly apply transitions to the theory repeatedly
|
|
664
|
+
// to get the (last_observation, action, observation, reward, done) tuple
|
|
665
|
+
var stateActionTotal: String = ""
|
|
666
|
+
val continue = new Breaks
|
|
667
|
+
// Initialising the state string
|
|
668
|
+
var stateString = getStateString
|
|
669
|
+
var proof_level_number = getProofLevel
|
|
670
|
+
Breaks.breakable {
|
|
671
|
+
for ((transition, text) <- parse_text(thy1, isarString).force.retrieveNow)
|
|
672
|
+
continue.breakable {
|
|
673
|
+
if (text.trim.isEmpty) continue.break
|
|
674
|
+
else if (text.trim.startsWith("text \\<open>") && text.trim.endsWith("\\<close>")) continue.break
|
|
675
|
+
else if (text.trim.startsWith("(*") && text.trim.endsWith("*)")) continue.break
|
|
676
|
+
else {
|
|
677
|
+
stateActionTotal =
|
|
678
|
+
stateActionTotal + (stateString + "<\\STATESEP>" + text.trim + "<\\STATESEP>" + s"$getProofLevel" + "<\\TRANSEP>")
|
|
679
|
+
stateString = singleTransition(transition)
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
stateActionTotal
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
def parse: String = parseStateAction(fileContent)
|
|
687
|
+
|
|
688
|
+
@throws(classOf[IsabelleMLException])
|
|
689
|
+
@throws(classOf[TimeoutException])
|
|
690
|
+
def step(
|
|
691
|
+
isar_string: String,
|
|
692
|
+
top_level_state: ToplevelState,
|
|
693
|
+
timeout_in_millis: Int = 10000,
|
|
694
|
+
): ToplevelState = {
|
|
695
|
+
if (debug) println("Begin step")
|
|
696
|
+
// Normal isabelle business
|
|
697
|
+
var tls_to_return: ToplevelState = clone_tls_scala(top_level_state)
|
|
698
|
+
var stateString: String = ""
|
|
699
|
+
val continue = new Breaks
|
|
700
|
+
if (debug) println("Starting to step")
|
|
701
|
+
val f_st = Future.apply {
|
|
702
|
+
blocking {
|
|
703
|
+
Breaks.breakable {
|
|
704
|
+
if (debug) println("start parsing")
|
|
705
|
+
for (
|
|
706
|
+
(transition, text) <- parse_text(
|
|
707
|
+
thy1,
|
|
708
|
+
isar_string
|
|
709
|
+
).force.retrieveNow
|
|
710
|
+
)
|
|
711
|
+
continue.breakable {
|
|
712
|
+
if (text.trim.isEmpty) continue.break
|
|
713
|
+
// println("Small step : " + text)
|
|
714
|
+
tls_to_return = singleTransitionWith10sTimeout(transition, tls_to_return)
|
|
715
|
+
// println("Applied transition successfully")
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
"success"
|
|
720
|
+
}
|
|
721
|
+
if (debug) println("inter")
|
|
722
|
+
|
|
723
|
+
// Await for infinite amount of time
|
|
724
|
+
Await.result(f_st, Duration.Inf)
|
|
725
|
+
if (debug) println(f_st)
|
|
726
|
+
tls_to_return
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
def step(isar_string: String): String = {
|
|
730
|
+
// Specific method for extracting data
|
|
731
|
+
if (isar_string == "PISA extract data")
|
|
732
|
+
return parse
|
|
733
|
+
|
|
734
|
+
// Exit string
|
|
735
|
+
if (isar_string == "exit") {
|
|
736
|
+
isabelle.destroy()
|
|
737
|
+
// print("Isabelle process destroyed")
|
|
738
|
+
return "Destroyed"
|
|
739
|
+
}
|
|
740
|
+
toplevel = step(isar_string, toplevel)
|
|
741
|
+
getStateString
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
def normal_with_hammer(
|
|
745
|
+
top_level_state: ToplevelState,
|
|
746
|
+
added_names: List[String],
|
|
747
|
+
deleted_names: List[String],
|
|
748
|
+
timeout_in_millis: Int,
|
|
749
|
+
): (Boolean, List[String]) = {
|
|
750
|
+
val f_res: Future[(Boolean, List[String])] = Future.apply {
|
|
751
|
+
val first_result = normal_with_Sledgehammer(
|
|
752
|
+
top_level_state,
|
|
753
|
+
thy1,
|
|
754
|
+
added_names,
|
|
755
|
+
deleted_names
|
|
756
|
+
).force.retrieveNow
|
|
757
|
+
(first_result._1, first_result._2._2)
|
|
758
|
+
}
|
|
759
|
+
Await.result(f_res, Duration(timeout_in_millis, "millis"))
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
if (debug) println("Checkpoint 13")
|
|
763
|
+
val transitions_and_texts = parse_text(thy1, fileContent).force.retrieveNow
|
|
764
|
+
var frontier_proceeding_index = 0
|
|
765
|
+
if (debug) println("Checkpoint 14")
|
|
766
|
+
|
|
767
|
+
def accumulative_step_to_before_transition_starting(
|
|
768
|
+
isar_string: String
|
|
769
|
+
): String = {
|
|
770
|
+
val sanitised_isar_string =
|
|
771
|
+
isar_string.trim.replaceAll("\n", " ").replaceAll(" +", " ")
|
|
772
|
+
val (transition, text) = transitions_and_texts(frontier_proceeding_index)
|
|
773
|
+
val sanitised_text = text.trim.replaceAll("\n", " ").replaceAll(" +", " ")
|
|
774
|
+
if (sanitised_text.trim.isEmpty) {
|
|
775
|
+
frontier_proceeding_index += 1
|
|
776
|
+
accumulative_step_to_before_transition_starting(sanitised_isar_string)
|
|
777
|
+
} else if (sanitised_text.trim == sanitised_isar_string) {
|
|
778
|
+
val top_level_proceeding_state = retrieve_tls("default")
|
|
779
|
+
getStateString(top_level_proceeding_state)
|
|
780
|
+
} else {
|
|
781
|
+
frontier_proceeding_index += 1
|
|
782
|
+
val top_level_proceeding_state = retrieve_tls("default")
|
|
783
|
+
val resulting_state: ToplevelState =
|
|
784
|
+
singleTransition(transition, top_level_proceeding_state)
|
|
785
|
+
register_tls("default", resulting_state)
|
|
786
|
+
accumulative_step_to_before_transition_starting(sanitised_isar_string)
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
var accumulative_index : Int = 0
|
|
791
|
+
def accumulative_step_before_theorem_starts(theorem_name: String): Unit = {
|
|
792
|
+
val sanitised_theorem_name = theorem_name.trim.replaceAll("\n", " ").replaceAll(" +", " ")
|
|
793
|
+
var found_theorem : Boolean = false
|
|
794
|
+
while (!found_theorem){
|
|
795
|
+
val (transition, text) = transitions_and_texts(accumulative_index)
|
|
796
|
+
val sanitised_text = text.trim.replaceAll("\n", " ").replaceAll(" +", " ")
|
|
797
|
+
if (sanitised_text == sanitised_theorem_name){
|
|
798
|
+
found_theorem = true
|
|
799
|
+
} else {
|
|
800
|
+
// println("Before theorem" + sanitised_text)
|
|
801
|
+
if (sanitised_text.nonEmpty) singleTransition(transition)
|
|
802
|
+
accumulative_index += 1
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
def accumulative_step_through_a_theorem: Unit = {
|
|
807
|
+
var proof_finished : Boolean = false
|
|
808
|
+
while (!proof_finished) {
|
|
809
|
+
val (transition, text) = transitions_and_texts(accumulative_index)
|
|
810
|
+
val sanitised_text = text.trim.replaceAll("\n", " ").replaceAll(" +", " ")
|
|
811
|
+
if (sanitised_text.isEmpty) {
|
|
812
|
+
accumulative_index += 1
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
// println("During theorem" + sanitised_text)
|
|
816
|
+
// println("Stepping to: " + sanitised_text)
|
|
817
|
+
singleTransition(transition)
|
|
818
|
+
val proof_level = getProofLevel
|
|
819
|
+
if (proof_level == 0) proof_finished = true
|
|
820
|
+
accumulative_index += 1
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
def accumulative_step_to_theorem_end(theorem_name: String) : Unit ={
|
|
825
|
+
accumulative_step_before_theorem_starts(theorem_name)
|
|
826
|
+
accumulative_step_through_a_theorem
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
def step_to_transition_text(
|
|
830
|
+
isar_string: String,
|
|
831
|
+
after: Boolean = true
|
|
832
|
+
): String = {
|
|
833
|
+
var stateString: String = ""
|
|
834
|
+
val continue = new Breaks
|
|
835
|
+
Breaks.breakable {
|
|
836
|
+
for (
|
|
837
|
+
(transition, text) <- parse_text(thy1, fileContent).force.retrieveNow
|
|
838
|
+
) {
|
|
839
|
+
continue.breakable {
|
|
840
|
+
if (text.trim.isEmpty) continue.break
|
|
841
|
+
val trimmed_text =
|
|
842
|
+
text.trim.replaceAll("\n", " ").replaceAll(" +", " ")
|
|
843
|
+
if (trimmed_text == isar_string) {
|
|
844
|
+
if (after) stateString = singleTransition(transition)
|
|
845
|
+
return stateString
|
|
846
|
+
}
|
|
847
|
+
stateString = singleTransition(transition)
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
println("Did not find the text")
|
|
852
|
+
stateString
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// Manage top level states with the internal map
|
|
856
|
+
def copy_tls: MLValue[ToplevelState] = toplevel.mlValue
|
|
857
|
+
|
|
858
|
+
def clone_tls(tls_name: String): Unit =
|
|
859
|
+
top_level_state_map += (tls_name -> copy_tls)
|
|
860
|
+
|
|
861
|
+
def clone_tls(old_name: String, new_name: String): Unit =
|
|
862
|
+
top_level_state_map += (new_name -> top_level_state_map(old_name))
|
|
863
|
+
|
|
864
|
+
def _clone_tls_scala(tls_scala: ToplevelState): Future[ToplevelState] =
|
|
865
|
+
ToplevelState.converter.retrieve(tls_scala.mlValue)
|
|
866
|
+
|
|
867
|
+
def clone_tls_scala(tls_scala: ToplevelState): ToplevelState =
|
|
868
|
+
Await.result(_clone_tls_scala(tls_scala), Duration.Inf)
|
|
869
|
+
|
|
870
|
+
def register_tls(name: String, tls: ToplevelState): Unit =
|
|
871
|
+
top_level_state_map += (name -> tls.mlValue)
|
|
872
|
+
|
|
873
|
+
def _retrieve_tls(tls_name: String): Future[ToplevelState] =
|
|
874
|
+
ToplevelState.converter.retrieve(top_level_state_map(tls_name))
|
|
875
|
+
|
|
876
|
+
def retrieve_tls(tls_name: String): ToplevelState =
|
|
877
|
+
Await.result(_retrieve_tls(tls_name), Duration.Inf)
|
|
878
|
+
|
|
879
|
+
def parse_entire_thy: List[String] =
|
|
880
|
+
parse_text(thy1, fileContent).force.retrieveNow.map(_._2)
|
|
881
|
+
}
|