mathai 2.1.8__tar.gz → 2.2.0__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.8 → mathai-2.2.0}/PKG-INFO +7 -4
  2. {mathai-2.1.8 → mathai-2.2.0}/README.md +5 -3
  3. {mathai-2.1.8 → mathai-2.2.0}/mathai/__init__.py +1 -1
  4. {mathai-2.1.8 → mathai-2.2.0}/mathai/electronic.py +195 -0
  5. {mathai-2.1.8 → mathai-2.2.0}/mathai.egg-info/PKG-INFO +7 -4
  6. {mathai-2.1.8 → mathai-2.2.0}/mathai.egg-info/requires.txt +1 -0
  7. {mathai-2.1.8 → mathai-2.2.0}/setup.py +3 -2
  8. {mathai-2.1.8 → mathai-2.2.0}/mathai/apart.py +0 -0
  9. {mathai-2.1.8 → mathai-2.2.0}/mathai/base.py +0 -0
  10. {mathai-2.1.8 → mathai-2.2.0}/mathai/decision.py +0 -0
  11. {mathai-2.1.8 → mathai-2.2.0}/mathai/diff.py +0 -0
  12. {mathai-2.1.8 → mathai-2.2.0}/mathai/expand.py +0 -0
  13. {mathai-2.1.8 → mathai-2.2.0}/mathai/factor.py +0 -0
  14. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/differentiation.marshal +0 -0
  15. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/integration.marshal +0 -0
  16. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/integration_trig.marshal +0 -0
  17. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/is_integrate_subs.marshal +0 -0
  18. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/lambda_compress.marshal +0 -0
  19. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/lambda_expand.marshal +0 -0
  20. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/lambda_reduce.marshal +0 -0
  21. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/limit_infinity.marshal +0 -0
  22. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/matrix_vectorization_calculus.marshal +0 -0
  23. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/power_rule.marshal +0 -0
  24. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/quadratic.marshal +0 -0
  25. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/statistics_1.marshal +0 -0
  26. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/statistics_2.marshal +0 -0
  27. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/test.marshal +0 -0
  28. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula/trigonometry_misc.marshal +0 -0
  29. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula_compiler.py +0 -0
  30. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula_data.py +0 -0
  31. {mathai-2.1.8 → mathai-2.2.0}/mathai/formula_interpretor.py +0 -0
  32. {mathai-2.1.8 → mathai-2.2.0}/mathai/fraction.py +0 -0
  33. {mathai-2.1.8 → mathai-2.2.0}/mathai/integrate.py +0 -0
  34. {mathai-2.1.8 → mathai-2.2.0}/mathai/inverse.py +0 -0
  35. {mathai-2.1.8 → mathai-2.2.0}/mathai/lambda_calculus.py +0 -0
  36. {mathai-2.1.8 → mathai-2.2.0}/mathai/limit.py +0 -0
  37. {mathai-2.1.8 → mathai-2.2.0}/mathai/linear.py +0 -0
  38. {mathai-2.1.8 → mathai-2.2.0}/mathai/logic.py +0 -0
  39. {mathai-2.1.8 → mathai-2.2.0}/mathai/matrix.py +0 -0
  40. {mathai-2.1.8 → mathai-2.2.0}/mathai/ml.py +0 -0
  41. {mathai-2.1.8 → mathai-2.2.0}/mathai/mlscalar.py +0 -0
  42. {mathai-2.1.8 → mathai-2.2.0}/mathai/ode.py +0 -0
  43. {mathai-2.1.8 → mathai-2.2.0}/mathai/parser.py +0 -0
  44. {mathai-2.1.8 → mathai-2.2.0}/mathai/pde.py +0 -0
  45. {mathai-2.1.8 → mathai-2.2.0}/mathai/printeq.py +0 -0
  46. {mathai-2.1.8 → mathai-2.2.0}/mathai/qm.py +0 -0
  47. {mathai-2.1.8 → mathai-2.2.0}/mathai/simplify.py +0 -0
  48. {mathai-2.1.8 → mathai-2.2.0}/mathai/statistics.py +0 -0
  49. {mathai-2.1.8 → mathai-2.2.0}/mathai/test.py +0 -0
  50. {mathai-2.1.8 → mathai-2.2.0}/mathai/tool.py +0 -0
  51. {mathai-2.1.8 → mathai-2.2.0}/mathai/trig.py +0 -0
  52. {mathai-2.1.8 → mathai-2.2.0}/mathai/univariate_inequality.py +0 -0
  53. {mathai-2.1.8 → mathai-2.2.0}/mathai.egg-info/SOURCES.txt +0 -0
  54. {mathai-2.1.8 → mathai-2.2.0}/mathai.egg-info/dependency_links.txt +0 -0
  55. {mathai-2.1.8 → mathai-2.2.0}/mathai.egg-info/top_level.txt +0 -0
  56. {mathai-2.1.8 → mathai-2.2.0}/setup.cfg +0 -0
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.1.8
3
+ Version: 2.2.0
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: more_itertools
9
+ Requires-Dist: schemdraw
9
10
  Dynamic: description
