Skip to content

Arinaranetwork/Variableplus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Variable+

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|")                 # → 10

📦 Installation

pip install variableplus

From source:

git clone https://github.com/Arinaranetwork/Variableplus
cd variableplus
pip install -e .

🚀 Quick Start

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}

✨ Supported Notation

Symbols & Operators

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

Functions

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

Special (v0.3)

Feature Syntax Example
Factorial n! calc("5!") → 120
Percent n% calc("25% × 200") → 50.0
Absolute |x| calc("|-5|") → 5

Greek Letters

Use as variables: α β γ δ ε θ λ μ σ φ ω

calc("θ² + φ²", θ=3, φ=4)  # 25

🔬 Domain Modules

Mathematics

from 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)

Physics

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 J

Chemistry

from 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/mol

🔧 Interactive REPL

python -m variableplus.repl
# or
vplus
Variable+ 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)

🔍 Debug Translation

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)'

🛡️ Security

Variable+ uses sandboxed evaluation:

  • math module only
  • ✅ AST validation before execution
  • ❌ No __builtins__ access
  • ❌ No imports allowed
  • ❌ No function/class definitions

⚠️ Error Handling

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

📁 Project Structure

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

🎯 Design Philosophy

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

📜 License

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.


🤝 Contributing

  1. Fork repository
  2. Create feature branch
  3. Submit pull request

Focus: symbol accuracy, edge cases, documentation.

Releases

Packages

Contributors

Languages