arcade-math 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arcade_math-1.0.4/.gitignore +175 -0
- arcade_math-1.0.4/.pre-commit-config.yaml +18 -0
- arcade_math-1.0.4/.ruff.toml +47 -0
- arcade_math-1.0.4/LICENSE +21 -0
- arcade_math-1.0.4/Makefile +55 -0
- arcade_math-1.0.4/PKG-INFO +19 -0
- arcade_math-1.0.4/arcade_math/__init__.py +0 -0
- arcade_math-1.0.4/arcade_math/tools/__init__.py +65 -0
- arcade_math-1.0.4/arcade_math/tools/arithmetic.py +97 -0
- arcade_math-1.0.4/arcade_math/tools/exponents.py +32 -0
- arcade_math-1.0.4/arcade_math/tools/miscellaneous.py +42 -0
- arcade_math-1.0.4/arcade_math/tools/random.py +38 -0
- arcade_math-1.0.4/arcade_math/tools/rational.py +30 -0
- arcade_math-1.0.4/arcade_math/tools/rounding.py +47 -0
- arcade_math-1.0.4/arcade_math/tools/statistics.py +34 -0
- arcade_math-1.0.4/arcade_math/tools/trigonometry.py +30 -0
- arcade_math-1.0.4/evals/eval_math_tools.py +131 -0
- arcade_math-1.0.4/pyproject.toml +56 -0
- arcade_math-1.0.4/tests/__init__.py +0 -0
- arcade_math-1.0.4/tests/test_arithmetic.py +147 -0
- arcade_math-1.0.4/tests/test_exponents.py +41 -0
- arcade_math-1.0.4/tests/test_miscellaneous.py +81 -0
- arcade_math-1.0.4/tests/test_rational.py +31 -0
- arcade_math-1.0.4/tests/test_rounding.py +54 -0
- arcade_math-1.0.4/tests/test_statistics.py +18 -0
- arcade_math-1.0.4/tests/test_trigonometry.py +45 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
credentials.yaml
|
|
3
|
+
docker/credentials.yaml
|
|
4
|
+
|
|
5
|
+
*.lock
|
|
6
|
+
|
|
7
|
+
# example data
|
|
8
|
+
examples/data
|
|
9
|
+
scratch
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
docs/source
|
|
13
|
+
|
|
14
|
+
# From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
|
|
15
|
+
|
|
16
|
+
# Byte-compiled / optimized / DLL files
|
|
17
|
+
__pycache__/
|
|
18
|
+
*.py[cod]
|
|
19
|
+
*$py.class
|
|
20
|
+
|
|
21
|
+
# C extensions
|
|
22
|
+
*.so
|
|
23
|
+
|
|
24
|
+
# Distribution / packaging
|
|
25
|
+
.Python
|
|
26
|
+
build/
|
|
27
|
+
develop-eggs/
|
|
28
|
+
dist/
|
|
29
|
+
downloads/
|
|
30
|
+
eggs/
|
|
31
|
+
.eggs/
|
|
32
|
+
lib/
|
|
33
|
+
lib64/
|
|
34
|
+
parts/
|
|
35
|
+
sdist/
|
|
36
|
+
var/
|
|
37
|
+
wheels/
|
|
38
|
+
share/python-wheels/
|
|
39
|
+
*.egg-info/
|
|
40
|
+
.installed.cfg
|
|
41
|
+
*.egg
|
|
42
|
+
MANIFEST
|
|
43
|
+
|
|
44
|
+
# PyInstaller
|
|
45
|
+
# Usually these files are written by a python script from a template
|
|
46
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
47
|
+
*.manifest
|
|
48
|
+
*.spec
|
|
49
|
+
|
|
50
|
+
# Installer logs
|
|
51
|
+
pip-log.txt
|
|
52
|
+
pip-delete-this-directory.txt
|
|
53
|
+
|
|
54
|
+
# Unit test / coverage reports
|
|
55
|
+
htmlcov/
|
|
56
|
+
.tox/
|
|
57
|
+
.nox/
|
|
58
|
+
.coverage
|
|
59
|
+
.coverage.*
|
|
60
|
+
.cache
|
|
61
|
+
nosetests.xml
|
|
62
|
+
coverage.xml
|
|
63
|
+
*.cover
|
|
64
|
+
*.py,cover
|
|
65
|
+
.hypothesis/
|
|
66
|
+
.pytest_cache/
|
|
67
|
+
cover/
|
|
68
|
+
|
|
69
|
+
# Translations
|
|
70
|
+
*.mo
|
|
71
|
+
*.pot
|
|
72
|
+
|
|
73
|
+
# Django stuff:
|
|
74
|
+
*.log
|
|
75
|
+
local_settings.py
|
|
76
|
+
db.sqlite3
|
|
77
|
+
db.sqlite3-journal
|
|
78
|
+
|
|
79
|
+
# Flask stuff:
|
|
80
|
+
instance/
|
|
81
|
+
.webassets-cache
|
|
82
|
+
|
|
83
|
+
# Scrapy stuff:
|
|
84
|
+
.scrapy
|
|
85
|
+
|
|
86
|
+
# Sphinx documentation
|
|
87
|
+
docs/_build/
|
|
88
|
+
|
|
89
|
+
# PyBuilder
|
|
90
|
+
.pybuilder/
|
|
91
|
+
target/
|
|
92
|
+
|
|
93
|
+
# Jupyter Notebook
|
|
94
|
+
.ipynb_checkpoints
|
|
95
|
+
|
|
96
|
+
# IPython
|
|
97
|
+
profile_default/
|
|
98
|
+
ipython_config.py
|
|
99
|
+
|
|
100
|
+
# pyenv
|
|
101
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
102
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
103
|
+
# .python-version
|
|
104
|
+
|
|
105
|
+
# pipenv
|
|
106
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
107
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
108
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
109
|
+
# install all needed dependencies.
|
|
110
|
+
#Pipfile.lock
|
|
111
|
+
|
|
112
|
+
# poetry
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
114
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
115
|
+
# commonly ignored for libraries.
|
|
116
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
117
|
+
poetry.lock
|
|
118
|
+
|
|
119
|
+
# pdm
|
|
120
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
121
|
+
#pdm.lock
|
|
122
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
123
|
+
# in version control.
|
|
124
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
125
|
+
.pdm.toml
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.venv
|
|
140
|
+
env/
|
|
141
|
+
venv/
|
|
142
|
+
ENV/
|
|
143
|
+
env.bak/
|
|
144
|
+
venv.bak/
|
|
145
|
+
|
|
146
|
+
# Spyder project settings
|
|
147
|
+
.spyderproject
|
|
148
|
+
.spyproject
|
|
149
|
+
|
|
150
|
+
# Rope project settings
|
|
151
|
+
.ropeproject
|
|
152
|
+
|
|
153
|
+
# mkdocs documentation
|
|
154
|
+
/site
|
|
155
|
+
|
|
156
|
+
# mypy
|
|
157
|
+
.mypy_cache/
|
|
158
|
+
.dmypy.json
|
|
159
|
+
dmypy.json
|
|
160
|
+
|
|
161
|
+
# Pyre type checker
|
|
162
|
+
.pyre/
|
|
163
|
+
|
|
164
|
+
# pytype static type analyzer
|
|
165
|
+
.pytype/
|
|
166
|
+
|
|
167
|
+
# Cython debug symbols
|
|
168
|
+
cython_debug/
|
|
169
|
+
|
|
170
|
+
# PyCharm
|
|
171
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
172
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
173
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
174
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
175
|
+
#.idea/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
files: ^.*/math/.*
|
|
2
|
+
repos:
|
|
3
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
4
|
+
rev: "v4.4.0"
|
|
5
|
+
hooks:
|
|
6
|
+
- id: check-case-conflict
|
|
7
|
+
- id: check-merge-conflict
|
|
8
|
+
- id: check-toml
|
|
9
|
+
- id: check-yaml
|
|
10
|
+
- id: end-of-file-fixer
|
|
11
|
+
- id: trailing-whitespace
|
|
12
|
+
|
|
13
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
14
|
+
rev: v0.6.7
|
|
15
|
+
hooks:
|
|
16
|
+
- id: ruff
|
|
17
|
+
args: [--fix]
|
|
18
|
+
- id: ruff-format
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
target-version = "py310"
|
|
2
|
+
line-length = 100
|
|
3
|
+
fix = true
|
|
4
|
+
|
|
5
|
+
[lint]
|
|
6
|
+
select = [
|
|
7
|
+
# flake8-2020
|
|
8
|
+
"YTT",
|
|
9
|
+
# flake8-bandit
|
|
10
|
+
"S",
|
|
11
|
+
# flake8-bugbear
|
|
12
|
+
"B",
|
|
13
|
+
# flake8-builtins
|
|
14
|
+
"A",
|
|
15
|
+
# flake8-comprehensions
|
|
16
|
+
"C4",
|
|
17
|
+
# flake8-debugger
|
|
18
|
+
"T10",
|
|
19
|
+
# flake8-simplify
|
|
20
|
+
"SIM",
|
|
21
|
+
# isort
|
|
22
|
+
"I",
|
|
23
|
+
# mccabe
|
|
24
|
+
"C90",
|
|
25
|
+
# pycodestyle
|
|
26
|
+
"E", "W",
|
|
27
|
+
# pyflakes
|
|
28
|
+
"F",
|
|
29
|
+
# pygrep-hooks
|
|
30
|
+
"PGH",
|
|
31
|
+
# pyupgrade
|
|
32
|
+
"UP",
|
|
33
|
+
# ruff
|
|
34
|
+
"RUF",
|
|
35
|
+
# tryceratops
|
|
36
|
+
"TRY",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[lint.per-file-ignores]
|
|
40
|
+
"*" = ["TRY003", "B904"]
|
|
41
|
+
"**/tests/*" = ["S101", "E501"]
|
|
42
|
+
"**/evals/*" = ["S101", "E501"]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
[format]
|
|
46
|
+
preview = true
|
|
47
|
+
skip-magic-trailing-comma = false
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Arcade AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
.PHONY: help
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "🛠️ github Commands:\n"
|
|
5
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
6
|
+
|
|
7
|
+
.PHONY: install
|
|
8
|
+
install: ## Install the uv environment and install all packages with dependencies
|
|
9
|
+
@echo "🚀 Creating virtual environment and installing all packages using uv"
|
|
10
|
+
@uv sync --active --all-extras --no-sources
|
|
11
|
+
@if [ -f .pre-commit-config.yaml ]; then uv run --no-sources pre-commit install; fi
|
|
12
|
+
@echo "✅ All packages and dependencies installed via uv"
|
|
13
|
+
|
|
14
|
+
.PHONY: install-local
|
|
15
|
+
install-local: ## Install the uv environment and install all packages with dependencies with local Arcade sources
|
|
16
|
+
@echo "🚀 Creating virtual environment and installing all packages using uv"
|
|
17
|
+
@uv sync --active --all-extras
|
|
18
|
+
@if [ -f .pre-commit-config.yaml ]; then uv run pre-commit install; fi
|
|
19
|
+
@echo "✅ All packages and dependencies installed via uv"
|
|
20
|
+
|
|
21
|
+
.PHONY: build
|
|
22
|
+
build: clean-build ## Build wheel file using poetry
|
|
23
|
+
@echo "🚀 Creating wheel file"
|
|
24
|
+
uv build
|
|
25
|
+
|
|
26
|
+
.PHONY: clean-build
|
|
27
|
+
clean-build: ## clean build artifacts
|
|
28
|
+
@echo "🗑️ Cleaning dist directory"
|
|
29
|
+
rm -rf dist
|
|
30
|
+
|
|
31
|
+
.PHONY: test
|
|
32
|
+
test: ## Test the code with pytest
|
|
33
|
+
@echo "🚀 Testing code: Running pytest"
|
|
34
|
+
@uv run --no-sources pytest -W ignore -v --cov --cov-config=pyproject.toml --cov-report=xml
|
|
35
|
+
|
|
36
|
+
.PHONY: coverage
|
|
37
|
+
coverage: ## Generate coverage report
|
|
38
|
+
@echo "coverage report"
|
|
39
|
+
@uv run --no-sources coverage report
|
|
40
|
+
@echo "Generating coverage report"
|
|
41
|
+
@uv run --no-sources coverage html
|
|
42
|
+
|
|
43
|
+
.PHONY: bump-version
|
|
44
|
+
bump-version: ## Bump the version in the pyproject.toml file by a patch version
|
|
45
|
+
@echo "🚀 Bumping version in pyproject.toml"
|
|
46
|
+
uv version --no-sources --bump patch
|
|
47
|
+
|
|
48
|
+
.PHONY: check
|
|
49
|
+
check: ## Run code quality tools.
|
|
50
|
+
@if [ -f .pre-commit-config.yaml ]; then\
|
|
51
|
+
echo "🚀 Linting code: Running pre-commit";\
|
|
52
|
+
uv run --no-sources pre-commit run -a;\
|
|
53
|
+
fi
|
|
54
|
+
@echo "🚀 Static type checking: Running mypy"
|
|
55
|
+
@uv run --no-sources mypy --config-file=pyproject.toml
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arcade_math
|
|
3
|
+
Version: 1.0.4
|
|
4
|
+
Summary: Arcade.dev LLM tools for doing math
|
|
5
|
+
Author-email: Arcade <dev@arcade.dev>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: arcade-tdk<3.0.0,>=2.0.0
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: arcade-ai[evals]<3.0.0,>=2.0.0; extra == 'dev'
|
|
11
|
+
Requires-Dist: arcade-serve<3.0.0,>=2.0.0; extra == 'dev'
|
|
12
|
+
Requires-Dist: mypy<1.6.0,>=1.5.1; extra == 'dev'
|
|
13
|
+
Requires-Dist: pre-commit<3.5.0,>=3.4.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: pytest-asyncio<0.25.0,>=0.24.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest-cov<4.1.0,>=4.0.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: pytest-mock<3.12.0,>=3.11.1; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest<8.4.0,>=8.3.0; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff<0.8.0,>=0.7.4; extra == 'dev'
|
|
19
|
+
Requires-Dist: tox<4.12.0,>=4.11.1; extra == 'dev'
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from arcade_math.tools.arithmetic import (
|
|
2
|
+
add,
|
|
3
|
+
divide,
|
|
4
|
+
mod,
|
|
5
|
+
multiply,
|
|
6
|
+
subtract,
|
|
7
|
+
sum_list,
|
|
8
|
+
sum_range,
|
|
9
|
+
)
|
|
10
|
+
from arcade_math.tools.exponents import (
|
|
11
|
+
log,
|
|
12
|
+
power,
|
|
13
|
+
)
|
|
14
|
+
from arcade_math.tools.miscellaneous import (
|
|
15
|
+
abs_val,
|
|
16
|
+
factorial,
|
|
17
|
+
sqrt,
|
|
18
|
+
)
|
|
19
|
+
from arcade_math.tools.random import (
|
|
20
|
+
generate_random_float,
|
|
21
|
+
generate_random_int,
|
|
22
|
+
)
|
|
23
|
+
from arcade_math.tools.rational import (
|
|
24
|
+
gcd,
|
|
25
|
+
lcm,
|
|
26
|
+
)
|
|
27
|
+
from arcade_math.tools.rounding import (
|
|
28
|
+
ceil,
|
|
29
|
+
floor,
|
|
30
|
+
round_num,
|
|
31
|
+
)
|
|
32
|
+
from arcade_math.tools.statistics import (
|
|
33
|
+
avg,
|
|
34
|
+
median,
|
|
35
|
+
)
|
|
36
|
+
from arcade_math.tools.trigonometry import (
|
|
37
|
+
deg_to_rad,
|
|
38
|
+
rad_to_deg,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"add",
|
|
43
|
+
"subtract",
|
|
44
|
+
"multiply",
|
|
45
|
+
"divide",
|
|
46
|
+
"sum_list",
|
|
47
|
+
"sum_range",
|
|
48
|
+
"mod",
|
|
49
|
+
"log",
|
|
50
|
+
"power",
|
|
51
|
+
"abs_val",
|
|
52
|
+
"factorial",
|
|
53
|
+
"sqrt",
|
|
54
|
+
"generate_random_float",
|
|
55
|
+
"generate_random_int",
|
|
56
|
+
"gcd",
|
|
57
|
+
"lcm",
|
|
58
|
+
"ceil",
|
|
59
|
+
"floor",
|
|
60
|
+
"round_num",
|
|
61
|
+
"avg",
|
|
62
|
+
"median",
|
|
63
|
+
"deg_to_rad",
|
|
64
|
+
"rad_to_deg",
|
|
65
|
+
]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import decimal
|
|
2
|
+
from decimal import Decimal
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
from arcade_tdk import tool
|
|
6
|
+
|
|
7
|
+
decimal.getcontext().prec = 100
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@tool
|
|
11
|
+
def add(
|
|
12
|
+
a: Annotated[str, "The first number as a string"],
|
|
13
|
+
b: Annotated[str, "The second number as a string"],
|
|
14
|
+
) -> Annotated[str, "The sum of the two numbers as a string"]:
|
|
15
|
+
"""
|
|
16
|
+
Add two numbers together
|
|
17
|
+
"""
|
|
18
|
+
# Use Decimal for arbitrary precision
|
|
19
|
+
a_decimal = Decimal(a)
|
|
20
|
+
b_decimal = Decimal(b)
|
|
21
|
+
return str(a_decimal + b_decimal)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@tool
|
|
25
|
+
def subtract(
|
|
26
|
+
a: Annotated[str, "The first number as a string"],
|
|
27
|
+
b: Annotated[str, "The second number as a string"],
|
|
28
|
+
) -> Annotated[str, "The difference of the two numbers as a string"]:
|
|
29
|
+
"""
|
|
30
|
+
Subtract two numbers
|
|
31
|
+
"""
|
|
32
|
+
# Use Decimal for arbitrary precision
|
|
33
|
+
a_decimal = Decimal(a)
|
|
34
|
+
b_decimal = Decimal(b)
|
|
35
|
+
return str(a_decimal - b_decimal)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@tool
|
|
39
|
+
def multiply(
|
|
40
|
+
a: Annotated[str, "The first number as a string"],
|
|
41
|
+
b: Annotated[str, "The second number as a string"],
|
|
42
|
+
) -> Annotated[str, "The product of the two numbers as a string"]:
|
|
43
|
+
"""
|
|
44
|
+
Multiply two numbers together
|
|
45
|
+
"""
|
|
46
|
+
# Use Decimal for arbitrary precision
|
|
47
|
+
a_decimal = Decimal(a)
|
|
48
|
+
b_decimal = Decimal(b)
|
|
49
|
+
return str(a_decimal * b_decimal)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@tool
|
|
53
|
+
def divide(
|
|
54
|
+
a: Annotated[str, "The first number as a string"],
|
|
55
|
+
b: Annotated[str, "The second number as a string"],
|
|
56
|
+
) -> Annotated[str, "The quotient of the two numbers as a string"]:
|
|
57
|
+
"""
|
|
58
|
+
Divide two numbers
|
|
59
|
+
"""
|
|
60
|
+
# Use Decimal for arbitrary precision
|
|
61
|
+
a_decimal = Decimal(a)
|
|
62
|
+
b_decimal = Decimal(b)
|
|
63
|
+
return str(a_decimal / b_decimal)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@tool
|
|
67
|
+
def sum_list(
|
|
68
|
+
numbers: Annotated[list[str], "The list of numbers as strings"],
|
|
69
|
+
) -> Annotated[str, "The sum of the numbers in the list as a string"]:
|
|
70
|
+
"""
|
|
71
|
+
Sum all numbers in a list
|
|
72
|
+
"""
|
|
73
|
+
# Use Decimal for arbitrary precision
|
|
74
|
+
return str(sum([Decimal(n) for n in numbers]))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@tool
|
|
78
|
+
def sum_range(
|
|
79
|
+
start: Annotated[str, "The start of the range to sum as a string"],
|
|
80
|
+
end: Annotated[str, "The end of the range to sum as a string"],
|
|
81
|
+
) -> Annotated[str, "The sum of the numbers in the list as a string"]:
|
|
82
|
+
"""
|
|
83
|
+
Sum all numbers from start through end
|
|
84
|
+
"""
|
|
85
|
+
return str(sum(list(range(int(start), int(end) + 1))))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
@tool
|
|
89
|
+
def mod(
|
|
90
|
+
a: Annotated[str, "The dividend as a string"],
|
|
91
|
+
b: Annotated[str, "The divisor as a string"],
|
|
92
|
+
) -> Annotated[str, "The remainder after dividing a by b as a string"]:
|
|
93
|
+
"""
|
|
94
|
+
Calculate the remainder (modulus) of one number divided by another
|
|
95
|
+
"""
|
|
96
|
+
# Use Decimal for arbitrary precision
|
|
97
|
+
return str(Decimal(a) % Decimal(b))
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import decimal
|
|
2
|
+
import math
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
from arcade_tdk import tool
|
|
7
|
+
|
|
8
|
+
decimal.getcontext().prec = 100
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@tool
|
|
12
|
+
def log(
|
|
13
|
+
a: Annotated[str, "The number to take the logarithm of as a string"],
|
|
14
|
+
base: Annotated[str, "The logarithmic base as a string"],
|
|
15
|
+
) -> Annotated[str, "The logarithm of the number with the specified base as a string"]:
|
|
16
|
+
"""
|
|
17
|
+
Calculate the logarithm of a number with a given base
|
|
18
|
+
"""
|
|
19
|
+
# Use Decimal for arbitrary precision
|
|
20
|
+
return str(math.log(Decimal(a), Decimal(base)))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@tool
|
|
24
|
+
def power(
|
|
25
|
+
a: Annotated[str, "The base number as a string"],
|
|
26
|
+
b: Annotated[str, "The exponent as a string"],
|
|
27
|
+
) -> Annotated[str, "The result of raising a to the power of b as a string"]:
|
|
28
|
+
"""
|
|
29
|
+
Calculate one number raised to the power of another
|
|
30
|
+
"""
|
|
31
|
+
# Use Decimal for arbitrary precision
|
|
32
|
+
return str(Decimal(a) ** Decimal(b))
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import decimal
|
|
2
|
+
import math
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
from arcade_tdk import tool
|
|
7
|
+
|
|
8
|
+
decimal.getcontext().prec = 100
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@tool
|
|
12
|
+
def abs_val(
|
|
13
|
+
a: Annotated[str, "The number as a string"],
|
|
14
|
+
) -> Annotated[str, "The absolute value of the number as a string"]:
|
|
15
|
+
"""
|
|
16
|
+
Calculate the absolute value of a number
|
|
17
|
+
"""
|
|
18
|
+
# Use Decimal for arbitrary precision
|
|
19
|
+
return str(abs(Decimal(a)))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@tool
|
|
23
|
+
def factorial(
|
|
24
|
+
a: Annotated[str, "The non-negative integer to compute the factorial for as a string"],
|
|
25
|
+
) -> Annotated[str, "The factorial of the number as a string"]:
|
|
26
|
+
"""
|
|
27
|
+
Compute the factorial of a non-negative integer
|
|
28
|
+
Returns "1" for "0"
|
|
29
|
+
"""
|
|
30
|
+
return str(math.factorial(int(a)))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@tool
|
|
34
|
+
def sqrt(
|
|
35
|
+
a: Annotated[str, "The number to square root as a string"],
|
|
36
|
+
) -> Annotated[str, "The square root of the number as a string"]:
|
|
37
|
+
"""
|
|
38
|
+
Get the square root of a number
|
|
39
|
+
"""
|
|
40
|
+
# Use Decimal for arbitrary precision
|
|
41
|
+
a_decimal = Decimal(a)
|
|
42
|
+
return str(a_decimal.sqrt())
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from typing import Annotated
|
|
3
|
+
|
|
4
|
+
from arcade_tdk import tool
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@tool
|
|
8
|
+
def generate_random_int(
|
|
9
|
+
min_value: Annotated[str, "The minimum value of the random integer as a string"],
|
|
10
|
+
max_value: Annotated[str, "The maximum value of the random integer as a string"],
|
|
11
|
+
seed: Annotated[
|
|
12
|
+
str | None,
|
|
13
|
+
"The seed for the random number generator as a string."
|
|
14
|
+
" If None, the current system time is used.",
|
|
15
|
+
] = None,
|
|
16
|
+
) -> Annotated[str, "A random integer between min_value and max_value as a string"]:
|
|
17
|
+
"""Generate a random integer between min_value and max_value (inclusive)."""
|
|
18
|
+
if seed is not None:
|
|
19
|
+
random.seed(int(seed))
|
|
20
|
+
|
|
21
|
+
return str(random.randint(int(min_value), int(max_value))) # noqa: S311
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@tool
|
|
25
|
+
def generate_random_float(
|
|
26
|
+
min_value: Annotated[str, "The minimum value of the random float as a string"],
|
|
27
|
+
max_value: Annotated[str, "The maximum value of the random float as a string"],
|
|
28
|
+
seed: Annotated[
|
|
29
|
+
str | None,
|
|
30
|
+
"The seed for the random number generator as a string."
|
|
31
|
+
" If None, the current system time is used.",
|
|
32
|
+
] = None,
|
|
33
|
+
) -> Annotated[str, "A random float between min_value and max_value as a string"]:
|
|
34
|
+
"""Generate a random float between min_value and max_value."""
|
|
35
|
+
if seed is not None:
|
|
36
|
+
random.seed(int(seed))
|
|
37
|
+
|
|
38
|
+
return str(random.uniform(float(min_value), float(max_value))) # noqa: S311
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Annotated
|
|
3
|
+
|
|
4
|
+
from arcade_tdk import tool
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@tool
|
|
8
|
+
def gcd(
|
|
9
|
+
a: Annotated[str, "First integer as a string"],
|
|
10
|
+
b: Annotated[str, "Second integer as a string"],
|
|
11
|
+
) -> Annotated[str, "The greatest common divisor of a and b as a string"]:
|
|
12
|
+
"""
|
|
13
|
+
Calculate the greatest common divisor (GCD) of two integers.
|
|
14
|
+
"""
|
|
15
|
+
return str(math.gcd(int(a), int(b)))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@tool
|
|
19
|
+
def lcm(
|
|
20
|
+
a: Annotated[str, "First integer as a string"],
|
|
21
|
+
b: Annotated[str, "Second integer as a string"],
|
|
22
|
+
) -> Annotated[str, "The least common multiple of a and b as a string"]:
|
|
23
|
+
"""
|
|
24
|
+
Calculate the least common multiple (LCM) of two integers.
|
|
25
|
+
Returns "0" if either integer is 0.
|
|
26
|
+
"""
|
|
27
|
+
a_int, b_int = int(a), int(b)
|
|
28
|
+
if a_int == 0 or b_int == 0:
|
|
29
|
+
return "0"
|
|
30
|
+
return str(abs(a_int * b_int) // math.gcd(a_int, b_int))
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import decimal
|
|
2
|
+
import math
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
from arcade_tdk import tool
|
|
7
|
+
|
|
8
|
+
decimal.getcontext().prec = 100
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@tool
|
|
12
|
+
def ceil(
|
|
13
|
+
a: Annotated[str, "The number to round up as a string"],
|
|
14
|
+
) -> Annotated[str, "The smallest integer greater than or equal to the number as a string"]:
|
|
15
|
+
"""
|
|
16
|
+
Return the ceiling of a number
|
|
17
|
+
"""
|
|
18
|
+
# Use Decimal for arbitrary precision
|
|
19
|
+
return str(math.ceil(Decimal(a)))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@tool
|
|
23
|
+
def floor(
|
|
24
|
+
a: Annotated[str, "The number to round down as a string"],
|
|
25
|
+
) -> Annotated[str, "The largest integer less than or equal to the number as a string"]:
|
|
26
|
+
"""
|
|
27
|
+
Return the floor of a number
|
|
28
|
+
"""
|
|
29
|
+
# Use Decimal for arbitrary precision
|
|
30
|
+
return str(math.floor(Decimal(a)))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@tool
|
|
34
|
+
def round_num(
|
|
35
|
+
value: Annotated[str, "The number to round as a string"],
|
|
36
|
+
ndigits: Annotated[str, "The number of digits after the decimal point as a string"],
|
|
37
|
+
) -> Annotated[str, "The number rounded to the specified number of digits as a string"]:
|
|
38
|
+
"""
|
|
39
|
+
Round a number to a specified number of positive digits
|
|
40
|
+
"""
|
|
41
|
+
ndigits_int = int(ndigits)
|
|
42
|
+
if ndigits_int >= 0:
|
|
43
|
+
# Use Decimal for arbitrary precision
|
|
44
|
+
return str(round(Decimal(value), int(ndigits_int)))
|
|
45
|
+
# cast value from str -> float -> int here because rounding with negative
|
|
46
|
+
# decimals is only useful for weird math
|
|
47
|
+
return str(round(int(float(value)), int(ndigits_int)))
|