mathai 2.1.2__tar.gz → 2.1.3__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.
Files changed (56) hide show
  1. {mathai-2.1.2 → mathai-2.1.3}/PKG-INFO +32 -1
  2. {mathai-2.1.2 → mathai-2.1.3}/README.md +31 -0
  3. {mathai-2.1.2 → mathai-2.1.3}/mathai/__init__.py +2 -0
  4. mathai-2.1.3/mathai/electronic.py +217 -0
  5. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/differentiation.marshal +0 -0
  6. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula_data.py +1 -1
  7. {mathai-2.1.2 → mathai-2.1.3}/mathai.egg-info/PKG-INFO +32 -1
  8. {mathai-2.1.2 → mathai-2.1.3}/mathai.egg-info/SOURCES.txt +1 -0
  9. {mathai-2.1.2 → mathai-2.1.3}/setup.py +1 -1
  10. {mathai-2.1.2 → mathai-2.1.3}/mathai/apart.py +0 -0
  11. {mathai-2.1.2 → mathai-2.1.3}/mathai/base.py +0 -0
  12. {mathai-2.1.2 → mathai-2.1.3}/mathai/decision.py +0 -0
  13. {mathai-2.1.2 → mathai-2.1.3}/mathai/diff.py +0 -0
  14. {mathai-2.1.2 → mathai-2.1.3}/mathai/expand.py +0 -0
  15. {mathai-2.1.2 → mathai-2.1.3}/mathai/factor.py +0 -0
  16. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/integration.marshal +0 -0
  17. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/integration_trig.marshal +0 -0
  18. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/is_integrate_subs.marshal +0 -0
  19. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/lambda_compress.marshal +0 -0
  20. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/lambda_expand.marshal +0 -0
  21. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/lambda_reduce.marshal +0 -0
  22. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/limit_infinity.marshal +0 -0
  23. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/matrix_vectorization_calculus.marshal +0 -0
  24. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/power_rule.marshal +0 -0
  25. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/quadratic.marshal +0 -0
  26. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/statistics_1.marshal +0 -0
  27. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/statistics_2.marshal +0 -0
  28. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/test.marshal +0 -0
  29. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula/trigonometry_misc.marshal +0 -0
  30. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula_compiler.py +0 -0
  31. {mathai-2.1.2 → mathai-2.1.3}/mathai/formula_interpretor.py +0 -0
  32. {mathai-2.1.2 → mathai-2.1.3}/mathai/fraction.py +0 -0
  33. {mathai-2.1.2 → mathai-2.1.3}/mathai/integrate.py +0 -0
  34. {mathai-2.1.2 → mathai-2.1.3}/mathai/inverse.py +0 -0
  35. {mathai-2.1.2 → mathai-2.1.3}/mathai/lambda_calculus.py +0 -0
  36. {mathai-2.1.2 → mathai-2.1.3}/mathai/limit.py +0 -0
  37. {mathai-2.1.2 → mathai-2.1.3}/mathai/linear.py +0 -0
  38. {mathai-2.1.2 → mathai-2.1.3}/mathai/logic.py +0 -0
  39. {mathai-2.1.2 → mathai-2.1.3}/mathai/matrix.py +0 -0
  40. {mathai-2.1.2 → mathai-2.1.3}/mathai/ml.py +0 -0
  41. {mathai-2.1.2 → mathai-2.1.3}/mathai/mlscalar.py +0 -0
  42. {mathai-2.1.2 → mathai-2.1.3}/mathai/ode.py +0 -0
  43. {mathai-2.1.2 → mathai-2.1.3}/mathai/parser.py +0 -0
  44. {mathai-2.1.2 → mathai-2.1.3}/mathai/pde.py +0 -0
  45. {mathai-2.1.2 → mathai-2.1.3}/mathai/printeq.py +0 -0
  46. {mathai-2.1.2 → mathai-2.1.3}/mathai/qm.py +0 -0
  47. {mathai-2.1.2 → mathai-2.1.3}/mathai/simplify.py +0 -0
  48. {mathai-2.1.2 → mathai-2.1.3}/mathai/statistics.py +0 -0
  49. {mathai-2.1.2 → mathai-2.1.3}/mathai/test.py +0 -0
  50. {mathai-2.1.2 → mathai-2.1.3}/mathai/tool.py +0 -0
  51. {mathai-2.1.2 → mathai-2.1.3}/mathai/trig.py +0 -0
  52. {mathai-2.1.2 → mathai-2.1.3}/mathai/univariate_inequality.py +0 -0
  53. {mathai-2.1.2 → mathai-2.1.3}/mathai.egg-info/dependency_links.txt +0 -0
  54. {mathai-2.1.2 → mathai-2.1.3}/mathai.egg-info/requires.txt +0 -0
  55. {mathai-2.1.2 → mathai-2.1.3}/mathai.egg-info/top_level.txt +0 -0
  56. {mathai-2.1.2 → mathai-2.1.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.1.2
3
+ Version: 2.1.3
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
@@ -377,6 +377,8 @@ from mathai import *
377
377
  test(10)
378
378
  ```
379
379
 
380
+ #### Output
381
+
380
382
  ```
381
383
  problems generated
382
384
  1. (-1+x)/y
@@ -416,6 +418,35 @@ answer
416
418
  -1
417
419
  ```
418
420
 
421
+ #### Example Demonstration 10 (equivalent resistance)
422
+ ```python
423
+ from mathai import *
424
+ load_formula_from_file()
425
+ j1 = Junction("J1")
426
+ j2 = Junction("J2")
427
+ r1 = Resistor("R1", 100)
428
+ r2 = Resistor("R2", 200)
429
+ r3 = Resistor("R3", 300)
430
+ circuit = CircuitGraph()
431
+ _, curr1 = circuit.connect(j1, r1)
432
+ circuit.connect(r1, j2, incoming_current=curr1)
433
+ _, curr2 = circuit.connect(j1, r2)
434
+ circuit.connect(r2, j2, incoming_current=curr2)
435
+ _, curr3 = circuit.connect(j1, r3)
436
+ circuit.connect(r3, j2, incoming_current=curr3)
437
+ out = solve_equivalent_resistance(circuit, j1, j2)
438
+ print(out)
439
+ ```
440
+
441
+ #### Output
442
+
443
+ ```
444
+ loading formulas from file...
445
+ done
446
+
447
+ 600/11
448
+ ```
449
+
419
450
  ### Questions solved using god() function
420
451
 
421
452
  #### Code
@@ -362,6 +362,8 @@ from mathai import *
362
362
  test(10)
363
363
  ```
364
364
 
365
+ #### Output
366
+
365
367
  ```
366
368
  problems generated
367
369
  1. (-1+x)/y
@@ -401,6 +403,35 @@ answer
401
403
  -1
402
404
  ```
403
405
 
406
+ #### Example Demonstration 10 (equivalent resistance)
407
+ ```python
408
+ from mathai import *
409
+ load_formula_from_file()
410
+ j1 = Junction("J1")
411
+ j2 = Junction("J2")
412
+ r1 = Resistor("R1", 100)
413
+ r2 = Resistor("R2", 200)
414
+ r3 = Resistor("R3", 300)
415
+ circuit = CircuitGraph()
416
+ _, curr1 = circuit.connect(j1, r1)
417
+ circuit.connect(r1, j2, incoming_current=curr1)
418
+ _, curr2 = circuit.connect(j1, r2)
419
+ circuit.connect(r2, j2, incoming_current=curr2)
420
+ _, curr3 = circuit.connect(j1, r3)
421
+ circuit.connect(r3, j2, incoming_current=curr3)
422
+ out = solve_equivalent_resistance(circuit, j1, j2)
423
+ print(out)
424
+ ```
425
+
426
+ #### Output
427
+
428
+ ```
429
+ loading formulas from file...
430
+ done
431
+
432
+ 600/11
433
+ ```
434
+
404
435
  ### Questions solved using god() function
405
436
 
406
437
  #### Code
@@ -7,6 +7,8 @@ from .qm import hydrogen_gse, helium_gse, power_rule
7
7
 
8
8
  from .lambda_calculus import lambda_expand, lambda_compress, lambda_reduce
9
9
 
10
+ from .electronic import Junction, Resistor, CircuitGraph, solve_equivalent_resistance
11
+
10
12
  from .linear import linear_solve
11
13
 
12
14
  from .test import test
@@ -0,0 +1,217 @@
1
+ import math
2
+ from PIL import Image, ImageDraw, ImageFont
3
+ from .base import *
4
+ from .simplify import simplify
5
+ from .fraction import fraction
6
+ from .linear import linear_solve
7
+ from .inverse import inverse
8
+
9
+ # =====================================================================
10
+ # 1. CORE DATA STRUCTURES
11
+ # =====================================================================
12
+
13
+
14
+ class Junction:
15
+
16
+ def __init__(self, name: str):
17
+ self.name = name
18
+
19
+ def __repr__(self):
20
+ return f"Junction('{self.name}')"
21
+
22
+
23
+ class Resistor:
24
+
25
+ def __init__(self, name: str, resistance: float):
26
+ self.name = name
27
+ self.resistance = resistance # in Ohms
28
+
29
+ def __repr__(self):
30
+ return f"Resistor('{self.name}', {self.resistance} ohms)"
31
+
32
+
33
+ class DirectedWire:
34
+
35
+ def __init__(
36
+ self,
37
+ source: Junction | Resistor,
38
+ target: Junction | Resistor,
39
+ current_name: str = "",
40
+ ):
41
+ self.source = source
42
+ self.target = target
43
+ self.current_name = current_name # e.g., 'I1', 'I2'
44
+
45
+ def __repr__(self):
46
+ label = f" ({self.current_name})" if self.current_name else ""
47
+ return f"Wire({self.source.name} -> {self.target.name}{label})"
48
+
49
+
50
+ class CircuitGraph:
51
+
52
+ def __init__(self):
53
+ self.adjacency_list = {}
54
+ self.degree = {}
55
+ self.current_counter = 1
56
+
57
+ def add_vertex(self, vertex: Junction | Resistor):
58
+ if vertex not in self.adjacency_list:
59
+ self.adjacency_list[vertex] = []
60
+ self.degree[vertex] = 0
61
+
62
+ def connect(
63
+ self,
64
+ source: Junction | Resistor,
65
+ target: Junction | Resistor,
66
+ incoming_current: str = None,
67
+ ):
68
+ self.add_vertex(source)
69
+ self.add_vertex(target)
70
+
71
+ src_degree = self.degree[source] + 1
72
+
73
+ if src_degree > 2 or not incoming_current:
74
+ current_name = f"I{self.current_counter}"
75
+ self.current_counter += 1
76
+ else:
77
+ current_name = incoming_current
78
+
79
+ wire = DirectedWire(source, target, current_name)
80
+ self.adjacency_list[source].append(wire)
81
+
82
+ self.degree[source] += 1
83
+ self.degree[target] += 1
84
+
85
+ return wire, current_name
86
+
87
+ def display(self):
88
+ print("=== CIRCUIT GRAPH ===")
89
+ for vertex, outgoing_wires in self.adjacency_list.items():
90
+ deg = self.degree[vertex]
91
+ node_type = "Principal Junction" if deg > 2 else "Series Node"
92
+ connections = [
93
+ f"--> {w.target.name} [Current: {w.current_name}]"
94
+ for w in outgoing_wires
95
+ ]
96
+ print(
97
+ f"{vertex} (Degree: {deg}, {node_type}) connections:"
98
+ f" {connections}"
99
+ )
100
+
101
+
102
+ # =====================================================================
103
+ # 2. EQUIVALENT RESISTANCE SOLVER FUNCTION
104
+ # =====================================================================
105
+
106
+
107
+ def solve_equivalent_resistance(
108
+ circuit_graph: CircuitGraph, j1: Junction, j2: Junction
109
+ ) -> TreeNode:
110
+ """Calculates the equivalent resistance between two junctions in a CircuitGraph."""
111
+
112
+ # 1. Variable Mapping
113
+ symbolic_vars = []
114
+
115
+ # Collect Nodal Potentials
116
+ junction_nodes = [
117
+ node
118
+ for node in circuit_graph.adjacency_list.keys()
119
+ if isinstance(node, Junction)
120
+ ]
121
+ for j in junction_nodes:
122
+ symbolic_vars.append(f"V_{j.name}")
123
+
124
+ # Collect Branch Currents & I_total
125
+ current_vars = set()
126
+ for src, wires in circuit_graph.adjacency_list.items():
127
+ for w in wires:
128
+ if w.current_name:
129
+ current_vars.add(w.current_name)
130
+
131
+ sorted_currents = sorted(
132
+ list(current_vars),
133
+ key=lambda x: int(x[1:]) if x[1:].isdigit() else x,
134
+ )
135
+ symbolic_vars.extend(sorted_currents)
136
+ symbolic_vars.append("I_total")
137
+
138
+ # Target variable: R_eq
139
+ req_symbol = f"R_eq_{j1.name}_{j2.name}"
140
+ symbolic_vars.append(req_symbol)
141
+
142
+ # Map symbols to v_0, v_1, ...
143
+ var_map = {orig: f"v_{i}" for i, orig in enumerate(symbolic_vars)}
144
+
145
+ # AST Helper functions
146
+ def make_var_node(symbol: str) -> TreeNode:
147
+ return TreeNode(var_map[symbol])
148
+
149
+ def make_const_node(val: int) -> TreeNode:
150
+ return TreeNode(f"d_{val}")
151
+
152
+ def build_addition_chain(node_list):
153
+ if not node_list:
154
+ return make_const_node(0)
155
+ res = node_list[0]
156
+ for n in node_list[1:]:
157
+ res = res + n
158
+ return res
159
+
160
+ system_trees = []
161
+
162
+ # 2. Build KCL Equation at J1
163
+ outgoing_currents = [
164
+ make_var_node(w.current_name)
165
+ for w in circuit_graph.adjacency_list.get(j1, [])
166
+ ]
167
+ kcl_tree = TreeNode(
168
+ "f_eq", [make_var_node("I_total"), build_addition_chain(outgoing_currents)]
169
+ )
170
+ system_trees.append(kcl_tree)
171
+
172
+ # 3. Build Branch Nodal Equations: (V_J1 - V_J2) = I_k * R_k
173
+ v_diff = make_var_node(f"V_{j1.name}") - make_var_node(f"V_{j2.name}")
174
+ for wire in circuit_graph.adjacency_list.get(j1, []):
175
+ if isinstance(wire.target, Resistor):
176
+ res_node = wire.target
177
+ i_var = make_var_node(wire.current_name)
178
+ r_val = make_const_node(int(res_node.resistance))
179
+ system_trees.append(TreeNode("f_eq", [v_diff, i_var * r_val]))
180
+
181
+ # 4. Ground Reference: V_J2 = 0
182
+ ground_eq = TreeNode(
183
+ "f_eq", [make_var_node(f"V_{j2.name}"), make_const_node(0)]
184
+ )
185
+ system_trees.append(ground_eq)
186
+
187
+ # 5. Definition of R_eq: R_eq = (V_J1 - V_J2) / I_total
188
+ req_tree = TreeNode(
189
+ "f_eq", [make_var_node(req_symbol), v_diff / make_var_node("I_total")]
190
+ )
191
+ system_trees.append(req_tree)
192
+
193
+ # 6. Substitute Boundary Condition I_total = 1
194
+ i_total_var_node = tree_form(var_map["I_total"])
195
+ one_node = tree_form("d_1")
196
+ system_trees = [
197
+ replace(tree, i_total_var_node, one_node) for tree in system_trees
198
+ ]
199
+
200
+ # 7. Solve Linear System
201
+ eq = simplify(fraction(simplify(operation("f_and", system_trees))))
202
+ solved_system = linear_solve(eq)
203
+
204
+ # 8. Extract Equation for R_eq
205
+ out = None
206
+ target_v_var = var_map[req_symbol]
207
+
208
+ if solved_system.name == "f_and":
209
+ for item in solved_system.children:
210
+ if vlist(item) and vlist(item)[0] == target_v_var:
211
+ out = inverse(item.children[0], target_v_var)
212
+ break
213
+ else:
214
+ if vlist(solved_system) and vlist(solved_system)[0] == target_v_var:
215
+ out = inverse(solved_system.children[0], target_v_var)
216
+
217
+ return out
@@ -64,7 +64,7 @@ pdif(arctan(a),x) (1/(1+a^2))*pdif(a,x) x _ k _ [[c,1],[d,1],[f,0],[g,0]] _ _ 2
64
64
  pdif(k,x) 0 x _ k _ _ _ _ 2
65
65
  pdif(x,x) 1 x _ k _ _ _ _ 2
66
66
  pdif(a*b,x) pdif(a,x)*b+a*pdif(b,x) x _ k _ [[a,1],[b,1],[a,0],[b,0]] _ _ 3
67
- pdif(a+b,x) pdif(a,x)+pdif(b,x) x _ k _ [[a,1],[b,1],[a,0],[b,0]] _ _ 3
67
+ c+pdif(a+b,x) c+pdif(a,x)+pdif(b,x) x c k _ [[c,1],[b,1],[a,0],[b,0]] _ _ 3
68
68
  pdif(k*a,x) k*pdif(a,x) x _ k _ [[a,1],[k,1],[a,0],[k,0]] _ _ 3
69
69
  // differentiation
70
70
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.1.2
3
+ Version: 2.1.3
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
@@ -377,6 +377,8 @@ from mathai import *
377
377
  test(10)
378
378
  ```
379
379
 
380
+ #### Output
381
+
380
382
  ```
381
383
  problems generated
382
384
  1. (-1+x)/y
@@ -416,6 +418,35 @@ answer
416
418
  -1
417
419
  ```
418
420
 
421
+ #### Example Demonstration 10 (equivalent resistance)
422
+ ```python
423
+ from mathai import *
424
+ load_formula_from_file()
425
+ j1 = Junction("J1")
426
+ j2 = Junction("J2")
427
+ r1 = Resistor("R1", 100)
428
+ r2 = Resistor("R2", 200)
429
+ r3 = Resistor("R3", 300)
430
+ circuit = CircuitGraph()
431
+ _, curr1 = circuit.connect(j1, r1)
432
+ circuit.connect(r1, j2, incoming_current=curr1)
433
+ _, curr2 = circuit.connect(j1, r2)
434
+ circuit.connect(r2, j2, incoming_current=curr2)
435
+ _, curr3 = circuit.connect(j1, r3)
436
+ circuit.connect(r3, j2, incoming_current=curr3)
437
+ out = solve_equivalent_resistance(circuit, j1, j2)
438
+ print(out)
439
+ ```
440
+
441
+ #### Output
442
+
443
+ ```
444
+ loading formulas from file...
445
+ done
446
+
447
+ 600/11
448
+ ```
449
+
419
450
  ### Questions solved using god() function
420
451
 
421
452
  #### Code
@@ -6,6 +6,7 @@ mathai/apart.py
6
6
  mathai/base.py
7
7
  mathai/decision.py
8
8
  mathai/diff.py
9
+ mathai/electronic.py
9
10
  mathai/expand.py
10
11
  mathai/factor.py
11
12
  mathai/formula_compiler.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
  from pathlib import Path
3
3
  setup(
4
4
  name="mathai",
5
- version="2.1.2",
5
+ version="2.1.3",
6
6
  description="Mathematics solving Ai tailored to NCERT",
7
7
  long_description=Path("README.md").read_text(encoding="utf-8"),
8
8
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes