├── .github ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ ├── nightly-packages.yml │ ├── release-packages.yml │ ├── test-debug.yml │ └── test-release.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── DEVELOPMENT.md ├── Dockerfile ├── LICENSE.txt ├── README.md ├── VERSION ├── benchmark.sh ├── build.sh ├── clean.sh ├── cmake ├── generate-parser.cmake ├── git-defs.cmake ├── mingw-w64-x86_64.cmake ├── tau-common.cmake └── version_license.h.template ├── coverage.sh ├── debug.sh ├── demos ├── demo_1.1-basic_syntax_and_history.tau ├── demo_1.2-commands_and_history.tau ├── demo_1.3-recurrence_relations.tau ├── demo_1.4-normalization.tau ├── demo_2.1-strong_normalizationof_wff.tau ├── demo_2.2-solver.tau ├── demo_2.3-solver-min_max.tau ├── demo_3.1-interpreter_sbf.tau ├── demo_3.2-interpreter_tau.tau ├── demo_3.3-interpreter_fpbf.tau ├── run.sh └── sample_demo.tau ├── docs ├── Doxyfile.in ├── Theories-and-Applications-of-Boolean-Algebras-0.25.pdf └── images │ ├── TauNet_banner.png │ ├── Tau_Banner.png │ ├── tau_logo.png │ └── tau_logo.svg ├── examples └── .gitkeep ├── external ├── .gitkeep └── libboost-mingw-builder.sh ├── extract_packages.sh ├── packages.sh ├── parser ├── bitvector.tgf ├── bitvector_parser.generated.h ├── gen ├── sbf.tgf ├── sbf_parser.generated.h ├── tau.tgf └── tau_parser.generated.h ├── release.sh ├── relwithdebinfo.sh ├── save_benchmarks.sh ├── src ├── CMakeLists.txt ├── boolean_algebras │ ├── bdds │ │ ├── babdd.h │ │ └── bdd_handle.h │ ├── bool_ba.cpp │ ├── bool_ba.h │ ├── nso_ba.h │ ├── nso_ba.tmpl.h │ ├── product_ba.h │ ├── sbf_ba.h │ ├── sbf_ba.tmpl.h │ ├── tau_ba.h │ ├── tau_ba.tmpl.h │ └── variant_ba.h ├── builders.h ├── debug_helpers.h ├── definitions.h ├── defs.h ├── dict.cpp ├── dict.h ├── execution.h ├── experimental │ └── execution.h ├── hooks.h ├── hooks.tmpl.h ├── init_log.h ├── interpreter.h ├── interpreter.impl.h ├── language.h ├── language.tmpl.h ├── main.cpp ├── normal_forms.h ├── normalizer.h ├── nso_rr.cpp ├── nso_rr.h ├── queries.h ├── repl_evaluator.h ├── repl_evaluator.tmpl.h ├── satisfiability.h ├── solver.h ├── solver.tmpl.h ├── splitter.h ├── splitter_types.h └── utils.h ├── test-debug.sh ├── test-release.sh ├── test-relwithdebinfo.sh ├── tests ├── CMakeLists.txt ├── benchmark │ ├── CMakeLists.txt │ ├── test_benchmark-helper.h │ ├── test_benchmark-interpreter.cpp │ └── test_benchmark-wff_normalization.cpp ├── experimental │ ├── CMakeLists.txt │ └── test_experimental_execution.cpp ├── integration │ ├── CMakeLists.txt │ ├── test_files │ │ ├── sbf-alternating_zeros_and_ones-length_10.in │ │ ├── sbf-alternating_zeros_and_ones-length_2.in │ │ ├── sbf-ones-length_1.in │ │ ├── sbf-ones-length_10.in │ │ ├── sbf-zeros-length_1.in │ │ ├── sbf-zeros-length_10.in │ │ └── tau-alternating_zeros_and_ones-length_10.in │ ├── test_integration-bf_fixed_point.cpp │ ├── test_integration-bf_hooks.cpp │ ├── test_integration-bf_normalization.cpp │ ├── test_integration-interpreter.cpp │ ├── test_integration-normal_forms.cpp │ ├── test_integration-nso_rr_execution.cpp │ ├── test_integration-nso_rr_fixed_point.cpp │ ├── test_integration-nso_rr_partial_eval.cpp │ ├── test_integration-quantifiers.cpp │ ├── test_integration-ref_types.cpp │ ├── test_integration-satisfiability.cpp │ ├── test_integration-sbf1.cpp │ ├── test_integration-sbf2.cpp │ ├── test_integration-solver.cpp │ ├── test_integration-splitter.cpp │ ├── test_integration-splitter2.cpp │ ├── test_integration-tau1.cpp │ ├── test_integration-tau2.cpp │ ├── test_integration-tau_ba1.cpp │ ├── test_integration-tau_ba3.cpp │ ├── test_integration-wff_hooks.cpp │ ├── test_integration-wff_normalization.cpp │ └── test_integration_helpers.h ├── repl │ ├── CMakeLists.txt │ ├── commands │ │ ├── CMakeLists.txt │ │ ├── test_repl-definition_cmd.cmake │ │ ├── test_repl-get_cmd.cmake │ │ ├── test_repl-help_cmd.cmake │ │ ├── test_repl-history_cmd.cmake │ │ ├── test_repl-normal_forms_cmd.cmake │ │ ├── test_repl-normalize_cmd.cmake │ │ ├── test_repl-qelim_cmd.cmake │ │ ├── test_repl-quit_cmd.cmake │ │ ├── test_repl-set_cmd.cmake │ │ ├── test_repl-toggle_cmd.cmake │ │ └── test_repl-version_cmd.cmake │ ├── instantiation │ │ └── CMakeLists.txt │ ├── interpreter │ │ └── CMakeLists.txt │ ├── normal_forms │ │ ├── CMakeLists.txt │ │ ├── test_repl-cnf.cmake │ │ ├── test_repl-dnf.cmake │ │ ├── test_repl-mnf.cmake │ │ ├── test_repl-nnf.cmake │ │ ├── test_repl-onf.cmake │ │ └── test_repl-snf.cmake │ ├── normalizer │ │ └── CMakeLists.txt │ ├── qelim │ │ └── CMakeLists.txt │ ├── satisfiability │ │ └── CMakeLists.txt │ ├── solver │ │ └── CMakeLists.txt │ └── substitution │ │ └── CMakeLists.txt └── unit │ ├── CMakeLists.txt │ ├── test_bindings.cpp │ ├── test_bool.cpp │ ├── test_builders.cpp │ ├── test_hbdd.cpp │ ├── test_helpers.h │ ├── test_interpreter.cpp │ ├── test_make_node_hook.cpp │ ├── test_normal_forms.cpp │ ├── test_normalizer.cpp │ ├── test_nso_rr.cpp │ ├── test_product_ba.cpp │ ├── test_rewriting.cpp │ ├── test_rules-bf_execution.cpp │ ├── test_rules-bf_parsing.cpp │ ├── test_rules-wff_execution.cpp │ ├── test_rules-wff_parsing.cpp │ ├── test_sbf_ba_binding.cpp │ ├── test_tau.cpp │ ├── test_tau_parser.cpp │ ├── test_traversal.cpp │ ├── test_type_system.cpp │ └── test_variant_ba.cpp ├── w64-debug.sh ├── w64-packages.sh ├── w64-release.sh └── wine-test.sh /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Template for reporting a bug 4 | title: A concise title for the bug 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 1. **Summary** 11 | - **Description:** _Bug Summary in 2 to 3 sentences._ 12 | 13 | 2. **Environment** 14 | - **Tau Version:** for now "v0.7-alpha" 15 | - **Build Number or Date:** YYYY/MM/DD 16 | - **Operating System:** Windows/Ubuntu/Fedora... 17 | 18 | 3. **Steps to Reproduce** 19 | Step 1: What input did you first provide? 20 | Step 2: Any additional input to Tau? 21 | 22 | **Expected Result** 23 | 24 | **Actual Result** 25 | 26 | 4. **Additional Information** 27 | - **Error Messages or Logs:** 28 | - **Screenshots:** 29 | 30 | 5. **Severity and Impact** 31 | - **Severity Level:** Critical/Major/Minor/Trivial 32 | - **Impact on Work:** Crash/Program Hanging 33 | 34 | 6. **Workaround (if applicable)** 35 | - Tell us if you found a way around this problem: 36 | 37 | 7. **Contact Information** 38 | - **Name:** Your name or username. 39 | - **Email:** Your email address or preferred contact method, or simply ERC20 wallet address for bug bounty 40 | - **Additional Notes:** Any other message for the Tau Team 41 | 42 | **Submission Instructions** 43 | - Make sure to attach any input files to this bug report. 44 | -------------------------------------------------------------------------------- /.github/workflows/nightly-packages.yml: -------------------------------------------------------------------------------- 1 | name: Nightly Packages 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | workflow_dispatch: 7 | 8 | jobs: 9 | check_date: 10 | runs-on: ubuntu-24.04 11 | name: Check latest commit 12 | outputs: 13 | should_run: ${{ steps.should_run.outputs.should_run }} 14 | steps: 15 | - uses: actions/checkout@v4 16 | 17 | - name: print latest_commit 18 | run: echo ${{ github.sha }} 19 | 20 | - id: should_run 21 | continue-on-error: true 22 | name: check latest commit is less than a day 23 | if: ${{ github.event_name == 'schedule' }} 24 | run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "::set-output name=should_run::false" 25 | 26 | build_and_deploy_nightly: 27 | needs: check_date 28 | if: ${{ needs.check_date.outputs.should_run != 'false' }} 29 | runs-on: ubuntu-24.04 30 | steps: 31 | - uses: actions/checkout@v4 32 | 33 | - name: Build image with nightly packages 34 | run: docker build --build-arg RELEASE="yes" --build-arg NIGHTLY="yes" -t packages . 35 | 36 | - name: Copy nightly packages from container 37 | run: | 38 | CID=$(docker create packages) 39 | docker cp $CID:/tau-lang/build-Release/packages ${{ github.workspace }}/ 40 | docker rm $CID 41 | 42 | - name: Read Version 43 | id: version 44 | run: echo "version=v$(head -n 1 VERSION)" >> $GITHUB_ENV 45 | 46 | - name: Get ISO date 47 | id: date_iso 48 | run: echo "date_iso=$(date --iso)" >> $GITHUB_ENV 49 | 50 | - name: Upload nightly packages 51 | uses: actions/upload-artifact@v4 52 | with: 53 | name: "nightly-${{ env.date_iso }}" 54 | path: ${{ github.workspace }}/packages/ 55 | 56 | - name: Create Nightly Build Release 57 | uses: softprops/action-gh-release@v2 58 | with: 59 | tag_name: "nightly-${{ env.date_iso }}" 60 | name: "Tau Language Framework ${{ env.version }} Nightly Build ${{ env.date_iso }}" 61 | body: "Tau Language Framework ${{ env.version }} automated nightly build ${{ env.date_iso }} commit ${{ github.sha }}" 62 | draft: false 63 | prerelease: true 64 | files: ${{ github.workspace }}/packages/* 65 | env: 66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/release-packages.yml: -------------------------------------------------------------------------------- 1 | name: Release Packages 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build_and_deploy: 8 | runs-on: ubuntu-24.04 9 | steps: 10 | - uses: actions/checkout@v4 11 | 12 | - name: Build image with release packages 13 | run: docker build --build-arg RELEASE="yes" -t packages . 14 | 15 | - name: Copy release packages from container 16 | run: | 17 | CID=$(docker create packages) 18 | docker cp $CID:/tau-lang/build-Release/packages ${{ github.workspace }}/ 19 | docker rm $CID 20 | 21 | - name: Read Version 22 | id: version 23 | run: echo "version=v$(head -n 1 VERSION)" >> $GITHUB_ENV 24 | 25 | - name: Get ISO date 26 | id: date_iso 27 | run: echo "date_iso=$(date --iso)" >> $GITHUB_ENV 28 | 29 | - name: Upload release packages 30 | uses: actions/upload-artifact@v4 31 | with: 32 | name: "v${{ env.version }}" 33 | path: ${{ github.workspace }}/packages/ 34 | 35 | - name: Create Release 36 | uses: softprops/action-gh-release@v2 37 | with: 38 | tag_name: "v${{ env.version }}" 39 | name: "Tau Language Framework ${{ env.version }}" 40 | body: "Tau Language Framework ${{ env.version }} release ${{ env.date_iso }} commit ${{ github.sha }}" 41 | draft: true 42 | prerelease: true 43 | files: ${{ github.workspace }}/packages/* 44 | env: 45 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/test-debug.yml: -------------------------------------------------------------------------------- 1 | name: Test Debug 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | test-debug: 11 | runs-on: ubuntu-24.04 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: Build debug tests and run them 16 | run: docker build --build-arg TESTS="yes" --build-arg BUILD_TYPE="Debug" -t debug-tester . 17 | -------------------------------------------------------------------------------- /.github/workflows/test-release.yml: -------------------------------------------------------------------------------- 1 | name: Test Release 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | test-release: 11 | runs-on: ubuntu-24.04 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: Build release tests and run them 16 | run: docker build --build-arg TESTS="yes" --build-arg BUILD_TYPE="Release" -t release-tester . 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # IDE files 35 | .idea 36 | .vscode 37 | 38 | # GitHub local files 39 | *.github-issues 40 | 41 | # Cmake generated files 42 | build 43 | build-* 44 | cmake-build* 45 | tau-config.cmake 46 | CMakeFiles 47 | CMakeFiles/* 48 | Makefile 49 | CMakeCache.txt 50 | *.cmake 51 | *.nocmake 52 | !cmake/* 53 | !tests/repl/commands/* 54 | !tests/repl/execution/* 55 | !tests/repl/normal_forms/* 56 | !tests/repl/normalizer/* 57 | !tests/repl/satisfiability/* 58 | src/doctest.h 59 | src/version_license.h 60 | Testing 61 | 62 | # Sonarqube 63 | .scannerwork 64 | bw-output 65 | 66 | # private directory for a local stuff 67 | .local 68 | 69 | # cli history files 70 | .*_history 71 | 72 | # other files 73 | /.cache/* 74 | tests/benchmark/data/* 75 | logs/* 76 | .gdbinit 77 | external/boost 78 | libboost-mingw-w64 -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/parser"] 2 | path = external/parser 3 | url = https://github.com/IDNI/parser.git 4 | -------------------------------------------------------------------------------- /DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | ![The TAU logo](/docs/tau_logo.svg) 2 | 3 | Tau advances formal methods by removing coding from the process, while expanding its industrial capability, reliability and ease of maintenance. Tau enables you to automatically create the most complex, provably correct software, by simply writing sentences about what you want the software to do. 4 | 5 | Tau Language is able to embed and extend the most powerful decidable knowledge representation languages, logics, and Boolean algebras to describe states in the specification. 6 | Tau Language is able to embed and extend the most powerful decidable knowledge representation languages and logics to describe states in the Tau specification. 7 | 8 | This Document deals with general remarks to take into account during the development and testing of the Tau Language and the Tau Language API. 9 | 10 | # General remarks 11 | 12 | Throughout all the code we would use the following tags to denote different types of tasks or notes. We use TODO, DOING, IDEA, FIXME, REVIEW, DOCUMENTATION and MARK. Also, we could give a priority to each task by adding HIGH, LOW or MEDIUM between parenthesis. 13 | 14 | We use the subtags as follows: 15 | - (IMPORTANT) for main tasks of the project, 16 | - (HIGH) for tasks that should be done asap as they are important missing functionality or important improvements, 17 | - (MEDIUM) for tasks that should be done soon as they are but they are not missing functionality or important improvements, mostly related to code quality and testing, 18 | - (LOW) for tasks that should be done at some point but they are not important, mostly related to code quality and testing but not as important as MEDIUM tasks, 19 | - (VERY LOW) for tasks that should be done at some point but they are not important, mostly related to code quality and testing but not as important as LOW tasks. 20 | 21 | # Development and testing of Tau Language 22 | 23 | Check the `README.md`for details about compiling and running the Tau Language (in both Debug and Release mode). 24 | 25 | # Standalone executables 26 | 27 | We provide a set of standalone executables that are able to parse, normalize using different sets of BAs. The standalone executables are able to work with BDDs and BA of Tau over BBDs. 28 | 29 | ## Normalizer (BDDs and BA of Tau over BBDs) 30 | 31 | This normalizer is a standalone executable that takes a NSO formula with recurrence relations, over the BDDs and over the Tau BA over BBDs, and normalizes it. The name of the executable is 32 | `runner-normalizer-tau_over_bdd`. It only takes one argument, the path to the file containing the NSO formula with recurrence relations to normalize, p.e.: 33 | 34 | ```bash 35 | runner-normalizer-tau_over_bdd /path/to/file 36 | ``` 37 | 38 | ## Normalizer (BDDs) 39 | 40 | This normalizer is a standalone executable that takes a NSO formula with recurrence relations, over the BDDs, and normalizes it. The name of the executable is `runner-normalizer-bdd`. It only takes one argument, the path to the file containing the NSO formula with recurrence relations to normalize, p.e.: 41 | 42 | ```bash 43 | runner-normalizer-bdd /path/to/file 44 | ``` 45 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # This is a Dockerfile for building, testing, packaging and running the tau-lang 2 | 3 | # To build the image with tag 'tau' from ./Dockerfile: 4 | # docker build -t tau . 5 | 6 | # use --build-arg TESTS="no" to skip running tests 7 | # use --build-arg BUILD_TYPE="Debug" for building of the debugging version 8 | 9 | # To run tau using the created image in interactive mode: 10 | # docker run --rm -it tau [] 11 | 12 | # --rm flag is used to remove the container after it exits 13 | 14 | 15 | FROM ubuntu:24.04 16 | 17 | # Install dependencies 18 | RUN apt-get update && apt-get install -y \ 19 | bash wget git nsis rpm \ 20 | cmake=3.28.3-1build7 \ 21 | g++=4:13.2.0-7ubuntu1 \ 22 | mingw-w64=11.0.1-3build1 \ 23 | libboost-all-dev=1.83.0.1ubuntu2 \ 24 | libz3-dev=4.8.12-3.1build1 \ 25 | python3-distutils-extra 26 | 27 | # Argument BUILD_TYPE=Debug/Release 28 | ARG BUILD_TYPE=Release 29 | 30 | # Argument RELEASE=yes is used to build release packages 31 | ARG RELEASE=no 32 | 33 | # Argument NIGHTLY=yes is used to build nightly packages (works only if RELEASE=yes) 34 | ARG NIGHTLY=no 35 | 36 | # Argument TESTS=no is used to skip running tests 37 | ARG TESTS=yes 38 | 39 | # Copy source code 40 | COPY ./ /tau-lang 41 | 42 | # # OR clone from git 43 | # RUN git clone https://github.com/IDNI/tau-lang /tau-lang 44 | 45 | WORKDIR /tau-lang 46 | 47 | RUN ./clean.sh 48 | 49 | # if NIGHTLY is set to yes, then add .YYYY-MM-DD to the first line of the VERSION file 50 | RUN if [ "$NIGHTLY" = "yes" ]; then \ 51 | echo -n "$(head -n 1 VERSION)-$(date --iso)" > VERSION; \ 52 | fi 53 | RUN echo "(BUILD) -- Building version: $(head -n 1 VERSION)" 54 | 55 | # Build tests and run them if TESTS is set to yes. Stop the build if they fail 56 | RUN echo " (BUILD) -- Running tests: $TESTS" 57 | RUN if [ "$TESTS" = "yes" ]; then \ 58 | ./build.sh "${BUILD_TYPE}" -DTAU_BUILD_TESTS=ON && \ 59 | cd tests && \ 60 | ctest -j 8 --test-dir "../build-${BUILD_TYPE}" --output-on-failure \ 61 | || exit 1; \ 62 | fi 63 | 64 | RUN echo "(BUILD) -- Building packages: $RELEASE (nightly: $NIGHTLY)" 65 | 66 | # Linux packages 67 | RUN if [ "$RELEASE" = "yes" ]; then \ 68 | ./packages.sh && rm ./build-Release/CMakeCache.txt; \ 69 | fi 70 | 71 | # Windows packages 72 | RUN if [ "$RELEASE" = "yes" ]; then \ 73 | cd external && ./libboost-mingw-builder.sh && cd .. && \ 74 | ./w64-packages.sh; \ 75 | fi 76 | 77 | # If tau executable does not exist already, build it 78 | RUN if [ ! -f ./build-${BUILD_TYPE}/tau ]; then ./build.sh "${BUILD_TYPE}"; fi 79 | 80 | # Set the entrypoint to the tau executable 81 | WORKDIR /tau-lang/build-${BUILD_TYPE} 82 | ENTRYPOINT [ "./tau" ] 83 | CMD [] 84 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.7.0-alpha -------------------------------------------------------------------------------- /benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh RelWithDebInfo $@ 4 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_TYPE="${1:-Release}" 4 | case "${BUILD_TYPE}" in 5 | "Debug") 6 | SUFFIX="Debug" 7 | ;; 8 | "Release") 9 | SUFFIX="Release" 10 | ;; 11 | "RelWithDebInfo") 12 | SUFFIX="RelWithDebInfo" 13 | ;; 14 | "Coverage") 15 | SUFFIX="Coverage" 16 | ;; 17 | *) 18 | echo "Unknown build type: ${BUILD_TYPE}" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | BUILD_DIR="build-${SUFFIX}" 24 | 25 | git submodule status | while read -r LINE; do 26 | GIT_SUBMOD=$(echo $LINE | awk '{print $2}') 27 | if [[ $LINE == -* ]]; then 28 | echo "Initializing submodule $GIT_SUBMOD" 29 | git submodule update --init --recursive $GIT_SUBMOD 30 | else 31 | echo "Submodule ${GIT_SUBMOD} is already initialized" 32 | fi 33 | done 34 | 35 | mkdir -p "${BUILD_DIR}" 36 | cd "${BUILD_DIR}" 37 | rm -f ./CMakeCache.txt 38 | 39 | NINJA_BIN="$(which ninja 2>&1)"; 40 | if [ $? -ne 0 ]; then 41 | NINJA_BIN="$(which ninja-build 2>&1)"; 42 | if [ $? -ne 0 ]; then 43 | NINJA_BIN=""; 44 | fi 45 | fi 46 | 47 | if [ -z $NINJA_BIN ]; then 48 | echo "Using make build system" 49 | cmake .. -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${@:2} 50 | cmake --build . -- -j5 51 | STATUS=$? 52 | else 53 | echo "Using Ninja build system" 54 | cmake .. -G Ninja -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ${@:2} 55 | ninja 56 | STATUS=$? 57 | fi 58 | 59 | cd .. 60 | 61 | exit $STATUS 62 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf build-Release/ build-Debug/ build/ tau-config.cmake Testing/ build-RelWithDebInfo/ 4 | -------------------------------------------------------------------------------- /cmake/generate-parser.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | set(GEN_DIR "${PROJECT_SOURCE_DIR}/parser") 4 | set(GEN_EXECUTABLE "${GEN_DIR}/gen") 5 | 6 | function(generate_parser tgf_filename) 7 | execute_process(COMMAND ${GEN_EXECUTABLE} "${tgf_filename}" 8 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) 9 | endfunction(generate_parser) 10 | -------------------------------------------------------------------------------- /cmake/git-defs.cmake: -------------------------------------------------------------------------------- 1 | # populates GIT_DESCRIBED, GIT_BRANCH and GIT_COMMIT_HASH variables 2 | # and creates GIT_DEFINITIONS list 3 | 4 | execute_process( 5 | COMMAND git describe --tags --always 6 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 7 | OUTPUT_VARIABLE GIT_DESCRIBED 8 | OUTPUT_STRIP_TRAILING_WHITESPACE 9 | ) 10 | execute_process( 11 | COMMAND git rev-parse --abbrev-ref HEAD 12 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 13 | OUTPUT_VARIABLE GIT_BRANCH 14 | OUTPUT_STRIP_TRAILING_WHITESPACE 15 | ) 16 | execute_process( 17 | COMMAND git log -1 --format=%h 18 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 19 | OUTPUT_VARIABLE GIT_COMMIT_HASH 20 | OUTPUT_STRIP_TRAILING_WHITESPACE 21 | ) 22 | 23 | set(GIT_DEFINITIONS 24 | "GIT_DESCRIBED=\"${GIT_DESCRIBED}\"" 25 | "GIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"" 26 | "GIT_BRANCH=\"${GIT_BRANCH}\"" 27 | ) 28 | -------------------------------------------------------------------------------- /cmake/mingw-w64-x86_64.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Windows) 2 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 3 | set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) 4 | 5 | set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) 6 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) 7 | 8 | set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -------------------------------------------------------------------------------- /cmake/tau-common.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 3 | message(STATUS 4 | "${PROJECT_NAME} as a subproject of [${CMAKE_PROJECT_NAME}]") 5 | else() 6 | message(STATUS "${PROJECT_NAME} as a top project") 7 | endif() 8 | 9 | cmake_host_system_information(RESULT CORE_COUNT QUERY NUMBER_OF_LOGICAL_CORES) 10 | if(CMAKE_CONFIGURATION_TYPES) 11 | set(CMAKE_CONFIGURATION_TYPES Debug Release) 12 | set(CMAKE_CONFIGURATION_TYPES 13 | "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "" FORCE 14 | ) 15 | endif() 16 | if(NOT CMAKE_BUILD_TYPE) 17 | set(CMAKE_BUILD_TYPE "Release") 18 | endif() 19 | message(STATUS "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") 20 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 21 | message(STATUS "CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}") 22 | message(STATUS "CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}") 23 | endif () 24 | 25 | set(CMAKE_VERBOSE_MAKEFILE true CACHE BOOL "") 26 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 27 | set(USED_CMAKE_GENERATOR 28 | "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE 29 | ) 30 | if(USED_CMAKE_GENERATOR MATCHES "Ninja") 31 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") 32 | endif() 33 | 34 | set(TAU_DEBUG_OPTIONS "-O0;-DDEBUG;-ggdb3") 35 | set(TAU_RELEASE_OPTIONS "-O3;-DNDEBUG;-flto=auto") 36 | set(TAU_RELWITHDEBINFO_OPTIONS "-O3;-DNDEBUG;-flto=auto;-g") 37 | 38 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") 39 | set(COMPILE_OPTIONS "${TAU_DEBUG_OPTIONS}") 40 | elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") 41 | set(COMPILE_OPTIONS "${TAU_RELWITHDEBINFO_OPTIONS}") 42 | elseif (CMAKE_BUILD_TYPE STREQUAL "Release") 43 | set(COMPILE_OPTIONS "${TAU_RELEASE_OPTIONS}") 44 | endif() 45 | 46 | set(LINK_OPTIONS "-flto=auto") 47 | 48 | message(STATUS "COMPILE_OPTIONS ${COMPILE_OPTIONS}") 49 | message(STATUS "LINK_OPTIONS ${LINK_OPTIONS}") 50 | 51 | include(git-defs) # for ${GIT_DEFINITIONS} 52 | function(target_git_definitions target) 53 | target_compile_definitions(${target} PRIVATE ${GIT_DEFINITIONS}) 54 | endfunction() 55 | 56 | # passes definitions if they exist 57 | function(target_compile_definitions_if target access project_definitions) 58 | foreach(X IN LISTS project_definitions) 59 | if(${X}) 60 | target_compile_definitions(${target} ${access} "-D${X}") 61 | endif() 62 | endforeach() 63 | endfunction() 64 | 65 | # setups a target: sets COMPILE and LINK options, adds warnings, c++ std req... 66 | function(target_setup target) 67 | if(NOT MSVC) 68 | target_compile_options(${target} PRIVATE 69 | -W -Wall -Wextra -Wpedantic 70 | -Wformat=2 71 | -Wcast-align 72 | -Wstrict-aliasing=2 73 | -Wstrict-overflow=5 74 | -Wfloat-equal 75 | -Wwrite-strings 76 | # -Werror 77 | # -Wfatal-errors 78 | ) 79 | else() 80 | target_compile_options(${target} PRIVATE /W4) 81 | endif() 82 | target_compile_options(${target} PRIVATE "${COMPILE_OPTIONS}") 83 | target_compile_definitions_if(${target} PRIVATE "${TAU_DEFINITIONS}") 84 | if (CMAKE_SYSTEM_NAME STREQUAL "Windows" AND 85 | CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 86 | target_compile_features(${target} PRIVATE cxx_std_23) 87 | target_compile_options(${target} PRIVATE 88 | -Wa,-mbig-obj 89 | -fno-use-linker-plugin 90 | ) 91 | target_link_libraries(${target} 92 | ${CMAKE_THREAD_LIBS_INIT} 93 | -static-libgcc 94 | -static-libstdc++ 95 | ) 96 | else() 97 | target_compile_features(${target} PRIVATE cxx_std_23) 98 | target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT}) 99 | endif() 100 | target_link_options(${target} PRIVATE "${LINK_OPTIONS}") 101 | target_git_definitions(${target}) 102 | set_target_properties(${target} PROPERTIES 103 | ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 104 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 105 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" 106 | PUBLIC_HEADER "${PROJECT_HEADERS}" 107 | ) 108 | endfunction() 109 | 110 | # exclude target from all and default 111 | function(exclude target) 112 | set_target_properties(${target} PROPERTIES 113 | EXCLUDE_FROM_ALL 1 114 | EXCLUDE_FROM_DEFAULT_BUILD 1 115 | ) 116 | endfunction() 117 | 118 | # target names 119 | set(TAU_OBJECT_LIB_NAME "${PROJECT_LIB_NAME}o") 120 | set(TAU_STATIC_LIB_NAME "${PROJECT_LIB_NAME}_static") 121 | set(TAU_SHARED_LIB_NAME "${PROJECT_LIB_NAME}") 122 | set(TAU_EXECUTABLE_NAME "${PROJECT_NAME}") 123 | set(TAU_EXE_SHARED_NAME "${PROJECT_NAME}_shared") 124 | -------------------------------------------------------------------------------- /cmake/version_license.h.template: -------------------------------------------------------------------------------- 1 | namespace idni::tau_lang { 2 | 3 | constexpr char build_date[] = "@BUILD_DATE_ISO@"; 4 | constexpr char version[] = "@VERSION@"; 5 | constexpr char full_version[] = "Tau Language Framework version @VERSION@ (" 6 | GIT_COMMIT_HASH ")"; 7 | constexpr char license[] = R"LICENSE_TEXT( 8 | @LICENSE_CONTENT@ 9 | 10 | )LICENSE_TEXT"; 11 | 12 | } -------------------------------------------------------------------------------- /coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh Coverage $@ 4 | cd build-Coverage 5 | make coverage 6 | -------------------------------------------------------------------------------- /debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh Debug $@ 4 | -------------------------------------------------------------------------------- /demos/demo_1.1-basic_syntax_and_history.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_1.1-basic_syntax_and_history.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # The Tau REPL keeps track of all the results in a history store. There, you can 11 | # also store tau formulas and Boolean functions. 12 | 13 | # The history works like an array; the first stored formula or the first result 14 | # is at position 1. To access the elements of the history, you can use a relative 15 | # (from the end) or absolute (from the beginning) notation. The relative notation 16 | # is "%-position", simply "%" for the last result, whereas the absolute notation 17 | # is "%position". 18 | 19 | # We can store several functions in the history store by simply typing them: 20 | 21 | (X | Y) & Z # as usual | stands for disjunction and & stands for conjunction 22 | (X Y) | Z # conjunctions could be ommited 23 | (X + Y) & Z' # ' stands for complementation 24 | (Y + 1) | 0 # 1 and 0 stands for the corresponding constants in the Boolean algebra 25 | 26 | # To recover from history, we can use the following commands: 27 | 28 | hist % # last stored formula... 29 | hist %-1 # ...the previous one 30 | hist %1 # the first stored formula 31 | 32 | # Also we could output the whole content of the history store: 33 | 34 | hist # print all stored formulas 35 | 36 | # As previously commented, apart of Boolean functions, we can also store tau formulas 37 | # with free variables 38 | 39 | X = 0 && Y = 0 || Z = 0 # || and && stand for local disjunction and conjunction 40 | X = 0 ^ Y = 0 ^ !(Z = 0) # ^ stands for exclusive or and ! stands for negation 41 | (X = 0 -> Y = 0) <-> Z = 0 # <-> stands for equivalence and -> stands for implication 42 | X = 0 ? Y = 0 : Z = 0 # ? stands for if-then-else or conditional operator 43 | 44 | # We can also use quantifiers 45 | 46 | all X ex Y X = 0 && Y = 0 # all and ex stands for universal and existential quantifiers 47 | 48 | # and include constants from the Lindenbaum-Tarski algebra of Propositional Logic 49 | # represented by SBFs 50 | 51 | {X}:sbf & Y | Z 52 | 53 | # The '{type : ... }` syntax denotes constants in the supported types (Boolean algebras). 54 | # In the above example, as we have a constant in the SBF Boolean algebra corresponding 55 | # to the simple Boolean function X. 56 | 57 | # We can include formulas with temporal variables (i... are input variables and 58 | # o... are output variables) 59 | 60 | o1[t] = i1[t] || o2[t] != i2[t] # as before, || stands for disjunction 61 | o1[t] = i1[t] && o2[t] = i2[t] # as before, && stands for conjunction 62 | o1[t] = i1[t] && ! o2[t] = i2[t] # as before, ! stands for negation 63 | 64 | # We can also have formulas that involve constants over the Tau Boolean algebra 65 | # itself. 66 | 67 | 68 | {o1[t] = i1[t] || o2[t] != i2[t]} & {o1[t] != 0} 69 | {o1[t] = i1[t] && o2[t] = i2[t]} | {o1[t] != 0} 70 | {o1[t] = i1[t] && ! o2[t] = i2[t]} 71 | 72 | ({ i1[t]'o1[t] = 0 } i1[t] = 0) ? (o1[t] = 0) : (o1[t] = 1) 73 | 74 | # In the above example, as we have a constant in the Tau Boolean algebra, the type 75 | # could be ommited. This allow us to write Tau specifications that talk about 76 | # Tau specifications themselves. Also note, that we could use this notation 77 | # recursively to define Tau specifications that talk about Tau specifications 78 | # that talk about Tau specifications, and so on. 79 | 80 | # The syntax for constants would be clarify in the future in order to have 81 | # a cleaner one. 82 | 83 | # Obviously, we could have formulas that involving all the above mentioned elements 84 | # at the same time 85 | 86 | quit # quit the Tau REPL 87 | -------------------------------------------------------------------------------- /demos/demo_1.2-commands_and_history.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_1.2-commands_and_history.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # The above notations used to access the history can also be used in the commands. 11 | # For example, the following commands will compute the DNF of a Boolean function 12 | # passed as an argument or as a memory position. 13 | 14 | (X | Y) & Z # store a Boolean function 15 | (X | Y') & Z # store another Boolean function 16 | dnf %-1 # convert to DNF the first formula in history 17 | dnf %1 # also convert to DNF the first formula in history 18 | (X | Y) & Z' # store another Boolean function 19 | dnf % # convert to DNF the last formula in history 20 | dnf (X | Y | W) & Z # simply compute the DNF of the given Boolean function 21 | 22 | # The same happens when using formulas. The following command will convert 23 | # formulas to CNF. 24 | 25 | (X Y ) | Z # store a formula 26 | cnf % # convert to CNF the last formula in history 27 | cnf %-1 # convert to CNF the same formula 28 | cnf %1 # convert to CNF the first formula in history 29 | cnf (X Y) | Z # convert to CNF the given formula 30 | 31 | quit # quit the Tau REPL 32 | -------------------------------------------------------------------------------- /demos/demo_1.3-recurrence_relations.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_1.3-recurrence_relations.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # Apart from the Boolean functions and Tau formulas, you can define your own 11 | # recurrence relations: 12 | 13 | f(x) := x +1 # base case 14 | f(x) := x + f(x) # general case 15 | 16 | # or also 17 | 18 | p[1](x, y) := {all x ex y x' y = o1[t]} # base case 19 | p[n](x, y) := p[n-1](y, z) # general case 20 | 21 | # As with history, such definitions are stored in a array like structure. You can 22 | # check them as follows: 23 | 24 | defs 25 | 26 | # In order to use them, you should just invoke them by their name. 27 | 28 | h[0](x) := 1 # base case 29 | h[n](x) := x + h[n-1](x) # general case 30 | n all x h[7](x) != 0 # normalize a formula involving the above h 31 | 32 | quit # quit the Tau REPL 33 | -------------------------------------------------------------------------------- /demos/demo_1.4-normalization.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_1.4-normalization.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # Let us demonstrate several commands related to normalization and its inner workings. 11 | 12 | # The qelim command eliminate the inner quantifier from a formula. 13 | 14 | qelim all X (X = 0) # eliminate one quantifier from a simple formula given as argument 15 | 16 | # As before, you can also pass a formula stored in history. 17 | 18 | # Finally, the following example ilustrates the use of the new Boolean 19 | # function normalize and the new quantifier elimination algorithm. 20 | # It uses the normalize command to prove the validity of a formula in the 21 | # first order theory of atomless Boolean algebra. This is because we assume 22 | # non-typed variables to be of this type by default. In fact, our procedure can 23 | # decide the validity for any formula in the first order theory of atomless 24 | # Boolean algebra. 25 | 26 | n all x ex y all v ex w x'y = 0 && v + w = 0 27 | 28 | # The new Boolean function normalization procedure can minimize redundant parts 29 | # of a formula 30 | 31 | n xyzvw | xyzv | xyz | xy | x 32 | 33 | # It also gives canonical output, meaning two equivalent but syntactically different 34 | # Boolean functions will be normalized to the same syntactical expression. The 35 | # following is a simple example of this. 36 | 37 | n xa + ya' 38 | n a'y + ax 39 | 40 | quit # quit the Tau REPL 41 | -------------------------------------------------------------------------------- /demos/demo_2.1-strong_normalizationof_wff.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_2.1-strong_normalizationof_wff.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # Let us demonstrate the workings of strong normalization for wff 11 | 12 | # First, let us consider few trivial cases to check the basics 13 | snf T 14 | snf F 15 | snf x = 0 16 | snf x != 0 17 | snf x | y = 0 18 | snf x & y = 0 19 | snf x | y != 0 20 | snf x & y != 0 21 | snf x = 0 || y = 0 22 | 23 | # Let us check how the algorithm squeeze the positives 24 | snf {x}:sbf x = 0 && {y}:sbf x = 0 25 | 26 | # Let us now show how the algorithm appply the Corollary 3.1 from Taba book 27 | # to further normalize the formulas: 28 | snf {x}:sbf x = 0 && {y}:sbf x != 0 29 | snf {x}:sbf x = 0 && {y}:sbf x = 0 && {z}:sbf x != 0 30 | snf {x}:sbf x = 0 || {z}:sbf x != 0 31 | snf {x}:sbf x != 0 && {x}:sbf {y}:sbf x != 0 32 | 33 | quit # quit the Tau REPL 34 | -------------------------------------------------------------------------------- /demos/demo_2.2-solver.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_2.2-solver.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # Let us demonstrate the workings of the solver 11 | 12 | # First, let us consider few trivial cases to check the basics 13 | 14 | solve x = 0 15 | solve x = 0 && y = 0 16 | 17 | # Let us now add some (sbf) constants 18 | 19 | solve {a}:sbf x = 0 20 | 21 | # And now, let us add something that requieres splitters (sbf) 22 | 23 | solve x != 0 && x' != 0 24 | 25 | # Let us now add some more complex formulas, ones involving tau splitters 26 | 27 | solve {ex a a = 0} x != 0 && {ex b b = 0} x != 0 28 | 29 | # or for example 30 | 31 | solve {ex x x = 0} a + {ex y y = 0} b = 0 32 | solve a x + b y = 0 -------------------------------------------------------------------------------- /demos/demo_2.3-solver-min_max.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | 5 | # ./run.sh demo_2.3-solver-min_max.tau 6 | 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # Let us demonstrate the workings of the solver when using the minimum and 11 | # maximum options. In those cases, the solver provide the minimmum or the maximum 12 | # solution in the sense of Theorem 2.6 from Rudeanu 1974. 13 | 14 | # Let us consider few trivial cases to check the basics of the idea. 15 | 16 | # In the following case the minimum value is `{F}:tau`: 17 | solve --min x != 1 18 | # whewreas we have no maximum value: 19 | solve --max x != 1 20 | 21 | # Please note we could also use `--minimum` and `--maximum`. 22 | 23 | # In the following case we neither have minimum or maximum: 24 | solve --min x != 0:sbf && x != 1:sbf 25 | # however, we have a solution: 26 | solve x != 0:sbf && x != 1:sbf 27 | 28 | # By default (i.e. no `--max` or `--min` options are passed), the solver will 29 | # try to compute a maximum solution, then a minimum solution and finally a 30 | # general solution (returning the first one at hand). 31 | 32 | # Of course you could try to compute maximum and minimum solutions for more 33 | # complex formulas, like the following one: 34 | solve --max {a}:sbf x != 0 && {b}:sbf x + {a}:sbf y = 0 35 | 36 | # Finally, if you want to specify the boolean algebra to be used, you can do so 37 | # using the `--sbf` or `--tau` options. For example: 38 | solve --min --sbf x != 0 && x' != 0 -------------------------------------------------------------------------------- /demos/demo_3.1-interpreter_sbf.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_3.1-interpreter_sbf.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # This demo demonstrate the workings of the interpreter. 11 | 12 | # To run a tau program we need to define input and output variables. 13 | # If you attempt to run a program without defining the input and output variables, 14 | # the interpreter will throw an error. 15 | 16 | # The following program just echo the inputs to the outputs, but we have not 17 | # define inputs yet! So we would get an error. 18 | 19 | r i1[t] = o1[t] 20 | 21 | # Let us define the inputs for variable i1 directly from the console (of type sbf) 22 | 23 | sbf i1 = console 24 | 25 | # However, we still need to define the output variable. If we try to run the above 26 | # program, we will still get an error. 27 | 28 | r i1[t] = o1[t] 29 | 30 | # Let us define the output variable as the console 31 | 32 | sbf o1 = console 33 | 34 | # In order to check the defined inputs and outputs, we can run the following command: 35 | 36 | defs 37 | 38 | # Now we can run the program: 39 | 40 | r i1[t] = o1[t] 41 | 0 42 | 1 43 | 0 44 | 1 45 | 0 46 | 47 | # You would see the negations of you have seen previously in the console as that 48 | # is what we have defined as the output. 49 | # 50 | # Of course, we could also deal with more complex programs. The above examples are quite 51 | # simple but are provided to show the basic workings of the interpreter. 52 | # Let us consider the following example based on the Fibonacci sequence: 53 | 54 | r o1[t] = o1[t-1] + o1[t-2] && o1[0] = 1 && o1[1] = 1 55 | n 56 | n 57 | n 58 | n 59 | n 60 | n 61 | q 62 | 63 | 64 | # We can also execute specifications involving inequalities: 65 | 66 | r o1[t] != 0 && o1[t] != 1 67 | n 68 | n 69 | n 70 | n 71 | n 72 | n 73 | q 74 | 75 | 76 | # and also include uninterpreted constants: 77 | 78 | r o1[t] = <:a> 79 | n 80 | n 81 | n 82 | n 83 | n 84 | n 85 | q 86 | 87 | 88 | # or use functions: 89 | 90 | f(x) := {a}:sbf x + {b}:sbf x' 91 | g(x) := {c}:sbf x + {d}:sbf x' 92 | r o1[t] = f(o1[t-1]) + g(o1[t-2]) 93 | n 94 | n 95 | n 96 | q 97 | 98 | 99 | # Note that the 3 steps we are requesting are performed after the initial 100 | # conditions are set. 101 | 102 | # Of course, we could define inputs for variable from a file (of type sbf) 103 | 104 | sbf i2 = ifile("../tests/integration/test_files/sbf-alternating_zeros_and_ones-length_10.in") 105 | r i2[t]' = o1[t] 106 | 107 | # We could also define the output as a file, and run a similar program again. 108 | # In order to check the result, you could run the following command, in another console: 109 | 110 | # cat /tmp/output_file1 111 | 112 | sbf o2 = ofile("/tmp/output_file1") 113 | r i1[t]' = o2[t] 114 | 0 115 | 1 116 | 0 117 | 1 118 | 0 119 | 120 | # In the future we would provide more complex examples, but we 121 | # guess you have a taste of how the interpreter works, at least in simple cases. 122 | # 123 | 124 | q 125 | -------------------------------------------------------------------------------- /demos/demo_3.2-interpreter_tau.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (customized with 2 | # your settings if needed) and then execute the run.sh within the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_3.2-interpreter_tau.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | 10 | # This demo demonstrate the workings of the interpreter when considering inputs and 11 | # outputs tau programs. 12 | 13 | # Let us define the inputs/outputs from the console (of type tau) 14 | 15 | tau i1 = console 16 | tau o1 = console 17 | 18 | 19 | # Now, let us consider a simple tau program which always output the same program 20 | # (as the output doesn't depends on the inputs, we must specify the number of 21 | # steps to be performed when running it).: 22 | 23 | r o1[t] = { o1[t] = i1[t] } 24 | n 25 | n 26 | q 27 | 28 | # Now let us consider a program that take as inputs actual programs from the 29 | # console. 30 | 31 | r o1[t] = i1[t] 32 | o1[t] = 0. 33 | 34 | # Let us provide a slightly more complex example: 35 | 36 | r o1[t] = i1[t]' 37 | always o1[t] = 0. 38 | 39 | # Now, let us go into the rabbit hole of recursion. Let us consider the above 40 | # program but let us provide as input a program that sometimes return a program 41 | # that returns the same program. 42 | 43 | r o1[t] = i1[t]' 44 | sometimes o1[t] = { o1[t] = i1[t] }. 45 | 46 | # In the future we would provide more complex examples, but we 47 | # guess you have a taste of how the interpreter works, at least in simple cases. 48 | # 49 | 50 | q 51 | -------------------------------------------------------------------------------- /demos/demo_3.3-interpreter_fpbf.tau: -------------------------------------------------------------------------------- 1 | # To run it you need to compile the project using release.sh (c ustomized with 2 | # your settings if needed) and then execute the run.sh whithin the demo directory 3 | # as follows: 4 | # 5 | # ./run.sh demo_3.2-interpreter_fpbf.tau 6 | # 7 | # This demo should work under any *nix flavour due to the paths used for files. 8 | # To run it under windows you will need to change the paths to the files. 9 | # 10 | # IMPORTANT: This demo is not yet implemented. It is just a draft. 11 | # 12 | # The idea of this demo is to give a more complex example for the interpreter. 13 | # The demo is based in the well-known model of FPGA -field programable 14 | # gate array- (see https://en.wikipedia.org/wiki/Field-programmable_gate_array for 15 | # the details). 16 | # 17 | # In the FPGA model, we have a programmable array of gates, some memory to store 18 | # computations, inputs/outputs and a way to update the array gate. 19 | # 20 | # In our case we will deal with programmable Boolean Funtions, i.e. we will 21 | # copycut the same ideas but in order to compute the result of Boolean 22 | # functions instead of computing ouput bits. 23 | # 24 | # In order to keep it simple, we will assume that the programmable Boolean 25 | # function has only to variables. Moreover, we would restrain the memory to 26 | # just one Boolean algebra element. These restrictions are just to keep the 27 | # example simple, more elaborated constructions could be done in the obvious way. 28 | # 29 | # In order to program the Boolean function, we will parametrize the function 30 | # with several ouput variables of the Tau program. The idea is that the 31 | # output variables will be used to compute the new Boolean function value from 32 | # the input values. The input values will be given by the input variables of 33 | # the Tau program. 34 | # 35 | # The value to be store in the memory will be parametrized also by output 36 | # variables of the Tau program. The memory will be updated by the specific 37 | # inputs given by certain input variables of the Tau program. 38 | # 39 | # We will also consider an input variable defifing the update signal. If the update 40 | # signal is true, the Boolean function will be updated, otherwise it will remain 41 | # the same. The memory will be updated in the same way. 42 | # 43 | # Thus, we will consider the following variables: 44 | # 45 | # i0: update signal, 46 | # 47 | # i1...: the new Boolean function describing the Boolean Function to be computed 48 | # in the next step if the update signal is true. 49 | # 50 | # i2...: the new Boolean function describing the Boolean function computing the 51 | # to be stored in the memory in the next step if the update signal is true. 52 | # 53 | # i3..: the input values from which compute the Boolean function. 54 | # 55 | # and the following output variables: 56 | # 57 | # o1...: the current values of the Bollean function describing what is computed. 58 | # 59 | # o2...: the current values of the Boolean function describing what is stored in the memory. 60 | # 61 | # o3: the value of the evaluation of the current Boolean function described by o1... 62 | # 63 | # o4: the value of the evaluation of the current Boolean function described by o2... 64 | # 65 | # In order to simplify further the expressions, the Boolean formulas will be 66 | # given in algebraic normal form. 67 | # 68 | # Let us build our tau program step by step. 69 | # 70 | # First, let us deal with the evaluation of the Boolean function. We must take 71 | # into account the current Boolean function, the inputs and the previous memory: 72 | # 73 | # o1[t] = o1000[t-1] + ... + o1111[t-1] & i30[t-1] & i31[t-1] & o4[t-1] 74 | # 75 | # Regarding the memopry, we should have 76 | # 77 | # o2[t] = o200[t-1] + ... + o211[t-1] & i30[t-1] & i31[t-1] 78 | # 79 | # If the update signal is true, we must update the Boolean function and the memory, i.e. 80 | # we must have: 81 | # 82 | # (i0[t] = T ) -> (o1000[t] = i1000[t] && ... && o1111[t] = i1011[t]) 83 | # (i0[t] = T ) -> (o200[t] = i200[t] && ... && o211[t] = i211[t]) 84 | # 85 | # If the update signal is not true, we must keep the Boolean function and the memory 86 | # as they are, i.e. we must have: 87 | # 88 | # (i0[t] != T ) -> (o1000[t] = o1000[t-1] && ... && o1111[t-1] = o1111[t-1]) 89 | # (i0[t] != T ) -> (o200[t] = o200[t-1] && ... && o211[t-1] = o211[t-1]) 90 | # 91 | -------------------------------------------------------------------------------- /demos/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # clear the terminal 4 | clear 5 | 6 | # check parameter is passed 7 | if [ -z "$1" ]; then 8 | echo "Usage: $0 " 9 | exit 1 10 | fi 11 | 12 | # check that the demo file exists 13 | if [ ! -f $1 ]; then 14 | echo "File $1 not found!" 15 | exit 1 16 | fi 17 | 18 | # check that the tau executable exists 19 | if [ ! -f ./../build-Release/tau ]; then 20 | echo "Tau executable not found! Please compile the project first (in Release mode)." 21 | exit 1 22 | fi 23 | 24 | pipe=$(mktemp -u) 25 | mkfifo $pipe 26 | 27 | #echo "You are executing a Tau demo script. Please press any key to continue step by step over it." 28 | 29 | # wait 10 secs till tau is up and running 30 | (sleep 5 && while IFS= read -r line 31 | do 32 | # wait till the user press return 33 | read -s -n1 < /dev/tty 34 | # ignore ## comments 35 | echo "$line" | grep -v "##" 36 | done) < $1 > $pipe & 37 | 38 | ./../build-Release/tau < $pipe 39 | 40 | rm $pipe 41 | -------------------------------------------------------------------------------- /demos/sample_demo.tau: -------------------------------------------------------------------------------- 1 | # This is a sample demo script for the Tau REPL. 2 | # The character `#` is used to comment the code. 3 | # You could execute all commands available in the Tau REPL, p.e. 4 | 5 | version 6 | 7 | # Remember to always end the script with the quit command. 8 | 9 | quit 10 | -------------------------------------------------------------------------------- /docs/Theories-and-Applications-of-Boolean-Algebras-0.25.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDNI/tau-lang/6e13cf0fd23474ad6df66019a823c06a98cf17ee/docs/Theories-and-Applications-of-Boolean-Algebras-0.25.pdf -------------------------------------------------------------------------------- /docs/images/TauNet_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDNI/tau-lang/6e13cf0fd23474ad6df66019a823c06a98cf17ee/docs/images/TauNet_banner.png -------------------------------------------------------------------------------- /docs/images/Tau_Banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDNI/tau-lang/6e13cf0fd23474ad6df66019a823c06a98cf17ee/docs/images/Tau_Banner.png -------------------------------------------------------------------------------- /docs/images/tau_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDNI/tau-lang/6e13cf0fd23474ad6df66019a823c06a98cf17ee/docs/images/tau_logo.png -------------------------------------------------------------------------------- /docs/images/tau_logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 9 | 12 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDNI/tau-lang/6e13cf0fd23474ad6df66019a823c06a98cf17ee/examples/.gitkeep -------------------------------------------------------------------------------- /external/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IDNI/tau-lang/6e13cf0fd23474ad6df66019a823c06a98cf17ee/external/.gitkeep -------------------------------------------------------------------------------- /external/libboost-mingw-builder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_DIR=$(dirname "$(readlink -f "$0")") 4 | PREFIX_DIR=$SCRIPT_DIR/../libboost-mingw-w64 5 | BOOST_ROOT=$SCRIPT_DIR/boost 6 | BOOST_REPO=https://github.com/boostorg/boost 7 | BOOST_COMMIT=65c1319 # Boost 1.86 8 | 9 | # clone and checkout boost 10 | git clone $BOOST_REPO --branch master --single-branch $BOOST_ROOT 11 | cd $BOOST_ROOT 12 | git checkout $BOOST_COMMIT 13 | 14 | # initialize needed dependencies 15 | git submodule update --init tools/boostdep 16 | git submodule update --init libs/log 17 | python3 tools/boostdep/depinst/depinst.py log 18 | 19 | # create user-config.jam 20 | cat > "$BOOST_ROOT/user-config.jam" << EOF 21 | using gcc : mingw64 : x86_64-w64-mingw32-g++ 22 | : 23 | x86_64-w64-mingw32-windres 24 | x86_64-w64-mingw32-ar 25 | ; 26 | EOF 27 | mkdir -p $PREFIX_DIR 28 | 29 | # build boost 30 | ./bootstrap.sh --with-libraries=log 31 | ./b2 --user-config=./user-config.jam --prefix=$PREFIX_DIR target-os=windows address-model=64 variant=release install 32 | -------------------------------------------------------------------------------- /extract_packages.sh: -------------------------------------------------------------------------------- 1 | CID=$(docker create packages) 2 | mkdir -p build-Release 3 | docker cp $CID:/tau-lang/build-Release/packages build-Release 4 | docker rm $CID 5 | -------------------------------------------------------------------------------- /packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./release.sh $@ 4 | cd ./build-Release 5 | cpack -C Release 6 | cd .. 7 | -------------------------------------------------------------------------------- /parser/bitvector.tgf: -------------------------------------------------------------------------------- 1 | # To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | @use char classes space, alpha, digit. 4 | 5 | @enable productions charvar. 6 | 7 | start => _ bitvector _. 8 | bitvector => _uint 9 | | _int 10 | | _ulong 11 | | _long 12 | | _bits. 13 | sign => minus | plus. 14 | minus => '-'. 15 | plus => ['+']. 16 | _int => sign _ _unsigned. 17 | _long => sign _ _unsigned _ 'l'. 18 | _uint => [plus] _ _unsigned _ 'u'. 19 | _ulong => [plus] _ _unsigned _ "ul". 20 | _unsigned => digit (_digit)*. 21 | _bits => _bit (_ _bit)* 'b'. 22 | _bit => '0':zero | '1':one. 23 | -------------------------------------------------------------------------------- /parser/gen: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TGF_FILE=$1 4 | 5 | if [[ -z "$TGF_FILE" ]]; then 6 | echo "provide an existing TGF file path" 7 | exit 1 8 | fi 9 | 10 | TGF_DIR="./external/parser" 11 | TGF="$TGF_DIR/build-Release/tgf" 12 | 13 | if [[ ! -f "$TGF" ]]; then 14 | echo "tgf tool not built. Building..." 15 | D=`pwd` 16 | cd "$TGF_DIR" 17 | ./release.sh -DPARSER_BUILD_TOOLS=1 18 | cd "$D" 19 | fi 20 | 21 | echo "Generating parser from $TGF_FILE ..." 22 | $TGF "$TGF_FILE" gen 23 | echo "Generation done" 24 | -------------------------------------------------------------------------------- /parser/sbf.tgf: -------------------------------------------------------------------------------- 1 | # To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | @use char classes space, alpha, digit. 4 | 5 | @enable productions charvar. 6 | 7 | start => _ sbf _. 8 | sbf => ( '(' _ sbf _ ')' ) :group 9 | | variable 10 | | ( sbf _ '|' _ sbf ) :disjunction 11 | | ( sbf _ ('^' | '+') _ sbf ) :exclusive_disjunction 12 | | ( sbf (_ '&' _ | space _) sbf ) :conjunction 13 | | ( (group | variable | negation 14 | | one | zero) 15 | :negation_oprnd _ "'" ) :negation 16 | | ( (group | variable | disjunction 17 | | exclusive_disjunction | negation) 18 | :conjunction_nosep_1st_oprnd sbf ) :conjunction_nosep 19 | | '1' :one 20 | | '0' :zero. 21 | _ => [ space _ ]. 22 | 23 | variable[charvar] => alpha digit*. 24 | variable[var] => alpha (alnum | '_')*. 25 | 26 | @trim _. 27 | @trim all terminals except children of variable. 28 | @inline char classes, 29 | sbf > group > sbf, 30 | negation_oprnd > group > sbf, 31 | conjunction_nosep_1st_oprnd > group > sbf, 32 | conjunction_nosep > group > conjunction. 33 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh Release $@ 4 | -------------------------------------------------------------------------------- /relwithdebinfo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh RelWithDebInfo $@ 4 | -------------------------------------------------------------------------------- /save_benchmarks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mv *.measures tests/benchmark/data/ > /dev/null 2>&1 4 | mv *.callgrind.out tests/benchmark/data/ > /dev/null 2>&1 5 | mv build*/*.measures tests/benchmark/data/ > /dev/null 2>&1 6 | mv build*/*.callgrind.out tests/benchmark/data/ > /dev/null 2>&1 7 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TAU "${CMAKE_CURRENT_SOURCE_DIR}/..") 2 | 3 | set(TAU_HEADERS 4 | ../parser/sbf_parser.generated.h 5 | ../parser/tau_parser.generated.h 6 | boolean_algebras/bdds/babdd.h 7 | boolean_algebras/bdds/bdd_handle.h 8 | boolean_algebras/bool_ba.h 9 | boolean_algebras/sbf_ba.h 10 | boolean_algebras/variant_ba.h 11 | boolean_algebras/product_ba.h 12 | boolean_algebras/nso_ba.h 13 | experimental/execution.h 14 | defs.h 15 | definitions.h 16 | rewriting.h 17 | dict.h 18 | normalizer.h 19 | nso_rr.h 20 | execution.h 21 | tau.h 22 | normal_forms.h 23 | satisfiability.h 24 | solver.h 25 | splitter.h 26 | splitter_types.h 27 | interpreter.h 28 | interpreter.impl.h 29 | hooks.h 30 | builders.h 31 | language.h 32 | queries.h 33 | utils.h 34 | ) 35 | 36 | set(TAU_SOURCES 37 | boolean_algebras/bool_ba.cpp 38 | dict.cpp 39 | nso_rr.cpp 40 | ) 41 | 42 | set(CLI_SOURCES 43 | main.cpp 44 | ) 45 | 46 | # 47 | # object library 48 | # 49 | add_library(${TAU_OBJECT_LIB_NAME} OBJECT) 50 | target_sources(${TAU_OBJECT_LIB_NAME} PRIVATE ${TAU_SOURCES}) 51 | target_setup(${TAU_OBJECT_LIB_NAME}) 52 | target_link_libraries(${TAU_OBJECT_LIB_NAME} Boost::log ${Z3_LIB}) 53 | target_compile_options(${TAU_OBJECT_LIB_NAME} PRIVATE -fPIC) 54 | target_include_directories(${TAU_OBJECT_LIB_NAME} PUBLIC 55 | $ 56 | $ 57 | $ 58 | ) 59 | 60 | # 61 | # static library 62 | # 63 | add_library(${TAU_STATIC_LIB_NAME} STATIC) 64 | target_sources(${TAU_STATIC_LIB_NAME} PRIVATE ${TAU_SOURCES}) 65 | target_setup(${TAU_STATIC_LIB_NAME}) 66 | target_link_libraries(${TAU_STATIC_LIB_NAME} Boost::log ${Z3_LIB}) 67 | target_include_directories(${TAU_STATIC_LIB_NAME} PUBLIC 68 | $ 69 | $ 70 | $ 71 | ) 72 | set_target_properties(${TAU_STATIC_LIB_NAME} PROPERTIES 73 | OUTPUT_NAME ${PROJECT_LIB_NAME}) 74 | if(NOT TAU_BUILD_STATIC_LIBRARY) 75 | exclude(${TAU_STATIC_LIB_NAME}) 76 | endif() 77 | 78 | # 79 | # shared library 80 | # 81 | add_library(${TAU_SHARED_LIB_NAME} SHARED) 82 | add_library(${namespace}::${TAU_SHARED_LIB_NAME} ALIAS ${TAU_SHARED_LIB_NAME}) 83 | target_sources(${TAU_SHARED_LIB_NAME} PRIVATE ${TAU_SOURCES}) 84 | target_link_libraries(${TAU_SHARED_LIB_NAME} Boost::log ${Z3_LIB}) 85 | target_include_directories(${TAU_SHARED_LIB_NAME} PUBLIC 86 | $ 87 | $ 88 | $ 89 | $ 90 | ) 91 | set_target_properties(${TAU_SHARED_LIB_NAME} PROPERTIES 92 | EXPORT_NAME ${TAU_SHARED_LIB_NAME} 93 | PUBLIC_HEADER "${TAU_HEADERS}" 94 | ) 95 | if(NOT TAU_BUILD_SHARED_LIBRARY) 96 | exclude(${TAU_SHARED_LIB_NAME}) 97 | endif() 98 | 99 | # 100 | # executable 101 | # 102 | if(TAU_BUILD_EXECUTABLE) 103 | add_executable(${TAU_EXECUTABLE_NAME}) 104 | target_sources(${TAU_EXECUTABLE_NAME} PRIVATE ${CLI_SOURCES}) 105 | target_setup(${TAU_EXECUTABLE_NAME}) 106 | target_link_libraries(${TAU_EXECUTABLE_NAME} ${TAU_STATIC_LIB_NAME}) 107 | target_include_directories(${TAU_EXECUTABLE_NAME} PUBLIC 108 | $ 109 | $ 110 | $ 111 | ) 112 | endif(TAU_BUILD_EXECUTABLE) 113 | 114 | # 115 | # executable using shared library 116 | # 117 | if(TAU_BUILD_SHARED_EXECUTABLE) 118 | add_executable(${TAU_EXE_SHARED_NAME}) 119 | target_sources(${TAU_EXE_SHARED_NAME} PRIVATE ${CLI_SOURCES}) 120 | target_setup(${TAU_EXE_SHARED_NAME}) 121 | target_link_libraries(${TAU_EXE_SHARED_NAME} ${TAU_SHARED_LIB_NAME}) 122 | target_include_directories(${TAU_EXE_SHARED_NAME} PUBLIC 123 | $ 124 | $ 125 | $ 126 | ) 127 | endif(TAU_BUILD_SHARED_EXECUTABLE) 128 | 129 | # 130 | # install 131 | # 132 | include(GNUInstallDirs) 133 | 134 | set(BUILD_TARGETS ${TAU_OBJECT_LIB_NAME}) 135 | if(BUILD_SHARED_LIBRARY) 136 | set(BUILD_TARGETS "${BUILD_TARGETS}" ${TAU_SHARED_LIB_NAME}) 137 | endif() 138 | if(BUILD_STATIC_LIBRARY) 139 | set(BUILD_TARGETS "${BUILD_TARGETS}" ${TAU_STATIC_LIB_NAME}) 140 | endif() 141 | if(BUILD_EXECUTABLE) 142 | set(BUILD_TARGETS "${BUILD_TARGETS}" ${TAU_EXECUTABLE_NAME}) 143 | endif() 144 | if(BUILD_SHARED_EXECUTABLE) 145 | set(BUILD_TARGETS "${BUILD_TARGETS}" ${TAU_EXE_SHARED_NAME}) 146 | endif() 147 | -------------------------------------------------------------------------------- /src/boolean_algebras/bool_ba.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | #include 3 | #include "bool_ba.h" 4 | 5 | Bool::Bool() : b(false) {} 6 | Bool::Bool(bool b) : b(b) {} 7 | 8 | const Bool& Bool::zero() { static Bool b(false); return b; } 9 | const Bool& Bool::one() { static Bool b(true); return b; } 10 | 11 | Bool Bool::operator&(const Bool& x) const { 12 | return (this->b == false) ? zero() : x; 13 | } 14 | Bool Bool::operator|(const Bool& x) const { 15 | return (this->b == true) ? one() : x; 16 | } 17 | Bool Bool::operator^(const Bool& x) const { 18 | return (this->b == true) ? ~x : x; 19 | } 20 | Bool Bool::operator+(const Bool& x) const { 21 | return (this->b == true) ? ~x : x; 22 | } 23 | Bool Bool::operator~() const { 24 | return (this->b == true) ? zero() : one(); 25 | } 26 | bool Bool::is_zero() const { 27 | return !b; 28 | } 29 | bool Bool::is_one() const { 30 | return b; 31 | } 32 | 33 | Bool normalize(const Bool &b) { 34 | return b; 35 | } 36 | 37 | bool is_syntactic_one(const Bool& b) { 38 | return b.is_one(); 39 | } 40 | 41 | bool is_syntactic_zero(const Bool& b) { 42 | return b.is_zero(); 43 | } 44 | 45 | std::ostream& operator<<(std::ostream& os, const Bool& b) { 46 | return os << (b.b ? 1 : 0); 47 | } 48 | -------------------------------------------------------------------------------- /src/boolean_algebras/bool_ba.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | #ifndef __BOOL_BA_H__ 3 | #define __BOOL_BA_H__ 4 | 5 | #include "defs.h" 6 | 7 | struct Bool { 8 | Bool(); 9 | Bool(bool b); 10 | 11 | static const Bool& zero(); 12 | static const Bool& one(); 13 | 14 | Bool operator&(const Bool& x) const; 15 | Bool operator|(const Bool& x) const; 16 | Bool operator^(const Bool& x) const; 17 | Bool operator+(const Bool& x) const; 18 | Bool operator~() const; 19 | auto operator<=>(const Bool& x) const = default; 20 | 21 | bool is_zero() const; 22 | bool is_one() const; 23 | 24 | bool b; 25 | }; 26 | 27 | Bool normalize (const Bool& b); 28 | bool is_syntactic_one (const Bool& b); 29 | bool is_syntactic_zero(const Bool& b); 30 | 31 | 32 | template<> 33 | struct std::hash { 34 | size_t operator()(const Bool& b) { 35 | return b.b ? 1 : 0; 36 | } 37 | }; 38 | 39 | std::ostream& operator<<(std::ostream& os, const Bool& b); 40 | 41 | #endif // __BOOL_BA_H__ 42 | -------------------------------------------------------------------------------- /src/boolean_algebras/nso_ba.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __NSO_BA_H__ 4 | #define __NSO_BA_H__ 5 | 6 | #include "hooks.h" 7 | 8 | namespace idni::tau_lang { 9 | 10 | /** 11 | * @brief Bitwise AND operator for tau. 12 | * @param l Left-hand side operand. 13 | * @param r Right-hand side operand. 14 | * @return Result of bitwise AND operation. 15 | */ 16 | template 17 | tau operator&(const tau& l, const tau& r); 18 | 19 | /** 20 | * @brief Bitwise OR operator for tau. 21 | * @param l Left-hand side operand. 22 | * @param r Right-hand side operand. 23 | * @return Result of bitwise OR operation. 24 | */ 25 | template 26 | tau operator|(const tau& l, const tau& r); 27 | 28 | /** 29 | * @brief Bitwise NOT operator for tau. 30 | * @param l Operand. 31 | * @return Result of bitwise NOT operation. 32 | */ 33 | template 34 | tau operator~(const tau& l); 35 | 36 | /** 37 | * @brief Bitwise XOR operator for tau. 38 | * @param l Left-hand side operand. 39 | * @param r Right-hand side operand. 40 | * @return Result of bitwise XOR operation. 41 | */ 42 | template 43 | tau operator^(const tau& l, const tau& r); 44 | 45 | /** 46 | * @brief Addition operator for tau. 47 | * @param l Left-hand side operand. 48 | * @param r Right-hand side operand. 49 | * @return Result of addition operation. 50 | */ 51 | template 52 | tau operator+(const tau& l, const tau& r); 53 | 54 | /** 55 | * @brief Checks if the tau is zero. 56 | * @param l Operand. 57 | * @return True if the tau is zero, false otherwise. 58 | */ 59 | template 60 | bool is_zero(const tau& l); 61 | 62 | /** 63 | * @brief Checks if the tau is one. 64 | * @param l Operand. 65 | * @return True if the tau is one, false otherwise. 66 | */ 67 | template 68 | bool is_one(const tau& l); 69 | 70 | /** 71 | * @brief Equality operator for tau. 72 | * @param l Left-hand side operand. 73 | * @param r Right-hand side operand. 74 | * @return True if both tau are equal, false otherwise. 75 | */ 76 | template 77 | bool operator==(const tau& l, const tau& r); 78 | 79 | /** 80 | * @brief Inequality operator for tau. 81 | * @param l Left-hand side operand. 82 | * @param r Right-hand side operand. 83 | * @return True if both tau are not equal, false otherwise. 84 | */ 85 | template 86 | bool operator!=(const tau& l, const tau& r); 87 | 88 | /** 89 | * @brief Three-way comparison operator for tau. 90 | * @param l Left-hand side operand. 91 | * @param r Right-hand side operand. 92 | * @return Result of the three-way comparison. 93 | */ 94 | template 95 | std::weak_ordering operator<=>(const tau& l, const tau& r); 96 | 97 | /** 98 | * @brief Less-than operator for tau. 99 | * @param l Left-hand side operand. 100 | * @param r Right-hand side operand. 101 | * @return True if l is less than r, false otherwise. 102 | */ 103 | template 104 | bool operator<(const tau& l, const tau& r); 105 | 106 | /** 107 | * @brief Less-than or equal-to operator for tau. 108 | * @param l Left-hand side operand. 109 | * @param r Right-hand side operand. 110 | * @return True if l is less than or equal to r, false otherwise. 111 | */ 112 | template 113 | bool operator<=(const tau& l, const tau& r); 114 | 115 | /** 116 | * @brief Greater-than operator for tau. 117 | * @param l Left-hand side operand. 118 | * @param r Right-hand side operand. 119 | * @return True if l is greater than r, false otherwise. 120 | */ 121 | template 122 | bool operator>(const tau& l, const tau& r); 123 | 124 | /** 125 | * @brief Greater-than or equal-to operator for tau. 126 | * @param l Left-hand side operand. 127 | * @param r Right-hand side operand. 128 | * @return True if l is greater than or equal to r, false otherwise. 129 | */ 130 | template 131 | bool operator>=(const tau& l, const tau& r); 132 | 133 | /** 134 | * @brief Equality operator for tau and bool. 135 | * @param l Left-hand side operand. 136 | * @param r Right-hand side operand. 137 | * @return True if tau is equal to the boolean value, false otherwise. 138 | */ 139 | template 140 | bool operator==(const tau& l, const bool& r); 141 | 142 | /** 143 | * @brief Equality operator for bool and tau. 144 | * @param l Left-hand side operand. 145 | * @param r Right-hand side operand. 146 | * @return True if boolean value is equal to tau, false otherwise. 147 | */ 148 | template 149 | bool operator==(const bool l, const tau& r); 150 | 151 | /** 152 | * @brief Splitter function for a nso tau_parser::bf_constant node holding a BA constant. 153 | * @param n Operand. 154 | * @param st Splitter type (default is splitter_type::upper). 155 | * @return Result of the splitter operation. 156 | */ 157 | template 158 | tau splitter(const tau& n, splitter_type st = splitter_type::upper); 159 | 160 | } // namespace idni::tau_lang 161 | 162 | #include "nso_ba.tmpl.h" 163 | 164 | #endif // __NSO_BA_H__ -------------------------------------------------------------------------------- /src/boolean_algebras/product_ba.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __BA_H__ 4 | #define __BA_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // product boolean algebra 11 | template 12 | struct product_ba: std::tuple { 13 | 14 | product_ba(): std::tuple() {} 15 | product_ba(BAS... bas): std::tuple(bas...) {} 16 | 17 | auto operator<=>(const product_ba& that) const = default; 18 | 19 | product_ba operator~() { 20 | product_ba result; 21 | auto __not = [](auto a, auto& c ) { return c = ~a; }; 22 | (__not(get(*this), get(result)), ...); 23 | return result; 24 | } 25 | 26 | product_ba operator&(product_ba& that) { 27 | product_ba result; 28 | auto __and = [](auto a, auto b, auto& c ) { return c = (a & b); }; 29 | (__and(get(*this), get(that), get(result)), ...); 30 | return result; 31 | } 32 | 33 | product_ba operator|(product_ba& that) { 34 | product_ba result; 35 | auto __or = [](auto a, auto b, auto& c ) { return c = (a | b); }; 36 | (__or(get(*this), get(that), get(result)), ...); 37 | return result; 38 | } 39 | 40 | product_ba operator^(product_ba& that) { 41 | product_ba result; 42 | auto __xor = [](auto a, auto b, auto& c ) { return c = (a ^ b); }; 43 | (__xor(get(*this), get(that), get(result)), ...); 44 | return result; 45 | } 46 | }; 47 | 48 | #endif // __BA_H__ -------------------------------------------------------------------------------- /src/boolean_algebras/sbf_ba.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __SBF_BA_H__ 4 | #define __SBF_BA_H__ 5 | 6 | #include 7 | 8 | #include "boolean_algebras/tau_ba.h" 9 | #include "../parser/sbf_parser.generated.h" 10 | 11 | namespace idni::tau_lang { 12 | 13 | /** 14 | * @brief Simple Boolean function Boolean algebra represented by bdd 15 | */ 16 | using sbf_ba = hbdd; 17 | using sbf_source_sym = idni::lit; 18 | using sbf_sym = std::variant; 19 | 20 | /** 21 | * @brief global static bdd variable cache 22 | */ 23 | inline static std::map var_cache{}; 24 | 25 | /** 26 | * @brief Boolean algebra factory for Simple Boolean function 27 | * 28 | * @tparam BAs Boolean algebras 29 | */ 30 | template 31 | struct sbf_ba_factory { 32 | 33 | /** 34 | * @brief parses a SBF from a string 35 | * 36 | * @param src source string 37 | * @return optional parsed node if parsing successful 38 | */ 39 | std::optional> parse(const std::string& src); 40 | 41 | /** 42 | * @brief builds a SBF bounded node from a parsed terminals of a source binding 43 | * 44 | * @param sn tau code node with parsed SBF 45 | * @return bounded constant 46 | */ 47 | tau binding(const tau& sn); 48 | 49 | std::variant splitter_one () const; 50 | 51 | std::string one() const; 52 | 53 | std::string zero() const; 54 | // static sbf_ba_factory& instance(); 55 | private: 56 | 57 | inline static std::map> cache; 58 | }; 59 | 60 | /** 61 | * @brief NSO factory used during testing 62 | */ 63 | template<> 64 | struct nso_factory { 65 | inline static sbf_ba_factory bf; 66 | 67 | std::optional> parse(const std::string& src, 68 | const std::string& = ""); 69 | 70 | tau binding(const tau& n, 71 | const std::string& = ""); 72 | 73 | std::vector types() const; 74 | 75 | tau splitter_one() const; 76 | 77 | std::string default_type() const; 78 | 79 | std::string one(const std::string type_name) const; 80 | 81 | std::string zero(const std::string type_name) const; 82 | 83 | std::optional > unpack_tau_ba( 84 | const std::variant&) const; 85 | 86 | std::variant pack_tau_ba(const tau&) const; 87 | 88 | static nso_factory& instance(); 89 | private: 90 | nso_factory(); 91 | }; 92 | 93 | /** 94 | * @brief NSO factory used in REPL 95 | */ 96 | template<> 97 | struct nso_factory, sbf_ba> { 98 | inline static sbf_ba_factory, sbf_ba> bf; 99 | inline static tau_ba_factory tf; 100 | 101 | std::optional> parse(const std::string src, 102 | const std::string type_name); 103 | 104 | tau_nso binding( 105 | const tau, sbf_ba>& n, 106 | const std::string type_name); 107 | 108 | std::vector types() const; 109 | 110 | std::string default_type() const; 111 | 112 | tau_nso splitter_one(const std::string& type_name) const; 113 | 114 | std::string one(const std::string type_name = "tau") const; 115 | 116 | std::string zero(const std::string type_name = "tau") const; 117 | 118 | std::optional> unpack_tau_ba( 119 | const std::variant, sbf_ba>& v) const; 120 | 121 | std::variant, sbf_ba> pack_tau_ba( 122 | const tau, sbf_ba>& c) const; 123 | 124 | static nso_factory, sbf_ba>& instance(); 125 | private: 126 | nso_factory(); 127 | }; 128 | 129 | } // namespace idni::tau_lang 130 | 131 | // Hash for hbdd as specialization of std::hash 132 | template<> 133 | struct std::hash> { 134 | size_t operator()(const hbdd& h) const noexcept { 135 | return h->hash(); 136 | } 137 | }; 138 | 139 | #include "sbf_ba.tmpl.h" 140 | #endif // __SBF_BA_H__ -------------------------------------------------------------------------------- /src/debug_helpers.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __DEBUG_HELPERS_H__ 4 | #define __DEBUG_HELPERS_H__ 5 | 6 | namespace idni::tau_lang { 7 | #ifdef DEBUG 8 | 9 | template 10 | std::ostream& operator<<(std::ostream &os, 11 | std::map, rewriter::sp_node> m) 12 | { 13 | os << "{"; 14 | for (auto& [k, v] : m) os << " {" << k << " <- " << v << "} "; 15 | return os << "}\n"; 16 | } 17 | 18 | template 19 | std::ostream& print_sp_tau_source_node_tree(std::ostream &os, 20 | rewriter::sp_node n, size_t l = 0) 21 | { 22 | auto indent = [&os, &l]() { for (size_t t = 0; t < l; t++) os << "\t";}; 23 | auto& v = n->value; 24 | indent(); 25 | if (v.nt()) os << tau_parser::instance() 26 | .name(v.n()) << "(" << v.n() << ")"; 27 | else if (v.is_null()) os << "null"; 28 | else os << v.t(); 29 | if (n->child.size()) os << " {\n"; 30 | for (auto& c : n->child) print_sp_tau_source_node_tree(os, c, l + 1); 31 | if (n->child.size()) indent(), os << "}"; 32 | return os << "\n"; 33 | } 34 | 35 | // print the tree of tau nodes for general debugging 36 | template 37 | std::ostream& print_tau_tree(std::ostream &os, tau n, 38 | size_t l = 0) 39 | { 40 | auto indent = [&os, &l]() { for (size_t t = 0; t < l; t++) os << "\t";}; 41 | std::visit(overloaded{ 42 | [&os, &indent](tau_source_sym v) { 43 | indent(); 44 | if (v.nt()) os << tau_parser::instance() 45 | .name(v.n()) << "(" << v.n() << ")"; 46 | else if (v.is_null()) os << "null"; 47 | else os << v.t(); 48 | }, 49 | [&os, &indent](const auto& v) { indent(), os << v; } 50 | }, n->value); 51 | if (n->child.size()) os << " {\n"; 52 | for (auto& c : n->child) print_tau_tree(os, c, l + 1); 53 | if (n->child.size()) indent(), os << "}"; 54 | return os << "\n"; 55 | } 56 | 57 | template 58 | std::ostream& ptree(std::ostream &os, rewriter::sp_node n, size_t l = 0) { 59 | return print_sp_tau_source_node_tree(os, n, l); 60 | } 61 | 62 | template 63 | std::ostream& ptree(std::ostream &os, tau n, size_t l = 0) { 64 | return print_tau_tree(os, n, l); 65 | } 66 | 67 | template 68 | std::string ptree(rewriter::sp_node n, size_t l = 0) { 69 | std::stringstream ss; 70 | print_sp_tau_source_node_tree(ss, n, l); 71 | return ss.str(); 72 | } 73 | 74 | template 75 | std::string ptree(tau n, size_t l = 0) { 76 | std::stringstream ss; 77 | print_tau_tree(ss, n, l); 78 | return ss.str(); 79 | } 80 | 81 | #endif // DEBUG 82 | } // namespace idni::tau_lang 83 | 84 | #endif // __DEBUG_HELPERS_H__ -------------------------------------------------------------------------------- /src/definitions.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef DEFINITIONS_H 4 | #define DEFINITIONS_H 5 | 6 | #include "nso_rr.h" 7 | 8 | namespace idni::tau_lang { 9 | 10 | /* 11 | * Struct to manage function and predicate definitions 12 | */ 13 | template 14 | struct definitions { 15 | size_t add (const tau& head, const tau& body) { 16 | // Check if rule is updated 17 | for (size_t i = 0; i < heads.size(); ++i) { 18 | if (heads[i] == head) { 19 | // update definition 20 | heads[i] = head; 21 | bodies[i] = body; 22 | return i; 23 | } 24 | } 25 | heads.push_back(head); 26 | bodies.push_back(body); 27 | return heads.size() - 1; 28 | } 29 | 30 | rules> get () { 31 | rules> r; 32 | for (size_t i = 0; i < heads.size(); ++i) 33 | r.emplace_back(heads[i], bodies[i]); 34 | return r; 35 | } 36 | 37 | size_t size () const { 38 | DBG(assert(heads.size() == bodies.size());) 39 | return heads.size(); 40 | } 41 | 42 | std::pair, tau> back () const { 43 | return std::make_pair(heads.back(), bodies.back()); 44 | } 45 | 46 | std::pair, tau> operator[](const size_t i) const { 47 | return std::make_pair(heads[i], bodies[i]); 48 | } 49 | 50 | static definitions& instance() { 51 | static definitions d; 52 | return d; 53 | } 54 | private: 55 | definitions() = default; 56 | 57 | std::vector> heads = {}; 58 | std::vector> bodies = {}; 59 | }; 60 | 61 | } 62 | 63 | #endif //DEFINITIONS_H 64 | -------------------------------------------------------------------------------- /src/defs.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | #ifndef __DEF_H__ 3 | #define __DEF_H__ 4 | 5 | #include "./version_license.h" 6 | 7 | // basic macro for conditional execution of code 8 | #ifdef DEBUG 9 | # define DBG(x) x 10 | # include 11 | #else 12 | #define DBG(x) 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #define pfst(x) (*(x).begin()) 20 | #define hasbc(x, y, f) std::binary_search(x.begin(), x.end(), y, f) 21 | 22 | typedef int sym_t; 23 | 24 | template struct zero { 25 | bool operator()(const B&) const; 26 | }; 27 | 28 | template struct one { 29 | bool operator()(const B&) const; 30 | }; 31 | 32 | template bool has(const T& t, const V& v) { 33 | return t.find(v) != t.end(); 34 | } 35 | 36 | template bool hasv(const T& t, const V& v) { 37 | return std::find(t.begin(), t.end(), v) != t.end(); 38 | } 39 | 40 | template 41 | void hash_combine (size_t& seed, const T& v) { 42 | seed ^= std::hash{}(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); 43 | } 44 | 45 | template 46 | struct std::hash> { 47 | size_t operator()(const std::vector& vec) const { 48 | size_t seed = vec.size(); 49 | for(auto& i : vec) hash_combine(seed, i); 50 | return seed; 51 | } 52 | }; 53 | 54 | template 55 | struct std::hash> { 56 | size_t operator()(const std::pair& p) const noexcept { 57 | size_t seed = 0; 58 | hash_combine(seed, p.first); 59 | hash_combine(seed, p.second); 60 | return seed; 61 | } 62 | }; 63 | 64 | template 65 | struct std::hash> { 66 | size_t operator()(const std::tuple& p) const noexcept { 67 | size_t seed = 0; 68 | std::apply([&seed](auto&&... xs){(hash_combine(seed, xs),...);}, p); 69 | return seed; 70 | } 71 | }; 72 | 73 | template 74 | std::ostream& operator<<(std::ostream& os, const std::vector& vec) { 75 | os << "["; 76 | for (size_t i=0; i < vec.size(); ++i) 77 | if (i+1 < vec.size()) os << vec[i] << ","; 78 | if (!vec.empty()) os << vec.back(); 79 | os << "]"; 80 | return os; 81 | } 82 | //----------------------------------------------------------------------------- 83 | // GIT_* macros are populated at compile time by -D or they're set to "n/a" 84 | #ifndef GIT_DESCRIBED 85 | #define GIT_DESCRIBED "n/a" 86 | #endif 87 | #ifndef GIT_COMMIT_HASH 88 | #define GIT_COMMIT_HASH "n/a" 89 | #endif 90 | #ifndef GIT_BRANCH 91 | #define GIT_BRANCH "n/a" 92 | #endif 93 | 94 | #endif // __DEF_H__ 95 | -------------------------------------------------------------------------------- /src/dict.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "dict.h" 10 | 11 | using namespace std; 12 | 13 | vector v({"dummy"}); 14 | map m; 15 | 16 | sym_t dict(const char* s) { 17 | if (auto it = m.find(s); it != m.end()) return it->second; 18 | return m.emplace(s, v.size()), v.push_back(s), v.size() - 1; 19 | } 20 | 21 | const char* dict(sym_t n) { 22 | assert((size_t)n <= v.size()); 23 | if ((size_t)n == v.size()) { 24 | static string tmp; 25 | do { 26 | stringstream ss; 27 | ss << "x" << n; 28 | if (auto it = m.find(ss.str()); it == m.end()) { 29 | dict(ss.str()); 30 | return (tmp = ss.str()).c_str(); 31 | } 32 | ++n; 33 | } while (true); 34 | } 35 | return v[n].c_str(); 36 | } 37 | 38 | sym_t dict(const string& s) { return dict(s.c_str()); } 39 | -------------------------------------------------------------------------------- /src/dict.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __DICT_H__ 4 | #define __DICT_H__ 5 | 6 | #include "defs.h" 7 | #include 8 | 9 | sym_t dict(const char*); 10 | sym_t dict(const std::string&); 11 | const char* dict(sym_t); 12 | bool has(sym_t); 13 | 14 | #endif // __DICT_H__ 15 | -------------------------------------------------------------------------------- /src/execution.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __EXECUTION_H__ 4 | #define __EXECUTION_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "boolean_algebras/variant_ba.h" 11 | #include "parser.h" 12 | #include "normal_forms.h" 13 | #include "boolean_algebras/bdds/bdd_handle.h" 14 | 15 | namespace idni::tau_lang { 16 | 17 | // TODO (MEDIUM) clean execution api code 18 | template 19 | struct step { 20 | step(library> lib): lib(lib) {} 21 | 22 | tau operator()(const tau& n) const { 23 | return nso_rr_apply(lib, n); 24 | } 25 | 26 | library> lib; 27 | }; 28 | 29 | template 30 | struct steps { 31 | 32 | steps(std::vector libraries) : libraries(libraries) {} 33 | steps(step_t library) { 34 | libraries.push_back(library); 35 | } 36 | 37 | tau operator()(const tau& n) const { 38 | if (libraries.empty()) return n; 39 | auto nn = n; 40 | for (auto& lib : libraries) nn = lib(nn); 41 | return nn; 42 | } 43 | 44 | std::vector libraries; 45 | }; 46 | 47 | template 48 | struct repeat_each { 49 | 50 | repeat_each(steps s) : s(s) {} 51 | repeat_each(step_t s) : s(steps(s)) {} 52 | 53 | tau operator()(const tau& n) const { 54 | auto nn = n; 55 | for (auto& l: s.libraries) { 56 | std::set> visited; 57 | while (true) { 58 | nn = l(nn); 59 | if (visited.find(nn) != visited.end()) break; 60 | visited.insert(nn); 61 | } 62 | } 63 | return nn; 64 | } 65 | 66 | steps s; 67 | }; 68 | 69 | template 70 | struct repeat_all { 71 | 72 | repeat_all(steps s) : s(s) {} 73 | repeat_all(step_t s) : s(steps(s)) {} 74 | 75 | tau operator()(const tau& n) const { 76 | auto nn = n; 77 | std::set> visited; 78 | while (true) { 79 | for (auto& l: s.libraries) nn = l(nn); 80 | auto nnn = s(nn); 81 | if (nnn == nn) break; 82 | nn = nnn; 83 | } 84 | return nn; 85 | } 86 | 87 | steps s; 88 | }; 89 | 90 | template 91 | struct repeat_once { 92 | 93 | repeat_once(steps s) : s(s) {} 94 | repeat_once(step_t s) : s(steps(s)) {} 95 | 96 | tau operator()(const tau& n) const { 97 | auto nn = n; 98 | for(auto& l: s.libraries) { 99 | nn = l(nn); 100 | } 101 | return nn; 102 | } 103 | 104 | steps s; 105 | }; 106 | 107 | template 108 | steps, BAs...> operator|(const library>& l, const library>& r) { 109 | auto s = steps, BAs...>(step(l)); 110 | s.libraries.push_back(r); 111 | return s; 112 | } 113 | 114 | template 115 | steps, BAs...> operator|(const repeat_each& l, const repeat_each& r) { 116 | auto s = steps, BAs...>(l); 117 | s.libraries.push_back(r); 118 | return s; 119 | } 120 | 121 | template 122 | steps, BAs...> operator|(const repeat_all& l, const repeat_all& r) { 123 | auto s = steps, BAs...>(l); 124 | s.libraries.push_back(r); 125 | return s; 126 | } 127 | 128 | template 129 | steps operator|(const steps& s, const step_t& l) { 130 | auto ns = s; 131 | ns.libraries.push_back(l); 132 | return ns; 133 | } 134 | 135 | template 136 | steps operator|(const steps& s, const library>& l) { 137 | auto ns = s; 138 | ns.libraries.push_back(l); 139 | return ns; 140 | } 141 | 142 | template 143 | steps>, BAs...>, BAs...> operator|(const steps>, BAs...>, BAs...>& s, const library>& l) { 144 | auto ns = s; 145 | ns.libraries.push_back(l); 146 | return ns; 147 | } 148 | 149 | template 150 | tau operator|(const tau& n, const library>& l) { 151 | auto s = step(l); 152 | return s(n); 153 | } 154 | 155 | template 156 | tau operator|(const tau& n, const steps& s) { 157 | return s(n); 158 | } 159 | 160 | template 161 | tau operator|(const tau& n, const repeat_once& r) { 162 | return r(n); 163 | } 164 | 165 | template 166 | tau operator|(const tau& n, const repeat_all& r) { 167 | return r(n); 168 | } 169 | 170 | template 171 | tau operator|(const tau& n, const repeat_each& r) { 172 | return r(n); 173 | } 174 | 175 | } // namespace idni::tau_lang 176 | #endif // __EXECUTION_H__ -------------------------------------------------------------------------------- /src/experimental/execution.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __EXPERIMENTAL_EXECUTION_H__ 4 | #define __EXPERIMENTAL_EXECUTION_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "parser.h" 12 | #include "rewriting.h" 13 | 14 | /*#ifdef DEBUG 15 | #include "debug_helpers.h" 16 | #endif // DEBUG*/ 17 | 18 | namespace idni::tau_lang::experimental { 19 | 20 | // Check https://en.cppreference.com/w/cpp/utility/functional/function for more 21 | // information about std::function and how to use it. 22 | 23 | template 24 | auto operator|(const rewriter::sp_node& n, F f) { 25 | return f(n); 26 | } 27 | 28 | template 29 | auto operator|(const rewriter::sp_node& n, const std::pair& p) { 30 | return n | p.first | p.second; 31 | } 32 | 33 | template 34 | auto operator|(const F f, const S s) { 35 | return std::make_pair(f, s); 36 | } 37 | 38 | template 39 | struct repeat { 40 | 41 | repeat(F f) : f(f) {} 42 | 43 | auto operator()(const auto& n) const { 44 | auto current = n; 45 | auto next = f(current); 46 | while (current != next) { 47 | current = next; 48 | next = f(current); 49 | } 50 | return current; 51 | } 52 | 53 | F f; 54 | }; 55 | 56 | template 57 | struct apply_all { 58 | 59 | apply_all(selector_t s, function_t f) : s(s), f(f) {} 60 | 61 | N operator()(const N& n) const { 62 | std::map changes; 63 | for (auto& ns: s(n)){ 64 | changes[n] = f(n); 65 | } 66 | return replace(n, changes); 67 | } 68 | 69 | selector_t s; 70 | function_t f; 71 | }; 72 | 73 | template 74 | struct top { 75 | 76 | top(predicate_t p) : p(p) {} 77 | 78 | std::vector operator()(const N& n) const { 79 | return select_top(n, p); 80 | } 81 | 82 | predicate_t p; 83 | }; 84 | 85 | template 86 | struct bottom { 87 | 88 | bottom(predicate_t p) : p(p) {} 89 | 90 | std::optional operator()(const N& n) const { 91 | return find_bottom(n, p); 92 | } 93 | 94 | predicate_t p; 95 | }; 96 | 97 | template 98 | struct satisfying { 99 | 100 | satisfying(predicate_t p) : p(p) {} 101 | 102 | std::vector operator()(const N& n) const { 103 | return select_all(n, p); 104 | } 105 | 106 | predicate_t p; 107 | }; 108 | 109 | } // namespace idni::tau_lang::experimental 110 | 111 | #endif // __EXPERIMENTAL_EXECUTION_H__ -------------------------------------------------------------------------------- /src/hooks.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __HOOKS_H__ 4 | #define __HOOKS_H__ 5 | 6 | #include 7 | #include "nso_rr.h" 8 | #include "builders.h" 9 | 10 | namespace idni::tau_lang { 11 | 12 | /** 13 | * @brief Template struct to create a tau node. 14 | * 15 | * This struct defines an operator() that takes a rewriter node and returns 16 | * an optional tau node. 17 | * 18 | * @tparam BAs Variadic template parameters. 19 | */ 20 | template 21 | struct make_tau_node { 22 | /** 23 | * @brief Creates a tau node from a rewriter node. 24 | * 25 | * @param n The rewriter node to be converted. 26 | * @return std::optional> The created tau node, or std::nullopt if creation fails. 27 | */ 28 | std::optional> operator()( 29 | const rewriter::node>& n); 30 | }; 31 | 32 | } // namespace idni::tau_lang 33 | 34 | namespace idni::rewriter { 35 | 36 | /** 37 | * @brief Template specialization for creating a node hook for tau_sym. 38 | * 39 | * This struct defines an operator() that takes a rewriter node and returns 40 | * an optional tau node. 41 | * 42 | * @tparam BAs Variadic template parameters. 43 | */ 44 | template 45 | struct make_node_hook> { 46 | /** 47 | * @brief Creates a tau node from a rewriter node. 48 | * 49 | * @param n The rewriter node to be converted. 50 | * @return std::optional> The created tau node, or std::nullopt if creation fails. 51 | */ 52 | std::optional> operator()( 53 | const rewriter::node>& n); 54 | }; 55 | 56 | } // namespace idni::rewriter 57 | 58 | #include "hooks.tmpl.h" 59 | 60 | #endif // __HOOKS_H__ -------------------------------------------------------------------------------- /src/init_log.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | #ifndef __INIT_LOG_H__ 3 | #define __INIT_LOG_H__ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct logging_initializer { 11 | logging_initializer() { 12 | using namespace boost::log; 13 | core::get()->set_filter(trivial::severity >= trivial::info); 14 | static bool initialize_console_log = true; 15 | if (initialize_console_log) initialize_console_log = false, 16 | add_console_log(std::cout, keywords::format = 17 | expressions::stream << expressions::smessage); 18 | } 19 | }; 20 | inline static logging_initializer initialize_logging; 21 | 22 | #endif //__INIT_LOG_H__ -------------------------------------------------------------------------------- /src/nso_rr.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #include "boolean_algebras/nso_ba.h" 4 | 5 | namespace idni::tau_lang { 6 | 7 | using namespace idni::rewriter; 8 | 9 | bool pretty_printer_highlighting = false; 10 | bool pretty_printer_indenting = false; 11 | 12 | // extracts terminal from sp_tau_source_node 13 | std::function(const sp_tau_source_node& n)> 14 | tau_source_terminal_extractor = [](const sp_tau_source_node& n) 15 | { 16 | if (!n->value.nt() && !(n->value).is_null()) 17 | return std::optional(n->value.t()); 18 | return std::optional(); 19 | }; 20 | 21 | // make a tau source from the given source code string. 22 | sp_tau_source_node make_tau_source(const std::string& source, 23 | tau_parser::parse_options options) 24 | { 25 | // IDEA add cache for the parser 26 | auto result = tau_parser::instance().parse( 27 | source.c_str(), source.size(), options); 28 | if (!result.found) { 29 | auto msg = result.parse_error 30 | .to_str(tau_parser::error::info_lvl::INFO_BASIC); 31 | BOOST_LOG_TRIVIAL(error) << "(Error) " << msg << "\n"; 32 | return nullptr; // Syntax error 33 | } 34 | using parse_symbol = tau_parser::node_type; 35 | return make_node_from_parse_result< 36 | tau_parser, 37 | drop_location_t, 38 | tau_source_sym>(drop_location, 39 | result); 40 | } 41 | 42 | // make a tau source from the given source code stream. 43 | sp_tau_source_node make_tau_source(std::istream& is, 44 | tau_parser::parse_options options) 45 | { 46 | using parse_symbol = tau_parser::node_type; 47 | return make_node_from_stream< 48 | tau_parser, 49 | drop_location_t, 50 | tau_source_sym>(drop_location, 51 | is, options); 52 | } 53 | 54 | // make a tau source from the given source code stream. 55 | sp_tau_source_node make_tau_source_from_file(const std::string& filename, 56 | tau_parser::parse_options options) 57 | { 58 | using parse_symbol = tau_parser::node_type; 59 | return make_node_from_file< 60 | tau_parser, 61 | drop_location_t, 62 | tau_source_sym>(drop_location, 63 | filename, options); 64 | } 65 | 66 | } // idni::tau_lang namespace 67 | 68 | // << for tau_source_sym 69 | std::ostream& operator<<(std::ostream& stream, const idni::tau_lang::tau_source_sym& rs) { 70 | if (rs.nt()) stream << rs.t(); 71 | return stream; 72 | } 73 | 74 | // outputs a sp_tau_source_node to a stream, using the stringify transformer 75 | // and assumes that the constants also override operator<<. 76 | // 77 | // IDEA maybe it should be move to out.h 78 | std::ostream& operator<<(std::ostream& stream, const idni::tau_lang::sp_tau_source_node& n){ 79 | return stream << idni::tau_lang::make_string(idni::tau_lang::tau_source_terminal_extractor, n); 80 | } 81 | 82 | // << tau_source_node (make it shared to make use of the previous operator) 83 | std::ostream& operator<<(std::ostream& stream, const idni::tau_lang::tau_source_node& n){ 84 | return stream << std::make_shared(n); 85 | } 86 | -------------------------------------------------------------------------------- /src/splitter_types.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef SPLITTER_TYPES_H 4 | #define SPLITTER_TYPES_H 5 | 6 | // Define the possible types of splitters for a Boolean algebra constant 7 | enum class splitter_type { 8 | lower, middle, upper, bad 9 | }; 10 | 11 | #endif //SPLITTER_TYPES_H 12 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __UTILS_H__ 4 | #define __UTILS_H__ 5 | 6 | template 7 | struct overloaded : Ts... { using Ts::operator()...; }; 8 | template 9 | overloaded(Ts...) -> overloaded; 10 | 11 | #endif // __UTILS_H__ -------------------------------------------------------------------------------- /test-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd tests 4 | ctest -j 8 --test-dir ../build-Debug --output-on-failure $@ 5 | -------------------------------------------------------------------------------- /test-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd tests 4 | ctest -j 8 --test-dir ../build-Release --output-on-failure $@ 5 | -------------------------------------------------------------------------------- /test-relwithdebinfo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd build-RelWithDebInfo 4 | ctest -j 8 --output-on-failure $@ 5 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(DOCTEST_HEADER "${PROJECT_SOURCE_DIR}/src/doctest.h" CACHE PATH "Doctest header") 2 | if (NOT EXISTS "${DOCTEST_HEADER}") 3 | message(STATUS "Downloading doctest to '${PROJECT_SOURCE_DIR}'") 4 | find_package(Wget REQUIRED) 5 | # TODO (MEDIUM) we should use a fixed tag or commit instead of master 6 | execute_process(COMMAND "${WGET_EXECUTABLE}" https://raw.githubusercontent.com/doctest/doctest/master/doctest/doctest.h -P ${PROJECT_SOURCE_DIR}/src) 7 | endif () 8 | 9 | add_library(doctest INTERFACE) 10 | target_compile_definitions(doctest INTERFACE TAU_USE_DOCTEST) 11 | set(DOCTEST_CONFIG_ASSERTION_PARAMETERS_BY_VALUE "true") 12 | 13 | add_link_options("-flto") 14 | 15 | # 16 | # Integration testing 17 | # 18 | set(TAU_BUILD_INTEGRATION ON CACHE STRING "build the tau-lang integration suite ON") 19 | set_property(CACHE TAU_BUILD_INTEGRATION PROPERTY STRINGS "OFF" "ON") 20 | 21 | if (TAU_BUILD_INTEGRATION) 22 | enable_testing() 23 | add_subdirectory(integration) 24 | endif () 25 | 26 | # 27 | # Unit testing 28 | # 29 | set(TAU_BUILD_UNIT_TESTS ON CACHE STRING "build the tau-lang unit suite ON") 30 | set_property(CACHE TAU_BUILD_UNIT_TESTS PROPERTY STRINGS "OFF" "ON") 31 | 32 | if (TAU_BUILD_UNIT_TESTS) 33 | enable_testing() 34 | add_subdirectory(unit) 35 | endif () 36 | 37 | # 38 | # Experimental testing 39 | # 40 | if (TAU_BUILD_UNIT_TESTS) 41 | enable_testing() 42 | add_subdirectory(experimental) 43 | endif () 44 | 45 | # 46 | # Benchmark testing 47 | # 48 | if (TAU_BUILD_BENCHMARK) 49 | enable_testing() 50 | add_subdirectory(benchmark) 51 | endif () 52 | 53 | # 54 | # REPL testing 55 | # 56 | set(TAU_BUILD_REPL_TESTS ON CACHE STRING "build the tau-lang repl suite ON") 57 | set_property(CACHE TAU_BUILD_REPL_TESTS PROPERTY STRINGS "OFF" "ON") 58 | 59 | if (TAU_BUILD_REPL_TESTS) 60 | enable_testing() 61 | add_subdirectory(repl) 62 | endif () 63 | -------------------------------------------------------------------------------- /tests/benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | function(add_valgrind_file_test test_name test_file) 4 | add_test(NAME "test_repl-${test_name}" 5 | COMMAND bash -c "cat \"${test_file}\" | valgrind --tool=callgrind --callgrind-out-file=${PROJECT_BINARY_DIR}/test_benchmark-${test_name}-${GIT_COMMIT_HASH}.callgrind.out $") 6 | endfunction() 7 | 8 | function(add_valgrind_command_test test_name test_cmd) 9 | add_test(NAME "test_repl-${test_name}" 10 | COMMAND bash -c "echo \"${test_cmd}. q\" | valgrind --tool=callgrind --callgrind-out-file=${PROJECT_BINARY_DIR}/test_benchmark-${test_name}-${GIT_COMMIT_HASH}.callgrind.out $") 11 | endfunction() 12 | 13 | set(BENCHMARK_TESTS 14 | wff_normalization 15 | interpreter 16 | ) 17 | 18 | # adding benchmark tests 19 | foreach(X IN LISTS BENCHMARK_TESTS) 20 | set(N "test_benchmark-${X}") 21 | add_executable(${N} "${N}.cpp") 22 | target_setup(${N}) 23 | target_link_libraries(${N} ${TAU_OBJECT_LIB_NAME} ${IDNI_PARSER_OBJECT_LIB}) 24 | target_compile_options(${N} PUBLIC -Wno-unused-function) 25 | add_test(NAME ${N} COMMAND "${PROJECT_BINARY_DIR}/${N}") 26 | endforeach() 27 | 28 | # adding valgrind tests for wff normalization 29 | 30 | add_valgrind_command_test(luccas_example "n ex a ex b ex c ex d ex f ex e (ax + bx' = cy + dy' || ax + bx' != ey + fy') <-> (ax + bx' = cy + gy')") 31 | add_valgrind_command_test(ohads_example "n all a all b all c all d all p all q all r all s all m all j all k all l (all x ex y f(x,y)=0 || (g(x,y)=0 && h(x,y)!=0)) && !(all y0 all y1 all z0 all z1 ex x f(x,y1x+y0'x)=0 && (g(x,y1x+y0'x)!=0 && h(x,y1x+y0'x)=0))") 32 | -------------------------------------------------------------------------------- /tests/benchmark/test_benchmark-helper.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __TEST_BENCHMARK_HELPER_H__ 4 | #define __TEST_BENCHMARK_HELPER_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "boolean_algebras/tau_ba.h" 14 | 15 | // Function to get memory usage in bytes 16 | size_t get_memory_usage() { 17 | std::ifstream statm("/proc/self/statm"); 18 | size_t size; 19 | statm >> size; 20 | return size * sysconf(_SC_PAGESIZE); 21 | } 22 | 23 | void exit_after_mb(size_t limit_mb) { 24 | size_t limit_bytes = limit_mb * 1024 * 1024; 25 | while (true) { 26 | size_t memoryUsage = get_memory_usage(); 27 | if (memoryUsage > limit_bytes) { 28 | std::cout << "Memory usage exceeded " << limit_mb << " MB. Exiting program.\n"; 29 | std::exit(1); 30 | } 31 | std::this_thread::sleep_for(std::chrono::seconds(1)); // Check every second 32 | } 33 | } 34 | 35 | void exit_after_seconds(int limit_sec) { 36 | std::this_thread::sleep_for(std::chrono::seconds(limit_sec)); 37 | std::cout << "Time limit exceeded " << limit_sec << " seconds. Exiting program.\n"; 38 | std::exit(1); 39 | } 40 | 41 | #endif // __TEST_BENCHMARK_HELPER_H__ -------------------------------------------------------------------------------- /tests/experimental/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | set(TESTS 4 | experimental_execution 5 | ) 6 | 7 | foreach(X IN LISTS TESTS) 8 | set(N "test_${X}") 9 | add_executable(${N} "${N}.cpp") 10 | target_setup(${N}) 11 | target_link_libraries(${N} ${TAU_OBJECT_LIB_NAME} ${IDNI_PARSER_OBJECT_LIB} doctest) 12 | target_compile_options(${N} PUBLIC -Wno-unused-function) 13 | add_test(NAME ${N} COMMAND "${PROJECT_BINARY_DIR}/${N}") 14 | endforeach() 15 | -------------------------------------------------------------------------------- /tests/integration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | set(TESTS 4 | sbf1 5 | sbf2 6 | tau_ba1 7 | tau_ba3 8 | normal_forms 9 | nso_rr_execution 10 | nso_rr_partial_eval 11 | nso_rr_fixed_point 12 | ref_types 13 | bf_fixed_point 14 | bf_normalization 15 | wff_normalization 16 | satisfiability 17 | splitter 18 | splitter2 19 | solver 20 | quantifiers 21 | wff_hooks 22 | bf_hooks 23 | interpreter 24 | ) 25 | 26 | foreach(TEST IN LISTS TESTS) 27 | set(N "test_integration-${TEST}") 28 | add_executable(${N} "${N}.cpp") 29 | target_setup(${N}) 30 | target_link_libraries(${N} ${TAU_OBJECT_LIB_NAME} ${IDNI_PARSER_OBJECT_LIB} doctest) 31 | target_compile_options(${N} PUBLIC -Wno-unused-function) 32 | add_test(NAME ${N} COMMAND "${PROJECT_BINARY_DIR}/${N}") 33 | set_tests_properties(${N} PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..) 34 | endforeach() -------------------------------------------------------------------------------- /tests/integration/test_files/sbf-alternating_zeros_and_ones-length_10.in: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | 0 4 | 1 5 | 0 6 | 1 7 | 0 8 | 1 9 | 0 10 | 1 -------------------------------------------------------------------------------- /tests/integration/test_files/sbf-alternating_zeros_and_ones-length_2.in: -------------------------------------------------------------------------------- 1 | 0 2 | 1 3 | -------------------------------------------------------------------------------- /tests/integration/test_files/sbf-ones-length_1.in: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /tests/integration/test_files/sbf-ones-length_10.in: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | -------------------------------------------------------------------------------- /tests/integration/test_files/sbf-zeros-length_1.in: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /tests/integration/test_files/sbf-zeros-length_10.in: -------------------------------------------------------------------------------- 1 | 0 2 | 0 3 | 0 4 | 0 5 | 0 6 | 0 7 | 0 8 | 0 9 | 0 10 | 0 11 | -------------------------------------------------------------------------------- /tests/integration/test_files/tau-alternating_zeros_and_ones-length_10.in: -------------------------------------------------------------------------------- 1 | F. 2 | T. 3 | F. 4 | T. 5 | F. 6 | T. 7 | F. 8 | T. 9 | F. 10 | T. -------------------------------------------------------------------------------- /tests/integration/test_integration-bf_fixed_point.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | 7 | #include "test_integration_helpers.h" 8 | #include "../unit/test_helpers.h" 9 | 10 | using namespace idni::rewriter; 11 | using namespace idni::tau_lang; 12 | 13 | namespace testing = doctest; 14 | 15 | bool test_bf_rr_fp(const char* rec, const char* sample, tau_parser::nonterminal nt, 16 | bool expect_fail = false) 17 | { 18 | tau_parser::parse_options options; 19 | options.start = tau_parser::rec_relations; 20 | auto rec_src = make_tau_source(rec, options); 21 | auto rec_formula = make_nso_rr_using_factory(rec_src); 22 | if (!rec_formula.has_value()) return expect_fail; 23 | rec_formula = infer_ref_types(rec_formula.value()); 24 | if (!rec_formula.has_value()) return expect_fail; 25 | options.start = tau_parser::bf; 26 | auto sample_src = make_tau_source(sample, options); 27 | auto formula = make_nso_rr_using_factory(sample_src); 28 | if (!formula.has_value()) return expect_fail; 29 | auto sample_formula = formula.value(); 30 | sample_formula.rec_relations = rec_formula.value().rec_relations; 31 | auto result = bf_normalizer_with_rec_relation( 32 | sample_formula); 33 | if (!result) return expect_fail; 34 | auto check = result | nt; 35 | if (!check) return expect_fail; 36 | return expect_fail ? !check.has_value() : check.has_value(); 37 | } 38 | 39 | bool test_bf_rr_fp_1(const char* rec, const char* sample) { 40 | return test_bf_rr_fp(rec, sample, tau_parser::bf_t); 41 | } 42 | 43 | bool test_bf_rr_fp_0(const char* rec, const char* sample) { 44 | return test_bf_rr_fp(rec, sample, tau_parser::bf_f); 45 | } 46 | 47 | bool test_bf_rr_fp_expect_fail(const char* rec, const char* sample, 48 | tau_parser::nonterminal nt) 49 | { 50 | return test_bf_rr_fp(rec, sample, nt, true); 51 | } 52 | 53 | TEST_SUITE("Boolean function recurrence relation fixed point calculation") { 54 | 55 | TEST_CASE("loop default fallback (0)") { 56 | const char* rec="g[n](x) := g[n-1](x)'." 57 | "g[0](x) := 1."; 58 | const char* sample = "g(0)"; 59 | CHECK( test_bf_rr_fp_0(rec, sample) ); 60 | } 61 | 62 | TEST_CASE("loop fallback 1") { 63 | const char* rec="g[n](x) := g[n-1](x)'." 64 | "g[0](x) := 1."; 65 | const char* sample = "g(x) fallback 1"; 66 | CHECK( test_bf_rr_fp_1(rec, sample) ); 67 | } 68 | 69 | TEST_CASE("loop fallback last") { 70 | const char* rec="g[n](x) := g[n-1](x)'." 71 | "g[0](x) := 1."; 72 | const char* sample = "g(x) fallback last"; 73 | CHECK( test_bf_rr_fp_0(rec, sample) ); 74 | } 75 | 76 | TEST_CASE("loop fallback first") { 77 | const char* rec="g[n](x) := g[n-1](x)'." 78 | "g[0](x) := 1."; 79 | const char* sample = "g(x) fallback first"; 80 | CHECK( test_bf_rr_fp_1(rec, sample) ); 81 | } 82 | 83 | TEST_CASE("referring itself") { 84 | const char* rec="f[n](x) := f[n-1](x) & x." 85 | "f[0](x) := 1."; 86 | const char* sample = "f(x)"; 87 | CHECK( test_bf_rr_fp(rec, sample, tau_parser::variable) ); 88 | } 89 | 90 | TEST_CASE("multiple") { 91 | const char* rec="f[0](x) := 1." 92 | "g[0](x) := 0." 93 | "f[n](x) := f[n-1](x) | g[n](x)." 94 | "g[n](x) := g[n-1](x)'."; 95 | const char* sample = "f(x)"; 96 | CHECK( test_bf_rr_fp_1(rec, sample) ); 97 | } 98 | 99 | TEST_CASE("no initial condition") { 100 | const char* rec = "f[n](x) := f[n-1](x) & 1."; 101 | const char* sample = "f(x)"; 102 | CHECK( test_bf_rr_fp(rec, sample, tau_parser::bf_or) ); 103 | } 104 | 105 | TEST_CASE("with initial conditions") { 106 | const char* rec="f[0](x) := 0." 107 | "f[2](x) := 0." 108 | "f[4](x) := 0." 109 | "f[8](x) := 0." 110 | "f[n](x) := 1."; 111 | const char* sample = "f(x)"; 112 | CHECK( test_bf_rr_fp_1(rec, sample) ); 113 | } 114 | } 115 | 116 | TEST_SUITE("Boolean function recurrence relation well foundedness") { 117 | 118 | TEST_CASE("detect cycle direct") { 119 | const char* rec="f[0](x) := 1." 120 | "f[n](x) := f[n](x)."; 121 | const char* sample = "f(x)"; 122 | CHECK( test_bf_rr_fp_expect_fail(rec, sample, tau_parser::bf_f) ); 123 | } 124 | 125 | TEST_CASE("no rule") { 126 | const char* rec="g[0](Y) := 1." 127 | "g[1](Y) := 1."; 128 | const char* sample = "g(Y)"; 129 | CHECK( test_bf_rr_fp_expect_fail(rec, sample, tau_parser::bf_f) ); 130 | } 131 | 132 | TEST_CASE("fallback type mismatch") { 133 | const char* rec = "g[n](Y) := 1."; 134 | const char* sample = "g(Y) fallback T"; 135 | CHECK( test_bf_rr_fp_expect_fail(rec, sample, tau_parser::bf_f) ); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /tests/integration/test_integration-bf_normalization.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | 7 | #include "test_integration_helpers.h" 8 | #include "../unit/test_helpers.h" 9 | 10 | using namespace idni::rewriter; 11 | using namespace idni::tau_lang; 12 | 13 | namespace testing = doctest; 14 | 15 | bool test_bf_normalizer_and_test_for_value(const char* sample, 16 | tau_parser::nonterminal nt) 17 | { 18 | tau_parser::parse_options options; options.start = tau_parser::bf; 19 | auto sample_src = make_tau_source(sample, options); 20 | auto formula = make_nso_rr_using_factory(sample_src); 21 | if (!formula.has_value()) return false; 22 | auto result = bf_normalizer_without_rec_relation( 23 | formula.value().main); 24 | return (result | nt).has_value(); 25 | } 26 | 27 | TEST_SUITE("Normalize Boolean function without recurrence relation | simple cases") { 28 | 29 | TEST_CASE("True and False") { 30 | const char* sample = "1 & 0"; 31 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_f) ); 32 | } 33 | 34 | TEST_CASE("True or False") { 35 | const char* sample = "1 | 0"; 36 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_t) ); 37 | } 38 | 39 | TEST_CASE("False and True") { 40 | const char* sample = "0 & 1"; 41 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_f) ); 42 | } 43 | 44 | TEST_CASE("False or True") { 45 | const char* sample = "0 | 1"; 46 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_t) ); 47 | } 48 | 49 | TEST_CASE("X or X") { 50 | const char* sample = "X | X"; 51 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::variable) ); 52 | } 53 | 54 | TEST_CASE("X and X") { 55 | const char* sample = "X & X"; 56 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::variable) ); 57 | } 58 | 59 | TEST_CASE("X or X'") { 60 | const char* sample = "X | X'"; 61 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_t) ); 62 | } 63 | 64 | TEST_CASE("X and X'") { 65 | const char* sample = "X & X'"; 66 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_f) ); 67 | } 68 | } 69 | 70 | 71 | TEST_SUITE("Normalize Boolean function without recurrence relation | Simple SAT problems") { 72 | TEST_CASE("4 variables") { 73 | const char* sample = "ex x ex y ex v ex w (x' & y & v & w') != 0."; 74 | auto sample_src = make_tau_source(sample); 75 | auto formula = make_nso_rr_using_factory(sample_src); 76 | CHECK ( formula.has_value() ); 77 | if (!formula.has_value()) return; 78 | auto result = normalizer(formula.value()); 79 | auto check = result | tau_parser::wff_t; 80 | CHECK( check.has_value() ); 81 | } 82 | 83 | TEST_CASE("Quantifier Alternation") { 84 | const char* sample = "all x ex y all v ex w ((x' | y) & (y' | x) & (v' | w) & (w' | v)) != 0."; 85 | auto sample_src = make_tau_source(sample); 86 | auto sample_formula = make_nso_rr_using_factory(sample_src).value(); 87 | auto result = normalizer(sample_formula); 88 | auto check = result | tau_parser::wff_t; 89 | CHECK( check.has_value() ); 90 | } 91 | } 92 | 93 | TEST_SUITE("Normalize Boolean function with recurrence relation") { 94 | TEST_CASE("Alternating negation") { 95 | const char* rec = 96 | "h[n](X) := h[n - 1](X)'." 97 | "h[0](X) := X."; 98 | tau_parser::parse_options options; 99 | options.start = tau_parser::rec_relations; 100 | auto rec_src = make_tau_source(rec, options); 101 | auto rec_formula = make_nso_rr_using_factory(rec_src); 102 | CHECK ( rec_formula.has_value() ); 103 | if (!rec_formula.has_value()) return; 104 | rec_formula = infer_ref_types(rec_formula.value()); 105 | const char* sample = "h[8](Y)"; 106 | options.start = tau_parser::bf; 107 | auto sample_src = make_tau_source(sample, options); 108 | auto formula = make_nso_rr_using_factory(sample_src); 109 | CHECK ( formula.has_value() ); 110 | if (!formula.has_value()) return; 111 | auto sample_formula = formula.value(); 112 | sample_formula.rec_relations = rec_formula.value().rec_relations; 113 | auto result = bf_normalizer_with_rec_relation(sample_formula); 114 | auto check = result | tau_parser::variable; 115 | CHECK( check.has_value() ); 116 | } 117 | 118 | TEST_CASE("Dependend recurrence relations") { 119 | const char* rec = 120 | "h[n](X) := g[n - 1](X)'." 121 | "h[0](X) := X." 122 | "g[n](Y) := h[n - 1](Y)'." 123 | "g[0](Y) := Y'."; 124 | 125 | tau_parser::parse_options options; 126 | options.start = tau_parser::rec_relations; 127 | auto rec_src = make_tau_source(rec, options); 128 | auto rec_formula = make_nso_rr_using_factory(rec_src); 129 | CHECK ( rec_formula.has_value() ); 130 | if (!rec_formula.has_value()) return; 131 | rec_formula = infer_ref_types(rec_formula.value()); 132 | const char* sample = "h[8](Y)"; 133 | options.start = tau_parser::bf; 134 | auto sample_src = make_tau_source(sample, options); 135 | auto formula = make_nso_rr_using_factory(sample_src); 136 | CHECK ( formula.has_value() ); 137 | if (!formula.has_value()) return; 138 | auto sample_formula = formula.value(); 139 | sample_formula.rec_relations = rec_formula.value().rec_relations; 140 | auto result = bf_normalizer_with_rec_relation(sample_formula); 141 | auto check = result | tau_parser::variable; 142 | CHECK( check.has_value() ); 143 | } 144 | } 145 | 146 | TEST_SUITE("SBF expressions") { 147 | TEST_CASE("X or Y") { 148 | bdd_init(); 149 | const char* sample = "{X}:sbf | {Y}:sbf"; 150 | CHECK( test_bf_normalizer_and_test_for_value(sample, tau_parser::bf_constant) ); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /tests/integration/test_integration-normal_forms.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | 7 | #include "test_integration_helpers.h" 8 | #include "../unit/test_helpers.h" 9 | 10 | #ifdef DEBUG 11 | #include "debug_helpers.h" 12 | #endif 13 | 14 | using namespace idni::rewriter; 15 | using namespace idni::tau_lang; 16 | 17 | namespace testing = doctest; 18 | 19 | TEST_SUITE("normal forms: snf for wff") { 20 | 21 | TEST_CASE("simple case: T") { 22 | const char* sample = "T."; 23 | auto sample_src = make_tau_source(sample); 24 | auto nso__rr = make_nso_rr_using_factory(sample_src); 25 | CHECK( nso__rr.has_value() ); 26 | if (!nso__rr.has_value()) return; 27 | #ifdef DEBUG 28 | print_tau_tree(std::cout, nso__rr.value().main); 29 | #endif // DEBUG 30 | auto check = nso__rr.value().main 31 | | tau_parser::wff_t; 32 | CHECK( check.has_value() ); 33 | } 34 | 35 | TEST_CASE("simple case: F") { 36 | const char* sample = "F."; 37 | auto sample_src = make_tau_source(sample); 38 | auto nso__rr = make_nso_rr_using_factory(sample_src); 39 | CHECK( nso__rr.has_value() ); 40 | if (!nso__rr.has_value()) return; 41 | auto check = nso__rr.value().main 42 | | tau_parser::wff_f; 43 | CHECK( check.has_value() ); 44 | } 45 | 46 | TEST_CASE("simple case: X = 0") { 47 | const char* sample = "X = 0."; 48 | auto sample_src = make_tau_source(sample); 49 | auto nso__rr = make_nso_rr_using_factory(sample_src); 50 | CHECK( nso__rr.has_value() ); 51 | if (!nso__rr.has_value()) return; 52 | auto result = snf_wff(nso__rr.value().main); 53 | CHECK( nso__rr.value().main == result ); 54 | } 55 | 56 | TEST_CASE("quantifiers: always X = 0") { 57 | const char* sample = "always X = 0."; 58 | auto sample_src = make_tau_source(sample); 59 | auto nso__rr = make_nso_rr_using_factory(sample_src); 60 | CHECK( nso__rr.has_value() ); 61 | if (!nso__rr.has_value()) return; 62 | auto result = snf_wff(nso__rr.value().main); 63 | CHECK( nso__rr.value().main == result ); 64 | } 65 | 66 | TEST_CASE("quantifiers: sometimes o1[t] = 0") { 67 | const char* sample = "sometimes o1[t] = 0."; 68 | auto sample_src = make_tau_source(sample); 69 | auto nso__rr = make_nso_rr_using_factory(sample_src); 70 | CHECK( nso__rr.has_value() ); 71 | if (!nso__rr.has_value()) return; 72 | auto result = snf_wff(nso__rr.value().main); 73 | CHECK( nso__rr.value().main == result ); 74 | } 75 | 76 | TEST_CASE("quantifiers: all X X = 0") { 77 | const char* sample = "all X X = 0."; 78 | auto sample_src = make_tau_source(sample); 79 | auto nso__rr = make_nso_rr_using_factory(sample_src); 80 | CHECK( nso__rr.has_value() ); 81 | if (!nso__rr.has_value()) return; 82 | auto result = snf_wff(nso__rr.value().main); 83 | CHECK( nso__rr.value().main == result ); 84 | } 85 | 86 | TEST_CASE("quantifiers: ex X X = 0") { 87 | const char* sample = "ex X X = 0."; 88 | auto sample_src = make_tau_source(sample); 89 | auto nso__rr = make_nso_rr_using_factory(sample_src); 90 | CHECK( nso__rr.has_value() ); 91 | if (!nso__rr.has_value()) return; 92 | auto result = snf_wff(nso__rr.value().main); 93 | CHECK( nso__rr.value().main == result ); 94 | } 95 | 96 | TEST_CASE("rec. relations: f[0](X)") { 97 | const char* sample = "f[0](X)."; 98 | auto sample_src = make_tau_source(sample); 99 | auto nso__rr = make_nso_rr_using_factory(sample_src); 100 | CHECK( nso__rr.has_value() ); 101 | if (!nso__rr.has_value()) return; 102 | auto result = snf_wff(nso__rr.value().main); 103 | CHECK( nso__rr.value().main == result ); 104 | } 105 | 106 | // TODO (MEDIUM) fix this test 107 | /*TEST_CASE("simple case: {sbf: a} x = 0 && {sbf:a}' x = 0") { 108 | const char* sample = "{sbf: a} x = 0 && {sbf:a}' x = 0."; 109 | auto sample_src = make_tau_source(sample); 110 | auto nso__rr = make_nso_rr_using_factory(sample_src); 111 | CHECK( nso__rr.has_value() ); 112 | if (!nso__rr.has_value()) return; 113 | auto result = snf_wff(nso__rr.value().main); 114 | std::stringstream ss; ss << result; 115 | CHECK( ss.str() == "x = 0" ); 116 | }*/ 117 | 118 | TEST_CASE("simple case: xy = 0 && x = 0") { 119 | const char* sample = "xy = 0 && x = 0."; 120 | auto sample_src = make_tau_source(sample); 121 | auto nso__rr = make_nso_rr_using_factory(sample_src); 122 | CHECK( nso__rr.has_value() ); 123 | if (!nso__rr.has_value()) return; 124 | auto result = snf_wff(nso__rr.value().main); 125 | std::stringstream ss; ss << result; 126 | CHECK( ss.str() == "x = 0" ); 127 | } 128 | 129 | TEST_CASE("simple case: xy != 0 && x != 0") { 130 | const char* sample = "xy != 0 && x != 0."; 131 | auto sample_src = make_tau_source(sample); 132 | auto nso__rr = make_nso_rr_using_factory(sample_src); 133 | CHECK( nso__rr.has_value() ); 134 | if (!nso__rr.has_value()) return; 135 | auto result = snf_wff(nso__rr.value().main); 136 | std::stringstream ss; ss << result; 137 | CHECK( ss.str() == "xy != 0" ); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /tests/integration/test_integration-nso_rr_fixed_point.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | 7 | #include "test_integration_helpers.h" 8 | #include "../unit/test_helpers.h" 9 | 10 | using namespace idni::rewriter; 11 | using namespace idni::tau_lang; 12 | 13 | namespace testing = doctest; 14 | 15 | bool fp_test(const char* sample, const size_t& nt, bool expect_fail = false) { 16 | auto sample_src = make_tau_source(sample); 17 | auto formula = make_nso_rr_using_factory(sample_src); 18 | if (!formula) return expect_fail; 19 | auto normalized = normalizer(formula.value()); 20 | if (!normalized) return expect_fail; 21 | auto ret = (normalized | nt).has_value(); 22 | return expect_fail ? !ret : ret; 23 | } 24 | 25 | bool fp_test_F(const char* sample) { 26 | return fp_test(sample, tau_parser::wff_f); 27 | } 28 | 29 | bool fp_test_T(const char* sample) { 30 | return fp_test(sample, tau_parser::wff_t); 31 | } 32 | 33 | bool fp_test_fail(const char* sample, const size_t& nt) { 34 | return fp_test(sample, nt, true); 35 | } 36 | 37 | bool fp_test_fail(const char* sample) { 38 | return fp_test_fail(sample, tau_parser::wff_f); 39 | } 40 | 41 | TEST_SUITE("rec relations fixed point") { 42 | 43 | TEST_CASE("loop default fallback (F)") { 44 | const char* sample = 45 | "g[n](x) := !g[n-1](x)." 46 | "g[0](x) := T." 47 | "g(x)."; 48 | CHECK( fp_test_F(sample) ); 49 | } 50 | 51 | TEST_CASE("loop fallback T") { 52 | const char* sample = 53 | "g[n](x) := !g[n-1](x)." 54 | "g[0](x) := T." 55 | "g(x) fallback T."; 56 | CHECK( fp_test_T(sample) ); 57 | } 58 | 59 | TEST_CASE("loop fallback last") { 60 | const char* sample = 61 | "g[n](x) := !g[n-1](x)." 62 | "g[0](x) := T." 63 | "g(x) fallback last."; 64 | CHECK( fp_test_F(sample) ); 65 | } 66 | 67 | TEST_CASE("loop fallback first") { 68 | const char* sample = 69 | "g[n](x) := !g[n-1](x)." 70 | "g[0](x) := T." 71 | "g(x) fallback first."; 72 | CHECK( fp_test_T(sample) ); 73 | } 74 | 75 | TEST_CASE("referring itself") { 76 | const char* sample = 77 | "f[n](x) := f[n-1](x) && x = 1." 78 | "f[0](x) := T." 79 | "f(x)."; 80 | CHECK( fp_test(sample, tau_parser::bf_eq) ); 81 | } 82 | 83 | TEST_CASE("multiple") { 84 | const char* sample = 85 | "f[0](x) := T." 86 | "g[0](x) := F." 87 | "f[n](x) := f[n-1](x) || g[n](x)." 88 | "g[n](x) := !g[n-1](x)." 89 | "f(x)."; 90 | CHECK( fp_test_T(sample) ); 91 | } 92 | 93 | TEST_CASE("no initial condition") { 94 | const char* sample = 95 | "f[n](x) := f[n-1](x) && T." 96 | "f(x)."; 97 | CHECK( fp_test(sample, tau_parser::wff_ref) ); 98 | } 99 | 100 | TEST_CASE("with initial conditions") { 101 | const char* sample = 102 | "f[0](x) := F." 103 | "f[2](x) := F." 104 | "f[4](x) := F." 105 | "f[8](x) := F." 106 | "f[n](x) := T." 107 | "f(x)."; 108 | CHECK( fp_test_T(sample) ); 109 | } 110 | } 111 | 112 | TEST_SUITE("rec relations well foundedness") { 113 | 114 | TEST_CASE("shift in header") { 115 | const char* sample = 116 | "f[n-1](x) := f[n-2](x)." 117 | "f(x)."; 118 | CHECK( fp_test_fail(sample) ); 119 | } 120 | 121 | TEST_CASE("left fixed, right relative") { 122 | const char* sample = 123 | "f[0](x) := f[n](x)." 124 | "f(x)."; 125 | CHECK( fp_test_fail(sample) ); 126 | } 127 | 128 | TEST_CASE("left < right") { 129 | const char* sample = 130 | "f[1](x) := f[2](x)." 131 | "f(x)."; 132 | CHECK( fp_test_fail(sample) ); 133 | } 134 | 135 | TEST_CASE("detect cycle direct") { 136 | const char* sample = 137 | "f[0](x) := T." 138 | "f[n](x) := f[n](x)." 139 | "f(x)."; 140 | CHECK( fp_test_fail(sample) ); 141 | } 142 | 143 | TEST_CASE("detect cycle indirect") { 144 | const char* sample = 145 | "f[n](x) := g[n](x)." 146 | "g[n](x) := f[n](x)." 147 | "g(x)."; 148 | CHECK( fp_test_fail(sample) ); 149 | } 150 | 151 | TEST_CASE("no rule") { 152 | const char* sample = 153 | "g[0](Y) := T." 154 | "g[1](Y) := T." 155 | "g(Y)."; 156 | CHECK( fp_test_fail(sample) ); 157 | } 158 | 159 | TEST_CASE("fallback type mismatch") { 160 | const char* sample = 161 | "g[n](Y) := T." 162 | "g(Y) fallback 1."; 163 | CHECK( fp_test_fail(sample) ); 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /tests/integration/test_integration-nso_rr_partial_eval.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | 7 | #include "test_integration_helpers.h" 8 | #include "../unit/test_helpers.h" 9 | 10 | using namespace idni::rewriter; 11 | using namespace idni::tau_lang; 12 | 13 | namespace testing = doctest; 14 | 15 | bool normalize_and_test_for_value(const char* sample, tau_parser::nonterminal nt) { 16 | auto sample_src = make_tau_source(sample); 17 | auto sample_formula = make_nso_rr_using_factory(sample_src); 18 | if (!sample_formula.has_value()) return false; 19 | auto result = normalizer(sample_formula.value()); 20 | auto check = result | nt; 21 | return check.has_value(); 22 | } 23 | 24 | TEST_SUITE("rec relations partial evaluation: simple cases") { 25 | 26 | TEST_CASE("wff_rec_relation") { 27 | const char* sample = 28 | "h[0](X, Y) := X + Y != 0." 29 | "g[n](Y) := h[n-1](Y, 0)." 30 | "g[1](1)."; 31 | CHECK( normalize_and_test_for_value(sample, tau_parser::wff_t) ); 32 | } 33 | 34 | TEST_CASE("bf_rec_relation") { 35 | const char* sample = 36 | "h[0](X, Y) := X + Y." 37 | "g[n](Y) := h[n-1](Y, 0)." 38 | "g[1](0) = 0."; 39 | CHECK( normalize_and_test_for_value(sample, tau_parser::wff_t) ); 40 | } 41 | } 42 | 43 | TEST_SUITE("functions partial evaluation: simple cases") { 44 | 45 | TEST_CASE("wff_rec_relation") { 46 | const char* sample = 47 | "h(X, Y) := X = Y." 48 | "g(Y) := h(Y, 0)." 49 | "g(0)."; 50 | CHECK( normalize_and_test_for_value(sample, tau_parser::wff_t) ); 51 | } 52 | 53 | TEST_CASE("bf_rec_relation") { 54 | const char* sample = 55 | "h(X, Y) := X + Y." 56 | "g(Y) := h(Y, 0)." 57 | "g(1) = 1."; 58 | CHECK( normalize_and_test_for_value(sample, tau_parser::wff_t) ); 59 | } 60 | } -------------------------------------------------------------------------------- /tests/integration/test_integration-quantifiers.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | // tests parsing, printing, normalization and printed result of 4 | // quantifiers: all, ex 5 | 6 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 7 | 8 | #include "doctest.h" 9 | 10 | #include "test_integration_helpers.h" 11 | #include "../unit/test_helpers.h" 12 | 13 | // #include "debug_helpers.h" 14 | 15 | using namespace std; 16 | using namespace idni::rewriter; 17 | using namespace idni::tau_lang; 18 | 19 | namespace testing = doctest; 20 | 21 | using test_case = array; 22 | using test_cases = vector; 23 | 24 | test_cases ex_cases = { 25 | { "ex x x=0.", "ex x x = 0", "T" }, 26 | { "ex x,y xy=0.", "ex x, y xy = 0", "T" }, 27 | { "ex x ex y xy=0.", "ex x, y xy = 0", "T" }, 28 | }; 29 | 30 | test_cases all_cases = { 31 | { "all x x!=0.", "all x x != 0", "F" }, 32 | { "all x,y xy!=0.", "all x, y xy != 0", "F" }, 33 | { "all x all y xy!=0.", "all x, y xy != 0", "F" }, 34 | }; 35 | 36 | test_cases ex_all_cases = { 37 | { "ex x all y x=y.", "ex x all y x'y|xy' = 0", "F" }, 38 | { "ex x,y all w,z x=w&&y=z.", 39 | "ex x, y all w, z x'w|xw' = 0 && y'z|yz' = 0", "F"}, 40 | }; 41 | 42 | test_cases all_ex_cases = { 43 | { "all x ex y x=y.", "all x ex y x'y|xy' = 0", "T" }, 44 | { "all x,y ex w,z x=w && y=z.", 45 | "all x, y ex w, z x'w|xw' = 0 && y'z|yz' = 0", "T"}, 46 | }; 47 | 48 | ostream& operator<<(ostream& os, const test_case& tc) { 49 | return os << "input source: \"" << tc[0] 50 | << "\"\n\texpected: \"" << tc[1] 51 | << "\" result: \"" << tc[2] << "\""; 52 | } 53 | 54 | string to_str(const auto& n) { 55 | stringstream ss; return (ss << n, ss.str()); 56 | } 57 | 58 | bool test(const test_case& tc) { 59 | const auto& [ sample, exp, nexp ] = tc; 60 | bool fail = false; 61 | auto src = make_tau_source(sample.c_str()); 62 | auto formula = make_nso_rr_using_factory(src); 63 | if (!formula.has_value()) return fail; 64 | auto got = to_str(formula.value()); 65 | if (got != exp) fail = true; 66 | auto norm = normalizer(formula.value()); 67 | auto ngot = to_str(norm); 68 | if (fail || ngot != nexp) fail = true, 69 | cout << tc << "\n\tgot: \"" << got 70 | << "\" result: \"" << ngot << "\"\n"; 71 | return !fail; 72 | } 73 | 74 | #define CASES(name, cases) TEST_CASE(name) { \ 75 | for (const auto& tc : cases) { \ 76 | bool result = test(tc); \ 77 | CHECK( result ); \ 78 | if (!result) break; \ 79 | } \ 80 | } 81 | 82 | TEST_SUITE("quantifiers") { 83 | CASES("ex", ex_cases); 84 | CASES("all", all_cases); 85 | CASES("ex all", ex_all_cases); 86 | CASES("all ex", all_ex_cases); 87 | } 88 | -------------------------------------------------------------------------------- /tests/integration/test_integration-ref_types.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | // #include "init_log.h" 6 | 7 | #include "doctest.h" 8 | 9 | #include "test_integration_helpers.h" 10 | #include "../unit/test_helpers.h" 11 | 12 | using namespace idni::rewriter; 13 | using namespace idni::tau_lang; 14 | 15 | namespace testing = doctest; 16 | 17 | bool test_ref_types(const char* rec_relation, 18 | const std::string& expected_error = "", bool expect_fail = false) 19 | { 20 | // boost::log::core::get()->set_filter( 21 | // boost::log::trivial::severity >= boost::log::trivial::trace); 22 | 23 | auto source = make_tau_source(rec_relation, { .start = tau_parser::rr }); 24 | auto code = make_tau_code(source); 25 | factory_binder fb; 26 | auto binded = bind_tau_code_using_binder< 27 | factory_binder, sbf_ba>(code, fb); 28 | if (!binded) return false; 29 | 30 | // auto nt = binded | non_terminal_extractor 31 | // | optional_value_extractor; 32 | // std::cerr << "nt: " << tau_parser::instance().name(nt) << "\n"; 33 | 34 | auto main = binded | tau_parser::main 35 | | tau_parser::wff | optional_value_extractor>; 36 | auto nso_rr = rr>{ make_rec_relations(binded), main }; 37 | 38 | rr_types ts(nso_rr); 39 | auto nso_rr_opt = infer_ref_types(nso_rr, ts); 40 | bool fail = !ts.ok(); 41 | 42 | if (!expect_fail) expect_fail = expected_error != ""; 43 | // std::cerr << "fail: " << fail << " expect_fail: " << expect_fail << "\n"; 44 | if (fail) { // type checking or inference error 45 | if (expected_error == "Unknown") { 46 | if (ts.unresolved().size()) { 47 | // std::cerr << "Unresolved not empty\n"; 48 | return expect_fail; 49 | } else { 50 | // std::cerr << "Unresolved empty\n"; 51 | return false; 52 | } 53 | } 54 | for (auto& e : ts.errors()) 55 | if (e.find(expected_error) != std::string::npos) 56 | return expect_fail; 57 | return false; 58 | } else { 59 | auto normalized = normalizer(nso_rr_opt.value()); 60 | if (normalized == nullptr) { 61 | // std::cerr << "normalizer failed\n"; 62 | return expect_fail; 63 | } else if (!(normalized | tau_parser::wff_t).has_value()) { 64 | // std::cerr << "not T " << expect_fail << "\n"; 65 | return expect_fail; 66 | } 67 | } 68 | return !expect_fail; 69 | } 70 | 71 | TEST_SUITE("Boolean function recurrence relation fixed point calculation") { 72 | 73 | TEST_CASE("arities make different signature") { CHECK( test_ref_types( 74 | "f[0](x) := T." 75 | "f[0](x, y) := 1." 76 | "g[0](x) := F." 77 | "g[0, 0](x) := 0." 78 | "f[0](x) && !g[0](x) && f[0](x, y) != g[0, 0](x)." 79 | ) ); } 80 | 81 | TEST_CASE("fp call over inferred refs (loop)") { CHECK( test_ref_types( 82 | "w[0](x, y) := T." 83 | "q[0](x, y) := w[0](x, y)." 84 | "q[n](x, y) := !q[n-1](x, y)." 85 | "!q(0, 0)." 86 | ) ); } 87 | 88 | TEST_CASE("fp call over inferred refs, incl. bf") { CHECK( test_ref_types( 89 | "f[0](x) := x." 90 | "f[n](x) := f[n-1](x)'." 91 | "f[0](x, y) := T." 92 | "f[n](x, y) := f[n-1](x, y) && f[n-1](x) = 1." 93 | "f(1, 0)." 94 | ) ); } 95 | 96 | TEST_CASE("type mismatch 1") { CHECK( test_ref_types( 97 | "e[0, 0](x) := 1." 98 | "e[1, 0](x) := T." 99 | "F.", "Type mismatch" 100 | ) ); } 101 | 102 | TEST_CASE("type mismatch 2") { CHECK( test_ref_types( 103 | "f[0](x, y) := 1." 104 | "f[1](x, y) := T." 105 | "F.", "Type mismatch" 106 | ) ); } 107 | 108 | TEST_CASE("unsupported multiindex offset arity fp call") { CHECK( test_ref_types( 109 | "g[0, 0](x) := T." 110 | "g[m, n](x) := !g[m-1, n-1](x)." 111 | "g(0).", "", true 112 | ) ); } 113 | 114 | TEST_CASE("typo undetected") { CHECK( test_ref_types( 115 | "f[0](x, y) := T." 116 | "f[n](x) := f[n-1](x, y)." 117 | "f[1](0, 0).", "", true 118 | ) ); } 119 | 120 | TEST_CASE("typo unresolved 1") { CHECK( test_ref_types( 121 | "f[0](x) := T." 122 | "f[n](x) := f[n-1](x, 0)." 123 | "f[1](0).", "Unknown" 124 | ) ); } 125 | 126 | TEST_CASE("typo unresolved 2") { CHECK( test_ref_types( 127 | "f[0](x) := T." 128 | "f[n](x) := f[m, n-1](x)." 129 | "f[1](0).", "Unknown" 130 | ) ); } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /tests/integration/test_integration-satisfiability.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "boolean_algebras/sbf_ba.h" 7 | #include "satisfiability.h" 8 | 9 | // TODO (LOW) consider move this test to integration tests 10 | #include "../integration/test_integration_helpers.h" 11 | 12 | #define base_bas tau_ba, sbf_ba 13 | 14 | using namespace idni::rewriter; 15 | using namespace idni::tau_lang; 16 | 17 | namespace testing = doctest; 18 | 19 | using namespace idni::rewriter; 20 | using namespace idni::tau_lang; 21 | using namespace std; 22 | 23 | namespace testing = doctest; 24 | 25 | template 26 | tau create_spec(const char* spec) { 27 | auto sample_src = make_tau_source(spec); 28 | return make_nso_rr_using_factory, sbf_ba>( 29 | sample_src).value().main; 30 | } 31 | 32 | TEST_SUITE("Alignments") { 33 | TEST_CASE("equal_lookback_one_st") { 34 | bdd_init(); 35 | auto spec = create_spec("(always o1[t-1] = 0) && (sometimes o1[t] = 1 && o1[t-1] = 0)."); 36 | CHECK(!is_tau_formula_sat(spec)); 37 | } 38 | TEST_CASE("smaller_lookback_one_st") { 39 | bdd_init(); 40 | auto spec = create_spec("(always o1[t] = o1[t-1] && o1[t-1] = 1) && (sometimes o2[t] = 0)."); 41 | CHECK(is_tau_formula_sat(spec)); 42 | } 43 | TEST_CASE("greater_lookback_one_st") { 44 | bdd_init(); 45 | auto spec = create_spec("(always o1[t] = o1[t-1]) && (sometimes o1[t] != o1[t-2])."); 46 | CHECK(!is_tau_formula_sat(spec)); 47 | } 48 | TEST_CASE("equal_lookback_two_st") { 49 | bdd_init(); 50 | auto spec = create_spec("(always o1[t] = 0) && (sometimes o1[t] = 0) && (sometimes o1[t] = 1)."); 51 | CHECK(transform_to_execution(spec) == _F); 52 | } 53 | TEST_CASE("greater_lookback_two_st_1") { 54 | bdd_init(); 55 | auto spec = create_spec("(always o1[t] = 1 && o2[t] = 1) && (sometimes o1[t-1] = 1) && (sometimes o2[t-2] = 0)."); 56 | CHECK(!is_tau_formula_sat(spec)); 57 | } 58 | TEST_CASE("greater_lookback_two_st_2") { 59 | bdd_init(); 60 | auto spec = create_spec("(always o1[t] = 1 && o2[t] = 1) && (sometimes o1[t-1] = 0) && (sometimes o2[t-2] = 1)."); 61 | CHECK(!is_tau_formula_sat(spec)); 62 | } 63 | TEST_CASE("smaller_lookback_two_st_1") { 64 | bdd_init(); 65 | auto spec = create_spec("(always o1[t-2] = 0 && o2[t-2] = 0) && (sometimes o1[t] = 1) && (sometimes o1[t-1] = 0)."); 66 | CHECK(!is_tau_formula_sat(spec)); 67 | } 68 | TEST_CASE("smaller_lookback_two_st_2") { 69 | bdd_init(); 70 | auto spec = create_spec("(always o1[t-2] = 0 && o2[t-2] = 0) && (sometimes o1[t] = 0) && (sometimes o1[t-1] = 1)."); 71 | CHECK(!is_tau_formula_sat(spec)); 72 | } 73 | #ifndef DEBUG 74 | TEST_CASE("mixed_lookback_two_st_1") { 75 | bdd_init(); 76 | auto spec = create_spec("(always o1[t-2] = 1) && (sometimes o1[t-3] = 0) && (sometimes o1[t] = 1)."); 77 | CHECK(!is_tau_formula_sat(spec)); 78 | } 79 | 80 | TEST_CASE("mixed_lookback_two_st_2") { 81 | bdd_init(); 82 | auto spec = create_spec("(always o1[t-2] = 1) && (sometimes o1[t-3] = 1) && (sometimes o1[t] = 0)."); 83 | CHECK(!is_tau_formula_sat(spec)); 84 | } 85 | #endif 86 | } 87 | 88 | TEST_SUITE("Mixed") { 89 | TEST_CASE("this_stream_is_input_stream") { 90 | bdd_init(); 91 | auto spec = create_spec("this[t] < 1."); 92 | CHECK(!is_tau_formula_sat(spec)); 93 | } 94 | } -------------------------------------------------------------------------------- /tests/integration/test_integration-sbf2.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include 17 | 18 | #include "doctest.h" 19 | 20 | #include "test_integration_helpers.h" 21 | 22 | using namespace idni::rewriter; 23 | using namespace idni::tau_lang; 24 | 25 | namespace testing = doctest; 26 | 27 | // TODO (LOW) simplify this test cases extracting common logic to the helpers file 28 | 29 | TEST_SUITE("formulas: no variables, no bindings and no quantifiers") { 30 | 31 | TEST_CASE("i1[t] = o1[t]") { 32 | const char* sample = "( i1[t] = o1[t] )."; 33 | auto sample_src = make_tau_source(sample); 34 | auto sample_formula = make_nso_rr_using_factory( 35 | sample_src); 36 | CHECK( sample_formula.has_value() ); 37 | if (!sample_formula.has_value()) return; 38 | auto result = normalizer(sample_formula.value()); 39 | auto check1 = result | tau_parser::wff_f; 40 | auto check2 = result | tau_parser::wff_t; 41 | CHECK( !check1.has_value() ); 42 | CHECK( !check2.has_value() ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/integration/test_integration-splitter2.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "doctest.h" 23 | 24 | #include "test_integration_helpers.h" 25 | 26 | using namespace std; 27 | using namespace idni::rewriter; 28 | using namespace idni::tau_lang; 29 | using namespace boost::log; 30 | 31 | namespace testing = doctest; 32 | 33 | TEST_SUITE("configuration") { 34 | 35 | 36 | TEST_CASE("logging") { 37 | core::get()->set_filter(trivial::severity >= trivial::trace); 38 | add_console_log(std::cout, keywords::format = 39 | expressions::stream << expressions::smessage); 40 | } 41 | 42 | TEST_CASE("bdd initialization") { 43 | bdd_init(); 44 | } 45 | } 46 | 47 | TEST_SUITE("Tau_splitter_tau_coeff") { 48 | 49 | TEST_CASE("Tau_splitter_tau_coeff1") { 50 | const char *src = "{o1[t]o2[t] = 0.} v != 0."; 51 | auto fm = make_nso_rr_using_factory, sbf_ba>(src).value().main; 52 | auto s = tau_splitter(fm, splitter_type::upper); 53 | stringstream ss; ss << s; 54 | 55 | #ifdef DEBUG 56 | std::cout << ss.str() << "\n"; 57 | #endif 58 | 59 | CHECK(ss.str() == "{ o1[t]o2[t] = 0 } : tau ({ o1[t]o2[t] = 0 } : tau v)' = 0"); 60 | } 61 | 62 | TEST_CASE("Tau_splitter_tau_coeff2") { 63 | const char *src = "{o1[t]|o2[t] = 0.}&v = 0."; 64 | auto fm = make_nso_rr_using_factory, sbf_ba>(src).value().main; 65 | auto s = tau_splitter(fm, splitter_type::upper); 66 | stringstream ss; ss << s; 67 | 68 | #ifdef DEBUG 69 | std::cout << ss.str() << "\n"; 70 | #endif 71 | 72 | CHECK((ss.str() == "{ o1[t]|o2[t] = 0 } : tau v = 0 && v{ !(always o1[t] = 0 && o2[t] = 0) } : tau = 0" 73 | || ss.str() == "{ o1[t]|o2[t] = 0 } : tau v = 0 && v{ !(always o2[t] = 0 && o1[t] = 0) } = 0" 74 | || ss.str() == "{ o1[t]|o2[t] = 0 } v = 0 && v{ !(always o1[t] = 0 && o2[t] = 0) } : tau = 0" 75 | || ss.str() == "{ o1[t]|o2[t] = 0 } v = 0 && v{ !(always o1[t] = 0 && o2[t] = 0) } = 0")); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/integration/test_integration-tau1.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include 17 | 18 | #include "doctest.h" 19 | #include "satisfiability.h" 20 | 21 | #include "test_integration_helpers-tau.h" 22 | 23 | using namespace idni::rewriter; 24 | using namespace idni::tau_lang; 25 | 26 | namespace testing = doctest; 27 | 28 | TEST_SUITE("simple tau formulas: no variables") { 29 | 30 | TEST_CASE("{T}") { 31 | const char* sample = "{T};"; 32 | auto sample_src = make_tau_source(sample); 33 | sbf_ba_factory btf; 34 | tau_factory tf(btf); 35 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 36 | CHECK( is_tau_spec_satisfiable(sample_formula) ); 37 | } 38 | 39 | TEST_CASE("{F}") { 40 | const char* sample = "{F};"; 41 | auto sample_src = make_tau_source(sample); 42 | sbf_ba_factory btf; 43 | tau_factory tf(btf); 44 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 45 | CHECK( !is_tau_spec_satisfiable(sample_formula) ); 46 | } 47 | 48 | TEST_CASE("{T} &&& {T}") { 49 | const char* sample = "{T} &&& {T};"; 50 | auto sample_src = make_tau_source(sample); 51 | sbf_ba_factory btf; 52 | tau_factory tf(btf); 53 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 54 | CHECK( is_tau_spec_satisfiable(sample_formula) ); 55 | } 56 | 57 | TEST_CASE("{F} &&& {F}") { 58 | const char* sample = "{F} &&& {F};"; 59 | auto sample_src = make_tau_source(sample); 60 | sbf_ba_factory btf; 61 | tau_factory tf(btf); 62 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 63 | CHECK( !is_tau_spec_satisfiable(sample_formula) ); 64 | } 65 | 66 | TEST_CASE("{T} &&& {F}") { 67 | const char* sample = "{T} &&& {F};"; 68 | auto sample_src = make_tau_source(sample); 69 | sbf_ba_factory btf; 70 | tau_factory tf(btf); 71 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 72 | CHECK( !is_tau_spec_satisfiable(sample_formula) ); 73 | } 74 | 75 | TEST_CASE("{F} &&& {T}") { 76 | const char* sample = "{F} &&& {T};"; 77 | auto sample_src = make_tau_source(sample); 78 | sbf_ba_factory btf; 79 | tau_factory tf(btf); 80 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 81 | CHECK( !is_tau_spec_satisfiable(sample_formula) ); 82 | } 83 | 84 | TEST_CASE("{T} ||| {T}") { 85 | const char* sample = "{T} ||| {T};"; 86 | auto sample_src = make_tau_source(sample); 87 | sbf_ba_factory btf; 88 | tau_factory tf(btf); 89 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 90 | CHECK( is_tau_spec_satisfiable(sample_formula) ); 91 | } 92 | 93 | TEST_CASE("{F} ||| {F}") { 94 | const char* sample = "{F} ||| {F};"; 95 | auto sample_src = make_tau_source(sample); 96 | sbf_ba_factory btf; 97 | tau_factory tf(btf); 98 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 99 | CHECK( !is_tau_spec_satisfiable(sample_formula) ); 100 | } 101 | 102 | TEST_CASE("{T} ||| {F}") { 103 | const char* sample = "{T} ||| {F};"; 104 | auto sample_src = make_tau_source(sample); 105 | sbf_ba_factory btf; 106 | tau_factory tf(btf); 107 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 108 | CHECK( is_tau_spec_satisfiable(sample_formula) ); 109 | } 110 | 111 | TEST_CASE("{F} ||| {T}") { 112 | const char* sample = "{F} ||| {T};"; 113 | auto sample_src = make_tau_source(sample); 114 | sbf_ba_factory btf; 115 | tau_factory tf(btf); 116 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 117 | CHECK( is_tau_spec_satisfiable(sample_formula) ); 118 | } 119 | 120 | TEST_CASE("- {F}") { 121 | const char* sample = "- {F};"; 122 | auto sample_src = make_tau_source(sample); 123 | sbf_ba_factory btf; 124 | tau_factory tf(btf); 125 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 126 | CHECK( is_tau_spec_satisfiable(sample_formula) ); 127 | } 128 | 129 | TEST_CASE("- {T}") { 130 | const char* sample = "- {T};"; 131 | auto sample_src = make_tau_source(sample); 132 | sbf_ba_factory btf; 133 | tau_factory tf(btf); 134 | auto sample_formula = make_tau_spec_using_factory, sbf_ba>(sample_src, tf); 135 | CHECK( !is_tau_spec_satisfiable(sample_formula) ); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /tests/integration/test_integration-tau_ba3.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include 17 | 18 | #include "doctest.h" 19 | 20 | #include "test_integration_helpers.h" 21 | 22 | using namespace idni::rewriter; 23 | using namespace idni::tau_lang; 24 | 25 | namespace testing = doctest; 26 | 27 | TEST_SUITE("cpp operators") { 28 | 29 | TEST_CASE("Ohad's example: ex X ( { ex X ( X = {ex Y (Y = 0).}). } = 0).") { 30 | const char* sample = "ex X ( { ex X ( X = { ( ex Y Y = 0).}). } = 0)."; 31 | auto normalized = normalize_test_tau(sample); 32 | auto check = normalized | tau_parser::wff_f; 33 | CHECK( check.has_value() ); 34 | } 35 | } 36 | 37 | TEST_SUITE("allowing unresolved rr's in normalization") { 38 | 39 | TEST_CASE("f[0](x).") { 40 | const char* sample = "f[0](x)."; 41 | auto normalized = normalize_test_tau(sample); 42 | std::stringstream ss; ss << normalized; 43 | CHECK( ss.str() == "f[0](x)" ); 44 | } 45 | 46 | TEST_CASE("ex x f[0](x).") { 47 | const char* sample = "ex x f[0](x)."; 48 | auto normalized = normalize_test_tau(sample); 49 | std::stringstream ss; ss << normalized; 50 | CHECK( ss.str() == "ex x f[0](x)" ); 51 | } 52 | 53 | TEST_CASE("ex x f[0](x) && x = 0.") { 54 | const char* sample = "ex x f[0](x) && x = 0."; 55 | auto normalized = normalize_test_tau(sample); 56 | std::stringstream ss; ss << normalized; 57 | CHECK( ss.str() == "ex x f[0](x) && x = 0" ); 58 | } 59 | 60 | TEST_CASE("ex x f[0](x) && x != 0.") { 61 | const char* sample = "ex x f[0](x) && x != 0."; 62 | auto normalized = normalize_test_tau(sample); 63 | std::stringstream ss; ss << normalized; 64 | CHECK( ss.str() == "ex x f[0](x) && x != 0" ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/integration/test_integration_helpers.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __TEST_INTEGRATION_HELPERS_SBF_H__ 4 | #define __TEST_INTEGRATION_HELPERS_SBF_H__ 5 | 6 | #include "../src/boolean_algebras/sbf_ba.h" 7 | #include "../src/boolean_algebras/bool_ba.h" 8 | #include "../src/nso_rr.h" 9 | #include "../src/boolean_algebras/bdds/babdd.h" 10 | #include "../src/nso_rr.h" 11 | #include "../src/boolean_algebras/bdds/bdd_handle.h" 12 | #include "../src/normalizer.h" 13 | #include "dict.h" 14 | 15 | using namespace idni::rewriter; 16 | using namespace idni::tau_lang; 17 | 18 | rr> sbf_make_nso_rr(const std::string& src) { 19 | auto sample_src = make_tau_source(src); 20 | return make_nso_rr_using_factory(sample_src).value(); 21 | } 22 | 23 | tau sbf_make_nso(const std::string& src) { 24 | return sbf_make_nso_rr(src).main; 25 | } 26 | 27 | rr, sbf_ba>> tau_make_nso_rr_test(const std::string& src) { 28 | auto sample_src = make_tau_source(src); 29 | return make_nso_rr_using_factory, sbf_ba>(sample_src).value(); 30 | } 31 | 32 | tau, sbf_ba> tau_make_nso_test(const std::string& src) { 33 | return tau_make_nso_rr_test(src).main; 34 | } 35 | 36 | tau, sbf_ba> normalize_test_tau(const char* src) { 37 | rr, sbf_ba>> nso_rr = make_nso_rr_using_factory< 38 | tau_ba, sbf_ba>(src).value(); 39 | return normalizer, sbf_ba>(nso_rr); 40 | } 41 | 42 | std::ostream& print_tau(std::ostream &os, tau n, size_t l = 0) { 43 | os << "{"; 44 | // for (size_t t = 0; t < l; t++) os << " "; 45 | std::visit(overloaded{ 46 | [&os](tau_source_sym v) { if (v.nt()) os << v.n(); else os << v.t(); }, 47 | [&os](std::variant v) { 48 | if (auto b = std::get<0>(v); b == true) os << "true"; 49 | else if (auto b = std::get<0>(v); b == false) os << "false"; 50 | else os << "...sbf..."; } 51 | }, n->value); 52 | for (auto& d : n->child) print_tau(os, d, l + 1); 53 | os << "}"; 54 | return os; 55 | } 56 | 57 | std::ostream& pretty_print_tau(std::ostream &os, tau n, size_t l = 0) { 58 | // for (size_t t = 0; t < l; t++) os << " "; 59 | std::visit(overloaded{ 60 | [&os](tau_source_sym v) { if (!v.nt()) os << v.t(); }, 61 | [&os](std::variant v) { 62 | if (auto b = std::get<0>(v); b == true) os << "true"; 63 | else if (auto b = std::get<0>(v); b == false) os << "false"; 64 | else os << "...sbf..."; } 65 | }, n->value); 66 | for (auto& d : n->child) pretty_print_tau(os, d, l + 1); 67 | return os; 68 | } 69 | 70 | #endif // __TEST_INTEGRATION_HELPERS_SBF_H__ -------------------------------------------------------------------------------- /tests/repl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # REPL testing 3 | # 4 | set(TAU_BUILD_REPL_TESTS ON CACHE STRING "build the tau-lang repl suite ON") 5 | set_property(CACHE TAU_BUILD_REPL_TESTS PROPERTY STRINGS "OFF" "ON") 6 | 7 | function(add_repl_test test_name test_cmd test_regex) 8 | add_test(NAME "test_repl-${test_name}" 9 | COMMAND bash -c "echo \"${test_cmd}. q\" | $") 10 | set_tests_properties("test_repl-${test_name}" PROPERTIES 11 | PASS_REGULAR_EXPRESSION "${test_regex}") 12 | # add_test(NAME "test_repl-e-${test_name}" 13 | # COMMAND bash -c "$ -e \"${test_cmd}\"") 14 | # set_tests_properties("test_repl-e-${test_name}" PROPERTIES 15 | # PASS_REGULAR_EXPRESSION "${test_regex}") 16 | endfunction() 17 | 18 | if (TAU_BUILD_REPL_TESTS) 19 | enable_testing() 20 | add_subdirectory(commands) 21 | add_subdirectory(qelim) 22 | add_subdirectory(normalizer) 23 | add_subdirectory(satisfiability) 24 | add_subdirectory(interpreter) 25 | add_subdirectory(solver) 26 | add_subdirectory(normal_forms) 27 | add_subdirectory(substitution) 28 | add_subdirectory(instantiation) 29 | endif () 30 | -------------------------------------------------------------------------------- /tests/repl/commands/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we only test that the commands is executed, we don't check 4 | # if the results are the proper ones. 5 | 6 | include(test_repl-quit_cmd.cmake) 7 | include(test_repl-version_cmd.cmake) 8 | include(test_repl-get_cmd.cmake) 9 | include(test_repl-set_cmd.cmake) 10 | include(test_repl-toggle_cmd.cmake) 11 | include(test_repl-help_cmd.cmake) 12 | include(test_repl-history_cmd.cmake) 13 | include(test_repl-definition_cmd.cmake) 14 | include(test_repl-qelim_cmd.cmake) 15 | include(test_repl-normal_forms_cmd.cmake) 16 | include(test_repl-normalize_cmd.cmake) 17 | 18 | # TODO (HIGH) add tests for help definition,... 19 | # TODO (VERY_HIGH) add tests for normalize command 20 | # TODO (VERY_HIGH) add tests definition command 21 | # TODO (VERY_HIGH) add tests for sat/unsat/valid command 22 | # TODO (VERY_HIGH) add tests for solving command 23 | # TODO (VERY_HIGH) add tests for configuration commands 24 | # TODO (VERY_HIGH) add tests for examples command 25 | # TODO (VERY_HIGH) add tests for outputs command 26 | 27 | # sample for comparing output with a file 28 | #add_test(NAME test_name COMMAND bash -c "$ | diff - test_name.dump") -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-definition_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # definition command 3 | # 4 | 5 | # definition command wff_tule 6 | add_repl_test(def_wff_cmd "g(Y) := T" "\\[1\\] g") 7 | 8 | # definition command bf_rule 9 | add_repl_test(def_bf_cmd "g(Y) := 1" "\\[1\\] g") 10 | 11 | # definition command list 12 | # 13 | # no defs 14 | add_repl_test(def_list_cmd "defs" "definitions: empty") 15 | 16 | # with defs 17 | add_repl_test(def_list_cmd-with_defs "g(Y) := 1. defs" "\\[1\\] g") 18 | 19 | # definition command print 20 | # 21 | # no defs 22 | add_repl_test(def_print_cmd-empty "defs 1" "rec. relations: empty") 23 | 24 | # printing defs 25 | add_repl_test(def_print_cmd-1 "g(Y) := 1. defs 1" "\\[1\\] g") 26 | add_repl_test(def_print_cmd-2 "g(Y) := 1. f(Y) := T. defs 2" "\\[2\\] f") 27 | 28 | # not existing defs 29 | add_repl_test(def_print_cmd-0 "g(Y) := 1. defs 0" "\\(Error\\) definition \\[0\\] does not exist") 30 | add_repl_test(def_print_cmd-3 "g(Y) := 1. defs 3" "\\(Error\\) definition \\[3\\] does not exist") 31 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-get_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # get command 3 | # 4 | 5 | add_repl_test(get_cmd-all "get" "status:") 6 | add_repl_test(get_cmd-one "get colors" "colors:") 7 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-help_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # help command 3 | # 4 | 5 | # basic help command 6 | add_repl_test(help_cmd-full "help" "General") 7 | add_repl_test(help_cmd-shortened "h" "General") 8 | 9 | # help normalize command 10 | add_repl_test(help_normalize_command_cmd-full "help normalize" "the normalize command") 11 | add_repl_test(help_shortened_normalize_cmd "h normalize" "the normalize command") 12 | 13 | # help qelim command 14 | add_test(NAME test_repl-help_qelim_command_cmd-full 15 | COMMAND bash -c "echo 'help qelim. quit' | $") 16 | set_tests_properties(test_repl-help_qelim_command_cmd-full PROPERTIES 17 | PASS_REGULAR_EXPRESSION "the qelim command eliminates") 18 | add_test(NAME test_repl-help_shortened_qelim_cmd 19 | COMMAND bash -c "echo 'h qelim. q' | $") 20 | set_tests_properties(test_repl-help_shortened_qelim_cmd PROPERTIES 21 | PASS_REGULAR_EXPRESSION "the qelim command eliminates") 22 | 23 | # help normalize command with shortened command 24 | add_repl_test(help_normalize_cmd_shortened "help n" "the normalize command") 25 | add_repl_test(help_shortened_normalize_cmd-shortened "h n" "the normalize command") 26 | 27 | # help dnf 28 | add_repl_test(help_shortened-dnf_cmd "h dnf" "dnf converts") 29 | add_repl_test(help_dnf_cmd "help dnf" "dnf converts") 30 | 31 | # help cnf command 32 | add_repl_test(help_shortened-cnf_cmd "h cnf" "cnf converts") 33 | add_repl_test(help_cnf_cmd "help cnf" "cnf converts") 34 | 35 | # help nnf command 36 | add_repl_test(help_shortened-nnf_cmd "h nnf" "nnf converts") 37 | add_repl_test(help_nnf_cmd "help nnf" "nnf converts") 38 | 39 | # help mnf command 40 | add_repl_test(help_shortened-mnf_cmd "h mnf" "mnf converts") 41 | add_repl_test(help_mnf_cmd "help mnf" "mnf converts") 42 | 43 | # help onf command 44 | add_repl_test(help_shortened-onf_cmd "h onf" "onf converts") 45 | add_repl_test(help_onf_cmd "help onf" "onf converts") 46 | 47 | # help history command 48 | add_repl_test(help_shortened-history_cmd "h history" "the history") 49 | add_repl_test(help_history_cmd "help history" "the history") 50 | add_repl_test(help_shortened-history_shortened_m_cmd "h hist" "the history") 51 | add_repl_test(help-history_shortened_m_cmd "help hist" "the history") 52 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-history_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # history commands 3 | # 4 | 5 | # history list command 6 | add_repl_test(history_list_cmd-empty "history" "history is empty") 7 | add_repl_test(history_list_cmd-non_empty "1. history" ": 1") 8 | 9 | # history store command 10 | add_repl_test(history_store_cmd-bf "1" ": 1") 11 | add_repl_test(history_store_cmd-wff "T" ": T") 12 | add_repl_test(history_store_cmd-tau "{T.}" "1") 13 | 14 | add_repl_test(history_store_cmd-tau_fail "always o1[t]' = {x } i1[t]" "Syntax Error") 15 | add_repl_test(history_store_cmd-sbf_fail "always o1[t]' = {x = 0}:sbf i1[t]" "Syntax Error") 16 | 17 | # history print command 18 | add_repl_test(history_print_cmd-empty_absolute "history %1" "history is empty") 19 | add_repl_test(history_print_cmd-empty_relative "history %-1" "history is empty") 20 | add_repl_test(history_print_cmd-non_empty_absolute "1. history %1" ": 1") 21 | add_repl_test(history_print_cmd-non_empty_relative "1. history %" ": 1") 22 | add_repl_test(history_print_cmd-non_empty_last "1. T. history %-1" ": 1") 23 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-normal_forms_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # normal forms commands 3 | # 4 | 5 | # dnf command 6 | add_repl_test(normal_forms-dnf_wff "dnf T" ": T") 7 | add_repl_test(normal_forms-dnf_wff_mem_abs "T. dnf %0" "T") 8 | add_repl_test(normal_forms-dnf_wff_mem_rel "T. dnf %-0" "T") 9 | 10 | add_repl_test(normal_forms-dnf_bf "dnf 1" ": 1") 11 | add_repl_test(normal_forms-dnf_bf_mem_abs "1. dnf %0" "1") 12 | add_repl_test(normal_forms-dnf_bf_mem_rel "1. dnf %-0" "1") 13 | 14 | # cnf command 15 | add_repl_test(normal_forms-cnf_wff "cnf T" ": T") 16 | add_repl_test(normal_forms-cnf_wff_mem_abs "T. cnf %0" "T") 17 | add_repl_test(normal_forms-cnf_wff_mem_rel "T. cnf %-0" "T") 18 | 19 | add_repl_test(normal_forms-cnf_bf "cnf 1" ": 1") 20 | add_repl_test(normal_forms-cnf_bf_mem_abs "1. cnf %0" "1") 21 | add_repl_test(normal_forms-cnf_bf_mem_rel "1. cnf %-0" "1") 22 | 23 | # nnf command 24 | add_repl_test(normal_forms-nnf_wff "nnf T" ": T") 25 | add_repl_test(normal_forms-nnf_wff_mem_abs "T. nnf %0" "T") 26 | add_repl_test(normal_forms-nnf_wff_mem_rel "T. nnf %-0" "T") 27 | 28 | add_repl_test(normal_forms-nnf_bf "nnf 1" ": 1") 29 | add_repl_test(normal_forms-nnf_bf_mem_abs "1. nnf %0" "1") 30 | add_repl_test(normal_forms-nnf_bf_mem_rel "1. nnf %-0" "1") 31 | 32 | # mnf command 33 | # TODO (HIGH) fixme it's not working properly, returns Y & X |Y & X | Z & X 34 | add_repl_test(normal_forms-mnf_wff "mnf T" ": T") 35 | add_repl_test(normal_forms-mnf_wff_mem_abs "T. mnf %0" "T") 36 | add_repl_test(normal_forms-mnf_wff_mem_rel "T. mnf %-0" "T") 37 | 38 | add_repl_test(normal_forms-mnf_bf "mnf T" ": T") 39 | add_repl_test(normal_forms-mnf_bf_mem_abs "T. mnf %0" "T") 40 | add_repl_test(normal_forms-mnf_bf_mem_rel "T. mnf %-0" "T") 41 | 42 | # onf command(only wff) 43 | # TODO (HIGH) fixme it's not working properly, returns (X = 0) && (Y = 0 || Z = 0) again... 44 | #add_test(NAME test_repl-onf_wff_cmd 45 | # COMMAND bash -c "echo 'onf X (X = 0) && ((Y=0) || (Z=0)). q' | $") 46 | #set_tests_properties(test_repl-onf_wff_cmd PROPERTIES 47 | # PASS_REGULAR_EXPRESSION "onf command converts") 48 | 49 | # snf command 50 | add_repl_test(normal_forms-snf-wff "snf T" "T") 51 | add_repl_test(normal_forms-snf-wff_mem_abs "T. snf %0" "T") 52 | add_repl_test(normal_forms-snf-wff_mem_rel "T. snf %-0" "T") 53 | 54 | add_repl_test(normal_forms-snf-bf "snf 1" "1") 55 | add_repl_test(normal_forms-snf-bf_mem_abs "1. snf %0" "1") 56 | add_repl_test(normal_forms-snf-bf_mem_rel "1. snf %-0" "1") -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-normalize_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # normalize command 3 | # 4 | 5 | #test_repl-nnf_bf_cmd 6 | #add_repl_test(normalize_cmd "normalize X & (Y | Z). q" "X & Y | X & Z") 7 | 8 | # 'normalize' command for Boolean functions 9 | add_repl_test(normalize_cmd_bf "normalize 1" ": 1") 10 | add_repl_test(normalize_cmd_bf_mem_rel "1. normalize %-0" "1") 11 | add_repl_test(normalize_cmd_bf_mem_abs "1. normalize %0" "1") 12 | 13 | # 'n' command for normalization for Boolean functions 14 | add_repl_test(normalize_cmd_wff "normalize T" ": T") 15 | add_repl_test(normalize_cmd_wff_mem_rel "T. normalize %-0" "T") 16 | add_repl_test(normalize_cmd_wff_mem_abs "T. normalize %0" "T") 17 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-qelim_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # qelim command 3 | # 4 | 5 | add_repl_test(qelim_cmd-form "qelim T" ": T") 6 | add_repl_test(qelim_cmd-abs_mem "T. qelim %0" "T") 7 | add_repl_test(qelim_cmd-rel_mem "T. qelim %-0" "T") 8 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-quit_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # quit command 3 | # 4 | 5 | add_repl_test(quit_cmd-full "quit" "Quit.") 6 | add_repl_test(quit_cmd-shortened "q" "Quit.") 7 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-set_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # set command 3 | # 4 | 5 | add_repl_test(set_cmd-status "set status off" "off") 6 | add_repl_test(set_cmd-colors "set colors off" "off") 7 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-toggle_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # toggle command 3 | # 4 | 5 | add_repl_test(toggle_cmd-status "toggle status" "off") 6 | add_repl_test(toggle_cmd-colors "toggle colors" "off") 7 | -------------------------------------------------------------------------------- /tests/repl/commands/test_repl-version_cmd.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # version command 3 | # 4 | 5 | add_repl_test(version_cmd-full "version" "Tau Language Framework version") 6 | add_repl_test(version_cmd-shortened "v" "Tau Language Framework version") 7 | -------------------------------------------------------------------------------- /tests/repl/instantiation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the instantiation command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | # BF Instantiation 7 | 8 | add_repl_test(instantiation_cmd_bf1 "x. 1. i %[x / %1]" ": 1") 9 | 10 | add_repl_test(instantiation_cmd_bf2 "ax + bx'. y&z. i %1[x / %2]" ": \\(ayz\\)'b\\(yz\\)'|ayz\\(b\\(yz\\)'\\)") 11 | 12 | add_repl_test(instantiation_cmd_bf3 "(x | (w & z)) & z. b. i %1[ z / %2]" ": \\(x|wb\\)b") 13 | 14 | add_repl_test(instantiation_cmd_bf4 "x & y. T. i %1[x / %2]" "\\(Error\\) invalid argument") 15 | 16 | # WFF Instantiation 17 | 18 | add_repl_test(instantiation_cmd_wff1 "x=0. 1. i %-1[x/ %]" ": F") 19 | 20 | add_repl_test(instantiation_cmd_wff2 "a=0 && x=0^ b=0 && !x=0. y & z. i %1[x/ %2]" ": !\\(a = 0 && y & z = 0\\) && b = 0 && !y & z = 0 || !\\(b = 0 && !y & z = 0\\) && a = 0 && y & z = 0") 21 | 22 | add_repl_test(instantiation_cmd_wff3 "ex k h=0 && k=0. v & w. i %1[k / %2]" ": ex k h = 0 && k = 0") 23 | 24 | add_repl_test(instantiation_cmd_wff4 "ex x x=0 && y=0. x. i %1[y / %2]" ": ex x2 x2 = 0 && x = 0") 25 | 26 | add_repl_test(instantiation_cmd_wff5 "ex x x=0 && y=0. x. i %1[y / %2]" ": ex x2 x2 = 0 && x = 0") 27 | 28 | add_repl_test(instantiation_cmd_wff6 "(x=0|| (w=0 && z=0)) && z=0. b. i %1[z / %2]" ": \\(x = 0 || w = 0 && b = 0\\) && b = 0") 29 | 30 | add_repl_test(instantiation_cmd_wff7 "x=0&& y=0. x=0. i %1[x/ %2]" "argument has wrong type") 31 | 32 | add_repl_test(instantiation_cmd_wff8 "i (ex x x=0 && y=0) && x=0[y/x|a]" ": \\(ex x2 x2 = 0 && x|a = 0\\) && x = 0") 33 | 34 | add_repl_test(instantiation_cmd_wff9 "i ex x ex x x=0 && y=0 [y/x]" ": ex x2, x3 x3 = 0 && x = 0") 35 | 36 | add_repl_test(instantiation_cmd_wff10 "i (ex x x=0 && y=0) && x=0 [y/x]" ": \\(ex x2 x2 = 0 && x = 0\\) && x = 0") 37 | -------------------------------------------------------------------------------- /tests/repl/interpreter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the satisfiability command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | # 7 | # sample 8 | # 9 | 10 | #add_repl_test(test_name "test_command" "test_regexp") 11 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the normalized command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | #include(test_repl-onf.cmake) 7 | include(test_repl-dnf.cmake) 8 | include(test_repl-cnf.cmake) 9 | include(test_repl-nnf.cmake) 10 | include(test_repl-mnf.cmake) 11 | #include(test_repl-onf.cmake) 12 | include(test_repl-snf.cmake) 13 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/test_repl-cnf.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # order normal form (cnf) tests 3 | # 4 | 5 | # 6 | # wff 7 | # 8 | 9 | add_repl_test(normal_forms-cnf_wff_T "cnf T" ": T") 10 | add_repl_test(normal_forms-cnf_wff_F "cnf F" ": F") 11 | add_repl_test(normal_forms-cnf_wff_dist_right "cnf (X=0 || (Y=0 && Z=0))" ": \\(X = 0 \\|\\| Y = 0\\) && \\(X = 0 \\|\\| Z = 0\\)") 12 | add_repl_test(normal_forms-cnf_wff_dist_left "cnf ((X=0 && Y=0) || Z=0)" ": \\(X = 0 \\|\\| Z = 0\\) && \\(Z = 0 \\|\\| Y = 0\\)") 13 | 14 | # 15 | # bf 16 | # 17 | 18 | add_repl_test(normal_forms-cnf_bf_1 "cnf 1" ": 1") 19 | add_repl_test(normal_forms-cnf_bf_0 "cnf 0" ": 0") 20 | add_repl_test(normal_forms-cnf_bf_dist_right "cnf (X | (Y & Z))" ": \\(.\\|.\\)\\(.\\|.\\)|") 21 | add_repl_test(normal_forms-cnf_bf_dist_left "cnf ((X & Y) | Z)" ": \\(.\\|.\\)\\(.\\|.\\)") 22 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/test_repl-dnf.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # order normal form (dnf) tests 3 | # 4 | 5 | # 6 | # wff 7 | # 8 | 9 | add_repl_test(normal_forms-dnf_wff_T "dnf T" ": T") 10 | add_repl_test(normal_forms-dnf_wff_F "dnf F" ": F") 11 | add_repl_test(normal_forms-dnf_wff_dist_right "dnf (X=0 && (Y=0 || Z=0))" ": X = 0 && Y = 0 \\|\\| X = 0 && Z = 0") 12 | add_repl_test(normal_forms-dnf_wff_dist_left "dnf ((X=0 || Y=0) && Z=0)" ": X = 0 && Z = 0 \\|\\| Z = 0 && Y = 0") 13 | 14 | # 15 | # bf 16 | # 17 | 18 | add_repl_test(normal_forms-dnf_bf_1 "dnf 1" ": 1") 19 | add_repl_test(normal_forms-dnf_bf_0 "dnf 0" ": 0") 20 | add_repl_test(normal_forms-dnf_bf_dist_right "dnf (X & (Y | Z))" ": ..\\|..") 21 | add_repl_test(normal_forms-dnf_bf_dist_left "dnf ((X | Y) & Z)" ": ..\\|..") 22 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/test_repl-mnf.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # order normal form tests 3 | # 4 | 5 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/test_repl-nnf.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # order normal form tests 3 | # 4 | 5 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/test_repl-onf.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # order normal form tests 3 | # 4 | 5 | # TODO (HIGH) the results should be reviewed and checked for correctness 6 | add_repl_test(normal_forms-onf_T "onf X T" "T") 7 | add_repl_test(normal_forms-onf_F "onf X F" "F") 8 | add_repl_test(normal_forms-onf_X_eq_0 "onf X (X = 0)" "F") 9 | add_repl_test(normal_forms-onf_Y_eq_0 "onf X (Y = 0)" "Y") 10 | add_repl_test(normal_forms-onf_X_neq_0 "onf X (X != 0)" "F") 11 | add_repl_test(normal_forms-onf_Y_neq_0 "onf X (Y != 0)" "Y") 12 | -------------------------------------------------------------------------------- /tests/repl/normal_forms/test_repl-snf.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # order normal form tests 3 | # 4 | 5 | -------------------------------------------------------------------------------- /tests/repl/normalizer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the normalized command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | # 7 | # bf 8 | # 9 | 10 | add_repl_test(normalize_cmd_bf "n X & 1" ": X") 11 | add_repl_test(normalize_cmd_nso "n X & X' = 0" ": T") 12 | 13 | # 14 | # wff 15 | # 16 | 17 | add_repl_test(normalize_cmd_wff "n X & X' = 0" ": T") 18 | add_repl_test(normalize_cmd_memory "n X & X' = 0" ": T") 19 | -------------------------------------------------------------------------------- /tests/repl/qelim/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # qelim 3 | # 4 | 5 | add_repl_test(qelim_cmd-form_1 "qelim all x ex y x=y" ": T") 6 | -------------------------------------------------------------------------------- /tests/repl/satisfiability/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the satisfiability command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | # 7 | # sample 8 | # 9 | 10 | #add_repl_test(test_name "test_command" "test_regexp") 11 | -------------------------------------------------------------------------------- /tests/repl/solver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the execution command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | # 7 | # sample 8 | # 9 | 10 | #add_repl_test(test_name "test_command" "test_regexp") 11 | -------------------------------------------------------------------------------- /tests/repl/substitution/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | # In these tests cases we check the results obtained in the substitution command. 4 | # The output of the tests cases must be validated against expected results. 5 | 6 | # BF Substitution 7 | 8 | add_repl_test(substitution_cmd_bf1 "x. 1. s %[x / %1]" ": 1") 9 | 10 | add_repl_test(substitution_cmd_bf2 "ax + bx'. y&z. s %1[x / %2]" ": \\(ayz\\)'b\\(yz\\)'|ayz\\(b\\(yz\\)'\\)'") 11 | 12 | add_repl_test(substitution_cmd_bf5 "(x | (w & z)) & z. b. s %1[ z / %2]" ": \\(x|wb\\)b") 13 | 14 | add_repl_test(substitution_cmd_bf6 "x & y. T. s %1[x / %2]" "invalid argument") 15 | 16 | # WFF Substitution 17 | 18 | add_repl_test(substitution_cmd_wff1 "x=0. T. s %-1[x=0/ %]" ": T") 19 | 20 | add_repl_test(substitution_cmd_wff2 "a=0 && x=0 ^ b=0 && !x=0. y=0 && z=0. s %1[x=0 / %2]" ": !\\(a = 0 && y = 0 && z = 0\\) && b = 0 && !\\(y = 0 && z = 0\\) || !\\(b = 0 && !\\(y = 0 && z = 0\\)\\) && a = 0 && y = 0 && z = 0") 21 | 22 | add_repl_test(substitution_cmd_wff3 "ex k h=0 && k=0. v=0 && w=0. s %1[k=0 / %2]" ": ex k h = 0 && k = 0") 23 | 24 | add_repl_test(substitution_cmd_wff4 "ex x x=0 && y=0. x=0. s %1[y=0 / %2]" ": ex x2 x2 = 0 && x = 0") 25 | 26 | add_repl_test(substitution_cmd_wff6 "(x=0 || (w=0 && z=0)) && z=0. b=0. s %1[z=0 / %2]" ": \\(x=0 || w=0 && b=0\\) && b=0") 27 | 28 | add_repl_test(substitution_cmd_wff7 "x=0 && y=0. 0. s %1[x=0 / %2]" "argument has wrong type") 29 | 30 | add_repl_test(substitution_cmd_wff8 "s (ex x x=0 && y=0) && x=0 [y=0/x=0]" ": \\(ex x2 x2 = 0 && x = 0\\) && x = 0") 31 | 32 | add_repl_test(substitution_cmd_wff9 "s (ex x x=0 && y=0) && x=0 [y=0/x=0 || a=0]" ": \\(ex x2 x2 = 0 && \\(x=0 || a = 0\\)\\) && x=0") 33 | 34 | add_repl_test(substitution_cmd_wff10 "s (ex x x=0 && y=0 && all y y=0) && x=0 && y=0 [x=0 && y=0 / x=0 || a=0]" 35 | ": \\(ex x x=0 && y=0 && \\(all y y=0\\)\\) && \\(x=0 || a = 0\\)") 36 | 37 | add_repl_test(substitution_cmd_wff11 "s ex x ex x x=0 && y=0 [y=0/x=0]" ": ex x2, x3 x3 = 0 && x = 0") 38 | 39 | add_repl_test(substitution_cmd_wff12 "s (ex x x=0 && y=0) && x=0 [y/x]" ": \\(ex x2 x2 = 0 && x = 0\\) && x = 0") 40 | 41 | add_repl_test(substitution_cmd_wff13 "s (ex x x=0 && y=0) && x=0 [y/x=0]" "\\(Error\\) invalid argument") 42 | 43 | add_repl_test(substitution_cmd_wff14 "s (ex x x=0 && y=0) && x=0 [y=0/x]" "\\(Error\\) invalid argument") 44 | -------------------------------------------------------------------------------- /tests/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) 2 | 3 | set(TESTS 4 | product_ba 5 | bool 6 | hbdd 7 | rules-bf_execution 8 | rules-bf_parsing 9 | rules-wff_execution 10 | rules-wff_parsing 11 | builders 12 | rewriting 13 | nso_rr 14 | tau_parser 15 | normalizer 16 | type_system 17 | bindings 18 | sbf_ba_binding 19 | traversal 20 | tau 21 | variant_ba 22 | normal_forms 23 | make_node_hook 24 | interpreter 25 | ) 26 | 27 | foreach(X IN LISTS TESTS) 28 | set(N "test_${X}") 29 | add_executable(${N} "${N}.cpp") 30 | target_setup(${N}) 31 | target_link_libraries(${N} ${TAU_OBJECT_LIB_NAME} ${IDNI_PARSER_OBJECT_LIB} doctest) 32 | target_compile_options(${N} PUBLIC -Wno-unused-function) 33 | add_test(NAME ${N} COMMAND "${PROJECT_BINARY_DIR}/${N}") 34 | endforeach() 35 | -------------------------------------------------------------------------------- /tests/unit/test_bindings.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "defs.h" 7 | #include "nso_rr.h" 8 | #include "language.h" 9 | #include "boolean_algebras/bool_ba.h" 10 | #include "test_helpers.h" 11 | 12 | using namespace idni::rewriter; 13 | using namespace idni::tau_lang; 14 | using namespace std; 15 | 16 | namespace testing = doctest; 17 | 18 | TEST_SUITE("named bindings") { 19 | 20 | TEST_CASE("binding: given one statement with no bindigns, the binding process returns the same statement.") { 21 | const char* sample = "$X := $X."; 22 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 23 | auto statement = make_statement(src); 24 | bindings bs; bs["binding"] = { Bool(true) }; 25 | auto binded = make_named_bindings(statement, bs); 26 | CHECK( binded == statement ); 27 | } 28 | 29 | TEST_CASE("binding: given one statement with one binding, the binding process returns the statement with the binding replaced.") { 30 | const char* sample = "{ binding } := { binding }."; 31 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 32 | auto statement = make_statement(src); 33 | bindings bs; bs["binding"] = { Bool(true) }; 34 | auto binded = make_named_bindings(statement, bs); 35 | CHECK( binded != statement ); 36 | } 37 | 38 | TEST_CASE("binding: given one statement with one non-matching binding, the binding process returns the original statement.") { 39 | const char* sample = "{ nonmatching } := { nonmatching }."; 40 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 41 | auto statement = make_statement(src); 42 | bindings bs; bs["binding"] = { Bool(true) }; 43 | auto binded = make_named_bindings(statement, bs); 44 | CHECK( binded == nullptr ); 45 | } 46 | } 47 | 48 | TEST_SUITE("factory bindings") { 49 | 50 | TEST_CASE("binding: given one statement with no bindigns, the binding process returns the same statement.") { 51 | const char* sample = "$X := $X."; 52 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 53 | auto statement = make_statement(src); 54 | auto binded = make_factory_bindings(statement); 55 | CHECK( binded == statement ); 56 | } 57 | 58 | TEST_CASE("binding: given one statement with one binding, the binding process returns the statement with the binding replaced.") { 59 | const char* sample = "{ binding } := { some_source_sode } : bool."; 60 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 61 | auto statement = make_statement(src); 62 | auto binded = make_factory_bindings(statement); 63 | CHECK( binded != statement ); 64 | } 65 | 66 | TEST_CASE("binding: given one statement with one non-matching binding, the binding process returns the original statement.") { 67 | const char* sample = "{ nonmatching } := { some_source_code } : nonbool."; 68 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 69 | auto statement = make_statement(src); 70 | auto binded = make_factory_bindings(statement); 71 | CHECK( binded == statement ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/unit/test_bool.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include "doctest.h" 17 | #include "boolean_algebras/bool_ba.h" 18 | 19 | namespace testing = doctest; 20 | 21 | TEST_SUITE("bool boolean algebra") { 22 | 23 | TEST_CASE("Bool == bool") { 24 | CHECK( Bool(true) == true ); 25 | CHECK( Bool(false) == false ); 26 | CHECK( Bool(true) != false ); 27 | CHECK( Bool(false) != true ); 28 | } 29 | 30 | TEST_CASE("operator&") { 31 | CHECK( (Bool(true) & Bool(true)) == true ); 32 | CHECK( (Bool(true) & Bool(false)) == false ); 33 | CHECK( (Bool(false) & Bool(true)) == false ); 34 | CHECK( (Bool(false) & Bool(false)) == false ); 35 | } 36 | 37 | TEST_CASE("operator|") { 38 | CHECK( (Bool(true) | Bool(true)) == true ); 39 | CHECK( (Bool(true) | Bool(false)) == true ); 40 | CHECK( (Bool(false) | Bool(true)) == true ); 41 | CHECK( (Bool(false) | Bool(false)) == false ); 42 | } 43 | 44 | TEST_CASE("operator^") { 45 | CHECK( (Bool(true) ^ Bool(true)) == false ); 46 | CHECK( (Bool(true) ^ Bool(false)) == true ); 47 | CHECK( (Bool(false) ^ Bool(true)) == true ); 48 | CHECK( (Bool(false) ^ Bool(false)) == false ); 49 | } 50 | 51 | TEST_CASE("operator+") { 52 | CHECK( (Bool(true) + Bool(true)) == false ); 53 | CHECK( (Bool(true) + Bool(false)) == true ); 54 | CHECK( (Bool(false) + Bool(true)) == true ); 55 | CHECK( (Bool(false) + Bool(false)) == false ); 56 | } 57 | 58 | TEST_CASE("operator~") { 59 | CHECK( (~Bool(true)) == Bool(false) ); 60 | CHECK( (~Bool(false)) == Bool(true) ); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/unit/test_builders.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "nso_rr.h" 7 | #include "boolean_algebras/bool_ba.h" 8 | #include "boolean_algebras/bdds/bdd_handle.h" 9 | #include "normalizer.h" 10 | #include "test_helpers.h" 11 | 12 | #include "debug_helpers.h" 13 | 14 | using namespace idni::rewriter; 15 | using namespace idni::tau_lang; 16 | 17 | namespace testing = doctest; 18 | 19 | // TODO (MEDIUM) split into test_builder-parsing and test_builder-execution 20 | 21 | TEST_SUITE("builders parsing") { 22 | 23 | TEST_CASE("BLDR_WFF_EQ") { 24 | auto bldr = make_builder(BLDR_WFF_EQ); 25 | CHECK( is_non_terminal(bldr.first) ); 26 | CHECK( is_non_terminal(bldr.second) ); 27 | } 28 | 29 | TEST_CASE("BLDR_WFF_NEQ") { 30 | auto bldr = make_builder(BLDR_WFF_NEQ); 31 | CHECK( is_non_terminal(bldr.first) ); 32 | CHECK( is_non_terminal(bldr.second) ); 33 | } 34 | 35 | TEST_CASE("BLDR_WFF_ALL") { 36 | auto bldr = make_builder(BLDR_WFF_ALL); 37 | CHECK( is_non_terminal(bldr.first) ); 38 | CHECK( is_non_terminal(bldr.second) ); 39 | } 40 | 41 | TEST_CASE("BLDR_WFF_EX") { 42 | auto bldr = make_builder(BLDR_WFF_EX); 43 | CHECK( is_non_terminal(bldr.first) ); 44 | CHECK( is_non_terminal(bldr.second) ); 45 | } 46 | 47 | TEST_CASE("BLDR_BF_SPLITTER") { 48 | auto bldr = make_builder(BLDR_BF_SPLITTER); 49 | CHECK( is_non_terminal(bldr.first) ); 50 | CHECK( is_non_terminal(bldr.second) ); 51 | } 52 | 53 | TEST_CASE("BLDR_BF_NOT_LESS_EQUAL") { 54 | auto bldr = make_builder(BLDR_BF_NOT_LESS_EQUAL); 55 | CHECK( is_non_terminal(bldr.first) ); 56 | CHECK( is_non_terminal(bldr.second) ); 57 | } 58 | } 59 | 60 | // TODO (HIGH) check builded structures deeply in execution tests 61 | 62 | TEST_SUITE("builders execution") { 63 | 64 | const char* sample = " X = 0 ."; 65 | auto src = make_tau_source(sample); 66 | auto frml = make_statement(src); 67 | auto bfs = frml 68 | | tau_parser::rr | tau_parser::main | tau_parser::wff 69 | | tau_parser::bf_eq || tau_parser::bf; 70 | auto X = bfs[0] | tau_parser::variable 71 | | optional_value_extractor>; 72 | auto F = bfs[1] | tau_parser::bf_f 73 | | optional_value_extractor>; 74 | 75 | TEST_CASE("BLDR_WFF_EQ") { 76 | auto bldr = make_builder(BLDR_WFF_EQ); 77 | std::vector> args = {X}; 78 | auto check = tau_apply_builder(bldr, args) | tau_parser::bf_eq; 79 | CHECK( check.has_value() ); 80 | } 81 | 82 | TEST_CASE("BLDR_WFF_NEQ") { 83 | auto bldr = make_builder(BLDR_WFF_NEQ); 84 | std::vector> args = {X}; 85 | auto check = tau_apply_builder(bldr, args) | tau_parser::bf_neq; 86 | CHECK( check.has_value() ); 87 | } 88 | 89 | TEST_CASE("BLDR_WFF_XOR") { 90 | // TODO (LOW) write proper test 91 | CHECK( true ); 92 | } 93 | 94 | TEST_CASE("BLDR_WFF_IMPLY") { 95 | // TODO (LOW) write proper test 96 | CHECK( true ); 97 | } 98 | 99 | TEST_CASE("BLDR_WFF_EQUIV") { 100 | // TODO (LOW) write proper test 101 | CHECK( true ); 102 | } 103 | 104 | TEST_CASE("BLDR_WFF_ALL") { 105 | auto bldr = make_builder(BLDR_WFF_ALL); 106 | std::vector> args = {X, F}; 107 | auto check = tau_apply_builder(bldr, args) | tau_parser::wff_all; 108 | CHECK( check.has_value() ); 109 | } 110 | 111 | TEST_CASE("BLDR_WFF_EX") { 112 | auto bldr = make_builder(BLDR_WFF_EX); 113 | std::vector> args = {X, F}; 114 | auto check = tau_apply_builder(bldr, args) | tau_parser::wff_ex; 115 | CHECK( check.has_value() ); 116 | } 117 | 118 | TEST_CASE("BLDR_BF_SPLITTER") { 119 | auto bldr = make_builder(BLDR_BF_SPLITTER); 120 | std::vector> args = {F}; 121 | auto check = tau_apply_builder(bldr, args) | tau_parser::bf_splitter; 122 | CHECK( check.has_value() ); 123 | } 124 | 125 | TEST_CASE("BLDR_BF_LESS") { 126 | // TODO (LOW) write proper test 127 | CHECK( true ); 128 | } 129 | 130 | TEST_CASE("BLDR_BF_LESS_EQUAL") { 131 | // TODO (LOW) write proper test 132 | CHECK( true ); 133 | } 134 | 135 | // TODO (HIGH) implement update this tests to cover upper and lower bounds 136 | /*TEST_CASE("BLDR_BF_NOT_LESS_EQUAL") { 137 | auto bldr = make_builder(BLDR_BF_NOT_LESS_EQUAL); 138 | std::vector> args = {F, F}; 139 | auto check = tau_apply_builder(bldr, args) | tau_parser::bf_not_less_equal; 140 | CHECK( check.has_value() ); 141 | }*/ 142 | 143 | TEST_CASE("BLDR_BF_GREATER") { 144 | // TODO (LOW) write proper test 145 | CHECK( true ); 146 | } 147 | } -------------------------------------------------------------------------------- /tests/unit/test_hbdd.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include "doctest.h" 17 | #include "boolean_algebras/bool_ba.h" 18 | #include "boolean_algebras/bdds/bdd_handle.h" 19 | 20 | namespace testing = doctest; 21 | 22 | TEST_SUITE("operator==") { 23 | 24 | TEST_CASE("hbdd == bool") { 25 | CHECK( get_one() == true ); 26 | CHECK( get_zero() == false ); 27 | CHECK( get_one() != false ); 28 | CHECK( get_zero() != true ); 29 | } 30 | } 31 | 32 | TEST_SUITE("operator&") { 33 | 34 | TEST_CASE("hbdd & hbdd") { 35 | CHECK( (get_one() & get_one()) == true ); 36 | CHECK( (get_one() & get_zero()) == false ); 37 | CHECK( (get_zero() & get_one()) == false ); 38 | CHECK( (get_zero() & get_zero()) == false ); 39 | } 40 | } 41 | 42 | TEST_SUITE("operator|") { 43 | 44 | TEST_CASE("hbdd | hbdd") { 45 | CHECK( (get_one() | get_one()) == true ); 46 | CHECK( (get_one() | get_zero()) == true ); 47 | CHECK( (get_zero() | get_one()) == true ); 48 | CHECK( (get_zero() | get_zero()) == false ); 49 | } 50 | } 51 | 52 | TEST_SUITE("operator^") { 53 | 54 | TEST_CASE("hbdd ^ hbdd") { 55 | CHECK( (get_one() ^ get_one()) == false ); 56 | CHECK( (get_one() ^ get_zero()) == true ); 57 | CHECK( (get_zero() ^ get_one()) == true ); 58 | CHECK( (get_zero() ^ get_zero()) == false ); 59 | } 60 | } 61 | 62 | TEST_SUITE("operator+") { 63 | 64 | TEST_CASE("hbdd + hbdd") { 65 | CHECK( (get_one() + get_one()) == false ); 66 | CHECK( (get_one() + get_zero()) == true ); 67 | CHECK( (get_zero() + get_one()) == true ); 68 | CHECK( (get_zero() + get_zero()) == false ); 69 | } 70 | } 71 | 72 | TEST_SUITE("operator~") { 73 | 74 | TEST_CASE("hbdd ~") { 75 | CHECK( (~get_one()) == get_zero() ); 76 | CHECK( (~get_zero()) == get_one() ); 77 | } 78 | } 79 | 80 | TEST_SUITE("BDD_Splitter") { 81 | TEST_CASE("DNF_clause_deletion1") { 82 | bdd_init(); 83 | auto a1 = bdd_handle::bit(true, 1); 84 | auto a2 = bdd_handle::bit(true, 2); 85 | auto a3 = bdd_handle::bit(true, 3); 86 | 87 | auto d1 = a1 | a2 | a3; 88 | CHECK(splitter(d1, splitter_type::upper) == (a1 | a2)); 89 | } 90 | 91 | TEST_CASE("DNF_clause_deletion2") { 92 | bdd_init(); 93 | auto a1 = bdd_handle::bit(false, 1); 94 | auto a2 = bdd_handle::bit(false, 2); 95 | auto a3 = bdd_handle::bit(false, 3); 96 | 97 | auto d1 = a1 | a2 | a3; 98 | CHECK(splitter(d1, splitter_type::upper) == (a1 | a2)); 99 | } 100 | 101 | TEST_CASE("single_DNF_clause") { 102 | bdd_init(); 103 | auto a1 = bdd_handle::bit(true, 1); 104 | auto a2 = bdd_handle::bit(true, 2); 105 | auto a3 = bdd_handle::bit(true, 3); 106 | auto a4 = bdd_handle::bit(true, 4); 107 | 108 | auto d1 = a1 & a2 & a3; 109 | CHECK(splitter(d1, splitter_type::upper) == (d1 & a4)); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /tests/unit/test_helpers.h: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #ifndef __TEST_HELPERS_H__ 4 | #define __TEST_HELPERS_H__ 5 | 6 | #include "nso_rr.h" 7 | #include "language.h" 8 | 9 | using namespace idni::rewriter; 10 | using namespace idni::tau_lang; 11 | 12 | namespace testing = doctest; 13 | 14 | // TODO (LOW) most of this functions could be remove and replace by the standart API 15 | 16 | 17 | namespace idni::tau_lang { 18 | 19 | template<> 20 | struct nso_factory { 21 | 22 | tau parse(const std::string&, 23 | const std::string&) const { 24 | throw std::logic_error("not implemented"); 25 | } 26 | 27 | tau binding(const tau& n, 28 | const std::string& type) const { 29 | if (type != "bool") return n; 30 | return make_node>(Bool(true), {}); 31 | } 32 | 33 | std::vector types() const { 34 | return { "bool" }; 35 | } 36 | 37 | std::string default_type() const { 38 | return "bool"; 39 | } 40 | 41 | std::string one(const std::string&) const { 42 | throw std::logic_error("not implemented"); 43 | } 44 | 45 | std::string zero(const std::string&) const { 46 | throw std::logic_error("not implemented"); 47 | } 48 | 49 | tau splitter_one(const std::string&) const { 50 | throw std::logic_error("not implemented"); 51 | } 52 | 53 | std::optional unpack_tau_ba( 54 | const std::variant&) const { 55 | // There is no tau_ba 56 | return {}; 57 | } 58 | 59 | std::variant pack_tau_ba(const Bool&) const { 60 | // There is no tau_ba 61 | return {}; 62 | } 63 | 64 | static nso_factory& instance() { 65 | static nso_factory factory; 66 | return factory; 67 | } 68 | 69 | private: 70 | 71 | nso_factory() {}; 72 | }; 73 | 74 | } // namespace idni::tau_lang 75 | 76 | // helper functions 77 | tau make_statement(const sp_tau_source_node& source) { 78 | tauify tf; 79 | map_transformer, sp_tau_source_node, tau> transform(tf); 80 | return post_order_traverser< 81 | map_transformer, sp_tau_source_node, tau>, 82 | all_t, 83 | sp_node, 84 | tau>( 85 | transform, all)(source); 86 | } 87 | 88 | tau make_named_bindings(const tau& statement, const bindings& bs) { 89 | name_binder nb(bs); 90 | bind_transformer, Bool> binder(nb); 91 | return post_order_traverser< 92 | bind_transformer, Bool>, 93 | all_t, 94 | tau>( 95 | binder, all)(statement); 96 | } 97 | 98 | tau make_factory_bindings(const tau& statement) { 99 | factory_binder fb; 100 | bind_transformer, Bool> binder(fb); 101 | return post_order_traverser< 102 | bind_transformer, Bool>, 103 | all_t, 104 | tau>( 105 | binder, all)(statement); 106 | } 107 | 108 | std::ostream& print_tau(std::ostream &os, tau n, size_t l = 0) { 109 | os << "{"; 110 | // for (size_t t = 0; t < l; t++) os << " "; 111 | std::visit(overloaded { 112 | [&os](tau_source_sym v) { if (v.nt()) os << v.n(); else os << v.t(); }, 113 | [&os](std::variant v) { if (auto b = std::get<0>(v); b.b) os << "true"; else os << "false"; }, 114 | [&os](size_t v) { os << v; } 115 | }, n->value); 116 | for (auto& d : n->child) print_tau(os, d, l + 1); 117 | os << "}"; 118 | return os; 119 | } 120 | 121 | std::ostream& pretty_print_tau(std::ostream &os, tau n, size_t l = 0) { 122 | // for (size_t t = 0; t < l; t++) os << " "; 123 | std::visit(overloaded{ 124 | [&os](tau_source_sym v) { if (!v.nt()) os << v.t(); }, 125 | [&os](std::variant v) { 126 | if (auto b = std::get<0>(v); b == true) os << "true"; 127 | else if (auto b = std::get<0>(v); b == false) os << "false"; 128 | else os << "...bdd..."; }, 129 | [&os](size_t v) { os << v; } 130 | }, n->value); 131 | for (auto& d : n->child) pretty_print_tau(os, d, l + 1); 132 | return os; 133 | } 134 | #endif // __TEST_HELPERS_H__ -------------------------------------------------------------------------------- /tests/unit/test_interpreter.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "interpreter.h" 7 | 8 | TEST_SUITE("interpreter") { 9 | 10 | TEST_CASE("interpreter") { 11 | CHECK( true ); 12 | } 13 | } -------------------------------------------------------------------------------- /tests/unit/test_make_node_hook.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include "doctest.h" 17 | 18 | namespace testing = doctest; 19 | 20 | TEST_SUITE("make_node_hook: simplify_bf and double negation") { 21 | // TODO (HIGH) write tests to check simplify_bf and double negation in make_node_hook 22 | //RULE(BF_ELIM_DOUBLE_NEGATION_0, "$X'' := $X.") 23 | //RULE(BF_SIMPLIFY_ONE_0, "1 | $X := 1.") 24 | //RULE(BF_SIMPLIFY_ONE_1, "$X | 1 := 1.") 25 | //RULE(BF_SIMPLIFY_ONE_2, "1 & $X := $X.") 26 | //RULE(BF_SIMPLIFY_ONE_3, "$X & 1 := $X.") 27 | //RULE(BF_SIMPLIFY_ONE_4, "1' := 0.") 28 | //RULE(BF_SIMPLIFY_ZERO_0, "0 & $X := 0.") 29 | //RULE(BF_SIMPLIFY_ZERO_1, "$X & 0 := 0.") 30 | //RULE(BF_SIMPLIFY_ZERO_2, "0 | $X := $X.") 31 | //RULE(BF_SIMPLIFY_ZERO_3, "$X | 0 := $X.") 32 | //RULE(BF_SIMPLIFY_ZERO_4, "0' := 1.") 33 | //RULE(BF_SIMPLIFY_SELF_0, "$X & $X := $X.") 34 | //RULE(BF_SIMPLIFY_SELF_1, "$X | $X := $X.") 35 | //RULE(BF_SIMPLIFY_SELF_2, "$X & $X' := 0.") 36 | //RULE(BF_SIMPLIFY_SELF_3, "$X | $X' := 1.") 37 | //RULE(BF_SIMPLIFY_SELF_4, "$X' & $X := 0.") 38 | //RULE(BF_SIMPLIFY_SELF_5, "$X' | $X := 1.") 39 | } 40 | -------------------------------------------------------------------------------- /tests/unit/test_normalizer.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include "doctest.h" 17 | #include "test_helpers.h" 18 | #include "normalizer.h" 19 | #include "boolean_algebras/bdds/bdd_handle.h" 20 | 21 | using namespace idni::rewriter; 22 | using namespace idni::tau_lang; 23 | 24 | namespace testing = doctest; 25 | 26 | // TODO (HIGH) write tests to check build_dnf_from_clauses 27 | // TODO (HIGH) write tests to check to_minterm 28 | // TODO (HIGH) write tests to check get_dnf_clauses 29 | // TODO (HIGH) write tests to check get_positive_negative_literals 30 | // TODO (HIGH) write tests to check get_literals 31 | 32 | // TODO (VERY_LOW) write tests to check make_tau_source 33 | // TODO (VERY_LOW) write tests to check make_tau_source_from_file 34 | // TODO (VERY_LOW) write tests to check process_digits 35 | // TODO (VERY_LOW) write tests to check make_tau_code 36 | // TODO (VERY_LOW) write tests to check make_library 37 | // TODO (VERY_LOW) write tests to check make_nso_rr_using_binder 38 | // TODO (VERY_LOW) write tests to check make_nso_rr_using_bindings 39 | // TODO (VERY_LOW) write tests to check make_nso_rr_using_factory 40 | // TODO (VERY_LOW) write tests to check make_builder 41 | 42 | // TODO (VERY_LOW) write tests to check tau_apply_builder 43 | // TODO (VERY_LOW) write tests to check trim 44 | // TODO (VERY_LOW) write tests to check wrap 45 | 46 | // TODO (VERY_LOW) write tests to check nso_rr_apply_if 47 | // TODO (VERY_LOW) write tests to check nso_rr_apply 48 | 49 | // TODO (VERY_LOW) write tests to check operator<< (all versions) 50 | 51 | 52 | // TODO (LOW) write tests to check steps 53 | // TODO (LOW) write tests to check repeat_each 54 | // TODO (LOW) write tests to check repeat_all 55 | // TODO (LOW) write tests to check repeat 56 | // TODO (LOW) write tests to check operator| (all versions) 57 | 58 | // TODO (LOW) write tests to check get_free_vars_from_nso 59 | -------------------------------------------------------------------------------- /tests/unit/test_nso_rr.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include 17 | 18 | #include "boolean_algebras/bool_ba.h" 19 | #include "doctest.h" 20 | #include "nso_rr.h" 21 | #include "boolean_algebras/bdds/bdd_handle.h" 22 | #include "normalizer.h" 23 | #include "test_helpers.h" 24 | 25 | using namespace idni::rewriter; 26 | using namespace idni::tau_lang; 27 | 28 | namespace testing = doctest; 29 | 30 | TEST_SUITE("make_library") { 31 | 32 | TEST_CASE("make_library: one rule case") { 33 | const auto sample = BF_TO_DNF_0; 34 | auto lib = make_library(sample); 35 | CHECK( lib.size() == 1 ); 36 | } 37 | } 38 | 39 | // TODO (VERY_LOW) write more unit tests for make_library 40 | // TODO (VERY_LOW) write tests to check make_rule 41 | // TODO (VERY_LOW) write tests to check make_tau_source 42 | // TODO (VERY_LOW) write tests to check make_tau_code 43 | // TODO (VERY_LOW) write tests to check make_builder 44 | // TODO (VERY_LOW) write tests for make_nso_rr_using_factory 45 | // TODO (VERY_LOW) write tests for make_nso_rr_using_bindings 46 | // TODO (VERY_LOW) write tests for make_tau_source 47 | // TODO (VERY_LOW) write tests for nso_rr_apply 48 | // TODO (VERY_LOW) write tests for tau_apply_builder 49 | // 50 | // They are tagged as VERY_LOW because they are extensively tested inderectly in 51 | // other unit/integration tests. However, it is better to have explicit tests 52 | // for each of them. 53 | 54 | // TODO (VERY_LOW) write tests for operator<<(ostream, tau<...>) 55 | // TODO (VERY_LOW) write tests for operator<<(ostream, sp_tau_source_node) 56 | // 57 | // They are tagged as VERY_LOW because they should be remove once we have a proper 58 | // UI and I/O api. 59 | 60 | // TODO (LOW) write tests for is_non_terminal 61 | // TODO (LOW) write tests for is_terminal 62 | // TODO (LOW) write tests for value_extractor 63 | // TODO (LOW) write tests for terminal_extractor 64 | // TODO (LOW) write tests for non_terminal_extractor 65 | // TODO (LOW) write tests for ba_extractor 66 | // TODO (LOW) write tests for stringify 67 | // TODO (LOW) write tests for make_string 68 | // 69 | // All of them are extensively tested inderectly in other unit/integration tests. 70 | // However, it is better to have explicit tests for each of them. 71 | 72 | TEST_SUITE("callbacks") { 73 | 74 | 75 | // TODO (MEDIUM) write tests for execution bf_has_clashing_subformulas_cb 76 | // TODO (MEDIUM) write tests for execution bf_has_subformula_cb 77 | // TODO (MEDIUM) write tests for execution bf_remove_fexistential_cb 78 | // TODO (MEDIUM) write tests for execution bf_remove_funiversal_cb 79 | 80 | // TODO (MEDIUM) write tests for execution wff_remove_existential_cb 81 | // TODO (MEDIUM) write tests for execution wff_remove_bexistential_cb 82 | // TODO (MEDIUM) write tests for execution wff_remove_buniversal_cb. 83 | // TODO (MEDIUM) write tests for execution wff_has_clashing_subformulas_cb 84 | // TODO (MEDIUM) write tests for execution wff_has_subformula_cb 85 | // 86 | // Callbacks are a crucial part of the execution of the normalizer and should 87 | // be tested properly. However, they are extensively tested inderectly in 88 | // other unit/integration tests. However, it is better to have explicit tests 89 | // for each of them. 90 | 91 | } 92 | -------------------------------------------------------------------------------- /tests/unit/test_product_ba.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include "boolean_algebras/product_ba.h" 17 | #include "doctest.h" 18 | 19 | namespace testing = doctest; 20 | 21 | TEST_SUITE("product boolean algebra") { 22 | 23 | // Classical 0/1 boolean algebra for testing purposes. 24 | struct ba_01 { 25 | bool value; 26 | 27 | ba_01 operator&(const ba_01& that) { return ba_01(value & that.value); } 28 | ba_01 operator|(const ba_01& that) { return ba_01(value | that.value); } 29 | ba_01 operator^(const ba_01& that) { return ba_01(value ^ that.value); } 30 | ba_01 operator~() { return {!value}; } 31 | auto operator<=>(const ba_01& that) const = default; 32 | }; 33 | 34 | struct ba_01p { 35 | bool value; 36 | 37 | ba_01p operator&(const ba_01p& that) { return ba_01p(value & that.value); } 38 | ba_01p operator|(const ba_01p& that) { return ba_01p(value | that.value); } 39 | ba_01p operator^(const ba_01p& that) { return ba_01p(value ^ that.value); } 40 | ba_01p operator~() { return {!value}; } 41 | auto operator<=>(const ba_01p& that) const = default; 42 | }; 43 | 44 | TEST_CASE("the product of one 0/1 boolean algebra is the correct boolean algebra") { 45 | 46 | product_ba F(ba_01(false)); 47 | product_ba T(ba_01(true)); 48 | 49 | CHECK( ~F == T); CHECK( ~T == F); 50 | 51 | CHECK( (F & F) == F); CHECK( (F & T) == F); 52 | CHECK( (T & F) == F); CHECK( (T & T) == T); 53 | 54 | CHECK( (F | F) == F); CHECK( (F | T) == T); 55 | CHECK( (T | F) == T); CHECK( (T | T) == T); 56 | 57 | CHECK( (F ^ F) == F); CHECK( (F ^ T) == T); 58 | CHECK( (T ^ F) == T); CHECK( (T ^ T) == F); 59 | } 60 | 61 | TEST_CASE("the product of two 0/1 boolean algebra is the correct boolean algebra") { 62 | 63 | product_ba FF(ba_01(false), ba_01p(false)); 64 | product_ba FT(ba_01(false), ba_01p(true)); 65 | product_ba TF(ba_01(true), ba_01p(false)); 66 | product_ba TT(ba_01(true), ba_01p(true)); 67 | 68 | CHECK( ~FF == TT); CHECK( ~FT == TF); 69 | CHECK( ~TF == FT); CHECK( ~TT == FF); 70 | 71 | CHECK( (FF & TT) == FF); CHECK( (FF & TF) == FF); 72 | CHECK( (FF & FT) == FF); CHECK( (FF & FF) == FF); 73 | CHECK( (FT & TT) == FT); CHECK( (FT & TF) == FF); 74 | CHECK( (FT & FT) == FT); CHECK( (FT & FF) == FF); 75 | CHECK( (TF & TT) == TF); CHECK( (TF & FT) == FF); 76 | CHECK( (TF & TF) == TF); CHECK( (TF & FF) == FF); 77 | CHECK( (TT & TT) == TT); CHECK( (TT & TF) == TF); 78 | CHECK( (TT & FT) == FT); CHECK( (TT & FF) == FF); 79 | 80 | CHECK( (FF | TT) == TT); CHECK( (FF | TF) == TF); 81 | CHECK( (FF | FT) == FT); CHECK( (FF | FF) == FF); 82 | CHECK( (FT | TT) == TT); CHECK( (FT | TF) == TT); 83 | CHECK( (FT | FT) == FT); CHECK( (FT | FF) == FT); 84 | CHECK( (TF | TT) == TT); CHECK( (TF | FT) == TT); 85 | CHECK( (TF | TF) == TF); CHECK( (TF | FF) == TF); 86 | CHECK( (TT | TT) == TT); CHECK( (TT | TF) == TT); 87 | CHECK( (TT | FT) == TT); CHECK( (TT | FF) == TT); 88 | 89 | CHECK( (FF ^ TT) == TT); CHECK( (FF ^ TF) == TF); 90 | CHECK( (FF ^ FT) == FT); CHECK( (FF ^ FF) == FF); 91 | CHECK( (FT ^ TT) == TF); CHECK( (FT ^ TF) == TT); 92 | CHECK( (FT ^ FT) == FF); CHECK( (FT ^ FF) == FT); 93 | CHECK( (TF ^ TT) == FT); CHECK( (TF ^ FT) == TT); 94 | CHECK( (TF ^ TF) == FF); CHECK( (TF ^ FF) == TF); 95 | CHECK( (TT ^ TT) == FF); CHECK( (TT ^ TF) == FT); 96 | CHECK( (TT ^ FT) == TF); CHECK( (TT ^ FF) == TT); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /tests/unit/test_rules-bf_execution.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "nso_rr.h" 7 | #include "boolean_algebras/bool_ba.h" 8 | #include "boolean_algebras/bdds/bdd_handle.h" 9 | #include "normalizer.h" 10 | #include "test_helpers.h" 11 | 12 | using namespace idni::rewriter; 13 | using namespace idni::tau_lang; 14 | 15 | namespace testing = doctest; 16 | 17 | std::tuple, tau, tau> 18 | test_rule(const std::string& rule_str) 19 | { 20 | auto src_rule = make_tau_source(rule_str, { 21 | .start = tau_parser::library }); 22 | auto statement = make_statement(src_rule); 23 | auto rule = statement 24 | | tau_parser::rules 25 | | tau_parser::rule; 26 | auto tau_rule = make_rule(rule.value()); 27 | auto [matcher, body] = tau_rule; 28 | auto result = nso_rr_apply(tau_rule, matcher); 29 | return { matcher, body, result }; 30 | } 31 | -------------------------------------------------------------------------------- /tests/unit/test_rules-bf_parsing.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "nso_rr.h" 7 | #include "boolean_algebras/bool_ba.h" 8 | #include "boolean_algebras/bdds/bdd_handle.h" 9 | #include "normalizer.h" 10 | #include "test_helpers.h" 11 | 12 | using namespace idni::rewriter; 13 | using namespace idni::tau_lang; 14 | 15 | namespace testing = doctest; 16 | 17 | bool test_rule(const std::string& sample, tau_parser::nonterminal rule_type) { 18 | auto src_rule = make_tau_source(sample, { 19 | .start = tau_parser::library }); 20 | auto tau_rule = make_statement(src_rule); 21 | auto check = tau_rule 22 | | tau_parser::rules 23 | | tau_parser::rule 24 | | rule_type; 25 | return check.has_value(); 26 | } 27 | 28 | TEST_SUITE("parsing bf rules") { 29 | 30 | TEST_CASE("BF_TO_DNF_0") { 31 | CHECK( test_rule(BF_TO_DNF_0, tau_parser::bf_rule) ); 32 | } 33 | 34 | TEST_CASE("BF_TO_DNF_1") { 35 | CHECK( test_rule(BF_TO_DNF_1, tau_parser::bf_rule) ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/unit/test_rules-wff_execution.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "nso_rr.h" 7 | #include "boolean_algebras/bool_ba.h" 8 | #include "boolean_algebras/bdds/bdd_handle.h" 9 | #include "normalizer.h" 10 | #include "test_helpers.h" 11 | 12 | using namespace idni::rewriter; 13 | using namespace idni::tau_lang; 14 | 15 | namespace testing = doctest; 16 | 17 | std::tuple, tau, tau> 18 | test_rule(const std::string& rule_str) 19 | { 20 | auto src_rule = make_tau_source(rule_str, { 21 | .start = tau_parser::library }); 22 | auto statement = make_statement(src_rule); 23 | auto rule = statement 24 | | tau_parser::rules 25 | | tau_parser::rule; 26 | auto tau_rule = make_rule(rule.value()); 27 | auto [matcher, body] = tau_rule; 28 | auto result = nso_rr_apply(tau_rule, matcher); 29 | return { matcher, body, result }; 30 | } 31 | 32 | TEST_SUITE("executing wff rules") { 33 | 34 | TEST_CASE("WFF_TO_DNF_0") { 35 | auto [ matcher, body, result ] = test_rule(WFF_TO_DNF_0); 36 | CHECK( matcher != body ); 37 | CHECK( result == body ); 38 | } 39 | 40 | TEST_CASE("WFF_TO_DNF_1") { 41 | auto [ matcher, body, result ] = test_rule(WFF_TO_DNF_1); 42 | CHECK( matcher != body ); 43 | CHECK( result == body ); 44 | } 45 | 46 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_0") { 47 | auto [ matcher, body, result ] = 48 | test_rule(WFF_PUSH_NEGATION_INWARDS_0); 49 | CHECK( matcher != body ); 50 | CHECK( result == body ); 51 | } 52 | 53 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_1") { 54 | auto [ matcher, body, result ] = 55 | test_rule(WFF_PUSH_NEGATION_INWARDS_1); 56 | CHECK( matcher != body ); 57 | CHECK( result == body ); 58 | } 59 | 60 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_2") { 61 | auto [ matcher, body, result ] = 62 | test_rule(WFF_PUSH_NEGATION_INWARDS_2); 63 | CHECK( matcher != body ); 64 | CHECK( result == body ); 65 | } 66 | 67 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_3") { 68 | auto [ matcher, body, result ] = 69 | test_rule(WFF_PUSH_NEGATION_INWARDS_3); 70 | CHECK( matcher != body ); 71 | CHECK( result == body ); 72 | } 73 | 74 | TEST_CASE("WFF_ELIM_FORALL") { 75 | auto [ matcher, body, result ] = test_rule(WFF_ELIM_FORALL); 76 | CHECK( matcher != body ); 77 | CHECK( result == body ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/unit/test_rules-wff_parsing.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "boolean_algebras/bool_ba.h" 7 | #include "nso_rr.h" 8 | #include "boolean_algebras/bdds/bdd_handle.h" 9 | #include "normalizer.h" 10 | #include "test_helpers.h" 11 | 12 | using namespace idni::rewriter; 13 | using namespace idni::tau_lang; 14 | 15 | namespace testing = doctest; 16 | 17 | bool test_rule(const std::string& sample) { 18 | auto src_rule = make_tau_source(sample, { 19 | .start = tau_parser::library }); 20 | auto tau_rule = make_statement(src_rule); 21 | auto check = tau_rule 22 | | tau_parser::rules 23 | | tau_parser::rule 24 | | tau_parser::wff_rule; 25 | return check.has_value(); 26 | } 27 | 28 | TEST_SUITE("parsing wff rules") { 29 | 30 | TEST_CASE("WFF_TO_DNF_0") { 31 | CHECK( test_rule(WFF_TO_DNF_0) ); 32 | } 33 | 34 | TEST_CASE("WFF_TO_DNF_1") { 35 | CHECK( test_rule(WFF_TO_DNF_1) ); 36 | } 37 | 38 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_0") { 39 | CHECK( test_rule(WFF_PUSH_NEGATION_INWARDS_0) ); 40 | } 41 | 42 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_1") { 43 | CHECK( test_rule(WFF_PUSH_NEGATION_INWARDS_1) ); 44 | } 45 | 46 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_2") { 47 | CHECK( test_rule(WFF_PUSH_NEGATION_INWARDS_2) ); 48 | } 49 | 50 | TEST_CASE("WFF_PUSH_NEGATION_INWARDS_3") { 51 | CHECK( test_rule(WFF_PUSH_NEGATION_INWARDS_3) ); 52 | } 53 | 54 | TEST_CASE("WFF_ELIM_FORALL") { 55 | CHECK( test_rule(WFF_ELIM_FORALL) ); 56 | } 57 | } -------------------------------------------------------------------------------- /tests/unit/test_tau.cpp: -------------------------------------------------------------------------------- 1 | // LICENSE 2 | // This software is free for use and redistribution while including this 3 | // license notice, unless: 4 | // 1. is used for commercial or non-personal purposes, or 5 | // 2. used for a product which includes or associated with a blockchain or other 6 | // decentralized database technology, or 7 | // 3. used for a product which includes or associated with the issuance or use 8 | // of cryptographic or electronic currencies/coins/tokens. 9 | // On all of the mentiTd cases, an explicit and written permission is required 10 | // from the Author (Ohad Asor). 11 | // Contact ohad@idni.org for requesting a permission. This license may be 12 | // modified over time by the Author. 13 | 14 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 15 | 16 | #include 17 | 18 | #include "doctest.h" 19 | #include "boolean_algebras/bool_ba.h" 20 | #include "nso_rr.h" 21 | #include "boolean_algebras/bdds/bdd_handle.h" 22 | #include "normalizer.h" 23 | #include "test_helpers.h" 24 | 25 | using namespace idni::rewriter; 26 | using namespace idni::tau_lang; 27 | 28 | namespace testing = doctest; 29 | 30 | TEST_SUITE("something") { 31 | 32 | TEST_CASE("something") { 33 | CHECK( true ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/unit/test_traversal.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include 6 | 7 | #include "doctest.h" 8 | #include "nso_rr.h" 9 | #include "language.h" 10 | #include "boolean_algebras/bool_ba.h" 11 | #include "boolean_algebras/bdds/bdd_handle.h" 12 | #include "test_helpers.h" 13 | 14 | using namespace idni::rewriter; 15 | using namespace idni::tau_lang; 16 | using namespace std; 17 | 18 | namespace testing = doctest; 19 | 20 | TEST_SUITE("operator|") { 21 | 22 | TEST_CASE("match zero nodes") { 23 | const char* sample = "$X & $Y := $Z."; 24 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 25 | auto lib = make_statement(src); 26 | auto args = lib 27 | | tau_parser::main; 28 | CHECK( !args ); 29 | } 30 | 31 | TEST_CASE("match one node") { 32 | const char* sample = "$X & $Y := $Z."; 33 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 34 | auto lib = make_statement(src); 35 | auto args = lib 36 | | tau_parser::rules; 37 | CHECK( args.has_value() ); 38 | } 39 | } 40 | 41 | TEST_SUITE("operator||") { 42 | 43 | TEST_CASE("match zero nodes") { 44 | const char* sample = "$X & $Y := $Z."; 45 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 46 | auto lib = make_statement(src); 47 | auto args = lib 48 | | tau_parser::rules 49 | | tau_parser::rule 50 | | tau_parser::wff_rule 51 | || tau_parser::wff; 52 | CHECK( args.size() == 0 ); 53 | } 54 | 55 | TEST_CASE("match one node") { 56 | const char* sample = "X & Y := Z."; 57 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 58 | auto lib = make_statement(src); 59 | auto args = lib 60 | | tau_parser::rules 61 | | tau_parser::rule 62 | || tau_parser::bf_rule; 63 | CHECK( args.size() == 1 ); 64 | } 65 | 66 | TEST_CASE("match several nodes") { 67 | const char* sample = "X & Y := Z."; 68 | auto src = make_tau_source(sample, { .start = tau_parser::library }); 69 | auto lib = make_statement(src); 70 | auto args = lib 71 | | tau_parser::rules 72 | | tau_parser::rule 73 | | tau_parser::bf_rule 74 | | tau_parser::bf_matcher 75 | | tau_parser::bf 76 | | tau_parser::bf_and 77 | || tau_parser::bf; 78 | CHECK( args.size() == 2 ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tests/unit/test_type_system.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "boolean_algebras/bool_ba.h" 7 | #include "defs.h" 8 | #include "nso_rr.h" 9 | #include "test_helpers.h" 10 | 11 | #include "debug_helpers.h" 12 | 13 | using namespace idni::rewriter; 14 | using namespace idni::tau_lang; 15 | using namespace std; 16 | 17 | namespace testing = doctest; 18 | 19 | tau infer(const char* sample) { 20 | auto src = make_tau_source(sample); 21 | auto stmt = make_statement(src); 22 | return infer_constant_types(stmt); 23 | } 24 | 25 | bool expect_infer_fail(const char* sample) { 26 | auto x = infer(sample); 27 | return x.get() == 0; 28 | } 29 | 30 | bool are_all_typed_as(const tau& n, const std::string& type) { 31 | for (const auto& c : select_all(n, 32 | is_non_terminal)) 33 | { 34 | auto tn = c | tau_parser::type; 35 | if ((!tn && type.size()) || ((tn && type != make_string< 36 | tau_node_terminal_extractor_t, tau>( 37 | tau_node_terminal_extractor, tn.value())))) 38 | return false; 39 | } 40 | return true; 41 | } 42 | 43 | TEST_SUITE("constant types") { 44 | TEST_CASE("all typed") { 45 | auto n = infer("{ 0 } : bool = { 1 } : bool & { 0 } : bool."); 46 | // ptree(std::cout << "inferred: ", n) << "\n"; 47 | CHECK( are_all_typed_as(n, "bool") ); 48 | } 49 | 50 | TEST_CASE("some typed") { 51 | auto n = infer("{ 0 } : bool = { 1 } { 0 } : bool."); 52 | // ptree(std::cout << "inferred: ", n) << "\n"; 53 | CHECK( are_all_typed_as(n, "bool") ); 54 | } 55 | 56 | TEST_CASE("only 1 typed") { 57 | auto n = infer("{ 0 } = { 1 } & { 0 } : bool."); 58 | // ptree(std::cout << "inferred: ", n) << "\n"; 59 | CHECK( are_all_typed_as(n, "bool") ); 60 | } 61 | 62 | TEST_CASE("only 1 typed sbf") { 63 | auto n = expect_infer_fail("{ x } = { y } { 0 } : sbf."); 64 | // ptree(std::cout << "inferred: ", n) << "\n"; 65 | CHECK( n ); 66 | } 67 | 68 | TEST_CASE("only 1 typed tau") { 69 | auto n = expect_infer_fail("{ F. } = { T. } { F. } : tau."); 70 | // ptree(std::cout << "inferred: ", n) << "\n"; 71 | CHECK( n ); 72 | } 73 | 74 | TEST_CASE("none typed") { 75 | auto n = infer("{ F. } = { T. } { F. }."); 76 | // ptree(std::cout << "inferred: ", n) << "\n"; 77 | CHECK( are_all_typed_as(n, "bool") ); 78 | } 79 | 80 | TEST_CASE("type mismatch") { 81 | auto n = expect_infer_fail("{ F. }:tau = { 0 }:sbf { 1 }:sbf."); 82 | // ptree(std::cout << "inferred: ", n) << "\n"; 83 | CHECK( n ); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /tests/unit/test_variant_ba.cpp: -------------------------------------------------------------------------------- 1 | // To view the license please visit https://github.com/IDNI/tau-lang/blob/main/LICENSE.txt 2 | 3 | #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN 4 | 5 | #include "doctest.h" 6 | #include "boolean_algebras/bool_ba.h" 7 | #include "boolean_algebras/variant_ba.h" 8 | 9 | namespace testing = doctest; 10 | 11 | using namespace idni::tau_lang; 12 | 13 | TEST_SUITE("variant Boolen algebra") { 14 | 15 | TEST_CASE("variant Bool == Bool") { 16 | CHECK( variant_ba(Bool(true)) == true ); 17 | CHECK( variant_ba(Bool(false)) == false ); 18 | CHECK( variant_ba(Bool(true)) != false ); 19 | CHECK( variant_ba(Bool(false)) != true ); 20 | } 21 | 22 | TEST_CASE("operator&") { 23 | CHECK( (variant_ba(Bool(true)) & variant_ba(Bool(true))) == true ); 24 | CHECK( (variant_ba(Bool(true)) & variant_ba(Bool(false))) == false ); 25 | CHECK( (variant_ba(Bool(false)) & variant_ba(Bool(true))) == false ); 26 | CHECK( (variant_ba(Bool(false)) & variant_ba(Bool(false))) == false ); 27 | } 28 | 29 | TEST_CASE("operator|") { 30 | CHECK( (variant_ba(Bool(true)) | variant_ba(Bool(true))) == true ); 31 | CHECK( (variant_ba(Bool(true)) | variant_ba(Bool(false))) == true ); 32 | CHECK( (variant_ba(Bool(false)) | variant_ba(Bool(true))) == true ); 33 | CHECK( (variant_ba(Bool(false)) | variant_ba(Bool(false))) == false ); 34 | } 35 | 36 | TEST_CASE("operator^") { 37 | CHECK( (variant_ba(Bool(true)) ^ variant_ba(Bool(true))) == false ); 38 | CHECK( (variant_ba(Bool(true)) ^ variant_ba(Bool(false))) == true ); 39 | CHECK( (variant_ba(Bool(false)) ^ variant_ba(Bool(true))) == true ); 40 | CHECK( (variant_ba(Bool(false)) ^ variant_ba(Bool(false))) == false ); 41 | } 42 | 43 | TEST_CASE("operator+") { 44 | CHECK( (variant_ba(Bool(true)) + variant_ba(Bool(true))) == false ); 45 | CHECK( (variant_ba(Bool(true)) + variant_ba(Bool(false))) == true ); 46 | CHECK( (variant_ba(Bool(false)) + variant_ba(Bool(true))) == true ); 47 | CHECK( (variant_ba(Bool(false)) + variant_ba(Bool(false))) == false ); 48 | } 49 | 50 | TEST_CASE("operator~") { 51 | CHECK( ~variant_ba(Bool(true)) == false ); 52 | CHECK( ~variant_ba(Bool(false)) == true ); 53 | } 54 | } -------------------------------------------------------------------------------- /w64-debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh Debug -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake $@ 4 | -------------------------------------------------------------------------------- /w64-packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh Release -DTAU_WINDOWS_ZIP_PACKAGE=ON -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake $@ 4 | cd ./build-Release 5 | cpack -C Release 6 | cd .. 7 | 8 | ./build.sh Release -DTAU_WINDOWS_PACKAGE=ON -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake $@ 9 | cd ./build-Release 10 | cpack -C Release 11 | cd .. 12 | -------------------------------------------------------------------------------- /w64-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./build.sh Release -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake $@ 4 | -------------------------------------------------------------------------------- /wine-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_TYPE=${1:-Release} 4 | TESTS_DIR=../build-$BUILD_TYPE 5 | STATUS=0 6 | 7 | echo "Building $BUILD_TYPE exe files" 8 | ./build.sh $BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-x86_64.cmake -DTAU_BUILD_TESTS=ON 9 | 10 | cd tests 11 | for TEST in $TESTS_DIR/test_*.exe; do 12 | echo "Running wine $TEST" 13 | wine "$TEST" 14 | S=$? 15 | if [ $S -ne 0 ]; then 16 | STATUS=$S 17 | echo "Test $TEST failed with status $STATUS" 18 | fi 19 | done 20 | 21 | if [ $STATUS -ne 0 ]; then 22 | echo "One or more tests failed" 23 | exit $STATUS 24 | fi 25 | 26 | echo "All tests passed" --------------------------------------------------------------------------------