10
11
  Dynamic: description-content-type
11
12
  Dynamic: home-page
@@ -424,8 +425,8 @@ from mathai import *
424
425
  load_formula_from_file()
425
426
  wire_1 = Edge((0,1))
426
427
  ohm_10 = Edge((1,2), "resistor", TreeNode("d_10"))
427
- ohm_5 = Edge((1,3), "resistor", TreeNode("d_5"))
428
- ohm_6 = Edge((1,4), "resistor", TreeNode("d_6"))
428
+ ohm_5 = Edge((2,3), "resistor", TreeNode("d_5"))
429
+ ohm_6 = Edge((2,4), "resistor", TreeNode("d_6"))
429
430
  ohm_7 = Edge((4,5), "resistor", TreeNode("d_7"))
430
431
  ohm_8 = Edge((4,6), "resistor", TreeNode("d_8"))
431
432
  ohm_20 = Edge((6,7), "resistor", TreeNode("d_20"))
@@ -435,6 +436,7 @@ wire_4 = Edge((3,8))
435
436
  edge_list = [wire_1, wire_2, wire_3, wire_4, ohm_5, ohm_6, ohm_7, ohm_8, ohm_10, ohm_20]
436
437
  graph = CircuitGraph(9,edge_list,{})
437
438
  print(compute(find_resistance(graph, 0,8)))
439
+ draw_circuit(graph)
438
440
 
439
441
  wire_1 = Edge((0,1))
440
442
  ohm_5 = Edge((1,2), "resistor", TreeNode("d_5"))
@@ -451,6 +453,7 @@ wire_4 = Edge((4,9))
451
453
  edge_list = [wire_1, wire_2, wire_3, wire_4, ohm_5, ohm_6, ohm_7, ohm_8, ohm_8_2, ohm_10, ohm_11, ohm_20]
452
454
  graph = CircuitGraph(10,edge_list,{})
453
455
  print(compute(find_resistance(graph, 0, 9)))
456
+ draw_circuit(graph)
454
457
  ```
455
458
 
456
459
  #### Output
@@ -459,7 +462,7 @@ print(compute(find_resistance(graph, 0, 9)))
459
462
  loading formulas from file...
460
463
  done
461
464
 
462
- 3.493975903614458
465
+ 13.493975903614459
463
466
  8.66474543707973
464
467
  ```
465
468
 
@@ -409,8 +409,8 @@ from mathai import *
409
409
  load_formula_from_file()
410
410
  wire_1 = Edge((0,1))
411
411
  ohm_10 = Edge((1,2), "resistor", TreeNode("d_10"))
