A series of experiments with Julia and Python
0

Configure Feed

Select the types of activity you want to include in your feed.

julia-playground / packages / GAlgebra.jl.ipynb
22 kB 1021 lines
1{ 2 "cells": [ 3 { 4 "cell_type": "code", 5 "execution_count": 1, 6 "metadata": {}, 7 "outputs": [], 8 "source": [ 9 "using SymPy" 10 ] 11 }, 12 { 13 "cell_type": "code", 14 "execution_count": 2, 15 "metadata": {}, 16 "outputs": [ 17 { 18 "data": { 19 "text/plain": [ 20 "\"1.3\"" 21 ] 22 }, 23 "execution_count": 2, 24 "metadata": {}, 25 "output_type": "execute_result" 26 } 27 ], 28 "source": [ 29 "SymPy.sympy.__version__" 30 ] 31 }, 32 { 33 "cell_type": "code", 34 "execution_count": 3, 35 "metadata": {}, 36 "outputs": [], 37 "source": [ 38 "using PyCall" 39 ] 40 }, 41 { 42 "cell_type": "code", 43 "execution_count": 4, 44 "metadata": {}, 45 "outputs": [ 46 { 47 "data": { 48 "text/plain": [ 49 "PyObject <module 'galgebra.ga' from '/Users/utensil/projects/galgebra/galgebra/ga.py'>" 50 ] 51 }, 52 "execution_count": 4, 53 "metadata": {}, 54 "output_type": "execute_result" 55 } 56 ], 57 "source": [ 58 "const ga = PyCall.PyNULL()\n", 59 "copy!(ga, PyCall.pyimport_conda(\"galgebra.ga\", \"galgebra\"))\n", 60 "const mv = PyCall.PyNULL()\n", 61 "copy!(mv, PyCall.pyimport_conda(\"galgebra.mv\", \"galgebra\"))\n", 62 "const printer = PyCall.PyNULL()\n", 63 "copy!(printer, PyCall.pyimport_conda(\"galgebra.printer\", \"galgebra\"))\n", 64 "ga" 65 ] 66 }, 67 { 68 "cell_type": "code", 69 "execution_count": 5, 70 "metadata": {}, 71 "outputs": [], 72 "source": [ 73 "printer.Format()" 74 ] 75 }, 76 { 77 "cell_type": "code", 78 "execution_count": 6, 79 "metadata": {}, 80 "outputs": [ 81 { 82 "data": { 83 "text/plain": [ 84 "9-element Array{Tuple{PyObject,Type},1}:\n", 85 " (PyObject <class 'sympy.combinatorics.permutations.Permutation'>, SymPermutation) \n", 86 " (PyObject <class 'sympy.combinatorics.perm_groups.PermutationGroup'>, SymPermutationGroup)\n", 87 " (PyObject <class 'sympy.polys.polytools.Poly'>, Sym) \n", 88 " (PyObject <class 'sympy.matrices.dense.MutableDenseMatrix'>, Array{Sym,N} where N) \n", 89 " (PyObject <class 'sympy.matrices.matrices.MatrixBase'>, Array{Sym,N} where N) \n", 90 " (PyObject <class 'sympy.core.basic.Basic'>, Sym) \n", 91 " (PyObject <class 'mpmath.ctx_mp_python.mpf'>, BigFloat) \n", 92 " (PyObject <class 'mpmath.ctx_mp_python.mpc'>, Complex{BigFloat}) \n", 93 " (PyObject <class 'galgebra.mv.Mv'>, Mv) " 94 ] 95 }, 96 "execution_count": 6, 97 "metadata": {}, 98 "output_type": "execute_result" 99 } 100 ], 101 "source": [ 102 "mutable struct Mv\n", 103 " o::PyCall.PyObject\n", 104 "end\n", 105 "\n", 106 "Base.convert(::Type{Mv}, o::PyCall.PyObject) = Mv(o)\n", 107 "\n", 108 "pytype_mapping(mv.Mv, Mv)" 109 ] 110 }, 111 { 112 "cell_type": "code", 113 "execution_count": 7, 114 "metadata": {}, 115 "outputs": [ 116 { 117 "data": { 118 "text/plain": [ 119 "@define_op (macro with 1 method)" 120 ] 121 }, 122 "execution_count": 7, 123 "metadata": {}, 124 "output_type": "execute_result" 125 } 126 ], 127 "source": [ 128 "macro define_op(type, op, method)\n", 129 " @eval begin\n", 130 " $op(x::$type, y::$type) = x.o.$method(y.o)\n", 131 " end\n", 132 "end" 133 ] 134 }, 135 { 136 "cell_type": "code", 137 "execution_count": 8, 138 "metadata": {}, 139 "outputs": [ 140 { 141 "data": { 142 "text/plain": [ 143 "@define_rop (macro with 1 method)" 144 ] 145 }, 146 "execution_count": 8, 147 "metadata": {}, 148 "output_type": "execute_result" 149 } 150 ], 151 "source": [ 152 "macro define_lop(type, rtype, op, lmethod)\n", 153 " @eval begin\n", 154 " $op(x::$type, y::$rtype) = x.o.$lmethod(y)\n", 155 " end\n", 156 "end\n", 157 " \n", 158 "macro define_rop(type, ltype, op, rmethod)\n", 159 " @eval begin\n", 160 " $op(x::$ltype, y::$type) = y.o.$rmethod(x)\n", 161 " end\n", 162 "end" 163 ] 164 }, 165 { 166 "cell_type": "code", 167 "execution_count": 9, 168 "metadata": {}, 169 "outputs": [ 170 { 171 "data": { 172 "text/plain": [ 173 "⊢ (generic function with 1 method)" 174 ] 175 }, 176 "execution_count": 9, 177 "metadata": {}, 178 "output_type": "execute_result" 179 } 180 ], 181 "source": [ 182 "import Base: +,-,*,/,^,==\n", 183 "@define_op(Mv, +, __add__)\n", 184 "@define_op(Mv, -, __sub__)\n", 185 "# Geometric product: *\n", 186 "@define_op(Mv, *, __mul__)\n", 187 "@define_op(Mv, /, __div__)\n", 188 "@define_op(Mv, ^, __pow__)\n", 189 "@define_op(Mv, ==, __eq__)\n", 190 "\n", 191 "# Wedge product: \\wedge\n", 192 "@define_op(Mv, ∧, __xor__)\n", 193 "# Hestene's inner product: \\cdot\n", 194 "@define_op(Mv, ⋅, __or__)\n", 195 "# Left contraction: \\rfloor\n", 196 "@define_op(Mv, <<, __lt__)\n", 197 "@define_op(Mv, ⊣, __lt__)\n", 198 "# Right contraction: \\lfloor\n", 199 "@define_op(Mv, >>, __rt__)\n", 200 "@define_op(Mv, ⊢, __rt__)" 201 ] 202 }, 203 { 204 "cell_type": "code", 205 "execution_count": 10, 206 "metadata": {}, 207 "outputs": [ 208 { 209 "data": { 210 "text/plain": [ 211 "/ (generic function with 112 methods)" 212 ] 213 }, 214 "execution_count": 10, 215 "metadata": {}, 216 "output_type": "execute_result" 217 } 218 ], 219 "source": [ 220 "@define_lop(Mv, Sym, +, __add__)\n", 221 "@define_rop(Mv, Sym, +, __radd__)\n", 222 "@define_lop(Mv, Sym, -, __sub__)\n", 223 "@define_rop(Mv, Sym, -, __rsub__)\n", 224 "@define_lop(Mv, Sym, *, __mul__)\n", 225 "@define_rop(Mv, Sym, *, __rmul__)\n", 226 "@define_lop(Mv, Sym, /, __div__)\n", 227 "@define_rop(Mv, Sym, /, __rdiv__)\n", 228 "\n", 229 "@define_lop(Mv, Number, +, __add__)\n", 230 "@define_rop(Mv, Number, +, __radd__)\n", 231 "@define_lop(Mv, Number, -, __sub__)\n", 232 "@define_rop(Mv, Number, -, __rsub__)\n", 233 "@define_lop(Mv, Number, *, __mul__)\n", 234 "@define_rop(Mv, Number, *, __rmul__)\n", 235 "@define_lop(Mv, Number, /, __div__)\n", 236 "@define_rop(Mv, Number, /, __rdiv__)" 237 ] 238 }, 239 { 240 "cell_type": "code", 241 "execution_count": 11, 242 "metadata": {}, 243 "outputs": [ 244 { 245 "data": { 246 "text/plain": [ 247 "- (generic function with 188 methods)" 248 ] 249 }, 250 "execution_count": 11, 251 "metadata": {}, 252 "output_type": "execute_result" 253 } 254 ], 255 "source": [ 256 "-(x::Mv) = x.o.__neg__()" 257 ] 258 }, 259 { 260 "cell_type": "code", 261 "execution_count": 12, 262 "metadata": {}, 263 "outputs": [ 264 { 265 "data": { 266 "text/plain": [ 267 "PyObject <function vector at 0x134460840>" 268 ] 269 }, 270 "execution_count": 12, 271 "metadata": {}, 272 "output_type": "execute_result" 273 } 274 ], 275 "source": [ 276 "py\"\"\"\n", 277 "def vector(ga, components):\n", 278 " bases = ga.mv()\n", 279 " return sum([components[i] * e for i, e in enumerate(bases)])\n", 280 "\"\"\"\n", 281 "const vector = py\"vector\"" 282 ] 283 }, 284 { 285 "cell_type": "code", 286 "execution_count": 13, 287 "metadata": {}, 288 "outputs": [ 289 { 290 "data": { 291 "text/plain": [ 292 "@define_show (macro with 1 method)" 293 ] 294 }, 295 "execution_count": 13, 296 "metadata": {}, 297 "output_type": "execute_result" 298 } 299 ], 300 "source": [ 301 "macro define_show(type)\n", 302 " @eval begin\n", 303 " Base.show(io::IO, x::$type) = print(io, pystr(x.o))\n", 304 " Base.show(io::IO, ::MIME\"text/plain\", x::$type) = print(io, pystr(x.o))\n", 305 " Base.show(io::IO, ::MIME\"text/latex\", x::$type) = print(io, \"\\\\begin{align*}\" * printer.latex(x.o) * \"\\\\end{align*}\")\n", 306 " end\n", 307 "end" 308 ] 309 }, 310 { 311 "cell_type": "code", 312 "execution_count": 14, 313 "metadata": {}, 314 "outputs": [], 315 "source": [ 316 "@define_show(Mv)" 317 ] 318 }, 319 { 320 "cell_type": "code", 321 "execution_count": 15, 322 "metadata": {}, 323 "outputs": [ 324 { 325 "data": { 326 "text/plain": [ 327 "(x, y, z)" 328 ] 329 }, 330 "execution_count": 15, 331 "metadata": {}, 332 "output_type": "execute_result" 333 } 334 ], 335 "source": [ 336 "(x, y, z) = xyz = symbols(\"x,y,z\",real=true)" 337 ] 338 }, 339 { 340 "cell_type": "code", 341 "execution_count": 16, 342 "metadata": {}, 343 "outputs": [ 344 { 345 "data": { 346 "text/plain": [ 347 "(PyObject <galgebra.ga.Ga object at 0x1256866a0>, \\boldsymbol{e}_{x}, \\boldsymbol{e}_{y}, \\boldsymbol{e}_{z})" 348 ] 349 }, 350 "execution_count": 16, 351 "metadata": {}, 352 "output_type": "execute_result" 353 } 354 ], 355 "source": [ 356 "(o3d, ex, ey, ez) = ga.Ga.build(\"e_x e_y e_z\", g=[1, 1, 1], coords=xyz)" 357 ] 358 }, 359 { 360 "cell_type": "code", 361 "execution_count": 17, 362 "metadata": { 363 "scrolled": true 364 }, 365 "outputs": [ 366 { 367 "data": { 368 "text/latex": [ 369 "\\begin{align*} \\boldsymbol{e}_{x}\\end{align*}" 370 ], 371 "text/plain": [ 372 " \\boldsymbol{e}_{x}" 373 ] 374 }, 375 "execution_count": 17, 376 "metadata": {}, 377 "output_type": "execute_result" 378 } 379 ], 380 "source": [ 381 "ex" 382 ] 383 }, 384 { 385 "cell_type": "code", 386 "execution_count": 18, 387 "metadata": {}, 388 "outputs": [ 389 { 390 "data": { 391 "text/latex": [ 392 "\\begin{align*} \\boldsymbol{e}_{y}\\end{align*}" 393 ], 394 "text/plain": [ 395 " \\boldsymbol{e}_{y}" 396 ] 397 }, 398 "execution_count": 18, 399 "metadata": {}, 400 "output_type": "execute_result" 401 } 402 ], 403 "source": [ 404 "ey" 405 ] 406 }, 407 { 408 "cell_type": "code", 409 "execution_count": 19, 410 "metadata": {}, 411 "outputs": [ 412 { 413 "data": { 414 "text/latex": [ 415 "\\begin{align*} \\boldsymbol{e}_{z}\\end{align*}" 416 ], 417 "text/plain": [ 418 " \\boldsymbol{e}_{z}" 419 ] 420 }, 421 "execution_count": 19, 422 "metadata": {}, 423 "output_type": "execute_result" 424 } 425 ], 426 "source": [ 427 "ez" 428 ] 429 }, 430 { 431 "cell_type": "code", 432 "execution_count": 20, 433 "metadata": {}, 434 "outputs": [ 435 { 436 "data": { 437 "text/plain": [ 438 "PyObject <galgebra.ga.Ga object at 0x1256866a0>" 439 ] 440 }, 441 "execution_count": 20, 442 "metadata": {}, 443 "output_type": "execute_result" 444 } 445 ], 446 "source": [ 447 "const V = o3d" 448 ] 449 }, 450 { 451 "cell_type": "code", 452 "execution_count": 21, 453 "metadata": {}, 454 "outputs": [ 455 { 456 "data": { 457 "text/latex": [ 458 "\\begin{align*}w^{x} \\boldsymbol{e}_{x} + w^{y} \\boldsymbol{e}_{y} + w^{z} \\boldsymbol{e}_{z}\\end{align*}" 459 ], 460 "text/plain": [ 461 "w^{x} \\boldsymbol{e}_{x} + w^{y} \\boldsymbol{e}_{y} + w^{z} \\boldsymbol{e}_{z}" 462 ] 463 }, 464 "execution_count": 21, 465 "metadata": {}, 466 "output_type": "execute_result" 467 } 468 ], 469 "source": [ 470 "a = V.mv(\"a\", \"scalar\")\n", 471 "b = V.mv(\"b\", \"scalar\")\n", 472 "c = V.mv(\"c\", \"scalar\")\n", 473 "d = V.mv(\"d\", \"scalar\")\n", 474 "u = V.mv(\"u\", \"vector\")\n", 475 "v = V.mv(\"v\", \"vector\")\n", 476 "w = V.mv(\"w\", \"vector\")" 477 ] 478 }, 479 { 480 "cell_type": "code", 481 "execution_count": 22, 482 "metadata": {}, 483 "outputs": [ 484 { 485 "data": { 486 "text/plain": [ 487 "true" 488 ] 489 }, 490 "execution_count": 22, 491 "metadata": {}, 492 "output_type": "execute_result" 493 } 494 ], 495 "source": [ 496 "v + w == w + v" 497 ] 498 }, 499 { 500 "cell_type": "code", 501 "execution_count": 23, 502 "metadata": {}, 503 "outputs": [ 504 { 505 "data": { 506 "text/plain": [ 507 "true" 508 ] 509 }, 510 "execution_count": 23, 511 "metadata": {}, 512 "output_type": "execute_result" 513 } 514 ], 515 "source": [ 516 "(u + v) + w == u + (v + w)" 517 ] 518 }, 519 { 520 "cell_type": "code", 521 "execution_count": 24, 522 "metadata": {}, 523 "outputs": [ 524 { 525 "data": { 526 "text/plain": [ 527 "true" 528 ] 529 }, 530 "execution_count": 24, 531 "metadata": {}, 532 "output_type": "execute_result" 533 } 534 ], 535 "source": [ 536 "v + Sym(0) == v" 537 ] 538 }, 539 { 540 "cell_type": "code", 541 "execution_count": 25, 542 "metadata": {}, 543 "outputs": [ 544 { 545 "data": { 546 "text/latex": [ 547 "\\begin{align*} 0 \\end{align*}" 548 ], 549 "text/plain": [ 550 " 0 " 551 ] 552 }, 553 "execution_count": 25, 554 "metadata": {}, 555 "output_type": "execute_result" 556 } 557 ], 558 "source": [ 559 "# TODO Why can't == work?\n", 560 "Sym(0) * v - Sym(0)" 561 ] 562 }, 563 { 564 "cell_type": "code", 565 "execution_count": 26, 566 "metadata": {}, 567 "outputs": [ 568 { 569 "data": { 570 "text/plain": [ 571 "true" 572 ] 573 }, 574 "execution_count": 26, 575 "metadata": {}, 576 "output_type": "execute_result" 577 } 578 ], 579 "source": [ 580 "Sym(1) * v == v" 581 ] 582 }, 583 { 584 "cell_type": "code", 585 "execution_count": 27, 586 "metadata": {}, 587 "outputs": [ 588 { 589 "data": { 590 "text/plain": [ 591 "true" 592 ] 593 }, 594 "execution_count": 27, 595 "metadata": {}, 596 "output_type": "execute_result" 597 } 598 ], 599 "source": [ 600 "a * (b * v) == (a * b) * v" 601 ] 602 }, 603 { 604 "cell_type": "code", 605 "execution_count": 28, 606 "metadata": {}, 607 "outputs": [ 608 { 609 "data": { 610 "text/plain": [ 611 "true" 612 ] 613 }, 614 "execution_count": 28, 615 "metadata": {}, 616 "output_type": "execute_result" 617 } 618 ], 619 "source": [ 620 "a * (v + w) == a * v + a * w" 621 ] 622 }, 623 { 624 "cell_type": "code", 625 "execution_count": 29, 626 "metadata": {}, 627 "outputs": [ 628 { 629 "data": { 630 "text/plain": [ 631 "true" 632 ] 633 }, 634 "execution_count": 29, 635 "metadata": {}, 636 "output_type": "execute_result" 637 } 638 ], 639 "source": [ 640 "(a + b) * v == a * v + b * v" 641 ] 642 }, 643 { 644 "cell_type": "code", 645 "execution_count": 30, 646 "metadata": {}, 647 "outputs": [ 648 { 649 "data": { 650 "text/latex": [ 651 "\\begin{align*}5 \\boldsymbol{e}_{x} + 6 \\boldsymbol{e}_{y} + 7 \\boldsymbol{e}_{z}\\end{align*}" 652 ], 653 "text/plain": [ 654 "5 \\boldsymbol{e}_{x} + 6 \\boldsymbol{e}_{y} + 7 \\boldsymbol{e}_{z}" 655 ] 656 }, 657 "execution_count": 30, 658 "metadata": {}, 659 "output_type": "execute_result" 660 } 661 ], 662 "source": [ 663 "uu = vector(V, [1, 2, 3])\n", 664 "vv = vector(V, [4, 5, 6])\n", 665 "ww = vector(V, [5, 6, 7])" 666 ] 667 }, 668 { 669 "cell_type": "code", 670 "execution_count": 31, 671 "metadata": {}, 672 "outputs": [ 673 { 674 "data": { 675 "text/latex": [ 676 "\\begin{align*}5 \\boldsymbol{e}_{x} + 7 \\boldsymbol{e}_{y} + 9 \\boldsymbol{e}_{z}\\end{align*}" 677 ], 678 "text/plain": [ 679 "5 \\boldsymbol{e}_{x} + 7 \\boldsymbol{e}_{y} + 9 \\boldsymbol{e}_{z}" 680 ] 681 }, 682 "execution_count": 31, 683 "metadata": {}, 684 "output_type": "execute_result" 685 } 686 ], 687 "source": [ 688 "uu + vv" 689 ] 690 }, 691 { 692 "cell_type": "code", 693 "execution_count": 32, 694 "metadata": {}, 695 "outputs": [ 696 { 697 "data": { 698 "text/latex": [ 699 "\\begin{align*}17 \\boldsymbol{e}_{x} + 26 \\boldsymbol{e}_{y} + 35 \\boldsymbol{e}_{z}\\end{align*}" 700 ], 701 "text/plain": [ 702 "17 \\boldsymbol{e}_{x} + 26 \\boldsymbol{e}_{y} + 35 \\boldsymbol{e}_{z}" 703 ] 704 }, 705 "execution_count": 32, 706 "metadata": {}, 707 "output_type": "execute_result" 708 } 709 ], 710 "source": [ 711 "7 * uu + 2 * ww" 712 ] 713 }, 714 { 715 "cell_type": "code", 716 "execution_count": 33, 717 "metadata": {}, 718 "outputs": [ 719 { 720 "data": { 721 "text/latex": [ 722 "\\begin{align*}-3 \\boldsymbol{e}_{x} + 2 \\boldsymbol{e}_{y} + 7 \\boldsymbol{e}_{z}\\end{align*}" 723 ], 724 "text/plain": [ 725 "-3 \\boldsymbol{e}_{x} + 2 \\boldsymbol{e}_{y} + 7 \\boldsymbol{e}_{z}" 726 ] 727 }, 728 "execution_count": 33, 729 "metadata": {}, 730 "output_type": "execute_result" 731 } 732 ], 733 "source": [ 734 "7 * uu - 2 * ww" 735 ] 736 }, 737 { 738 "cell_type": "code", 739 "execution_count": 34, 740 "metadata": {}, 741 "outputs": [ 742 { 743 "data": { 744 "text/latex": [ 745 "\\begin{align*}16 \\boldsymbol{e}_{x} + 22 \\boldsymbol{e}_{y} + 28 \\boldsymbol{e}_{z}\\end{align*}" 746 ], 747 "text/plain": [ 748 "16 \\boldsymbol{e}_{x} + 22 \\boldsymbol{e}_{y} + 28 \\boldsymbol{e}_{z}" 749 ] 750 }, 751 "execution_count": 34, 752 "metadata": {}, 753 "output_type": "execute_result" 754 } 755 ], 756 "source": [ 757 "3 * uu + 2 * vv + ww" 758 ] 759 }, 760 { 761 "cell_type": "code", 762 "execution_count": 35, 763 "metadata": {}, 764 "outputs": [ 765 { 766 "data": { 767 "text/latex": [ 768 "\\begin{align*} 0 \\end{align*}" 769 ], 770 "text/plain": [ 771 " 0 " 772 ] 773 }, 774 "execution_count": 35, 775 "metadata": {}, 776 "output_type": "execute_result" 777 } 778 ], 779 "source": [ 780 "v + ga.S(-1) * v" 781 ] 782 }, 783 { 784 "cell_type": "code", 785 "execution_count": 36, 786 "metadata": {}, 787 "outputs": [ 788 { 789 "data": { 790 "text/latex": [ 791 "\\begin{align*} 0 \\end{align*}" 792 ], 793 "text/plain": [ 794 " 0 " 795 ] 796 }, 797 "execution_count": 36, 798 "metadata": {}, 799 "output_type": "execute_result" 800 } 801 ], 802 "source": [ 803 "v0 = vector(V, [0, 0, 0])" 804 ] 805 }, 806 { 807 "cell_type": "code", 808 "execution_count": 37, 809 "metadata": {}, 810 "outputs": [ 811 { 812 "data": { 813 "text/plain": [ 814 "true" 815 ] 816 }, 817 "execution_count": 37, 818 "metadata": {}, 819 "output_type": "execute_result" 820 } 821 ], 822 "source": [ 823 "a * v0 == v0" 824 ] 825 }, 826 { 827 "cell_type": "code", 828 "execution_count": 38, 829 "metadata": {}, 830 "outputs": [ 831 { 832 "data": { 833 "text/plain": [ 834 "true" 835 ] 836 }, 837 "execution_count": 38, 838 "metadata": {}, 839 "output_type": "execute_result" 840 } 841 ], 842 "source": [ 843 "(-a) * v == a * (-v)" 844 ] 845 }, 846 { 847 "cell_type": "code", 848 "execution_count": 39, 849 "metadata": {}, 850 "outputs": [ 851 { 852 "data": { 853 "text/plain": [ 854 "true" 855 ] 856 }, 857 "execution_count": 39, 858 "metadata": {}, 859 "output_type": "execute_result" 860 } 861 ], 862 "source": [ 863 "(-a) * v == - a * v" 864 ] 865 }, 866 { 867 "cell_type": "code", 868 "execution_count": 40, 869 "metadata": {}, 870 "outputs": [ 871 { 872 "data": { 873 "text/plain": [ 874 "1.4142135623730951" 875 ] 876 }, 877 "execution_count": 40, 878 "metadata": {}, 879 "output_type": "execute_result" 880 } 881 ], 882 "source": [ 883 "SymPy.sqrt(2)" 884 ] 885 }, 886 { 887 "cell_type": "code", 888 "execution_count": 41, 889 "metadata": {}, 890 "outputs": [ 891 { 892 "data": { 893 "text/latex": [ 894 "\\begin{equation*}\\sqrt{2}\\end{equation*}" 895 ], 896 "text/plain": [ 897 "√2" 898 ] 899 }, 900 "execution_count": 41, 901 "metadata": {}, 902 "output_type": "execute_result" 903 } 904 ], 905 "source": [ 906 "SymPy.sqrt(Sym(2))" 907 ] 908 }, 909 { 910 "cell_type": "code", 911 "execution_count": 42, 912 "metadata": {}, 913 "outputs": [ 914 { 915 "data": { 916 "text/plain": [ 917 "2//3" 918 ] 919 }, 920 "execution_count": 42, 921 "metadata": {}, 922 "output_type": "execute_result" 923 } 924 ], 925 "source": [ 926 "SymPy.Rational(2, 3)" 927 ] 928 }, 929 { 930 "cell_type": "code", 931 "execution_count": 43, 932 "metadata": {}, 933 "outputs": [ 934 { 935 "data": { 936 "text/latex": [ 937 "\\begin{equation*}\\frac{2}{3}\\end{equation*}" 938 ], 939 "text/plain": [ 940 "\\frac{2}{3}" 941 ] 942 }, 943 "execution_count": 43, 944 "metadata": {}, 945 "output_type": "execute_result" 946 } 947 ], 948 "source": [ 949 "Sym(SymPy.Rational(2, 3))" 950 ] 951 }, 952 { 953 "cell_type": "code", 954 "execution_count": 44, 955 "metadata": {}, 956 "outputs": [ 957 { 958 "data": { 959 "text/latex": [ 960 "\\begin{align*}\\left ( 1.4142135623731 u^{x} + 0.666666666666667 v^{x}\\right ) \\boldsymbol{e}_{x} + \\left ( 1.4142135623731 u^{y} + 0.666666666666667 v^{y}\\right ) \\boldsymbol{e}_{y} + \\left ( 1.4142135623731 u^{z} + 0.666666666666667 v^{z}\\right ) \\boldsymbol{e}_{z}\\end{align*}" 961 ], 962 "text/plain": [ 963 "\\left ( 1.4142135623731 u^{x} + 0.666666666666667 v^{x}\\right ) \\boldsymbol{e}_{x} + \\left ( 1.4142135623731 u^{y} + 0.666666666666667 v^{y}\\right ) \\boldsymbol{e}_{y} + \\left ( 1.4142135623731 u^{z} + 0.666666666666667 v^{z}\\right ) \\boldsymbol{e}_{z}" 964 ] 965 }, 966 "execution_count": 44, 967 "metadata": {}, 968 "output_type": "execute_result" 969 } 970 ], 971 "source": [ 972 "SymPy.sqrt(2) * u + SymPy.Rational(2, 3) * v" 973 ] 974 }, 975 { 976 "cell_type": "code", 977 "execution_count": 45, 978 "metadata": {}, 979 "outputs": [ 980 { 981 "data": { 982 "text/latex": [ 983 "\\begin{align*}\\left ( \\sqrt{2} u^{x} + \\frac{2 v^{x}}{3}\\right ) \\boldsymbol{e}_{x} + \\left ( \\sqrt{2} u^{y} + \\frac{2 v^{y}}{3}\\right ) \\boldsymbol{e}_{y} + \\left ( \\sqrt{2} u^{z} + \\frac{2 v^{z}}{3}\\right ) \\boldsymbol{e}_{z}\\end{align*}" 984 ], 985 "text/plain": [ 986 "\\left ( \\sqrt{2} u^{x} + \\frac{2 v^{x}}{3}\\right ) \\boldsymbol{e}_{x} + \\left ( \\sqrt{2} u^{y} + \\frac{2 v^{y}}{3}\\right ) \\boldsymbol{e}_{y} + \\left ( \\sqrt{2} u^{z} + \\frac{2 v^{z}}{3}\\right ) \\boldsymbol{e}_{z}" 987 ] 988 }, 989 "execution_count": 45, 990 "metadata": {}, 991 "output_type": "execute_result" 992 } 993 ], 994 "source": [ 995 "SymPy.sqrt(Sym(2)) * u + Sym(SymPy.Rational(2, 3)) * v" 996 ] 997 }, 998 { 999 "cell_type": "code", 1000 "execution_count": null, 1001 "metadata": {}, 1002 "outputs": [], 1003 "source": [] 1004 } 1005 ], 1006 "metadata": { 1007 "kernelspec": { 1008 "display_name": "Julia 1.1.0", 1009 "language": "julia", 1010 "name": "julia-1.1" 1011 }, 1012 "language_info": { 1013 "file_extension": ".jl", 1014 "mimetype": "application/julia", 1015 "name": "julia", 1016 "version": "1.1.0" 1017 } 1018 }, 1019 "nbformat": 4, 1020 "nbformat_minor": 2 1021}