caesium-toolkit 0.1.2__tar.gz → 0.1.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: caesium-toolkit
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A beginner-friendly toolkit to make Python and life easy.
5
5
  Requires-Python: >=3.8
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "caesium-toolkit"
7
- version = "0.1.2"
7
+ version = "0.1.4"
8
8
  description = "A beginner-friendly toolkit to make Python and life easy."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -14,4 +14,5 @@ dependencies = [
14
14
  ]
15
15
 
16
16
  [tool.setuptools.packages.find]
17
+ where = ["src"]
17
18
  include = ["caesium_toolkit*"]
@@ -0,0 +1,2 @@
1
+ from .client import *
2
+ from .llm import *
@@ -0,0 +1,164 @@
1
+ import math
2
+ import cmath
3
+
4
+
5
+ def quadratic(a=None, b=None, c=None):
6
+ """Solves a quadratic equation ax² + bx + c = 0 for real roots."""
7
+ if a is None:
8
+ a = float(input('Enter a from your quadratic (ax² + bx + c = 0): '))
9
+ if b is None:
10
+ b = float(input('Enter b from your quadratic (ax² + bx + c = 0): '))
11
+ if c is None:
12
+ c = float(input('Enter c from your quadratic (ax² + bx + c = 0): '))
13
+
14
+ if a == 0:
15
+ print("If 'a' is 0, this is a linear equation, not a quadratic.")
16
+ return None
17
+
18
+ d = b ** 2
19
+ e = 4 * a * c
20
+ f = d - e
21
+ g = 2 * a
22
+ h = -1 * b
23
+
24
+ if f > 0:
25
+ print('Quadratic has two real roots. Proceeding to solve...')
26
+ k = math.sqrt(f)
27
+ l = (h + k) / g
28
+ m = (h - k) / g
29
+ print(f'x = {l} or {m}.')
30
+ return l, m
31
+ elif f == 0:
32
+ print('Quadratic has one real root. Proceeding to solve...')
33
+ p = h / g
34
+ print(f'x = {p}.')
35
+ return p
36
+ else:
37
+ print('Quadratic has no real roots. Use imag_quadratic()')
38
+ return None
39
+
40
+
41
+ def imag_quadratic(a=None, b=None, c=None):
42
+ """Solves a quadratic equation ax² + bx + c = 0 for imaginary roots."""
43
+ if a is None:
44
+ a = float(input('Enter a from your quadratic (ax² + bx + c = 0): '))
45
+ if b is None:
46
+ b = float(input('Enter b from your quadratic (ax² + bx + c = 0): '))
47
+ if c is None:
48
+ c = float(input('Enter c from your quadratic (ax² + bx + c = 0): '))
49
+
50
+ if a == 0:
51
+ print("If 'a' is 0, this is a linear equation, not a quadratic.")
52
+ return None
53
+
54
+ d = b ** 2
55
+ e = 4 * a * c
56
+ f = d - e
57
+ g = 2 * a
58
+ h = -1 * b
59
+
60
+ if f >= 0:
61
+ print('Quadratic has real roots. Use quadratic()')
62
+ return None
63
+ else:
64
+ print('Quadratic has two imaginary roots. Proceeding to solve...')
65
+ k = cmath.sqrt(f)
66
+ l = (h + k) / g
67
+ m = (h - k) / g
68
+ print(f'x = {l} or {m}.')
69
+ return l, m
70
+
71
+
72
+ def factors(x=None):
73
+ """Prints and returns a list of all positive factors of x."""
74
+ if x is None:
75
+ x = int(input('Input the number whose factors will be displayed: '))
76
+
77
+ y = []
78
+ for i in range(1, x + 1):
79
+ if x % i == 0:
80
+ y.append(i)
81
+
82
+ print(y)
83
+ return y
84
+
85
+
86
+ def is_prime(x=None):
87
+ """Checks if x is a prime number, printing and returning True or False."""
88
+ if x is None:
89
+ x = int(input('Input a number to check if it is prime: '))
90
+
91
+ result = x >= 2 and len(factors(x)) == 2
92
+ print(result)
93
+ return result
94
+ import cmath
95
+ import math
96
+
97
+
98
+ def cubic(a=None, b=None, c=None, d=None):
99
+ """Solves a cubic equation ax³ + bx² + cx + d = 0 for all three roots."""
100
+ if a is None:
101
+ a = float(input('Enter a from your cubic (ax³ + bx² + cx + d = 0): '))
102
+ if b is None:
103
+ b = float(input('Enter b from your cubic (ax³ + bx² + cx + d = 0): '))
104
+ if c is None:
105
+ c = float(input('Enter c from your cubic (ax³ + bx² + cx + d = 0): '))
106
+ if d is None:
107
+ d = float(input('Enter d from your cubic (ax³ + bx² + cx + d = 0): '))
108
+
109
+ if a == 0:
110
+ print("If 'a' is 0, this is not a cubic.")
111
+ return None
112
+
113
+ s = b / (3 * a)
114
+ t = 3 * a * c - b**2
115
+ p = t / (3 * a**2)
116
+
117
+ w = 2 * (b**3) - 9 * a * b * c + 27 * (a**2) * d
118
+ q = w / (27 * (a**3))
119
+
120
+ delta = (q / 2) ** 2 + (p / 3) ** 3
121
+
122
+ if delta > 1e-12:
123
+ print(
124
+ 'Cubic has one real root and two complex roots. Proceeding to solve...'
125
+ )
126
+ sqrt_delta = math.sqrt(delta)
127
+ u = math.cbrt(-q / 2 + sqrt_delta)
128
+ v = math.cbrt(-q / 2 - sqrt_delta)
129
+
130
+ x1 = round((u + v) - s, 10) + 0.0
131
+ real_part = round(-0.5 * (u + v) - s, 10) + 0.0
132
+ imag_part = round((math.sqrt(3) / 2) * (u - v), 10) + 0.0
133
+
134
+ x2 = complex(real_part, imag_part)
135
+ x3 = complex(real_part, -imag_part + 0.0)
136
+ print(f'x = {x1}, {x2}, or {x3}.')
137
+ return x1, x2, x3
138
+
139
+ elif abs(delta) <= 1e-12:
140
+ if abs(p) < 1e-12 and abs(q) < 1e-12:
141
+ print('Cubic has one triple real root. Proceeding to solve...')
142
+ x1 = round(-s, 10) + 0.0
143
+ print(f'x = {x1}.')
144
+ return x1, x1, x1
145
+ else:
146
+ print('Cubic has repeated real roots. Proceeding to solve...')
147
+ x1 = round((3 * q / p) - s, 10) + 0.0
148
+ x2 = round((-3 * q / (2 * p)) - s, 10) + 0.0
149
+ print(f'x = {x1} or {x2} (double root).')
150
+ return x1, x2, x2
151
+
152
+ else:
153
+ print('Cubic has three distinct real roots. Proceeding to solve...')
154
+ r = 2 * math.sqrt(-p / 3)
155
+ cos_val = (3 * q) / (2 * p) * math.sqrt(-3 / p)
156
+ cos_val = max(-1.0, min(1.0, cos_val))
157
+ theta = math.acos(cos_val) / 3
158
+
159
+ x1 = round(r * math.cos(theta) - s, 10) + 0.0
160
+ x2 = round(r * math.cos(theta - (2 * math.pi / 3)) - s, 10) + 0.0
161
+ x3 = round(r * math.cos(theta - (4 * math.pi / 3)) - s, 10) + 0.0
162
+ print(f'x = {x1}, {x2}, or {x3}.')
163
+ return x1, x2, x3
164
+
@@ -0,0 +1,32 @@
1
+ _llm = None
2
+
3
+
4
+ def _get_model():
5
+ global _llm
6
+ if _llm is None:
7
+ from llama_cpp import Llama
8
+ _llm = Llama.from_pretrained(
9
+ repo_id='Qwen/Qwen2.5-Math-1.5B-Instruct-GGUF',
10
+ filename='qwen2.5-math-1.5b-instruct-q4_k_m.gguf',
11
+ n_ctx=2048,
12
+ verbose=False,
13
+ )
14
+ return _llm
15
+
16
+
17
+ def ask_ai(problem=None):
18
+ if problem is None:
19
+ problem = input('Enter your math problem or question: ')
20
+
21
+ llm = _get_model()
22
+ response = llm.create_chat_completion(
23
+ messages=[
24
+ {'role': 'system', 'content': 'You are a concise math tutor.'},
25
+ {'role': 'user', 'content': problem},
26
+ ],
27
+ max_tokens=512,
28
+ temperature=0.1,
29
+ )
30
+ answer = response['choices'][0]['message']['content'].strip()
31
+ print(answer)
32
+ return answer
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: caesium-toolkit
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A beginner-friendly toolkit to make Python and life easy.
5
5
  Requires-Python: >=3.8
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/caesium_toolkit/_init_.py
5
+ src/caesium_toolkit/client.py
6
+ src/caesium_toolkit/llm.py
7
+ src/caesium_toolkit.egg-info/PKG-INFO
8
+ src/caesium_toolkit.egg-info/SOURCES.txt
9
+ src/caesium_toolkit.egg-info/dependency_links.txt
10
+ src/caesium_toolkit.egg-info/requires.txt
11
+ src/caesium_toolkit.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ caesium_toolkit
@@ -1,8 +0,0 @@
1
- LICENSE
2
- README.md
3
- pyproject.toml
4
- caesium_toolkit.egg-info/PKG-INFO
5
- caesium_toolkit.egg-info/SOURCES.txt
6
- caesium_toolkit.egg-info/dependency_links.txt
7
- caesium_toolkit.egg-info/requires.txt
8
- caesium_toolkit.egg-info/top_level.txt
File without changes