├── .github └── workflows │ └── build.yml ├── INSTALL ├── LICENSE ├── README.md ├── doc ├── appendix_operators.tex ├── ar.tex ├── builtin.tex ├── cinterface.tex ├── constraints.tex ├── data_types.tex ├── datetime.tex ├── exception.tex ├── format.tex ├── get_started.pdf ├── get_started.tex ├── intro_sys.tex ├── io.tex ├── lex_grammar.tex ├── loops.tex ├── math.tex ├── module.tex ├── neuralnets.tex ├── nn.tex ├── operators.tex ├── ordset.tex ├── os.tex ├── overview.tex ├── picat_guide.pdf ├── picat_guide.tex ├── planner.tex ├── predfunc.tex ├── preface.tex ├── syntax_grammar.tex ├── sys.tex ├── tabling.tex └── util.tex ├── emu ├── Makefile ├── Makefile.cygwin64 ├── Makefile.linux32 ├── Makefile.linux64 ├── Makefile.mac64 ├── Makefile.mingwin32 ├── Makefile.mingwin64 ├── Makefile.mingwin64-32 ├── arith.c ├── assert.c ├── assert_bp.c ├── bapi.h ├── basic.h ├── basicd.h ├── bigint.c ├── bprolog.h ├── bprolog_cg_cgevent.h ├── bprolog_plc_plc.h ├── builtins.c ├── cfd.c ├── clause.c ├── clpfd.c ├── clpfd.h ├── clpfd_libs.c ├── common.mak ├── cpreds.c ├── debug.c ├── delay.c ├── dis.c ├── dis_inst.h ├── domain.c ├── dynamic.h ├── emu_inst.h ├── espresso │ ├── COPYING │ ├── Makefile │ ├── Makefile.mac64 │ ├── black_white.c │ ├── canonical.c │ ├── cofactor.c │ ├── cols.c │ ├── compl.c │ ├── contain.c │ ├── copyright.h │ ├── cpu_time.c │ ├── cubestr.c │ ├── cvrin.c │ ├── cvrm.c │ ├── cvrmisc.c │ ├── cvrout.c │ ├── dominate.c │ ├── equiv.c │ ├── espresso.c │ ├── espresso.h │ ├── espresso_expand.c │ ├── espresso_main.c │ ├── essen.c │ ├── essentiality.c │ ├── exact.c │ ├── gasp.c │ ├── gimpel.c │ ├── globals.c │ ├── hack.c │ ├── indep.c │ ├── irred.c │ ├── main.h │ ├── map.c │ ├── matrix.c │ ├── mincov.c │ ├── mincov.h │ ├── mincov_int.h │ ├── opo.c │ ├── pair.c │ ├── part.c │ ├── port.h │ ├── primes.c │ ├── prtime.c │ ├── reduce.c │ ├── rows.c │ ├── set.c │ ├── setc.c │ ├── sharp.c │ ├── sigma.c │ ├── signature.c │ ├── signature.h │ ├── signature_exact.c │ ├── sminterf.c │ ├── solution.c │ ├── sparse.c │ ├── sparse.h │ ├── sparse_int.h │ ├── unate.c │ ├── util_signature.c │ ├── utility.h │ └── verify.c ├── espresso_bp.c ├── event.c ├── event.h ├── expand.c ├── expand_bp.c ├── extern_decl.h ├── fann │ ├── fann_interface.cpp │ ├── fann_interface.h │ └── src │ │ ├── CMakeLists.txt │ │ ├── README.txt │ │ ├── doublefann.c │ │ ├── fann.c │ │ ├── fann_cascade.c │ │ ├── fann_error.c │ │ ├── fann_io.c │ │ ├── fann_train.c │ │ ├── fann_train_data.c │ │ ├── fixedfann.c │ │ ├── floatfann.c │ │ ├── include │ │ ├── CMakeLists.txt │ │ ├── compat_time.h │ │ ├── config.h │ │ ├── doublefann.h │ │ ├── fann.h │ │ ├── fann_activation.h │ │ ├── fann_cascade.h │ │ ├── fann_cpp.h │ │ ├── fann_data.h │ │ ├── fann_data_cpp.h │ │ ├── fann_error.h │ │ ├── fann_internal.h │ │ ├── fann_io.h │ │ ├── fann_train.h │ │ ├── fann_training_data_cpp.h │ │ ├── fixedfann.h │ │ ├── floatfann.h │ │ ├── parallel_fann.h │ │ └── parallel_fann.hpp │ │ ├── parallel_doublefann_cpp.cpp │ │ ├── parallel_fann.c │ │ ├── parallel_fann_cpp.cpp │ │ └── parallel_floatfann_cpp.cpp ├── file.c ├── findall.c ├── float1.c ├── frame.h ├── fzn_picat_smt_bc.h ├── gc.h ├── gcheap.c ├── gcqueue.c ├── gcstack.c ├── getline.c ├── getline.h ├── global.c ├── glpk_bp.c ├── init.c ├── init_sym.c ├── inst.h ├── inst_inf.c ├── jmp_table.c ├── kapi.c ├── kapi.h ├── kissat │ ├── CONTRIBUTING │ ├── LICENSE │ ├── README.md │ ├── VERSION │ └── src │ │ ├── allocate.c │ │ ├── allocate.h │ │ ├── analyze.c │ │ ├── analyze.h │ │ ├── ands.c │ │ ├── ands.h │ │ ├── application.c │ │ ├── application.h │ │ ├── arena.c │ │ ├── arena.h │ │ ├── array.h │ │ ├── assign.c │ │ ├── assign.h │ │ ├── attribute.h │ │ ├── autarky.c │ │ ├── autarky.h │ │ ├── averages.c │ │ ├── averages.h │ │ ├── backbone.c │ │ ├── backbone.h │ │ ├── backtrack.c │ │ ├── backtrack.h │ │ ├── backward.c │ │ ├── backward.h │ │ ├── build.c │ │ ├── build.h │ │ ├── bump.c │ │ ├── bump.h │ │ ├── check.c │ │ ├── check.h │ │ ├── clause.c │ │ ├── clause.h │ │ ├── clueue.c │ │ ├── clueue.h │ │ ├── collect.c │ │ ├── collect.h │ │ ├── colors.c │ │ ├── colors.h │ │ ├── compact.c │ │ ├── compact.h │ │ ├── config.c │ │ ├── config.h │ │ ├── configure │ │ ├── cover.h │ │ ├── decide.c │ │ ├── decide.h │ │ ├── deduce.c │ │ ├── deduce.h │ │ ├── definition.c │ │ ├── definition.h │ │ ├── dense.c │ │ ├── dense.h │ │ ├── dominate.c │ │ ├── dominate.h │ │ ├── dump.c │ │ ├── eliminate.c │ │ ├── eliminate.h │ │ ├── endianess.h │ │ ├── endianness.h │ │ ├── equivalences.c │ │ ├── equivalences.h │ │ ├── error.c │ │ ├── error.h │ │ ├── extend.c │ │ ├── extend.h │ │ ├── failed.c │ │ ├── failed.h │ │ ├── fastassign.h │ │ ├── file.c │ │ ├── file.h │ │ ├── flags.c │ │ ├── flags.h │ │ ├── format.c │ │ ├── format.h │ │ ├── forward.c │ │ ├── forward.h │ │ ├── frames.c │ │ ├── frames.h │ │ ├── gates.c │ │ ├── gates.h │ │ ├── gen_make.pi │ │ ├── gen_o.pi │ │ ├── handle.c │ │ ├── handle.h │ │ ├── heap.c │ │ ├── heap.h │ │ ├── ifthenelse.c │ │ ├── ifthenelse.h │ │ ├── import.c │ │ ├── import.h │ │ ├── inline.h │ │ ├── inlineassign.h │ │ ├── inlineframes.h │ │ ├── inlineheap.h │ │ ├── inlinequeue.h │ │ ├── inlinevector.h │ │ ├── internal.c │ │ ├── internal.h │ │ ├── kimits.c │ │ ├── kimits.h │ │ ├── kissat.h │ │ ├── kissat_bool.h │ │ ├── kitten.c │ │ ├── kitten.h │ │ ├── learn.c │ │ ├── learn.h │ │ ├── limits.c │ │ ├── limits.h │ │ ├── literal.h │ │ ├── logging.c │ │ ├── logging.h │ │ ├── main.c │ │ ├── minimize.c │ │ ├── minimize.h │ │ ├── mode.c │ │ ├── mode.h │ │ ├── options.c │ │ ├── options.h │ │ ├── parse.c │ │ ├── parse.h │ │ ├── phases.c │ │ ├── phases.h │ │ ├── print.c │ │ ├── print.h │ │ ├── probe.c │ │ ├── probe.h │ │ ├── profile.c │ │ ├── profile.h │ │ ├── promote.c │ │ ├── promote.h │ │ ├── proof.c │ │ ├── proof.h │ │ ├── propbeyond.c │ │ ├── propbeyond.h │ │ ├── propdense.c │ │ ├── propdense.h │ │ ├── prophyper.c │ │ ├── prophyper.h │ │ ├── proplit.h │ │ ├── proprobe.c │ │ ├── proprobe.h │ │ ├── propsearch.c │ │ ├── propsearch.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── random.h │ │ ├── rank.h │ │ ├── reduce.c │ │ ├── reduce.h │ │ ├── reference.h │ │ ├── reluctant.c │ │ ├── reluctant.h │ │ ├── rephase.c │ │ ├── rephase.h │ │ ├── report.c │ │ ├── report.h │ │ ├── require.h │ │ ├── resize.c │ │ ├── resize.h │ │ ├── resolve.c │ │ ├── resolve.h │ │ ├── resources.c │ │ ├── resources.h │ │ ├── restart.c │ │ ├── restart.h │ │ ├── search.c │ │ ├── search.h │ │ ├── shrink.c │ │ ├── shrink.h │ │ ├── smooth.c │ │ ├── smooth.h │ │ ├── sort.c │ │ ├── sort.h │ │ ├── stack.c │ │ ├── stack.h │ │ ├── statistics.c │ │ ├── statistics.h │ │ ├── strengthen.c │ │ ├── strengthen.h │ │ ├── substitute.c │ │ ├── substitute.h │ │ ├── sweep.c │ │ ├── sweep.h │ │ ├── terminate.c │ │ ├── terminate.h │ │ ├── ternary.c │ │ ├── ternary.h │ │ ├── trail.c │ │ ├── trail.h │ │ ├── transitive.c │ │ ├── transitive.h │ │ ├── utilities.c │ │ ├── utilities.h │ │ ├── value.h │ │ ├── vector.c │ │ ├── vector.h │ │ ├── vivify.c │ │ ├── vivify.h │ │ ├── walk.c │ │ ├── walk.h │ │ ├── warmup.c │ │ ├── warmup.h │ │ ├── watch.c │ │ ├── watch.h │ │ ├── weaken.c │ │ ├── weaken.h │ │ ├── witness.c │ │ ├── witness.h │ │ ├── xors.c │ │ └── xors.h ├── kissat_picat.c ├── load_inst.c ├── load_inst.h ├── load_inst_frombplist.h ├── load_inst_fromcarray.h ├── loader.c ├── main.c ├── make_picat_scip_linux ├── make_picat_scip_mac ├── maple │ ├── LICENSE │ ├── bin │ │ └── starexec_run_default │ ├── core │ │ ├── Dimacs.h │ │ ├── Main.cc │ │ ├── Makefile │ │ ├── Solver.cc │ │ ├── Solver.h │ │ └── SolverTypes.h │ ├── mtl │ │ ├── Alg.h │ │ ├── Alloc.h │ │ ├── Heap.h │ │ ├── IntTypes.h │ │ ├── Map.h │ │ ├── Queue.h │ │ ├── Sort.h │ │ ├── Vec.h │ │ ├── XAlloc.h │ │ ├── config.mk │ │ └── template.mk │ ├── simp │ │ ├── Main.cc │ │ ├── Makefile │ │ ├── SimpSolver.cc │ │ ├── SimpSolver.h │ │ └── depend.mk │ ├── starexec_build │ └── utils │ │ ├── Makefile │ │ ├── Options.cc │ │ ├── Options.h │ │ ├── ParseUtils.h │ │ ├── System.cc │ │ └── System.h ├── maple_interface.cpp ├── maple_interface.h ├── mic.c ├── numbervars.c ├── picat.h ├── picat_bc.h ├── picat_utilities.c ├── picat_utilities.h ├── plc_java.c ├── qc.c ├── reasonls_interface.cpp ├── reasonls_interface.h ├── sapi.c ├── sapi.h ├── sat_bp.c ├── scip_picat.c ├── scipsuite.tar.gz ├── table.c ├── term.h ├── toam.c ├── toam.h ├── toamprofile.c ├── token.c ├── unify.c └── univ.c ├── exs ├── cp │ ├── kakuro.pi │ ├── knightTour.pi │ ├── pigeon_hole.pi │ ├── ppm.pi │ ├── queens.pi │ ├── sequence.pi │ ├── sudoku.pi │ └── zebra.pi ├── euler │ ├── base_exp.txt │ ├── names.txt │ ├── p1.pi │ ├── p10.pi │ ├── p100.pi │ ├── p106.pi │ ├── p108.pi │ ├── p10_rb.pi │ ├── p11.pi │ ├── p12.pi │ ├── p13.pi │ ├── p14.pi │ ├── p15.pi │ ├── p16.pi │ ├── p17.pi │ ├── p18.pi │ ├── p19.pi │ ├── p1_rb.pi │ ├── p2.pi │ ├── p20.pi │ ├── p206.pi │ ├── p21.pi │ ├── p22.pi │ ├── p23.pi │ ├── p24.pi │ ├── p25.pi │ ├── p26.pi │ ├── p27.pi │ ├── p28.pi │ ├── p29.pi │ ├── p2_rb.pi │ ├── p3.pi │ ├── p30.pi │ ├── p31.pi │ ├── p32.pi │ ├── p33.pi │ ├── p34.pi │ ├── p35.pi │ ├── p36.pi │ ├── p37.pi │ ├── p38.pi │ ├── p39.pi │ ├── p4.pi │ ├── p40.pi │ ├── p41.pi │ ├── p42.pi │ ├── p43.pi │ ├── p44.pi │ ├── p45.pi │ ├── p46.pi │ ├── p47.pi │ ├── p48.pi │ ├── p49.pi │ ├── p5.pi │ ├── p50.pi │ ├── p52.pi │ ├── p6.pi │ ├── p67.pi │ ├── p67_old.pi │ ├── p7.pi │ ├── p7_old.pi │ ├── p8.pi │ ├── p9.pi │ ├── p99.pi │ ├── p9_rb.pi │ ├── pi_rb.pi │ ├── test.txt │ ├── triangle.txt │ └── words.txt ├── exs.pi ├── mip │ ├── bqueens.pi │ ├── coin.pi │ ├── diet.pi │ ├── maxflow_mip.pi │ ├── tmip_ex1.pi │ ├── tmip_ex2.pi │ ├── tmip_ex3.pi │ ├── tmip_ex4.pi │ ├── tmip_ex5.pi │ ├── tmip_ex6.pi │ └── tmip_ex7.pi ├── nn │ ├── author_classify │ │ ├── README.md │ │ ├── author_classify_test.pi │ │ ├── author_classify_train.pi │ │ ├── chesterton1.txt │ │ ├── chesterton2.txt │ │ ├── chesterton3.txt │ │ ├── melville1.txt │ │ ├── melville2.txt │ │ ├── melville3.txt │ │ ├── preprocess.pi │ │ ├── processed_chesterton1.txt │ │ ├── processed_chesterton2.txt │ │ ├── processed_chesterton3.txt │ │ ├── processed_melville1.txt │ │ ├── processed_melville2.txt │ │ ├── processed_melville3.txt │ │ ├── transition_probabilities.data │ │ └── transition_probabilities.pi │ ├── lang_classify │ │ ├── README.md │ │ ├── english1.txt │ │ ├── english2.txt │ │ ├── english3.txt │ │ ├── french1.txt │ │ ├── french2.txt │ │ ├── french3.txt │ │ ├── frequencies.data │ │ ├── frequencies.pi │ │ ├── lang_classify.net │ │ ├── lang_classify_test.pi │ │ ├── lang_classify_train.pi │ │ ├── spanish1.txt │ │ ├── spanish2.txt │ │ └── spanish3.txt │ ├── mnist │ │ ├── README.md │ │ ├── digits_test.pi │ │ └── digits_train.pi │ ├── scaling │ │ ├── scaling.data │ │ ├── scaling.tar.gz │ │ ├── scaling_test.pi │ │ └── scaling_train.pi │ ├── spam_detector │ │ ├── README.md │ │ ├── TestX.csv │ │ ├── Train.csv │ │ ├── Train.txt │ │ ├── csv2fann.pi │ │ ├── spam.net │ │ ├── spambase.DOCUMENTATION │ │ ├── spambase.data │ │ ├── spambase.names │ │ ├── test.pi │ │ └── train.pi │ └── xor │ │ ├── __tmp.data │ │ ├── fann_xor.pi │ │ ├── xor.data │ │ ├── xor.net │ │ ├── xor_test.pi │ │ ├── xor_train_data.pi │ │ └── xor_train_file.pi ├── planner │ ├── 15_puzzle.pi │ ├── 15_puzzle.pi~ │ ├── farmer.pi │ ├── klotski.pi │ ├── nomystery.pi │ ├── ricochet.pi │ ├── sokoban.pi │ ├── solitaire.pi │ ├── treasure.pi │ └── water.pi ├── sat │ ├── bqueens.pi │ ├── crossword.pi │ ├── magic_square.pi │ ├── marriage_roman_sat.pi │ ├── maxClique.pi │ ├── numberlink_b.pi │ ├── queens.pi │ ├── sudoku.pi │ └── vmtl.pi ├── smt │ ├── bqueens.pi │ ├── maxClique.pi │ ├── queens.pi │ └── sudoku.pi ├── test_exs.pi └── test_exs_cp.pi ├── lib ├── basic.pi ├── common_constr.pi ├── cp.pi ├── cp_sat_mip_smt.pi ├── datetime.pi ├── io.pi ├── math.pi ├── mip.pi ├── mip_aux.pi ├── mip_smt.pi ├── nn.pi ├── ordset.pi ├── os.pi ├── picat_lib_aux.pi ├── planner.pi ├── prism.pi ├── prism_ex.pi ├── sat.pi ├── sat_mip.pi ├── sat_mip_smt.pi ├── smt.pi ├── smt_aux.pi ├── sys.pi └── util.pi └── lib2 ├── analyze_pb.pi ├── apl_util.pi ├── bv.pi ├── cg.pi ├── chmod_dir.pi ├── common_constr.pi ├── common_sat_cp.pi ├── comp_lib.pi ├── compare_objs.pi ├── conv_rsat.pi ├── count_ans.pi ├── cp_glop.pi ├── cp_small.pi ├── del_file.pi ├── extract_insts.pi ├── extract_julia_functions.pi ├── extract_solved.pi ├── extract_solved_hakan.pi ├── extract_solved_julia.pi ├── extract_timeout_julia.pi ├── extract_uncompiled.pi ├── flatten_dir.pi ├── fzn2julia.pi ├── fzn2picat.pi ├── fzn2picat_dump.pi ├── fzn2picat_maxsat.pi ├── fzn_parser.pi ├── fzn_picat_cp.pi ├── fzn_picat_sat.pi ├── fzn_tokenizer.pi ├── gen_check_all.pi ├── gen_comp_all.pi ├── gen_conv.pi ├── gen_conv_all.pi ├── gen_conv_fzn2julia.pi ├── gen_conv_fzn2picat.pi ├── gen_conv_pb2julia.pi ├── gen_conv_pb2pi.pi ├── gen_conv_xcsp2julia.pi ├── gen_conv_xcsp2picat.pi ├── gen_diff.pi ├── gen_extract_pattern.pi ├── gen_indent_all.pi ├── gen_make.pi ├── gen_makefile.pi ├── gen_run_all.pi ├── gen_run_all0.pi ├── gen_solve_all.pi ├── gen_solve_all_dfvs.pi ├── gen_solve_all_fzn.pi ├── gen_solve_all_fzn_dump.pi ├── gen_solve_all_julia.pi ├── gen_solve_all_pc.pi ├── gen_solve_all_xcsp.pi ├── gen_test_all_julia.pi ├── gen_unzip_all.pi ├── geom.pi ├── global_contiguity.pi ├── globals.pi ├── gps_utils.pi ├── graph.pi ├── grep_rec.pi ├── haskell_prelude.pi ├── json.pi ├── latex2html.pi ├── list_set.pi ├── pb.pi ├── pb2julia.pi ├── pb2pi.pi ├── picat_lib_aux.pi ├── prism.pi ├── proc_mac.pi ├── proc_mac_2.pi ├── proc_pb.pi ├── regular.pi ├── remove_c.pi ├── remove_dirs.pi ├── remove_empty_lines.pi ├── remove_stranges.pi ├── rm_incomplete.pi ├── rm_pi_jl.pi ├── set_util.pi ├── stat.pi ├── state_list.pi ├── sugar2pi.pi ├── sum_time.pi ├── tabular_runtimes.pi ├── test.pi ├── traverse_dir.pi ├── trim_lines.pi ├── uncompress_xcsp.pi ├── unzip_all.pi ├── util.pi └── utils.pi /INSTALL: -------------------------------------------------------------------------------- 1 | There are several make files in the fold "emu/" for 2 | different platforms. To make the executable for a 3 | platform, simply run the command 4 | 5 | make -f Makefile*** 6 | 7 | For example, for MacOS, type 8 | 9 | make -f Makefile.mac64 10 | 11 | The interface between Picat and SCIP, which is supported 12 | for Linux and MacOS, is not included in the default make 13 | files. To make Picat including the SCIP interface, type 14 | 15 | sh make_picat_scip_linux 16 | 17 | or 18 | 19 | sh make_picat_scip_mac 20 | 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The copyright of Picat is owned by picat-lang.org. 3 | Picat is provided, free of charge, for any purposes, 4 | including commercial ones. The C source files of Picat are 5 | covered by the Mozilla Public License, v. 2.0: 6 | 7 | http://mozilla.org/MPL/2.0/. 8 | 9 | In essence, anyone is allowed to build works, including 10 | proprietary ones, based on Picat, as long as the Source 11 | Code Form is retained. The copyright holders, developers, 12 | and distributors will not be held liable for any direct or 13 | indirect damages. 14 | -------------------------------------------------------------------------------- /doc/appendix_operators.tex: -------------------------------------------------------------------------------- 1 | \chapter{Appendix: Operators} 2 | 3 | \vspace*{2cm} 4 | 5 | \input{operators.tex} 6 | 7 | 8 | -------------------------------------------------------------------------------- /doc/get_started.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/doc/get_started.pdf -------------------------------------------------------------------------------- /doc/picat_guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/doc/picat_guide.pdf -------------------------------------------------------------------------------- /emu/Makefile: -------------------------------------------------------------------------------- 1 | MFLAGS=-DM64BITS 2 | #MFLAGS=-DM32BITS 3 | #MFLAGS=-m32 -DM32BITS 4 | 5 | #CPP = clang-16-env clang++ -DGC -DGCC -DPICAT -DSAT -DMAPLESAT $(MFLAGS) -DFANN_NO_DLL -DFANN 6 | #CC = clang-16-env clang -std=c99 -D_XOPEN_SOURCE=500 -DNSIG=256 -DGC -DGCC -DPICAT -DSAT -DMAPLESAT $(MFLAGS) -DFANN_NO_DLL -DFANN 7 | 8 | #CPP = emsdk-env emcc -DGC -DGCC -DPICAT -DSAT -DMAPLESAT $(MFLAGS) -DFANN_NO_DLL -DFANN 9 | #CC = emsdk-env emcc -DGC -DGCC -DPICAT -DSAT -DMAPLESAT $(MFLAGS) -DFANN_NO_DLL -DFANN 10 | 11 | CPP = g++ -DGC -DGCC -DPICAT -DSAT -DMAPLESAT $(MFLAGS) -DFANN_NO_DLL -DFANN 12 | CC = gcc -DGC -DGCC -DPICAT -DSAT -DMAPLESAT $(MFLAGS) -DFANN_NO_DLL -DFANN 13 | 14 | #CC = cc 15 | 16 | #CFLAGS = -O3 -Dunix -DGC -DBSD #SunOS 17 | CFLAGS = $(MFLAGS) -O3 -fno-strict-aliasing -finline-functions -fomit-frame-pointer -Dunix -DLINUX -DPOSIX #Linux,#HP 18 | #CFLAGS = -g -DNOINLINE -fno-strict-aliasing -Dunix -DLINUX -DPOSIX #Linux,#HP 19 | #CFLAGS = -O3 -Dunix -DGC -DPOSIX #HP 20 | #CFLAGS = -O3 -Dunix -DGC #Solaris,SonyNews 21 | #CFLAGS = -O3 -DWIN32 -DGC #Windows-PC 22 | #CFLAGS = -O3 -DDARWIN #MacOS X, Darwin 23 | 24 | #LGLFLAG = -Wall -DNLGLOG -DNLGLSTATS -DNDEBUG -DNLGLPICOSAT 25 | #ESPRESSO_FLAGS = $(MFLAGS) -O3 -I. -Iespresso 26 | #KISSAT_FLAGS = $(MFLAGS) -O3 -W -Wall -DNEMBEDDED -DNDEBUG -DNMETRICS -DQUIET -DNSTATISTICS -DNPROOFS 27 | 28 | LFLAGS = $(MFLAGS) -lm -lpthread 29 | 30 | include common.mak 31 | -------------------------------------------------------------------------------- /emu/Makefile.linux32: -------------------------------------------------------------------------------- 1 | CPP = i686-linux-gnu-g++-8 -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM32BITS -DFANN_NO_DLL -DFANN 2 | CC = i686-linux-gnu-gcc-8 -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM32BITS -DFANN_NO_DLL -DFANN 3 | 4 | #CC = cc 5 | 6 | #CFLAGS = -O3 -Dunix -DGC -DBSD #SunOS 7 | CFLAGS = -O3 -fno-strict-aliasing -finline-functions -fomit-frame-pointer -Dunix -DLINUX -DPOSIX #Linux,#HP 8 | #CFLAGS = -O3 -Dunix -DGC -DPOSIX #HP 9 | #CFLAGS = -O3 -Dunix -DGC #Solaris,SonyNews 10 | #CFLAGS = -O3 -DWIN32 -DGC #Windows-PC 11 | #CFLAGS = -O3 -DDARWIN #MacOS X, Darwin 12 | 13 | #LGLFLAG = -Wall -DNLGLOG -DNLGLSTATS -DNDEBUG -DNLGLPICOSAT 14 | ESPRESSO_FLAGS = -O3 -I. -Iespresso 15 | KISSAT_FLAGS = -c -O3 -W -Wall -DNEMBEDDED -DNDEBUG -DNMETRICS -DQUIET -DNSTATISTICS 16 | 17 | LFLAGS = -lm -lpthread 18 | 19 | include common.mak 20 | -------------------------------------------------------------------------------- /emu/Makefile.mingwin32: -------------------------------------------------------------------------------- 1 | EXT =.exe 2 | CPP = i686-w64-mingw32-g++ -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM32BITS -DFANN_NO_DLL -DFANN 3 | CC = i686-w64-mingw32-gcc -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM32BITS -DFANN_NO_DLL -DFANN 4 | #CC = gcc -DGC -pg -DSAT -DNO_SEMI_OPT -DGLPK -DPICAT 5 | #CC = gcc -DGCC -shared 6 | #CC = cc 7 | 8 | CFLAGS = -O3 -fno-strict-aliasing #-Dunix -DLINUX -DPOSIX -DCYGWIN #Linux,#HP 9 | #CFLAGS = -O4 -Dunix -DBSD #SunOS 10 | #CFLAGS = -O3 -fno-strict-aliasing -Dunix -DLINUX -DPOSIX -DCYGWIN #Linux,#HP 11 | #CFLAGS = -O4 -Dunix -DPOSIX #HP 12 | #CFLAGS = -O4 -Dunix #Solaris,SonyNews 13 | #CFLAGS = -O4 -DWIN32 #Windows-PC 14 | #CFLAGS = -O4 -DDARWIN #MacOS X, Darwin 15 | 16 | #LGLFLAG = -Wall -DNLGLOG -DNLGLSTATS -DNDEBUG -DNLGLPICOSAT 17 | ESPRESSO_FLAGS = -O3 -I. -Iespresso 18 | KISSAT_FLAGS = -c -O3 -W -Wall -DNEMBEDDED -DNDEBUG -DNMETRICS -DQUIET -DNSTATISTICS 19 | 20 | LFLAGS = -lm -lpthread -static-libgcc -static-libstdc++ 21 | 22 | include common.mak 23 | -------------------------------------------------------------------------------- /emu/Makefile.mingwin64: -------------------------------------------------------------------------------- 1 | EXT =.exe 2 | CPP = x86_64-w64-mingw32-g++ -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM64BITS -DFANN_NO_DLL -DFANN 3 | CC = x86_64-w64-mingw32-gcc -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM64BITS -DFANN_NO_DLL -DFANN 4 | #CC = gcc -DGC -pg -DSAT -DNO_SEMI_OPT -DGLPK -DPICAT 5 | #CC = gcc -DGCC -shared 6 | #CC = cc 7 | 8 | CFLAGS = -O3 -fno-strict-aliasing #-Dunix -DLINUX -DPOSIX -DCYGWIN #Linux,#HP 9 | #CFLAGS = -O4 -Dunix -DBSD #SunOS 10 | #CFLAGS = -O3 -fno-strict-aliasing -Dunix -DLINUX -DPOSIX -DCYGWIN #Linux,#HP 11 | #CFLAGS = -O4 -Dunix -DPOSIX #HP 12 | #CFLAGS = -O4 -Dunix #Solaris,SonyNews 13 | #CFLAGS = -O4 -DWIN32 #Windows-PC 14 | #CFLAGS = -O4 -DDARWIN #MacOS X, Darwin 15 | 16 | #LGLFLAG = -Wall -DNLGLOG -DNLGLSTATS -DNDEBUG -DNLGLPICOSAT 17 | ESPRESSO_FLAGS = -O3 -I. -Iespresso 18 | KISSAT_FLAGS = -c -O3 -W -Wall -DNEMBEDDED -DNDEBUG -DNMETRICS -DQUIET -DNSTATISTICS 19 | 20 | LFLAGS = -lm -lpthread -static-libgcc -static-libstdc++ 21 | 22 | include common.mak 23 | -------------------------------------------------------------------------------- /emu/Makefile.mingwin64-32: -------------------------------------------------------------------------------- 1 | EXT =.exe 2 | CPP = x86_64-w64-mingw32-g++ -m32 -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM32BITS -DFANN_NO_DLL -DFANN 3 | CC = x86_64-w64-mingw32-gcc -m32 -DGC -DGCC -DPICAT -DSAT -DMAPLESAT -DM32BITS -DFANN_NO_DLL -DFANN 4 | #CC = gcc -DGC -pg -DSAT -DNO_SEMI_OPT -DGLPK -DPICAT 5 | #CC = gcc -DGCC -shared 6 | #CC = cc 7 | 8 | CFLAGS = -O3 -fno-strict-aliasing #-Dunix -DLINUX -DPOSIX -DCYGWIN #Linux,#HP 9 | #CFLAGS = -O4 -Dunix -DBSD #SunOS 10 | #CFLAGS = -O3 -fno-strict-aliasing -Dunix -DLINUX -DPOSIX -DCYGWIN #Linux,#HP 11 | #CFLAGS = -O4 -Dunix -DPOSIX #HP 12 | #CFLAGS = -O4 -Dunix #Solaris,SonyNews 13 | #CFLAGS = -O4 -DWIN32 #Windows-PC 14 | #CFLAGS = -O4 -DDARWIN #MacOS X, Darwin 15 | 16 | #LGLFLAG = -Wall -DNLGLOG -DNLGLSTATS -DNDEBUG -DNLGLPICOSAT 17 | ESPRESSO_FLAGS = -O3 -I. -Iespresso 18 | KISSAT_FLAGS = -c -O3 -W -Wall -DNEMBEDDED -DNDEBUG -DNMETRICS -DQUIET -DNSTATISTICS 19 | 20 | LFLAGS = -lm -lpthread -static-libgcc -static-libstdc++ 21 | 22 | include common.mak 23 | -------------------------------------------------------------------------------- /emu/bprolog.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * File : bprolog.h 3 | * Author : Neng-Fa ZHOU Copyright (C) 1994-2022 4 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | ********************************************************************/ 9 | 10 | #include "basic.h" 11 | #include "bapi.h" 12 | #include "term.h" 13 | 14 | -------------------------------------------------------------------------------- /emu/bprolog_plc_plc.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class bprolog_plc_Plc */ 4 | 5 | #ifndef _Included_bprolog_plc_Plc 6 | #define _Included_bprolog_plc_Plc 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* Inaccessible static: oa */ 11 | /* 12 | * Class: bprolog_plc_Plc 13 | * Method: call 14 | * Signature: (Ljava/lang/String;[Ljava/lang/Object;)Z 15 | */ 16 | JNIEXPORT jboolean JNICALL Java_bprolog_plc_Plc_call 17 | (JNIEnv *, jobject, jstring, jobjectArray); 18 | 19 | /* 20 | * Class: bprolog_plc_Plc 21 | * Method: exec 22 | * Signature: (Ljava/lang/String;)Z 23 | */ 24 | JNIEXPORT jboolean JNICALL Java_bprolog_plc_Plc_exec 25 | (JNIEnv *, jclass, jstring); 26 | 27 | /* 28 | * Class: bprolog_plc_Plc 29 | * Method: startPlc 30 | * Signature: ([Ljava/lang/String;[Ljava/lang/Object;)V 31 | */ 32 | JNIEXPORT void JNICALL Java_bprolog_plc_Plc_startPlc 33 | (JNIEnv *, jclass, jobjectArray, jobjectArray); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | #endif 39 | -------------------------------------------------------------------------------- /emu/dynamic.h: -------------------------------------------------------------------------------- 1 | extern SYM_REC_PTR dollar_var; 2 | 3 | #define ALLOCATE_FROM_PAREA(ptr, size) { \ 4 | ALIGN(CHAR_PTR, curr_fence); \ 5 | if ((BPLONG_PTR)curr_fence + size >= (BPLONG_PTR)parea_water_mark) { \ 6 | int success = 0; \ 7 | if (size > parea_size) parea_size = size; \ 8 | ALLOCATE_NEW_PAREA_BLOCK(parea_size, success); \ 9 | if (success == 0) { \ 10 | ptr = NULL; \ 11 | } else { \ 12 | ptr = (BPLONG_PTR)curr_fence; \ 13 | curr_fence += sizeof(BPLONG)*size; \ 14 | } \ 15 | } else { \ 16 | ptr = (BPLONG_PTR)curr_fence; \ 17 | curr_fence += sizeof(BPLONG)*size; \ 18 | } \ 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /emu/espresso/COPYING: -------------------------------------------------------------------------------- 1 | /* Oct Tools Distribution 3.0 2 | * 3 | * Copyright (c) 1988, 1989, Regents of the University of California. 4 | * All rights reserved. 5 | * 6 | * Use and copying of this software and preparation of derivative works 7 | * based upon this software are permitted. However, any distribution of 8 | * this software or derivative works must include the above copyright 9 | * notice. 10 | * 11 | * This software is made available AS IS, and neither the Electronics 12 | * Research Laboratory or the University of California make any 13 | * warranty about the software, its performance or its conformity to 14 | * any specification. 15 | * 16 | * Suggestions, comments, or improvements are welcome and should be 17 | * addressed to: 18 | * 19 | * octtools@eros.berkeley.edu 20 | * ..!ucbvax!eros!octtools 21 | */ 22 | -------------------------------------------------------------------------------- /emu/espresso/Makefile.mac64: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -fomit-frame-pointer -arch x86_64 2 | expresso : black_white.o canonical.o cofactor.o cols.o compl.o contain.o cpu_time.o cubestr.o cvrin.o \ 3 | cvrm.o cvrmisc.o cvrout.o dominate.o equiv.o essen.o essentiality.o exact.o espresso_expand.o \ 4 | gasp.o gimpel.o globals.o hack.o indep.o irred.o map.o matrix.o mincov.o opo.o \ 5 | pair.o part.o primes.o prtime.o reduce.o rows.o set.o setc.o sharp.o sigma.o signature.o \ 6 | signature_exact.o sminterf.o solution.o sparse.o unate.o util_signature.o verify.o espresso.o 7 | -------------------------------------------------------------------------------- /emu/espresso/copyright.h: -------------------------------------------------------------------------------- 1 | #ifndef OCTTOOLS_COPYRIGHT_H 2 | #define OCTTOOLS_COPYRIGHT_H 3 | /* 4 | * Oct Tools Distribution 3.0 5 | * 6 | * Copyright (c) 1988, 1989, Regents of the University of California. 7 | * All rights reserved. 8 | * 9 | * Use and copying of this software and preparation of derivative works 10 | * based upon this software are permitted. However, any distribution of 11 | * this software or derivative works must include the above copyright 12 | * notice. 13 | * 14 | * This software is made available AS IS, and neither the Electronics 15 | * Research Laboratory or the University of California make any 16 | * warranty about the software, its performance or its conformity to 17 | * any specification. 18 | * 19 | * Suggestions, comments, or improvements are welcome and should be 20 | * addressed to: 21 | * 22 | * octtools@eros.berkeley.edu 23 | * ..!ucbvax!eros!octtools 24 | */ 25 | 26 | static char octtools_copyright[] = "Copyright (c) 1988, 1989, Regents of the University of California. All rights reserved."; 27 | #endif 28 | -------------------------------------------------------------------------------- /emu/espresso/mincov.h: -------------------------------------------------------------------------------- 1 | /* exported */ 2 | extern sm_row *sm_minimum_cover(sm_matrix *A, int *weight, int heuristic, int debug_level); 3 | -------------------------------------------------------------------------------- /emu/espresso/prtime.c: -------------------------------------------------------------------------------- 1 | /* LINTLIBRARY */ 2 | #include "port.h" 3 | #include "utility.h" 4 | 5 | /* 6 | * util_print_time -- massage a long which represents a time interval in 7 | * milliseconds, into a string suitable for output 8 | * 9 | * Hack for IBM/PC -- avoids using floating point 10 | */ 11 | 12 | char * 13 | util_print_time(long int t) 14 | { 15 | static char s[40]; 16 | 17 | (void) sprintf(s, "%ld.%02ld sec", t/1000, (t%1000)/10); 18 | return s; 19 | } 20 | -------------------------------------------------------------------------------- /emu/espresso/sminterf.c: -------------------------------------------------------------------------------- 1 | #include "espresso.h" 2 | 3 | 4 | pset 5 | do_sm_minimum_cover(pset_family A) 6 | { 7 | sm_matrix *M; 8 | sm_row *sparse_cover; 9 | sm_element *pe; 10 | pset cover; 11 | register int i, base, rownum; 12 | register unsigned val; 13 | register pset last, p; 14 | 15 | M = sm_alloc(); 16 | rownum = 0; 17 | foreach_set(A, last, p) { 18 | foreach_set_element(p, i, val, base) { 19 | (void) sm_insert(M, rownum, base); 20 | } 21 | rownum++; 22 | } 23 | 24 | sparse_cover = sm_minimum_cover(M, NIL(int), 1, 0); 25 | sm_free(M); 26 | 27 | cover = set_new(A->sf_size); 28 | sm_foreach_row_element(sparse_cover, pe) { 29 | set_insert(cover, pe->col_num); 30 | } 31 | sm_row_free(sparse_cover); 32 | 33 | return cover; 34 | } 35 | -------------------------------------------------------------------------------- /emu/espresso/utility.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_H 2 | #define UTILITY_H 3 | 4 | /* 5 | * assumes the memory manager is libmm.a 6 | * - allows malloc(0) or realloc(obj, 0) 7 | * - catches out of memory (and calls MMout_of_memory()) 8 | * - catch free(0) and realloc(0, size) in the macros 9 | */ 10 | #define NIL(type) ((type *) 0) 11 | #define ALLOC(type, num) \ 12 | ((type *) malloc(sizeof(type) * (num))) 13 | #define REALLOC(type, obj, num) \ 14 | (obj) ? ((type *) realloc((char *) obj, sizeof(type) * (num))) : \ 15 | ((type *) malloc(sizeof(type) * (num))) 16 | #define FREE(obj) \ 17 | if ((obj)) { (void) free((char *) (obj)); (obj) = 0; } 18 | 19 | extern long util_cpu_time(void); 20 | extern char *util_print_time (long t); 21 | 22 | #ifndef NIL_FN 23 | #define NIL_FN(type) ((type (*)()) 0) 24 | #endif /* NIL_FN */ 25 | 26 | #ifndef MAX 27 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 28 | #endif /* MAX */ 29 | #ifndef MIN 30 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 31 | #endif /* MIN */ 32 | #ifndef ABS 33 | #define ABS(a) ((a) > 0 ? (a) : -(a)) 34 | #endif /* ABS */ 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /emu/expand.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/emu/expand.c -------------------------------------------------------------------------------- /emu/fann/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY( include ) 2 | 3 | INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include) 4 | ADD_DEFINITIONS(-D_REENTRANT) 5 | ########### next target ############### 6 | 7 | SET(floatfann_LIB_SRCS 8 | floatfann.c 9 | ) 10 | 11 | ADD_LIBRARY(floatfann SHARED ${floatfann_LIB_SRCS}) 12 | 13 | SET_TARGET_PROPERTIES(floatfann PROPERTIES VERSION ${VERSION} SOVERSION 2 ) 14 | INSTALL(TARGETS floatfann DESTINATION ${LIB_INSTALL_DIR} ) 15 | 16 | 17 | ########### next target ############### 18 | 19 | SET(doublefann_LIB_SRCS 20 | doublefann.c 21 | ) 22 | 23 | ADD_LIBRARY(doublefann SHARED ${doublefann_LIB_SRCS}) 24 | 25 | SET_TARGET_PROPERTIES(doublefann PROPERTIES VERSION ${VERSION} SOVERSION 2 ) 26 | INSTALL(TARGETS doublefann DESTINATION ${LIB_INSTALL_DIR} ) 27 | 28 | 29 | ########### next target ############### 30 | 31 | SET(fixedfann_LIB_SRCS 32 | fixedfann.c 33 | ) 34 | 35 | ADD_LIBRARY(fixedfann SHARED ${fixedfann_LIB_SRCS}) 36 | 37 | SET_TARGET_PROPERTIES(fixedfann PROPERTIES VERSION ${VERSION} SOVERSION 2 ) 38 | INSTALL(TARGETS fixedfann DESTINATION ${LIB_INSTALL_DIR} ) 39 | 40 | 41 | ########### next target ############### 42 | 43 | SET(fann_LIB_SRCS 44 | floatfann.c 45 | ) 46 | 47 | ADD_LIBRARY(fann SHARED ${fann_LIB_SRCS}) 48 | 49 | SET_TARGET_PROPERTIES(fann PROPERTIES VERSION ${VERSION} SOVERSION 2 ) 50 | INSTALL(TARGETS fann DESTINATION ${LIB_INSTALL_DIR} ) 51 | 52 | -------------------------------------------------------------------------------- /emu/fann/src/doublefann.c: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* Easy way to allow for build of multiple binaries */ 21 | 22 | #include "config.h" 23 | #include "doublefann.h" 24 | 25 | #include "fann.c" 26 | #include "fann_io.c" 27 | #include "fann_train.c" 28 | #include "fann_train_data.c" 29 | #include "fann_error.c" 30 | #include "fann_cascade.c" 31 | #include "parallel_fann.c" 32 | -------------------------------------------------------------------------------- /emu/fann/src/fixedfann.c: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* Easy way to allow for build of multiple binaries */ 21 | 22 | #include "config.h" 23 | #include "fixedfann.h" 24 | 25 | #include "fann.c" 26 | #include "fann_io.c" 27 | #include "fann_train.c" 28 | #include "fann_train_data.c" 29 | #include "fann_error.c" 30 | #include "fann_cascade.c" 31 | -------------------------------------------------------------------------------- /emu/fann/src/floatfann.c: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* Easy way to allow for build of multiple binaries */ 21 | 22 | #include "config.h" 23 | #include "floatfann.h" 24 | 25 | #include "fann.c" 26 | #include "fann_io.c" 27 | #include "fann_train.c" 28 | #include "fann_train_data.c" 29 | #include "fann_error.c" 30 | #include "fann_cascade.c" 31 | #include "parallel_fann.c" 32 | -------------------------------------------------------------------------------- /emu/fann/src/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ########### install files ############### 2 | 3 | INSTALL_FILES( /include FILES fann.h doublefann.h fann_internal.h floatfann.h fann_data.h fixedfann.h compat_time.h fann_activation.h fann_cascade.h fann_error.h fann_train.h fann_io.h fann_cpp.h ) 4 | 5 | -------------------------------------------------------------------------------- /emu/fann/src/include/config.h: -------------------------------------------------------------------------------- 1 | /* Name of package */ 2 | /* #undef PACKAGE */ 3 | 4 | /* Version number of package */ 5 | #define VERSION "2.2.0" 6 | 7 | /* Define for the x86_64 CPU famyly */ 8 | /* #undef X86_64 */ 9 | -------------------------------------------------------------------------------- /emu/fann/src/include/doublefann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __doublefann_h__ 21 | #define __doublefann_h__ 22 | 23 | typedef double fann_type; 24 | 25 | #undef DOUBLEFANN 26 | #define DOUBLEFANN 27 | #define FANNPRINTF "%.20e" 28 | #define FANNSCANF "%le" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /emu/fann/src/include/fixedfann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __fixedfann_h__ 21 | #define __fixedfann_h__ 22 | 23 | typedef int fann_type; 24 | 25 | #undef FIXEDFANN 26 | #define FIXEDFANN 27 | #define FANNPRINTF "%d" 28 | #define FANNSCANF "%d" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /emu/fann/src/include/floatfann.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef __floatfann_h__ 21 | #define __floatfann_h__ 22 | 23 | typedef float fann_type; 24 | 25 | #undef FLOATFANN 26 | #define FLOATFANN 27 | #define FANNPRINTF "%.20e" 28 | #define FANNSCANF "%f" 29 | 30 | #define FANN_INCLUDE 31 | #include "fann.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /emu/fann/src/parallel_doublefann_cpp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* Easy way to allow for build of multiple binaries */ 21 | 22 | #ifndef DISABLE_PARALLEL_FANN 23 | #include "config.h" 24 | #include "doublefann.h" 25 | 26 | #include "parallel_fann_cpp.cpp" 27 | #endif /* DISABLE_PARALLEL_FANN */ 28 | -------------------------------------------------------------------------------- /emu/fann/src/parallel_floatfann_cpp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Fast Artificial Neural Network Library (fann) 3 | Copyright (C) 2003-2016 Steffen Nissen (steffen.fann@gmail.com) 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | /* Easy way to allow for build of multiple binaries */ 21 | 22 | #ifndef DISABLE_PARALLEL_FANN 23 | #include "config.h" 24 | #include "floatfann.h" 25 | 26 | #include "parallel_fann_cpp.cpp" 27 | #endif /* DISABLE_PARALLEL_FANN */ 28 | -------------------------------------------------------------------------------- /emu/getline.h: -------------------------------------------------------------------------------- 1 | #ifndef GETLINE_H 2 | #define GETLINE_H 3 | 4 | /* unix systems can #define POSIX to use termios, otherwise 5 | * the bsd or sysv interface will be used 6 | */ 7 | 8 | #if __STDC__ > 0 9 | #include 10 | 11 | typedef size_t (*gl_strwidth_proc)(char *); 12 | 13 | char *bp_getline(char *); /* read a line of input */ 14 | char *nogl_getline(char *); /* read a line of input */ 15 | void gl_setwidth(int); /* specify width of screen */ 16 | void gl_histadd(char *); /* adds entries to hist */ 17 | void gl_strwidth(gl_strwidth_proc); /* to bind gl_strlen */ 18 | 19 | extern int (*gl_in_hook)(char *); 20 | extern int (*gl_out_hook)(char *); 21 | extern int (*gl_tab_hook)(char *, int, int *); 22 | 23 | #else /* not __STDC__ */ 24 | 25 | char *bp_getline(); 26 | char *nogl_getline(); 27 | void gl_setwidth(); 28 | void gl_histadd(); 29 | void gl_strwidth(); 30 | 31 | extern int (*gl_in_hook)(); 32 | extern int (*gl_out_hook)(); 33 | extern int (*gl_tab_hook)(); 34 | 35 | #endif /* __STDC__ */ 36 | 37 | #endif /* GETLINE_H */ 38 | -------------------------------------------------------------------------------- /emu/kapi.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * File : kapi.h 3 | * Author : Neng-Fa ZHOU Copyright (C) 1994-2022 4 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | ********************************************************************/ 9 | 10 | /* Test Prolog terms in C */ 11 | 12 | #define PisVar(term) ISREF(term) 13 | 14 | #define PisAtom(term) ISATOM(term) 15 | 16 | #define PisInt(term) ISINT(term) 17 | 18 | #define PisLong(term) 0 19 | 20 | #define PisReal(term) ISFLOAT(term) 21 | 22 | #define PisList(term) ISLIST(term) 23 | 24 | #define PisEndList(term) ISNIL(term) 25 | 26 | #define PisAddr(term) (ISSTRUCT(term) && FOLLOW(UNTAGGED_ADDR(term)) == (BPLONG)objectRef) 27 | 28 | #define PisCompound(term) ISSTRUCT(term) 29 | 30 | #define PvalueOfInt(term) INTVAL(term) 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /emu/kissat/CONTRIBUTING: -------------------------------------------------------------------------------- 1 | At this point we want to keep complete ownership in one hand 2 | to particularly avoid any additional co-authorship claims. 3 | Thus please refrain from generating pull requests. Use the issue 4 | tracker or send email to 'armin.biere@gmail.com' instead. 5 | -------------------------------------------------------------------------------- /emu/kissat/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019-2020 Armin Biere, Johannes Kepler University Linz, Austria 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /emu/kissat/README.md: -------------------------------------------------------------------------------- 1 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 2 | [![Build Status](https://travis-ci.com/arminbiere/kissat.svg?branch=master)](https://travis-ci.com/arminbiere/kissat) 3 | 4 | The Kissat SAT Solver 5 | ===================== 6 | 7 | Kissat is a "keep it simple and clean bare metal SAT solver" written in C. 8 | It is a port of CaDiCaL back to C with improved data structures, better 9 | scheduling of inprocessing and optimized algorithms and implementation. 10 | 11 | Coincidentally "kissat" also means "cats" in Finnish. 12 | 13 | Run `./configure && make test` to configure, build and test in `build`. 14 | -------------------------------------------------------------------------------- /emu/kissat/VERSION: -------------------------------------------------------------------------------- 1 | 1.0.3 2 | -------------------------------------------------------------------------------- /emu/kissat/src/allocate.h: -------------------------------------------------------------------------------- 1 | #ifndef _allocate_h_INCLUDED 2 | #define _allocate_h_INCLUDED 3 | 4 | #include 5 | 6 | struct kissat; 7 | 8 | void *kissat_malloc (struct kissat *, size_t bytes); 9 | void kissat_free (struct kissat *, void *, size_t bytes); 10 | 11 | void *kissat_calloc (struct kissat *, size_t n, size_t size); 12 | void kissat_dealloc (struct kissat *, void *ptr, size_t n, size_t size); 13 | 14 | void *kissat_realloc (struct kissat *, void *, size_t old, size_t bytes); 15 | void *kissat_nrealloc (struct kissat *, void *, size_t o, size_t n, size_t); 16 | 17 | char *kissat_strdup (struct kissat *, const char *); 18 | void kissat_delstr (struct kissat *, char *str); 19 | 20 | #define DEALLOC(P,N) \ 21 | do { \ 22 | kissat_dealloc (solver, (P), (N), sizeof *(P)); \ 23 | } while (0) 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /emu/kissat/src/analyze.h: -------------------------------------------------------------------------------- 1 | #ifndef _analyze_h_INCLUDED 2 | #define _analyze_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct clause; 7 | struct kissat; 8 | 9 | int kissat_analyze (struct kissat *, struct clause *); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /emu/kissat/src/ands.h: -------------------------------------------------------------------------------- 1 | #ifndef _ands_h_INCLUDED 2 | #define _ands_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | 8 | bool kissat_find_and_gate (struct kissat *, unsigned lit, unsigned negative); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/application.h: -------------------------------------------------------------------------------- 1 | #ifndef _application_h_INCLUDED 2 | #define _application_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | int kissat_application (struct kissat *, int argc, char **argv); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/arena.h: -------------------------------------------------------------------------------- 1 | #ifndef _arena_h_INCLUDED 2 | #define _arena_h_INCLUDED 3 | 4 | #include "reference.h" 5 | #include "stack.h" 6 | #include "utilities.h" 7 | 8 | #define LD_MAX_ARENA ((sizeof (word) == 4) ? 28 : LD_MAX_REF) 9 | #define MAX_ARENA ((size_t)1 << LD_MAX_ARENA) 10 | 11 | // *INDENT-OFF* 12 | 13 | typedef STACK (word) arena; 14 | 15 | // *INDENT-ON* 16 | 17 | struct clause; 18 | struct kissat; 19 | 20 | reference kissat_allocate_clause (struct kissat *, size_t size); 21 | void kissat_shrink_arena (struct kissat *); 22 | 23 | #if !defined(NDEBUG) || defined(LOGGING) 24 | 25 | bool kissat_clause_in_arena (const struct kissat *, const struct clause *); 26 | 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /emu/kissat/src/array.h: -------------------------------------------------------------------------------- 1 | #ifndef _array_h_INCLUDED 2 | #define _array_h_INCLUDED 3 | 4 | #include "allocate.h" 5 | #include "stack.h" 6 | 7 | #define ARRAY(TYPE) \ 8 | struct { TYPE * begin; TYPE * end; } 9 | 10 | #define ALLOCATE_ARRAY(A,N) \ 11 | do { \ 12 | const size_t TMP_N = (N); \ 13 | (A).begin = (A).end = kissat_nalloc (solver, TMP_N, sizeof *(A).begin); \ 14 | } while (0) 15 | 16 | #define EMPTY_ARRAY EMPTY_STACK 17 | #define SIZE_ARRAY SIZE_STACK 18 | 19 | #define PUSH_ARRAY(A,E) \ 20 | do { \ 21 | *(A).end++ = (E); \ 22 | } while (0) 23 | 24 | #define REALLOCATE_ARRAY(A,O,N) \ 25 | do { \ 26 | const size_t SIZE = SIZE_ARRAY (A); \ 27 | (A).begin = kissat_nrealloc (solver, (A).begin, \ 28 | (O), (N), sizeof *(A).begin); \ 29 | (A).end = (A).begin + SIZE; \ 30 | } while (0) 31 | 32 | #define RELEASE_ARRAY(A,N) \ 33 | do { \ 34 | const size_t TMP_NIZE = (N); \ 35 | DEALLOC((A).begin, TMP_NIZE); \ 36 | } while (0) 37 | 38 | #define CLEAR_ARRAY CLEAR_STACK 39 | #define TOP_ARRAY TOP_STACK 40 | #define PEEK_ARRAY PEEK_STACK 41 | #define POKE_ARRAY POKE_STACK 42 | #define POP_ARRAY POP_STACK 43 | #define BEGIN_ARRAY BEGIN_STACK 44 | #define END_ARRAY END_STACK 45 | #define RESIZE_ARRAY RESIZE_STACK 46 | #define SET_END_OF_ARRAY SET_END_OF_STACK 47 | 48 | // *INDENT-OFF* 49 | 50 | typedef ARRAY (unsigned) unsigned_array; 51 | 52 | // *INDENT-ON* 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /emu/kissat/src/assign.h: -------------------------------------------------------------------------------- 1 | #ifndef _assign_h_INCLUDED 2 | #define _assign_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | #define DECISION UINT_MAX 7 | #define UNIT (DECISION - 1) 8 | 9 | #define ANALYZED 1 10 | #define POISONED 2 11 | #define REMOVABLE 3 12 | 13 | #define LD_MAX_LEVEL 28 14 | #define INFINITE_LEVEL UINT_MAX 15 | #define INVALID_LEVEL UINT_MAX 16 | #define MAX_LEVEL ((1u << LD_MAX_LEVEL) - 1) 17 | 18 | typedef struct assigned assigned; 19 | struct clause; 20 | 21 | struct assigned 22 | { 23 | unsigned level:LD_MAX_LEVEL; 24 | unsigned analyzed:2; 25 | bool redundant:1; 26 | bool binary:1; 27 | unsigned reason; 28 | }; 29 | 30 | #define ASSIGNED(LIT) \ 31 | (assert (VALID_INTERNAL_LITERAL (LIT)), \ 32 | solver->assigned + IDX (LIT)) 33 | 34 | #define LEVEL(LIT) \ 35 | (ASSIGNED(LIT)->level) 36 | 37 | #define REASON(LIT) \ 38 | (ASSIGNED(LIT)->reason) 39 | 40 | #ifndef INLINE_ASSIGN 41 | 42 | struct kissat; 43 | struct clause; 44 | 45 | void kissat_assign_unit (struct kissat *, unsigned lit); 46 | void kissat_assign_decision (struct kissat *, unsigned lit); 47 | 48 | void kissat_assign_binary (struct kissat *, bool, unsigned, unsigned); 49 | 50 | void kissat_assign_reference (struct kissat *, unsigned lit, 51 | reference, struct clause *); 52 | 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /emu/kissat/src/attribute.h: -------------------------------------------------------------------------------- 1 | #ifndef _attribute_h_INCLUDED 2 | #define _attribute_h_INCLUDED 3 | 4 | #define ATTRIBUTE_FORMAT(FORMAT_POSITION,VARIADIC_ARGUMENT_POSITION) \ 5 | __attribute__ ((format (printf, FORMAT_POSITION, VARIADIC_ARGUMENT_POSITION))) 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /emu/kissat/src/autarky.h: -------------------------------------------------------------------------------- 1 | #ifndef _autarky_h_INCLUDED 2 | #define _autarky_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_autarky (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/averages.c: -------------------------------------------------------------------------------- 1 | #include "internal.h" 2 | 3 | void 4 | kissat_init_averages (kissat * solver, averages * averages) 5 | { 6 | if (averages->initialized) 7 | return; 8 | #define INIT_EMA(EMA,WINDOW) \ 9 | kissat_init_smooth (solver, &averages->EMA, WINDOW, #EMA) 10 | INIT_EMA (level, GET_OPTION (emaslow)); 11 | INIT_EMA (size, GET_OPTION (emaslow)); 12 | INIT_EMA (fast_glue, GET_OPTION (emafast)); 13 | INIT_EMA (slow_glue, GET_OPTION (emaslow)); 14 | INIT_EMA (trail, GET_OPTION (emaslow)); 15 | averages->initialized = true; 16 | } 17 | -------------------------------------------------------------------------------- /emu/kissat/src/averages.h: -------------------------------------------------------------------------------- 1 | #ifndef _averages_h_INCLUDED 2 | #define _averages_h_INCLUDED 3 | 4 | #include "smooth.h" 5 | 6 | #include "kissat_bool.h" 7 | 8 | typedef struct averages averages; 9 | 10 | struct averages 11 | { 12 | bool initialized; 13 | smooth level, size, fast_glue, slow_glue, trail; 14 | }; 15 | 16 | struct kissat; 17 | 18 | void kissat_init_averages (struct kissat *, averages *); 19 | 20 | #define AVERAGES (solver->averages[solver->stable]) 21 | 22 | #define EMA(NAME) (AVERAGES.NAME) 23 | 24 | #define AVERAGE(NAME) (EMA(NAME).value) 25 | 26 | #define UPDATE(NAME,VALUE) \ 27 | kissat_update_smooth (solver, &EMA(NAME), VALUE) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /emu/kissat/src/backbone.h: -------------------------------------------------------------------------------- 1 | #ifndef _backbone_h_INCLUDED 2 | #define _backbone_h_INCLUDED 3 | 4 | struct kissat; 5 | void kissat_binary_clauses_backbone (struct kissat *); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /emu/kissat/src/backtrack.h: -------------------------------------------------------------------------------- 1 | #ifndef _backtrack_h_INCLUDED 2 | #define _backtrack_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_backtrack (struct kissat *, unsigned level); 7 | void kissat_backtrack_propagate_and_flush_trail (struct kissat *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/backward.h: -------------------------------------------------------------------------------- 1 | #ifndef _backward_h_INCLUDED 2 | #define _backward_h_INCLUDED 3 | 4 | #include "reference.h" 5 | 6 | #include "kissat_bool.h" 7 | 8 | struct kissat; 9 | 10 | bool kissat_backward_subsume_temporary (struct kissat *, reference ignore); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /emu/kissat/src/build.c: -------------------------------------------------------------------------------- 1 | #include "build.h" 2 | #include "colors.h" 3 | #include "print.h" 4 | #include "kissat.h" 5 | 6 | #include 7 | 8 | const char * 9 | kissat_id (void) 10 | { 11 | return ID; 12 | } 13 | 14 | const char * 15 | kissat_version (void) 16 | { 17 | return VERSION; 18 | } 19 | 20 | const char * 21 | kissat_compiler (void) 22 | { 23 | return COMPILER; 24 | } 25 | 26 | #define PREFIX(COLORS) \ 27 | do { \ 28 | if (prefix) \ 29 | fputs (prefix, stdout); \ 30 | COLOR (COLORS); \ 31 | } while (0) 32 | 33 | #define NL() \ 34 | do { \ 35 | fputs ("\n", stdout); \ 36 | COLOR (NORMAL); \ 37 | } while (0) 38 | 39 | void 40 | kissat_banner (const char *prefix, const char *name) 41 | { 42 | TERMINAL (stdout, 1); 43 | if (!prefix) 44 | connected_to_terminal = false; 45 | 46 | PREFIX (BOLD MAGENTA); 47 | printf ("%s", name); 48 | NL (); 49 | 50 | PREFIX (BOLD MAGENTA); 51 | printf ("Copyright (c) 2019-2020 Armin Biere JKU Linz"); 52 | NL (); 53 | 54 | if (prefix) 55 | { 56 | PREFIX (""); 57 | NL (); 58 | } 59 | 60 | PREFIX (MAGENTA); 61 | if (ID) 62 | printf ("Version %s %s", VERSION, ID); 63 | else 64 | printf ("Version %s", VERSION); 65 | NL (); 66 | 67 | PREFIX (MAGENTA); 68 | printf ("%s", COMPILER); 69 | NL (); 70 | 71 | PREFIX (MAGENTA); 72 | printf ("%s", BUILD); 73 | NL (); 74 | 75 | fflush (stdout); 76 | } 77 | -------------------------------------------------------------------------------- /emu/kissat/src/build.h: -------------------------------------------------------------------------------- 1 | #define VERSION "1.0.3" 2 | #define COMPILER "gcc (GCC) 9.2.0 -W -Wall -O3 -DNEMBEDDED -DNDEBUG -DNMETRICS -DQUIET -DNSTATISTICS" 3 | #define ID "unknown" 4 | #define BUILD "Sun, Sep 19, 2021 11:57:39 AM CYGWIN_NT-10.0 DESKTOP-A4UEIAT 3.1.4(0.340/5/3) x86_64" 5 | #define DIR "/cygdrive/c/Picat/emu/kissat_orig/build" 6 | -------------------------------------------------------------------------------- /emu/kissat/src/bump.h: -------------------------------------------------------------------------------- 1 | #ifndef _bump_h_INCLUDED 2 | #define _bump_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_bump_variables (struct kissat *); 7 | 8 | #define MAX_SCORE 1e150 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/clueue.h: -------------------------------------------------------------------------------- 1 | #ifndef _clueue_h_INCLUDED 2 | #define _clueue_h_INCLUDED 3 | 4 | #include "reference.h" 5 | 6 | #include 7 | 8 | typedef struct clueue clueue; 9 | 10 | struct clueue 11 | { 12 | unsigned size, next; 13 | reference *elements; 14 | }; 15 | 16 | struct kissat; 17 | 18 | void kissat_clear_clueue (struct kissat *, clueue *); 19 | void kissat_init_clueue (struct kissat *, clueue *, unsigned size); 20 | void kissat_release_clueue (struct kissat *, clueue *); 21 | 22 | static inline void 23 | kissat_push_clueue (clueue * clueue, reference element) 24 | { 25 | if (!clueue->size) 26 | return; 27 | assert (clueue->next < clueue->size); 28 | clueue->elements[clueue->next++] = element; 29 | if (clueue->next == clueue->size) 30 | clueue->next = 0; 31 | } 32 | 33 | void kissat_eager_subsume (struct kissat *); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /emu/kissat/src/collect.h: -------------------------------------------------------------------------------- 1 | #ifndef _collect_h_INCLUDED 2 | #define _collect_h_INCLUDED 3 | 4 | #include "internal.h" 5 | 6 | void kissat_dense_collect (struct kissat *); 7 | void kissat_sparse_collect (struct kissat *, bool compact, reference start); 8 | 9 | static inline void 10 | kissat_defrag_watches_if_needed (kissat * solver) 11 | { 12 | const size_t size = SIZE_STACK (solver->vectors.stack); 13 | const size_t size_limit = GET_OPTION (defragsize); 14 | if (size <= size_limit) 15 | return; 16 | 17 | const size_t usable = solver->vectors.usable; 18 | const size_t usable_limit = (size * GET_OPTION (defraglim)) / 100; 19 | if (usable <= usable_limit) 20 | return; 21 | 22 | INC (vectors_defrags_needed); 23 | kissat_defrag_vectors (solver, &solver->vectors, LITS, solver->watches); 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /emu/kissat/src/colors.c: -------------------------------------------------------------------------------- 1 | #include "colors.h" 2 | 3 | #include 4 | 5 | int kissat_is_terminal[3] = { 0, -1, -1 }; 6 | 7 | int 8 | kissat_initialize_terminal (int fd) 9 | { 10 | assert (fd == 1 || fd == 2); 11 | assert (kissat_is_terminal[fd] < 0); 12 | return kissat_is_terminal[fd] = isatty (fd); 13 | } 14 | 15 | void 16 | kissat_force_colors (void) 17 | { 18 | kissat_is_terminal[1] = kissat_is_terminal[2] = 1; 19 | } 20 | 21 | void 22 | kissat_force_no_colors (void) 23 | { 24 | kissat_is_terminal[1] = kissat_is_terminal[2] = 0; 25 | } 26 | -------------------------------------------------------------------------------- /emu/kissat/src/compact.h: -------------------------------------------------------------------------------- 1 | #ifndef _compact_h_INCLUDED 2 | #define _compact_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | unsigned kissat_compact_literals (struct kissat *, unsigned *mfixed_ptr); 7 | void kissat_finalize_compacting (struct kissat *, 8 | unsigned vars, unsigned mfixed); 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/config.c: -------------------------------------------------------------------------------- 1 | #ifndef NOPTIONS 2 | 3 | #include "config.h" 4 | #include "kissat.h" 5 | #include "options.h" 6 | 7 | #include 8 | #include 9 | 10 | bool 11 | kissat_has_configuration (const char *name) 12 | { 13 | if (!strcmp (name, "default")) 14 | return true; 15 | if (!strcmp (name, "sat")) 16 | return true; 17 | if (!strcmp (name, "unsat")) 18 | return true; 19 | return false; 20 | } 21 | 22 | void 23 | kissat_configuration_usage (void) 24 | { 25 | const char *fmt = " --%-24s %s\n"; 26 | printf (fmt, "default", "default configuration"); 27 | printf (fmt, "sat", "target satisfiable instances ('--target=2')"); 28 | printf (fmt, "unsat", "target unsatisfiable instances ('--stable=0')"); 29 | } 30 | 31 | void 32 | kissat_set_configuration (kissat * solver, const char *name) 33 | { 34 | if (!strcmp (name, "default")) 35 | return; 36 | if (!strcmp (name, "sat")) 37 | { 38 | kissat_set_option (solver, "target", TARGET_SAT); 39 | return; 40 | } 41 | if (!strcmp (name, "unsat")) 42 | { 43 | kissat_set_option (solver, "stable", STABLE_UNSAT); 44 | return; 45 | } 46 | } 47 | 48 | #else 49 | int kissat_config_dummy_to_avoid_warning; 50 | #endif 51 | -------------------------------------------------------------------------------- /emu/kissat/src/config.h: -------------------------------------------------------------------------------- 1 | #ifndef NOPTIONS 2 | #ifndef _config_h_INCLUDED 3 | #define _config_h_INCLUDED 4 | 5 | #include "kissat_bool.h" 6 | 7 | struct kissat; 8 | 9 | void kissat_configuration_usage (void); 10 | bool kissat_has_configuration (const char *); 11 | 12 | #endif 13 | #endif 14 | -------------------------------------------------------------------------------- /emu/kissat/src/configure: -------------------------------------------------------------------------------- 1 | ../configure -------------------------------------------------------------------------------- /emu/kissat/src/cover.h: -------------------------------------------------------------------------------- 1 | #ifndef _cover_h_INCLUDED 2 | #define _cover_h_INCLUDED 3 | 4 | #include 5 | #include 6 | 7 | #define COVER(COND) \ 8 | ( \ 9 | (COND) \ 10 | ? \ 11 | \ 12 | ( \ 13 | fflush (stdout), \ 14 | fprintf (stderr, "%s:%ld: %s: Coverage goal `%s' reached.\n", \ 15 | __FILE__, (long) __LINE__, __func__, #COND), \ 16 | abort (), \ 17 | (void) 0 \ 18 | ) \ 19 | : \ 20 | (void) 0 \ 21 | ) 22 | 23 | #ifdef COVERAGE 24 | #define FLUSH_COVERAGE() \ 25 | do { \ 26 | void __gcov_flush (void); \ 27 | __gcov_flush (); \ 28 | } while (0) 29 | #else 30 | #define FLUSH_COVERAGE() do { } while (0) 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /emu/kissat/src/decide.h: -------------------------------------------------------------------------------- 1 | #ifndef _decide_h_INCLUDED 2 | #define _decide_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_decide (struct kissat *); 7 | void kissat_internal_assume (struct kissat *, unsigned lit); 8 | unsigned kissat_next_decision_variable (struct kissat *); 9 | 10 | #define INITIAL_PHASE (GET_OPTION (phase) ? 1 : -1) 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /emu/kissat/src/deduce.h: -------------------------------------------------------------------------------- 1 | #ifndef _deduce_h_INCLUDED 2 | #define _deduce_h_INCLUDED 3 | 4 | struct clause; 5 | struct kissat; 6 | 7 | struct clause *kissat_deduce_first_uip_clause (struct kissat *, 8 | struct clause *); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/definition.h: -------------------------------------------------------------------------------- 1 | #ifndef _definition_h_INCLUDED 2 | #define _definition_h_INCLUDED 3 | 4 | #include 5 | 6 | struct kissat; 7 | 8 | bool kissat_find_definition (struct kissat *, unsigned lit); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/dense.h: -------------------------------------------------------------------------------- 1 | #ifndef _dense_h_INCLUDED 2 | #define _dense_h_INCLUDED 3 | 4 | #include "watch.h" 5 | 6 | void kissat_enter_dense_mode (struct kissat *, 7 | litpairs * saved_irredundant_binary_clauses, 8 | litwatches * saved_redundant_binary_clauses); 9 | 10 | void kissat_resume_sparse_mode (struct kissat *, bool flush_eliminated, 11 | litpairs *, litwatches *); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /emu/kissat/src/dominate.h: -------------------------------------------------------------------------------- 1 | #ifndef _dominate_h_INCLUDED 2 | #define _dominate_h_INCLUDED 3 | 4 | struct kissat; 5 | struct clause; 6 | 7 | unsigned kissat_find_dominator (struct kissat *, unsigned, struct clause *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/eliminate.h: -------------------------------------------------------------------------------- 1 | #ifndef _eliminate_hpp_INCLUDED 2 | #define _eliminate_hpp_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | struct clause; 8 | 9 | void kissat_update_after_removing_variable (struct kissat *, unsigned); 10 | void kissat_update_after_removing_clause (struct kissat *, struct clause *, 11 | unsigned except); 12 | 13 | void kissat_flush_units_while_connected (struct kissat *); 14 | 15 | bool kissat_eliminating (struct kissat *); 16 | int kissat_eliminate (struct kissat *); 17 | 18 | void kissat_eliminate_binary (struct kissat *, unsigned, unsigned); 19 | void kissat_eliminate_clause (struct kissat *, struct clause *, unsigned); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /emu/kissat/src/endianess.h: -------------------------------------------------------------------------------- 1 | #ifndef _endianess_h_INCLUDED 2 | #define _endianess_h_INCLUDED 3 | 4 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 5 | #define KISSAT_IS_BIG_ENDIAN 6 | #endif 7 | 8 | #endif 9 | 10 | -------------------------------------------------------------------------------- /emu/kissat/src/endianness.h: -------------------------------------------------------------------------------- 1 | #ifndef _endianness_h_INCLUDED 2 | #define _endianness_h_INCLUDED 3 | 4 | #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 5 | #define KISSAT_IS_BIG_ENDIAN 6 | #endif 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/equivalences.c: -------------------------------------------------------------------------------- 1 | #include "internal.h" 2 | #include "gates.h" 3 | #include "logging.h" 4 | 5 | bool 6 | kissat_find_equivalence_gate (kissat * solver, unsigned lit) 7 | { 8 | if (!GET_OPTION (equivalences)) 9 | return false; 10 | if (!kissat_mark_binaries (solver, lit)) 11 | return false; 12 | value *marks = solver->marks; 13 | unsigned not_lit = NOT (lit); 14 | watches *watches = &WATCHES (not_lit); 15 | unsigned replace = INVALID_LIT; 16 | for (all_binary_large_watches (watch, *watches)) 17 | { 18 | if (!watch.type.binary) 19 | continue; 20 | const unsigned other = watch.binary.lit; 21 | const unsigned not_other = NOT (other); 22 | if (!marks[not_other]) 23 | continue; 24 | replace = other; 25 | break; 26 | } 27 | kissat_unmark_binaries (solver, lit); 28 | if (replace == INVALID_LIT) 29 | return false; 30 | LOG ("found equivalence gate %s = %s", LOGLIT (lit), LOGLIT (replace)); 31 | 32 | const watch watch1 = kissat_binary_watch (replace, false, false); 33 | PUSH_STACK (solver->gates[1], watch1); 34 | 35 | const watch watch0 = kissat_binary_watch (NOT (replace), false, false); 36 | PUSH_STACK (solver->gates[0], watch0); 37 | solver->gate_eliminated = GATE_ELIMINATED (equivalences); 38 | return true; 39 | } 40 | -------------------------------------------------------------------------------- /emu/kissat/src/equivalences.h: -------------------------------------------------------------------------------- 1 | #ifndef _equivs_h_INCLUDED 2 | #define _equivs_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | 8 | bool kissat_find_equivalence_gate (struct kissat *, unsigned lit); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/error.h: -------------------------------------------------------------------------------- 1 | #ifndef _error_h_INCLUDED 2 | #define _error_h_INCLUDED 3 | 4 | void kissat_error (const char *fmt, ...); 5 | void kissat_fatal (const char *fmt, ...); 6 | 7 | void kissat_fatal_message_start (void); 8 | 9 | void kissat_call_function_instead_of_abort (void (*)(void)); 10 | void kissat_abort (); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /emu/kissat/src/extend.h: -------------------------------------------------------------------------------- 1 | #ifndef _extend_h_INCLUDED 2 | #define _extend_h_INCLUDED 3 | 4 | #include "stack.h" 5 | #include "utilities.h" 6 | 7 | typedef struct extension extension; 8 | 9 | struct extension 10 | { 11 | signed int lit:31; 12 | bool blocking:1; 13 | }; 14 | 15 | // *INDENT-OFF* 16 | typedef STACK (extension) extensions; 17 | // *INDENT-ON* 18 | 19 | static inline extension 20 | kissat_extension (bool blocking, int lit) 21 | { 22 | assert (ABS (lit) < (1 << 30)); 23 | extension res; 24 | res.blocking = blocking; 25 | res.lit = lit; 26 | return res; 27 | } 28 | 29 | struct kissat; 30 | 31 | void kissat_extend (struct kissat *solver); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /emu/kissat/src/failed.h: -------------------------------------------------------------------------------- 1 | #ifndef _failed_h_INCLUDED 2 | #define _failed_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_failed_literal_probing (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/fastassign.h: -------------------------------------------------------------------------------- 1 | #ifndef _fastassign_h_INCLUDED 2 | #define _fastassign_h_INCLUDED 3 | 4 | #define FAST_ASSIGN 5 | 6 | #include "inline.h" 7 | #include "inlineassign.h" 8 | 9 | static inline void 10 | kissat_fast_binary_assign (kissat * solver, 11 | const bool probing, const unsigned level, 12 | value * values, assigned * assigned, 13 | bool redundant, unsigned lit, unsigned other) 14 | { 15 | kissat_fast_assign (solver, probing, level, values, assigned, 16 | true, redundant, lit, other); 17 | LOGBINARY (lit, other, "assign %s %s reason", 18 | LOGLIT (lit), redundant ? "redundant" : "irredundant"); 19 | } 20 | 21 | static inline void 22 | kissat_fast_assign_reference (kissat * solver, 23 | value * values, assigned * assigned, 24 | unsigned lit, reference ref, clause * reason) 25 | { 26 | assert (reason == kissat_dereference_clause (solver, ref)); 27 | const unsigned level = 28 | kissat_assignment_level (solver, values, assigned, lit, reason); 29 | assert (level <= solver->level); 30 | assert (ref != DECISION_REASON); 31 | assert (ref != UNIT_REASON); 32 | kissat_fast_assign (solver, solver->probing, level, 33 | values, assigned, false, false, lit, ref); 34 | LOGREF (ref, "assign %s reason", LOGLIT (lit)); 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /emu/kissat/src/flags.h: -------------------------------------------------------------------------------- 1 | #ifndef _flags_h_INCLUDED 2 | #define _flags_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | typedef struct flags flags; 7 | 8 | struct flags 9 | { 10 | bool active:1; 11 | bool eliminate:1; 12 | bool eliminated:1; 13 | bool fixed:1; 14 | bool probe:1; 15 | bool subsume:1; 16 | }; 17 | 18 | #define FLAGS(IDX) \ 19 | (assert ((IDX) < VARS), (solver->flags + (IDX))) 20 | 21 | #define ACTIVE(IDX) (FLAGS(IDX)->active) 22 | #define ELIMINATED(IDX) (FLAGS(IDX)->eliminated) 23 | 24 | struct kissat; 25 | 26 | void kissat_activate_literal (struct kissat *, unsigned); 27 | void kissat_activate_literals (struct kissat *, unsigned, unsigned *); 28 | 29 | void kissat_mark_eliminated_variable (struct kissat *, unsigned idx); 30 | void kissat_mark_fixed_literal (struct kissat *, unsigned lit); 31 | void kissat_mark_autarkic_literal (struct kissat *, unsigned lit); 32 | 33 | void kissat_mark_added_literals (struct kissat *, unsigned, unsigned *); 34 | void kissat_mark_removed_literals (struct kissat *, unsigned, unsigned *); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /emu/kissat/src/format.h: -------------------------------------------------------------------------------- 1 | #ifndef _format_h_INCLUDED 2 | #define _format_h_INCLUDED 3 | 4 | #include "utilities.h" 5 | 6 | #include "kissat_bool.h" 7 | #include 8 | 9 | #define NUM_FORMAT_STRINGS 4 10 | #define FORMAT_STRING_SIZE 64 11 | 12 | typedef struct format format; 13 | 14 | struct format 15 | { 16 | unsigned pos; 17 | char str[NUM_FORMAT_STRINGS][FORMAT_STRING_SIZE]; 18 | }; 19 | 20 | char *kissat_next_format_string (format *); 21 | 22 | const char *kissat_format_bytes (format *, uint64_t bytes); 23 | const char *kissat_format_count (format *, uint64_t); 24 | const char *kissat_format_ordinal (format *, uint64_t); 25 | const char *kissat_format_signs (format *, unsigned size, word); 26 | const char *kissat_format_time (format *, uint64_t seconds); 27 | const char *kissat_format_value (format *, bool boolean, int value); 28 | 29 | #define FORMAT_BYTES(BYTES) \ 30 | kissat_format_bytes (&solver->format, BYTES) 31 | 32 | #define FORMAT_COUNT(WORD) \ 33 | kissat_format_count (&solver->format, WORD) 34 | 35 | #define FORMAT_ORDINAL(WORD) \ 36 | kissat_format_ordinal (&solver->format, WORD) 37 | 38 | #define FORMAT_SIGNS(SIZE, SIGNS) \ 39 | kissat_format_signs (&solver->format, SIZE, SIGNS) 40 | 41 | #define FORMAT_TIME(SECONDS) \ 42 | kissat_format_time (&solver->format, SECONDS) 43 | 44 | #define FORMAT_VALUE(BOOLEAN,VALUE) \ 45 | kissat_format_value (&solver->format, BOOLEAN, VALUE) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /emu/kissat/src/forward.h: -------------------------------------------------------------------------------- 1 | #ifndef _forward_h_INCLUDED 2 | #define _forward_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | bool kissat_forward_subsume_temporary (struct kissat *); 7 | void kissat_forward_subsume_during_elimination (struct kissat *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/frames.c: -------------------------------------------------------------------------------- 1 | #include "allocate.h" 2 | #include "internal.h" 3 | 4 | void 5 | kissat_push_frame (kissat * solver, unsigned decision) 6 | { 7 | const size_t trail = SIZE_STACK (solver->trail); 8 | assert (trail <= MAX_TRAIL); 9 | frame frame; 10 | frame.decision = decision; 11 | frame.trail = trail; 12 | frame.promote = false; 13 | frame.used = 0; 14 | PUSH_STACK (solver->frames, frame); 15 | } 16 | -------------------------------------------------------------------------------- /emu/kissat/src/frames.h: -------------------------------------------------------------------------------- 1 | #ifndef _frames_h_INCLUDED 2 | #define _frames_h_INCLUDED 3 | 4 | #include "literal.h" 5 | #include "stack.h" 6 | 7 | #include "kissat_bool.h" 8 | 9 | typedef struct frame frame; 10 | 11 | #define LD_MAX_TRAIL LD_MAX_VAR 12 | #define MAX_TRAIL ((1u<frames, (LEVEL))) 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /emu/kissat/src/gates.h: -------------------------------------------------------------------------------- 1 | #ifndef _gates_h_INCLUDED 2 | #define _gates_h_INCLUDED 3 | 4 | #include 5 | #include "kissat_bool.h" 6 | 7 | struct kissat; 8 | struct clause; 9 | 10 | bool kissat_find_gates (struct kissat *, unsigned lit); 11 | void kissat_get_antecedents (struct kissat *, unsigned lit); 12 | 13 | size_t kissat_mark_binaries (struct kissat *, unsigned lit); 14 | void kissat_unmark_binaries (struct kissat *, unsigned lit); 15 | 16 | #ifdef NMETRICS 17 | #define GATE_ELIMINATED(...) true 18 | #else 19 | #define GATE_ELIMINATED(NAME) (&solver->statistics.NAME ## _eliminated) 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /emu/kissat/src/gen_make.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir("."), 5 | foreach (F in Fs, append(MainStr,".c",F)) 6 | printf("kis_%s.o : kissat/src/%s.c \n",MainStr,MainStr), 7 | printf("\t$(CC) $(KISSAT_FLAGS) -o kis_%s.o kissat/src/%s.c\n",MainStr,MainStr) 8 | end. 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /emu/kissat/src/gen_o.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir("."), 5 | C = 1, 6 | print(" "), 7 | foreach (F in Fs, append(MainStr,".c",F)) 8 | printf(" kis_%s.o",MainStr), 9 | C := C+1, 10 | if (C mod 5 == 0) then 11 | println("\\"), 12 | print(" ") 13 | end 14 | end. 15 | -------------------------------------------------------------------------------- /emu/kissat/src/handle.h: -------------------------------------------------------------------------------- 1 | #ifndef _handle_h_INCLUDED 2 | #define _handle_h_INCLUDED 3 | 4 | void kissat_init_signal_handler (void (*handler) (int)); 5 | void kissat_reset_signal_handler (void); 6 | 7 | void kissat_init_alarm (void (*handler) (void)); 8 | void kissat_reset_alarm (void); 9 | 10 | const char *kissat_signal_name (int sig); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /emu/kissat/src/ifthenelse.h: -------------------------------------------------------------------------------- 1 | #ifndef _ifthenelse_h_INCLUDED 2 | #define _ifthenelse_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | 8 | bool kissat_find_if_then_else_gate (struct kissat *, 9 | unsigned lit, unsigned negative); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /emu/kissat/src/import.h: -------------------------------------------------------------------------------- 1 | #ifndef _import_h_INLCUDED 2 | #define _import_h_INLCUDED 3 | 4 | struct kissat; 5 | 6 | unsigned kissat_import_literal (struct kissat *solver, int lit); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/inlineframes.h: -------------------------------------------------------------------------------- 1 | #ifndef _inlineframes_h_INCLUDEDd 2 | #define _inlineframes_h_INCLUDEDd 3 | 4 | #include "allocate.h" 5 | #include "internal.h" 6 | 7 | static inline void 8 | kissat_push_frame (kissat * solver, unsigned decision) 9 | { 10 | assert (!solver->level || decision != UINT_MAX); 11 | const size_t trail = SIZE_ARRAY (solver->trail); 12 | frame frame; 13 | frame.decision = decision; 14 | frame.promote = false; 15 | frame.trail = trail; 16 | frame.used = 0; 17 | PUSH_STACK (solver->frames, frame); 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /emu/kissat/src/kissat.h: -------------------------------------------------------------------------------- 1 | #ifndef _kissat_h_INCLUDED 2 | #define _kissat_h_INCLUDED 3 | 4 | typedef struct kissat kissat; 5 | 6 | // Default (partial) IPASIR interface. 7 | 8 | const char *kissat_signature (void); 9 | kissat *kissat_init (void); 10 | /* 11 | void kissat_alarm_handler (void); 12 | void kissat_signal_handler (int sig); 13 | void kissat_init_alarm (void (*handler) (void)); 14 | void kissat_init_signal_handler (void (*h) (int sig)); 15 | */ 16 | void kissat_add (kissat * solver, int lit); 17 | int kissat_solve (kissat * solver); 18 | void kissat_terminate (kissat * solver); 19 | int kissat_value (kissat * solver, int lit); 20 | void kissat_release (kissat * solver); 21 | 22 | void kissat_set_terminate (kissat * solver, 23 | void *state, int (*terminate) (void *state)); 24 | 25 | // Additional API functions. 26 | 27 | void kissat_reserve (kissat * solver, int max_var); 28 | 29 | const char *kissat_id (void); 30 | const char *kissat_version (void); 31 | const char *kissat_compiler (void); 32 | 33 | void kissat_banner (const char *line_prefix, const char *name_of_app); 34 | 35 | int kissat_get_option (kissat * solver, const char *name); 36 | int kissat_set_option (kissat * solver, const char *name, int new_value); 37 | 38 | void kissat_set_configuration (kissat * solver, const char *name); 39 | 40 | void kissat_set_conflict_limit (kissat * solver, unsigned); 41 | void kissat_set_decision_limit (kissat * solver, unsigned); 42 | 43 | void kissat_print_statistics (kissat * solver); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /emu/kissat/src/kissat_bool.h: -------------------------------------------------------------------------------- 1 | #ifndef kissat_bool_h_INCLUDED 2 | #define kissat_bool_h_INCLUDED 3 | #ifdef WIN32 4 | typedef unsigned bool; 5 | #define false 0 6 | #define true 1 7 | #else 8 | #include 9 | #endif 10 | #endif // kissat_bool -------------------------------------------------------------------------------- /emu/kissat/src/learn.h: -------------------------------------------------------------------------------- 1 | #ifndef _learn_h_INCLUDED 2 | #define _learn_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_learn_clause (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/literal.h: -------------------------------------------------------------------------------- 1 | #ifndef _literal_h_INCLUDED 2 | #define _literal_h_INCLUDED 3 | 4 | #include 5 | 6 | #define LD_MAX_VAR 28 7 | 8 | #define EXTERNAL_MAX_VAR ((1<> 1)) 26 | 27 | #define LIT(IDX) \ 28 | (assert ((IDX) < VARS), ((IDX) << 1)) 29 | 30 | #define NOT(LIT) \ 31 | (assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) ^ 1u)) 32 | 33 | #define NEGATED(LIT) \ 34 | (assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) & 1u)) 35 | 36 | #define STRIP(LIT) \ 37 | (assert (VALID_INTERNAL_LITERAL (LIT)), ((LIT) & ~1u)) 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /emu/kissat/src/main.c: -------------------------------------------------------------------------------- 1 | #include "application.h" 2 | #include "cover.h" 3 | #include "handle.h" 4 | #include "kissat.h" 5 | #include "print.h" 6 | 7 | #include 8 | #include "kissat_bool.h" 9 | 10 | static kissat *solver; 11 | 12 | // *INDENT-OFF* 13 | 14 | static void 15 | kissat_signal_handler (int sig) 16 | { 17 | assert (solver); 18 | kissat_signal (solver, "caught", sig); 19 | kissat_print_statistics (solver); 20 | kissat_signal (solver, "raising", sig); 21 | #ifdef QUIET 22 | (void) sig; 23 | #endif 24 | FLUSH_COVERAGE (); } // Keep this '}' in the same line! 25 | 26 | // *INDENT-ON* 27 | 28 | static volatile bool ignore_alarm = false; 29 | 30 | static void 31 | kissat_alarm_handler (void) 32 | { 33 | if (ignore_alarm) 34 | return; 35 | assert (solver); 36 | kissat_terminate (solver); 37 | } 38 | 39 | #ifndef NDEBUG 40 | extern int dump (kissat *); 41 | #endif 42 | 43 | #include "random.h" 44 | #include "error.h" 45 | #include 46 | 47 | /* 48 | int 49 | main (int argc, char **argv) 50 | { 51 | int res; 52 | solver = kissat_init (); 53 | kissat_init_alarm (kissat_alarm_handler); 54 | kissat_init_signal_handler (kissat_signal_handler); 55 | res = kissat_application (solver, argc, argv); 56 | kissat_reset_signal_handler (); 57 | ignore_alarm = true; 58 | kissat_reset_alarm (); 59 | kissat_release (solver); 60 | #ifndef NDEBUG 61 | if (!res) 62 | return dump (0); 63 | #endif 64 | return res; 65 | } 66 | */ 67 | -------------------------------------------------------------------------------- /emu/kissat/src/minimize.h: -------------------------------------------------------------------------------- 1 | #ifndef _minimize_h_INCLUDED 2 | #define _minimize_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_minimize_clause (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/mode.h: -------------------------------------------------------------------------------- 1 | #ifndef _mode_h_INCLUDED 2 | #define _mode_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | typedef struct mode mode; 7 | 8 | struct mode 9 | { 10 | uint64_t ticks; 11 | #ifndef QUIET 12 | double entered; 13 | uint64_t conflicts; 14 | #ifndef NMETRICS 15 | uint64_t propagations; 16 | uint64_t visits; 17 | #endif 18 | #endif 19 | }; 20 | 21 | void kissat_switch_search_mode (struct kissat *); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /emu/kissat/src/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef _parse_h_INCLUDED 2 | #define _parse_h_INCLUDED 3 | 4 | #include "file.h" 5 | 6 | enum strictness 7 | { 8 | RELAXED_PARSING = 0, 9 | NORMAL_PARSING = 1, 10 | PEDANTIC_PARSING = 2, 11 | }; 12 | 13 | typedef enum strictness strictness; 14 | 15 | const char *kissat_parse_dimacs (struct kissat *, strictness, file *, 16 | uint64_t * linenoptr, int *max_var_ptr); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /emu/kissat/src/phases.c: -------------------------------------------------------------------------------- 1 | #include "internal.h" 2 | #include "logging.h" 3 | 4 | void 5 | kissat_save_target_phases (kissat * solver) 6 | { 7 | LOG ("saving %u target values", LITS); 8 | const value *v = solver->values; 9 | for (all_phases (p)) 10 | p->target = *v, v += 2; 11 | assert (v == solver->values + LITS); 12 | } 13 | 14 | void 15 | kissat_clear_target_phases (kissat * solver) 16 | { 17 | LOG ("clearing %u target values", LITS); 18 | const value *v = solver->values; 19 | for (all_phases (p)) 20 | p->target = *v, v += 2; 21 | assert (v == solver->values + LITS); 22 | } 23 | 24 | void 25 | kissat_save_best_phases (kissat * solver) 26 | { 27 | LOG ("saving %u target values", LITS); 28 | const value *v = solver->values; 29 | for (all_phases (p)) 30 | p->best = *v, v += 2; 31 | assert (v == solver->values + LITS); 32 | } 33 | -------------------------------------------------------------------------------- /emu/kissat/src/phases.h: -------------------------------------------------------------------------------- 1 | #ifndef _phases_h_INCLUDED 2 | #define _phases_h_INCLUDED 3 | 4 | typedef struct phase phase; 5 | 6 | struct phase 7 | { 8 | signed char best:2; 9 | signed char saved:2; 10 | signed char target:2; 11 | }; 12 | 13 | #define PHASE(IDX) \ 14 | (assert ((IDX) < VARS), (solver->phases + (IDX))) 15 | 16 | #define BEST(IDX) (PHASE(IDX)->best) 17 | #define SAVED(IDX) (PHASE(IDX)->saved) 18 | #define TARGET(IDX) (PHASE(IDX)->target) 19 | 20 | struct kissat; 21 | 22 | void kissat_save_best_phases (struct kissat *); 23 | void kissat_save_target_phases (struct kissat *); 24 | void kissat_clear_target_phases (struct kissat *); 25 | 26 | #define all_phases(P) \ 27 | phase * P = solver->phases, * END_ ## P = P + VARS; P != END_ ## P; P++ 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /emu/kissat/src/print.h: -------------------------------------------------------------------------------- 1 | #ifndef _print_h_INCLUDED 2 | #define _print_h_INCLUDED 3 | 4 | #ifndef QUIET 5 | 6 | #include 7 | 8 | struct kissat; 9 | 10 | int kissat_verbosity (struct kissat *); 11 | 12 | void kissat_signal (struct kissat *, const char *type, int sig); 13 | void kissat_message (struct kissat *, const char *fmt, ...); 14 | void kissat_section (struct kissat *, const char *name); 15 | void kissat_verbose (struct kissat *, const char *fmt, ...); 16 | void kissat_very_verbose (struct kissat *, const char *fmt, ...); 17 | void kissat_extremely_verbose (struct kissat *, const char *fmt, ...); 18 | void kissat_warning (struct kissat *, const char *fmt, ...); 19 | 20 | void kissat_phase (struct kissat *, const char *name, uint64_t, 21 | const char *fmt, ...); 22 | #else 23 | 24 | #define kissat_message(...) do { } while (0) 25 | #define kissat_phase(...) do { } while (0) 26 | #define kissat_section(...) do { } while (0) 27 | #define kissat_signal(...) do { } while (0) 28 | #define kissat_verbose(...) do { } while (0) 29 | #define kissat_very_verbose(...) do { } while (0) 30 | #define kissat_extremely_verbose(...) do { } while (0) 31 | #define kissat_warning(...) do { } while (0) 32 | 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /emu/kissat/src/probe.h: -------------------------------------------------------------------------------- 1 | #ifndef _probe_h_INCLUDED 2 | #define _probe_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | bool kissat_probing (struct kissat *); 7 | int kissat_probe (struct kissat *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/promote.h: -------------------------------------------------------------------------------- 1 | #ifndef _promote_h_INCLUDED 2 | #define _promote_h_INCLUDED 3 | 4 | struct clause; 5 | struct kissat; 6 | 7 | unsigned kissat_recompute_glue (struct kissat *, struct clause *c); 8 | void kissat_promote_clause (struct kissat *, clause *, unsigned new_glue); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/propbeyond.c: -------------------------------------------------------------------------------- 1 | #include "fastassign.h" 2 | #include "propbeyond.h" 3 | #include "trail.h" 4 | 5 | #define PROPAGATE_LITERAL propagate_literal_beyond_conflicts 6 | #define CONTINUE_PROPAGATING_AFTER_CONFLICT 7 | #define PROPAGATION_TYPE "beyond conflict" 8 | 9 | #include "proplit.h" 10 | 11 | static void 12 | propagate_literals_beyond_conflicts (kissat * solver) 13 | { 14 | unsigned *propagate = solver->propagate; 15 | while (propagate != END_ARRAY (solver->trail)) 16 | (void) propagate_literal_beyond_conflicts (solver, *propagate++); 17 | solver->propagate = propagate; 18 | } 19 | 20 | void 21 | kissat_propagate_beyond_conflicts (kissat * solver) 22 | { 23 | assert (!solver->probing); 24 | assert (solver->watching); 25 | assert (!solver->inconsistent); 26 | 27 | START (propagate); 28 | 29 | solver->ticks = 0; 30 | const unsigned *saved_propagate = solver->propagate; 31 | propagate_literals_beyond_conflicts (solver); 32 | kissat_update_search_propagation_statistics (solver, saved_propagate); 33 | 34 | STOP (propagate); 35 | } 36 | -------------------------------------------------------------------------------- /emu/kissat/src/propbeyond.h: -------------------------------------------------------------------------------- 1 | #ifndef _propall_h_INCLUDED 2 | #define _propall_h_INCLUDED 3 | 4 | struct kissat; 5 | struct clause; 6 | 7 | void kissat_propagate_beyond_conflicts (struct kissat *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/propdense.h: -------------------------------------------------------------------------------- 1 | #ifndef _propdense_h_INCLUDED 2 | #define _propdense_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | #include 7 | 8 | #define NO_DENSE_PROPAGATION_LIMIT UINT_MAX 9 | 10 | bool kissat_dense_propagate (struct kissat *, 11 | unsigned limit, unsigned ignore_idx); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /emu/kissat/src/prophyper.h: -------------------------------------------------------------------------------- 1 | #ifndef _prophyper_h_INCLUDED 2 | #define _prophyper_h_INCLUDED 3 | 4 | struct kissat; 5 | struct clause; 6 | 7 | struct clause *kissat_hyper_propagate (struct kissat *, 8 | const struct clause *); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/proprobe.c: -------------------------------------------------------------------------------- 1 | #define INLINE_ASSIGN 2 | 3 | #include "inline.h" 4 | #include "proprobe.h" 5 | 6 | // Keep this 'inlined' file separate: 7 | 8 | #include "assign.c" 9 | 10 | #define PROPAGATE_LITERAL probing_propagate_literal 11 | #define PROPAGATION_TYPE "probing" 12 | #define PROBING_PROPAGATION 13 | 14 | #include "proplit.h" 15 | 16 | static clause * 17 | probing_propagate (kissat * solver, clause * ignore) 18 | { 19 | clause *res = 0; 20 | while (!res && solver->propagated < SIZE_STACK (solver->trail)) 21 | { 22 | const unsigned lit = PEEK_STACK (solver->trail, solver->propagated); 23 | res = probing_propagate_literal (solver, ignore, lit); 24 | solver->propagated++; 25 | } 26 | return res; 27 | } 28 | 29 | clause * 30 | kissat_probing_propagate (kissat * solver, clause * ignore) 31 | { 32 | assert (solver->probing); 33 | assert (solver->watching); 34 | assert (!solver->inconsistent); 35 | 36 | START (propagate); 37 | 38 | solver->ticks = 0; 39 | const unsigned propagated = solver->propagated; 40 | clause *conflict = probing_propagate (solver, ignore); 41 | kissat_update_probing_propagation_statistics (solver, propagated); 42 | 43 | STOP (propagate); 44 | 45 | return conflict; 46 | } 47 | -------------------------------------------------------------------------------- /emu/kissat/src/proprobe.h: -------------------------------------------------------------------------------- 1 | #ifndef _proprobe_h_INCLUDED 2 | #define _proprobe_h_INCLUDED 3 | 4 | struct kissat; 5 | struct clause; 6 | 7 | struct clause *kissat_probing_propagate (struct kissat *, struct clause *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/propsearch.h: -------------------------------------------------------------------------------- 1 | #ifndef _propsearch_h_INCLUDED 2 | #define _propsearch_h_INCLUDED 3 | 4 | struct kissat; 5 | struct clause; 6 | 7 | struct clause *kissat_search_propagate (struct kissat *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef _queue_h_INCLUDED 2 | #define _queue_h_INCLUDED 3 | 4 | #define DISCONNECT UINT_MAX 5 | #define DISCONNECTED(IDX) ((int)(IDX) < 0) 6 | 7 | struct kissat; 8 | 9 | typedef struct links links; 10 | typedef struct queue queue; 11 | 12 | struct links 13 | { 14 | unsigned prev, next; 15 | unsigned stamp; 16 | }; 17 | 18 | struct queue 19 | { 20 | unsigned first, last, stamp; 21 | struct 22 | { 23 | unsigned idx, stamp; 24 | } search; 25 | }; 26 | 27 | void kissat_init_queue (queue *); 28 | void kissat_enqueue (struct kissat *, unsigned idx); 29 | void kissat_dequeue (struct kissat *, unsigned idx); 30 | void kissat_move_to_front (struct kissat *, unsigned idx); 31 | 32 | #define LINK(IDX) \ 33 | (solver->links[assert ((IDX) < VARS), (IDX)]) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /emu/kissat/src/random.h: -------------------------------------------------------------------------------- 1 | #ifndef _random_h_INCLUDED 2 | #define _random_h_INCLUDED 3 | 4 | #include 5 | #include "kissat_bool.h" 6 | #include 7 | 8 | typedef uint64_t generator; 9 | 10 | static inline uint64_t 11 | kissat_next_random64 (generator * rng) 12 | { 13 | *rng *= 6364136223846793005ul; 14 | *rng += 1442695040888963407ul; 15 | return *rng; 16 | } 17 | 18 | static inline unsigned 19 | kissat_next_random32 (generator * rng) 20 | { 21 | return kissat_next_random64 (rng) >> 32; 22 | } 23 | 24 | static inline unsigned 25 | kissat_pick_random (generator * rng, unsigned l, unsigned r) 26 | { 27 | assert (l < r); 28 | const unsigned delta = r - l; 29 | const unsigned tmp = kissat_next_random32 (rng); 30 | const double fraction = tmp / 4294967296.0; 31 | assert (0 <= fraction), assert (fraction < 1); 32 | const unsigned scaled = delta * fraction; 33 | assert (scaled < delta); 34 | const unsigned res = l + scaled; 35 | assert (l <= res), assert (res < r); 36 | return res; 37 | } 38 | 39 | static inline bool 40 | kissat_pick_bool (generator * rng) 41 | { 42 | return kissat_pick_random (rng, 0, 2); 43 | } 44 | 45 | static inline double 46 | kissat_pick_double (generator * rng) 47 | { 48 | return kissat_next_random32 (rng) / 4294967296.0; 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /emu/kissat/src/reduce.h: -------------------------------------------------------------------------------- 1 | #ifndef _reduce_h_INCLUDED 2 | #define _reduce_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | 8 | bool kissat_reducing (struct kissat *); 9 | int kissat_reduce (struct kissat *); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /emu/kissat/src/reference.h: -------------------------------------------------------------------------------- 1 | #ifndef _reference_h_INCLUDED 2 | #define _reference_h_INCLUDED 3 | 4 | #include "stack.h" 5 | 6 | typedef unsigned reference; 7 | 8 | #define LD_MAX_REF 31 9 | #define MAX_REF (((reference)1 << LD_MAX_REF)-1) 10 | 11 | #define INVALID_REF UINT_MAX 12 | 13 | // *INDENT-OFF* 14 | typedef STACK (reference) references; 15 | // *INDENT-ON* 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /emu/kissat/src/reluctant.h: -------------------------------------------------------------------------------- 1 | #ifndef _reluctant_h_INCLUDED 2 | #define _reluctant_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | #include 6 | 7 | typedef struct reluctant reluctant; 8 | 9 | struct reluctant 10 | { 11 | bool limited; 12 | bool trigger; 13 | uint64_t period; 14 | uint64_t wait; 15 | uint64_t u, v; 16 | uint64_t limit; 17 | }; 18 | 19 | void kissat_enable_reluctant (reluctant *, uint64_t period, uint64_t limit); 20 | void kissat_disable_reluctant (reluctant *); 21 | void kissat_tick_reluctant (reluctant *); 22 | 23 | static inline bool 24 | kissat_reluctant_triggered (reluctant * reluctant) 25 | { 26 | if (!reluctant->trigger) 27 | return false; 28 | reluctant->trigger = false; 29 | return true; 30 | } 31 | 32 | struct kissat; 33 | 34 | void kissat_init_reluctant (struct kissat *); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /emu/kissat/src/rephase.h: -------------------------------------------------------------------------------- 1 | #ifndef _rephase_h_INCLUDED 2 | #define _rephase_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | #include 6 | 7 | typedef struct rephased rephased; 8 | 9 | struct rephased 10 | { 11 | char type; 12 | uint64_t count; 13 | uint64_t last; 14 | }; 15 | 16 | struct kissat; 17 | 18 | bool kissat_rephasing (struct kissat *); 19 | void kissat_rephase (struct kissat *); 20 | char kissat_rephase_best (struct kissat *); 21 | 22 | void kissat_reset_rephased (struct kissat *); 23 | void kissat_reset_target_assigned (struct kissat *); 24 | void kissat_reset_consistently_assigned (struct kissat *); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /emu/kissat/src/report.h: -------------------------------------------------------------------------------- 1 | #ifndef _report_h_INCLUDED 2 | #define _report_h_INCLUDED 3 | 4 | #ifdef QUIET 5 | 6 | #define REPORT(...) do { } while (0) 7 | 8 | #else 9 | 10 | struct kissat; 11 | 12 | void kissat_report (struct kissat *, bool verbose, char type); 13 | 14 | #define REPORT(LEVEL,TYPE) \ 15 | kissat_report (solver, (LEVEL), (TYPE)) 16 | 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /emu/kissat/src/require.h: -------------------------------------------------------------------------------- 1 | #ifndef _require_h_INCLUDED 2 | #define _require_h_INCLUDED 3 | 4 | #define kissat_require(COND,...) \ 5 | do { \ 6 | if ((COND)) \ 7 | break; \ 8 | kissat_fatal_message_start (); \ 9 | fprintf (stderr, "calling '%s': ", __func__); \ 10 | fprintf (stderr, __VA_ARGS__); \ 11 | fputc ('\n', stderr); \ 12 | fflush (stderr); \ 13 | kissat_abort (); \ 14 | } while (0) 15 | 16 | #define kissat_require_initialized(SOLVER) \ 17 | kissat_require (SOLVER, "uninitialized") 18 | 19 | #define kissat_require_valid_external_internal(LIT) \ 20 | do { \ 21 | kissat_require ((LIT) != INT_MIN, \ 22 | "invalid literal '%d' (INT_MIN)", (LIT)); \ 23 | const int TMP_IDX = ABS (LIT); \ 24 | kissat_require (TMP_IDX <= EXTERNAL_MAX_VAR, \ 25 | "invalid literal '%d' (variable larger than %d)", \ 26 | (LIT), EXTERNAL_MAX_VAR); \ 27 | assert (VALID_EXTERNAL_LITERAL (LIT)); \ 28 | } while (0) 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /emu/kissat/src/resize.h: -------------------------------------------------------------------------------- 1 | #ifndef _resize_h_INCLUDED 2 | #define _resize_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_decrease_size (struct kissat *solver); 7 | void kissat_increase_size (struct kissat *, unsigned new_size); 8 | void kissat_enlarge_variables (struct kissat *, unsigned new_vars); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/resolve.h: -------------------------------------------------------------------------------- 1 | #ifndef _resolve_h_INCLUDED 2 | #define _resolve_h_INCLUDED 3 | 4 | bool kissat_generate_resolvents (struct kissat *, 5 | unsigned idx, unsigned *lit_ptr); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /emu/kissat/src/resources.h: -------------------------------------------------------------------------------- 1 | #ifndef _resources_h_INCLUDED 2 | #define _resources_h_INCLUDED 3 | 4 | double kissat_wall_clock_time (void); 5 | 6 | #ifndef QUIET 7 | 8 | #ifndef _resources_h_INLCUDED 9 | #define _resources_h_INLCUDED 10 | 11 | #include 12 | 13 | struct kissat; 14 | 15 | double kissat_process_time (void); 16 | uint64_t kissat_current_resident_set_size (void); 17 | uint64_t kissat_maximum_resident_set_size (void); 18 | void kissat_print_resources (struct kissat *); 19 | 20 | #endif 21 | 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /emu/kissat/src/restart.h: -------------------------------------------------------------------------------- 1 | #ifndef _restart_h_INCLUDED 2 | #define _restart_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | bool kissat_restarting (struct kissat *); 7 | void kissat_restart (struct kissat *); 8 | void kissat_new_focused_restart_limit (struct kissat *); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/search.h: -------------------------------------------------------------------------------- 1 | #ifndef _search_h_INCLUDED 2 | #define _search_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | int kissat_search (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/shrink.h: -------------------------------------------------------------------------------- 1 | #ifndef _shrink_h_INCLUDED 2 | #define _shrink_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_shrink_clause (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/smooth.c: -------------------------------------------------------------------------------- 1 | #include "allocate.h" 2 | #include "internal.h" 3 | #include "logging.h" 4 | 5 | #include 6 | 7 | void 8 | kissat_init_smooth (kissat * solver, smooth * smooth, int window, 9 | const char *name) 10 | { 11 | assert (window > 0); 12 | const double alpha = 1.0 / window; 13 | LOG ("initialized 'EMA (%s)' with alpha %g (window %d)", name, alpha, 14 | window); 15 | smooth->value = 0; 16 | smooth->alpha = alpha; 17 | smooth->beta = 1.0; 18 | smooth->wait = smooth->period = 0; 19 | #ifdef LOGGING 20 | smooth->name = name; 21 | #else 22 | (void) solver; 23 | (void) name; 24 | #endif 25 | } 26 | 27 | void 28 | kissat_update_smooth (kissat * solver, smooth * smooth, double y) 29 | { 30 | smooth->value += smooth->beta * (y - smooth->value); 31 | LOG ("updated 'EMA (%s)' with %g (%s %g) yields %g", 32 | smooth->name, 33 | (smooth->beta == smooth->alpha ? "alpha" : "beta"), 34 | y, smooth->beta, smooth->value); 35 | if (smooth->beta <= smooth->alpha || smooth->wait--) 36 | return; 37 | smooth->wait = smooth->period = 2 * (smooth->period + 1) - 1; 38 | smooth->beta *= 0.5; 39 | if (smooth->beta < smooth->alpha) 40 | smooth->alpha = smooth->beta; 41 | LOG ("new EMA (%s) wait = period = %" PRIu64 ", beta = %g", 42 | smooth->name, smooth->wait, smooth->beta); 43 | #ifndef LOGGING 44 | (void) solver; 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /emu/kissat/src/smooth.h: -------------------------------------------------------------------------------- 1 | #ifndef _smooth_h_INCLUDED 2 | #define _smooth_h_INCLUDED 3 | 4 | #include 5 | 6 | typedef struct smooth smooth; 7 | 8 | struct smooth 9 | { 10 | #ifdef LOGGING 11 | const char *name; 12 | #endif 13 | double value, alpha, beta; 14 | uint64_t wait, period; 15 | }; 16 | 17 | struct kissat; 18 | 19 | void kissat_init_smooth (struct kissat *, smooth *, int window, const char *); 20 | void kissat_update_smooth (struct kissat *, smooth *, double); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /emu/kissat/src/strengthen.h: -------------------------------------------------------------------------------- 1 | #ifndef _strengthen_h_INCLUDED 2 | #define _strengthen_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct clause; 7 | struct kissat; 8 | 9 | struct clause *kissat_on_the_fly_strengthen (struct kissat *, struct clause *, 10 | unsigned lit); 11 | 12 | void 13 | kissat_on_the_fly_subsume (struct kissat *, struct clause *, struct clause *); 14 | 15 | bool kissat_strengthen_clause (struct kissat *, struct clause *, unsigned); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /emu/kissat/src/substitute.h: -------------------------------------------------------------------------------- 1 | #ifndef _substitute_h_INCLUDED 2 | #define _substitute_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | 8 | void kissat_substitute (struct kissat *, bool first); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/kissat/src/sweep.h: -------------------------------------------------------------------------------- 1 | #ifndef _sweep_h_INCLUDED 2 | #define _sweep_h_INCLUDED 3 | 4 | struct kissat; 5 | void kissat_sweep (struct kissat *); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /emu/kissat/src/terminate.c: -------------------------------------------------------------------------------- 1 | #include "print.h" 2 | #include "terminate.h" 3 | 4 | #ifndef QUIET 5 | 6 | void 7 | kissat_report_termination (kissat * solver, int bit, 8 | const char *file, long lineno, const char *fun) 9 | { 10 | kissat_very_verbose (solver, "%s:%ld: %s: TERMINATED (%d)", 11 | file, lineno, fun, bit); 12 | } 13 | 14 | #else 15 | int kissat_terminate_dummy_to_avoid_warning; 16 | #endif 17 | -------------------------------------------------------------------------------- /emu/kissat/src/terminate.h: -------------------------------------------------------------------------------- 1 | #ifndef _terminate_h_INCLUDED 2 | #define _terminate_h_INCLUDED 3 | 4 | #include "internal.h" 5 | 6 | #ifndef QUIET 7 | void kissat_report_termination (kissat *, int bit, const char *file, 8 | long lineno, const char *fun); 9 | #endif 10 | 11 | static inline bool 12 | kissat_terminated (kissat * solver, int bit, 13 | const char *file, long lineno, const char *fun) 14 | { 15 | assert (0 <= bit), assert (bit < 32); 16 | #ifdef COVERAGE 17 | const unsigned mask = 1u << bit; 18 | if (!(solver->terminate & mask)) 19 | return false; 20 | solver->terminate = ~(unsigned) 0; 21 | #else 22 | if (!solver->terminate) 23 | return false; 24 | #endif 25 | #ifndef QUIET 26 | kissat_report_termination (solver, bit, file, lineno, fun); 27 | #else 28 | (void) file; 29 | (void) lineno; 30 | (void) fun; 31 | #ifndef COVERAGE 32 | (void) bit; 33 | #endif 34 | #endif 35 | return true; 36 | } 37 | 38 | #define TERMINATED(BIT) \ 39 | kissat_terminated (solver, BIT, __FILE__, __LINE__, __func__) 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /emu/kissat/src/ternary.h: -------------------------------------------------------------------------------- 1 | #ifndef _ternary_h_INCLUDED 2 | #define _ternary_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_ternary (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/trail.h: -------------------------------------------------------------------------------- 1 | #ifndef _trail_h_INLCUDED 2 | #define _trail_h_INLCUDED 3 | 4 | #include "reference.h" 5 | 6 | #include "kissat_bool.h" 7 | 8 | struct kissat; 9 | 10 | void kissat_flush_trail (struct kissat *); 11 | void kissat_restart_and_flush_trail (struct kissat *); 12 | bool kissat_flush_and_mark_reason_clauses (struct kissat *, reference start); 13 | void kissat_unmark_reason_clauses (struct kissat *, reference start); 14 | void kissat_mark_reason_clauses (struct kissat *, reference start); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /emu/kissat/src/transitive.h: -------------------------------------------------------------------------------- 1 | #ifndef _transitive_h_INCLUDED 2 | #define _transitive_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_transitive_reduction (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/utilities.c: -------------------------------------------------------------------------------- 1 | #include "utilities.h" 2 | 3 | #include 4 | 5 | bool 6 | kissat_has_suffix (const char *str, const char *suffix) 7 | { 8 | size_t l = strlen (str); 9 | size_t k = strlen (suffix); 10 | if (l < k) 11 | return false; 12 | return !strcmp (str + l - k, suffix); 13 | } 14 | 15 | unsigned 16 | kissat_ldceil (word w) 17 | { 18 | unsigned res = 0; 19 | word limit = 1; 20 | while (limit && w > limit) 21 | { 22 | limit <<= 1; 23 | res++; 24 | } 25 | return res; 26 | } 27 | -------------------------------------------------------------------------------- /emu/kissat/src/value.h: -------------------------------------------------------------------------------- 1 | #ifndef _value_h_INCLUDED 2 | #define _value_h_INCLUDED 3 | 4 | typedef signed char value; 5 | typedef signed char mark; 6 | 7 | #define VALUE(LIT) \ 8 | (solver->values[assert ((LIT) < LITS), (LIT)]) 9 | 10 | #define MARK(LIT) \ 11 | (solver->marks[assert ((LIT) < LITS), (LIT)]) 12 | 13 | #define BOOL_TO_VALUE(B) ((signed char)((B) ? -1 : 1)) 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /emu/kissat/src/vivify.h: -------------------------------------------------------------------------------- 1 | #ifndef _vivify_h_INCLUDED 2 | #define _vivify_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_vivify (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/walk.h: -------------------------------------------------------------------------------- 1 | #ifndef _walk_h_INCLUDED 2 | #define _walk_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | char kissat_walk (struct kissat *); 7 | int kissat_walk_initially (struct kissat *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /emu/kissat/src/warmup.c: -------------------------------------------------------------------------------- 1 | #include "backtrack.h" 2 | #include "decide.h" 3 | #include "internal.h" 4 | #include "print.h" 5 | #include "propbeyond.h" 6 | #include "terminate.h" 7 | #include "warmup.h" 8 | 9 | void 10 | kissat_warmup (kissat * solver) 11 | { 12 | assert (!solver->level); 13 | assert (solver->watching); 14 | assert (!solver->inconsistent); 15 | assert (GET_OPTION (warmup)); 16 | START (warmup); 17 | INC (warmups); 18 | #ifndef QUIET 19 | const statistics *stats = &solver->statistics; 20 | uint64_t propagations = stats->propagations; 21 | uint64_t decisions = stats->decisions; 22 | #endif 23 | while (solver->unassigned) 24 | { 25 | if (TERMINATED (warmup_terminated_1)) 26 | break; 27 | kissat_decide (solver); 28 | kissat_propagate_beyond_conflicts (solver); 29 | } 30 | assert (!solver->inconsistent); 31 | #ifndef QUIET 32 | decisions = stats->decisions - decisions; 33 | propagations = stats->propagations - propagations; 34 | 35 | kissat_very_verbose (solver, 36 | "warming-up needed %" PRIu64 " decisions and %" 37 | PRIu64 " propagations", decisions, propagations); 38 | 39 | if (solver->unassigned) 40 | kissat_verbose (solver, "reached decision level %u " 41 | "during warming-up saved phases", solver->level); 42 | else 43 | kissat_verbose (solver, "all variables assigned at decision level %u " 44 | "during warming-up saved phases", solver->level); 45 | #endif 46 | kissat_backtrack_without_updating_phases (solver, 0); 47 | STOP (warmup); 48 | } 49 | -------------------------------------------------------------------------------- /emu/kissat/src/warmup.h: -------------------------------------------------------------------------------- 1 | #ifndef _warmup_h_INCLUDED 2 | #define _warmup_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_warmup (struct kissat *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/weaken.h: -------------------------------------------------------------------------------- 1 | #ifndef _weaken_h_INCLUDED 2 | #define _weaken_h_INCLUDED 3 | 4 | struct clause; 5 | struct kissat; 6 | 7 | void kissat_weaken_unit (struct kissat *, unsigned lit); 8 | void kissat_weaken_binary (struct kissat *, unsigned lit, unsigned other); 9 | void kissat_weaken_clause (struct kissat *, unsigned lit, struct clause *); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /emu/kissat/src/witness.c: -------------------------------------------------------------------------------- 1 | #include "allocate.h" 2 | #include "internal.h" 3 | #include "witness.h" 4 | 5 | #include 6 | #include 7 | 8 | static void 9 | flush_buffer (chars * buffer) 10 | { 11 | fputs ("v", stdout); 12 | for (all_stack (char, ch, *buffer)) 13 | fputc (ch, stdout); 14 | fputc ('\n', stdout); 15 | CLEAR_STACK (*buffer); 16 | } 17 | 18 | static void 19 | print_int (kissat * solver, chars * buffer, int i) 20 | { 21 | char tmp[16]; 22 | sprintf (tmp, " %d", i); 23 | size_t tmp_len = strlen (tmp); 24 | size_t buf_len = SIZE_STACK (*buffer); 25 | if (buf_len + tmp_len > 77) 26 | flush_buffer (buffer); 27 | for (const char *p = tmp; *p; p++) 28 | PUSH_STACK (*buffer, *p); 29 | } 30 | 31 | void 32 | kissat_print_witness (kissat * solver, int max_var, bool partial) 33 | { 34 | chars buffer; 35 | INIT_STACK (buffer); 36 | for (int eidx = 1; eidx <= max_var; eidx++) 37 | { 38 | int tmp = kissat_value (solver, eidx); 39 | if (!tmp && !partial) 40 | tmp = eidx; 41 | if (tmp) 42 | print_int (solver, &buffer, tmp); 43 | } 44 | print_int (solver, &buffer, 0); 45 | assert (!EMPTY_STACK (buffer)); 46 | flush_buffer (&buffer); 47 | RELEASE_STACK (buffer); 48 | } 49 | -------------------------------------------------------------------------------- /emu/kissat/src/witness.h: -------------------------------------------------------------------------------- 1 | #ifndef _witness_h_INCLUDED 2 | #define _witness_h_INCLUDED 3 | 4 | struct kissat; 5 | 6 | void kissat_print_witness (struct kissat *, int max_var, bool partial); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /emu/kissat/src/xors.h: -------------------------------------------------------------------------------- 1 | #ifndef _xors_h_INCLUDED 2 | #define _xors_h_INCLUDED 3 | 4 | #include "kissat_bool.h" 5 | 6 | struct kissat; 7 | 8 | bool kissat_find_xor_gate (struct kissat *, unsigned lit, unsigned negative); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /emu/load_inst.c: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /emu/main.c: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * File : main.c 3 | * Author : Neng-Fa ZHOU Copyright (C) 1994-2024 4 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | ********************************************************************/ 9 | 10 | #include "bprolog.h" 11 | int main(int argc, char *argv[]); 12 | static INLINE int bprolog_main(int argc, char *argv[]); 13 | 14 | int bprolog_main(int argc, char *argv[]) 15 | { 16 | initialize_bprolog(argc, argv); 17 | if (disassem) { 18 | dis(); 19 | printf("The byte code file is dumped in the file dump.pil\n"); 20 | finish_bprolog(); 21 | return (0); 22 | } 23 | else { 24 | #ifdef PICAT 25 | if (main_args != nil_sym) { 26 | use_gl_getline = 0; 27 | } 28 | #endif 29 | bp_call_term(ADDTAG(insert_sym("$bp_first_call", 14, 0), ATM)); 30 | // toam(inst_begin,arreg,local_top); 31 | finish_bprolog(); 32 | return (0); 33 | } 34 | } 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | return bprolog_main(argc, argv); 39 | } 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /emu/make_picat_scip_linux: -------------------------------------------------------------------------------- 1 | rm -r scipsuite 2 | tar xvf scipsuite.tar.gz 3 | cd scipsuite 4 | sed -i "s/add_library(libscip/add_library(libscip STATIC/g" scip/src/CMakeLists.txt 5 | mkdir build && cd build 6 | cmake -DNO_EXTERNAL_CODE=on -DSOPLEX=on -DTPI=tny .. 7 | make libscip 8 | cd ../.. 9 | make -f Makefile.linux64.scip clean 10 | make -f Makefile.linux64.scip 11 | 12 | 13 | -------------------------------------------------------------------------------- /emu/make_picat_scip_mac: -------------------------------------------------------------------------------- 1 | rm -r scipsuite 2 | tar xvf scipsuite.tar.gz 3 | cd scipsuite 4 | sed -i "s/add_library(libscip/add_library(libscip STATIC/g" scip/src/CMakeLists.txt 5 | mkdir build && cd build 6 | cmake -DNO_EXTERNAL_CODE=on -DSOPLEX=on -DTPI=tny .. 7 | make libscip 8 | cd ../.. 9 | make -f Makefile.mac64.scip clean 10 | make -f Makefile.mac64.scip 11 | -------------------------------------------------------------------------------- /emu/maple/bin/starexec_run_default: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./MapleLCMDistChrBt-DL-v3 $1 -drup-file=$2/proof.out 4 | -------------------------------------------------------------------------------- /emu/maple/core/Makefile: -------------------------------------------------------------------------------- 1 | EXEC = glucose 2 | DEPDIR = mtl utils 3 | MROOT = .. 4 | 5 | include $(MROOT)/mtl/template.mk 6 | -------------------------------------------------------------------------------- /emu/maple/mtl/config.mk: -------------------------------------------------------------------------------- 1 | ## 2 | ## This file is for system specific configurations. For instance, on 3 | ## some systems the path to zlib needs to be added. Example: 4 | ## 5 | ## CFLAGS += -I/usr/local/include 6 | ## LFLAGS += -L/usr/local/lib 7 | -------------------------------------------------------------------------------- /emu/maple/simp/Makefile: -------------------------------------------------------------------------------- 1 | EXEC = glucose 2 | DEPDIR = mtl utils core 3 | MROOT = ../ 4 | 5 | include $(MROOT)/mtl/template.mk 6 | -------------------------------------------------------------------------------- /emu/maple/simp/depend.mk: -------------------------------------------------------------------------------- 1 | /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/SimpSolver.o /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/SimpSolver.or /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/SimpSolver.od /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/SimpSolver.op: \ 2 | /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/SimpSolver.cc \ 3 | ../mtl/Sort.h ../mtl/Vec.h ../mtl/IntTypes.h ../mtl/XAlloc.h \ 4 | ../simp/SimpSolver.h ../mtl/Queue.h ../core/Solver.h ../mtl/Heap.h \ 5 | ../mtl/Alg.h ../utils/Options.h ../utils/ParseUtils.h \ 6 | ../core/SolverTypes.h ../mtl/Map.h ../mtl/Alloc.h ../utils/System.h 7 | /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/Main.o /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/Main.or /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/Main.od /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/Main.op: \ 8 | /nfs/iil/proj/dt/prover01/work/vryvchin/OtherSolvers/Maple_LCM_Dist_chrono/sources/simp/Main.cc \ 9 | ../utils/System.h ../mtl/IntTypes.h ../utils/ParseUtils.h \ 10 | ../utils/Options.h ../mtl/Vec.h ../mtl/XAlloc.h ../core/Dimacs.h \ 11 | ../core/SolverTypes.h ../mtl/Alg.h ../mtl/Map.h ../mtl/Alloc.h \ 12 | ../simp/SimpSolver.h ../mtl/Queue.h ../core/Solver.h ../mtl/Heap.h 13 | -------------------------------------------------------------------------------- /emu/maple/starexec_build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd sources/simp 4 | make clean 5 | make rs 6 | cp glucose_static ../../bin/MapleLCMDistChrBt-DL-v3 7 | 8 | -------------------------------------------------------------------------------- /emu/maple/utils/Makefile: -------------------------------------------------------------------------------- 1 | EXEC = system_test 2 | DEPDIR = mtl 3 | 4 | include $(MROOT)/mtl/template.mk 5 | -------------------------------------------------------------------------------- /emu/maple_interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "bprolog.h" 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | void maple_init(); 9 | void maple_add_lit(int lit0); 10 | int maple_start_solver(); 11 | int maple_get_binding(int varNum); 12 | 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /emu/picat.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * File : picat.h 3 | * Author : Neng-Fa ZHOU Copyright (C) 1994-2022 4 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | ********************************************************************/ 9 | #ifndef PICATH 10 | #define PICATH 11 | 12 | #include "basic.h" 13 | #include "bapi.h" 14 | #include "term.h" 15 | 16 | #define PICAT_FALSE 0 17 | #define PICAT_TRUE 1 18 | #define PICAT_ERROR -1 19 | #endif 20 | -------------------------------------------------------------------------------- /emu/picat_utilities.h: -------------------------------------------------------------------------------- 1 | #ifndef PICAT_UTILITIES 2 | #define PICAT_UTILITIES 3 | 4 | #include "picat.h" 5 | 6 | TERM cstring_to_picat(char* ch_ptr, int n); 7 | 8 | char* picat_string_to_cstring(TERM t); 9 | 10 | TERM picat_get_list_end(TERM l); 11 | 12 | TERM new_picat_map(int C); 13 | 14 | void add_to_picat_map(TERM m, TERM key, TERM value); 15 | 16 | TERM picat_map_get(TERM map, TERM key); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /emu/reasonls_interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "bprolog.h" 3 | 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | void maple_init(); 9 | void maple_add_lit(int lit0); 10 | int maple_start_solver(); 11 | int maple_get_binding(int varNum); 12 | 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /emu/sapi.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * File : sapi.h 3 | * Author : Neng-Fa ZHOU Copyright (C) 1994-2022 4 | 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | ********************************************************************/ 9 | 10 | /* SICStus Prolog APIs */ 11 | 12 | #define SP_ERROR -1 13 | #define SP_FAILURE 0 14 | #define SP_SUCCESS 1 15 | 16 | #define SP_TYPE_VARIABLE BP_TYPE_VARIABLE 17 | #define SP_TYPE_INTEGER BP_TYPE_INTEGER 18 | #define SP_TYPE_FLOAT BP_TYPE_FLOAT 19 | #define SP_TYPE_ATOM BP_TYPE_ATOM 20 | #define SP_TYPE_COMPOUND BP_TYPE_COMPOUND 21 | 22 | int SP_errno; 23 | 24 | 25 | #define SP_term_ref BP_term_ref 26 | 27 | #define SP_pred_ref BP_pred_ref 28 | 29 | extern SP_pred_ref SP_predicate(char *name_string, long arity, char *module_string); 30 | extern SP_pred_ref SP_pred(BPULONG name_atom, long arity, BPULONG module_atom); 31 | extern SP_term_ref SP_new_term_ref(); 32 | extern char *SP_string_from_atom(BPULONG a); 33 | extern char *SP_alloc(); 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /emu/scipsuite.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/emu/scipsuite.tar.gz -------------------------------------------------------------------------------- /exs/cp/queens.pi: -------------------------------------------------------------------------------- 1 | import cp. 2 | 3 | main => top. 4 | 5 | top => 6 | queens(100). 7 | 8 | queens(N) => 9 | Qs=new_array(N), 10 | Qs :: 1..N, 11 | foreach (I in 1..N-1, J in I+1..N) 12 | Qs[I] #!= Qs[J], 13 | abs(Qs[I]-Qs[J]) #!= J-I 14 | end, 15 | solve([ff],Qs), 16 | writeln(Qs). 17 | -------------------------------------------------------------------------------- /exs/euler/p1.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=1 3 | 4 | If we list all the natural numbers below 10 that are 5 | multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these 6 | multiples is 23. 7 | 8 | Find the sum of all the multiples of 3 or 5 below 1000. 9 | *********************************************************/ 10 | 11 | main => 12 | S = sum([I : I in 1..999, (I mod 3 = 0; I mod 5 = 0)]), 13 | writef("Sum of all the multiples of 3 or 5 below 1000 is %w%n",S). 14 | 15 | 16 | /* here is another implementation 17 | main => 18 | S = 0, 19 | foreach (I in 1..999) 20 | if (I mod 3 = 0; I mod 5 = 0) then 21 | S:=S+I 22 | end 23 | end, 24 | writef("Sum of all the multiples of 3 or 5 below 1000 is %w%n",S). 25 | */ 26 | -------------------------------------------------------------------------------- /exs/euler/p10.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=10 3 | 4 | The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. 5 | 6 | Find the sum of all the primes below two million. 7 | *********************************************************/ 8 | 9 | % primes defined in module 'math'. 10 | main => % NOTE: the specifier %d is not good since the integer is too large. Therefore, use %w. 11 | writef("The sum of all the primes below two million is %w%n",sum(primes(2000000))). 12 | 13 | /* Curious about how the function primes/1 is defined? Here is the definition in math.pi : 14 | % Sieve of Eratosthenes 15 | primes(N)=L => 16 | A=new_array(N), 17 | foreach(I in 2..floor(sqrt(N))) 18 | if (var(A[I])) then 19 | foreach(J in I**2..I..N) 20 | A[J]=0 21 | end 22 | end 23 | end, 24 | L=[I : I in 2..N, var(A[I])]. 25 | */ 26 | 27 | -------------------------------------------------------------------------------- /exs/euler/p100.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=100 3 | Haskell: http://www.haskell.org/haskellwiki/Euler_problems 4 | *********************************************************/ 5 | 6 | main => 7 | writeln(nextAB(14,20)). 8 | 9 | nextAB(A,B) = (A,B), A+B>1000000000000 => true. 10 | nextAB(A,B) = nextAB(3*A+2*B+2, 4*A+3*B+3). 11 | 12 | -------------------------------------------------------------------------------- /exs/euler/p106.pi: -------------------------------------------------------------------------------- 1 | binomial(X,Y) = prodxy(Y+1,X) div prodxy(1,X-Y). 2 | 3 | prodxy(X,Y) = prod(X..Y). 4 | 5 | % -- http://mathworld.wolfram.com/DyckPath.html 6 | catalan(N) = binomial(2*N,N) div (N+1). 7 | 8 | calc(N) = sum([E*(C-D) : A in 1..(N div 2), 9 | Mu2 = A*2, 10 | C = binomial(Mu2,A) div 2, 11 | D = catalan(A), 12 | E = binomial(N,Mu2)]). 13 | 14 | main => writeln(calc(12)). 15 | -------------------------------------------------------------------------------- /exs/euler/p108.pi: -------------------------------------------------------------------------------- 1 | import cp. 2 | 3 | main => 4 | N :: 5..99999, 5 | R #> 0, 6 | S #> 0, 7 | R*S #= N*N, % 1/(N+R) + 1/(N+S) = 1/N 8 | R #=< S, 9 | S #< N*N, 10 | % writeln((R,S)), 11 | solve_all([R,S])=All, 12 | All.length > 1000. 13 | 14 | 15 | -------------------------------------------------------------------------------- /exs/euler/p10_rb.pi: -------------------------------------------------------------------------------- 1 | 2 | myprime(X) => 3 | foreach (I in 2..floor(sqrt(X))) 4 | X mod I !== 0 5 | end. 6 | 7 | myprimes(Upto) =Primes => 8 | Primes = [I : I in 2..Upto, myprime(I)]. 9 | 10 | main => 11 | X = 2000000, 12 | Primes = myprimes(X), 13 | writeln(hhhhhhhhh), 14 | statistics, 15 | writeln(sum(Primes)). -------------------------------------------------------------------------------- /exs/euler/p11.pi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/exs/euler/p11.pi -------------------------------------------------------------------------------- /exs/euler/p12.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=12 3 | 4 | The sequence of triangle numbers is generated by adding the 5 | natural numbers. So the 7th triangle number would be 1 + 2 6 | + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 7 | 8 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... 9 | 10 | Let us list the factors of the first seven triangle numbers: 11 | 12 | 1: 1 13 | 3: 1,3 14 | 6: 1,2,3,6 15 | 10: 1,2,5,10 16 | 15: 1,3,5,15 17 | 21: 1,3,7,21 18 | 28: 1,2,4,7,14,28 19 | 20 | We can see that 28 is the first triangle number to have 21 | over five divisors. 22 | 23 | What is the value of the first triangle number to have over 24 | five hundred divisors? 25 | 26 | See also http://www.hakank.org/picat/euler12.pi 27 | *********************************************************/ 28 | 29 | main => 30 | I = 1, 31 | Num = 0, 32 | NDivisors = 0, 33 | while (NDivisors <= 500) 34 | Num := Num+I, 35 | NDivisors := countDivisors(Num), 36 | I := I+1 37 | end, 38 | writef("I = %w, SIGMA_{1}_{%w} = %w, num_of_divisors=%w%n", I-1, I-1, Num, NDivisors). 39 | 40 | countDivisors(N) = C => 41 | Count = 0, 42 | End = to_integer(sqrt(N)), 43 | foreach (I in 1..End-1) 44 | if (N mod I == 0) then 45 | Count := Count+2 46 | end 47 | end, 48 | if (End*End==N) then 49 | Count := Count+1 50 | end, 51 | C = Count. 52 | 53 | -------------------------------------------------------------------------------- /exs/euler/p14.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=14 3 | 4 | The following iterative sequence is defined for the set of 5 | positive integers: 6 | 7 | n -> n/2 (n is even) 8 | n -> 3n + 1 (n is odd) 9 | 10 | Using the rule above and starting with 13, we generate the 11 | following sequence: 12 | 13 | 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 14 | 15 | It can be seen that this sequence (starting at 13 and 16 | finishing at 1) contains 10 terms. Although it has not been 17 | proved yet (Collatz Problem), it is thought that all 18 | starting numbers finish at 1. 19 | 20 | Which starting number, under one million, produces the 21 | longest chain? 22 | 23 | NOTE: Once the chain starts the terms are allowed to go 24 | above one million. 25 | *********************************************************/ 26 | 27 | main => 28 | max_chain(N,Chain,Len), 29 | writef("N=%w\nLen=%w%nChain=%w%n",N,Len,Chain). 30 | 31 | table (-,-,max) 32 | max_chain(N,Chain,Len) => 33 | between(1,1000000,N), 34 | gen(N,Chain,Len). 35 | 36 | table (+,-,-) 37 | gen(1,Chain,Len) => Chain=[1], Len=1. 38 | gen(N,Chain,Len), N mod 2 ==0 => 39 | gen(N div 2,Chain1,Len1), 40 | Chain=[N|Chain1], 41 | Len=Len1+1. 42 | gen(N,Chain,Len) => 43 | gen(3*N+1,Chain1,Len1), 44 | Chain=[N|Chain1], 45 | Len=Len1+1. 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /exs/euler/p15.pi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/exs/euler/p15.pi -------------------------------------------------------------------------------- /exs/euler/p16.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=10 3 | 4 | 2**15 = 32768 and the sum of its digits is 3+2+7+6+8 = 26. 5 | 6 | What is the sum of the digits of the number 2**1000? 7 | *********************************************************/ 8 | 9 | main => 10 | writef("The sum of the digits of the number 2**1000 is %w%n", 11 | sum([to_integer(D) : D in (2**1000).to_string()])). 12 | 13 | 14 | -------------------------------------------------------------------------------- /exs/euler/p1_rb.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=1 3 | 4 | If we list all the natural numbers below 10 that are 5 | multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these 6 | multiples is 23. 7 | 8 | Find the sum of all the multiples of 3 or 5 below 1000. 9 | 10 | ANS = 233168 11 | *********************************************************/ 12 | 13 | main => 14 | S = 0, 15 | foreach (I in 1..999) 16 | if (I mod 3 = 0; I mod 5 = 0) then 17 | S:=S+I 18 | end 19 | end, 20 | writef("Sum of all the multiples of 3 or 5 below 1000 is %w%n",S). -------------------------------------------------------------------------------- /exs/euler/p2.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=2 3 | 4 | Each new term in the Fibonacci sequence is generated by 5 | adding the previous two terms. By starting with 1 and 2, 6 | the first 10 terms will be: 7 | 8 | 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 9 | 10 | By considering the terms in the Fibonacci sequence whose 11 | values do not exceed four million, find the sum of the 12 | even-valued terms. 13 | *********************************************************/ 14 | 15 | main => 16 | S = 0, 17 | I = 1, 18 | F = fib(I), 19 | while (F <= 4000000) 20 | if (F mod 2 = 0) then 21 | S:=S+F 22 | end, 23 | I:=I+1, 24 | F:=fib(I) 25 | end, 26 | writef("Sum of the even-valued terms is %w%n",S). 27 | 28 | table 29 | fib(1) = 1. 30 | fib(2) = 2. 31 | fib(N)=fib(N-1)+fib(N-2). 32 | 33 | /* here is another definition 34 | 35 | fibs(Upto) = Fibs => 36 | L = [2,1], 37 | F = L[1]+L[2], 38 | while (F <= Upto) 39 | L := [F|L], 40 | F := L[1]+L[2] 41 | end, 42 | Fibs = L. 43 | 44 | main => 45 | writeln(sum([X : X in fibs(4000000), even(X)])). 46 | */ 47 | -------------------------------------------------------------------------------- /exs/euler/p20.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=20 3 | 4 | Find the sum of the digits in the number 100! 5 | *********************************************************/ 6 | 7 | main => 8 | F = factorial(100), % factorial defined in module 'math' 9 | println(sum([to_integer(D) : D in F.to_string()])). 10 | 11 | -------------------------------------------------------------------------------- /exs/euler/p206.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=206 3 | 4 | Find the unique positive integer whose square has the form 5 | 1_2_3_4_5_6_7_8_9_0, where each "_" is a single digit. 6 | 7 | *********************************************************/ 8 | % X's last digit must be 0 and X*X's last two digits must be 00 9 | main => 10 | I = sqrt(19293949596979899).to_integer(), 11 | Found=fail, 12 | while (not Found) 13 | if ((I mod 10 == 3 || I mod 10 == 7) && (I*I).to_string()=['1',_,'2',_,'3',_,'4',_,'5',_,'6',_,'7',_,'8'|_]) then 14 | writeln(I*10), 15 | Found := true 16 | else 17 | I := I-1 18 | end 19 | end. 20 | 21 | -------------------------------------------------------------------------------- /exs/euler/p21.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #21 in Picat. 4 | 5 | Problem 21 6 | """ 7 | Let d(n) be defined as the sum of proper divisors of n (numbers less 8 | than n which divide evenly into n). 9 | If d(a) = b and d(b) = a, where a /= b, then a and b are an amicable 10 | pair and each of a and b are called amicable numbers. 11 | 12 | For example, the proper divisors of 220 are 13 | 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. 14 | The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. 15 | 16 | Evaluate the sum of all the amicable numbers under 10000. 17 | """ 18 | 19 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 20 | See also my Picat page: http://www.hakank.org/picat/ 21 | */ 22 | 23 | 24 | main => go. 25 | 26 | go => time(euler21). 27 | 28 | euler21 => 29 | S = new_map(), 30 | foreach(A in 1..10000-1) 31 | B = sum_divisors2(A), 32 | C = sum_divisors2(B), 33 | if A != B, A == C then 34 | S.put(A, 1), 35 | S.put(B, 1) 36 | end 37 | end, 38 | % writeln(s=S), 39 | println(sum(S.keys())), 40 | nl. 41 | 42 | table 43 | sum_divisors2(N) = Sum => 44 | D = floor(sqrt(N)), 45 | Sum1 = 1, 46 | foreach(I in 2..D, N mod I == 0) 47 | Sum1 := Sum1+I, 48 | if I != N div I then 49 | Sum1 := Sum1 + N div I 50 | end 51 | end, 52 | Sum = Sum1. 53 | -------------------------------------------------------------------------------- /exs/euler/p22.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #22 in Picat. 4 | 5 | """ 6 | Using names.txt (right click and 'Save Link/Target As...'), a 46K 7 | text file containing over five-thousand first names, begin by sorting 8 | it into alphabetical order. Then working out the alphabetical value 9 | for each name, multiply this value by its alphabetical position in the 10 | list to obtain a name score. 11 | 12 | For example, when the list is sorted into alphabetical order, COLIN, 13 | which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in 14 | the list. So, COLIN would obtain a score of 938 53 = 49714. 15 | 16 | What is the total of all the name scores in the file?") 17 | """ 18 | 19 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 20 | See also my Picat page: http://www.hakank.org/picat/ 21 | 22 | */ 23 | 24 | import util. 25 | 26 | main => go. 27 | 28 | go => euler22. % , euler22b. 29 | 30 | euler22 => 31 | Names = split(read_file_chars("names.txt"),","), 32 | A = 1, 33 | Sum = 0, 34 | foreach(Name in Names.sort()) 35 | CodeSum = sum(to_code([C : C in Name, C != '"'])), % " 36 | Sum := Sum + A*CodeSum, 37 | A := A + 1 38 | end, 39 | writeln(Sum). 40 | 41 | % tighter 42 | euler22b => 43 | Names = split(read_file_chars("euler22_names.txt"),",").sort(), 44 | sum([A*sum(to_code([C:C in Name,C!='"'])):{Name,A}in zip(Names,1..Names.length)]).writeln(). 45 | 46 | 47 | 48 | % convert a string to position code 49 | % A=1, B=2, etc 50 | to_code(S) = [C.ord()-64 : C in S]. 51 | -------------------------------------------------------------------------------- /exs/euler/p28.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #28 in Picat. 4 | 5 | Problem 28 6 | """ 7 | Starting with the number 1 and moving to the right in a clockwise 8 | direction a 5 by 5 spiral is formed as follows: 9 | 10 | 21 22 23 24 25 11 | 20 7 8 9 10 12 | 19 6 1 2 11 13 | 18 5 4 3 12 14 | 17 16 15 14 13 15 | 16 | It can be verified that the sum of the numbers on the diagonals is 101. 17 | 18 | What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way? 19 | """ 20 | 21 | 22 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 23 | See also my Picat page: http://www.hakank.org/picat/ 24 | 25 | */ 26 | 27 | main => go. 28 | 29 | go => time(euler28). 30 | 31 | euler28 => 32 | S = 1, 33 | N = 3, 34 | while (N <= 1001) 35 | S := S + 4 * N**2 - 6 * N + 6, 36 | N := N + 2 37 | end, 38 | println(S). 39 | -------------------------------------------------------------------------------- /exs/euler/p29.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=29 3 | 4 | How many distinct terms are in the sequence generated by a**b 5 | for 2 <= a <= 100 and 2 <= b <= 100? 6 | 7 | See also http://www.hakank.org/picat/euler29.pi 8 | *********************************************************/ 9 | 10 | main => 11 | L = [A**B : A in 2 .. 100, B in 2.. 100], 12 | println(L.remove_dups().length). -------------------------------------------------------------------------------- /exs/euler/p2_rb.pi: -------------------------------------------------------------------------------- 1 | fibs(Upto) = Fibs => 2 | L = [2,1], 3 | F = L[1]+L[2], 4 | while (F <= Upto) 5 | L := [F|L], 6 | F := L[1]+L[2] 7 | end, 8 | Fibs = L. 9 | 10 | main => 11 | writeln(sum([X : X in fibs(4000000), even(X)])). 12 | -------------------------------------------------------------------------------- /exs/euler/p3.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=3 3 | 4 | The prime factors of 13195 are 5, 7, 13 and 29. 5 | 6 | What is the largest prime factor of the number 600851475143 ? 7 | *********************************************************/ 8 | 9 | main => 10 | F=largest_pime_factor(600851475143), 11 | writef("The largest prime factor of 600851475143 is %w%n", F). 12 | 13 | largest_pime_factor(N)=F => 14 | SF = smallest_factor(N,2,to_integer(sqrt(N))), 15 | while (SF !== N) 16 | N := N div SF, 17 | SF := smallest_factor(N,SF,to_integer(sqrt(N))) 18 | end, 19 | F=N. 20 | 21 | smallest_factor(N,I,End)=F, I<=End => 22 | if (N mod I == 0) then 23 | F = I 24 | else 25 | F=smallest_factor(N,I+1,End) 26 | end. 27 | smallest_factor(N,_I,_End)=F => F=N. 28 | -------------------------------------------------------------------------------- /exs/euler/p30.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #30 in Picat. 4 | 5 | Problem 30 6 | """ 7 | Surprisingly there are only three numbers that can be written 8 | as the sum of fourth powers of their digits: 9 | 10 | 1634 = 1^(4) + 6^(4) + 3^(4) + 4^(4) 11 | 8208 = 8^(4) + 2^(4) + 0^(4) + 8^(4) 12 | 9474 = 9^(4) + 4^(4) + 7^(4) + 4^(4) 13 | 14 | As 1 = 1^(4) is not a sum it is not included. 15 | 16 | The sum of these numbers is 1634 + 8208 + 9474 = 19316. 17 | 18 | Find the sum of all the numbers that can be written as the sum of 19 | fifth powers of their digits. 20 | """ 21 | 22 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 23 | See also my Picat page: http://www.hakank.org/picat/ 24 | 25 | */ 26 | 27 | main => go. 28 | 29 | go => time(euler30). % , time(euler30b). 30 | 31 | euler30 => 32 | T = 0, 33 | M = 5, 34 | foreach(N in 10..6*9**5) 35 | if N == sum([I**M : I in [J.to_integer() : J in N.to_string() ]]) then 36 | T := T + N 37 | end 38 | end, 39 | println(T). 40 | 41 | 42 | euler30b => 43 | println(sum([N : N in 10..6*9**5, 44 | N == sum([I**5 : I in [J.to_integer() : J in N.to_string()]])])). 45 | -------------------------------------------------------------------------------- /exs/euler/p31.pi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/exs/euler/p31.pi -------------------------------------------------------------------------------- /exs/euler/p33.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #33 in Picat. 4 | 5 | """ 6 | The fraction 49/98 is a curious fraction, as an inexperienced mathematician in 7 | attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, 8 | is obtained by cancelling the 9s. 9 | 10 | We shall consider fractions like, 30/50 = 3/5, to be trivial examples. 11 | 12 | There are exactly four non-trivial examples of this type of fraction, less than 13 | one in value, and containing two digits in the numerator and denominator. 14 | 15 | If the product of these four fractions is given in its lowest common terms, find 16 | the value of the denominator. 17 | """ 18 | 19 | 20 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 21 | See also my Picat page: http://www.hakank.org/picat/ 22 | 23 | */ 24 | 25 | main => go. 26 | 27 | go => time(euler33). 28 | 29 | euler33 => 30 | S = 1, 31 | foreach(Y in 1..9,Z in Y..9) 32 | X = 9.0*Y*Z/(10.0*Y-Z), 33 | if 1.0*floor(X)==X*1.0, Y/Z < 1.0, X < 10.0 then 34 | S := (S*Y)/Z % , 35 | % println([X,Y, Z, (floor(10*Y+X)),"/", (floor(Z+10*X)), Y,"/",Z, floor(1/S)]) 36 | end 37 | end, 38 | println(floor(1/S)). 39 | -------------------------------------------------------------------------------- /exs/euler/p34.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #34 in Picat. 4 | 5 | Problem 34 6 | """ 7 | 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. 8 | 9 | Find the sum of all numbers which are equal to the sum of the 10 | factorial of their digits. 11 | 12 | Note: as 1! = 1 and 2! = 2 are not sums they are not included. 13 | """ 14 | 15 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 16 | See also my Picat page: http://www.hakank.org/picat/ 17 | 18 | */ 19 | 20 | main => go. 21 | 22 | go => time(euler34). 23 | 24 | euler34 => 25 | Sum = sum([ N : N in 10..100000, 26 | N = sum([I.to_integer().factorial() : I in N.to_string()])]), 27 | println(Sum). 28 | -------------------------------------------------------------------------------- /exs/euler/p38.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #38 in Picat. 4 | 5 | """ 6 | Take the number 192 and multiply it by each of 1, 2, and 3: 7 | 8 | 192 × 1 = 192 9 | 192 × 2 = 384 10 | 192 × 3 = 576 11 | 12 | By concatenating each product we get the 1 to 9 pandigital, 13 | 192384576. We will call 192384576 the concatenated product of 192 14 | and (1,2,3) 15 | 16 | The same can be achieved by starting with 9 and multiplying by 17 | 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the 18 | concatenated product of 9 and (1,2,3,4,5). 19 | 20 | What is the largest 1 to 9 pandigital 9-digit number that can be 21 | formed as the concatenated product of an integer with 22 | (1,2, ... , n) where n > 1? 23 | """ 24 | 25 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 26 | See also my Picat page: http://www.hakank.org/picat/ 27 | 28 | */ 29 | 30 | main => go. 31 | 32 | go => time(euler38). 33 | 34 | euler38 => 35 | MaxN = 0, 36 | foreach(N in 9876..-1..9, S = N.to_string(), S[1] != 49+9, MaxN == 0) 37 | I = 2, 38 | while(S.length < 9) 39 | S := S ++ (N*I).to_string(), 40 | I := I + 1 41 | end, 42 | SLen = S.length, 43 | if SLen == 9, is_pandigital(S) then 44 | MaxN := S 45 | end 46 | 47 | end, 48 | 49 | println(MaxN). 50 | 51 | 52 | is_pandigital(L) => 53 | L.length == 9, not member('0',L), [I=1 : I in L.to_string()].new_map().keys().length == 9. 54 | -------------------------------------------------------------------------------- /exs/euler/p39.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=39 3 | 4 | If p is the perimeter of a right angle triangle with 5 | integral length sides, {a,b,c}, there are exactly three 6 | solutions for p = 120. 7 | 8 | {20,48,52}, {24,45,51}, {30,40,50} 9 | 10 | For which value of p <= 1000, is the number of solutions 11 | maximised? 12 | *********************************************************/ 13 | 14 | import cp. 15 | 16 | main ?=> 17 | M = get_global_map(), 18 | M.put(val,(0,0)), 19 | between(1,1000,P), 20 | Len = num_solutions(P), 21 | if (Len>M.get(val).second_of_pair()) then 22 | M.put(val,(P,Len)) 23 | end, 24 | fail. 25 | main => 26 | M = get_global_map(), 27 | println(M.get(val)), 28 | M.clear(). 29 | 30 | second_of_pair((_X,Y)) = Y. 31 | 32 | num_solutions(I) = N => 33 | Vars = [A, B, C], 34 | Vars :: 1 .. I div 2 + 1, 35 | 36 | A #<= B, 37 | B #< C, 38 | A + B #> C, 39 | A + B + C #= I, 40 | A * A + B * B #= C * C, 41 | 42 | N = solve_all([split],Vars).length. 43 | -------------------------------------------------------------------------------- /exs/euler/p4.pi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/exs/euler/p4.pi -------------------------------------------------------------------------------- /exs/euler/p42.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #42 in Picat. 4 | 5 | """ 6 | The nth term of the sequence of triangle numbers is given by, 7 | tn = 1/2*n*(n+1); 8 | so the first ten triangle numbers are: 9 | 10 | 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... 11 | 12 | By converting each letter in a word to a number corresponding to its 13 | alphabetical position and adding these values we form a word value. For example, 14 | the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value 15 | is a triangle number then we shall call the word a triangle word. 16 | 17 | Using words.txt (right click and 'Save Link/Target As...'), a 16K text file 18 | containing nearly two-thousand common English words, how many 19 | are triangle words? 20 | """ 21 | 22 | 23 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 24 | See also my Picat page: http://www.hakank.org/picat/ 25 | 26 | */ 27 | 28 | import util. 29 | 30 | main => go. 31 | 32 | go => time(euler42). 33 | 34 | euler42 => 35 | Words = [[W : W in Word, W != '"'] : Word in split(read_file_chars("words.txt"), ",")], 36 | T20 = [triangle_number(I) : I in 1..20], 37 | Len = [WW : WW in Words, membchk(get_score(WW),T20)].length, 38 | println(Len). 39 | 40 | 41 | triangle_number(N) = (N*(N+1)) div 2. 42 | 43 | get_score(Name) = Total => 44 | Total = 0, 45 | foreach(I in 1..Name.length) 46 | Total := Total+(ord(Name[I])-64) 47 | end. 48 | -------------------------------------------------------------------------------- /exs/euler/p44.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #44 in Picat. 4 | 5 | """ 6 | Pentagonal numbers are generated by the formula, P(n)=n(3n−1)/2. 7 | The first ten pentagonal numbers are: 8 | 9 | 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ... 10 | 11 | It can be seen that P(4) + P(7) = 22 + 70 = 92 = P(8). However, 12 | their difference, 70 − 22 = 48, is not pentagonal. 13 | 14 | Find the pair of pentagonal numbers, P(j) and P(k), for which their sum 15 | and difference is pentagonal and D = |P(k) − P(j)| is minimised; what 16 | is the value of D? 17 | """ 18 | 19 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 20 | See also my Picat page: http://www.hakank.org/picat/ 21 | 22 | */ 23 | 24 | main => go. 25 | 26 | go => time(euler44). 27 | 28 | euler44 => 29 | S = [pent(N) : N in 1..2500], 30 | T = new_map([V=1 : V in S]), 31 | D = 100000000, 32 | foreach(J in S, K in S, 33 | J < K, 34 | A = J+K, 35 | T.has_key(A), 36 | B = abs(J-K), 37 | T.has_key(B), 38 | B < D) 39 | D := B 40 | end, 41 | println(D). 42 | 43 | 44 | pent(N) = N*(3*N-1) div 2. 45 | -------------------------------------------------------------------------------- /exs/euler/p45.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #45 in Picat. 4 | 5 | """ 6 | Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: 7 | 8 | Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ... 9 | Pentagonal Pn=n(3n−1)/2 1, 5, 12, 22, 35, ... 10 | Hexagonal Hn=n(2n−1) 1, 6, 15, 28, 45, ... 11 | 12 | It can be verified that T(285) = P(165) = H(143) = 40755. 13 | 14 | Find the next triangle number that is also pentagonal and hexagonal. 15 | """ 16 | 17 | 18 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 19 | See also my Picat page: http://www.hakank.org/picat/ 20 | 21 | */ 22 | 23 | main => go. 24 | 25 | go => time(euler45). 26 | 27 | euler45 => 28 | T = 285+1, 29 | TT = tri(T), 30 | P = 165, 31 | PP = pent(P), 32 | H = 143, 33 | HH = hex(H), 34 | while (TT != PP; PP != HH) 35 | T := T+1, 36 | TT := tri(T), 37 | if TT > PP then P := P+1, PP := pent(P) end, 38 | if PP > HH then H := H+1, HH := hex(H) end, 39 | if TT > HH then H := H+1, HH := hex(H) end 40 | end, 41 | println(TT). 42 | 43 | 44 | pent(N) = N*(3*N-1) div 2. 45 | tri(N) = N*(N+1) div 2. 46 | hex(N) = N*(2*N-1). 47 | -------------------------------------------------------------------------------- /exs/euler/p46.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #46 in Picat. 4 | 5 | """ 6 | It was proposed by Christian Goldbach that every odd composite number can be 7 | written as the sum of a prime and twice a square. 8 | 9 | 9 = 7 + 2×1^2 10 | 15 = 7 + 2×2^2 11 | 21 = 3 + 2×3^2 12 | 25 = 7 + 2×3^2 13 | 27 = 19 + 2×2^2 14 | 33 = 31 + 2×1^2 15 | 16 | It turns out that the conjecture was false. 17 | 18 | What is the smallest odd composite that cannot be written as the 19 | sum of a prime and twice a square? 20 | """ 21 | 22 | 23 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 24 | See also my Picat page: http://www.hakank.org/picat/ 25 | 26 | */ 27 | 28 | main => go. 29 | 30 | go => time(euler46). 31 | 32 | euler46 => 33 | Res = 0, 34 | GotIt = 0, 35 | foreach(I in 3..2..10000, not prime(I), GotIt == 0) 36 | S = round(sqrt(I/2)), 37 | Found = 0, 38 | foreach(J in 1..S, Found == 0) 39 | Ts = J*J*2, 40 | if prime(abs(I-Ts)) then 41 | Found := 1 42 | end 43 | end, 44 | if Found == 0 then 45 | Res := I, 46 | GotIt := 1 47 | end 48 | end, 49 | 50 | println(res=Res). 51 | 52 | -------------------------------------------------------------------------------- /exs/euler/p47.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #47 in Picat. 4 | 5 | """ 6 | The first two consecutive numbers to have two distinct prime factors are: 7 | 8 | 14 = 2 x 7 9 | 15 = 3 x 5 10 | 11 | The first three consecutive numbers to have three distinct 12 | prime factors are: 13 | 14 | 644 = 2^2 x 7 x 23 15 | 645 = 3 x 5 x 43 16 | 646 = 2 x 17 x 19. 17 | 18 | Find the first four consecutive integers to have four distinct primes 19 | factors. What is the first of these numbers? 20 | """ 21 | 22 | 23 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 24 | See also my Picat page: http://www.hakank.org/picat/ 25 | 26 | */ 27 | 28 | main => go. 29 | 30 | go => time(euler47). 31 | 32 | euler47 => 33 | MaxN = 1000000, 34 | % F = [0 : I in 1..MaxN], 35 | % It's much faster using an array. 36 | F = new_array(MaxN), 37 | foreach(I in 1..MaxN) F[I] := 0 end, 38 | foreach(I in 2..MaxN-1) 39 | if F[I] == 0 then 40 | foreach(J in 2*I..I..MaxN-1) 41 | F[J] := F[J] + 1 42 | end 43 | end 44 | end, 45 | 46 | Goal = [4,4,4,4], 47 | % println(goal=Goal), 48 | Found = 0, 49 | foreach(I in 2..MaxN-3, Found==0) 50 | if [F[J] : J in I..I+3] == Goal then 51 | println(I), 52 | Found := 1 53 | end 54 | end. 55 | -------------------------------------------------------------------------------- /exs/euler/p48.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=48 3 | 4 | The series, 1**1 + 2**2 + 3**3 + ... + 10**10 = 10405071317. 5 | 6 | Find the last ten digits of the series, 1**1 + 2**2 + 3**3 + ... 7 | + 1000**1000. 8 | 9 | See also http://www.hakank.org/picat/euler48.pi 10 | *********************************************************/ 11 | 12 | main => 13 | Mod = 10 ** 10, 14 | Sum = 0, 15 | foreach (I in 1 .. 1000) 16 | Sum := (Sum + (I ** I)) mod Mod 17 | end, 18 | println(Sum). -------------------------------------------------------------------------------- /exs/euler/p5.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=5 3 | 4 | 2520 is the smallest number that can be divided by each of 5 | the numbers from 1 to 10 without any remainder. 6 | 7 | What is the smallest positive number that is evenly 8 | divisible by all of the numbers from 1 to 20? 9 | *********************************************************/ 10 | 11 | main => 12 | L = 1, 13 | foreach (I in 1 .. 20) 14 | L := I * L div gcd(I,L) % gcd/2 defined in math 15 | end, 16 | writef("The smallest positive number is %w%n",L). 17 | 18 | -------------------------------------------------------------------------------- /exs/euler/p50.pi: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Euler #50 in Picat. 4 | 5 | Problem 50 6 | """ 7 | The prime 41, can be written as the sum of six consecutive primes: 8 | 41 = 2 + 3 + 5 + 7 + 11 + 13 9 | 10 | This is the longest sum of consecutive primes that adds to a prime 11 | below one-hundred. 12 | 13 | The longest sum of consecutive primes below one-thousand that adds to a prime, 14 | contains 21 terms, and is equal to 953. 15 | 16 | Which prime, below one-million, can be written as the sum of the most 17 | consecutive primes? 18 | """ 19 | 20 | 21 | This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com 22 | See also my Picat page: http://www.hakank.org/picat/ 23 | 24 | */ 25 | 26 | main => go. 27 | 28 | go => time(euler50). 29 | 30 | euler50 => 31 | N = 10000, 32 | Primes = [P : P in 1..N, prime(P)].to_array(), 33 | Found = 0, 34 | foreach(Len in 550..-1..21, Found == 0) 35 | foreach(Offset in 1..549, 36 | Found == 0, 37 | prime(sum([Primes[J] : J in Offset+1..Offset+Len]))) 38 | PP = sum([Primes[J] : J in Offset+1..Offset+Len]), 39 | if PP < 1000000 then 40 | Found := PP 41 | end 42 | end 43 | end, 44 | writeln(Found). 45 | -------------------------------------------------------------------------------- /exs/euler/p52.pi: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | Permuted multiples 3 | Problem 52 4 | It can be seen that the number, 125874, and its double, 251748, 5 | contain exactly the same digits, but in a different order. 6 | 7 | Find the smallest positive integer, x, such that 2x, 3x, 4x, 8 | 5x, and 6x, contain the same digits. 9 | 10 | ************************************************************/ 11 | main => time(go). 12 | 13 | go => 14 | N = 102, 15 | while (not is_perm(N.to_string().sort(), N, 2)) 16 | N := N + 3 /*Add three each time because of the divisible by 3 rule*/ 17 | 18 | end, 19 | writef("The smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits is %w", N). 20 | 21 | 22 | is_perm(_S,_N,7) => true. 23 | is_perm(S,N,D) => 24 | NewN =(D*N), 25 | floor(log10(N)) == floor(log10(NewN)), 26 | S == to_string(NewN).sort(), 27 | is_perm(S, N, D+1). 28 | -------------------------------------------------------------------------------- /exs/euler/p6.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=6 3 | 4 | Find the difference between the sum of the squares of the 5 | first one hundred natural numbers and the square of the sum. 6 | *********************************************************/ 7 | 8 | main => 9 | N = 100, 10 | Sum = 0, 11 | Sum2 = 0, 12 | foreach (I in 1..N) 13 | Sum := Sum + I, 14 | Sum2 := Sum2 + I * I 15 | end, 16 | writef("The difference is %w%n", Sum * Sum - Sum2). 17 | -------------------------------------------------------------------------------- /exs/euler/p7.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=7 3 | 4 | By listing the first six prime numbers: 2, 3, 5, 7, 11, and 5 | 13, we can see that the 6th prime is 13. 6 | 7 | What is the 10 001st prime number? 8 | *********************************************************/ 9 | 10 | main => 11 | I = 11, 12 | Count = 4, 13 | while (Count !== 10001) 14 | if (prime(I)) then % prime defined in module math. 15 | Count := Count+1 16 | end, 17 | I := I + 2 18 | end, 19 | writef("The 10001st prime number is %w%n",I-2). 20 | 21 | 22 | -------------------------------------------------------------------------------- /exs/euler/p7_old.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=7 3 | 4 | By listing the first six prime numbers: 2, 3, 5, 7, 11, and 5 | 13, we can see that the 6th prime is 13. 6 | 7 | What is the 10 001st prime number? 8 | *********************************************************/ 9 | 10 | main => 11 | I = 2, 12 | Count = 0, 13 | while (Count !== 10001) 14 | if ( isPrime(I) ) then 15 | Count := Count+1, 16 | writef("%d %d\n",Count,I) 17 | end, 18 | I := I + 1 19 | end, 20 | writef("The 10001st prime number is %w%n",I-1). 21 | 22 | isPrime(N),N mod 2 == 0 => fail. 23 | isPrime(N),N mod 3 == 0 => fail. 24 | isPrime(N),N mod 5 == 0 => fail. 25 | isPrime(N),N mod 7 == 0 => fail. 26 | isPrime(N) => 27 | foreach (I in 3..2..sqrt(N)) 28 | N mod I != 0 29 | end. 30 | -------------------------------------------------------------------------------- /exs/euler/p9.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=9 3 | 4 | There exists exactly one Pythagorean triplet for which 5 | 6 | a + b + c = 1000. 7 | 8 | Find the product abc. 9 | *********************************************************/ 10 | import cp. 11 | 12 | main => 13 | Triplet = [A,B,C], 14 | Triplet :: 1..1000, 15 | A**2 + B**2 #= C**2, 16 | A+B+C #= 1000, 17 | A #=< B, 18 | B #=< C, 19 | solve(Triplet), 20 | writef("The Pythagorean triplet is %w%n",Triplet), 21 | writef("The product is %w%n",A*B*C). 22 | 23 | -------------------------------------------------------------------------------- /exs/euler/p99.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=99 3 | *********************************************************/ 4 | 5 | import util. 6 | 7 | main => 8 | Lines = read_file_lines("base_exp.txt"), 9 | TokLists = [split(Line,",") : Line in Lines], 10 | NumLists = [[to_integer(BStr),to_integer(EStr)] : [BStr,EStr] in TokLists], 11 | ResList = [E*log(B) : [B,E] in NumLists], 12 | writeln(ResList.find_first_of(max(ResList))). 13 | 14 | -------------------------------------------------------------------------------- /exs/euler/p9_rb.pi: -------------------------------------------------------------------------------- 1 | % Euclid's formula yields Pythagorean triples for integers m and n with m < n: 2 | % a = m**2 - n**2 ; b = 2*m*n ; c = m**2 + n**2 3 | 4 | euclids(Upto) = Triples => 5 | Triples = [[M**2-N**2,2*M*N,M**2+N**2] : M in 2..Upto, N in 1..M]. 6 | 7 | main => 8 | X = 1000, 9 | foreach([A,B,C] in euclids(X div 2)) 10 | if A + B + C == X then 11 | writeln(A * B * C), 12 | halt 13 | end 14 | end. 15 | 16 | -------------------------------------------------------------------------------- /exs/euler/pi_rb.pi: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | http://projecteuler.net/problem=1 3 | 4 | If we list all the natural numbers below 10 that are 5 | multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these 6 | multiples is 23. 7 | 8 | Find the sum of all the multiples of 3 or 5 below 1000. 9 | 10 | ANS = 233168 11 | *********************************************************/ 12 | 13 | main => 14 | S = 0, 15 | foreach (I in 1..999) 16 | if (I mod 3 = 0; I mod 5 = 0) then 17 | S:=S+I 18 | end, 19 | end, 20 | writef("Sum of all the multiples of 3 or 5 below 1000 is %w%n",S). -------------------------------------------------------------------------------- /exs/euler/test.txt: -------------------------------------------------------------------------------- 1 | 895447,504922 2 | 999665,500894 3 | -------------------------------------------------------------------------------- /exs/mip/bqueens.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | queens(100). 5 | 6 | queens(N) => 7 | Qs = new_array(N,N), 8 | Qs :: 0..1, 9 | foreach(I in 1..N) % 1 in each row 10 | sum([Qs[I,J] : J in 1..N]) #= 1 11 | end, 12 | foreach(J in 1..N) % 1 in each column 13 | sum([Qs[I,J] : I in 1..N]) #= 1 14 | end, 15 | foreach(K in 1-N..N-1) % at most one 16 | sum([Qs[I,J] : I in 1..N, J in 1..N, I-J=:=K]) #=< 1 17 | end, 18 | foreach(K in 2..2*N) % at most one 19 | sum([Qs[I,J] : I in 1..N, J in 1..N, I+J=:=K]) #=< 1 20 | end, 21 | solve(Qs), 22 | foreach(I in 1..N) 23 | writeln(Qs[I]) 24 | end. 25 | 26 | -------------------------------------------------------------------------------- /exs/mip/coin.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | N = 31, 5 | C = 14, 6 | time2(coins(N, C)). 7 | 8 | coins(N,C) => 9 | X = new_array(N,N), 10 | X :: 0..1, 11 | 12 | foreach (I in 1..N) 13 | C #= sum([X[I,J] : J in 1..N]), % rows 14 | C #= sum([X[J,I] : J in 1..N]) % columns 15 | end, 16 | 17 | % quadratic horizontal distance 18 | Sum #= sum([(X[I,J] * abs(I-J)*abs(I-J)) : I in 1..N, J in 1..N]), 19 | 20 | solve($[min(Sum)],X), 21 | println(sum=Sum). 22 | -------------------------------------------------------------------------------- /exs/mip/diet.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | data(Prices,Limits,{Calories,Chocolate,Sugar,Fat}), 5 | Len = length(Prices), 6 | Xs = new_array(Len), 7 | Xs :: 0..10, 8 | 9 | scalar_product(Calories,Xs, #>=,Limits[1]), 10 | scalar_product(Chocolate,Xs,#>=,Limits[2]), 11 | scalar_product(Sugar,Xs, #>=,Limits[3]), 12 | scalar_product(Fat,Xs, #>=,Limits[4]), 13 | scalar_product(Prices,Xs,XSum), 14 | solve($[min(XSum)],Xs), 15 | writeln(Xs). 16 | 17 | % plain scalar product 18 | scalar_product(A,Xs,Product) => 19 | Product #= sum([A[I]*Xs[I] : I in 1..A.length]). 20 | 21 | scalar_product(A,Xs,Rel,Product) => 22 | scalar_product(A,Xs,P), 23 | call(Rel,P,Product). 24 | 25 | data(Prices,Limits,Nutrition) => 26 | Prices = {50,20,30,80},% prices in cents for each product 27 | Limits = {500,6,10,8},% limits,requirements for each nutrition type 28 | 29 | % nutrition for each product 30 | Nutrition = 31 | {{400,200,150,500},% calories 32 | { 3, 2, 0, 0},% chocolate 33 | { 2, 2, 4, 4},% sugar 34 | { 2, 4, 1, 5}}. % fat 35 | 36 | -------------------------------------------------------------------------------- /exs/mip/maxflow_mip.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | M={{0,3,2,3,0,0,0,0}, 5 | {0,0,0,0,0,0,5,0}, 6 | {0,1,0,0,0,1,0,0}, 7 | {0,0,2,0,2,0,0,0}, 8 | {0,0,0,0,0,0,0,5}, 9 | {0,4,0,0,2,0,0,1}, 10 | {0,0,0,0,0,2,0,3}, 11 | {0,0,0,0,0,0,0,0}}, 12 | maxflow(M,1,8). 13 | 14 | maxflow(CapM,Source,Sink) => 15 | N=CapM.length, 16 | M=new_array(N,N), 17 | foreach(I in 1..N, J in 1..N) 18 | M[I,J] :: 0..CapM[I,J] 19 | end, 20 | foreach(I in 1..N, I!=Source, I!=Sink) 21 | sum([M[J,I] : J in 1..N]) #= sum([M[I,J] : J in 1..N]) 22 | end, 23 | Total #= sum([M[Source,I] : I in 1..N]), 24 | Total #= sum([M[I,Sink] : I in 1..N]), 25 | solve([$max(Total)],M), 26 | writeln(Total), 27 | writeln(M). 28 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex1.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | Vars=[X1,X2,X3], 5 | X1 :: 0.0..40.0, 6 | -X1+X2+X3 #=< 20, 7 | X1-3*X2+X3 #=< 30, 8 | Cost = $(X1+2*X2+3*X3), 9 | solve([$max(Cost)],Vars), 10 | Obj is Cost, 11 | printf("sol(%w,%f)%n",Vars,Obj). 12 | 13 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex2.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | Vars=[X1,X2,X3,X4], 5 | X1 + 2*X3 #=< 740, 6 | 2*X2 - 7*X4 #=< 0, 7 | X2 - X3 + 2*X4 #>= 0.5, 8 | X1 + X2 + X3 + X4 #= 9, 9 | Cost = $(X1 + X2 + 3*X3 - 0.5*X4), 10 | solve([$max(Cost)],Vars), 11 | Obj is Cost, 12 | printf("sol(%w,%f)%n",Vars,Obj). 13 | 14 | 15 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex3.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | Vars=[X1,X2], 5 | 0.25*X1 + 1.0*X2 #=< 65, 6 | 1.25*X1 + 0.5*X2 #=< 90, 7 | 1.0*X1 + 1.0*X2 #=< 85, 8 | Cost = $(15*X1 + 10*X2), 9 | solve([$max(Cost)],Vars), 10 | Obj is Cost, 11 | printf("sol(%w,%f)%n",Vars,Obj). 12 | 13 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex4.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | %dual of ex3.pl 4 | 5 | main => 6 | Vars=[Y1,Y2,Y3], 7 | 0.25*Y1 + 1.25*Y2 + 1.0*Y3 #>= 15, 8 | 1.0*Y1 + 0.5*Y2 + 1.0*Y3 #>= 10, 9 | Cost = $(65*Y1 + 90*Y2 + 85*Y3), 10 | solve([$min(Cost)],Vars), 11 | Obj is Cost, 12 | printf("sol(%w,%f)%n",Vars,Obj). 13 | 14 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex5.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | Vars=[X1,X2], 5 | X1 + X2 #=< 65, 6 | X1 + X2 #>= 90, 7 | Cost = $(15*X1 + 10*X2), 8 | solve([$min(Cost)],Vars), 9 | Obj is Cost, 10 | printf("sol(%w,%f)%n",Vars,Obj). 11 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex6.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | Vars=[X1,X2,X3], 5 | X1+X2+X3 #=< 100, 6 | 10*X1+4*X2+5*X3 #=< 600, 7 | 2*X1+2*X2+6*X3 #=< 300, 8 | Cost = $(10*X1+6*X2+4*X3), 9 | solve([$max(Cost)],Vars), 10 | Obj is Cost, 11 | printf("sol(%w,%f)%n",Vars,Obj). 12 | -------------------------------------------------------------------------------- /exs/mip/tmip_ex7.pi: -------------------------------------------------------------------------------- 1 | import mip. 2 | 3 | main => 4 | Vars=[X1,X2,X3], 5 | X1+X2+X3 #=< 100, 6 | 10*X1+4*X2+5*X3 #=< 600, 7 | 2*X1+2*X2+6*X3 #=< 300, 8 | Cost = $(10*X1+6*X2+4*X3), 9 | solve([$max(Cost)],Vars), 10 | Obj is Cost, 11 | printf("sol(%w,%f)%n",Vars,Obj). 12 | -------------------------------------------------------------------------------- /exs/nn/author_classify/README.md: -------------------------------------------------------------------------------- 1 | # author-classify 2 | # by Moshe Lach 3 | 4 | Based on this paper: http://people.oregonstate.edu/~kelberta/dima/PAPERS/published/llc/khmelev-tweedie-2001.pdf. 5 | 6 | First run "preprocess.pi", which will preprocess the files according to the instructions in the above paper and generate new, processed files. (For example, from chesterton1.txt it will produce processed_chesterton1.txt.) 7 | 8 | Next, run "transition_probabilities.pi" to create the training data, which will be stored in "transition_probabilities.data". As this program runs, provide to it the newly processed files. 9 | 10 | Next, run "author_classify_train.pi" to create and train a NN. 11 | 12 | Finally, run "author_classify_test.pi" to make a prediction. 13 | 14 | (The text files are from books by G.K. Chesterton and Herman Melville, respectively, from Project Gutenberg: http://gutenberg.net/.) 15 | -------------------------------------------------------------------------------- /exs/nn/author_classify/author_classify_train.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | NN = new_nn([729,729,729,729,729,2]), 5 | nn_train(NN,"transition_probabilities.data", $[derror(0.01),maxep(1000),report(10)]), 6 | nn_save(NN, "author_classify.net"), 7 | nn_destroy_all, 8 | println("Done"). 9 | -------------------------------------------------------------------------------- /exs/nn/author_classify/preprocess.pi: -------------------------------------------------------------------------------- 1 | 2 | main => 3 | Files = ["chesterton1.txt", "chesterton2.txt", "chesterton3.txt", 4 | "melville1.txt", "melville2.txt", "melville3.txt"], 5 | foreach (File in Files) 6 | preprocess(File) 7 | end. 8 | 9 | main([Filename]) => 10 | preprocess(Filename). 11 | 12 | preprocess(Filename) => 13 | printf("preprocessing %s\n", Filename), 14 | Reader = open(Filename, read), 15 | Writer = open("processed_" ++ Filename, write), 16 | Char = read_char(Reader), 17 | while(Char !== end_of_file) 18 | % If the current character is uppercase, skip the entire word 19 | if ascii_uppercase(Char) then 20 | while(Char != ' ' && Char !== end_of_file) 21 | Char := read_char(Reader) 22 | end 23 | elseif ascii_lowercase(Char) || Char == ' ' then 24 | print(Writer, Char) 25 | end, 26 | Char := read_char(Reader), 27 | end, 28 | close(Reader), 29 | close(Writer). 30 | -------------------------------------------------------------------------------- /exs/nn/lang_classify/README.md: -------------------------------------------------------------------------------- 1 | # language-classify 2 | # by Moshe Lach 3 | 4 | Based on the FANN tutorial (http://fann.sourceforge.net/fann_en.pdf). 5 | 6 | The goal is to create a NN that given a text file of English, French, or Spanish will be able to determine which of those 3 languages it is. It does so based on the frequencies of the 26 letters of the alphabet. 7 | 8 | The "lang_classify_train.pi" program creates and trains a NN using the dataset "frequencies.data". 9 | 10 | The program in "lang_classify_test.pi" can then be compiled and used; it asks for the name of a text file, finds the frequencies, and runs that information through the NN to classify the language as either English, French, or Spanish. 11 | -------------------------------------------------------------------------------- /exs/nn/lang_classify/frequencies.data: -------------------------------------------------------------------------------- 1 | 3 26 3 2 | 0.085631672597865 0.013734430604982 0.031528024911032 0.041870551601423 0.126278914590747 0.031027580071174 0.022575622775801 0.047709074733096 0.07178603202847 0.002279804270463 0.005560498220641 0.048209519572954 0.028636565836299 0.064056939501779 0.082406583629893 0.02057384341637 0.000333629893238 0.067893683274021 0.057717971530249 0.085075622775801 0.021908362989324 0.016014234875445 0.011232206405694 0.002224199288256 0.012288701067616 0.001445729537367 3 | 1 0 0 4 | 5 | 0.073284218689414 0.009801387273276 0.042415234156219 0.038774718883288 0.145814484511654 0.010016802378183 0.010081426909655 0.007625694713713 0.076730860367929 0.002218775580544 0.000710869846194 0.061565636982465 0.043255353065357 0.078324932144242 0.060100814269097 0.026754556029469 0.006268579552798 0.06410753522037 0.085433630606178 0.076041532032226 0.058355951919349 0.01445435353927 0.000387747188833 0.004265219077162 0.002606522769377 0.00060316229374 6 | 0 1 0 7 | 8 | 0.128309071924329 0.014341870892451 0.0468030219274 0.048430686075794 0.127694859038143 0.008834428679647 0.017136539524599 0.008824191798211 0.069702925700715 0.002200929508834 0.001167004483754 0.069498188071986 0.026626128616178 0.079919333374281 0.084095981000348 0.027997870728661 0.003982146878775 0.054501156767602 0.076715189484675 0.044602092418566 0.034283315930635 0.009131298241304 0.001371742112483 0.002815142395021 0.007995004401859 0.00301988002375 9 | 0 0 1 10 | 11 | -------------------------------------------------------------------------------- /exs/nn/lang_classify/lang_classify_test.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | Ann = nn_load("lang_classify.net"), 5 | println("Enter the name of the file to test"), 6 | Filename = read_line(stdin), 7 | Frequencies = new_array(26), 8 | generate_frequencies(Filename, Frequencies), 9 | nn_print(Ann), 10 | Out = nn_run(Ann, Frequencies), 11 | print("English: "), println(Out[1]), 12 | print("French: "), println(Out[2]), 13 | print("Spanish: "), println(Out[3]). 14 | 15 | 16 | % Fills array "Frequencies" with the frequencies of each of the 17 | % 26 letters of the Latin alphabet. Lowercase and uppercase 18 | % letters are counted together, e.g., 'a' and 'A' are treated in 19 | % the same way. 20 | generate_frequencies(Filename, Frequencies) => 21 | INS = open(Filename), 22 | Letter_count = new_array(26), 23 | foreach(E in Letter_count) 24 | E = 0 25 | end, 26 | Num_chars = 0, 27 | Char = read_char(INS), 28 | while(Char != end_of_file) 29 | if (ascii_alpha(Char)) then 30 | Char := to_lowercase(Char), 31 | Letter_count[ord(Char) - ord('a') + 1] := Letter_count[ord(Char) - ord('a') + 1] + 1, 32 | Num_chars := Num_chars + 1 33 | end, 34 | Char := read_char(INS) 35 | end, 36 | foreach(I in 1..26) 37 | Frequencies[I] = Letter_count[I]/Num_chars 38 | end, 39 | close(INS). 40 | -------------------------------------------------------------------------------- /exs/nn/lang_classify/lang_classify_train.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | Ann = new_nn([26,13,3]), 5 | nn_train(Ann,"frequencies.data",$[derror(0.0001),maxep(200),report(10)]), 6 | nn_save(Ann, "lang_classify.net"), 7 | nn_destroy_all, 8 | println("Done"). 9 | -------------------------------------------------------------------------------- /exs/nn/mnist/README.md: -------------------------------------------------------------------------------- 1 | # by Moshe Lach 2 | 3 | Program to use an artificial neural network to recognize the handwritten digits 0-9. 4 | 5 | Requires the MNIST training set, available at http://yann.lecun.com/exdb/mnist/. Specifically, it needs the following 2 files: "train-images-idx3-ubyte.gz" and "train-labels-idx1-ubyte.gz". 6 | 7 | After downloading the files from the web page, run (on Linux or Cygwin) "gunzip .gz" to unzip each .gz file. 8 | 9 | Then the program "digits_train.pi" can create "digits.train", which will be in the proper FANN format, and which it will then use to train a NN. 10 | 11 | There are two possibilities for the number of output neurons: either there is just one, with a value (hopefully) equivalent to one of the digits 0...9, or 10 output neurons, with (ideally) the appropiate neuron having a value of 1 and the rest -1. 12 | -------------------------------------------------------------------------------- /exs/nn/scaling/scaling.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mingodad/picat/5203601697dfe7139cb648d6f9c276aed2360b97/exs/nn/scaling/scaling.tar.gz -------------------------------------------------------------------------------- /exs/nn/scaling/scaling_test.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | NN = nn_load("scaling.net"), 5 | L = nn_train_data_size("scaling.data"), 6 | foreach(I in 1..L) 7 | (In, Out) = nn_train_data_get("scaling.data",I), 8 | Res = nn_run(NN,In,[$scaleIn(1),$scaleOut(-1),resetMSE]), 9 | printf("Result %w original %w error %f%n",Res, Out, abs(Res[1] - Out[1])), 10 | end, 11 | nn_destroy_all. 12 | -------------------------------------------------------------------------------- /exs/nn/scaling/scaling_train.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | NN = new_nn({3,5,1}), 5 | nn_set_activation_function_layer(NN,sigmoid,2), 6 | nn_set_activation_function_output(NN,linear), 7 | nn_train(NN, "scaling.data", $[train_func(rprop), derror(0.0001), maxep(5000), report(1000), scale(-1,1,-1,1)]), 8 | nn_save(NN,"scaling.net"), 9 | nn_destroy_all. 10 | -------------------------------------------------------------------------------- /exs/nn/spam_detector/README.md: -------------------------------------------------------------------------------- 1 | # Spam detector 2 | # by Neng-Fa Zhou, November 29, 2019 3 | 4 | This program uses a neural network to detect if an email is a spam or a ham. The original labeled emails are available at: 5 | 6 | https://archive.ics.uci.edu/ml/datasets.php 7 | 8 | The file "Train.csv" is a database of attributes extracted from the original labeled data set. See "spambase.names" for the 9 | meaning of each of the attributes. 10 | 11 | First, convert the csv file to the Fann format: 12 | 13 | picat csv2fann Train.csv 1 > Train.txt 14 | 15 | where 1 means that there is only one output attribute. 16 | 17 | Second, create and train a neural network: 18 | 19 | picat train Train.txt 20 | 21 | Finally, test the neural network on the test dataset: 22 | 23 | picat test TestX.csv 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /exs/nn/spam_detector/csv2fann.pi: -------------------------------------------------------------------------------- 1 | import util. 2 | 3 | main([File,NOutStr]) => 4 | NOut = to_int(NOutStr), 5 | proc_file(File,NIn,NOut,Ins,Outs,Count), 6 | printf("%d %d %d\n",Count,NIn,NOut), 7 | foreach ({In,Out} in zip(Ins,Outs)) 8 | print_line(In), 9 | print_line(Out) 10 | end. 11 | main([File|_]) => 12 | NOut = 0, 13 | proc_file(File,NIn,NOut,Ins,Outs,Count), 14 | foreach (In in Ins) 15 | print_line(In) 16 | end. 17 | 18 | proc_file(File,NIn,NOut,Ins,Outs,Count) => 19 | InStream = open(File), 20 | L = InStream.read_line(), 21 | proc(InStream,L,NIn,NOut,Ins,Outs,0,Count), 22 | close(InStream). 23 | 24 | proc(_InStream,end_of_file,_NIn,_NOut,Ins,Outs,Count0,Count) => 25 | Count = Count0, 26 | Ins = [], 27 | Outs = []. 28 | proc(InStream,Line,NIn,NOut,Ins,Outs,Count0,Count) => 29 | Tokens = split(strip(Line),","), 30 | N = len(Tokens), 31 | separate(Tokens,N,NOut,In,Out), 32 | NIn = N-NOut, 33 | Ins = [In|InsR], 34 | Outs = [Out|OutsR], 35 | L1 = InStream.read_line(), 36 | proc(InStream,L1,NIn,NOut,InsR,OutsR,Count0+1,Count). 37 | 38 | separate(Tokens,N,N,In,Out) => 39 | In = [], 40 | Out = [to_number(Token) : Token in Tokens]. 41 | separate([Token|Tokens],N,NOut,In,Out) => 42 | In = [to_number(Token)|InR], 43 | separate(Tokens,N-1,NOut,InR,Out). 44 | 45 | print_line([]) => nl. 46 | print_line([X|Xs]) => 47 | print(X), print(' '), 48 | print_line(Xs). 49 | -------------------------------------------------------------------------------- /exs/nn/spam_detector/test.pi: -------------------------------------------------------------------------------- 1 | import nn, util. 2 | 3 | main => 4 | TestFile = "TestX.csv", 5 | main([TestFile]). 6 | 7 | main([TestFile]) => 8 | Ann = nn_load("spam.net"), 9 | InStream = open(TestFile), 10 | L = InStream.read_line(), 11 | read_and_predict(Ann,InStream,L,1). 12 | 13 | read_and_predict(_Ann,InStream,end_of_file,_LineNum) => close(InStream). 14 | read_and_predict(Ann,InStream,Line,LineNum) => 15 | Input = {to_number(Token) : Token in split(strip(Line),",")}, 16 | Output = nn_run(Ann, Input,$[resetMSE, scaleIn(1), scaleOut(1)]), 17 | printf("%d: %w\n",LineNum,Output), 18 | NLine = InStream.read_line(), 19 | read_and_predict(Ann,InStream,NLine,LineNum+1). 20 | 21 | -------------------------------------------------------------------------------- /exs/nn/spam_detector/train.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | main(["Train.txt"]). 5 | 6 | main([File]) => 7 | Ann = new_nn([57,2,1]), 8 | nn_train(Ann,File,$[derror(0.0001),maxep(2000),report(10),scale(-1,1,-1,1)]), 9 | nn_set_activation_function_hidden(Ann,sigmoid), 10 | nn_save(Ann, "spam.net"), 11 | nn_destroy_all, 12 | println("Done"). 13 | -------------------------------------------------------------------------------- /exs/nn/xor/__tmp.data: -------------------------------------------------------------------------------- 1 | 4 2 1 2 | -1 -1 3 | -1 4 | -1 1 5 | 1 6 | 1 -1 7 | 1 8 | 1 1 9 | -1 10 | -------------------------------------------------------------------------------- /exs/nn/xor/xor.data: -------------------------------------------------------------------------------- 1 | 4 2 1 2 | -1 -1 3 | -1 4 | -1 1 5 | 1 6 | 1 -1 7 | 1 8 | 1 1 9 | -1 10 | -------------------------------------------------------------------------------- /exs/nn/xor/xor_test.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | NN = nn_load("xor.net"), 5 | printf("xor(-1,-1) = %w\n",nn_run(NN,{-1,-1})), 6 | printf("xor(-1,1) = %w\n",nn_run(NN,{-1,1})), 7 | printf("xor(1,-1) = %w\n",nn_run(NN,{1,-1})), 8 | printf("xor(1,1) = %w\n",nn_run(NN,{1,1})), 9 | nn_destroy(NN). 10 | 11 | -------------------------------------------------------------------------------- /exs/nn/xor/xor_train_data.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | NN = new_nn({2,3,1}), 5 | Data = [({-1,-1}, -1), 6 | ({-1,1}, 1), 7 | ({1,-1}, 1), 8 | ({1,1}, -1)], 9 | nn_train(NN,Data,$[maxep(500000), report(1000), derror(0.0), bfl(0.1), train_func(rprop), stop_func(stop_bit)]), 10 | nn_save(NN,"xor.net"), 11 | nn_print(NN), 12 | nn_destroy_all. 13 | 14 | -------------------------------------------------------------------------------- /exs/nn/xor/xor_train_file.pi: -------------------------------------------------------------------------------- 1 | import nn. 2 | 3 | main => 4 | NN = new_nn({2,3,1}), 5 | nn_train(NN,"xor.data",$[maxep(500000), report(1000), derror(0.0), bfl(0.1), train_func(rprop), stop_func(stop_bit)]), 6 | nn_save(NN,"xor.net"), 7 | nn_print(NN), 8 | nn_destroy_all. 9 | 10 | -------------------------------------------------------------------------------- /exs/planner/15_puzzle.pi: -------------------------------------------------------------------------------- 1 | import planner. 2 | 3 | main => 4 | InitS = [(1,2),(2,2),(4,4),(1,3), 5 | (1,1),(3,2),(1,4),(2,4), 6 | (4,2),(3,1),(3,3),(2,3), 7 | (2,1),(4,1),(4,3),(3,4)], 8 | best_plan(InitS,Plan), 9 | println(len=len(Plan)), 10 | foreach (Action in Plan) 11 | println(Action) 12 | end. 13 | 14 | final(State) => State=[(1,1),(1,2),(1,3),(1,4), 15 | (2,1),(2,2),(2,3),(2,4), 16 | (3,1),(3,2),(3,3),(3,4), 17 | (4,1),(4,2),(4,3),(4,4)]. 18 | 19 | action([P0@(R0,C0)|Tiles],NextS,Action,Cost) => 20 | Cost = 1, 21 | (R1 = R0-1, R1 >= 1, C1 = C0, Action = up; 22 | R1 = R0+1, R1 =< 4, C1 = C0, Action = down; 23 | R1 = R0, C1 = C0-1, C1 >= 1, Action = left; 24 | R1 = R0, C1 = C0+1, C1 =< 4, Action = right), 25 | P1 = (R1,C1), 26 | slide(P0,P1,Tiles,NTiles), 27 | NextS = [P1|NTiles]. 28 | 29 | % slide the tile at P1 to the empty square at P0 30 | slide(P0,P1,[P1|Tiles],NTiles) => 31 | NTiles = [P0|Tiles]. 32 | slide(P0,P1,[Tile|Tiles],NTiles) => 33 | NTiles=[Tile|NTilesR], 34 | slide(P0,P1,Tiles,NTilesR). 35 | 36 | heuristic([_|Tiles]) = Dist => 37 | final([_|FTiles]), 38 | Dist = sum([abs(R-FR)+abs(C-FC) : 39 | {(R,C),(FR,FC)} in zip(Tiles,FTiles)]). 40 | -------------------------------------------------------------------------------- /exs/planner/15_puzzle.pi~: -------------------------------------------------------------------------------- 1 | import planner. 2 | 3 | main => 4 | InitS = [(1,2),(2,2),(4,4),(1,3), 5 | (1,1),(3,2),(1,4),(2,4), 6 | (4,2),(3,1),(3,3),(2,3), 7 | (2,1),(4,1),(4,3),(3,4)], 8 | best_plan(InitS,Plan), 9 | foreach (Action in Plan) 10 | println(Action) 11 | end. 12 | 13 | final(State) => State=[(1,1),(1,2),(1,3),(1,4), 14 | (2,1),(2,2),(2,3),(2,4), 15 | (3,1),(3,2),(3,3),(3,4), 16 | (4,1),(4,2),(4,3),(4,4)]. 17 | 18 | action([P0@(R0,C0)|Tiles],NextS,Action,Cost) => 19 | Cost = 1, 20 | (R1 = R0-1, R1 >= 1, C1 = C0, Action = up; 21 | R1 = R0+1, R1 =< 4, C1 = C0, Action = down; 22 | R1 = R0, C1 = C0-1, C1 >= 1, Action = left; 23 | R1 = R0, C1 = C0+1, C1 =< 4, Action = right), 24 | P1 = (R1,C1), 25 | slide(P0,P1,Tiles,NTiles), 26 | NextS = [P1|NTiles]. 27 | 28 | % slide the tile at P1 to the empty square at P0 29 | slide(P0,P1,[P1|Tiles],NTiles) => 30 | NTiles = [P0|Tiles]. 31 | slide(P0,P1,[Tile|Tiles],NTiles) => 32 | NTiles=[Tile|NTilesR], 33 | slide(P0,P1,Tiles,NTilesR). 34 | 35 | heuristic([_|Tiles]) = Dist => 36 | final([_|FTiles]), 37 | Dist = sum([abs(R-FR)+abs(C-FC) : 38 | {(R,C),(FR,FC)} in zip(Tiles,FTiles)]). 39 | -------------------------------------------------------------------------------- /exs/planner/farmer.pi: -------------------------------------------------------------------------------- 1 | % farmer.pi in Picat 2 | % Farmer's problem 3 | % by Neng-Fa Zhou, 2013 4 | 5 | import planner. 6 | 7 | main => go. 8 | 9 | go => 10 | S0=[s,s,s,s], 11 | best_plan(S0,Plan), 12 | writeln(Plan). 13 | 14 | final([n,n,n,n]) => true. 15 | 16 | action([F,F,G,C],S1,Action,ActionCost) ?=> 17 | Action=farmer_wolf, 18 | ActionCost = 1, 19 | F1 = opposite(F), 20 | S1=[F1,F1,G,C], 21 | not unsafe(S1). 22 | action([F,W,F,C],S1,Action,ActionCost) ?=> 23 | Action=farmer_goat, 24 | ActionCost = 1, 25 | F1 = opposite(F), 26 | S1=[F1,W,F1,C], 27 | not unsafe(S1). 28 | action([F,W,G,F],S1,Action,ActionCost) ?=> 29 | Action=farmer_cabbage, 30 | ActionCost = 1, 31 | F1 = opposite(F), 32 | S1=[F1,W,G,F1], 33 | not unsafe(S1). 34 | action([F,W,G,C],S1,Action,ActionCost) => 35 | Action=farmer_alone, 36 | ActionCost = 1, 37 | F1 = opposite(F), 38 | S1=[F1,W,G,C], 39 | not unsafe(S1). 40 | 41 | opposite(n) = s. 42 | opposite(s) = n. 43 | 44 | unsafe([F,W,G,_C]),W==G,F!==W => true. 45 | unsafe([F,_W,G,C]),G==C,F!==G => true. 46 | 47 | -------------------------------------------------------------------------------- /exs/planner/water.pi: -------------------------------------------------------------------------------- 1 | % water.pi in Picat 2 | % Water Jugs Problem 3 | % by Neng-Fa Zhou, 2013 4 | 5 | import planner. 6 | 7 | main => go. 8 | 9 | go => 10 | plan([0,0],Plan), 11 | foreach(Step in Plan) writeln(Step) end. 12 | 13 | final([4,_]) => true. 14 | final([_,4]) => true. 15 | 16 | action([_V1,V2],S1,Action,Cost) ?=> 17 | Cost = 1, 18 | Action = fill1, 19 | capacity(1,C), 20 | S1 = [C,V2]. 21 | action([V1,_V2],S1,Action,Cost) ?=> 22 | Cost = 1, 23 | Action = fill2, 24 | capacity(2,C), 25 | S1 = [V1,C]. 26 | action([V1,V2],S1,Action,Cost),V1>0 ?=> 27 | Cost = 1, 28 | Action = empty1, 29 | S1 = [0,V2]. 30 | action([V1,V2],S1,Action,Cost),V2>0 ?=> 31 | Cost = 1, 32 | Action = empty2, 33 | S1 = [V1,0]. 34 | action([V1,V2],S1,Action,Cost),V2>0 ?=> 35 | Cost = 1, 36 | Action = transfer_2_to_1, 37 | capcity(1,C1), 38 | Liquid is V1+V2, 39 | Excess is Liquid-C1, 40 | (Excess=<0-> 41 | W1=Liquid,W2=0 42 | ; 43 | W1=C1,W2=Excess 44 | ), 45 | S1=[W1,W2]. 46 | action([V1,V2],S1,Action,Cost),V1>0 => 47 | Cost = 1, 48 | Action = transfer_1_to_2, 49 | capcity(2,C2), 50 | Liquid is V1+V2, 51 | Excess is Liquid-C2, 52 | (Excess=<0-> 53 | W2=Liquid,W1=0 54 | ; 55 | W2=C2,W1=Excess 56 | ), 57 | S1=[W1,W2]. 58 | 59 | capacity(1,C1) => C1=8. 60 | capcity(2,C2) => C2=5. 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /exs/sat/bqueens.pi: -------------------------------------------------------------------------------- 1 | import sat. 2 | 3 | main => 4 | queens(100). 5 | 6 | queens(N) => 7 | Qs = new_array(N,N), 8 | Qs :: 0..1, 9 | foreach(I in 1..N) % 1 in each row 10 | sum([Qs[I,J] : J in 1..N]) #= 1 11 | end, 12 | foreach(J in 1..N) % 1 in each column 13 | sum([Qs[I,J] : I in 1..N]) #= 1 14 | end, 15 | foreach(K in 1-N..N-1) % at most one 16 | sum([Qs[I,J] : I in 1..N, J in 1..N, I-J=:=K]) #=< 1 17 | end, 18 | foreach(K in 2..2*N) % at most one 19 | sum([Qs[I,J] : I in 1..N, J in 1..N, I+J=:=K]) #=< 1 20 | end, 21 | solve(Qs), 22 | foreach(I in 1..N) 23 | writeln(Qs[I]) 24 | end. 25 | 26 | -------------------------------------------------------------------------------- /exs/sat/crossword.pi: -------------------------------------------------------------------------------- 1 | import sat. 2 | 3 | main => 4 | crossword(_Vars). 5 | 6 | crossword(Vars) => 7 | Vars=[X1,X2,X3,X4,X5,X6,X7], 8 | Words2=[{ord('I'),ord('N')}, 9 | {ord('I'),ord('F')}, 10 | {ord('A'),ord('S')}, 11 | {ord('G'),ord('O')}, 12 | {ord('T'),ord('O')}], 13 | Words3=[{ord('F'),ord('U'),ord('N')}, 14 | {ord('T'),ord('A'),ord('D')}, 15 | {ord('N'),ord('A'),ord('G')}, 16 | {ord('S'),ord('A'),ord('G')}], 17 | table_in([{X1,X2},{X1,X3},{X5,X7},{X6,X7}], Words2), 18 | table_in([{X3,X4,X5},{X2,X4,X6}],Words3), 19 | AllSols=solve_all(Vars), 20 | foreach(Sol in AllSols.sort()) 21 | writeln([chr(Code) : Code in Sol]) 22 | end. 23 | -------------------------------------------------------------------------------- /exs/sat/queens.pi: -------------------------------------------------------------------------------- 1 | import sat. 2 | 3 | main => top. 4 | 5 | top => 6 | queens(100). 7 | 8 | queens(N) => 9 | Qs=new_array(N), 10 | Qs :: 1..N, 11 | foreach (I in 1..N-1, J in I+1..N) 12 | Qs[I] #!= Qs[J], 13 | Qs[I]-Qs[J] #!= J-I, 14 | Qs[J]-Qs[I] #!= J-I 15 | end, 16 | solve([ff],Qs), 17 | writeln(Qs). 18 | -------------------------------------------------------------------------------- /exs/sat/vmtl.pi: -------------------------------------------------------------------------------- 1 | /* 2 | The SAT Compiler in B-Prolog 3 | The Vertex Magic Total Labeling (VMTL) Problem 4 | http://www.cs.nmsu.edu/ALP/2013/03/the-sat-compiler-in-b-prolog/ 5 | by Neng-Fa Zhou 6 | */ 7 | import sat. 8 | 9 | main => 10 | vmtl(9). 11 | 12 | go => 13 | vmtl(12). 14 | 15 | vmtl(NV) => 16 | VVars = new_array(NV), 17 | EVars = new_array(NV,NV), 18 | foreach(I in 1..NV) EVars[I,I] = 0 end, 19 | foreach(I in 1..NV-1, J in I+1..NV) EVars[I,J] = EVars[J,I] end, 20 | Vars = vars((VVars,EVars)), 21 | NE = NV*(NV-1) div 2, % max number of edges for complete graph 22 | Vars :: 1..(NV+NE), 23 | LB = truncate(NV*(NV**2+3)/4), 24 | UB = truncate(NV*(NV+1)**2/4), 25 | K :: LB..UB, 26 | 27 | % constraints 28 | all_different(Vars), 29 | foreach(I in 1..NV) 30 | VVars[I] + sum([EVars[I,J] : J in 1..NV]) #= K 31 | end, 32 | solve([K|Vars]), 33 | % solve([$nvars(NVars),$ncls(NCls)],[K|Vars]), 34 | % printf("%% nvars(%w) %n",NVars), 35 | % printf("%% ncls(%w) %n",NCls), 36 | writeln(k=K), 37 | writeln(vvars=VVars), 38 | writeln(evars=EVars). 39 | 40 | -------------------------------------------------------------------------------- /exs/smt/bqueens.pi: -------------------------------------------------------------------------------- 1 | import smt. 2 | 3 | main => 4 | queens(30). 5 | 6 | queens(N) => 7 | Qs = new_array(N,N), 8 | Qs :: 0..1, 9 | foreach(I in 1..N) % 1 in each row 10 | sum([Qs[I,J] : J in 1..N]) #= 1 11 | end, 12 | foreach(J in 1..N) % 1 in each column 13 | sum([Qs[I,J] : I in 1..N]) #= 1 14 | end, 15 | foreach(K in 1-N..N-1) % at most one 16 | sum([Qs[I,J] : I in 1..N, J in 1..N, I-J=:=K]) #=< 1 17 | end, 18 | foreach(K in 2..2*N) % at most one 19 | sum([Qs[I,J] : I in 1..N, J in 1..N, I+J=:=K]) #=< 1 20 | end, 21 | solve([$logic("LIA"),cvc4],Qs), 22 | foreach(I in 1..N) 23 | writeln(Qs[I]) 24 | end. 25 | 26 | -------------------------------------------------------------------------------- /exs/smt/queens.pi: -------------------------------------------------------------------------------- 1 | import smt. 2 | 3 | main => top. 4 | 5 | top => 6 | queens(50). 7 | 8 | queens(N) => 9 | Qs=new_array(N), 10 | Qs :: 1..N, 11 | foreach (I in 1..N-1, J in I+1..N) 12 | Qs[I] #!= Qs[J], 13 | Qs[I]-Qs[J] #!= J-I, 14 | Qs[J]-Qs[I] #!= J-I 15 | end, 16 | solve([ff],Qs), 17 | writeln(Qs). 18 | -------------------------------------------------------------------------------- /lib/datetime.pi: -------------------------------------------------------------------------------- 1 | module datetime. 2 | 3 | current_datetime() = $date_time(Year,Month,Day,Hour,Min,Sec) => 4 | bp.c_TIME_ffffff(Year,Month,Day,Hour,Min,Sec). 5 | 6 | current_date() = $date(Year,Month,Day) => 7 | bp.c_TIME_ffffff(Year,Month,Day,_Hour,_Min,_Sec). 8 | 9 | current_time() = $time(Hour,Min,Sec) => 10 | bp.c_TIME_ffffff(_Year,_Month,_Day,Hour,Min,Sec). 11 | 12 | current_day() = WDay => 13 | bp.c_WDAY_f(WDay). 14 | -------------------------------------------------------------------------------- /lib/ordset.pi: -------------------------------------------------------------------------------- 1 | module ordset. 2 | 3 | delete(OSet, Elm) = OSet1 => bp.ord_del_element(OSet,Elm,OSet1). 4 | disjoint(OSet1, OSet2) => bp.ord_disjoint(OSet1,OSet2). 5 | insert(OSet, Elm) = OSet1 => bp.ord_insert(OSet,Elm,OSet1). 6 | intersection(OSet1, OSet2) = OSet3 => bp.ord_intersection(OSet1,OSet2,OSet3). 7 | membchk(E, OSet) => bp.ord_member(E,OSet). 8 | new_ordset(List) = sort_remove_dups(List). 9 | ordset(Term) => bp.is_ordset(Term). 10 | subset(OSet1, OSet2) => bp.ord_subset(OSet1,OSet2). 11 | subtract(OSet1, OSet2) = OSet3 => bp.ord_subtract(OSet1,OSet2,OSet3). 12 | union(OSet1, OSet2) = OSet3 => bp.ord_union(OSet1,OSet2,OSet3). 13 | -------------------------------------------------------------------------------- /lib/prism_ex.pi: -------------------------------------------------------------------------------- 1 | module prism_ex. 2 | 3 | chindsight(Goal) => chindsight_aux(Goal). 4 | chindsight(Goal,SubG, HProbs) => chindsight_aux(Goal,SubG,HProbs). 5 | chindsight_agg(Goal, Agg) => chindsight_agg_aux(Goal,Agg). 6 | hindsight(Goal) => hindsight_aux(Goal). 7 | hindsight(Goal,SubG, HProbs) => hindsight_aux(Goal,SubG,HProbs). 8 | 9 | chindsight_aux(Goal) => 10 | bp.prism_dyna_change_goal(Goal,NGoal), 11 | bp.chindsight(NGoal,_SubG,HProbs), 12 | print_chindsight(HProbs). 13 | 14 | chindsight_aux(Goal,SubG,HProbs) => 15 | bp.prism_dyna_change_goal(Goal,NGoal), 16 | bp.prism_dyna_change_goal(SubG,NSubG), 17 | bp.chindsight(NGoal,NSubG,HProbs0), 18 | trans_expls(HProbs0,HProbs). 19 | 20 | chindsight_agg_aux(Goal,Agg) => 21 | bp.prism_dyna_change_goal(Goal,NGoal), 22 | bp.prism_dyna_change_goal(Agg,NAgg), 23 | bp.chindsight_agg(NGoal,NAgg). 24 | 25 | hindsight_aux(Goal) => 26 | bp.prism_dyna_change_goal(Goal,NGoal), 27 | hindsight(NGoal,_SubG,HProbs), 28 | print_hindsight(HProbs). 29 | 30 | hindsight_aux(Goal,SubG,HProbs) => 31 | bp.prism_dyna_change_goal(Goal,NGoal), 32 | bp.prism_dyna_change_goal(SubG,NSubG), 33 | bp.hindsight(NGoal,NSubG,HProbs0), 34 | trans_expls(HProbs0,HProbs). 35 | 36 | -------------------------------------------------------------------------------- /lib/sat_mip.pi: -------------------------------------------------------------------------------- 1 | p(a). 2 | 3 | -------------------------------------------------------------------------------- /lib/sys.pi: -------------------------------------------------------------------------------- 1 | module sys. % imported by default 2 | 3 | abort => abort. 4 | cl(File) => cl(File). 5 | cl_facts(Facts) => cl_facts(Facts,[]). 6 | cl_facts(Facts, IndexInfo) => cl_facts(Facts,IndexInfo). 7 | cl_facts_table(Facts) => cl_facts_table(Facts,[]). 8 | cl_facts_table(Facts, IndexInfo) => cl_facts_table(Facts,IndexInfo). 9 | command(String) = command(String). 10 | compile(File) => compile(File). 11 | compile_bp(File) => compile_bp(File). 12 | compile_files_to_c(Fs, CFile) => compile_files_to_c(Fs,CFile). 13 | debug => debug. 14 | exit => halt. 15 | garbage_collect => garbage_collect. 16 | garbage_collect(Size) => garbage_collect(Size). 17 | halt => halt. 18 | help => help. 19 | initialize_table => initialize_table. 20 | load(File) => load(File). 21 | loaded_modules() = loaded_modules(). 22 | nodebug => nodebug. 23 | nolog => nolog. 24 | nospy => nospy. 25 | notrace => notrace. 26 | picat_path() = picat_path(). 27 | spy(Point) => spy(Point). 28 | statistics => statistics. 29 | statistics(Name, Val) => statistics(Name,Val). 30 | statistics_all() = statistics_all(). 31 | time(Goal) => throw($meta_meta_call_not_allowed(time(Goal))). 32 | time2(Goal) => throw($meta_meta_call_not_allowed(time2(Goal))). 33 | time_out(Goal,Limit, Res) => throw($meta_meta_call_not_allowed(time_out(Goal,Limit,Res))). 34 | trace => trace. 35 | 36 | -------------------------------------------------------------------------------- /lib2/analyze_pb.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Files = listdir("."), 5 | foreach (File in Files, append(_,".out",File)) 6 | main([File]) 7 | end. 8 | 9 | 10 | main([File]) => 11 | IS = open(File), 12 | Map = new_map(), 13 | Line = IS.read_line(), 14 | (Line !== end_of_file -> printf("analyzing %s\n",File); true), 15 | proc_lines(Line,IS,Map), 16 | List = [(Val,Key) : (Key=Val) in Map].sort_down(), 17 | foreach((Val,Key) in List, Val >= 100) 18 | printf("%s: %w\n",Key,Val) 19 | end, 20 | close(IS). 21 | 22 | proc_lines(end_of_file,_IS,_Map) => true. 23 | proc_lines(Line,IS,Map) => 24 | Count = Map.get(Line,0), 25 | Map.put(Line,Count+1), 26 | NLine = IS.read_line(), 27 | proc_lines(NLine,IS,Map). 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /lib2/chmod_dir.pi: -------------------------------------------------------------------------------- 1 | /* change the access mode of every file/directory to "rw" */ 2 | 3 | import os. 4 | 5 | main => 6 | Wd = pwd(), 7 | chmod_dir(Wd). 8 | 9 | chmod_dir(Dir) => 10 | Items = listdir(Dir), 11 | foreach (Item in Items, Item !== ".", Item !== "..") 12 | FullName = full_path(Dir, Item), 13 | command("chmod +rw " ++ FullName) = _, 14 | println("chmod +rw " ++ FullName), 15 | (directory(FullName) -> 16 | chmod_dir(FullName) 17 | ; 18 | true 19 | ) 20 | end. 21 | 22 | full_path(Dir,Name) = 23 | Dir ++ [separator()] ++ Name. 24 | -------------------------------------------------------------------------------- /lib2/comp_lib.pi: -------------------------------------------------------------------------------- 1 | main => 2 | compile_bp(basic), 3 | compile_bp(math), 4 | compile_bp(sys), 5 | compile_bp(io), 6 | compile_bp(cp), 7 | compile_bp(sat), 8 | compile_bp(common_constr), 9 | compile_bp(mip), 10 | compile_bp(mip_aux), 11 | compile_bp(smt), 12 | compile_bp(smt_aux), 13 | compile_bp(ordset), 14 | compile_bp(list_set), 15 | compile_bp(planner), 16 | compile_bp(os), 17 | compile_bp(util), 18 | compile_bp(prism), 19 | compile_bp(set_util), 20 | compile_bp(apl_util), 21 | compile_bp(datetime), 22 | compile_bp(picat_lib_aux), 23 | compile_bp(graph). 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /lib2/count_ans.pi: -------------------------------------------------------------------------------- 1 | findall_upto(Template,Call,N) 2 | -------------------------------------------------------------------------------- /lib2/cp_small.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = [F : F in listdir(".").sort(), append(_,".opb",F)], 5 | foreach (F in Fs) 6 | if os.size(F) <= 2000000 && not contains_big_int(F) then 7 | cp(F, "small/"++F) 8 | end 9 | end. 10 | 11 | contains_big_int(F) => 12 | IS = open(F), 13 | Token = read_picat_token(IS), 14 | (contains_big_int(IS,Token) -> Res = true; Res = false), 15 | close(IS), 16 | Res = true. 17 | 18 | contains_big_int(IS,end_of_file) => fail. 19 | contains_big_int(IS,Token), integer(Token), (Token =< -2147483648 || Token >= 2147483647) => true. 20 | contains_big_int(IS,Token) => 21 | NextToken = read_picat_token(IS), 22 | contains_big_int(IS,NextToken). 23 | 24 | 25 | -------------------------------------------------------------------------------- /lib2/del_file.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Files = listdir("."), 5 | foreach (File in Files, File != ".", File != "..") 6 | if append(_,".jl",File) && contains(File,"println(\"incomplete instance\")") then 7 | printf("echo deleting %s\n",File), 8 | rm(File) 9 | end 10 | end. 11 | 12 | contains(File, Str) => 13 | Ls = read_file_lines(File), 14 | member(L,Ls), 15 | append(Str,_,L),!. 16 | -------------------------------------------------------------------------------- /lib2/extract_julia_functions.pi: -------------------------------------------------------------------------------- 1 | main => 2 | extract_keywords0("constrs.jl",KWs1), 3 | extract_keywords0("glob_constrs.jl",KWs2), 4 | foreach (KW in sort(KWs1++KWs2)) 5 | printf("fun(\"%s\") => true.\n", KW) 6 | end. 7 | 8 | extract_keywords0(F,KWs) => 9 | Lines = read_file_lines(F), 10 | extract_keywords(Lines,KWs). 11 | 12 | extract_keywords([],KWs) => KWs = []. 13 | extract_keywords([Line|Lines],KWs), append("function ",Func,['('|_],Line) => 14 | KWs = [Func|KWs1], 15 | extract_keywords(Lines,KWs1). 16 | extract_keywords([Line|Lines],KWs) => 17 | extract_keywords(Lines,KWs). 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib2/extract_timeout_julia.pi: -------------------------------------------------------------------------------- 1 | import util. 2 | 3 | main([File]) => 4 | FD=open(File), 5 | FD.read_line()=Line, 6 | separate(FD,Line). 7 | 8 | separate(_,end_of_file) => true. 9 | separate(FD,L), 10 | append(_,"solving",Name,L), 11 | => 12 | FD.read_line()=Line, 13 | solved_or_not(FD,Line,Name). 14 | separate(FD,_L) => 15 | FD.read_line()=Line, 16 | separate(FD,Line). 17 | 18 | solved_or_not(FD,L,Name), 19 | append("real",Time,L) 20 | => 21 | printf("%s %s\n",Name,Time), 22 | FD.read_line()=Line, 23 | separate(FD,Line). 24 | solved_or_not(FD,_,Name) => 25 | FD.read_line()=Line, 26 | solved_or_not(FD,Line,Name). 27 | -------------------------------------------------------------------------------- /lib2/flatten_dir.pi: -------------------------------------------------------------------------------- 1 | /* copy all the plain files from subdirectories to the current directory */ 2 | 3 | import os. 4 | 5 | main => 6 | Wd = pwd(), 7 | flatten_dir(Wd, Wd). 8 | 9 | flatten_dir(Wd, Dir) => 10 | Items = listdir(Dir), 11 | foreach (Item in Items, Item !== ".", Item !== "..") 12 | FullName = full_path(Dir, Item), 13 | (directory(FullName) -> 14 | flatten_dir(Wd, FullName) 15 | ; 16 | cp(FullName, full_path(Wd, Item)) 17 | ) 18 | end. 19 | 20 | full_path(Dir,Name) = 21 | Dir ++ [separator()] ++ Name. 22 | -------------------------------------------------------------------------------- /lib2/gen_check_all.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | gen("."). 8 | 9 | gen(Dir) => 10 | Files = listdir(Dir), 11 | foreach (File in Files, append("ins",Str,".in",File), member("ins"++Str++".out", Files)) 12 | printf("cat %s %s | python checker.py\n", File, "ins" ++ Str ++ ".out") 13 | end. 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib2/gen_comp_all.pi: -------------------------------------------------------------------------------- 1 | main => 2 | Lines = read_file_lines("all_csp"), 3 | foreach(Line in Lines) 4 | once append(MainFileStr,".csp",Line), 5 | printf("java -cp my_sugar.jar jp.kobe_u.sugar.SugarMain -encode %s.csp %s.cnf %s.tmp\n",MainFileStr,MainFileStr,MainFileStr) 6 | end. 7 | -------------------------------------------------------------------------------- /lib2/gen_conv.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Dirs = listdir("."), 5 | foreach (Dir in Dirs, not append(".",_,Dir), directory(Dir)) 6 | Files = listdir(Dir), 7 | if (member("data",Files)) then 8 | DFiles = listdir(Dir++"/data"), 9 | foreach (DFile in DFiles, (append(_,".dzn",DFile); append(_,".json",DFile))) 10 | cp(Dir++"/data/"++DFile, Dir++"/"++DFile) 11 | end 12 | end, 13 | if (member("instances",Files)) then 14 | DFiles = listdir(Dir++"/instances"), 15 | foreach (DFile in DFiles, (append(_,".dzn",DFile); append(_,".json",DFile))) 16 | cp(Dir++"/instances/"++DFile, Dir++"/"++DFile) 17 | end 18 | end, 19 | if once ((member(MznFile,Files), append(MznStr,".mzn",MznFile),not append(".",_,MznStr))), 20 | member(DznFile,Files), (append(_,".dzn",DznFile); append(_,".json",DznFile)) then 21 | foreach (File in Files, (append(InsStr,".dzn",File); append(InsStr,".json",File)), not append(".",_,File)) 22 | printf("echo converting %s\n",File), 23 | printf("minizinc -c -G picat --fzn %s_%s.fzn %s %s\n", Dir, InsStr, Dir++"/"++MznFile, Dir++"/"++File) 24 | end 25 | else 26 | foreach (File in Files, append(MznStr,".mzn",File), not append(".",_,File)) 27 | printf("echo converting %s\n",File), 28 | printf("minizinc -c -G picat --fzn %s_%s.fzn %s\n", Dir, MznStr, Dir++"/"++File) 29 | end 30 | end 31 | end. 32 | 33 | -------------------------------------------------------------------------------- /lib2/gen_conv_all.pi: -------------------------------------------------------------------------------- 1 | main => 2 | Lines = read_file_lines("all"), 3 | foreach(Line in Lines) 4 | printf("echo %s\n",Line), 5 | printf("/cygdrive/c/BProlog/Emulator/picat.exe /cygdrive/c/BProlog/Picat/sugar2pi %s\n",Line) 6 | end. 7 | -------------------------------------------------------------------------------- /lib2/gen_conv_fzn2julia.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = sort(listdir(".")), 5 | foreach (F in Fs, append(MainF,".fzn",F)) 6 | printf("echo converting %s\n",F), 7 | printf("time picat ~/work/sat/fzn2julia %s > %s.jl\n", F, MainF) 8 | end. 9 | 10 | -------------------------------------------------------------------------------- /lib2/gen_conv_fzn2picat.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainF,".fzn",F)) 6 | printf("echo converting %s\n",F), 7 | printf("picat ~/work/sat/fzn2picat %s > %s.pi\n", F, MainF) 8 | end. 9 | 10 | -------------------------------------------------------------------------------- /lib2/gen_conv_pb2julia.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainF,".opb",F)) 6 | printf("echo converting %s\n",F), 7 | printf("time timeout -k 1200 1200 picat pb2julia %s\n", F) 8 | end. 9 | 10 | -------------------------------------------------------------------------------- /lib2/gen_conv_pb2pi.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainF,".opb",F)) 6 | printf("echo converting %s\n",F), 7 | printf("time timeout -k 1200 1200 picat pb2pi %s\n", F) 8 | end. 9 | 10 | -------------------------------------------------------------------------------- /lib2/gen_conv_xcsp2julia.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainF,".xml",F), MainF != "_tmp") 6 | printf("echo converting %s\n",F), 7 | printf("time timeout -k 120 120 picat ~/solvers/xcsp23/xcsp2julia %s > %s.jl\n", F, MainF) 8 | end. 9 | 10 | -------------------------------------------------------------------------------- /lib2/gen_conv_xcsp2picat.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainF,".xml",F), MainF != "_tmp") 6 | printf("echo converting %s\n",F), 7 | printf("time timeout -k 120 120 picat ~/solvers/xcsp23/xcsp2picat %s > %s.pi\n", F, MainF) 8 | end. 9 | 10 | -------------------------------------------------------------------------------- /lib2/gen_diff.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main([D1,D2]) => 4 | Fs1 = listdir(D1), 5 | Fs2 = listdir(D2), 6 | foreach (F in Fs1, membchk(F,Fs2), not directory(F)) 7 | printf("echo %s\n", F), 8 | printf("diff %s %s\n", D1++"/"++F, D2++"/"++F) 9 | end. 10 | 11 | 12 | -------------------------------------------------------------------------------- /lib2/gen_extract_pattern.pi: -------------------------------------------------------------------------------- 1 | main => 2 | Lines = read_file_lines("solve_all"), 3 | foreach (Line in Lines, append(_,".opb",Line)) 4 | printf("echo %s\n",Line), 5 | printf("timeout 10 picat /cygdrive/c/BProlog/Picat/pb %s > %s.out\n",Line,Line) 6 | end. 7 | -------------------------------------------------------------------------------- /lib2/gen_indent_all.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".c", output a command line to indent the file */ 2 | /* by Neng-Fa Zhou, Sep. 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | create_emacs_format_file, 8 | Files = listdir("."), 9 | foreach (File in Files, append(_,".c",File)) 10 | printf("echo %s\n",File), 11 | printf("emacs -batch %s -l emacs_format_file -f emacs-format-function \n", File) 12 | end. 13 | 14 | create_emacs_format_file => 15 | INS = open("emacs_format_file",write), 16 | Content = 17 | ";;; File: emacs-format-file 18 | ;;; Stan Warford 19 | ;;; 17 May 2006 20 | 21 | (defun emacs-format-function () 22 | \"Format the whole buffer.\" 23 | (c-set-style \"stroustrup\") 24 | (indent-region (point-min) (point-max) nil) 25 | (untabify (point-min) (point-max)) 26 | (save-buffer) 27 | ) 28 | ", 29 | INS.print(Content), 30 | INS.close(). 31 | 32 | -------------------------------------------------------------------------------- /lib2/gen_make.pi: -------------------------------------------------------------------------------- 1 | main([File]) => 2 | Lines = read_file_lines(File), 3 | foreach(Line in Lines) 4 | append(Target,[':'|_],Line), 5 | println(Line), 6 | (append(MainTarget,".o",Target) -> 7 | printf("\tgcc -c -O3 %s.c\n",MainTarget) 8 | ; 9 | true 10 | ) 11 | end. 12 | -------------------------------------------------------------------------------- /lib2/gen_makefile.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main([Dir]) => 4 | Fs = listdir(Dir), 5 | print("KISSAT_OBJ = "), 6 | Count = 0, 7 | foreach (F in Fs, append(MainStr,".c",F)) 8 | printf("kis_%s.o ",MainStr), 9 | Count := Count+1, 10 | if Count mod 4 == 0 then 11 | println(" \\"), 12 | print(" ") 13 | end 14 | end, 15 | nl, 16 | foreach (F in Fs, append(MainStr,".c",F)) 17 | printf("kis_%s.o : %s/%s\n",MainStr, Dir, F), 18 | printf("\t$(CC) $(KISSAT_FLAGS) -o kis_%s.o %s/%s\n", MainStr, Dir, F) 19 | end. 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /lib2/gen_run_all.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Files = listdir("."), 5 | foreach (File in Files, append(MainFileStr,".pi",File)) 6 | printf("echo solving %s\n",MainFileStr), 7 | printf("picat.exe %s > tmp.out\n",MainFileStr), 8 | printf("diff tmp.out %s.out\n",MainFileStr) 9 | end. 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /lib2/gen_run_all0.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Files = listdir("."), 5 | foreach (File in Files, append(MainFileStr,".pi",File)) 6 | printf("echo solving %s\n",MainFileStr), 7 | printf("picat.exe %s > %s.out\n",MainFileStr,MainFileStr) 8 | end. 9 | -------------------------------------------------------------------------------- /lib2/gen_solve_all.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | Files = listdir(".").sort(), 8 | foreach (File in Files, append(_,".pi",File)) 9 | printf("echo solving %s\n",File), 10 | printf("time timeout -k 1200 1200 picat -log %s\n",File) 11 | end. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib2/gen_solve_all_dfvs.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | Files = listdir(".").sort(), 8 | foreach (File in Files, append(MainStr, ".bz2", File)) 9 | printf("echo solving %s\n",MainStr), 10 | printf("time timeout -k 600 600 picat dfvs %s\n",MainStr) 11 | end. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib2/gen_solve_all_fzn.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | gen("."). 8 | 9 | gen(Dir) => 10 | Files = listdir(Dir).sort(), 11 | foreach (File in Files, append(_,".fzn",File)) 12 | printf("echo solving %s\n",File), 13 | printf("time timeout -k 1200 1200 $HOME/BProlog/Emulator/fzn_picat_sat -log %s\n",File) 14 | end. 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib2/gen_solve_all_fzn_dump.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | gen("."). 8 | 9 | gen(Dir) => 10 | Files = listdir(Dir).sort(), 11 | foreach (File in Files, append(MainStr,".fzn",File)) 12 | printf("echo solving %s\n",File), 13 | printf("time timeout -k 1200 1200 ~/BProlog/Emulator/fzn_picat_sat %s\n",File), 14 | printf("cp __tmp.cnf %s.cnf\n", MainStr) 15 | end. 16 | 17 | 18 | -------------------------------------------------------------------------------- /lib2/gen_solve_all_julia.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | Files = listdir(".").sort(), 8 | foreach (File in Files, append(_,".jl",File)) 9 | printf("echo solving %s\n",File), 10 | printf("time timeout -k 1200 1200 julia %s\n",File) 11 | end. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib2/gen_solve_all_pc.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main([Com]) => 7 | gen(".",Com). 8 | 9 | gen(Dir,Com) => 10 | Files = listdir(Dir), 11 | foreach (File in Files, append("ins",Str,".in",File)) 12 | printf("echo picat %s %s %s\n", Com, File, "ins" ++ Str ++ ".out"), 13 | printf("picat %s < %s > %s\n", Com, File, "ins" ++ Str ++ ".out") 14 | end. 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib2/gen_solve_all_xcsp.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | gen("."). 8 | 9 | gen(Dir) => 10 | Files = listdir(Dir).sort(), 11 | foreach (File in Files, append(_,".xml",File)) 12 | printf("echo solving %s\n",File), 13 | printf("time timeout -k 300 300 ~/BProlog/Emulator/xcsp_picat -log %s\n",File) 14 | end. 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib2/gen_test_all_julia.pi: -------------------------------------------------------------------------------- 1 | /* for each file with the extension name ".pi", generate a command line to execute the file */ 2 | /* by Neng-Fa Zhou, 2015 */ 3 | 4 | import os. 5 | 6 | main => 7 | Files = listdir(".").sort(), 8 | foreach (File in Files, append("test_",_,".jl",File)) 9 | printf("echo solving %s\n",File), 10 | printf("julia %s\n",File) 11 | end. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib2/gen_unzip_all.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Files = listdir(".").sort(), 5 | foreach (File in Files, append(_,"lzma", File)) 6 | printf("7z x %s\n", File) 7 | end. 8 | -------------------------------------------------------------------------------- /lib2/globals.pi: -------------------------------------------------------------------------------- 1 | import cp. 2 | 3 | /* 4 | predicate value_precede_int(int: s, int: t, array[int] of var int: x) = 5 | let { 6 | int: imin = min(index_set(x)), 7 | int: imax = max(index_set(x)), 8 | array[imin..imax+1] of var bool: b 9 | } in ( 10 | forall (i in imin..imax) (let { 11 | var bool: xis = (x[i] == s) 12 | } in 13 | (xis -> (b[i+1] == true)) 14 | /\ ((not xis) -> (b[i] == b[i+1])) 15 | /\ ((not b[i]) -> (x[i] != t)) 16 | ) 17 | /\ b[imin] == false 18 | ); 19 | */ 20 | value_precede(S,T,X), list(X) => 21 | value_precede_aux(S,T,to_array(X)). 22 | value_precede(S,T,X), array(X) => 23 | value_precede_aux(S,T,X). 24 | value_precede(_S,_T,X) => 25 | handle_exception($list_or_array_expected(X),value_precede). 26 | 27 | value_precede_aux(S,T,X), integer(S), integer(T) => 28 | N = len(X), 29 | B = new_array(N+1), 30 | foreach (I in 1..N) 31 | Xis #= (X[i] #= S), 32 | Xis #=> B[I+1], 33 | #~ Xis #=> B[I] #= B[I+1], 34 | #~ B[I] #=> X[I] #!= T 35 | end, 36 | B[1] = 0. 37 | value_precede_aux(S,T,_X) => 38 | (integer(S) -> 39 | handle_exception($integer_expected(T),value_precede) 40 | ; 41 | handle_exception($integer_expected(S),value_precede) 42 | ). 43 | 44 | -------------------------------------------------------------------------------- /lib2/grep_rec.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main([Word]) => 4 | lookup_dir(".",Word). 5 | 6 | lookup_dir(Dir,Word) => 7 | Fs = listdir(Dir), 8 | foreach (F in Fs, F !== ".", F !== "..") 9 | lookup(Dir++"/"++F,Word) 10 | end. 11 | 12 | lookup(F,Word), directory(F) => 13 | lookup_dir(F,Word). 14 | lookup(F,Word), (append(_,".h",F); append(_,".cc",F); append(_,".c",F); append(_,".inc",F)) => 15 | lookup_plain(F,Word). 16 | lookup(F,Word) => true. 17 | 18 | lookup_plain(F,Word) => 19 | Lines = read_file_lines(F), 20 | foreach (Line in Lines) 21 | if append(_,Word,_,Line) then 22 | printf("%s: %s\n",F,Line) 23 | end 24 | end. 25 | 26 | 27 | -------------------------------------------------------------------------------- /lib2/list_set.pi: -------------------------------------------------------------------------------- 1 | module list_set. 2 | 3 | delete(LSet,Elm) = LSet1 => bp.list_set_del_element(LSet,Elm,LSet1). 4 | disjoint(LSet1,LSet2) => bp.list_set_disjoint(LSet1,LSet2). 5 | insert(LSet,Elm) = LSet1 => bp.b_LIST_SET_INSERT_ccf(LSet,Elm,LSet1). 6 | intersection(LSet1,LSet2)=LSet3 => bp.list_set_intersection(LSet1,LSet2,LSet3). 7 | membchk(E,LSet) => bp.list_set_member(E,LSet). 8 | new_list_set(List) = LSet => new_list_set_aux(List,[],LSet). 9 | list_set(Term) => bp.is_list_set(Term). 10 | subset(LSet1,LSet2) => bp.list_set_subset(LSet1,LSet2). 11 | subtract(LSet1,LSet2)=LSet3 => bp.list_set_subtract(LSet1,LSet2,LSet3). 12 | union(LSet1,LSet2)=LSet3 => bp.list_set_union(LSet1,LSet2,LSet3). 13 | 14 | new_list_set_aux([],LSet0,LSet) => LSet = LSet0. 15 | new_list_set_aux([E|List],LSet0,LSet) => 16 | bp.b_LIST_SET_INSERT_ccf(LSet0,E,LSet1), 17 | new_list_set_aux(List,LSet1,LSet). 18 | 19 | -------------------------------------------------------------------------------- /lib2/remove_c.pi: -------------------------------------------------------------------------------- 1 | main([File,OFile]) => 2 | printf("%s %s\n",File, OFile), 3 | FD = open(File), 4 | FD.read_line() = Line, 5 | OFD = open(OFile, write), 6 | proc(Line,FD,OFD). 7 | 8 | proc(end_of_file,FD,OFD) => 9 | close(FD), 10 | close(OFD). 11 | proc([c,' '|_],FD,OFD) => 12 | FD.read_line() = Line, 13 | proc(Line,FD,OFD). 14 | proc([],FD,OFD) => 15 | nl(OFD), 16 | FD.read_line() = Line, 17 | proc(Line,FD,OFD). 18 | proc(Line,FD,OFD) => 19 | OFD.println(Line), 20 | FD.read_line() = NLine, 21 | proc(NLine,FD,OFD). 22 | -------------------------------------------------------------------------------- /lib2/remove_dirs.pi: -------------------------------------------------------------------------------- 1 | /* copy all the plain files from subdirectories to the current directory */ 2 | 3 | import os. 4 | 5 | main => 6 | Wd = pwd(), 7 | remove_dir(Wd, Wd). 8 | 9 | remove_dir(Wd, Dir) => 10 | Items = listdir(Dir), 11 | foreach (Item in Items, Item !== ".", Item !== "..") 12 | FullName = full_path(Dir, Item), 13 | (directory(FullName) -> 14 | Command = "rm -r " ++ FullName, 15 | _ = command(Command) 16 | ; 17 | true 18 | ) 19 | end. 20 | 21 | full_path(Dir,Name) = 22 | Dir ++ [separator()] ++ Name. 23 | -------------------------------------------------------------------------------- /lib2/remove_empty_lines.pi: -------------------------------------------------------------------------------- 1 | main([File]) => 2 | Ls = read_file_lines(File), 3 | foreach (L in Ls, L !== []) 4 | println(L) 5 | end. 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib2/remove_stranges.pi: -------------------------------------------------------------------------------- 1 | /* copy all the plain files from subdirectories to the current directory */ 2 | 3 | import os. 4 | 5 | main => 6 | Wd = pwd(), 7 | remove_strange_dir(Wd, Wd). 8 | 9 | remove_strange_dir(Wd, Dir) => 10 | Items = listdir(Dir), 11 | foreach (Item in Items, Item !== ".", Item !== "..") 12 | FullName = full_path(Dir, Item), 13 | (directory(FullName) -> 14 | remove_strange_dir(Wd, FullName) 15 | ; (Item = ['#'|_] || append(_,"~",Item)) -> 16 | Command = "rm -r " ++ FullName, 17 | _ = command(Command) 18 | ; 19 | true 20 | ) 21 | end. 22 | 23 | full_path(Dir,Name) = 24 | Dir ++ [separator()] ++ Name. 25 | -------------------------------------------------------------------------------- /lib2/rm_incomplete.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainStr,".jl",F)) 6 | if not complete(F) then 7 | Command = "mv " ++ MainStr ++ ".*" ++ " hard", 8 | println(Command), 9 | _ = command(Command) 10 | end 11 | end. 12 | 13 | complete(File) => 14 | IS = open(File), 15 | my_read_lines(IS,Lines), 16 | close(IS), 17 | member(Line, Lines), 18 | % append(_,[s,o,l,v,e,'('|_],Line), 19 | append([r,e,s,' ', '='|_],_,Line), 20 | !. 21 | 22 | my_read_lines(IS,Lines) => 23 | my_read_line(IS,Line), 24 | (Line == end_of_file -> 25 | Lines = [] 26 | ; 27 | Lines = [Line|LinesR], 28 | my_read_lines(IS,LinesR) 29 | ). 30 | 31 | my_read_line(IS,Line) => 32 | Ch = read_char(IS), 33 | (Ch == end_of_file -> 34 | Line = end_of_file 35 | ; 36 | my_read_line(IS,Ch,Line) 37 | ). 38 | 39 | my_read_line(IS,'\n',Line) => Line = []. 40 | my_read_line(IS,end_of_file,Line) => Line = []. 41 | my_read_line(IS,Ch,Line) => 42 | Line = [Ch|LineR], 43 | NextCh = read_char(IS), 44 | my_read_line(IS,NextCh,LineR). 45 | 46 | 47 | -------------------------------------------------------------------------------- /lib2/rm_pi_jl.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | Fs = listdir(".").sort(), 5 | foreach (F in Fs, append(MainStr,".jl",F)) 6 | if not exists(MainStr++".pi") then 7 | Command = "mv " ++ MainStr ++ ".*" ++ " hard", 8 | println(Command), 9 | _ = command(Command) 10 | end 11 | end. 12 | 13 | -------------------------------------------------------------------------------- /lib2/state_list.pi: -------------------------------------------------------------------------------- 1 | module state_list. 2 | 3 | 4 | -------------------------------------------------------------------------------- /lib2/sum_time.pi: -------------------------------------------------------------------------------- 1 | import util. 2 | 3 | main([File]),string(File) => 4 | proc_file(File). 5 | 6 | main => 7 | proc_file("trace"). 8 | 9 | proc_file(File) => 10 | Lines = read_file_lines(File), 11 | proc_lines0(Lines,0,Time), 12 | printf("Total real time %fs\n", Time). 13 | 14 | proc_lines0([],Time0,Time) => Time = Time0. 15 | proc_lines0([Line|Lines],Time0,Time), 16 | append("real",Rem,Line) 17 | => 18 | [M,S] = split(Rem,"ms"), 19 | Time1 is Time0+to_number(M)*3600+to_number(S), 20 | proc_lines0(Lines,Time1,Time). 21 | proc_lines0([_Line|Lines],Time0,Time) => 22 | proc_lines0(Lines,Time0,Time). 23 | -------------------------------------------------------------------------------- /lib2/tabular_runtimes.pi: -------------------------------------------------------------------------------- 1 | main(Files@[File1|_]) => 2 | extract_benchmarks(File1,Probs), 3 | RTLists = [RTList : File in Files, extract_runtimes(File,RTList)], 4 | foreach (Tuple in zip([Probs|RTLists])) 5 | output_tuple(Tuple) 6 | end. 7 | 8 | output_tuple(Tuple) => 9 | foreach (I in 1..len(Tuple)) 10 | print(Tuple[I]), 11 | if I == len(Tuple) then 12 | println(" \\\\") 13 | else 14 | print(" & ") 15 | end 16 | end. 17 | 18 | extract_benchmarks(File,Probs) => 19 | Lines = read_file_lines(File), 20 | Probs = [Prob : Line in Lines, append(_,"solving ",Prob,Line)]. 21 | 22 | extract_runtimes(File,RTList) => 23 | Lines = read_file_lines(File), 24 | RTList = [Runtime : Line in Lines, append(_,"real",Runtime,Line)]. 25 | 26 | -------------------------------------------------------------------------------- /lib2/traverse_dir.pi: -------------------------------------------------------------------------------- 1 | import os. 2 | 3 | main => 4 | traverse_dir(0, "."). 5 | 6 | traverse_dir(Depth, Dir) => 7 | Dirs = listdir(Dir), 8 | foreach (File in Dirs, File !== ".", File !== "..") 9 | FullName = Dir ++ "/" ++ File, 10 | if directory(FullName) then 11 | traverse_dir(Depth+1, FullName) 12 | else 13 | printf("%*s%s\n", 4*Depth, "", File) 14 | end 15 | end. 16 | -------------------------------------------------------------------------------- /lib2/trim_lines.pi: -------------------------------------------------------------------------------- 1 | import util. 2 | 3 | main([File]) => 4 | IS = open(File), 5 | Line = IS.read_line(), 6 | while (Line !== end_of_file) 7 | printf("%s\n",strip(Line)), 8 | Line := IS.read_line() 9 | end, 10 | close(IS). 11 | 12 | -------------------------------------------------------------------------------- /lib2/unzip_all.pi: -------------------------------------------------------------------------------- 1 | /* copy all the plain files from subdirectories to the current directory */ 2 | 3 | import os. 4 | 5 | main([ExtStr]) => 6 | Wd = pwd(), 7 | unzip_dir(ExtStr,Wd, Wd). 8 | 9 | unzip_dir(ExtStr, Wd, Dir) => 10 | Items = listdir(Dir), 11 | foreach (Item in Items, Item !== ".", Item !== "..") 12 | FullName = full_path(Dir, Item), 13 | (directory(FullName) -> 14 | true 15 | % unzip_dir(ExtStr, Wd, FullName) 16 | ; append(_,ExtStr,Item) -> 17 | Command = "7z x " ++ FullName, 18 | println(Command), 19 | _ = command(Command) 20 | ; 21 | true 22 | ) 23 | end. 24 | 25 | full_path(Dir,Name) = 26 | Dir ++ [separator()] ++ Name. 27 | --------------------------------------------------------------------------------