Symbolic Computation & Scientific Expression Layer for Python
Write math with π, √, ², × — execute as Python.
from variableplus import calc
calc("π × r²", r=5) # → 78.54
calc("√(a² + b²)", a=3, b=4) # → 5.0
calc("5!") # → 120
calc("25% × 200") # → 50.0
calc("|-10|") # → 10pip install variableplusFrom source:
git clone https://github.com/Arinaranetwork/Variableplus
cd variableplus
pip install -e .from variableplus import calc
# Circle area
result = calc("π × r²", r=5)
print(result) # 78.53981633974483
# Pythagorean theorem
calc("√(a² + b²)", a=3, b=4) # 5.0
# Assignment expressions return dict
calc("F = m × a", m=10, a=9.8) # {'F': 98.0}| Category | Symbols | Example |
|---|---|---|
| Constants | π e τ φ |
calc("2π") → 6.28 |
| Operators | × ÷ − ± |
calc("a × b", a=3, b=4) → 12 |
| Powers | ² ³ ⁴...⁹ or ^n |
calc("r²", r=5) → 25 |
| Fractions | ½ ⅓ ¼ ⅔ ¾ |
calc("½ × 10") → 5.0 |
| Function | Symbol | Example |
|---|---|---|
| Square root | √ |
calc("√16") → 4.0 |
| Cube root | ∛ |
calc("∛8") → 2.0 |
| Trig | sin cos tan | calc("sin(θ)", θ=1.57) → 1.0 |
| Inverse trig | asin acos atan | calc("asin(1)") → π/2 |
| Logarithm | log ln lg | calc("log(100)") → 2.0 |
| Exponential | exp | calc("exp(1)") → e |
| Feature | Syntax | Example |
|---|---|---|
| Factorial | n! |
calc("5!") → 120 |
| Percent | n% |
calc("25% × 200") → 50.0 |
| Absolute | |x| |
calc("|-5|") → 5 |
Use as variables: α β γ δ ε θ λ μ σ φ ω
calc("θ² + φ²", θ=3, φ=4) # 25from variableplus import calc_math
from variableplus.domains import MathDomain
calc_math("π × r²", r=10) # Circle area
MathDomain.pythagorean(3, 4) # → 5.0
MathDomain.quadratic(1, -5, 6) # → (3.0, 2.0)from variableplus import calc_physics
from variableplus.domains import PhysicsDomain
# Speed of light (c) auto-included
calc_physics("E = m × c²", m=1) # → {'E': 8.99e+16}
PhysicsDomain.kinetic_energy(mass=10, velocity=5) # → 125.0 Jfrom variableplus import calc_chem
from variableplus.domains import ChemistryDomain
calc_chem("n = m ÷ M", m=18, M=18.016) # → {'n': 0.999}
ChemistryDomain.molecular_mass({"H": 2, "O": 1}) # → 18.016 g/molpython -m variableplus.repl
# or
vplusVariable+ v0.3 - Interactive Calculator
Type :help for commands, :quit to exit
>>> r = 5
Variable 'r' set to 5
>>> π × r²
78.53981633974483
>>> :show √(a² + b²)
Python: math.sqrt(a**2+b**2)
from variableplus import show_translation
show_translation("π × r²") # → 'math.pi*r**2'
show_translation("√(a² + b²)") # → 'math.sqrt(a**2+b**2)'
show_translation("5!") # → 'math.factorial(5)'
show_translation("|x|") # → 'abs(x)'Variable+ uses sandboxed evaluation:
- ✅
mathmodule only - ✅ AST validation before execution
- ❌ No
__builtins__access - ❌ No imports allowed
- ❌ No function/class definitions
from variableplus import calc
from variableplus.errors import MissingVariableError
try:
calc("π × r²") # Forgot r
except MissingVariableError as e:
print(e)
# Missing variable 'r'.
# Hint: Pass r=<value> to calc()| Error | Description |
|---|---|
UnknownSymbolError |
Unrecognized symbol |
InvalidExpressionError |
Syntax problem |
MissingVariableError |
Variable not provided |
EvaluationError |
Runtime error |
SecurityError |
Blocked operation |
variableplus/
├── __init__.py # calc(), v0.3.0
├── errors.py # Custom exceptions
├── repl.py # Interactive mode
├── core/
│ ├── tokenizer.py # Expression → tokens
│ ├── translator.py # Tokens → Python
│ └── evaluator.py # Safe execution
├── symbols/
│ └── table.json # 90+ symbol mappings
└── domains/
├── math.py # Math formulas
├── physics.py # Physics constants
└── chemistry.py # Stoichiometry
Humans write symbols, machines execute logic.
For:
- 📚 Students learning STEM
- 👩🏫 Educators creating materials
- 🔬 Researchers doing calculations
- 🎨 Visual thinkers
Not for:
- High-performance computing
- Full symbolic algebra (use SymPy)
- Production backends
Variable+ is licensed under Arinara Network License 1. Use, modification, distribution, and commercial use are permitted with visible credit to Arinara Network and retention of the license notice.
- Fork repository
- Create feature branch
- Submit pull request
Focus: symbol accuracy, edge cases, documentation.