From: Thomas Walker Lynch Date: Fri, 19 Sep 2025 12:11:06 +0000 (-0700) Subject: removes authored files marker, includes some python3 for example X-Git-Url: https://git.reasoningtechnology.com/style/static/git-logo.png?a=commitdiff_plain;h=8bdb6b9adaadd2dab4fdcfedb42dd9ae4a0d13d5;p=Harmony.git removes authored files marker, includes some python3 for example --- diff --git a/developer/document/.githolder b/developer/document/.githolder new file mode 100644 index 0000000..e69de29 diff --git a/developer/document/python packages b/developer/document/python packages new file mode 100644 index 0000000..83a0dd0 --- /dev/null +++ b/developer/document/python packages @@ -0,0 +1,2 @@ + +pip install isqrt diff --git a/developer/document/tests.sh b/developer/document/tests.sh new file mode 100644 index 0000000..6892145 --- /dev/null +++ b/developer/document/tests.sh @@ -0,0 +1,10 @@ + + +2025-05-19T09:56:17Z[Harmony] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/Harmony/developer/python§ +> python test_isqrt.py 500000 20000 +.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... +✅ Passed: 500000 +❌ Failed: 0 + + diff --git a/developer/python/test_env.py b/developer/python/test_env.py deleted file mode 100644 index d47e8a1..0000000 --- a/developer/python/test_env.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys - -def print_env_var(name): - value = os.getenv(name) - print(f"{name:<16}: {value if value else ''}") - -def main(): - print("=== Python Environment Test ===") - print(f"Python executable : {sys.executable}") - print(f"Python version : {sys.version}") - print() - - print("=== Harmony Environment Variables ===") - for var in ["ROLE", "REPO_HOME", "PYTHON_HOME", "VIRTUAL_ENV", "ENV"]: - print_env_var(var) - - print() - print("=== Current Working Directory ===") - print(os.getcwd()) - -if __name__ == "__main__": - main() diff --git a/developer/python3/decompose.py b/developer/python3/decompose.py new file mode 100644 index 0000000..f979189 --- /dev/null +++ b/developer/python3/decompose.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import sys +import random +from isqrt import isqrt + +def decompose(n0_h ,r1_p ,acc_car): + + if r0_h < 0 : print "r0_h is negative" + if r1_p < 0 : print "r1_p is negative" + if acc_car != 0 and acc_car != 1 : print "acc_car is not 0 or 1" + + k_n0_h = n0_h.bit_length() + k_r1_p = r1_p.bit_length() + + if acc_car : + k_n1_p = k_ + + return z1 ,n1_p + + +def main(): + return 1 + +if __name__ == "__main__": + main() diff --git a/developer/python3/iroot.py b/developer/python3/iroot.py new file mode 100644 index 0000000..a6ae3e8 --- /dev/null +++ b/developer/python3/iroot.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import sys +import random +from isqrt import isqrt + +def iroot(z): + c = isqrt(z) + r = z - n0_h ** 2 + return c ,r + +def main(): + return 1 + +if __name__ == "__main__": + main() diff --git a/developer/python3/test_env.py b/developer/python3/test_env.py new file mode 100644 index 0000000..d47e8a1 --- /dev/null +++ b/developer/python3/test_env.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import os +import sys + +def print_env_var(name): + value = os.getenv(name) + print(f"{name:<16}: {value if value else ''}") + +def main(): + print("=== Python Environment Test ===") + print(f"Python executable : {sys.executable}") + print(f"Python version : {sys.version}") + print() + + print("=== Harmony Environment Variables ===") + for var in ["ROLE", "REPO_HOME", "PYTHON_HOME", "VIRTUAL_ENV", "ENV"]: + print_env_var(var) + + print() + print("=== Current Working Directory ===") + print(os.getcwd()) + +if __name__ == "__main__": + main() diff --git a/developer/python3/test_isqrt.py b/developer/python3/test_isqrt.py new file mode 100644 index 0000000..adac4ad --- /dev/null +++ b/developer/python3/test_isqrt.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 + +import sys +import random +from isqrt import isqrt + +def test_isqrt(num_tests, max_bits): + failed = 0 + passed = 0 + + for i in range(1, num_tests + 1): + bits = random.randint(1, max_bits) + n = random.getrandbits(bits) + + root = isqrt(n) + lower = root * root + upper = (root + 1) * (root + 1) + + if lower <= n < upper: + passed += 1 + else: + print(f"\n❌ Test failed:") + print(f"bits = {bits}") + print(f"n = {hex(n)}") + print(f"root = {hex(root)}") + if lower > n: + print("Reason = root is too large") + elif upper <= n: + print("Reason = root + 1 is too small") + failed += 1 + + if i % 1000 == 0: + print(".", end="", flush=True) + + if num_tests >= 10: + print() + + print(f"✅ Passed: {passed}") + print(f"❌ Failed: {failed}") + +def print_root(n): + print_bin(isqrt(n)) + +def reduce(n): + n + +def main(): + if len(sys.argv) != 3: + print(f"Usage: {sys.argv[0]} ") + sys.exit(1) + + try: + n = int(sys.argv[1], 0) + max = int(sys.argv[2], 0) + except ValueError: + print("Error: argument must be a valid integer.") + sys.exit(1) + + if n < 0: + print("Error: number of tests must be non-negative.") + sys.exit(1) + + if max < 4: + print("Error: max_bits must be at least 4.") + sys.exit(1) + + test_isqrt(n, max) + +if __name__ == "__main__": + main() diff --git a/developer/python3/test_reduce.py b/developer/python3/test_reduce.py new file mode 100644 index 0000000..02cb53e --- /dev/null +++ b/developer/python3/test_reduce.py @@ -0,0 +1,70 @@ + +import sys +import random +from iroot import iroot + +def test_reduce(num_tests, max_bits): + failed = 0 + passed = 0 + + hex_width = (max_bits + 3) // 4 # ceil(max_bits / 4) for hex digit count + hex_widtho2 = (max_bits + 7) // 8 # ceil(max_bits / 8) for reduced-width fields + + field = f"#0{hex_width + 2}x" + fieldo2 = f"#0{hex_widtho2 + 2}x" + + header = ( + f"{'z':>{hex_width + 2}} " + f"{'n0h':>{hex_widtho2 + 2}} " + f"{'r_h':>{hex_widtho2 + 2}} " + f"{'r_hp':>{hex_widtho2 + 2}}" + ) + print(header) + print("-" * len(header)) + + for i in range(1, num_tests + 1): + bits = random.randint(1, max_bits) + z = random.getrandbits(bits) + + n0h, r_h, r_hp = iroot(z) + + # Format fields, fallback to full-width hex if overflow detected + z_str = format(z, field) if z.bit_length() <= max_bits else f"{z:#x}" + n0h_str = format(n0h, fieldo2) if n0h.bit_length() <= max_bits else f"{n0h:#x}" + r_h_str = format(r_h, fieldo2) if r_h.bit_length() <= max_bits else f"{r_h:#x}" + r_hp_str = format(r_hp, fieldo2) if r_hp.bit_length() <= max_bits else f"{r_hp:#x}" + + print(f"{z_str} {n0h_str} {r_h_str} {r_hp_str}") + + if i % 1000 == 0: + print(".", end="", flush=True) + + if num_tests >= 1000: + print() + + + +def main(): + if len(sys.argv) != 3: + print(f"Usage: {sys.argv[0]} ") + sys.exit(1) + + try: + n = int(sys.argv[1], 0) + max = int(sys.argv[2], 0) + except ValueError: + print("Error: argument must be a valid integer.") + sys.exit(1) + + if n < 0: + print("Error: number of tests must be non-negative.") + sys.exit(1) + + if max < 4: + print("Error: max_bits must be at least 4.") + sys.exit(1) + + test_reduce(n, max) + +if __name__ == "__main__": + main() diff --git a/env_developer b/env_developer index a1c0eda..24f92fe 100644 --- a/env_developer +++ b/env_developer @@ -6,7 +6,7 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then fi export ROLE=developer -source tool_shared/bespoke🖉/env +source tool_shared/bespoke/env if [[ ":$PATH:" != *":$PYTHON_HOME/bin:"* ]]; then export PATH="$PYTHON_HOME/bin:$PATH" diff --git a/env_tester b/env_tester index b9c8139..45439c1 100644 --- a/env_tester +++ b/env_tester @@ -6,7 +6,7 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then fi export ROLE=tester -source tool_shared/bespoke🖉/env +source tool_shared/bespoke/env if [[ ":$PATH:" != *":$PYTHON_HOME/bin:"* ]]; then export PATH="$PYTHON_HOME/bin:$PATH" diff --git a/env_toolsmith b/env_toolsmith index 68fd2d3..b121a82 100644 --- a/env_toolsmith +++ b/env_toolsmith @@ -6,6 +6,6 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then fi export ROLE=toolsmith -source tool_shared/bespoke🖉/env +source tool_shared/bespoke/env export ENV=$ROLE diff --git a/tool_shared/bespoke/env b/tool_shared/bespoke/env new file mode 100644 index 0000000..eb93ff3 --- /dev/null +++ b/tool_shared/bespoke/env @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") +if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then + echo "$script_afp:: This script must be sourced, not executed." + exit 1 +fi + +# without this bash takes non-matching globs literally +shopt -s nullglob + +# -------------------------------------------------------------------------------- +# project definition + +# actual absolute director path for this script file + + script_adp(){ + dirname "$script_afp" + } + +# assume this script is located $REPO_HOME/tools_shared/bespoke and work backwards +# to get $REPO_HOME, etc. + + REPO_HOME=$(dirname "$(dirname "$(script_adp)")") + echo REPO_HOME "$REPO_HOME" + + PROJECT=$(basename "$REPO_HOME") + echo PROJECT "$PROJECT" + + # set the prompt decoration to the name of the project + PROMPT_DECOR=$PROJECT + + export REPO_HOME PROJECT PROMPT_DECOR + +# -------------------------------------------------------------------------------- +# Project wide Tool setup +# + +export VIRTUAL_ENV="$REPO_HOME/tool_shared/third_party/Python" +export PYTHON_HOME="$VIRTUAL_ENV" +unset PYTHONHOME + + +# -------------------------------------------------------------------------------- +# PATH +# precedence: last defined, first discovered + + PATH="$REPO_HOME/tool_shared/third_party/RT-project-share/release/bash:$PATH" + PATH="$REPO_HOME/tool_shared/third_party/RT-project-share/release/amd64:$PATH" + PATH="$REPO_HOME/tool_shared/third_party:$PATH" + PATH="$REPO_HOME/tool_shared/customized:$PATH" + PATH="$REPO_HOME"/tool_shared/bespoke:"$PATH" + + # Remove duplicates + clean_path() { + PATH=$(echo ":$PATH" | awk -v RS=: -v ORS=: '!seen[$0]++' | sed 's/^://; s/:$//') + } + clean_path + export PATH + +# -------------------------------------------------------------------------------- +# the following functions are provided for other scripts to use. +# at the top of files that make use of these functions put the following line: +# script_afp=$(realpath "${BASH_SOURCE[0]}") +# + + ## script's filename + script_fn(){ + basename "$script_afp" + } + + ## script's dirpath relative to $REPO_HOME + script_fp(){ + realpath --relative-to="${REPO_HOME}" "$script_afp" + } + + ## script's dirpath relative to $REPO_HOME + script_dp(){ + dirname "$(script_fp)" + } + + export -f script_adp script_fn script_dp script_fp + +#-------------------------------------------------------------------------------- +# used by release scripts +# + + install_file() { + if [ "$#" -lt 3 ]; then + echo "env::install_file usage: install_file ... " + return 1 + fi + + perms="${@: -1}" # Last argument is permissions + target_dp="${@: -2:1}" # Second-to-last argument is the target directory + sources=("${@:1:$#-2}") # All other arguments are source files + + if [ ! -d "$target_dp" ]; then + echo "env::install_file no install done: target directory '$target_dp' does not exist." + return 1 + fi + + for source_fp in "${sources[@]}"; do + if [ ! -f "$source_fp" ]; then + echo "env::install_file: source file '$source_fp' does not exist." + return 1 + fi + + target_file="$target_dp/$(basename "$source_fp")" + + if ! install -m "$perms" "$source_fp" "$target_file"; then + echo "env::install_file: Failed to install $(basename "$source_fp") to $target_dp" + return 1 + else + echo "env::install_file: installed $(basename "$source_fp") to $target_dp with permissions $perms" + fi + done + } + + export -f install_file + +# -------------------------------------------------------------------------------- +# closing +# + if [[ -z "$ENV" ]]; then + export ENV=$(script_fp) + fi + diff --git a/tool_shared/bespoke/version b/tool_shared/bespoke/version new file mode 100755 index 0000000..9d91a98 --- /dev/null +++ b/tool_shared/bespoke/version @@ -0,0 +1,5 @@ +#!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") + +echo "Harmony v0.1 2025-05-19" + diff --git "a/tool_shared/bespoke\360\237\226\211/env" "b/tool_shared/bespoke\360\237\226\211/env" deleted file mode 100644 index 4c0ca3f..0000000 --- "a/tool_shared/bespoke\360\237\226\211/env" +++ /dev/null @@ -1,127 +0,0 @@ -#!/usr/bin/env bash -script_afp=$(realpath "${BASH_SOURCE[0]}") -if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then - echo "$script_afp:: This script must be sourced, not executed." - exit 1 -fi - -# without this bash takes non-matching globs literally -shopt -s nullglob - -# -------------------------------------------------------------------------------- -# project definition - -# actual absolute director path for this script file - - script_adp(){ - dirname "$script_afp" - } - -# assume this script is located $REPO_HOME/tools_shared/bespoke and work backwards -# to get $REPO_HOME, etc. - - REPO_HOME=$(dirname "$(dirname "$(script_adp)")") - echo REPO_HOME "$REPO_HOME" - - PROJECT=$(basename "$REPO_HOME") - echo PROJECT "$PROJECT" - - # set the prompt decoration to the name of the project - PROMPT_DECOR=$PROJECT - - export REPO_HOME PROJECT PROMPT_DECOR - -# -------------------------------------------------------------------------------- -# Project wide Tool setup -# - -export VIRTUAL_ENV="$REPO_HOME/tool_shared/third_party/Python" -export PYTHON_HOME="$VIRTUAL_ENV" -unset PYTHONHOME - - -# -------------------------------------------------------------------------------- -# PATH -# precedence: last defined, first discovered - - PATH="$REPO_HOME/tool_shared/third_party/RT-project-share/release/bash:$PATH" - PATH="$REPO_HOME/tool_shared/third_party/RT-project-share/release/amd64:$PATH" - PATH="$REPO_HOME/tool_shared/third_party:$PATH" - PATH="$REPO_HOME/tool_shared/customized:$PATH" - PATH="$REPO_HOME"/tool_shared/bespoke🖉:"$PATH" - - # Remove duplicates - clean_path() { - PATH=$(echo ":$PATH" | awk -v RS=: -v ORS=: '!seen[$0]++' | sed 's/^://; s/:$//') - } - clean_path - export PATH - -# -------------------------------------------------------------------------------- -# the following functions are provided for other scripts to use. -# at the top of files that make use of these functions put the following line: -# script_afp=$(realpath "${BASH_SOURCE[0]}") -# - - ## script's filename - script_fn(){ - basename "$script_afp" - } - - ## script's dirpath relative to $REPO_HOME - script_fp(){ - realpath --relative-to="${REPO_HOME}" "$script_afp" - } - - ## script's dirpath relative to $REPO_HOME - script_dp(){ - dirname "$(script_fp)" - } - - export -f script_adp script_fn script_dp script_fp - -#-------------------------------------------------------------------------------- -# used by release scripts -# - - install_file() { - if [ "$#" -lt 3 ]; then - echo "env::install_file usage: install_file ... " - return 1 - fi - - perms="${@: -1}" # Last argument is permissions - target_dp="${@: -2:1}" # Second-to-last argument is the target directory - sources=("${@:1:$#-2}") # All other arguments are source files - - if [ ! -d "$target_dp" ]; then - echo "env::install_file no install done: target directory '$target_dp' does not exist." - return 1 - fi - - for source_fp in "${sources[@]}"; do - if [ ! -f "$source_fp" ]; then - echo "env::install_file: source file '$source_fp' does not exist." - return 1 - fi - - target_file="$target_dp/$(basename "$source_fp")" - - if ! install -m "$perms" "$source_fp" "$target_file"; then - echo "env::install_file: Failed to install $(basename "$source_fp") to $target_dp" - return 1 - else - echo "env::install_file: installed $(basename "$source_fp") to $target_dp with permissions $perms" - fi - done - } - - export -f install_file - -# -------------------------------------------------------------------------------- -# closing -# - if [[ -z "$ENV" ]]; then - export ENV=$(script_fp) - fi - diff --git "a/tool_shared/bespoke\360\237\226\211/version" "b/tool_shared/bespoke\360\237\226\211/version" deleted file mode 100755 index 9d91a98..0000000 --- "a/tool_shared/bespoke\360\237\226\211/version" +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/env bash -script_afp=$(realpath "${BASH_SOURCE[0]}") - -echo "Harmony v0.1 2025-05-19" - diff --git a/tool_shared/document/install_Python.org b/tool_shared/document/install_Python.org new file mode 100644 index 0000000..4725c04 --- /dev/null +++ b/tool_shared/document/install_Python.org @@ -0,0 +1,75 @@ +#+TITLE: Installing Python in Harmony +#+AUTHOR: Thomas Walker Lynch +#+OPTIONS: toc:2 num:nil + +* Overview + +This document describes how to install a project-local Python environment under: + +#+begin_src bash +tool_shared/third_party/Python +#+end_src + +This environment is shared across the =developer= and =tester= roles and is automatically activated through their respective =env_= scripts. + +* Precondition + +Ensure the following: + +- You are in a POSIX shell with =python3= installed. +- The =python3-venv= package is available (on Debian: =sudo apt install python3-venv=). +- You have sourced the Harmony environment via =env_toolsmith= to initialize =REPO_HOME= and related variables. + +* Step-by-Step Installation + +1. Source the Harmony environment: + #+begin_src bash + source env_toolsmith + #+end_src + +2. Create the virtual environment: + #+begin_src bash + python3 -m venv "$REPO_HOME/tool_shared/third_party/Python" + #+end_src + +3. Activate it temporarily to install required packages: + #+begin_src bash + source "$REPO_HOME/tool_shared/third_party/Python/bin/activate" + pip install --upgrade pip + pip install pytest # Add any shared packages here + deactivate + #+end_src + +4. Rename Python's default activate and deactivate: + Harmony provides its own role-aware environment management. Using Python’s default activation scripts may interfere with prompt logic, PATH order, and role-specific behavior. + + Disable the default scripts by renaming them: + #+begin_src bash + mv "$REPO_HOME/tool_shared/third_party/Python/bin/activate" \ + "$REPO_HOME/tool_shared/third_party/Python/bin/activate_deprecated" + #+end_src + + This ensures that accidental sourcing of Python’s =activate= script won't override Harmony's environment setup. + +5. Verify installation: + #+begin_src bash + ls "$REPO_HOME/tool_shared/third_party/Python/bin/python3" + #+end_src + + The binary should exist and report a working Python interpreter when run. + +* Notes + +- The virtual environment is deliberately named =Python=, not =venv=, to reflect its role as a shared system component. +- Harmony environment scripts define and control =VIRTUAL_ENV=, =PYTHON_HOME=, and =PATH=, making Python activation seamless and uniform. +- There is no need to use Python’s =bin/activate= directly — it is fully replaced by Harmony’s environment logic. + +* Related Files + +- =tool_shared/bespoke/env= +- =tool_shared/bespoke/env_source= +- =env_developer=, =env_tester=, =env_toolsmith= + +* Last Verified + +2025-05-19 :: Activate/deactivate renamed post-install. Requires Harmony environment sourcing prior to execution. diff --git "a/tool_shared/document\360\237\226\211/install_Python.org" "b/tool_shared/document\360\237\226\211/install_Python.org" deleted file mode 100644 index 236940a..0000000 --- "a/tool_shared/document\360\237\226\211/install_Python.org" +++ /dev/null @@ -1,75 +0,0 @@ -#+TITLE: Installing Python in Harmony -#+AUTHOR: Thomas Walker Lynch -#+OPTIONS: toc:2 num:nil - -* Overview - -This document describes how to install a project-local Python environment under: - -#+begin_src bash -tool_shared/third_party/Python -#+end_src - -This environment is shared across the =developer= and =tester= roles and is automatically activated through their respective =env_= scripts. - -* Precondition - -Ensure the following: - -- You are in a POSIX shell with =python3= installed. -- The =python3-venv= package is available (on Debian: =sudo apt install python3-venv=). -- You have sourced the Harmony environment via =env_toolsmith= to initialize =REPO_HOME= and related variables. - -* Step-by-Step Installation - -1. Source the Harmony environment: - #+begin_src bash - source env_toolsmith - #+end_src - -2. Create the virtual environment: - #+begin_src bash - python3 -m venv "$REPO_HOME/tool_shared/third_party/Python" - #+end_src - -3. Activate it temporarily to install required packages: - #+begin_src bash - source "$REPO_HOME/tool_shared/third_party/Python/bin/activate" - pip install --upgrade pip - pip install pytest # Add any shared packages here - deactivate - #+end_src - -4. Rename Python's default activate and deactivate: - Harmony provides its own role-aware environment management. Using Python’s default activation scripts may interfere with prompt logic, PATH order, and role-specific behavior. - - Disable the default scripts by renaming them: - #+begin_src bash - mv "$REPO_HOME/tool_shared/third_party/Python/bin/activate" \ - "$REPO_HOME/tool_shared/third_party/Python/bin/activate_deprecated" - #+end_src - - This ensures that accidental sourcing of Python’s =activate= script won't override Harmony's environment setup. - -5. Verify installation: - #+begin_src bash - ls "$REPO_HOME/tool_shared/third_party/Python/bin/python3" - #+end_src - - The binary should exist and report a working Python interpreter when run. - -* Notes - -- The virtual environment is deliberately named =Python=, not =venv=, to reflect its role as a shared system component. -- Harmony environment scripts define and control =VIRTUAL_ENV=, =PYTHON_HOME=, and =PATH=, making Python activation seamless and uniform. -- There is no need to use Python’s =bin/activate= directly — it is fully replaced by Harmony’s environment logic. - -* Related Files - -- =tool_shared/bespoke🖉/env= -- =tool_shared/bespoke🖉/env_source= -- =env_developer=, =env_tester=, =env_toolsmith= - -* Last Verified - -2025-05-19 :: Activate/deactivate renamed post-install. Requires Harmony environment sourcing prior to execution.