412
- ohm_5 = Edge((1,3), "resistor", TreeNode("d_5"))
413
- ohm_6 = Edge((1,4), "resistor", TreeNode("d_6"))
412
+ ohm_5 = Edge((2,3), "resistor", TreeNode("d_5"))
413
+ ohm_6 = Edge((2,4), "resistor", TreeNode("d_6"))
414
414
  ohm_7 = Edge((4,5), "resistor", TreeNode("d_7"))
415
415
  ohm_8 = Edge((4,6), "resistor", TreeNode("d_8"))
416
416
  ohm_20 = Edge((6,7), "resistor", TreeNode("d_20"))
@@ -420,6 +420,7 @@ wire_4 = Edge((3,8))
420
420
  edge_list = [wire_1, wire_2, wire_3, wire_4, ohm_5, ohm_6, ohm_7, ohm_8, ohm_10, ohm_20]
421
421
  graph = CircuitGraph(9,edge_list,{})
422
422
  print(compute(find_resistance(graph, 0,8)))
423
+ draw_circuit(graph)
423
424
 
424
425
  wire_1 = Edge((0,1))
425
426
  ohm_5 = Edge((1,2), "resistor", TreeNode("d_5"))
@@ -436,6 +437,7 @@ wire_4 = Edge((4,9))
436
437
  edge_list = [wire_1, wire_2, wire_3, wire_4, ohm_5, ohm_6, ohm_7, ohm_8, ohm_8_2, ohm_10, ohm_11, ohm_20]
437
438
  graph = CircuitGraph(10,edge_list,{})
438
439
  print(compute(find_resistance(graph, 0, 9)))
440
+ draw_circuit(graph)
439
441
  ```
440
442
 
441
443
  #### Output
@@ -444,7 +446,7 @@ print(compute(find_resistance(graph, 0, 9)))
444
446
  loading formulas from file...
445
447
  done
446
448
 
447
- 3.493975903614458
449
+ 13.493975903614459
448
450
  8.66474543707973
449
451
  ```
450
452
 
@@ -7,7 +7,7 @@ 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 Edge, CircuitGraph, find_resistance
10
+ from .electronic import Edge, CircuitGraph, find_resistance, draw_circuit
11
11
 
12
12
  from .linear import linear_solve
13
13
 
@@ -1,3 +1,5 @@
1
+ import schemdraw
2
+ import schemdraw.elements as elm
1
3
  import copy
2
4
  from .base import *
3
5
  from .simplify import simplify
@@ -218,3 +220,196 @@ def find_resistance(circuit, start, end):
218
220
  if current == TreeNode("d_0"):
219
221
  return None
220
222
  return simplify(TreeNode("d_1") / current)
