mathai 2.1.2__tar.gz → 2.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.
- {mathai-2.1.2 → mathai-2.1.4}/PKG-INFO +29 -1
- {mathai-2.1.2 → mathai-2.1.4}/README.md +28 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/__init__.py +2 -0
- mathai-2.1.4/mathai/electronic.py +134 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/differentiation.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula_data.py +1 -1
- {mathai-2.1.2 → mathai-2.1.4}/mathai.egg-info/PKG-INFO +29 -1
- {mathai-2.1.2 → mathai-2.1.4}/mathai.egg-info/SOURCES.txt +1 -0
- {mathai-2.1.2 → mathai-2.1.4}/setup.py +1 -1
- {mathai-2.1.2 → mathai-2.1.4}/mathai/apart.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/base.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/decision.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/diff.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/expand.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/factor.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/integration.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/integration_trig.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/is_integrate_subs.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/lambda_compress.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/lambda_expand.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/lambda_reduce.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/limit_infinity.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/matrix_vectorization_calculus.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/power_rule.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/quadratic.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/statistics_1.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/statistics_2.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/test.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula/trigonometry_misc.marshal +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula_compiler.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/formula_interpretor.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/fraction.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/integrate.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/inverse.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/lambda_calculus.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/limit.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/linear.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/logic.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/matrix.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/ml.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/mlscalar.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/ode.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/parser.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/pde.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/printeq.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/qm.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/simplify.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/statistics.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/test.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/tool.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/trig.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai/univariate_inequality.py +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai.egg-info/dependency_links.txt +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai.egg-info/requires.txt +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/mathai.egg-info/top_level.txt +0 -0
- {mathai-2.1.2 → mathai-2.1.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mathai
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.4
|
|
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,32 @@ 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
|
+
graph = CircuitGraph(
|
|
426
|
+
node_list=[
|
|
427
|
+
Node(),
|
|
428
|
+
Node(),
|
|
429
|
+
Node("resistor", TreeNode("d_5")),
|
|
430
|
+
Node("resistor", TreeNode("d_5")),
|
|
431
|
+
Node(),
|
|
432
|
+
],
|
|
433
|
+
connection={0: [1], 1: [2, 3], 2: [4], 3: [4], 4: [5]}
|
|
434
|
+
)
|
|
435
|
+
print(find_resistance(graph, 0, 5))
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
#### Output
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
loading formulas from file...
|
|
442
|
+
done
|
|
443
|
+
|
|
444
|
+
5/2
|
|
445
|
+
```
|
|
446
|
+
|
|
419
447
|
### Questions solved using god() function
|
|
420
448
|
|
|
421
449
|
#### 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,32 @@ 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
|
+
graph = CircuitGraph(
|
|
411
|
+
node_list=[
|
|
412
|
+
Node(),
|
|
413
|
+
Node(),
|
|
414
|
+
Node("resistor", TreeNode("d_5")),
|
|
415
|
+
Node("resistor", TreeNode("d_5")),
|
|
416
|
+
Node(),
|
|
417
|
+
],
|
|
418
|
+
connection={0: [1], 1: [2, 3], 2: [4], 3: [4], 4: [5]}
|
|
419
|
+
)
|
|
420
|
+
print(find_resistance(graph, 0, 5))
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
#### Output
|
|
424
|
+
|
|
425
|
+
```
|
|
426
|
+
loading formulas from file...
|
|
427
|
+
done
|
|
428
|
+
|
|
429
|
+
5/2
|
|
430
|
+
```
|
|
431
|
+
|
|
404
432
|
### Questions solved using god() function
|
|
405
433
|
|
|
406
434
|
#### Code
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from .base import *
|
|
3
|
+
from .simplify import simplify
|
|
4
|
+
from .fraction import fraction
|
|
5
|
+
from .linear import linear_solve
|
|
6
|
+
from .inverse import inverse
|
|
7
|
+
from .expand import expand
|
|
8
|
+
|
|
9
|
+
class Node:
|
|
10
|
+
def __init__(self, node_type="wire", value=None, cell_direction=None):
|
|
11
|
+
self.node_type = node_type
|
|
12
|
+
self.value = value
|
|
13
|
+
self.cell_direction = cell_direction
|
|
14
|
+
class CircuitGraph:
|
|
15
|
+
def __init__(self, node_list=None, connection=None):
|
|
16
|
+
self.node_list = node_list if node_list else []
|
|
17
|
+
self.connection = connection if connection else {}
|
|
18
|
+
self.variable_list = [TreeNode(f"v_{i}") for i in range(26)]
|
|
19
|
+
def complete_connection(self):
|
|
20
|
+
lst = list(self.connection.items())
|
|
21
|
+
for node, edge in lst:
|
|
22
|
+
for item in edge:
|
|
23
|
+
if item not in self.connection.keys():
|
|
24
|
+
self.connection[item] = [node]
|
|
25
|
+
elif node not in self.connection[item]:
|
|
26
|
+
self.connection[item].append(node)
|
|
27
|
+
def loop_rule(self, cycle):
|
|
28
|
+
_, edge_cycle = cycle
|
|
29
|
+
loop_sum = None
|
|
30
|
+
for u, v in edge_cycle:
|
|
31
|
+
node_u = self.node_list[u]
|
|
32
|
+
current = self.current_map.get((u, v))
|
|
33
|
+
if node_u.node_type == "resistor" and node_u.value is not None:
|
|
34
|
+
term = current * node_u.value
|
|
35
|
+
loop_sum = term if loop_sum is None else loop_sum + term
|
|
36
|
+
if node_u.node_type == "cell" and node_u.value is not None:
|
|
37
|
+
if node_u.cell_direction == (u, v):
|
|
38
|
+
term = -node_u.value
|
|
39
|
+
else:
|
|
40
|
+
term = node_u.value
|
|
41
|
+
loop_sum = term if loop_sum is None else loop_sum + term
|
|
42
|
+
return loop_sum
|
|
43
|
+
def all_simple_cycle(self):
|
|
44
|
+
cycles = []
|
|
45
|
+
canonical_cycles = set()
|
|
46
|
+
def find_cycles(start_node, curr_node, parent_node, path):
|
|
47
|
+
for neighbor in self.connection.get(curr_node, []):
|
|
48
|
+
if neighbor == parent_node:
|
|
49
|
+
continue
|
|
50
|
+
if neighbor == start_node and len(path) >= 3:
|
|
51
|
+
cycle_nodes = path[:]
|
|
52
|
+
min_idx = cycle_nodes.index(min(cycle_nodes))
|
|
53
|
+
rotated = cycle_nodes[min_idx:] + cycle_nodes[:min_idx]
|
|
54
|
+
reversed_rotated = rotated[:1] + list(reversed(rotated[1:]))
|
|
55
|
+
canonical = tuple(min(rotated, reversed_rotated))
|
|
56
|
+
if canonical not in canonical_cycles:
|
|
57
|
+
canonical_cycles.add(canonical)
|
|
58
|
+
cycle_edges = [
|
|
59
|
+
(cycle_nodes[i], cycle_nodes[(i + 1) % len(cycle_nodes)])
|
|
60
|
+
for i in range(len(cycle_nodes))
|
|
61
|
+
]
|
|
62
|
+
cycles.append((cycle_nodes, cycle_edges))
|
|
63
|
+
elif neighbor not in path and neighbor > start_node:
|
|
64
|
+
find_cycles(start_node, neighbor, curr_node, path + [neighbor])
|
|
65
|
+
num_nodes = len(self.node_list) if self.node_list else len(self.connection)
|
|
66
|
+
for node in range(num_nodes):
|
|
67
|
+
find_cycles(node, node, None, [node])
|
|
68
|
+
return cycles
|
|
69
|
+
def current_direction_map(self):
|
|
70
|
+
direction_map = {}
|
|
71
|
+
start_node = 0
|
|
72
|
+
first_neighbor = self.connection[start_node][0]
|
|
73
|
+
v0 = self.variable_list.pop(0)
|
|
74
|
+
direction_map[(start_node, first_neighbor)] = v0
|
|
75
|
+
direction_map[(first_neighbor, start_node)] = -v0
|
|
76
|
+
while True:
|
|
77
|
+
progress = False
|
|
78
|
+
for node in range(len(self.node_list)):
|
|
79
|
+
neighbors = self.connection[node]
|
|
80
|
+
unassigned = [nbr for nbr in neighbors if (node, nbr) not in direction_map]
|
|
81
|
+
if len(unassigned) == 1:
|
|
82
|
+
last_nbr = unassigned[0]
|
|
83
|
+
total_in = None
|
|
84
|
+
for nbr in neighbors:
|
|
85
|
+
if (nbr, node) in direction_map:
|
|
86
|
+
inc = direction_map[(nbr, node)]
|
|
87
|
+
total_in = inc if total_in is None else total_in + inc
|
|
88
|
+
|
|
89
|
+
direction_map[(node, last_nbr)] = total_in
|
|
90
|
+
direction_map[(last_nbr, node)] = -total_in
|
|
91
|
+
progress = True
|
|
92
|
+
if progress:
|
|
93
|
+
continue
|
|
94
|
+
for node in range(len(self.node_list)):
|
|
95
|
+
neighbors = self.connection[node]
|
|
96
|
+
unassigned = [nbr for nbr in neighbors if (node, nbr) not in direction_map]
|
|
97
|
+
has_known_in = any((nbr, node) in direction_map for nbr in neighbors)
|
|
98
|
+
if len(unassigned) > 1 and has_known_in:
|
|
99
|
+
var = self.variable_list.pop(0)
|
|
100
|
+
target = unassigned[0]
|
|
101
|
+
direction_map[(node, target)] = var
|
|
102
|
+
direction_map[(target, node)] = -var
|
|
103
|
+
progress = True
|
|
104
|
+
break
|
|
105
|
+
if not progress:
|
|
106
|
+
break
|
|
107
|
+
return direction_map
|
|
108
|
+
def find_resistance(circuit, start, end):
|
|
109
|
+
if start not in circuit.connection.keys():
|
|
110
|
+
circuit.connection[start] = []
|
|
111
|
+
circuit.connection[start].append(end)
|
|
112
|
+
circuit.node_list.append(Node("cell", TreeNode("d_1"), (start, end)))
|
|
113
|
+
circuit.complete_connection()
|
|
114
|
+
circuit.current_map = circuit.current_direction_map()
|
|
115
|
+
cycles = circuit.all_simple_cycle()
|
|
116
|
+
eq_list = []
|
|
117
|
+
for cycle in cycles:
|
|
118
|
+
eq = circuit.loop_rule(cycle)
|
|
119
|
+
eq_list.append(expand(eq))
|
|
120
|
+
eq_list = operation("f_and", [TreeNode("f_eq", [item, TreeNode("d_0")]) for item in eq_list])
|
|
121
|
+
eq_list = simplify(fraction(simplify(eq_list)))
|
|
122
|
+
eq_list = linear_solve(eq_list)
|
|
123
|
+
var = vlist(circuit.current_map[(start, end)])[0]
|
|
124
|
+
result = None
|
|
125
|
+
if eq_list.name == "f_and":
|
|
126
|
+
for child in eq_list.children:
|
|
127
|
+
if [var] == vlist(child):
|
|
128
|
+
result = inverse(child.children[0], var)
|
|
129
|
+
else:
|
|
130
|
+
if [var] == vlist(child):
|
|
131
|
+
result = inverse(eq_list.children[0], var)
|
|
132
|
+
if result is None:
|
|
133
|
+
return None
|
|
134
|
+
return TreeNode("d_1")/replace(circuit.current_map[(start, end)], tree_form(var), result)
|
|
Binary file
|
|
@@ -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
|
|
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.
|
|
3
|
+
Version: 2.1.4
|
|
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,32 @@ 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
|
+
graph = CircuitGraph(
|
|
426
|
+
node_list=[
|
|
427
|
+
Node(),
|
|
428
|
+
Node(),
|
|
429
|
+
Node("resistor", TreeNode("d_5")),
|
|
430
|
+
Node("resistor", TreeNode("d_5")),
|
|
431
|
+
Node(),
|
|
432
|
+
],
|
|
433
|
+
connection={0: [1], 1: [2, 3], 2: [4], 3: [4], 4: [5]}
|
|
434
|
+
)
|
|
435
|
+
print(find_resistance(graph, 0, 5))
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
#### Output
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
loading formulas from file...
|
|
442
|
+
done
|
|
443
|
+
|
|
444
|
+
5/2
|
|
445
|
+
```
|
|
446
|
+
|
|
419
447
|
### Questions solved using god() function
|
|
420
448
|
|
|
421
449
|
#### Code
|
|
@@ -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.
|
|
5
|
+
version="2.1.4",
|
|
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
|
|
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
|