223
+ def draw_circuit(graph):
224
+ size = 80
225
+ margin = 35
226
+ spacing = 6
227
+ positions = []
228
+ n = graph.node_count
229
+ side_counts = [n // 4] * 4
230
+ for i in range(n % 4):
231
+ side_counts[i] += 1
232
+ top, right, bottom, left = side_counts
233
+ for i in range(top):
234
+ positions.append((margin, margin + i * spacing))
235
+ for i in range(right):
236
+ positions.append(
237
+ (margin + i * spacing, size - margin - 1)
238
+ )
239
+ for i in range(bottom):
240
+ positions.append(
241
+ (size - margin - 1, size - margin - 1 - i * spacing)
242
+ )
243
+ for i in range(left):
244
+ positions.append(
245
+ (size - margin - 1 - i * spacing, margin)
246
+ )
247
+ if len(positions) != n:
248
+ print("No circuit layout found.")
249
+ return
250
+ edges = []
251
+ for edge in graph.edge_list:
252
+ if not edge.edge:
253
+ continue
254
+ u, v = edge.edge
255
+ if u == v:
256
+ continue
257
+ edges.append((u, v))
258
+ def orientation(a, b, c):
259
+ value = (
260
+ (b[1] - a[1]) * (c[0] - b[0])
261
+ - (b[0] - a[0]) * (c[1] - b[1])
262
+ )
263
+ if value == 0:
264
+ return 0
265
+ return 1 if value > 0 else 2
266
+ def on_segment(a, b, c):
267
+ return (
268
+ min(a[0], c[0]) <= b[0] <= max(a[0], c[0])
269
+ and
270
+ min(a[1], c[1]) <= b[1] <= max(a[1], c[1])
271
+ )
272
+ def intersects(a, b, c, d):
273
+ o1 = orientation(a, b, c)
274
+ o2 = orientation(a, b, d)
275
+ o3 = orientation(c, d, a)
276
+ o4 = orientation(c, d, b)
277
+ if o1 != o2 and o3 != o4:
278
+ return True
279
+ if o1 == 0 and on_segment(a, c, b):
280
+ return True
281
+ if o2 == 0 and on_segment(a, d, b):
282
+ return True
283
+ if o3 == 0 and on_segment(c, a, d):
284
+ return True
285
+ if o4 == 0 and on_segment(c, b, d):
286
+ return True
287
+ return False
288
+ def edge_intersects_node(a, b, node):
289
+ if node == a or node == b:
290
+ return False
291
+ x1, y1 = a
292
+ x2, y2 = b
293
+ x, y = node
294
+ cross = (
295
+ (x - x1) * (y2 - y1)
296
+ - (y - y1) * (x2 - x1)
297
+ )
298
+ if cross != 0:
299
+ return False
300
+ return (
301
+ min(x1, x2) <= x <= max(x1, x2)
302
+ and
303
+ min(y1, y2) <= y <= max(y1, y2)
304
+ )
305
+ def valid_edge(a, b, drawn_edges, node_positions):
306
+ for node in node_positions.values():
307
+ if edge_intersects_node(a, b, node):
308
+ return False
309
+ for c, d in drawn_edges:
310
+ if (
311
+ a == c or
312
+ a == d or
313
+ b == c or
314
+ b == d
315
+ ):
316
+ continue
317
+ if intersects(a, b, c, d):
318
+ return False
319
+ return True
320
+ node_order = list(range(n))
321
+ def try_permutation(order):
322
+ node_positions = {
323
+ node: positions[i]
324
+ for i, node in enumerate(order)
325
+ }
326
+ drawn_edges = []
327
+ ordered_edges = sorted(
328
+ edges,
329
+ key=lambda edge: (
330
+ abs(
331
+ node_positions[edge[0]][0]
332
+ - node_positions[edge[1]][0]
333
+ )
334
+ +
335
+ abs(
336
+ node_positions[edge[0]][1]
337
+ - node_positions[edge[1]][1]
338
+ )
339
+ ),
340
+ reverse=True
341
+ )
342
+ for u, v in ordered_edges:
343
+ a = node_positions[u]
344
+ b = node_positions[v]
345
+ if not valid_edge(
346
+ a,
347
+ b,
348
+ drawn_edges,
349
+ node_positions
350
+ ):
351
+ return None
352
+ drawn_edges.append((a, b))
353
+ return node_positions, drawn_edges
354
+ def permutations(items):
355
+ if len(items) <= 1:
356
+ yield items
357
+ return
358
+ for i in range(len(items)):
359
+ first = items[i]
360
+ rest = items[:i] + items[i + 1:]
361
+ for result in permutations(rest):
362
+ yield [first] + result
363
+ result = None
364
+ for order in permutations(node_order):
365
+ result = try_permutation(order)
366
+ if result is not None:
367
+ break
368
+ if result is None:
369
+ print("No circuit layout found.")
370
+ return
371
+ node_positions, drawn_edges = result
372
+ d = schemdraw.Drawing()
373
+ for edge in graph.edge_list:
374
+ if not edge.edge:
375
+ continue
376
+ u, v = edge.edge
377
+ if u == v:
378
+ continue
379
+ start = node_positions[u]
380
+ end = node_positions[v]
381
+ if edge.edge_type == "resistor":
382
+ element = (
383
+ elm.Resistor()
384
+ .at(start)
385
+ .to(end)
386
+ )
387
+ if edge.value is not None:
388
+ element.label(str(edge.value))
389
+ elif edge.edge_type == "cell":
390
+ element = (
391
+ elm.Cell()
392
+ .at(start)
393
+ .to(end)
394
+ )
395
+ else:
396
+ element = (
397
+ elm.Line()
398
+ .at(start)
399
+ .to(end)
400
+ )
401
+ d.add(element)
402
+ for node, position in node_positions.items():
403
+ d.add(
404
+ elm.Dot()
405
+ .at(position)
406
+ .label(chr(ord("A") + node))
407
+ )
408
+ d.draw()
409
+ d.save("circuit.png")
410
+ try:
411
+ from IPython.display import Image, display
412
+ display(Image("circuit.png"))
413
+ except:
414
+ pass
415
+ return node_positions
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mathai
3
- Version: 2.1.8
3
+ Version: 2.2.0
4
4
  Summary: Mathematics solving Ai tailored to NCERT
5
5
  Home-page: https://github.com/infinity390/mathai
6
6
  Requires-Python: >=3.7
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: more_itertools
9
+ Requires-Dist: schemdraw
9
10
  Dynamic: description
10
11
  Dynamic: description-content-type
11
12
  Dynamic: home-page
@@ -424,8 +425,8 @@ from mathai import *
424
425
  load_formula_from_file()
425
426
  wire_1 = Edge((0,1))
426
427
  ohm_10 = Edge((1,2), "resistor", TreeNode("d_10"))
427
- ohm_5 = Edge((1,3), "resistor", TreeNode("d_5"))
428
- ohm_6 = Edge((1,4), "resistor", TreeNode("d_6"))
428
+ ohm_5 = Edge((2,3), "resistor", TreeNode("d_5"))
429
+ ohm_6 = Edge((2,4), "resistor", TreeNode("d_6"))
429
430
  ohm_7 = Edge((4,5), "resistor", TreeNode("d_7"))
430
431
  ohm_8 = Edge((4,6), "resistor", TreeNode("d_8"))
431
432
  ohm_20 = Edge((6,7), "resistor", TreeNode("d_20"))
@@ -435,6 +436,7 @@ wire_4 = Edge((3,8))
435
436
  edge_list = [wire_1, wire_2, wire_3, wire_4, ohm_5, ohm_6, ohm_7, ohm_8, ohm_10, ohm_20]
436
437
  graph = CircuitGraph(9,edge_list,{})
437
438
  print(compute(find_resistance(graph, 0,8)))
439
+ draw_circuit(graph)
438
440
 
439
441
  wire_1 = Edge((0,1))
440
442
  ohm_5 = Edge((1,2), "resistor", TreeNode("d_5"))
@@ -451,6 +453,7 @@ wire_4 = Edge((4,9))
451
453
  edge_list = [wire_1, wire_2, wire_3, wire_4, ohm_5, ohm_6, ohm_7, ohm_8, ohm_8_2, ohm_10, ohm_11, ohm_20]
452
454
  graph = CircuitGraph(10,edge_list,{})
453
455
  print(compute(find_resistance(graph, 0, 9)))
456
+ draw_circuit(graph)
454
457
  ```
455
458
 
456
459
  #### Output
@@ -459,7 +462,7 @@ print(compute(find_resistance(graph, 0, 9)))
459
462
  loading formulas from file...
460
463
  done
461
464
 
462
- 3.493975903614458
465
+ 13.493975903614459
463
466
  8.66474543707973
464
467
  ```
465
468
 
@@ -1 +1,2 @@
1
1
  more_itertools
2
+ schemdraw
@@ -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.8",
5
+ version="2.2.0",
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",
@@ -13,6 +13,7 @@ setup(
13
13
  },
14
14
  python_requires=">=3.7",
15
15
  install_requires=[
16
- "more_itertools"
16
+ "more_itertools",
17
+ "schemdraw"
17
18
  ],
18
19
  )
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