├── .github └── workflows │ └── deploy.yaml ├── .gitignore ├── .nojeklyll ├── 01_APL.ipynb ├── 02_functions.ipynb ├── 03_operators.ipynb ├── 04_competition.ipynb ├── 05_the_rest.ipynb ├── LICENSE ├── MANIFEST.in ├── README.md ├── _quarto.yml ├── aplstudy ├── __init__.py └── _modidx.py ├── index.ipynb ├── nbdev.yml ├── python.ipynb ├── settings.ini ├── setup.py ├── sidebar.yml ├── styles.css └── www ├── SAX2.ttf └── SAX2.woff2 /.github/workflows/deploy.yaml: -------------------------------------------------------------------------------- 1 | name: Deploy to GitHub Pages 2 | on: 3 | push: 4 | branches: [master] 5 | workflow_dispatch: 6 | jobs: 7 | deploy: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: fastai/workflows/quarto-ghp@master 11 | with: {pre: 1} 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _proc/ 2 | _docs/ 3 | .DS_Store 4 | *.bak 5 | .gitattributes 6 | .last_checked 7 | .gitconfig 8 | *.bak 9 | *.log 10 | *~ 11 | ~* 12 | _tmp* 13 | tmp* 14 | tags 15 | *.pkg 16 | 17 | # Byte-compiled / optimized / DLL files 18 | __pycache__/ 19 | *.py[cod] 20 | *$py.class 21 | 22 | # C extensions 23 | *.so 24 | 25 | # Distribution / packaging 26 | .Python 27 | env/ 28 | build/ 29 | develop-eggs/ 30 | dist/ 31 | downloads/ 32 | eggs/ 33 | .eggs/ 34 | lib/ 35 | lib64/ 36 | parts/ 37 | sdist/ 38 | var/ 39 | wheels/ 40 | *.egg-info/ 41 | .installed.cfg 42 | *.egg 43 | 44 | # PyInstaller 45 | # Usually these files are written by a python script from a template 46 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 47 | *.manifest 48 | *.spec 49 | 50 | # Installer logs 51 | pip-log.txt 52 | pip-delete-this-directory.txt 53 | 54 | # Unit test / coverage reports 55 | htmlcov/ 56 | .tox/ 57 | .coverage 58 | .coverage.* 59 | .cache 60 | nosetests.xml 61 | coverage.xml 62 | *.cover 63 | .hypothesis/ 64 | 65 | # Translations 66 | *.mo 67 | *.pot 68 | 69 | # Django stuff: 70 | *.log 71 | local_settings.py 72 | 73 | # Flask stuff: 74 | instance/ 75 | .webassets-cache 76 | 77 | # Scrapy stuff: 78 | .scrapy 79 | 80 | # Sphinx documentation 81 | docs/_build/ 82 | 83 | # PyBuilder 84 | target/ 85 | 86 | # Jupyter Notebook 87 | .ipynb_checkpoints 88 | 89 | # pyenv 90 | .python-version 91 | 92 | # celery beat schedule file 93 | celerybeat-schedule 94 | 95 | # SageMath parsed files 96 | *.sage.py 97 | 98 | # dotenv 99 | .env 100 | 101 | # virtualenv 102 | .venv 103 | venv/ 104 | ENV/ 105 | 106 | # Spyder project settings 107 | .spyderproject 108 | .spyproject 109 | 110 | # Rope project settings 111 | .ropeproject 112 | 113 | # mkdocs documentation 114 | /site 115 | 116 | # mypy 117 | .mypy_cache/ 118 | 119 | .vscode 120 | *.swp 121 | 122 | # osx generated files 123 | .DS_Store 124 | .DS_Store? 125 | .Trashes 126 | ehthumbs.db 127 | Thumbs.db 128 | .idea 129 | 130 | # pytest 131 | .pytest_cache 132 | 133 | # tools/trust-doc-nbs 134 | docs_src/.last_checked 135 | 136 | # symlinks to fastai 137 | docs_src/fastai 138 | tools/fastai 139 | 140 | # link checker 141 | checklink/cookies.txt 142 | 143 | # .gitconfig is now autogenerated 144 | .gitconfig 145 | 146 | 147 | /.quarto/ 148 | -------------------------------------------------------------------------------- /.nojeklyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fastai/apl-study/115c5b1468823884889b3eb966ceaf2acfc68266/.nojeklyll -------------------------------------------------------------------------------- /02_functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "raw", 5 | "id": "2990f581", 6 | "metadata": {}, 7 | "source": [ 8 | "---\n", 9 | "title: \"First functions\"\n", 10 | "author: \"Jeremy Howard\"\n", 11 | "date: \"2022-07-05\"\n", 12 | "categories: [Dyalog, APL, Glyphs]\n", 13 | "---" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "id": "84e8fa35", 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "data": { 24 | "text/html": [ 25 | "
┌→─────────────────────────────────────┐\n",
  26 |        "│Was ON -style=max -trains=tree -fns=on│\n",
  27 |        "└──────────────────────────────────────┘\n",
  28 |        "
" 29 | ] 30 | }, 31 | "execution_count": null, 32 | "metadata": {}, 33 | "output_type": "execute_result" 34 | } 35 | ], 36 | "source": [ 37 | "]box on -style=max -trains=tree -fns=on" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "id": "2dbbce67", 43 | "metadata": {}, 44 | "source": [ 45 | "## Boolean" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "71f403e7", 51 | "metadata": {}, 52 | "source": [ 53 | "### `=` (Equal sign)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "id": "2df02fe7", 59 | "metadata": {}, 60 | "source": [ 61 | "#### dyadic `=` (Equal to)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "id": "22de5339-feeb-4050-8fd2-c49604d38546", 67 | "metadata": {}, 68 | "source": [ 69 | "`=` is equal and returns a boolean (true/false). 1 means true, 0 means false." 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "id": "f9a1f4c0", 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/html": [ 81 | "
 \n",
  82 |        "1\n",
  83 |        " \n",
  84 |        "
" 85 | ] 86 | }, 87 | "execution_count": null, 88 | "metadata": {}, 89 | "output_type": "execute_result" 90 | } 91 | ], 92 | "source": [ 93 | "1 = 1" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "id": "2dbd9b1e-f7dd-43ef-9198-42210c33f7f6", 99 | "metadata": {}, 100 | "source": [ 101 | "`=` works elementwise and will broadcast as needed." 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "id": "e494be50", 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "data": { 112 | "text/html": [ 113 | "
┌→──┐\n",
 114 |        "│1 0│\n",
 115 |        "└~──┘\n",
 116 |        "
" 117 | ] 118 | }, 119 | "execution_count": null, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "1 = 1 2" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": null, 131 | "id": "d31b5778", 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/html": [ 137 | "
┌→──┐\n",
 138 |        "│1 1│\n",
 139 |        "└~──┘\n",
 140 |        "
" 141 | ] 142 | }, 143 | "execution_count": null, 144 | "metadata": {}, 145 | "output_type": "execute_result" 146 | } 147 | ], 148 | "source": [ 149 | "1 = 1 1" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "id": "2fbb3372-ec47-45a7-9c0f-0c5264207eaf", 155 | "metadata": {}, 156 | "source": [ 157 | "We can also compare characters" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "id": "8d9ff9d7", 164 | "metadata": {}, 165 | "outputs": [ 166 | { 167 | "data": { 168 | "text/html": [ 169 | "
┌→──────────┐\n",
 170 |        "│0 1 0 1 0 1│\n",
 171 |        "└~──────────┘\n",
 172 |        "
" 173 | ] 174 | }, 175 | "execution_count": null, 176 | "metadata": {}, 177 | "output_type": "execute_result" 178 | } 179 | ], 180 | "source": [ 181 | "'Banana' = 'aaaaaa'" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": null, 187 | "id": "0077e614", 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/html": [ 193 | "
┌→──────────┐\n",
 194 |        "│0 1 0 1 0 1│\n",
 195 |        "└~──────────┘\n",
 196 |        "
" 197 | ] 198 | }, 199 | "execution_count": null, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "'Banana' = 'a'" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": null, 211 | "id": "aa551f28", 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/html": [ 217 | "
┌→──────────────────────────────────────┐\n",
 218 |        "│ ┌→──────────┐ ┌→────────┐ ┌→────────┐ │\n",
 219 |        "│ │0 1 0 1 0 1│ │0 0 0 0 0│ │0 1 0 0 0│ │\n",
 220 |        "│ └~──────────┘ └~────────┘ └~────────┘ │\n",
 221 |        "└∊──────────────────────────────────────┘\n",
 222 |        "
" 223 | ] 224 | }, 225 | "execution_count": null, 226 | "metadata": {}, 227 | "output_type": "execute_result" 228 | } 229 | ], 230 | "source": [ 231 | "'Banana' 'Apple' 'Candy' = 'a'" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "id": "12b33beb", 237 | "metadata": {}, 238 | "source": [ 239 | "### `≠` (Not equal)" 240 | ] 241 | }, 242 | { 243 | "cell_type": "markdown", 244 | "id": "3b0b6323", 245 | "metadata": {}, 246 | "source": [ 247 | "#### monadic `≠` (Unique Mask)" 248 | ] 249 | }, 250 | { 251 | "cell_type": "markdown", 252 | "id": "5a19caf7-f061-44da-99c0-7495223a1812", 253 | "metadata": {}, 254 | "source": [ 255 | "Monadic `≠` returns 1 on the first occurrence of an item in an array." 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": null, 261 | "id": "0d283400", 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "data": { 266 | "text/html": [ 267 | "
┌→──────────────┐\n",
 268 |        "│1 1 0 0 1 0 1 0│\n",
 269 |        "└~──────────────┘\n",
 270 |        "
" 271 | ] 272 | }, 273 | "execution_count": null, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "≠22 10 22 22 21 10 5 10" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": null, 285 | "id": "1b52166b", 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "data": { 290 | "text/html": [ 291 | "
┌→──────────┐\n",
 292 |        "│1 1 1 0 0 0│\n",
 293 |        "└~──────────┘\n",
 294 |        "
" 295 | ] 296 | }, 297 | "execution_count": null, 298 | "metadata": {}, 299 | "output_type": "execute_result" 300 | } 301 | ], 302 | "source": [ 303 | "≠ 'Banana'" 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "execution_count": null, 309 | "id": "84ed720d", 310 | "metadata": {}, 311 | "outputs": [ 312 | { 313 | "data": { 314 | "text/html": [ 315 | "
┌→────────────────────┐\n",
 316 |        "│1 1 1 0 0 0 0 0 1 0 0│\n",
 317 |        "└~────────────────────┘\n",
 318 |        "
" 319 | ] 320 | }, 321 | "execution_count": null, 322 | "metadata": {}, 323 | "output_type": "execute_result" 324 | } 325 | ], 326 | "source": [ 327 | "≠ 'Mississippi'" 328 | ] 329 | }, 330 | { 331 | "cell_type": "markdown", 332 | "id": "ec2830de", 333 | "metadata": {}, 334 | "source": [ 335 | "#### dyadic `≠` (Not Equal To)" 336 | ] 337 | }, 338 | { 339 | "cell_type": "markdown", 340 | "id": "a062070b-2923-4a0b-b964-df59052f23ed", 341 | "metadata": {}, 342 | "source": [ 343 | "Dyadic `≠` returns true (1) if elements are not equal, and false (0) if elements are equal. " 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": null, 349 | "id": "21b37853", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "data": { 354 | "text/html": [ 355 | "
┌→────┐\n",
 356 |        "│1 0 1│\n",
 357 |        "└~────┘\n",
 358 |        "
" 359 | ] 360 | }, 361 | "execution_count": null, 362 | "metadata": {}, 363 | "output_type": "execute_result" 364 | } 365 | ], 366 | "source": [ 367 | "1 2 3 ≠ 4 2 ¯1" 368 | ] 369 | }, 370 | { 371 | "cell_type": "markdown", 372 | "id": "5e01edbc-b54f-458b-a3ac-2b6ad344ae54", 373 | "metadata": {}, 374 | "source": [ 375 | "The number 7 and the character 7 are not equal." 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": null, 381 | "id": "7b1f2164", 382 | "metadata": {}, 383 | "outputs": [ 384 | { 385 | "data": { 386 | "text/html": [ 387 | "
 \n",
 388 |        "1\n",
 389 |        " \n",
 390 |        "
" 391 | ] 392 | }, 393 | "execution_count": null, 394 | "metadata": {}, 395 | "output_type": "execute_result" 396 | } 397 | ], 398 | "source": [ 399 | "7 ≠ '7'" 400 | ] 401 | }, 402 | { 403 | "cell_type": "markdown", 404 | "id": "2d5dfcd5", 405 | "metadata": {}, 406 | "source": [ 407 | "### `<` (Less than sign)" 408 | ] 409 | }, 410 | { 411 | "cell_type": "markdown", 412 | "id": "4277bc63", 413 | "metadata": {}, 414 | "source": [ 415 | "#### dyadic `<` (Less than)" 416 | ] 417 | }, 418 | { 419 | "cell_type": "code", 420 | "execution_count": null, 421 | "id": "b3c6be5e", 422 | "metadata": {}, 423 | "outputs": [ 424 | { 425 | "data": { 426 | "text/html": [ 427 | "
┌→────┐\n",
 428 |        "│1 0 0│\n",
 429 |        "└~────┘\n",
 430 |        "
" 431 | ] 432 | }, 433 | "execution_count": null, 434 | "metadata": {}, 435 | "output_type": "execute_result" 436 | } 437 | ], 438 | "source": [ 439 | "1 2 3 < 4 2 ¯1" 440 | ] 441 | }, 442 | { 443 | "cell_type": "code", 444 | "execution_count": null, 445 | "id": "61f6c499", 446 | "metadata": {}, 447 | "outputs": [ 448 | { 449 | "data": { 450 | "text/html": [ 451 | "
┌→────┐\n",
 452 |        "│1 0 0│\n",
 453 |        "└~────┘\n",
 454 |        "
" 455 | ] 456 | }, 457 | "execution_count": null, 458 | "metadata": {}, 459 | "output_type": "execute_result" 460 | } 461 | ], 462 | "source": [ 463 | "1 2 3 < 2" 464 | ] 465 | }, 466 | { 467 | "cell_type": "markdown", 468 | "id": "3bd3a0ea", 469 | "metadata": {}, 470 | "source": [ 471 | "### `>` (Greater than sign)" 472 | ] 473 | }, 474 | { 475 | "cell_type": "markdown", 476 | "id": "b487022a", 477 | "metadata": {}, 478 | "source": [ 479 | "#### dyadic `>` (Greater than)" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": null, 485 | "id": "ed7bc01e", 486 | "metadata": {}, 487 | "outputs": [ 488 | { 489 | "data": { 490 | "text/html": [ 491 | "
┌→────┐\n",
 492 |        "│0 0 1│\n",
 493 |        "└~────┘\n",
 494 |        "
" 495 | ] 496 | }, 497 | "execution_count": null, 498 | "metadata": {}, 499 | "output_type": "execute_result" 500 | } 501 | ], 502 | "source": [ 503 | "1 2 3 > 4 2 ¯1" 504 | ] 505 | }, 506 | { 507 | "cell_type": "code", 508 | "execution_count": null, 509 | "id": "b68ae705", 510 | "metadata": {}, 511 | "outputs": [ 512 | { 513 | "data": { 514 | "text/html": [ 515 | "
┌→────┐\n",
 516 |        "│0 0 1│\n",
 517 |        "└~────┘\n",
 518 |        "
" 519 | ] 520 | }, 521 | "execution_count": null, 522 | "metadata": {}, 523 | "output_type": "execute_result" 524 | } 525 | ], 526 | "source": [ 527 | "1 2 3 > 2" 528 | ] 529 | }, 530 | { 531 | "cell_type": "markdown", 532 | "id": "903c506f", 533 | "metadata": {}, 534 | "source": [ 535 | "### `≤` (Less than or equal to sign)" 536 | ] 537 | }, 538 | { 539 | "cell_type": "markdown", 540 | "id": "21b33cbf", 541 | "metadata": {}, 542 | "source": [ 543 | "#### dyadic `≤` (Less than or equal to)" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": null, 549 | "id": "985c9324", 550 | "metadata": {}, 551 | "outputs": [ 552 | { 553 | "data": { 554 | "text/html": [ 555 | "
┌→────┐\n",
 556 |        "│1 1 0│\n",
 557 |        "└~────┘\n",
 558 |        "
" 559 | ] 560 | }, 561 | "execution_count": null, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "1 2 3 ≤ 4 2 ¯1" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": null, 573 | "id": "ebb03a6a", 574 | "metadata": {}, 575 | "outputs": [ 576 | { 577 | "data": { 578 | "text/html": [ 579 | "
┌→────┐\n",
 580 |        "│1 1 0│\n",
 581 |        "└~────┘\n",
 582 |        "
" 583 | ] 584 | }, 585 | "execution_count": null, 586 | "metadata": {}, 587 | "output_type": "execute_result" 588 | } 589 | ], 590 | "source": [ 591 | "1 2 3 ≤ 2" 592 | ] 593 | }, 594 | { 595 | "cell_type": "markdown", 596 | "id": "b9409575", 597 | "metadata": {}, 598 | "source": [ 599 | "### `≥` (Greater than or equal to sign)" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "id": "8dbc6595", 605 | "metadata": {}, 606 | "source": [ 607 | "#### dyadic `≥` (Greater than or equal to)" 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": null, 613 | "id": "c2db65ca", 614 | "metadata": {}, 615 | "outputs": [ 616 | { 617 | "data": { 618 | "text/html": [ 619 | "
┌→────┐\n",
 620 |        "│0 1 1│\n",
 621 |        "└~────┘\n",
 622 |        "
" 623 | ] 624 | }, 625 | "execution_count": null, 626 | "metadata": {}, 627 | "output_type": "execute_result" 628 | } 629 | ], 630 | "source": [ 631 | "1 2 3 ≥ 4 2 ¯1" 632 | ] 633 | }, 634 | { 635 | "cell_type": "code", 636 | "execution_count": null, 637 | "id": "3c4673b1", 638 | "metadata": {}, 639 | "outputs": [ 640 | { 641 | "data": { 642 | "text/html": [ 643 | "
┌→────┐\n",
 644 |        "│0 1 1│\n",
 645 |        "└~────┘\n",
 646 |        "
" 647 | ] 648 | }, 649 | "execution_count": null, 650 | "metadata": {}, 651 | "output_type": "execute_result" 652 | } 653 | ], 654 | "source": [ 655 | "1 2 3 ≥ 2" 656 | ] 657 | }, 658 | { 659 | "cell_type": "markdown", 660 | "id": "af629c33", 661 | "metadata": {}, 662 | "source": [ 663 | "### `≡` (Equal underbar)" 664 | ] 665 | }, 666 | { 667 | "cell_type": "markdown", 668 | "id": "04409fab", 669 | "metadata": {}, 670 | "source": [ 671 | "#### monadic `≡` (Depth)" 672 | ] 673 | }, 674 | { 675 | "cell_type": "markdown", 676 | "id": "9d6a0db6-2820-4e30-a53e-65e6010d8324", 677 | "metadata": {}, 678 | "source": [ 679 | "Depth shows how nested an array is. A simple scalar is an array with no nesting." 680 | ] 681 | }, 682 | { 683 | "cell_type": "code", 684 | "execution_count": null, 685 | "id": "fcb156fe", 686 | "metadata": {}, 687 | "outputs": [ 688 | { 689 | "data": { 690 | "text/html": [ 691 | "
 \n",
 692 |        "0\n",
 693 |        " \n",
 694 |        "
" 695 | ] 696 | }, 697 | "execution_count": null, 698 | "metadata": {}, 699 | "output_type": "execute_result" 700 | } 701 | ], 702 | "source": [ 703 | "≡ 7" 704 | ] 705 | }, 706 | { 707 | "cell_type": "markdown", 708 | "id": "3b3f7079-1edd-4d36-8142-f2fad11bf1db", 709 | "metadata": {}, 710 | "source": [ 711 | "An array of simple scalars has depth 1." 712 | ] 713 | }, 714 | { 715 | "cell_type": "code", 716 | "execution_count": null, 717 | "id": "53200fb6", 718 | "metadata": {}, 719 | "outputs": [ 720 | { 721 | "data": { 722 | "text/html": [ 723 | "
 \n",
 724 |        "1\n",
 725 |        " \n",
 726 |        "
" 727 | ] 728 | }, 729 | "execution_count": null, 730 | "metadata": {}, 731 | "output_type": "execute_result" 732 | } 733 | ], 734 | "source": [ 735 | "≡ 'abc'" 736 | ] 737 | }, 738 | { 739 | "cell_type": "markdown", 740 | "id": "a9b106d5-a182-44fc-b3d9-c660344bc186", 741 | "metadata": {}, 742 | "source": [ 743 | "An array that is an array of simple arrays has depth 2." 744 | ] 745 | }, 746 | { 747 | "cell_type": "code", 748 | "execution_count": null, 749 | "id": "35407dd6", 750 | "metadata": {}, 751 | "outputs": [ 752 | { 753 | "data": { 754 | "text/html": [ 755 | "
┌→────────────┐\n",
 756 |        "│ ┌→──┐ ┌→──┐ │\n",
 757 |        "│ │1 2│ │3 4│ │\n",
 758 |        "│ └~──┘ └~──┘ │\n",
 759 |        "└∊────────────┘\n",
 760 |        "
" 761 | ] 762 | }, 763 | "execution_count": null, 764 | "metadata": {}, 765 | "output_type": "execute_result" 766 | } 767 | ], 768 | "source": [ 769 | "(1 2)(3 4)" 770 | ] 771 | }, 772 | { 773 | "cell_type": "code", 774 | "execution_count": null, 775 | "id": "f64d2e8e", 776 | "metadata": {}, 777 | "outputs": [ 778 | { 779 | "data": { 780 | "text/html": [ 781 | "
 \n",
 782 |        "2\n",
 783 |        " \n",
 784 |        "
" 785 | ] 786 | }, 787 | "execution_count": null, 788 | "metadata": {}, 789 | "output_type": "execute_result" 790 | } 791 | ], 792 | "source": [ 793 | "≡ (1 2)(3 4)" 794 | ] 795 | }, 796 | { 797 | "cell_type": "markdown", 798 | "id": "36ec6b8f-882d-483f-a42b-1b2c6f35b559", 799 | "metadata": {}, 800 | "source": [ 801 | "If the depth is not consistent, then it returns the max depth as a negative number." 802 | ] 803 | }, 804 | { 805 | "cell_type": "code", 806 | "execution_count": null, 807 | "id": "0650e6e6", 808 | "metadata": {}, 809 | "outputs": [ 810 | { 811 | "data": { 812 | "text/html": [ 813 | "
┌→────────────────────────┐\n",
 814 |        "│ ┌→──┐ ┌→──┐ ┌→────────┐ │\n",
 815 |        "│ │1 2│ │3 4│ │   ┌→──┐ │ │\n",
 816 |        "│ └~──┘ └~──┘ │ 5 │6 7│ │ │\n",
 817 |        "│             │   └~──┘ │ │\n",
 818 |        "│             └∊────────┘ │\n",
 819 |        "└∊────────────────────────┘\n",
 820 |        "
" 821 | ] 822 | }, 823 | "execution_count": null, 824 | "metadata": {}, 825 | "output_type": "execute_result" 826 | } 827 | ], 828 | "source": [ 829 | "(1 2)(3 4) (5 (6 7))" 830 | ] 831 | }, 832 | { 833 | "cell_type": "code", 834 | "execution_count": null, 835 | "id": "ede6ebf7", 836 | "metadata": {}, 837 | "outputs": [ 838 | { 839 | "data": { 840 | "text/html": [ 841 | "
  \n",
 842 |        "¯3\n",
 843 |        "  \n",
 844 |        "
" 845 | ] 846 | }, 847 | "execution_count": null, 848 | "metadata": {}, 849 | "output_type": "execute_result" 850 | } 851 | ], 852 | "source": [ 853 | "≡ (1 2)(3 4) (5 (6 7))" 854 | ] 855 | }, 856 | { 857 | "cell_type": "markdown", 858 | "id": "d5e95d1d", 859 | "metadata": {}, 860 | "source": [ 861 | "#### dyadic `≡` (Match)" 862 | ] 863 | }, 864 | { 865 | "cell_type": "markdown", 866 | "id": "0819ac30-7d8f-446a-b4b9-e6113514cf1e", 867 | "metadata": {}, 868 | "source": [ 869 | "Match does a comparison to see if 2 objects are equal. It is similar to `=`, but it works on entire objects rather than elementwise. In other words it is equal with a wider scope." 870 | ] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": null, 875 | "id": "8f55c331", 876 | "metadata": {}, 877 | "outputs": [ 878 | { 879 | "data": { 880 | "text/html": [ 881 | "
 \n",
 882 |        "1\n",
 883 |        " \n",
 884 |        "
" 885 | ] 886 | }, 887 | "execution_count": null, 888 | "metadata": {}, 889 | "output_type": "execute_result" 890 | } 891 | ], 892 | "source": [ 893 | "1 ≡ 1" 894 | ] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "execution_count": null, 899 | "id": "ee929e76", 900 | "metadata": {}, 901 | "outputs": [ 902 | { 903 | "data": { 904 | "text/html": [ 905 | "
 \n",
 906 |        "0\n",
 907 |        " \n",
 908 |        "
" 909 | ] 910 | }, 911 | "execution_count": null, 912 | "metadata": {}, 913 | "output_type": "execute_result" 914 | } 915 | ], 916 | "source": [ 917 | "1 ≡ 0" 918 | ] 919 | }, 920 | { 921 | "cell_type": "markdown", 922 | "id": "1f48a33b-e717-47d3-a6f8-3395c759759e", 923 | "metadata": {}, 924 | "source": [ 925 | "`≡` works on whole objects and **not** elementwise with broadcasting." 926 | ] 927 | }, 928 | { 929 | "cell_type": "code", 930 | "execution_count": null, 931 | "id": "1419197c", 932 | "metadata": {}, 933 | "outputs": [ 934 | { 935 | "data": { 936 | "text/html": [ 937 | "
 \n",
 938 |        "0\n",
 939 |        " \n",
 940 |        "
" 941 | ] 942 | }, 943 | "execution_count": null, 944 | "metadata": {}, 945 | "output_type": "execute_result" 946 | } 947 | ], 948 | "source": [ 949 | "1 ≡ 1 1" 950 | ] 951 | }, 952 | { 953 | "cell_type": "markdown", 954 | "id": "284ae899", 955 | "metadata": {}, 956 | "source": [ 957 | "### `≢` (Equal Underbar Slash)" 958 | ] 959 | }, 960 | { 961 | "cell_type": "markdown", 962 | "id": "f6f859db", 963 | "metadata": {}, 964 | "source": [ 965 | "#### monadic `≢` (Tally)" 966 | ] 967 | }, 968 | { 969 | "cell_type": "markdown", 970 | "id": "026eab0b-68de-46c8-874e-f07035768242", 971 | "metadata": {}, 972 | "source": [ 973 | "Tally counts the major cells in an array. This means it gives the length of the leading axis. For a vector, or rank 1 array, this is the same as it's shape but as a scalar." 974 | ] 975 | }, 976 | { 977 | "cell_type": "code", 978 | "execution_count": null, 979 | "id": "10011239", 980 | "metadata": {}, 981 | "outputs": [ 982 | { 983 | "data": { 984 | "text/html": [ 985 | "
 \n",
 986 |        "3\n",
 987 |        " \n",
 988 |        "
" 989 | ] 990 | }, 991 | "execution_count": null, 992 | "metadata": {}, 993 | "output_type": "execute_result" 994 | } 995 | ], 996 | "source": [ 997 | "≢ 1 2 3" 998 | ] 999 | }, 1000 | { 1001 | "cell_type": "code", 1002 | "execution_count": null, 1003 | "id": "6f6449ea", 1004 | "metadata": {}, 1005 | "outputs": [ 1006 | { 1007 | "data": { 1008 | "text/html": [ 1009 | "
┌→┐\n",
1010 |        "│3│\n",
1011 |        "└~┘\n",
1012 |        "
" 1013 | ] 1014 | }, 1015 | "execution_count": null, 1016 | "metadata": {}, 1017 | "output_type": "execute_result" 1018 | } 1019 | ], 1020 | "source": [ 1021 | "⍴ 1 2 3" 1022 | ] 1023 | }, 1024 | { 1025 | "cell_type": "markdown", 1026 | "id": "9adbc6a0-e791-46df-83ef-dcf6787d0ed4", 1027 | "metadata": {}, 1028 | "source": [ 1029 | "If there are multiple dimensions, Tally returns the number of major cells, which is the size of the first dimension" 1030 | ] 1031 | }, 1032 | { 1033 | "cell_type": "code", 1034 | "execution_count": null, 1035 | "id": "7d2d2315", 1036 | "metadata": {}, 1037 | "outputs": [ 1038 | { 1039 | "data": { 1040 | "text/html": [ 1041 | "
 \n",
1042 |        "2\n",
1043 |        " \n",
1044 |        "
" 1045 | ] 1046 | }, 1047 | "execution_count": null, 1048 | "metadata": {}, 1049 | "output_type": "execute_result" 1050 | } 1051 | ], 1052 | "source": [ 1053 | "≢ 2 3 ⍴ ⍳6" 1054 | ] 1055 | }, 1056 | { 1057 | "cell_type": "code", 1058 | "execution_count": null, 1059 | "id": "b5c6f177-ce42-4718-8c3d-710febac94c2", 1060 | "metadata": {}, 1061 | "outputs": [ 1062 | { 1063 | "data": { 1064 | "text/html": [ 1065 | "
 \n",
1066 |        "3\n",
1067 |        " \n",
1068 |        "
" 1069 | ] 1070 | }, 1071 | "execution_count": null, 1072 | "metadata": {}, 1073 | "output_type": "execute_result" 1074 | } 1075 | ], 1076 | "source": [ 1077 | "≢ 3 2 ⍴ ⍳6" 1078 | ] 1079 | }, 1080 | { 1081 | "cell_type": "markdown", 1082 | "id": "63bf5a7c", 1083 | "metadata": {}, 1084 | "source": [ 1085 | "#### dyadic `≢` (Not match)" 1086 | ] 1087 | }, 1088 | { 1089 | "cell_type": "markdown", 1090 | "id": "b22c9e10-a63b-48c0-b811-96f416e76289", 1091 | "metadata": {}, 1092 | "source": [ 1093 | "Not match does a comparison to see if 2 objects are not equal. It is similar to `≠`, but it works on entire objects rather than elementwise. In other words, it is equal with a wider scope." 1094 | ] 1095 | }, 1096 | { 1097 | "cell_type": "code", 1098 | "execution_count": null, 1099 | "id": "762603e0", 1100 | "metadata": {}, 1101 | "outputs": [ 1102 | { 1103 | "data": { 1104 | "text/html": [ 1105 | "
 \n",
1106 |        "0\n",
1107 |        " \n",
1108 |        "
" 1109 | ] 1110 | }, 1111 | "execution_count": null, 1112 | "metadata": {}, 1113 | "output_type": "execute_result" 1114 | } 1115 | ], 1116 | "source": [ 1117 | "1 ≢ 1" 1118 | ] 1119 | }, 1120 | { 1121 | "cell_type": "code", 1122 | "execution_count": null, 1123 | "id": "87ebb14d", 1124 | "metadata": {}, 1125 | "outputs": [ 1126 | { 1127 | "data": { 1128 | "text/html": [ 1129 | "
 \n",
1130 |        "1\n",
1131 |        " \n",
1132 |        "
" 1133 | ] 1134 | }, 1135 | "execution_count": null, 1136 | "metadata": {}, 1137 | "output_type": "execute_result" 1138 | } 1139 | ], 1140 | "source": [ 1141 | "1 ≢ 0" 1142 | ] 1143 | }, 1144 | { 1145 | "cell_type": "markdown", 1146 | "id": "0846d742-8ba9-4a7e-b141-bc8cad0171c6", 1147 | "metadata": {}, 1148 | "source": [ 1149 | "``≢`` works on whole objects and **not** elementwise with broadcasting." 1150 | ] 1151 | }, 1152 | { 1153 | "cell_type": "code", 1154 | "execution_count": null, 1155 | "id": "9f3fb7c0", 1156 | "metadata": {}, 1157 | "outputs": [ 1158 | { 1159 | "data": { 1160 | "text/html": [ 1161 | "
 \n",
1162 |        "1\n",
1163 |        " \n",
1164 |        "
" 1165 | ] 1166 | }, 1167 | "execution_count": null, 1168 | "metadata": {}, 1169 | "output_type": "execute_result" 1170 | } 1171 | ], 1172 | "source": [ 1173 | "1 ≢ 1 1" 1174 | ] 1175 | }, 1176 | { 1177 | "cell_type": "markdown", 1178 | "id": "fa5c0d84", 1179 | "metadata": {}, 1180 | "source": [ 1181 | "### `∨` (Logical or)" 1182 | ] 1183 | }, 1184 | { 1185 | "cell_type": "markdown", 1186 | "id": "42407b65", 1187 | "metadata": {}, 1188 | "source": [ 1189 | "#### dyadic `∨` (Greatest Common Divisor (Or))" 1190 | ] 1191 | }, 1192 | { 1193 | "cell_type": "markdown", 1194 | "id": "37035211-ea5a-424d-8e3f-cd1735dab5a8", 1195 | "metadata": {}, 1196 | "source": [ 1197 | "Standard `or` operator when applied to booleans." 1198 | ] 1199 | }, 1200 | { 1201 | "cell_type": "code", 1202 | "execution_count": null, 1203 | "id": "439d7541", 1204 | "metadata": {}, 1205 | "outputs": [ 1206 | { 1207 | "data": { 1208 | "text/html": [ 1209 | "
┌→──────┐\n",
1210 |        "│0 1 1 1│\n",
1211 |        "└~──────┘\n",
1212 |        "
" 1213 | ] 1214 | }, 1215 | "execution_count": null, 1216 | "metadata": {}, 1217 | "output_type": "execute_result" 1218 | } 1219 | ], 1220 | "source": [ 1221 | "0 1 0 1 ∨ 0 0 1 1 ⍝ Truth table for *or*" 1222 | ] 1223 | }, 1224 | { 1225 | "cell_type": "markdown", 1226 | "id": "ceae61c8-16d3-4c50-83f6-655f20aaeaad", 1227 | "metadata": {}, 1228 | "source": [ 1229 | "5 is the largest number that divides 15 and 35 cleanly (meaning no remainder). Therefore, 5 is the greatest common divisor of 15 and 35." 1230 | ] 1231 | }, 1232 | { 1233 | "cell_type": "code", 1234 | "execution_count": null, 1235 | "id": "47abd9d1", 1236 | "metadata": {}, 1237 | "outputs": [ 1238 | { 1239 | "data": { 1240 | "text/html": [ 1241 | "
┌→──────┐\n",
1242 |        "│5 1 2 7│\n",
1243 |        "└~──────┘\n",
1244 |        "
" 1245 | ] 1246 | }, 1247 | "execution_count": null, 1248 | "metadata": {}, 1249 | "output_type": "execute_result" 1250 | } 1251 | ], 1252 | "source": [ 1253 | "15 1 2 7 ∨ 35 1 4 0 ⍝ GCD" 1254 | ] 1255 | }, 1256 | { 1257 | "cell_type": "markdown", 1258 | "id": "fc3e5b03", 1259 | "metadata": {}, 1260 | "source": [ 1261 | "### `⍱` (Logical NOR)" 1262 | ] 1263 | }, 1264 | { 1265 | "cell_type": "markdown", 1266 | "id": "47ff8cd5", 1267 | "metadata": {}, 1268 | "source": [ 1269 | "#### dyadic `⍱` (Nor)" 1270 | ] 1271 | }, 1272 | { 1273 | "cell_type": "markdown", 1274 | "id": "f067a891-a383-4794-9e2e-731f6d750c69", 1275 | "metadata": {}, 1276 | "source": [ 1277 | "For more details on logical nor, [see this page](https://en.wikipedia.org/wiki/Logical_NOR#Truth_table)" 1278 | ] 1279 | }, 1280 | { 1281 | "cell_type": "code", 1282 | "execution_count": null, 1283 | "id": "dc80c88d", 1284 | "metadata": {}, 1285 | "outputs": [ 1286 | { 1287 | "data": { 1288 | "text/html": [ 1289 | "
┌→──────┐\n",
1290 |        "│1 0 0 0│\n",
1291 |        "└~──────┘\n",
1292 |        "
" 1293 | ] 1294 | }, 1295 | "execution_count": null, 1296 | "metadata": {}, 1297 | "output_type": "execute_result" 1298 | } 1299 | ], 1300 | "source": [ 1301 | " 0 1 0 1 ⍱ 0 0 1 1 ⍝ Truth table for *nor*" 1302 | ] 1303 | }, 1304 | { 1305 | "cell_type": "markdown", 1306 | "id": "27932e1b", 1307 | "metadata": {}, 1308 | "source": [ 1309 | "### `∧` (Logical AND)" 1310 | ] 1311 | }, 1312 | { 1313 | "cell_type": "markdown", 1314 | "id": "31a3b8b5", 1315 | "metadata": {}, 1316 | "source": [ 1317 | "#### dyadic `∧` (Lowest Common Multiple (And))" 1318 | ] 1319 | }, 1320 | { 1321 | "cell_type": "markdown", 1322 | "id": "65f4a4d0-59ed-4e72-914e-c2ef482d8291", 1323 | "metadata": {}, 1324 | "source": [ 1325 | "Standard `and` operator when applied to booleans." 1326 | ] 1327 | }, 1328 | { 1329 | "cell_type": "code", 1330 | "execution_count": null, 1331 | "id": "ac4309ef", 1332 | "metadata": {}, 1333 | "outputs": [ 1334 | { 1335 | "data": { 1336 | "text/html": [ 1337 | "
┌→──────┐\n",
1338 |        "│0 0 0 1│\n",
1339 |        "└~──────┘\n",
1340 |        "
" 1341 | ] 1342 | }, 1343 | "execution_count": null, 1344 | "metadata": {}, 1345 | "output_type": "execute_result" 1346 | } 1347 | ], 1348 | "source": [ 1349 | "0 1 0 1 ∧ 0 0 1 1 ⍝ Truth table for *and*" 1350 | ] 1351 | }, 1352 | { 1353 | "cell_type": "markdown", 1354 | "id": "71b974e9-6f78-4e29-937f-ffb31a62af74", 1355 | "metadata": {}, 1356 | "source": [ 1357 | "105 is the smallest multiple of both 15 and 35, therefore 105 is the lowest common multiple of 15 and 35." 1358 | ] 1359 | }, 1360 | { 1361 | "cell_type": "code", 1362 | "execution_count": null, 1363 | "id": "fbfaebf4", 1364 | "metadata": {}, 1365 | "outputs": [ 1366 | { 1367 | "data": { 1368 | "text/html": [ 1369 | "
┌→────────┐\n",
1370 |        "│105 1 4 0│\n",
1371 |        "└~────────┘\n",
1372 |        "
" 1373 | ] 1374 | }, 1375 | "execution_count": null, 1376 | "metadata": {}, 1377 | "output_type": "execute_result" 1378 | } 1379 | ], 1380 | "source": [ 1381 | "15 1 2 7 ∧ 35 1 4 0 ⍝ LCM" 1382 | ] 1383 | }, 1384 | { 1385 | "cell_type": "markdown", 1386 | "id": "04987504-6a54-4e01-b38f-3e69b99c1abe", 1387 | "metadata": {}, 1388 | "source": [ 1389 | "### `~` (Logical NOT)" 1390 | ] 1391 | }, 1392 | { 1393 | "cell_type": "markdown", 1394 | "id": "09ab7565-f35c-4072-ab77-3e1cd58e17ee", 1395 | "metadata": {}, 1396 | "source": [ 1397 | "#### monadic `~` (Not)" 1398 | ] 1399 | }, 1400 | { 1401 | "cell_type": "code", 1402 | "execution_count": null, 1403 | "id": "b0abb3ae", 1404 | "metadata": {}, 1405 | "outputs": [ 1406 | { 1407 | "data": { 1408 | "text/html": [ 1409 | "
┌→──┐\n",
1410 |        "│1 0│\n",
1411 |        "└~──┘\n",
1412 |        "
" 1413 | ] 1414 | }, 1415 | "execution_count": null, 1416 | "metadata": {}, 1417 | "output_type": "execute_result" 1418 | } 1419 | ], 1420 | "source": [ 1421 | "~ 0 1 ⍝ Truth table for *not*" 1422 | ] 1423 | }, 1424 | { 1425 | "cell_type": "markdown", 1426 | "id": "190b5d68-57b5-4f04-a21e-3864fe8d8122", 1427 | "metadata": {}, 1428 | "source": [ 1429 | "#### dyadic `~` (Without;Excluding)" 1430 | ] 1431 | }, 1432 | { 1433 | "cell_type": "markdown", 1434 | "id": "d41d8180-bfaa-46f2-808e-d451673f4e5f", 1435 | "metadata": {}, 1436 | "source": [ 1437 | "Gives the elements from the left argument that are not in the right." 1438 | ] 1439 | }, 1440 | { 1441 | "cell_type": "code", 1442 | "execution_count": null, 1443 | "id": "f6b788cd", 1444 | "metadata": {}, 1445 | "outputs": [ 1446 | { 1447 | "data": { 1448 | "text/html": [ 1449 | "
┌→──┐\n",
1450 |        "│3 4│\n",
1451 |        "└~──┘\n",
1452 |        "
" 1453 | ] 1454 | }, 1455 | "execution_count": null, 1456 | "metadata": {}, 1457 | "output_type": "execute_result" 1458 | } 1459 | ], 1460 | "source": [ 1461 | "3 1 4 1 5 ~ 5 1" 1462 | ] 1463 | }, 1464 | { 1465 | "cell_type": "markdown", 1466 | "id": "82641989-2b43-4e01-a3d1-0489c417cae5", 1467 | "metadata": {}, 1468 | "source": [ 1469 | "Also works on the character vectors" 1470 | ] 1471 | }, 1472 | { 1473 | "cell_type": "code", 1474 | "execution_count": null, 1475 | "id": "bfdf7e89", 1476 | "metadata": {}, 1477 | "outputs": [ 1478 | { 1479 | "data": { 1480 | "text/html": [ 1481 | "
┌→──────────┐\n",
1482 |        "│ ┌→─┐ ┌→─┐ │\n",
1483 |        "│ │aa│ │cc│ │\n",
1484 |        "│ └──┘ └──┘ │\n",
1485 |        "└∊──────────┘\n",
1486 |        "
" 1487 | ] 1488 | }, 1489 | "execution_count": null, 1490 | "metadata": {}, 1491 | "output_type": "execute_result" 1492 | } 1493 | ], 1494 | "source": [ 1495 | "'aa' 'bb' 'cc' 'bb' ~ 'bb' 'xx'" 1496 | ] 1497 | }, 1498 | { 1499 | "cell_type": "markdown", 1500 | "id": "51a97128-c2ee-499a-a5e7-2f2e84897496", 1501 | "metadata": {}, 1502 | "source": [ 1503 | "Also works on nested arrays" 1504 | ] 1505 | }, 1506 | { 1507 | "cell_type": "code", 1508 | "execution_count": null, 1509 | "id": "9085478e", 1510 | "metadata": {}, 1511 | "outputs": [ 1512 | { 1513 | "data": { 1514 | "text/html": [ 1515 | "
┌→┐\n",
1516 |        "│3│\n",
1517 |        "└~┘\n",
1518 |        "
" 1519 | ] 1520 | }, 1521 | "execution_count": null, 1522 | "metadata": {}, 1523 | "output_type": "execute_result" 1524 | } 1525 | ], 1526 | "source": [ 1527 | "(1 2) 3 ~ ⊂1 2" 1528 | ] 1529 | }, 1530 | { 1531 | "cell_type": "markdown", 1532 | "id": "5f8cab64", 1533 | "metadata": {}, 1534 | "source": [ 1535 | "### `⍲` (Logical NAND)" 1536 | ] 1537 | }, 1538 | { 1539 | "cell_type": "markdown", 1540 | "id": "8b59feac", 1541 | "metadata": {}, 1542 | "source": [ 1543 | "#### dyadic `⍲` (Nand)" 1544 | ] 1545 | }, 1546 | { 1547 | "cell_type": "markdown", 1548 | "id": "abf07f68-d2d1-4784-b9f3-2fce4665a498", 1549 | "metadata": {}, 1550 | "source": [ 1551 | "Nand is \"Not and\"" 1552 | ] 1553 | }, 1554 | { 1555 | "cell_type": "code", 1556 | "execution_count": null, 1557 | "id": "0ee272ec", 1558 | "metadata": {}, 1559 | "outputs": [ 1560 | { 1561 | "data": { 1562 | "text/html": [ 1563 | "
┌→──────┐\n",
1564 |        "│1 1 1 0│\n",
1565 |        "└~──────┘\n",
1566 |        "
" 1567 | ] 1568 | }, 1569 | "execution_count": null, 1570 | "metadata": {}, 1571 | "output_type": "execute_result" 1572 | } 1573 | ], 1574 | "source": [ 1575 | " 0 1 0 1 ⍲ 0 0 1 1 ⍝ Truth table for *nand*" 1576 | ] 1577 | }, 1578 | { 1579 | "cell_type": "markdown", 1580 | "id": "327836f3-8acd-474d-a594-2fa525763bc6", 1581 | "metadata": {}, 1582 | "source": [ 1583 | "We could use and (`^`) apply not (`~`) afterward to get the same result. As you can see it truly is \"Not and\"" 1584 | ] 1585 | }, 1586 | { 1587 | "cell_type": "code", 1588 | "execution_count": null, 1589 | "id": "113f86fa-9645-4c8e-b559-6b5cf7c822f8", 1590 | "metadata": {}, 1591 | "outputs": [ 1592 | { 1593 | "data": { 1594 | "text/html": [ 1595 | "
┌→──────┐\n",
1596 |        "│1 1 1 0│\n",
1597 |        "└~──────┘\n",
1598 |        "
" 1599 | ] 1600 | }, 1601 | "execution_count": null, 1602 | "metadata": {}, 1603 | "output_type": "execute_result" 1604 | } 1605 | ], 1606 | "source": [ 1607 | "~ 0 1 0 1 ∧ 0 0 1 1 ⍝ Truth table for *nand*" 1608 | ] 1609 | }, 1610 | { 1611 | "cell_type": "markdown", 1612 | "id": "ebf0e3e4", 1613 | "metadata": {}, 1614 | "source": [ 1615 | "### `/` (Slash)" 1616 | ] 1617 | }, 1618 | { 1619 | "cell_type": "markdown", 1620 | "id": "81223d6f", 1621 | "metadata": {}, 1622 | "source": [ 1623 | "#### monadic `/` (Replicate)" 1624 | ] 1625 | }, 1626 | { 1627 | "cell_type": "code", 1628 | "execution_count": null, 1629 | "id": "1e6ccb42", 1630 | "metadata": {}, 1631 | "outputs": [ 1632 | { 1633 | "data": { 1634 | "text/html": [ 1635 | "
┌→──────────────┐\n",
1636 |        "│1 1 0 0 1 0 1 0│\n",
1637 |        "└~──────────────┘\n",
1638 |        "
" 1639 | ] 1640 | }, 1641 | "execution_count": null, 1642 | "metadata": {}, 1643 | "output_type": "execute_result" 1644 | } 1645 | ], 1646 | "source": [ 1647 | "v←22 10 22 22 21 10 5 10\n", 1648 | "≠v" 1649 | ] 1650 | }, 1651 | { 1652 | "cell_type": "code", 1653 | "execution_count": null, 1654 | "id": "ed0370b6", 1655 | "metadata": {}, 1656 | "outputs": [ 1657 | { 1658 | "data": { 1659 | "text/html": [ 1660 | "
┌→─────────┐\n",
1661 |        "│22 10 21 5│\n",
1662 |        "└~─────────┘\n",
1663 |        "
" 1664 | ] 1665 | }, 1666 | "execution_count": null, 1667 | "metadata": {}, 1668 | "output_type": "execute_result" 1669 | } 1670 | ], 1671 | "source": [ 1672 | "(≠v)/v" 1673 | ] 1674 | }, 1675 | { 1676 | "cell_type": "code", 1677 | "execution_count": null, 1678 | "id": "4a7aa794", 1679 | "metadata": {}, 1680 | "outputs": [ 1681 | { 1682 | "data": { 1683 | "text/html": [ 1684 | "
┌→───────────┐\n",
1685 |        "│BBBannnannna│\n",
1686 |        "└────────────┘\n",
1687 |        "
" 1688 | ] 1689 | }, 1690 | "execution_count": null, 1691 | "metadata": {}, 1692 | "output_type": "execute_result" 1693 | } 1694 | ], 1695 | "source": [ 1696 | "3 1 3 1 3 1 / 'Banana'" 1697 | ] 1698 | }, 1699 | { 1700 | "cell_type": "markdown", 1701 | "id": "95f0d135", 1702 | "metadata": {}, 1703 | "source": [ 1704 | "## Min, max, index, concat" 1705 | ] 1706 | }, 1707 | { 1708 | "cell_type": "markdown", 1709 | "id": "c184a076", 1710 | "metadata": {}, 1711 | "source": [ 1712 | "### `⍳` (iota)" 1713 | ] 1714 | }, 1715 | { 1716 | "cell_type": "markdown", 1717 | "id": "8485edff", 1718 | "metadata": {}, 1719 | "source": [ 1720 | "#### monadic `⍳` (index generator)" 1721 | ] 1722 | }, 1723 | { 1724 | "cell_type": "markdown", 1725 | "id": "6581d1bf-551f-42b5-a027-b080d72d4629", 1726 | "metadata": {}, 1727 | "source": [ 1728 | "Creates index locations for array with specified shape." 1729 | ] 1730 | }, 1731 | { 1732 | "cell_type": "code", 1733 | "execution_count": null, 1734 | "id": "69cc99e0", 1735 | "metadata": {}, 1736 | "outputs": [ 1737 | { 1738 | "data": { 1739 | "text/html": [ 1740 | "
┌→──────┐\n",
1741 |        "│1 2 3 4│\n",
1742 |        "└~──────┘\n",
1743 |        "
" 1744 | ] 1745 | }, 1746 | "execution_count": null, 1747 | "metadata": {}, 1748 | "output_type": "execute_result" 1749 | } 1750 | ], 1751 | "source": [ 1752 | "⍳4" 1753 | ] 1754 | }, 1755 | { 1756 | "cell_type": "code", 1757 | "execution_count": null, 1758 | "id": "155302ac", 1759 | "metadata": {}, 1760 | "outputs": [ 1761 | { 1762 | "data": { 1763 | "text/html": [ 1764 | "
┌→──────────────────┐\n",
1765 |        "↓ ┌→──┐ ┌→──┐ ┌→──┐ │\n",
1766 |        "│ │1 1│ │1 2│ │1 3│ │\n",
1767 |        "│ └~──┘ └~──┘ └~──┘ │\n",
1768 |        "│ ┌→──┐ ┌→──┐ ┌→──┐ │\n",
1769 |        "│ │2 1│ │2 2│ │2 3│ │\n",
1770 |        "│ └~──┘ └~──┘ └~──┘ │\n",
1771 |        "└∊──────────────────┘\n",
1772 |        "
" 1773 | ] 1774 | }, 1775 | "execution_count": null, 1776 | "metadata": {}, 1777 | "output_type": "execute_result" 1778 | } 1779 | ], 1780 | "source": [ 1781 | "⍳2 3" 1782 | ] 1783 | }, 1784 | { 1785 | "cell_type": "markdown", 1786 | "id": "841c9175-1100-41ed-8a7c-ec4bb7783504", 1787 | "metadata": {}, 1788 | "source": [ 1789 | "`⍳` is often used with `⍴` to create arrays " 1790 | ] 1791 | }, 1792 | { 1793 | "cell_type": "code", 1794 | "execution_count": null, 1795 | "id": "73e93a04", 1796 | "metadata": {}, 1797 | "outputs": [ 1798 | { 1799 | "data": { 1800 | "text/html": [ 1801 | "
┌→────┐\n",
1802 |        "↓1 2 3│\n",
1803 |        "│4 5 6│\n",
1804 |        "└~────┘\n",
1805 |        "
" 1806 | ] 1807 | }, 1808 | "execution_count": null, 1809 | "metadata": {}, 1810 | "output_type": "execute_result" 1811 | } 1812 | ], 1813 | "source": [ 1814 | "2 3 ⍴ ⍳6" 1815 | ] 1816 | }, 1817 | { 1818 | "cell_type": "markdown", 1819 | "id": "22e8cdfd-5251-432f-b0a6-716bd803085d", 1820 | "metadata": {}, 1821 | "source": [ 1822 | "To generate an array with various patterns you can combine with other functions." 1823 | ] 1824 | }, 1825 | { 1826 | "cell_type": "code", 1827 | "execution_count": null, 1828 | "id": "1744f807", 1829 | "metadata": {}, 1830 | "outputs": [ 1831 | { 1832 | "data": { 1833 | "text/html": [ 1834 | "
┌→────────────┐\n",
1835 |        "│3 5 7 9 11 13│\n",
1836 |        "└~────────────┘\n",
1837 |        "
" 1838 | ] 1839 | }, 1840 | "execution_count": null, 1841 | "metadata": {}, 1842 | "output_type": "execute_result" 1843 | } 1844 | ], 1845 | "source": [ 1846 | "1+2×⍳6" 1847 | ] 1848 | }, 1849 | { 1850 | "cell_type": "markdown", 1851 | "id": "f92ecb85-02b0-46fe-9812-d4ed90ed9498", 1852 | "metadata": {}, 1853 | "source": [ 1854 | "Array of shape 0 is nan empty vector and the index locations of a shape 0 array is and empty vector." 1855 | ] 1856 | }, 1857 | { 1858 | "cell_type": "code", 1859 | "execution_count": null, 1860 | "id": "3fd77f85", 1861 | "metadata": {}, 1862 | "outputs": [ 1863 | { 1864 | "data": { 1865 | "text/html": [ 1866 | "
┌⊖┐\n",
1867 |        "│0│\n",
1868 |        "└~┘\n",
1869 |        "
" 1870 | ] 1871 | }, 1872 | "execution_count": null, 1873 | "metadata": {}, 1874 | "output_type": "execute_result" 1875 | } 1876 | ], 1877 | "source": [ 1878 | "⍳0" 1879 | ] 1880 | }, 1881 | { 1882 | "cell_type": "markdown", 1883 | "id": "51f01e92", 1884 | "metadata": {}, 1885 | "source": [ 1886 | "#### dyadic `⍳` (index of)" 1887 | ] 1888 | }, 1889 | { 1890 | "cell_type": "markdown", 1891 | "id": "24713038-4260-48c3-aa7a-e79815cec6e8", 1892 | "metadata": {}, 1893 | "source": [ 1894 | "Provides the index locations for where `⍵` (right argument) is in `⍺` (left argument)" 1895 | ] 1896 | }, 1897 | { 1898 | "cell_type": "code", 1899 | "execution_count": null, 1900 | "id": "db34fc0c", 1901 | "metadata": {}, 1902 | "outputs": [ 1903 | { 1904 | "data": { 1905 | "text/html": [ 1906 | "
 \n",
1907 |        "2\n",
1908 |        " \n",
1909 |        "
" 1910 | ] 1911 | }, 1912 | "execution_count": null, 1913 | "metadata": {}, 1914 | "output_type": "execute_result" 1915 | } 1916 | ], 1917 | "source": [ 1918 | "1 3 6 5 4 ⍳ 3" 1919 | ] 1920 | }, 1921 | { 1922 | "cell_type": "code", 1923 | "execution_count": null, 1924 | "id": "1604dc20", 1925 | "metadata": {}, 1926 | "outputs": [ 1927 | { 1928 | "data": { 1929 | "text/html": [ 1930 | "
┌→────────┐\n",
1931 |        "│1 3 10 11│\n",
1932 |        "└~────────┘\n",
1933 |        "
" 1934 | ] 1935 | }, 1936 | "execution_count": null, 1937 | "metadata": {}, 1938 | "output_type": "execute_result" 1939 | } 1940 | ], 1941 | "source": [ 1942 | "'ABCDABCDEF' ⍳ 'ACFG'" 1943 | ] 1944 | }, 1945 | { 1946 | "cell_type": "code", 1947 | "execution_count": null, 1948 | "id": "e6a697da", 1949 | "metadata": {}, 1950 | "outputs": [ 1951 | { 1952 | "data": { 1953 | "text/html": [ 1954 | "
┌→──┐\n",
1955 |        "↓1 2│\n",
1956 |        "│3 4│\n",
1957 |        "│5 6│\n",
1958 |        "└~──┘\n",
1959 |        "
" 1960 | ] 1961 | }, 1962 | "execution_count": null, 1963 | "metadata": {}, 1964 | "output_type": "execute_result" 1965 | } 1966 | ], 1967 | "source": [ 1968 | "⎕←mat←3 2 ⍴ ⍳6" 1969 | ] 1970 | }, 1971 | { 1972 | "cell_type": "markdown", 1973 | "id": "4a0af1fb-7e47-4b68-8639-2d5e34d75dc2", 1974 | "metadata": {}, 1975 | "source": [ 1976 | "`⍳` works on major cells, or along the first dimension. The third major cell of mat is `5 6`." 1977 | ] 1978 | }, 1979 | { 1980 | "cell_type": "code", 1981 | "execution_count": null, 1982 | "id": "e7e56d92", 1983 | "metadata": {}, 1984 | "outputs": [ 1985 | { 1986 | "data": { 1987 | "text/html": [ 1988 | "
 \n",
1989 |        "3\n",
1990 |        " \n",
1991 |        "
" 1992 | ] 1993 | }, 1994 | "execution_count": null, 1995 | "metadata": {}, 1996 | "output_type": "execute_result" 1997 | } 1998 | ], 1999 | "source": [ 2000 | "mat←3 2 ⍴ ⍳6\n", 2001 | "mat ⍳ 5 6" 2002 | ] 2003 | }, 2004 | { 2005 | "cell_type": "markdown", 2006 | "id": "8dbfe270", 2007 | "metadata": {}, 2008 | "source": [ 2009 | "### `⍸` (iota underbar)" 2010 | ] 2011 | }, 2012 | { 2013 | "cell_type": "markdown", 2014 | "id": "c623312c", 2015 | "metadata": {}, 2016 | "source": [ 2017 | "#### monadic `⍸` (Where)" 2018 | ] 2019 | }, 2020 | { 2021 | "cell_type": "markdown", 2022 | "id": "6eb50df5-420e-456b-aebc-df8bcc377870", 2023 | "metadata": {}, 2024 | "source": [ 2025 | "When applied to a boolean/binary array, where gives index locations of the true values." 2026 | ] 2027 | }, 2028 | { 2029 | "cell_type": "code", 2030 | "execution_count": null, 2031 | "id": "cd826c58", 2032 | "metadata": {}, 2033 | "outputs": [ 2034 | { 2035 | "data": { 2036 | "text/html": [ 2037 | "
┌→────┐\n",
2038 |        "│1 4 5│\n",
2039 |        "└~────┘\n",
2040 |        "
" 2041 | ] 2042 | }, 2043 | "execution_count": null, 2044 | "metadata": {}, 2045 | "output_type": "execute_result" 2046 | } 2047 | ], 2048 | "source": [ 2049 | "⍸ 1 0 0 1 1" 2050 | ] 2051 | }, 2052 | { 2053 | "cell_type": "markdown", 2054 | "id": "80929a44-9b23-491a-98ef-d530ba1f3490", 2055 | "metadata": {}, 2056 | "source": [ 2057 | "When applied to a natural number, where repeats the index locations if the number is greater than 1. For example `⍸1 2 3` would give `1 2 2 3 3 3`" 2058 | ] 2059 | }, 2060 | { 2061 | "cell_type": "code", 2062 | "execution_count": null, 2063 | "id": "1b6a928b-705a-48bc-89b9-0f48158568cc", 2064 | "metadata": {}, 2065 | "outputs": [ 2066 | { 2067 | "data": { 2068 | "text/html": [ 2069 | "
┌→──────────┐\n",
2070 |        "│1 2 2 3 3 3│\n",
2071 |        "└~──────────┘\n",
2072 |        "
" 2073 | ] 2074 | }, 2075 | "execution_count": null, 2076 | "metadata": {}, 2077 | "output_type": "execute_result" 2078 | } 2079 | ], 2080 | "source": [ 2081 | "⍸1 2 3" 2082 | ] 2083 | }, 2084 | { 2085 | "cell_type": "code", 2086 | "execution_count": null, 2087 | "id": "f6dd11af", 2088 | "metadata": {}, 2089 | "outputs": [ 2090 | { 2091 | "data": { 2092 | "text/html": [ 2093 | "
┌→────────┐\n",
2094 |        "│1 1 4 4 5│\n",
2095 |        "└~────────┘\n",
2096 |        "
" 2097 | ] 2098 | }, 2099 | "execution_count": null, 2100 | "metadata": {}, 2101 | "output_type": "execute_result" 2102 | } 2103 | ], 2104 | "source": [ 2105 | "⍸ 2 0 0 2 1" 2106 | ] 2107 | }, 2108 | { 2109 | "cell_type": "markdown", 2110 | "id": "7be22017-4047-404f-a9fa-34c0a589c6ed", 2111 | "metadata": {}, 2112 | "source": [ 2113 | "When applied to a higher rank array it still provides the index locations of the elements, but index locations have multiple values (in this case row and column)." 2114 | ] 2115 | }, 2116 | { 2117 | "cell_type": "code", 2118 | "execution_count": null, 2119 | "id": "a8a4bf88", 2120 | "metadata": {}, 2121 | "outputs": [ 2122 | { 2123 | "data": { 2124 | "text/html": [ 2125 | "
┌→────┐\n",
2126 |        "↓0 1 0│\n",
2127 |        "│1 0 1│\n",
2128 |        "└~────┘\n",
2129 |        "
" 2130 | ] 2131 | }, 2132 | "execution_count": null, 2133 | "metadata": {}, 2134 | "output_type": "execute_result" 2135 | }, 2136 | { 2137 | "data": { 2138 | "text/html": [ 2139 | "
┌→──────────────────┐\n",
2140 |        "│ ┌→──┐ ┌→──┐ ┌→──┐ │\n",
2141 |        "│ │1 2│ │2 1│ │2 3│ │\n",
2142 |        "│ └~──┘ └~──┘ └~──┘ │\n",
2143 |        "└∊──────────────────┘\n",
2144 |        "
" 2145 | ] 2146 | }, 2147 | "execution_count": null, 2148 | "metadata": {}, 2149 | "output_type": "execute_result" 2150 | } 2151 | ], 2152 | "source": [ 2153 | "⎕←bmat ← 2 3 ⍴ 0 1 0 1 0 1\n", 2154 | "⍸ bmat" 2155 | ] 2156 | }, 2157 | { 2158 | "cell_type": "code", 2159 | "execution_count": null, 2160 | "id": "b3c0b9fa-98a8-4914-973e-57e01081c83b", 2161 | "metadata": {}, 2162 | "outputs": [ 2163 | { 2164 | "data": { 2165 | "text/html": [ 2166 | "
┌→────┐\n",
2167 |        "↓0 2 0│\n",
2168 |        "│2 0 2│\n",
2169 |        "└~────┘\n",
2170 |        "
" 2171 | ] 2172 | }, 2173 | "execution_count": null, 2174 | "metadata": {}, 2175 | "output_type": "execute_result" 2176 | }, 2177 | { 2178 | "data": { 2179 | "text/html": [ 2180 | "
┌→────────────────────────────────────┐\n",
2181 |        "│ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ ┌→──┐ │\n",
2182 |        "│ │1 2│ │1 2│ │2 1│ │2 1│ │2 3│ │2 3│ │\n",
2183 |        "│ └~──┘ └~──┘ └~──┘ └~──┘ └~──┘ └~──┘ │\n",
2184 |        "└∊────────────────────────────────────┘\n",
2185 |        "
" 2186 | ] 2187 | }, 2188 | "execution_count": null, 2189 | "metadata": {}, 2190 | "output_type": "execute_result" 2191 | } 2192 | ], 2193 | "source": [ 2194 | "⎕←bmat ← 2 3 ⍴ 0 2 0 2 0 2\n", 2195 | "⍸ bmat" 2196 | ] 2197 | }, 2198 | { 2199 | "cell_type": "markdown", 2200 | "id": "1c86ab76", 2201 | "metadata": {}, 2202 | "source": [ 2203 | "#### dyadic `⍸` (Interval Index)" 2204 | ] 2205 | }, 2206 | { 2207 | "cell_type": "markdown", 2208 | "id": "057b305f-dd6e-4658-9c53-55576cef9585", 2209 | "metadata": {}, 2210 | "source": [ 2211 | "Interval index creates intervals and returns an array that tells you which interval a value falls in.\n", 2212 | "\n", 2213 | "If the following example, `⍵` is `2 4 6`. Therefore the following intervals (sometimes called bins) are created.\n", 2214 | "\n", 2215 | "+ **0th interval:** Less than 2\n", 2216 | "+ **1st interval:** 2-4 (excluding 4)\n", 2217 | "+ **2nd interval:** 4-6 (excluding 6)\n", 2218 | "+ **3rd interval:** Greater than or equal to 6\n", 2219 | "\n", 2220 | "`⍺` (right argument) is `1 2 3 4 5 6 7` so let's put those into intervals, which the first interval starting at 0.\n", 2221 | "\n", 2222 | "+ The first value of `⍺` is 1. 1 is Less than 2. Therefore it is in the 0th interval and interval index returns 0.\n", 2223 | "+ The second value of `⍺` is 2. 2 is in the 2-4 range. Therefore it is in the 1st interval and interval index returns 1.\n", 2224 | "+ The third value of `⍺` is 3. 3 is in the 2-4 range. Therefore it is in the 1st interval and interval index returns 1.\n", 2225 | "+ The fourth value of `⍺` is 4. 4 is in the 4-6 range. Therefore it is in the 2nd interval and interval index returns 2.\n", 2226 | "\n", 2227 | "And so on and so forth." 2228 | ] 2229 | }, 2230 | { 2231 | "cell_type": "code", 2232 | "execution_count": null, 2233 | "id": "c402ce31", 2234 | "metadata": {}, 2235 | "outputs": [ 2236 | { 2237 | "data": { 2238 | "text/html": [ 2239 | "
┌→────────────┐\n",
2240 |        "│0 1 1 2 2 3 3│\n",
2241 |        "└~────────────┘\n",
2242 |        "
" 2243 | ] 2244 | }, 2245 | "execution_count": null, 2246 | "metadata": {}, 2247 | "output_type": "execute_result" 2248 | } 2249 | ], 2250 | "source": [ 2251 | "2 4 6 ⍸ 1 2 3 4 5 6 7" 2252 | ] 2253 | }, 2254 | { 2255 | "cell_type": "markdown", 2256 | "id": "46aea64b-c2d1-4ce9-ab66-de44e7cf5f52", 2257 | "metadata": {}, 2258 | "source": [ 2259 | "Interval index works the same way with character vectors.\n", 2260 | "\n", 2261 | "+ `D` is in the first interval because it is between `A` and `E`.\n", 2262 | "+ `Y` is in the last interval (fifth) because it is larger than all values\n", 2263 | "+ `A` is in the first interval because it is between `A` and `E`.\n", 2264 | "+ `L` is in the third interval because it is between `I` and `O`.\n", 2265 | "\n", 2266 | "etc." 2267 | ] 2268 | }, 2269 | { 2270 | "cell_type": "code", 2271 | "execution_count": null, 2272 | "id": "f66c7d8a", 2273 | "metadata": {}, 2274 | "outputs": [ 2275 | { 2276 | "data": { 2277 | "text/html": [ 2278 | "
┌→──────────┐\n",
2279 |        "│1 5 1 3 4 2│\n",
2280 |        "└~──────────┘\n",
2281 |        "
" 2282 | ] 2283 | }, 2284 | "execution_count": null, 2285 | "metadata": {}, 2286 | "output_type": "execute_result" 2287 | } 2288 | ], 2289 | "source": [ 2290 | "'AEIOU' ⍸ 'DYALOG'" 2291 | ] 2292 | }, 2293 | { 2294 | "cell_type": "markdown", 2295 | "id": "88e6e4a7-6538-4372-b752-48c2cfc9dfb1", 2296 | "metadata": {}, 2297 | "source": [ 2298 | "Interval index works across major cells." 2299 | ] 2300 | }, 2301 | { 2302 | "cell_type": "code", 2303 | "execution_count": null, 2304 | "id": "9c607eb4", 2305 | "metadata": {}, 2306 | "outputs": [ 2307 | { 2308 | "data": { 2309 | "text/html": [ 2310 | "
┌→──┐\n",
2311 |        "↓1 2│\n",
2312 |        "│3 4│\n",
2313 |        "│5 6│\n",
2314 |        "└~──┘\n",
2315 |        "
" 2316 | ] 2317 | }, 2318 | "execution_count": null, 2319 | "metadata": {}, 2320 | "output_type": "execute_result" 2321 | } 2322 | ], 2323 | "source": [ 2324 | "⎕←mat←3 2⍴⍳6" 2325 | ] 2326 | }, 2327 | { 2328 | "cell_type": "code", 2329 | "execution_count": null, 2330 | "id": "d4e1c0b4", 2331 | "metadata": {}, 2332 | "outputs": [ 2333 | { 2334 | "data": { 2335 | "text/html": [ 2336 | "
 \n",
2337 |        "1\n",
2338 |        " \n",
2339 |        "
" 2340 | ] 2341 | }, 2342 | "execution_count": null, 2343 | "metadata": {}, 2344 | "output_type": "execute_result" 2345 | } 2346 | ], 2347 | "source": [ 2348 | "mat ⍸ 3 3" 2349 | ] 2350 | }, 2351 | { 2352 | "cell_type": "code", 2353 | "execution_count": null, 2354 | "id": "5af2f8d1", 2355 | "metadata": {}, 2356 | "outputs": [ 2357 | { 2358 | "data": { 2359 | "text/html": [ 2360 | "
 \n",
2361 |        "2\n",
2362 |        " \n",
2363 |        "
" 2364 | ] 2365 | }, 2366 | "execution_count": null, 2367 | "metadata": {}, 2368 | "output_type": "execute_result" 2369 | } 2370 | ], 2371 | "source": [ 2372 | "mat ⍸ 3 5" 2373 | ] 2374 | }, 2375 | { 2376 | "cell_type": "code", 2377 | "execution_count": null, 2378 | "id": "fc9be234", 2379 | "metadata": {}, 2380 | "outputs": [ 2381 | { 2382 | "data": { 2383 | "text/html": [ 2384 | "
┌→──┐\n",
2385 |        "│1 2│\n",
2386 |        "└~──┘\n",
2387 |        "
" 2388 | ] 2389 | }, 2390 | "execution_count": null, 2391 | "metadata": {}, 2392 | "output_type": "execute_result" 2393 | } 2394 | ], 2395 | "source": [ 2396 | "mat ⍸ 2 2 ⍴ 3 3 3 5" 2397 | ] 2398 | }, 2399 | { 2400 | "cell_type": "markdown", 2401 | "id": "ad28d0b2", 2402 | "metadata": {}, 2403 | "source": [ 2404 | "### `⌈` (Upstile)" 2405 | ] 2406 | }, 2407 | { 2408 | "cell_type": "markdown", 2409 | "id": "3db6d6cb", 2410 | "metadata": {}, 2411 | "source": [ 2412 | "#### monadic `⌈` (Ceiling)" 2413 | ] 2414 | }, 2415 | { 2416 | "cell_type": "markdown", 2417 | "id": "f162a21e-b887-4a58-bb02-9c70e67100fa", 2418 | "metadata": {}, 2419 | "source": [ 2420 | "Rounds up to nearest whole number." 2421 | ] 2422 | }, 2423 | { 2424 | "cell_type": "code", 2425 | "execution_count": null, 2426 | "id": "7223b897", 2427 | "metadata": {}, 2428 | "outputs": [ 2429 | { 2430 | "data": { 2431 | "text/html": [ 2432 | "
┌→───────┐\n",
2433 |        "│4 ¯3 3 0│\n",
2434 |        "└~───────┘\n",
2435 |        "
" 2436 | ] 2437 | }, 2438 | "execution_count": null, 2439 | "metadata": {}, 2440 | "output_type": "execute_result" 2441 | } 2442 | ], 2443 | "source": [ 2444 | "⌈ 3.4 ¯3.4 3 0" 2445 | ] 2446 | }, 2447 | { 2448 | "cell_type": "markdown", 2449 | "id": "0717d224", 2450 | "metadata": {}, 2451 | "source": [ 2452 | "#### dyadic `⌈` (Maximum)" 2453 | ] 2454 | }, 2455 | { 2456 | "cell_type": "markdown", 2457 | "id": "e97c8bc5-420c-44a4-850d-1f900c0f48e8", 2458 | "metadata": {}, 2459 | "source": [ 2460 | "Takes maximum of 2 values" 2461 | ] 2462 | }, 2463 | { 2464 | "cell_type": "code", 2465 | "execution_count": null, 2466 | "id": "785a5a38", 2467 | "metadata": {}, 2468 | "outputs": [ 2469 | { 2470 | "data": { 2471 | "text/html": [ 2472 | "
 \n",
2473 |        "3\n",
2474 |        " \n",
2475 |        "
" 2476 | ] 2477 | }, 2478 | "execution_count": null, 2479 | "metadata": {}, 2480 | "output_type": "execute_result" 2481 | } 2482 | ], 2483 | "source": [ 2484 | "3⌈2" 2485 | ] 2486 | }, 2487 | { 2488 | "cell_type": "code", 2489 | "execution_count": null, 2490 | "id": "7a410ee3", 2491 | "metadata": {}, 2492 | "outputs": [ 2493 | { 2494 | "data": { 2495 | "text/html": [ 2496 | "
┌→──┐\n",
2497 |        "│3 3│\n",
2498 |        "└~──┘\n",
2499 |        "
" 2500 | ] 2501 | }, 2502 | "execution_count": null, 2503 | "metadata": {}, 2504 | "output_type": "execute_result" 2505 | } 2506 | ], 2507 | "source": [ 2508 | "3 2⌈2 3" 2509 | ] 2510 | }, 2511 | { 2512 | "cell_type": "code", 2513 | "execution_count": null, 2514 | "id": "f9f78ce3", 2515 | "metadata": {}, 2516 | "outputs": [ 2517 | { 2518 | "data": { 2519 | "text/html": [ 2520 | "
 \n",
2521 |        "6\n",
2522 |        " \n",
2523 |        "
" 2524 | ] 2525 | }, 2526 | "execution_count": null, 2527 | "metadata": {}, 2528 | "output_type": "execute_result" 2529 | } 2530 | ], 2531 | "source": [ 2532 | "4 ⌈ 6 ⌈ 2" 2533 | ] 2534 | }, 2535 | { 2536 | "cell_type": "code", 2537 | "execution_count": null, 2538 | "id": "04ed6871", 2539 | "metadata": {}, 2540 | "outputs": [ 2541 | { 2542 | "data": { 2543 | "text/html": [ 2544 | "
┌→────┐\n",
2545 |        "│0 6 2│\n",
2546 |        "└~────┘\n",
2547 |        "
" 2548 | ] 2549 | }, 2550 | "execution_count": null, 2551 | "metadata": {}, 2552 | "output_type": "execute_result" 2553 | } 2554 | ], 2555 | "source": [ 2556 | "a ← ¯4 6 2\n", 2557 | "0 ⌈ a" 2558 | ] 2559 | }, 2560 | { 2561 | "cell_type": "markdown", 2562 | "id": "c9a8d1b5", 2563 | "metadata": {}, 2564 | "source": [ 2565 | "### `⌊` (Downstile)" 2566 | ] 2567 | }, 2568 | { 2569 | "cell_type": "markdown", 2570 | "id": "c054a3e9", 2571 | "metadata": {}, 2572 | "source": [ 2573 | "#### monadic `⌊` (Floor)" 2574 | ] 2575 | }, 2576 | { 2577 | "cell_type": "markdown", 2578 | "id": "8feeafed-2657-4651-b817-95a4e09075a6", 2579 | "metadata": {}, 2580 | "source": [ 2581 | "Rounds down to nearest whole number" 2582 | ] 2583 | }, 2584 | { 2585 | "cell_type": "code", 2586 | "execution_count": null, 2587 | "id": "aa41f28e", 2588 | "metadata": {}, 2589 | "outputs": [ 2590 | { 2591 | "data": { 2592 | "text/html": [ 2593 | "
┌→───────┐\n",
2594 |        "│3 ¯4 3 0│\n",
2595 |        "└~───────┘\n",
2596 |        "
" 2597 | ] 2598 | }, 2599 | "execution_count": null, 2600 | "metadata": {}, 2601 | "output_type": "execute_result" 2602 | } 2603 | ], 2604 | "source": [ 2605 | "⌊ 3.4 ¯3.4 3 0" 2606 | ] 2607 | }, 2608 | { 2609 | "cell_type": "markdown", 2610 | "id": "a40dd397", 2611 | "metadata": {}, 2612 | "source": [ 2613 | "#### dyadic `⌊` (Minimum)" 2614 | ] 2615 | }, 2616 | { 2617 | "cell_type": "markdown", 2618 | "id": "524a4b1b-3f65-4a2c-850a-37dd0deed965", 2619 | "metadata": {}, 2620 | "source": [ 2621 | "Takes minimum of 2 values" 2622 | ] 2623 | }, 2624 | { 2625 | "cell_type": "code", 2626 | "execution_count": null, 2627 | "id": "d9a0b9a6", 2628 | "metadata": {}, 2629 | "outputs": [ 2630 | { 2631 | "data": { 2632 | "text/html": [ 2633 | "
   \n",
2634 |        "2.5\n",
2635 |        "   \n",
2636 |        "
" 2637 | ] 2638 | }, 2639 | "execution_count": null, 2640 | "metadata": {}, 2641 | "output_type": "execute_result" 2642 | } 2643 | ], 2644 | "source": [ 2645 | "4 ⌊ 6 ⌊ 2.5" 2646 | ] 2647 | } 2648 | ], 2649 | "metadata": { 2650 | "kernelspec": { 2651 | "display_name": "Dyalog APL", 2652 | "language": "apl", 2653 | "name": "dyalog-kernel" 2654 | } 2655 | }, 2656 | "nbformat": 4, 2657 | "nbformat_minor": 5 2658 | } 2659 | -------------------------------------------------------------------------------- /05_the_rest.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "raw", 5 | "id": "2990f581", 6 | "metadata": {}, 7 | "source": [ 8 | "---\n", 9 | "title: \"The rest of the glyphs\"\n", 10 | "author: \"Jeremy Howard\"\n", 11 | "date: \"2022-07-05\"\n", 12 | "categories: [Dyalog, APL, Glyphs]\n", 13 | "---" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "id": "84e8fa35", 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "data": { 24 | "text/html": [ 25 | "
┌→─────────────────────────────────────┐\n",
  26 |        "│Was ON -style=max -trains=tree -fns=on│\n",
  27 |        "└──────────────────────────────────────┘\n",
  28 |        "
" 29 | ] 30 | }, 31 | "execution_count": null, 32 | "metadata": {}, 33 | "output_type": "execute_result" 34 | } 35 | ], 36 | "source": [ 37 | "]box on -style=max -trains=tree -fns=on" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "id": "da2674b7", 43 | "metadata": {}, 44 | "source": [ 45 | "## Sets and stuff" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "84f5b849", 51 | "metadata": {}, 52 | "source": [ 53 | "### `∊` (Epsilon)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "id": "1407b15c", 59 | "metadata": {}, 60 | "source": [ 61 | "#### monadic `∊` (Enlist)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "id": "90a3cbab", 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/html": [ 73 | "
┌→────┐\n",
  74 |        "↓1 2 3│\n",
  75 |        "│4 5 6│\n",
  76 |        "└~────┘\n",
  77 |        "
" 78 | ] 79 | }, 80 | "execution_count": null, 81 | "metadata": {}, 82 | "output_type": "execute_result" 83 | } 84 | ], 85 | "source": [ 86 | "⎕←mat←2 3⍴⍳6" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "id": "3c31775c", 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "data": { 97 | "text/html": [ 98 | "
┌→─────────────────────┐\n",
  99 |        "│0 1 2 3 4 5 6 7 8 nine│\n",
 100 |        "└+─────────────────────┘\n",
 101 |        "
" 102 | ] 103 | }, 104 | "execution_count": null, 105 | "metadata": {}, 106 | "output_type": "execute_result" 107 | } 108 | ], 109 | "source": [ 110 | "∊ 0 mat (7 8) 'nine'" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "id": "36fb24f6", 116 | "metadata": {}, 117 | "source": [ 118 | "#### dyadic `∊` (Member of)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "id": "8f66b6f4", 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "data": { 129 | "text/html": [ 130 | "
┌→──┐\n",
 131 |        "│0 1│\n",
 132 |        "└~──┘\n",
 133 |        "
" 134 | ] 135 | }, 136 | "execution_count": null, 137 | "metadata": {}, 138 | "output_type": "execute_result" 139 | } 140 | ], 141 | "source": [ 142 | "'abc' 4 ∊ 4 'ab' 'abcd'" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": null, 148 | "id": "42c03182", 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "data": { 153 | "text/html": [ 154 | "
┌→────┐\n",
 155 |        "↓0 1 0│\n",
 156 |        "│1 0 1│\n",
 157 |        "└~────┘\n",
 158 |        "
" 159 | ] 160 | }, 161 | "execution_count": null, 162 | "metadata": {}, 163 | "output_type": "execute_result" 164 | } 165 | ], 166 | "source": [ 167 | "mat←2 3⍴⍳6\n", 168 | "mat ∊ 6 2 7 4" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "id": "567c7021", 174 | "metadata": {}, 175 | "source": [ 176 | "### `⍷` (Epsilon Underbar)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "id": "05507611", 182 | "metadata": {}, 183 | "source": [ 184 | "#### dyadic `⍷` (Find)" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": null, 190 | "id": "60eeabd6", 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/html": [ 196 | "
┌→────────────┐\n",
 197 |        "│0 1 0 1 0 0 0│\n",
 198 |        "└~────────────┘\n",
 199 |        "
" 200 | ] 201 | }, 202 | "execution_count": null, 203 | "metadata": {}, 204 | "output_type": "execute_result" 205 | } 206 | ], 207 | "source": [ 208 | "1 ⍷ 3 1 4 1 5 9 2" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": null, 214 | "id": "4ad69e8d", 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "data": { 219 | "text/html": [ 220 | "
┌→────────────┐\n",
 221 |        "│0 1 0 0 0 0 0│\n",
 222 |        "└~────────────┘\n",
 223 |        "
" 224 | ] 225 | }, 226 | "execution_count": null, 227 | "metadata": {}, 228 | "output_type": "execute_result" 229 | } 230 | ], 231 | "source": [ 232 | "1 4 ⍷ 3 1 4 1 5 9 2" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": null, 238 | "id": "210249f5", 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "data": { 243 | "text/html": [ 244 | "
┌→──────────┐\n",
 245 |        "│0 1 0 1 0 0│\n",
 246 |        "└~──────────┘\n",
 247 |        "
" 248 | ] 249 | }, 250 | "execution_count": null, 251 | "metadata": {}, 252 | "output_type": "execute_result" 253 | } 254 | ], 255 | "source": [ 256 | "'ana' ⍷ 'Banana'" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": null, 262 | "id": "965336e9", 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "data": { 267 | "text/html": [ 268 | "
┌→────────────────┐\n",
 269 |        "│ ┌→──┐ ┌→──────┐ │\n",
 270 |        "│ ↓0 1│ ↓0 1 0 0│ │\n",
 271 |        "│ │1 0│ │1 0 0 1│ │\n",
 272 |        "│ └~──┘ │0 0 1 0│ │\n",
 273 |        "│       │0 1 0 0│ │\n",
 274 |        "│       └~──────┘ │\n",
 275 |        "└∊────────────────┘\n",
 276 |        "
" 277 | ] 278 | }, 279 | "execution_count": null, 280 | "metadata": {}, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "X ← 2 2 ⍴ 0 1 1 0\n", 286 | "Y ← 4 4 ⍴ 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0\n", 287 | "X Y" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": null, 293 | "id": "14467662", 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/html": [ 299 | "
┌→──────┐\n",
 300 |        "↓1 0 0 0│\n",
 301 |        "│0 0 1 0│\n",
 302 |        "│0 1 0 0│\n",
 303 |        "│0 0 0 0│\n",
 304 |        "└~──────┘\n",
 305 |        "
" 306 | ] 307 | }, 308 | "execution_count": null, 309 | "metadata": {}, 310 | "output_type": "execute_result" 311 | } 312 | ], 313 | "source": [ 314 | "X ⍷ Y" 315 | ] 316 | }, 317 | { 318 | "cell_type": "markdown", 319 | "id": "426ab86a", 320 | "metadata": {}, 321 | "source": [ 322 | "### `∩` (Up shoe)" 323 | ] 324 | }, 325 | { 326 | "cell_type": "markdown", 327 | "id": "01db0c25", 328 | "metadata": {}, 329 | "source": [ 330 | "#### dyadic `∩` (Intersection)" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": null, 336 | "id": "7e4acc70", 337 | "metadata": {}, 338 | "outputs": [ 339 | { 340 | "data": { 341 | "text/html": [ 342 | "
┌→──┐\n",
 343 |        "│ARA│\n",
 344 |        "└───┘\n",
 345 |        "
" 346 | ] 347 | }, 348 | "execution_count": null, 349 | "metadata": {}, 350 | "output_type": "execute_result" 351 | } 352 | ], 353 | "source": [ 354 | "'ABRA'∩'CAR'" 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "execution_count": null, 360 | "id": "dc6d81d2", 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "data": { 365 | "text/html": [ 366 | "
┌→────────┐\n",
 367 |        "│    ┌→─┐ │\n",
 368 |        "│ 22 │ab│ │\n",
 369 |        "│    └──┘ │\n",
 370 |        "└∊────────┘\n",
 371 |        "
" 372 | ] 373 | }, 374 | "execution_count": null, 375 | "metadata": {}, 376 | "output_type": "execute_result" 377 | } 378 | ], 379 | "source": [ 380 | "22 'ab' 'fg' ∩ 'a' 'ab' 22" 381 | ] 382 | }, 383 | { 384 | "cell_type": "markdown", 385 | "id": "fb7757a4", 386 | "metadata": {}, 387 | "source": [ 388 | "### `∪` (Down shoe)" 389 | ] 390 | }, 391 | { 392 | "cell_type": "markdown", 393 | "id": "b5515721", 394 | "metadata": {}, 395 | "source": [ 396 | "#### monadic `∪` (Unique)" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": null, 402 | "id": "b87f55b6", 403 | "metadata": {}, 404 | "outputs": [], 405 | "source": [ 406 | "a ← 2 3 4 2 3 4 5" 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": null, 412 | "id": "c4d34ad5", 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "data": { 417 | "text/html": [ 418 | "
┌→──────┐\n",
 419 |        "│2 3 4 5│\n",
 420 |        "└~──────┘\n",
 421 |        "
" 422 | ] 423 | }, 424 | "execution_count": null, 425 | "metadata": {}, 426 | "output_type": "execute_result" 427 | } 428 | ], 429 | "source": [ 430 | "∪a" 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": null, 436 | "id": "8e0bc0e8", 437 | "metadata": {}, 438 | "outputs": [ 439 | { 440 | "data": { 441 | "text/html": [ 442 | "
┌→──────┐\n",
 443 |        "│2 3 4 5│\n",
 444 |        "└~──────┘\n",
 445 |        "
" 446 | ] 447 | }, 448 | "execution_count": null, 449 | "metadata": {}, 450 | "output_type": "execute_result" 451 | } 452 | ], 453 | "source": [ 454 | "(≠a)/a " 455 | ] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": null, 460 | "id": "dfbbec06", 461 | "metadata": {}, 462 | "outputs": [ 463 | { 464 | "data": { 465 | "text/html": [ 466 | "
┌→──────────────┐\n",
 467 |        "│ ┌→─┐ ┌→─┐     │\n",
 468 |        "│ │ab│ │ba│ 1 2 │\n",
 469 |        "│ └──┘ └──┘     │\n",
 470 |        "└∊──────────────┘\n",
 471 |        "
" 472 | ] 473 | }, 474 | "execution_count": null, 475 | "metadata": {}, 476 | "output_type": "execute_result" 477 | } 478 | ], 479 | "source": [ 480 | "∪ 'ab' 'ba' 'ab' 1 1 2" 481 | ] 482 | }, 483 | { 484 | "cell_type": "markdown", 485 | "id": "5e5b8871", 486 | "metadata": {}, 487 | "source": [ 488 | "#### dyadic `∪` (Union)" 489 | ] 490 | }, 491 | { 492 | "cell_type": "code", 493 | "execution_count": null, 494 | "id": "7fcc51fa", 495 | "metadata": {}, 496 | "outputs": [ 497 | { 498 | "data": { 499 | "text/html": [ 500 | "
┌→────┐\n",
 501 |        "│ABRAC│\n",
 502 |        "└─────┘\n",
 503 |        "
" 504 | ] 505 | }, 506 | "execution_count": null, 507 | "metadata": {}, 508 | "output_type": "execute_result" 509 | } 510 | ], 511 | "source": [ 512 | "'ABRA'∪'CAR'" 513 | ] 514 | }, 515 | { 516 | "cell_type": "code", 517 | "execution_count": null, 518 | "id": "1d1e7955", 519 | "metadata": {}, 520 | "outputs": [ 521 | { 522 | "data": { 523 | "text/html": [ 524 | "
┌→───────────────┐\n",
 525 |        "│    ┌→─┐ ┌→─┐   │\n",
 526 |        "│ 22 │ab│ │fg│ a │\n",
 527 |        "│    └──┘ └──┘ - │\n",
 528 |        "└∊───────────────┘\n",
 529 |        "
" 530 | ] 531 | }, 532 | "execution_count": null, 533 | "metadata": {}, 534 | "output_type": "execute_result" 535 | } 536 | ], 537 | "source": [ 538 | "22 'ab' 'fg' ∪ 'a' 'ab' 22" 539 | ] 540 | }, 541 | { 542 | "cell_type": "markdown", 543 | "id": "f8056248", 544 | "metadata": {}, 545 | "source": [ 546 | "## Sort / index" 547 | ] 548 | }, 549 | { 550 | "cell_type": "markdown", 551 | "id": "77e272c6", 552 | "metadata": {}, 553 | "source": [ 554 | "### `⌷` (Squad)" 555 | ] 556 | }, 557 | { 558 | "cell_type": "markdown", 559 | "id": "0c816033", 560 | "metadata": {}, 561 | "source": [ 562 | "#### monadic `⌷` (Materialise)" 563 | ] 564 | }, 565 | { 566 | "cell_type": "markdown", 567 | "id": "5ba60006", 568 | "metadata": {}, 569 | "source": [ 570 | "For `⌷ ⍵`: If ⍵ is an array, returns ⍵. For a class/COM/.Net object, it materialises the items." 571 | ] 572 | }, 573 | { 574 | "cell_type": "markdown", 575 | "id": "d8e72637", 576 | "metadata": {}, 577 | "source": [ 578 | "#### dyadic `⌷` (Index)" 579 | ] 580 | }, 581 | { 582 | "cell_type": "code", 583 | "execution_count": null, 584 | "id": "72801c8e", 585 | "metadata": {}, 586 | "outputs": [ 587 | { 588 | "data": { 589 | "text/html": [ 590 | "
 \n",
 591 |        "6\n",
 592 |        " \n",
 593 |        "
" 594 | ] 595 | }, 596 | "execution_count": null, 597 | "metadata": {}, 598 | "output_type": "execute_result" 599 | } 600 | ], 601 | "source": [ 602 | "v ← 2×⍳12\n", 603 | "3⌷v" 604 | ] 605 | }, 606 | { 607 | "cell_type": "code", 608 | "execution_count": null, 609 | "id": "b9a792d4", 610 | "metadata": {}, 611 | "outputs": [ 612 | { 613 | "data": { 614 | "text/html": [ 615 | "
┌→───┐\n",
 616 |        "│6 10│\n",
 617 |        "└~───┘\n",
 618 |        "
" 619 | ] 620 | }, 621 | "execution_count": null, 622 | "metadata": {}, 623 | "output_type": "execute_result" 624 | } 625 | ], 626 | "source": [ 627 | "(⊂3 5) ⌷v" 628 | ] 629 | }, 630 | { 631 | "cell_type": "code", 632 | "execution_count": null, 633 | "id": "1268fe10", 634 | "metadata": {}, 635 | "outputs": [ 636 | { 637 | "data": { 638 | "text/html": [ 639 | "
┌→─────────┐\n",
 640 |        "↓1  2  3  4│\n",
 641 |        "│5  6  7  8│\n",
 642 |        "│9 10 11 12│\n",
 643 |        "└~─────────┘\n",
 644 |        "
" 645 | ] 646 | }, 647 | "execution_count": null, 648 | "metadata": {}, 649 | "output_type": "execute_result" 650 | } 651 | ], 652 | "source": [ 653 | "⎕ ← mat ← 3 4 ⍴⍳12" 654 | ] 655 | }, 656 | { 657 | "cell_type": "code", 658 | "execution_count": null, 659 | "id": "137a5f5f", 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "data": { 664 | "text/html": [ 665 | "
 \n",
 666 |        "7\n",
 667 |        " \n",
 668 |        "
" 669 | ] 670 | }, 671 | "execution_count": null, 672 | "metadata": {}, 673 | "output_type": "execute_result" 674 | } 675 | ], 676 | "source": [ 677 | "2 3 ⌷ mat" 678 | ] 679 | }, 680 | { 681 | "cell_type": "markdown", 682 | "id": "3b2eaa84", 683 | "metadata": {}, 684 | "source": [ 685 | "### `⍒` (Grade Down)" 686 | ] 687 | }, 688 | { 689 | "cell_type": "markdown", 690 | "id": "09ab35bf", 691 | "metadata": {}, 692 | "source": [ 693 | "#### monadic `⍒` (Grade Down)" 694 | ] 695 | }, 696 | { 697 | "cell_type": "code", 698 | "execution_count": null, 699 | "id": "2e77203d", 700 | "metadata": {}, 701 | "outputs": [ 702 | { 703 | "data": { 704 | "text/html": [ 705 | "
┌→────────┐\n",
 706 |        "│4 3 1 5 2│\n",
 707 |        "└~────────┘\n",
 708 |        "
" 709 | ] 710 | }, 711 | "execution_count": null, 712 | "metadata": {}, 713 | "output_type": "execute_result" 714 | } 715 | ], 716 | "source": [ 717 | "⍒ 33 11 44 66 22" 718 | ] 719 | }, 720 | { 721 | "cell_type": "code", 722 | "execution_count": null, 723 | "id": "6df7fa75", 724 | "metadata": {}, 725 | "outputs": [], 726 | "source": [ 727 | "a ← 33 11 44 66 22" 728 | ] 729 | }, 730 | { 731 | "cell_type": "code", 732 | "execution_count": null, 733 | "id": "6ca39670", 734 | "metadata": {}, 735 | "outputs": [ 736 | { 737 | "data": { 738 | "text/html": [ 739 | "
┌→─────────────┐\n",
 740 |        "│66 44 33 22 11│\n",
 741 |        "└~─────────────┘\n",
 742 |        "
" 743 | ] 744 | }, 745 | "execution_count": null, 746 | "metadata": {}, 747 | "output_type": "execute_result" 748 | } 749 | ], 750 | "source": [ 751 | "a[⍒a]" 752 | ] 753 | }, 754 | { 755 | "cell_type": "code", 756 | "execution_count": null, 757 | "id": "c3dd94c3", 758 | "metadata": {}, 759 | "outputs": [ 760 | { 761 | "data": { 762 | "text/html": [ 763 | "
┌→─────────────┐\n",
 764 |        "│66 44 33 22 11│\n",
 765 |        "└~─────────────┘\n",
 766 |        "
" 767 | ] 768 | }, 769 | "execution_count": null, 770 | "metadata": {}, 771 | "output_type": "execute_result" 772 | } 773 | ], 774 | "source": [ 775 | "a⌷⍨⊂⍒a" 776 | ] 777 | }, 778 | { 779 | "cell_type": "markdown", 780 | "id": "0bec4127", 781 | "metadata": {}, 782 | "source": [ 783 | "`{⍵[⍋⍵]}` and `{(⊂⍋⍵)⌷⍵}` are sort idioms (special cased for performance)" 784 | ] 785 | }, 786 | { 787 | "cell_type": "code", 788 | "execution_count": null, 789 | "id": "ff298201", 790 | "metadata": {}, 791 | "outputs": [], 792 | "source": [ 793 | "sort ← ⌷⍨∘⊂∘⍒⍨" 794 | ] 795 | }, 796 | { 797 | "cell_type": "code", 798 | "execution_count": null, 799 | "id": "710685d5", 800 | "metadata": {}, 801 | "outputs": [ 802 | { 803 | "data": { 804 | "text/html": [ 805 | "
┌→─────────────┐\n",
 806 |        "│66 44 33 22 11│\n",
 807 |        "└~─────────────┘\n",
 808 |        "
" 809 | ] 810 | }, 811 | "execution_count": null, 812 | "metadata": {}, 813 | "output_type": "execute_result" 814 | } 815 | ], 816 | "source": [ 817 | "sort a" 818 | ] 819 | }, 820 | { 821 | "cell_type": "code", 822 | "execution_count": null, 823 | "id": "dafc738a", 824 | "metadata": {}, 825 | "outputs": [], 826 | "source": [ 827 | "tsort ← (⊂∘⍒)⌷⊢ ⍝ h/t Rory Kemp" 828 | ] 829 | }, 830 | { 831 | "cell_type": "code", 832 | "execution_count": null, 833 | "id": "92af3196", 834 | "metadata": {}, 835 | "outputs": [ 836 | { 837 | "data": { 838 | "text/html": [ 839 | "
┌→─────────────┐\n",
 840 |        "│66 44 33 22 11│\n",
 841 |        "└~─────────────┘\n",
 842 |        "
" 843 | ] 844 | }, 845 | "execution_count": null, 846 | "metadata": {}, 847 | "output_type": "execute_result" 848 | } 849 | ], 850 | "source": [ 851 | "tsort a" 852 | ] 853 | }, 854 | { 855 | "cell_type": "markdown", 856 | "id": "815f2ca9", 857 | "metadata": {}, 858 | "source": [ 859 | "#### dyadic `⍒` (Dyadic Grade Down)" 860 | ] 861 | }, 862 | { 863 | "cell_type": "code", 864 | "execution_count": null, 865 | "id": "834b4267", 866 | "metadata": {}, 867 | "outputs": [], 868 | "source": [ 869 | "a ← 'abcdefgabcdefg'" 870 | ] 871 | }, 872 | { 873 | "cell_type": "code", 874 | "execution_count": null, 875 | "id": "ed3d0a25", 876 | "metadata": {}, 877 | "outputs": [], 878 | "source": [ 879 | "b ← 'cgf' ⍒ a" 880 | ] 881 | }, 882 | { 883 | "cell_type": "code", 884 | "execution_count": null, 885 | "id": "16954655", 886 | "metadata": {}, 887 | "outputs": [ 888 | { 889 | "data": { 890 | "text/html": [ 891 | "
┌→─────────────┐\n",
 892 |        "│abdeabdeffggcc│\n",
 893 |        "└──────────────┘\n",
 894 |        "
" 895 | ] 896 | }, 897 | "execution_count": null, 898 | "metadata": {}, 899 | "output_type": "execute_result" 900 | } 901 | ], 902 | "source": [ 903 | "a⌷⍨⊂b" 904 | ] 905 | }, 906 | { 907 | "cell_type": "markdown", 908 | "id": "6462e384", 909 | "metadata": {}, 910 | "source": [ 911 | "### `⍋` (Grade Up)" 912 | ] 913 | }, 914 | { 915 | "cell_type": "markdown", 916 | "id": "325836fc", 917 | "metadata": {}, 918 | "source": [ 919 | "#### monadic `⍋` (Grade Up)" 920 | ] 921 | }, 922 | { 923 | "cell_type": "code", 924 | "execution_count": null, 925 | "id": "4659cd30", 926 | "metadata": {}, 927 | "outputs": [ 928 | { 929 | "data": { 930 | "text/html": [ 931 | "
┌→────────┐\n",
 932 |        "│2 5 1 3 4│\n",
 933 |        "└~────────┘\n",
 934 |        "
" 935 | ] 936 | }, 937 | "execution_count": null, 938 | "metadata": {}, 939 | "output_type": "execute_result" 940 | } 941 | ], 942 | "source": [ 943 | "⍋ 33 11 44 66 22" 944 | ] 945 | }, 946 | { 947 | "cell_type": "code", 948 | "execution_count": null, 949 | "id": "6e85eeeb", 950 | "metadata": {}, 951 | "outputs": [], 952 | "source": [ 953 | "a ← 33 11 44 66 22" 954 | ] 955 | }, 956 | { 957 | "cell_type": "code", 958 | "execution_count": null, 959 | "id": "670053ed", 960 | "metadata": {}, 961 | "outputs": [ 962 | { 963 | "data": { 964 | "text/html": [ 965 | "
┌→─────────────┐\n",
 966 |        "│11 22 33 44 66│\n",
 967 |        "└~─────────────┘\n",
 968 |        "
" 969 | ] 970 | }, 971 | "execution_count": null, 972 | "metadata": {}, 973 | "output_type": "execute_result" 974 | } 975 | ], 976 | "source": [ 977 | "a[⍋a]" 978 | ] 979 | }, 980 | { 981 | "cell_type": "code", 982 | "execution_count": null, 983 | "id": "8b0eb4bd", 984 | "metadata": {}, 985 | "outputs": [ 986 | { 987 | "data": { 988 | "text/html": [ 989 | "
┌→─────────────┐\n",
 990 |        "│11 22 33 44 66│\n",
 991 |        "└~─────────────┘\n",
 992 |        "
" 993 | ] 994 | }, 995 | "execution_count": null, 996 | "metadata": {}, 997 | "output_type": "execute_result" 998 | } 999 | ], 1000 | "source": [ 1001 | "a⌷⍨⊂⍋a" 1002 | ] 1003 | }, 1004 | { 1005 | "cell_type": "markdown", 1006 | "id": "a717b1f2", 1007 | "metadata": {}, 1008 | "source": [ 1009 | "#### dyadic `⍒` (Dyadic Grade Down)" 1010 | ] 1011 | }, 1012 | { 1013 | "cell_type": "code", 1014 | "execution_count": null, 1015 | "id": "90ad8673", 1016 | "metadata": {}, 1017 | "outputs": [ 1018 | { 1019 | "data": { 1020 | "text/html": [ 1021 | "
┌→─────────────┐\n",
1022 |        "│ccggffabdeabde│\n",
1023 |        "└──────────────┘\n",
1024 |        "
" 1025 | ] 1026 | }, 1027 | "execution_count": null, 1028 | "metadata": {}, 1029 | "output_type": "execute_result" 1030 | } 1031 | ], 1032 | "source": [ 1033 | "a ← 'abcdefgabcdefg'\n", 1034 | "b ← 'cgf' ⍋ a\n", 1035 | "a⌷⍨⊂b" 1036 | ] 1037 | }, 1038 | { 1039 | "cell_type": "markdown", 1040 | "id": "484bc54f", 1041 | "metadata": {}, 1042 | "source": [ 1043 | "## Rotate / transpose / flip" 1044 | ] 1045 | }, 1046 | { 1047 | "cell_type": "markdown", 1048 | "id": "39dcdf7b", 1049 | "metadata": {}, 1050 | "source": [ 1051 | "### `⌽` (Circle Stile)" 1052 | ] 1053 | }, 1054 | { 1055 | "cell_type": "markdown", 1056 | "id": "9799fd42", 1057 | "metadata": {}, 1058 | "source": [ 1059 | "#### monadic `⌽` (Reverse)" 1060 | ] 1061 | }, 1062 | { 1063 | "cell_type": "code", 1064 | "execution_count": null, 1065 | "id": "d8cf03d6", 1066 | "metadata": {}, 1067 | "outputs": [ 1068 | { 1069 | "data": { 1070 | "text/html": [ 1071 | "
┌→────┐\n",
1072 |        "│smart│\n",
1073 |        "└─────┘\n",
1074 |        "
" 1075 | ] 1076 | }, 1077 | "execution_count": null, 1078 | "metadata": {}, 1079 | "output_type": "execute_result" 1080 | } 1081 | ], 1082 | "source": [ 1083 | "⌽ 'trams'" 1084 | ] 1085 | }, 1086 | { 1087 | "cell_type": "code", 1088 | "execution_count": null, 1089 | "id": "c3007ccf", 1090 | "metadata": {}, 1091 | "outputs": [ 1092 | { 1093 | "data": { 1094 | "text/html": [ 1095 | "
┌→─────────┐\n",
1096 |        "↓1  2  3  4│\n",
1097 |        "│5  6  7  8│\n",
1098 |        "│9 10 11 12│\n",
1099 |        "└~─────────┘\n",
1100 |        "
" 1101 | ] 1102 | }, 1103 | "execution_count": null, 1104 | "metadata": {}, 1105 | "output_type": "execute_result" 1106 | } 1107 | ], 1108 | "source": [ 1109 | "⎕ ← mat ← 3 4 ⍴⍳12" 1110 | ] 1111 | }, 1112 | { 1113 | "cell_type": "code", 1114 | "execution_count": null, 1115 | "id": "076ec08c", 1116 | "metadata": {}, 1117 | "outputs": [ 1118 | { 1119 | "data": { 1120 | "text/html": [ 1121 | "
┌→─────────┐\n",
1122 |        "↓ 4  3  2 1│\n",
1123 |        "│ 8  7  6 5│\n",
1124 |        "│12 11 10 9│\n",
1125 |        "└~─────────┘\n",
1126 |        "
" 1127 | ] 1128 | }, 1129 | "execution_count": null, 1130 | "metadata": {}, 1131 | "output_type": "execute_result" 1132 | } 1133 | ], 1134 | "source": [ 1135 | "⌽ mat" 1136 | ] 1137 | }, 1138 | { 1139 | "cell_type": "markdown", 1140 | "id": "8912e595", 1141 | "metadata": {}, 1142 | "source": [ 1143 | "#### dyadic `⌽` (Rotate)" 1144 | ] 1145 | }, 1146 | { 1147 | "cell_type": "code", 1148 | "execution_count": null, 1149 | "id": "d10daf7d", 1150 | "metadata": {}, 1151 | "outputs": [ 1152 | { 1153 | "data": { 1154 | "text/html": [ 1155 | "
┌→───────┐\n",
1156 |        "│atStandH│\n",
1157 |        "└────────┘\n",
1158 |        "
" 1159 | ] 1160 | }, 1161 | "execution_count": null, 1162 | "metadata": {}, 1163 | "output_type": "execute_result" 1164 | } 1165 | ], 1166 | "source": [ 1167 | "1 ⌽ 'HatStand'" 1168 | ] 1169 | }, 1170 | { 1171 | "cell_type": "code", 1172 | "execution_count": null, 1173 | "id": "3c9acd25", 1174 | "metadata": {}, 1175 | "outputs": [ 1176 | { 1177 | "data": { 1178 | "text/html": [ 1179 | "
┌→───────┐\n",
1180 |        "│StandHat│\n",
1181 |        "└────────┘\n",
1182 |        "
" 1183 | ] 1184 | }, 1185 | "execution_count": null, 1186 | "metadata": {}, 1187 | "output_type": "execute_result" 1188 | } 1189 | ], 1190 | "source": [ 1191 | "3 ⌽ 'HatStand'" 1192 | ] 1193 | }, 1194 | { 1195 | "cell_type": "code", 1196 | "execution_count": null, 1197 | "id": "5fbabe11", 1198 | "metadata": {}, 1199 | "outputs": [ 1200 | { 1201 | "data": { 1202 | "text/html": [ 1203 | "
┌→──────────┐\n",
1204 |        "│5 6 1 2 3 4│\n",
1205 |        "└~──────────┘\n",
1206 |        "
" 1207 | ] 1208 | }, 1209 | "execution_count": null, 1210 | "metadata": {}, 1211 | "output_type": "execute_result" 1212 | } 1213 | ], 1214 | "source": [ 1215 | "¯2 ⌽ 1 2 3 4 5 6" 1216 | ] 1217 | }, 1218 | { 1219 | "cell_type": "code", 1220 | "execution_count": null, 1221 | "id": "4a5246f2", 1222 | "metadata": {}, 1223 | "outputs": [ 1224 | { 1225 | "data": { 1226 | "text/html": [ 1227 | "
┌→─────────┐\n",
1228 |        "↓1  2  3  4│\n",
1229 |        "│5  6  7  8│\n",
1230 |        "│9 10 11 12│\n",
1231 |        "└~─────────┘\n",
1232 |        "
" 1233 | ] 1234 | }, 1235 | "execution_count": null, 1236 | "metadata": {}, 1237 | "output_type": "execute_result" 1238 | } 1239 | ], 1240 | "source": [ 1241 | "⎕ ← mat ← 3 4 ⍴⍳12" 1242 | ] 1243 | }, 1244 | { 1245 | "cell_type": "code", 1246 | "execution_count": null, 1247 | "id": "ec0be1f9", 1248 | "metadata": {}, 1249 | "outputs": [ 1250 | { 1251 | "data": { 1252 | "text/html": [ 1253 | "
┌→─────────┐\n",
1254 |        "↓ 4 1  2  3│\n",
1255 |        "│ 8 5  6  7│\n",
1256 |        "│12 9 10 11│\n",
1257 |        "└~─────────┘\n",
1258 |        "
" 1259 | ] 1260 | }, 1261 | "execution_count": null, 1262 | "metadata": {}, 1263 | "output_type": "execute_result" 1264 | } 1265 | ], 1266 | "source": [ 1267 | "¯1 ⌽ mat" 1268 | ] 1269 | }, 1270 | { 1271 | "cell_type": "code", 1272 | "execution_count": null, 1273 | "id": "86a51ea9", 1274 | "metadata": {}, 1275 | "outputs": [ 1276 | { 1277 | "data": { 1278 | "text/html": [ 1279 | "
┌→─────────┐\n",
1280 |        "↓ 2  3 4  1│\n",
1281 |        "│ 8  5 6  7│\n",
1282 |        "│11 12 9 10│\n",
1283 |        "└~─────────┘\n",
1284 |        "
" 1285 | ] 1286 | }, 1287 | "execution_count": null, 1288 | "metadata": {}, 1289 | "output_type": "execute_result" 1290 | } 1291 | ], 1292 | "source": [ 1293 | "1 ¯1 2 ⌽ mat" 1294 | ] 1295 | }, 1296 | { 1297 | "cell_type": "markdown", 1298 | "id": "7b284ee6", 1299 | "metadata": {}, 1300 | "source": [ 1301 | "### `⊖` (Circle Bar)" 1302 | ] 1303 | }, 1304 | { 1305 | "cell_type": "markdown", 1306 | "id": "45a8f3e7", 1307 | "metadata": {}, 1308 | "source": [ 1309 | "#### monadic `⊖` (Reverse First)" 1310 | ] 1311 | }, 1312 | { 1313 | "cell_type": "code", 1314 | "execution_count": null, 1315 | "id": "606bbe70", 1316 | "metadata": {}, 1317 | "outputs": [ 1318 | { 1319 | "data": { 1320 | "text/html": [ 1321 | "
┌→────┐\n",
1322 |        "│smart│\n",
1323 |        "└─────┘\n",
1324 |        "
" 1325 | ] 1326 | }, 1327 | "execution_count": null, 1328 | "metadata": {}, 1329 | "output_type": "execute_result" 1330 | } 1331 | ], 1332 | "source": [ 1333 | "⊖ 'trams'" 1334 | ] 1335 | }, 1336 | { 1337 | "cell_type": "code", 1338 | "execution_count": null, 1339 | "id": "68ab5beb", 1340 | "metadata": {}, 1341 | "outputs": [ 1342 | { 1343 | "data": { 1344 | "text/html": [ 1345 | "
┌→─────────┐\n",
1346 |        "↓9 10 11 12│\n",
1347 |        "│5  6  7  8│\n",
1348 |        "│1  2  3  4│\n",
1349 |        "└~─────────┘\n",
1350 |        "
" 1351 | ] 1352 | }, 1353 | "execution_count": null, 1354 | "metadata": {}, 1355 | "output_type": "execute_result" 1356 | } 1357 | ], 1358 | "source": [ 1359 | "mat ← 3 4 ⍴⍳12\n", 1360 | "⊖ mat" 1361 | ] 1362 | }, 1363 | { 1364 | "cell_type": "markdown", 1365 | "id": "ae5a17ec", 1366 | "metadata": {}, 1367 | "source": [ 1368 | "#### dyadic `⊖` (Rotate First)" 1369 | ] 1370 | }, 1371 | { 1372 | "cell_type": "code", 1373 | "execution_count": null, 1374 | "id": "cd078b60", 1375 | "metadata": {}, 1376 | "outputs": [ 1377 | { 1378 | "data": { 1379 | "text/html": [ 1380 | "
┌→───────┐\n",
1381 |        "│StandHat│\n",
1382 |        "└────────┘\n",
1383 |        "
" 1384 | ] 1385 | }, 1386 | "execution_count": null, 1387 | "metadata": {}, 1388 | "output_type": "execute_result" 1389 | } 1390 | ], 1391 | "source": [ 1392 | "3 ⊖ 'HatStand'" 1393 | ] 1394 | }, 1395 | { 1396 | "cell_type": "code", 1397 | "execution_count": null, 1398 | "id": "cdf5770c", 1399 | "metadata": {}, 1400 | "outputs": [ 1401 | { 1402 | "data": { 1403 | "text/html": [ 1404 | "
┌→─────────┐\n",
1405 |        "↓9 10 11 12│\n",
1406 |        "│1  2  3  4│\n",
1407 |        "│5  6  7  8│\n",
1408 |        "└~─────────┘\n",
1409 |        "
" 1410 | ] 1411 | }, 1412 | "execution_count": null, 1413 | "metadata": {}, 1414 | "output_type": "execute_result" 1415 | } 1416 | ], 1417 | "source": [ 1418 | "mat ← 3 4 ⍴⍳12\n", 1419 | "¯1 ⊖ mat" 1420 | ] 1421 | }, 1422 | { 1423 | "cell_type": "markdown", 1424 | "id": "db239b56", 1425 | "metadata": {}, 1426 | "source": [ 1427 | "### `⍉` (Circle Bar)" 1428 | ] 1429 | }, 1430 | { 1431 | "cell_type": "markdown", 1432 | "id": "307d55a9", 1433 | "metadata": {}, 1434 | "source": [ 1435 | "#### monadic `⍉` (Transpose)" 1436 | ] 1437 | }, 1438 | { 1439 | "cell_type": "code", 1440 | "execution_count": null, 1441 | "id": "a8e58b17", 1442 | "metadata": {}, 1443 | "outputs": [ 1444 | { 1445 | "data": { 1446 | "text/html": [ 1447 | "
┌→─────┐\n",
1448 |        "↓1 5  9│\n",
1449 |        "│2 6 10│\n",
1450 |        "│3 7 11│\n",
1451 |        "│4 8 12│\n",
1452 |        "└~─────┘\n",
1453 |        "
" 1454 | ] 1455 | }, 1456 | "execution_count": null, 1457 | "metadata": {}, 1458 | "output_type": "execute_result" 1459 | } 1460 | ], 1461 | "source": [ 1462 | "mat ← 3 4 ⍴⍳12\n", 1463 | "⍉ mat" 1464 | ] 1465 | }, 1466 | { 1467 | "cell_type": "code", 1468 | "execution_count": null, 1469 | "id": "edde848f", 1470 | "metadata": {}, 1471 | "outputs": [ 1472 | { 1473 | "data": { 1474 | "text/html": [ 1475 | "
┌┌→──────────┐\n",
1476 |        "↓↓ 1  2  3  4│\n",
1477 |        "││ 5  6  7  8│\n",
1478 |        "││ 9 10 11 12│\n",
1479 |        "││           │\n",
1480 |        "││13 14 15 16│\n",
1481 |        "││17 18 19 20│\n",
1482 |        "││21 22 23 24│\n",
1483 |        "└└~──────────┘\n",
1484 |        "
" 1485 | ] 1486 | }, 1487 | "execution_count": null, 1488 | "metadata": {}, 1489 | "output_type": "execute_result" 1490 | } 1491 | ], 1492 | "source": [ 1493 | "⎕←cube ← 2 3 4 ⍴⍳24" 1494 | ] 1495 | }, 1496 | { 1497 | "cell_type": "code", 1498 | "execution_count": null, 1499 | "id": "c46169dd", 1500 | "metadata": {}, 1501 | "outputs": [ 1502 | { 1503 | "data": { 1504 | "text/html": [ 1505 | "
┌┌→────┐\n",
1506 |        "↓↓ 1 13│\n",
1507 |        "││ 5 17│\n",
1508 |        "││ 9 21│\n",
1509 |        "││     │\n",
1510 |        "││ 2 14│\n",
1511 |        "││ 6 18│\n",
1512 |        "││10 22│\n",
1513 |        "││     │\n",
1514 |        "││ 3 15│\n",
1515 |        "││ 7 19│\n",
1516 |        "││11 23│\n",
1517 |        "││     │\n",
1518 |        "││ 4 16│\n",
1519 |        "││ 8 20│\n",
1520 |        "││12 24│\n",
1521 |        "└└~────┘\n",
1522 |        "
" 1523 | ] 1524 | }, 1525 | "execution_count": null, 1526 | "metadata": {}, 1527 | "output_type": "execute_result" 1528 | } 1529 | ], 1530 | "source": [ 1531 | "⍉ cube" 1532 | ] 1533 | }, 1534 | { 1535 | "cell_type": "code", 1536 | "execution_count": null, 1537 | "id": "440ad418", 1538 | "metadata": {}, 1539 | "outputs": [ 1540 | { 1541 | "data": { 1542 | "text/html": [ 1543 | "
┌→────┐\n",
1544 |        "│4 3 2│\n",
1545 |        "└~────┘\n",
1546 |        "
" 1547 | ] 1548 | }, 1549 | "execution_count": null, 1550 | "metadata": {}, 1551 | "output_type": "execute_result" 1552 | } 1553 | ], 1554 | "source": [ 1555 | "⍴⍉ cube" 1556 | ] 1557 | }, 1558 | { 1559 | "cell_type": "markdown", 1560 | "id": "000eaa59", 1561 | "metadata": {}, 1562 | "source": [ 1563 | "#### dyadic `⊖` (Rotate First)" 1564 | ] 1565 | }, 1566 | { 1567 | "cell_type": "code", 1568 | "execution_count": null, 1569 | "id": "30e4a317", 1570 | "metadata": {}, 1571 | "outputs": [ 1572 | { 1573 | "data": { 1574 | "text/html": [ 1575 | "
┌→─────┐\n",
1576 |        "↓1 5  9│\n",
1577 |        "│2 6 10│\n",
1578 |        "│3 7 11│\n",
1579 |        "│4 8 12│\n",
1580 |        "└~─────┘\n",
1581 |        "
" 1582 | ] 1583 | }, 1584 | "execution_count": null, 1585 | "metadata": {}, 1586 | "output_type": "execute_result" 1587 | } 1588 | ], 1589 | "source": [ 1590 | "mat ← 3 4 ⍴⍳12\n", 1591 | "2 1 ⍉ mat" 1592 | ] 1593 | }, 1594 | { 1595 | "cell_type": "code", 1596 | "execution_count": null, 1597 | "id": "9dc16c94", 1598 | "metadata": {}, 1599 | "outputs": [ 1600 | { 1601 | "data": { 1602 | "text/html": [ 1603 | "
┌→─────┐\n",
1604 |        "│1 6 11│\n",
1605 |        "└~─────┘\n",
1606 |        "
" 1607 | ] 1608 | }, 1609 | "execution_count": null, 1610 | "metadata": {}, 1611 | "output_type": "execute_result" 1612 | } 1613 | ], 1614 | "source": [ 1615 | "1 1 ⍉ mat " 1616 | ] 1617 | }, 1618 | { 1619 | "cell_type": "code", 1620 | "execution_count": null, 1621 | "id": "b8f77a8e", 1622 | "metadata": {}, 1623 | "outputs": [ 1624 | { 1625 | "data": { 1626 | "text/html": [ 1627 | "
┌┌→──────────┐\n",
1628 |        "↓↓ 1  2  3  4│\n",
1629 |        "││ 5  6  7  8│\n",
1630 |        "││ 9 10 11 12│\n",
1631 |        "││           │\n",
1632 |        "││13 14 15 16│\n",
1633 |        "││17 18 19 20│\n",
1634 |        "││21 22 23 24│\n",
1635 |        "└└~──────────┘\n",
1636 |        "
" 1637 | ] 1638 | }, 1639 | "execution_count": null, 1640 | "metadata": {}, 1641 | "output_type": "execute_result" 1642 | } 1643 | ], 1644 | "source": [ 1645 | "⎕ ← cube ← 2 3 4 ⍴⍳24" 1646 | ] 1647 | }, 1648 | { 1649 | "cell_type": "code", 1650 | "execution_count": null, 1651 | "id": "9035bd1e", 1652 | "metadata": {}, 1653 | "outputs": [ 1654 | { 1655 | "data": { 1656 | "text/html": [ 1657 | "
┌→────┐\n",
1658 |        "│3 2 4│\n",
1659 |        "└~────┘\n",
1660 |        "
" 1661 | ] 1662 | }, 1663 | "execution_count": null, 1664 | "metadata": {}, 1665 | "output_type": "execute_result" 1666 | } 1667 | ], 1668 | "source": [ 1669 | "⍴ 2 1 3 ⍉ cube" 1670 | ] 1671 | }, 1672 | { 1673 | "cell_type": "code", 1674 | "execution_count": null, 1675 | "id": "80684b4c", 1676 | "metadata": {}, 1677 | "outputs": [ 1678 | { 1679 | "data": { 1680 | "text/html": [ 1681 | "
┌→───┐\n",
1682 |        "│1 18│\n",
1683 |        "└~───┘\n",
1684 |        "
" 1685 | ] 1686 | }, 1687 | "execution_count": null, 1688 | "metadata": {}, 1689 | "output_type": "execute_result" 1690 | } 1691 | ], 1692 | "source": [ 1693 | "1 1 1⍉ cube" 1694 | ] 1695 | }, 1696 | { 1697 | "cell_type": "code", 1698 | "execution_count": null, 1699 | "id": "755c266d", 1700 | "metadata": {}, 1701 | "outputs": [ 1702 | { 1703 | "data": { 1704 | "text/html": [ 1705 | "
┌→────┐\n",
1706 |        "↓ 1 13│\n",
1707 |        "│ 6 18│\n",
1708 |        "│11 23│\n",
1709 |        "└~────┘\n",
1710 |        "
" 1711 | ] 1712 | }, 1713 | "execution_count": null, 1714 | "metadata": {}, 1715 | "output_type": "execute_result" 1716 | } 1717 | ], 1718 | "source": [ 1719 | "2 1 1⍉ cube" 1720 | ] 1721 | }, 1722 | { 1723 | "cell_type": "markdown", 1724 | "id": "617899d6", 1725 | "metadata": {}, 1726 | "source": [ 1727 | "## Other operators" 1728 | ] 1729 | }, 1730 | { 1731 | "cell_type": "markdown", 1732 | "id": "240784d0", 1733 | "metadata": {}, 1734 | "source": [ 1735 | "### `⌺` (Quad Diamond)" 1736 | ] 1737 | }, 1738 | { 1739 | "cell_type": "markdown", 1740 | "id": "afd147ca", 1741 | "metadata": {}, 1742 | "source": [ 1743 | "#### Dyadic operator `⌺` (Stencil)" 1744 | ] 1745 | }, 1746 | { 1747 | "cell_type": "code", 1748 | "execution_count": null, 1749 | "id": "21fb8418", 1750 | "metadata": {}, 1751 | "outputs": [ 1752 | { 1753 | "data": { 1754 | "text/html": [ 1755 | "
┌→──────────────────────────────────────────────────────────┐\n",
1756 |        "↓ ┌→──────────────┐  ┌→──────────────┐  ┌→───────────────┐  │\n",
1757 |        "│ │ ┌→──┐ ┌→────┐ │  │ ┌→──┐ ┌→────┐ │  │ ┌→───┐ ┌→────┐ │  │\n",
1758 |        "│ │ │1 1│ ↓0 0 0│ │  │ │1 0│ ↓0 0 0│ │  │ │1 ¯1│ ↓0 0 0│ │  │\n",
1759 |        "│ │ └~──┘ │0 1 2│ │  │ └~──┘ │1 2 3│ │  │ └~───┘ │2 3 0│ │  │\n",
1760 |        "│ │       │0 4 5│ │  │       │4 5 6│ │  │        │5 6 0│ │  │\n",
1761 |        "│ │       └~────┘ │  │       └~────┘ │  │        └~────┘ │  │\n",
1762 |        "│ └∊──────────────┘  └∊──────────────┘  └∊───────────────┘  │\n",
1763 |        "│ ┌→──────────────┐  ┌→──────────────┐  ┌→───────────────┐  │\n",
1764 |        "│ │ ┌→──┐ ┌→────┐ │  │ ┌→──┐ ┌→────┐ │  │ ┌→───┐ ┌→────┐ │  │\n",
1765 |        "│ │ │0 1│ ↓0 1 2│ │  │ │0 0│ ↓1 2 3│ │  │ │0 ¯1│ ↓2 3 0│ │  │\n",
1766 |        "│ │ └~──┘ │0 4 5│ │  │ └~──┘ │4 5 6│ │  │ └~───┘ │5 6 0│ │  │\n",
1767 |        "│ │       │0 7 8│ │  │       │7 8 9│ │  │        │8 9 0│ │  │\n",
1768 |        "│ │       └~────┘ │  │       └~────┘ │  │        └~────┘ │  │\n",
1769 |        "│ └∊──────────────┘  └∊──────────────┘  └∊───────────────┘  │\n",
1770 |        "│ ┌→───────────────┐ ┌→───────────────┐ ┌→────────────────┐ │\n",
1771 |        "│ │ ┌→───┐ ┌→────┐ │ │ ┌→───┐ ┌→────┐ │ │ ┌→────┐ ┌→────┐ │ │\n",
1772 |        "│ │ │¯1 1│ ↓0 4 5│ │ │ │¯1 0│ ↓4 5 6│ │ │ │¯1 ¯1│ ↓5 6 0│ │ │\n",
1773 |        "│ │ └~───┘ │0 7 8│ │ │ └~───┘ │7 8 9│ │ │ └~────┘ │8 9 0│ │ │\n",
1774 |        "│ │        │0 0 0│ │ │        │0 0 0│ │ │         │0 0 0│ │ │\n",
1775 |        "│ │        └~────┘ │ │        └~────┘ │ │         └~────┘ │ │\n",
1776 |        "│ └∊───────────────┘ └∊───────────────┘ └∊────────────────┘ │\n",
1777 |        "└∊──────────────────────────────────────────────────────────┘\n",
1778 |        "
" 1779 | ] 1780 | }, 1781 | "execution_count": null, 1782 | "metadata": {}, 1783 | "output_type": "execute_result" 1784 | } 1785 | ], 1786 | "source": [ 1787 | "{⊂⍺ ⍵}⌺3 3⊢3 3⍴⍳12" 1788 | ] 1789 | }, 1790 | { 1791 | "cell_type": "code", 1792 | "execution_count": null, 1793 | "id": "05b866d9", 1794 | "metadata": {}, 1795 | "outputs": [ 1796 | { 1797 | "data": { 1798 | "text/html": [ 1799 | "
┌→────────────────────┐\n",
1800 |        "↓ ┌→────┐  ┌→────┐    │\n",
1801 |        "│ ↓0 0 0│  ↓0 0 0│    │\n",
1802 |        "│ │0 1 2│  │2 3 4│    │\n",
1803 |        "│ │0 5 6│  │6 7 8│    │\n",
1804 |        "│ └~────┘  └~────┘    │\n",
1805 |        "│ ┌→─────┐ ┌→───────┐ │\n",
1806 |        "│ ↓0 5  6│ ↓ 6  7  8│ │\n",
1807 |        "│ │0 9 10│ │10 11 12│ │\n",
1808 |        "│ │0 0  0│ │ 0  0  0│ │\n",
1809 |        "│ └~─────┘ └~───────┘ │\n",
1810 |        "└∊────────────────────┘\n",
1811 |        "
" 1812 | ] 1813 | }, 1814 | "execution_count": null, 1815 | "metadata": {}, 1816 | "output_type": "execute_result" 1817 | } 1818 | ], 1819 | "source": [ 1820 | "s←2 2⍴3 3 2 2 ⍝ 2x2 stride with 3x3 kernel\n", 1821 | "({⊂⍵}⌺s)3 4⍴⍳12" 1822 | ] 1823 | }, 1824 | { 1825 | "cell_type": "markdown", 1826 | "id": "78544c22", 1827 | "metadata": {}, 1828 | "source": [ 1829 | "### `@` (At)" 1830 | ] 1831 | }, 1832 | { 1833 | "cell_type": "markdown", 1834 | "id": "0543baf4", 1835 | "metadata": {}, 1836 | "source": [ 1837 | "#### Dyadic `@` (At)" 1838 | ] 1839 | }, 1840 | { 1841 | "cell_type": "code", 1842 | "execution_count": null, 1843 | "id": "d3befbc4", 1844 | "metadata": {}, 1845 | "outputs": [ 1846 | { 1847 | "data": { 1848 | "text/html": [ 1849 | "
┌→──────────┐\n",
1850 |        "│1 0 3 0 5 6│\n",
1851 |        "└~──────────┘\n",
1852 |        "
" 1853 | ] 1854 | }, 1855 | "execution_count": null, 1856 | "metadata": {}, 1857 | "output_type": "execute_result" 1858 | } 1859 | ], 1860 | "source": [ 1861 | "(0@2 4) ⍳6" 1862 | ] 1863 | }, 1864 | { 1865 | "cell_type": "code", 1866 | "execution_count": null, 1867 | "id": "e9971f12", 1868 | "metadata": {}, 1869 | "outputs": [ 1870 | { 1871 | "data": { 1872 | "text/html": [ 1873 | "
┌→──────────┐\n",
1874 |        "│1 3 3 1 5 6│\n",
1875 |        "└~──────────┘\n",
1876 |        "
" 1877 | ] 1878 | }, 1879 | "execution_count": null, 1880 | "metadata": {}, 1881 | "output_type": "execute_result" 1882 | } 1883 | ], 1884 | "source": [ 1885 | "(3 1@2 4) ⍳6" 1886 | ] 1887 | }, 1888 | { 1889 | "cell_type": "code", 1890 | "execution_count": null, 1891 | "id": "780a3c01", 1892 | "metadata": {}, 1893 | "outputs": [ 1894 | { 1895 | "data": { 1896 | "text/html": [ 1897 | "
┌→───────────────┐\n",
1898 |        "│1 0.5 3 0.25 5 6│\n",
1899 |        "└~───────────────┘\n",
1900 |        "
" 1901 | ] 1902 | }, 1903 | "execution_count": null, 1904 | "metadata": {}, 1905 | "output_type": "execute_result" 1906 | } 1907 | ], 1908 | "source": [ 1909 | "÷@2 4 ⍳6" 1910 | ] 1911 | }, 1912 | { 1913 | "cell_type": "code", 1914 | "execution_count": null, 1915 | "id": "96945f30", 1916 | "metadata": {}, 1917 | "outputs": [ 1918 | { 1919 | "data": { 1920 | "text/html": [ 1921 | "
┌→──────────┐\n",
1922 |        "│1 20 3 40 5│\n",
1923 |        "└~──────────┘\n",
1924 |        "
" 1925 | ] 1926 | }, 1927 | "execution_count": null, 1928 | "metadata": {}, 1929 | "output_type": "execute_result" 1930 | } 1931 | ], 1932 | "source": [ 1933 | "10 (×@2 4) ⍳5" 1934 | ] 1935 | }, 1936 | { 1937 | "cell_type": "code", 1938 | "execution_count": null, 1939 | "id": "29afcb4e", 1940 | "metadata": {}, 1941 | "outputs": [ 1942 | { 1943 | "data": { 1944 | "text/html": [ 1945 | "
┌→──────────┐\n",
1946 |        "│0 2 0 4 0 6│\n",
1947 |        "└~──────────┘\n",
1948 |        "
" 1949 | ] 1950 | }, 1951 | "execution_count": null, 1952 | "metadata": {}, 1953 | "output_type": "execute_result" 1954 | } 1955 | ], 1956 | "source": [ 1957 | "0@(2∘|)⍳6" 1958 | ] 1959 | }, 1960 | { 1961 | "cell_type": "code", 1962 | "execution_count": null, 1963 | "id": "26943cf8", 1964 | "metadata": {}, 1965 | "outputs": [ 1966 | { 1967 | "data": { 1968 | "text/html": [ 1969 | "
┌→──────────┐\n",
1970 |        "│5 2 3 4 1 6│\n",
1971 |        "└~──────────┘\n",
1972 |        "
" 1973 | ] 1974 | }, 1975 | "execution_count": null, 1976 | "metadata": {}, 1977 | "output_type": "execute_result" 1978 | } 1979 | ], 1980 | "source": [ 1981 | "⌽@(2∘|)⍳6" 1982 | ] 1983 | }, 1984 | { 1985 | "cell_type": "markdown", 1986 | "id": "e81d5acb", 1987 | "metadata": {}, 1988 | "source": [ 1989 | "## Special non-math glyphs" 1990 | ] 1991 | }, 1992 | { 1993 | "cell_type": "markdown", 1994 | "id": "071dbcaf", 1995 | "metadata": {}, 1996 | "source": [ 1997 | "### `&` (Ampersand)" 1998 | ] 1999 | }, 2000 | { 2001 | "cell_type": "markdown", 2002 | "id": "4825fc15", 2003 | "metadata": {}, 2004 | "source": [ 2005 | "#### Monadic `&` (Spawn)" 2006 | ] 2007 | }, 2008 | { 2009 | "cell_type": "markdown", 2010 | "id": "59a65bcc", 2011 | "metadata": {}, 2012 | "source": [ 2013 | "`&` spawns a new thread in which f is applied to its argument(s)." 2014 | ] 2015 | }, 2016 | { 2017 | "cell_type": "code", 2018 | "execution_count": null, 2019 | "id": "e173b86e", 2020 | "metadata": {}, 2021 | "outputs": [], 2022 | "source": [ 2023 | "÷&4 ⍝ Reciprocal in background" 2024 | ] 2025 | }, 2026 | { 2027 | "cell_type": "markdown", 2028 | "id": "1bcfcaaf", 2029 | "metadata": {}, 2030 | "source": [ 2031 | "### `→` (Branch)" 2032 | ] 2033 | }, 2034 | { 2035 | "cell_type": "markdown", 2036 | "id": "46dc51a2", 2037 | "metadata": {}, 2038 | "source": [ 2039 | "Branching is superseded by the more modern control structures such as :If ... :EndIf." 2040 | ] 2041 | }, 2042 | { 2043 | "cell_type": "markdown", 2044 | "id": "46f81f2f", 2045 | "metadata": {}, 2046 | "source": [ 2047 | "### `⍞` (Print without CR, or stdin)" 2048 | ] 2049 | }, 2050 | { 2051 | "cell_type": "markdown", 2052 | "id": "20e2f64f", 2053 | "metadata": {}, 2054 | "source": [ 2055 | "When ⍞ is assigned with a vector or a scalar, the array is displayed without the normal ending new-line character." 2056 | ] 2057 | }, 2058 | { 2059 | "cell_type": "code", 2060 | "execution_count": null, 2061 | "id": "795c17d9", 2062 | "metadata": {}, 2063 | "outputs": [ 2064 | { 2065 | "data": { 2066 | "text/html": [ 2067 | "
2+2=4\n",
2068 |        "
" 2069 | ] 2070 | }, 2071 | "execution_count": null, 2072 | "metadata": {}, 2073 | "output_type": "execute_result" 2074 | } 2075 | ], 2076 | "source": [ 2077 | "⍞←'2+2' ⋄ ⍞←'=' ⋄ ⍞←2+2" 2078 | ] 2079 | }, 2080 | { 2081 | "cell_type": "markdown", 2082 | "id": "7e407d30", 2083 | "metadata": {}, 2084 | "source": [ 2085 | "When ⍞ is referenced, terminal input is expected without any specific prompt, and the response is returned as a character vector (however this doesn't work in Jupyter)." 2086 | ] 2087 | }, 2088 | { 2089 | "cell_type": "code", 2090 | "execution_count": null, 2091 | "id": "4fd129ff", 2092 | "metadata": {}, 2093 | "outputs": [ 2094 | { 2095 | "data": { 2096 | "text/html": [ 2097 | "
┌→─────┐\n",
2098 |        "↓{     │\n",
2099 |        "│\"a\":1,│\n",
2100 |        "│\"b\":42│\n",
2101 |        "│}     │\n",
2102 |        "└──────┘\n",
2103 |        "
" 2104 | ] 2105 | }, 2106 | "execution_count": null, 2107 | "metadata": {}, 2108 | "output_type": "execute_result" 2109 | } 2110 | ], 2111 | "source": [ 2112 | "⎕←j ← 4 6 ⍴ '{ \"a\":1,\"b\":42} '" 2113 | ] 2114 | }, 2115 | { 2116 | "cell_type": "markdown", 2117 | "id": "3c2e8abd", 2118 | "metadata": {}, 2119 | "source": [ 2120 | "### `⍠` Variant" 2121 | ] 2122 | }, 2123 | { 2124 | "cell_type": "markdown", 2125 | "id": "9efca324", 2126 | "metadata": {}, 2127 | "source": [ 2128 | "Used to pass options/variants to some system functions, such as [JSON convert](https://help.dyalog.com/latest/index.htm#Language/System%20Functions/json.htm)." 2129 | ] 2130 | }, 2131 | { 2132 | "cell_type": "code", 2133 | "execution_count": null, 2134 | "id": "b7e7347a", 2135 | "metadata": {}, 2136 | "outputs": [ 2137 | { 2138 | "data": { 2139 | "text/html": [ 2140 | "
┌→────────────┐\n",
2141 |        "↓   ┌⊖┐ ┌⊖┐   │\n",
2142 |        "│ 0 │ │ │0│ 1 │\n",
2143 |        "│   └─┘ └~┘   │\n",
2144 |        "│   ┌→┐       │\n",
2145 |        "│ 1 │a│ 1   3 │\n",
2146 |        "│   └─┘       │\n",
2147 |        "│   ┌→┐       │\n",
2148 |        "│ 1 │b│ 42  3 │\n",
2149 |        "│   └─┘       │\n",
2150 |        "└∊────────────┘\n",
2151 |        "
" 2152 | ] 2153 | }, 2154 | "execution_count": null, 2155 | "metadata": {}, 2156 | "output_type": "execute_result" 2157 | } 2158 | ], 2159 | "source": [ 2160 | "⎕←mat←(⎕JSON⍠('Format' 'M'))j" 2161 | ] 2162 | }, 2163 | { 2164 | "cell_type": "code", 2165 | "execution_count": null, 2166 | "id": "3e27d184", 2167 | "metadata": {}, 2168 | "outputs": [ 2169 | { 2170 | "data": { 2171 | "text/html": [ 2172 | "
┌→─────────────┐\n",
2173 |        "│{\"a\":1,\"b\":42}│\n",
2174 |        "└──────────────┘\n",
2175 |        "
" 2176 | ] 2177 | }, 2178 | "execution_count": null, 2179 | "metadata": {}, 2180 | "output_type": "execute_result" 2181 | } 2182 | ], 2183 | "source": [ 2184 | "1(⎕JSON⍠('Format' 'M')) mat" 2185 | ] 2186 | }, 2187 | { 2188 | "cell_type": "markdown", 2189 | "id": "f72ad6b6", 2190 | "metadata": {}, 2191 | "source": [ 2192 | "### `⌶` (I-Beam)" 2193 | ] 2194 | }, 2195 | { 2196 | "cell_type": "markdown", 2197 | "id": "f551cbf3", 2198 | "metadata": {}, 2199 | "source": [ 2200 | "I-Beam is a monadic operator that provides a range of system related services. WARNING: Although documentation is provided for I-Beam functions, any service provided using I-Beam should be considered as \"experimental\" and subject to change. As at Aug-2022 services include SVD, probability distributions, and much more." 2201 | ] 2202 | }, 2203 | { 2204 | "cell_type": "markdown", 2205 | "id": "29015349", 2206 | "metadata": {}, 2207 | "source": [ 2208 | "### `⍎` (Hydrant)" 2209 | ] 2210 | }, 2211 | { 2212 | "cell_type": "markdown", 2213 | "id": "c53de407", 2214 | "metadata": {}, 2215 | "source": [ 2216 | "#### Monadic `⍎` (Execute expression)" 2217 | ] 2218 | }, 2219 | { 2220 | "cell_type": "code", 2221 | "execution_count": null, 2222 | "id": "273d73cc", 2223 | "metadata": {}, 2224 | "outputs": [ 2225 | { 2226 | "data": { 2227 | "text/html": [ 2228 | "
 \n",
2229 |        "2\n",
2230 |        " \n",
2231 |        "
" 2232 | ] 2233 | }, 2234 | "execution_count": null, 2235 | "metadata": {}, 2236 | "output_type": "execute_result" 2237 | } 2238 | ], 2239 | "source": [ 2240 | "⍎ '1+1'" 2241 | ] 2242 | }, 2243 | { 2244 | "cell_type": "code", 2245 | "execution_count": null, 2246 | "id": "d0c35053", 2247 | "metadata": {}, 2248 | "outputs": [ 2249 | { 2250 | "data": { 2251 | "text/html": [ 2252 | "
┌→────┐\n",
2253 |        "│1 2 3│\n",
2254 |        "└~────┘\n",
2255 |        "
" 2256 | ] 2257 | }, 2258 | "execution_count": null, 2259 | "metadata": {}, 2260 | "output_type": "execute_result" 2261 | } 2262 | ], 2263 | "source": [ 2264 | "V ← 1 2 3\n", 2265 | "⍎ 'V'" 2266 | ] 2267 | }, 2268 | { 2269 | "cell_type": "code", 2270 | "execution_count": null, 2271 | "id": "c7f0e353", 2272 | "metadata": {}, 2273 | "outputs": [ 2274 | { 2275 | "data": { 2276 | "text/html": [ 2277 | "
 \n",
2278 |        "2\n",
2279 |        " \n",
2280 |        "
" 2281 | ] 2282 | }, 2283 | "execution_count": null, 2284 | "metadata": {}, 2285 | "output_type": "execute_result" 2286 | } 2287 | ], 2288 | "source": [ 2289 | "A← ⍎'1+1 ⋄ 2+2'" 2290 | ] 2291 | }, 2292 | { 2293 | "cell_type": "code", 2294 | "execution_count": null, 2295 | "id": "9d4bd38a", 2296 | "metadata": {}, 2297 | "outputs": [ 2298 | { 2299 | "data": { 2300 | "text/html": [ 2301 | "
 \n",
2302 |        "4\n",
2303 |        " \n",
2304 |        "
" 2305 | ] 2306 | }, 2307 | "execution_count": null, 2308 | "metadata": {}, 2309 | "output_type": "execute_result" 2310 | } 2311 | ], 2312 | "source": [ 2313 | "A" 2314 | ] 2315 | }, 2316 | { 2317 | "cell_type": "markdown", 2318 | "id": "b883202f", 2319 | "metadata": {}, 2320 | "source": [ 2321 | "#### Dyadic `⍎` (Execute expression in given namespace)" 2322 | ] 2323 | }, 2324 | { 2325 | "cell_type": "markdown", 2326 | "id": "62259083", 2327 | "metadata": {}, 2328 | "source": [ 2329 | "X must be a namespace reference or a simple character scalar or vector representing the name of a namespace in which the expression is to be executed." 2330 | ] 2331 | }, 2332 | { 2333 | "cell_type": "markdown", 2334 | "id": "df1830bc", 2335 | "metadata": {}, 2336 | "source": [ 2337 | "### `⍕` (Thorn)" 2338 | ] 2339 | }, 2340 | { 2341 | "cell_type": "markdown", 2342 | "id": "79cfa777", 2343 | "metadata": {}, 2344 | "source": [ 2345 | "#### Monadic `⍕` (Format)" 2346 | ] 2347 | }, 2348 | { 2349 | "cell_type": "code", 2350 | "execution_count": null, 2351 | "id": "3a899b68", 2352 | "metadata": {}, 2353 | "outputs": [ 2354 | { 2355 | "data": { 2356 | "text/html": [ 2357 | "
┌→────┐\n",
2358 |        "│4 5 6│\n",
2359 |        "└~────┘\n",
2360 |        "
" 2361 | ] 2362 | }, 2363 | "execution_count": null, 2364 | "metadata": {}, 2365 | "output_type": "execute_result" 2366 | } 2367 | ], 2368 | "source": [ 2369 | "4 5 6 ⍝ These are numbers (see the `~` in bottom left)" 2370 | ] 2371 | }, 2372 | { 2373 | "cell_type": "code", 2374 | "execution_count": null, 2375 | "id": "efb6d04a", 2376 | "metadata": {}, 2377 | "outputs": [ 2378 | { 2379 | "data": { 2380 | "text/html": [ 2381 | "
┌→────┐\n",
2382 |        "│4 5 6│\n",
2383 |        "└─────┘\n",
2384 |        "
" 2385 | ] 2386 | }, 2387 | "execution_count": null, 2388 | "metadata": {}, 2389 | "output_type": "execute_result" 2390 | } 2391 | ], 2392 | "source": [ 2393 | "⍕ 4 5 6 ⍝ These are characters (no `~` in bottom left)" 2394 | ] 2395 | }, 2396 | { 2397 | "cell_type": "markdown", 2398 | "id": "787be6ff", 2399 | "metadata": {}, 2400 | "source": [ 2401 | "#### Dyadic `⍕` (Format By Specification)" 2402 | ] 2403 | }, 2404 | { 2405 | "cell_type": "markdown", 2406 | "id": "b58d9b26", 2407 | "metadata": {}, 2408 | "source": [ 2409 | "Field-width and number of decimal places:" 2410 | ] 2411 | }, 2412 | { 2413 | "cell_type": "code", 2414 | "execution_count": null, 2415 | "id": "1bc94bba", 2416 | "metadata": {}, 2417 | "outputs": [ 2418 | { 2419 | "data": { 2420 | "text/html": [ 2421 | "
┌→───────────┐\n",
2422 |        "│  3.13  0.00│\n",
2423 |        "└────────────┘\n",
2424 |        "
" 2425 | ] 2426 | }, 2427 | "execution_count": null, 2428 | "metadata": {}, 2429 | "output_type": "execute_result" 2430 | } 2431 | ], 2432 | "source": [ 2433 | "6 2 ⍕ 3.125 0.002" 2434 | ] 2435 | }, 2436 | { 2437 | "cell_type": "code", 2438 | "execution_count": null, 2439 | "id": "4d632ed2", 2440 | "metadata": {}, 2441 | "outputs": [], 2442 | "source": [] 2443 | } 2444 | ], 2445 | "metadata": { 2446 | "kernelspec": { 2447 | "display_name": "Dyalog APL", 2448 | "language": "apl", 2449 | "name": "dyalog-kernel" 2450 | } 2451 | }, 2452 | "nbformat": 4, 2453 | "nbformat_minor": 5 2454 | } 2455 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022, fastai 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include settings.ini 2 | include LICENSE 3 | include CONTRIBUTING.md 4 | include README.md 5 | recursive-exclude * __pycache__ 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | APL Study Group 2 | ================ 3 | 4 | 5 | 6 | Check out [the 7 | forum](https://forums.fast.ai/t/apl-array-programming/97188) for meeting 8 | time and resources! 9 | 10 | You’ll find here a walkthru of what will eventually be all the glyphs in 11 | Dyalog APL, in an order where no glyph is used in an example until it’s 12 | been introduced. So far there’s no prose – the explanations are purely 13 | through examples for now (but we’ll add prose later). 14 | 15 | There’s also a [Python equivalents](python.ipynb) notebook, which has 16 | explanations using python of some APL ideas, including `bind`/`partial` 17 | and APL operators (aka higher-order functions). 18 | -------------------------------------------------------------------------------- /_quarto.yml: -------------------------------------------------------------------------------- 1 | project: 2 | type: website 3 | 4 | format: 5 | html: 6 | theme: cosmo 7 | css: styles.css 8 | toc: true 9 | resources: '*.woff2' 10 | 11 | website: 12 | twitter-card: true 13 | open-graph: true 14 | repo-actions: [issue] 15 | navbar: 16 | background: primary 17 | search: true 18 | sidebar: 19 | style: floating 20 | 21 | metadata-files: [nbdev.yml, sidebar.yml] 22 | -------------------------------------------------------------------------------- /aplstudy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fastai/apl-study/115c5b1468823884889b3eb966ceaf2acfc68266/aplstudy/__init__.py -------------------------------------------------------------------------------- /aplstudy/_modidx.py: -------------------------------------------------------------------------------- 1 | # Autogenerated by nbdev 2 | 3 | d = { 'settings': { 'branch': 'master', 4 | 'doc_baseurl': '/apl-study/', 5 | 'doc_host': 'https://fastai.github.io', 6 | 'git_url': 'https://github.com/fastai/apl-study/tree/master/', 7 | 'lib_path': 'aplstudy'}, 8 | 'syms': {}} -------------------------------------------------------------------------------- /index.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# APL Study Group\n", 8 | "\n", 9 | "> This blog is a work in progress to document and share learning that the Fastai APL Study Group has as they learn Dyalog APL. If you are interested, join us!" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "Check out [the forum](https://forums.fast.ai/t/apl-array-programming/97188) for meeting time and resources!\n", 17 | "\n", 18 | "You'll find here a walkthru of what will eventually be all the glyphs in Dyalog APL, in an order where no glyph is used in an example until it's been introduced. So far there's no prose -- the explanations are purely through examples for now (but we'll add prose later).\n", 19 | "\n", 20 | "There's also a [Python equivalents](python.ipynb) notebook, which has explanations using python of some APL ideas, including `bind`/`partial` and APL operators (aka higher-order functions). " 21 | ] 22 | } 23 | ], 24 | "metadata": { 25 | "kernelspec": { 26 | "display_name": "Python 3 (ipykernel)", 27 | "language": "python", 28 | "name": "python3" 29 | } 30 | }, 31 | "nbformat": 4, 32 | "nbformat_minor": 4 33 | } 34 | -------------------------------------------------------------------------------- /nbdev.yml: -------------------------------------------------------------------------------- 1 | project: 2 | output-dir: _docs 3 | 4 | website: 5 | title: "apl-study" 6 | site-url: "https://fastai.github.io/apl-study/" 7 | description: "fast.ai APL study group notes" 8 | repo-branch: master 9 | repo-url: "https://github.com/fastai/apl-study/tree/master/" 10 | -------------------------------------------------------------------------------- /python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "raw", 5 | "id": "6857289c", 6 | "metadata": {}, 7 | "source": [ 8 | "---\n", 9 | "title: \"Python equivalents\"\n", 10 | "---" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "82d44d43", 16 | "metadata": {}, 17 | "source": [ 18 | "## Decorators" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "id": "8ae42943", 25 | "metadata": {}, 26 | "outputs": [ 27 | { 28 | "data": { 29 | "text/plain": [ 30 | "4" 31 | ] 32 | }, 33 | "execution_count": null, 34 | "metadata": {}, 35 | "output_type": "execute_result" 36 | } 37 | ], 38 | "source": [ 39 | "def add1(x): return x+1\n", 40 | "add1(3)" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "id": "1c1cbc34", 46 | "metadata": {}, 47 | "source": [ 48 | "A function that returns a function:" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "id": "28e83e74", 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "def logargs(f):\n", 59 | " \"Print arguments to `f` before calling it\"\n", 60 | " def _inner(*args, **kwargs):\n", 61 | " print(f\"Received: {args=}; {kwargs=}\")\n", 62 | " return f(*args, **kwargs)\n", 63 | " return _inner" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "id": "f140baf4", 69 | "metadata": {}, 70 | "source": [ 71 | "Using `logargs` to modify a function:" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "id": "9fca0a51", 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "name": "stdout", 82 | "output_type": "stream", 83 | "text": [ 84 | "Received: args=(3,); kwargs={}\n" 85 | ] 86 | }, 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "6" 91 | ] 92 | }, 93 | "execution_count": null, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "def _mult2(x): return x*2\n", 100 | "mult2 = logargs(_mult2)\n", 101 | "mult2(3)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "id": "74c1368e", 107 | "metadata": {}, 108 | "source": [ 109 | "Exactly the same thing but using a decorator as syntax sugar:" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "id": "02759326", 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "Received: args=(3,); kwargs={}\n" 123 | ] 124 | }, 125 | { 126 | "data": { 127 | "text/plain": [ 128 | "6" 129 | ] 130 | }, 131 | "execution_count": null, 132 | "metadata": {}, 133 | "output_type": "execute_result" 134 | } 135 | ], 136 | "source": [ 137 | "@logargs\n", 138 | "def mult2(x): return x*2\n", 139 | "mult2(3)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "id": "72c5a968", 145 | "metadata": {}, 146 | "source": [ 147 | "A class that takes a function and returns a function:" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "id": "482f917d", 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "class logargs:\n", 158 | " def __init__(self, prefix='Received: '): self.prefix=prefix\n", 159 | " def __call__(self, f): \n", 160 | " def _inner(*args, **kwargs):\n", 161 | " print(f\"{self.prefix}{args=}; {kwargs=}\")\n", 162 | " return f(*args, **kwargs)\n", 163 | " return _inner" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "id": "c45d150f", 169 | "metadata": {}, 170 | "source": [ 171 | "Here's how to use it:" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "id": "8013666a", 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "Logging: args=(3,); kwargs={}\n" 185 | ] 186 | }, 187 | { 188 | "data": { 189 | "text/plain": [ 190 | "4" 191 | ] 192 | }, 193 | "execution_count": null, 194 | "metadata": {}, 195 | "output_type": "execute_result" 196 | } 197 | ], 198 | "source": [ 199 | "def _add1(x): return x+1\n", 200 | "o = logargs('Logging: ')\n", 201 | "add1 = o(_add1)\n", 202 | "add1(3)" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "id": "f52282a2", 208 | "metadata": {}, 209 | "source": [ 210 | "Exactly the same thing but using a decorator as syntax sugar:" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "id": "22bd8c62", 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "Logging: args=(3,); kwargs={}\n" 224 | ] 225 | }, 226 | { 227 | "data": { 228 | "text/plain": [ 229 | "4" 230 | ] 231 | }, 232 | "execution_count": null, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "@logargs('Logging: ')\n", 239 | "def add1(x): return x+1\n", 240 | "add1(3)" 241 | ] 242 | }, 243 | { 244 | "cell_type": "markdown", 245 | "id": "3e96dc9e", 246 | "metadata": {}, 247 | "source": [ 248 | "## partial" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "id": "30a6ba64", 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "from functools import partial" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "id": "a4175712", 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "9" 271 | ] 272 | }, 273 | "execution_count": null, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "def pow(x,y): return x**y\n", 280 | "pow(3,2)" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": null, 286 | "id": "3395ce77", 287 | "metadata": {}, 288 | "outputs": [ 289 | { 290 | "data": { 291 | "text/plain": [ 292 | "9" 293 | ] 294 | }, 295 | "execution_count": null, 296 | "metadata": {}, 297 | "output_type": "execute_result" 298 | } 299 | ], 300 | "source": [ 301 | "squared = partial(pow, y=2)\n", 302 | "squared(3)" 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": null, 308 | "id": "78cd2374", 309 | "metadata": {}, 310 | "outputs": [], 311 | "source": [] 312 | } 313 | ], 314 | "metadata": { 315 | "kernelspec": { 316 | "display_name": "Python 3 (ipykernel)", 317 | "language": "python", 318 | "name": "python3" 319 | } 320 | }, 321 | "nbformat": 4, 322 | "nbformat_minor": 5 323 | } 324 | -------------------------------------------------------------------------------- /settings.ini: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | # All sections below are required unless otherwise specified 3 | # see https://github.com/fastai/nbdev/blob/master/settings.ini for examples 4 | host = github 5 | lib_name = apl-study 6 | description = fast.ai APL study group notes 7 | copyright = Jeremy Howard, 2022 onwards 8 | keywords = nbdev apl dyalog 9 | user = fastai 10 | author = Jeremy Howard 11 | author_email = info@fast.ai 12 | branch = master 13 | version = 0.0.1 14 | min_python = 3.9 15 | audience = Developers 16 | language = English 17 | license = apache2 18 | status = 2 19 | nbs_path = . 20 | doc_path = _docs 21 | recursive = True 22 | tst_flags = notest 23 | 24 | ### Inferred From Other Values ### 25 | doc_host = https://%(user)s.github.io 26 | doc_baseurl = /%(lib_name)s/ 27 | git_url = https://github.com/%(user)s/%(lib_name)s/tree/%(branch)s/ 28 | lib_path = aplstudy 29 | title = %(lib_name)s 30 | 31 | ### OPTIONAL ### see https://github.com/fastai/nbdev/blob/master/settings.ini for examples 32 | 33 | # requirements = fastcore pandas 34 | # dev_requirements = 35 | # console_scripts = 36 | 37 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from pkg_resources import parse_version 2 | from configparser import ConfigParser 3 | import setuptools 4 | assert parse_version(setuptools.__version__)>=parse_version('36.2') 5 | 6 | # note: all settings are in settings.ini; edit there, not here 7 | config = ConfigParser(delimiters=['=']) 8 | config.read('settings.ini') 9 | cfg = config['DEFAULT'] 10 | 11 | cfg_keys = 'version description keywords author author_email'.split() 12 | expected = cfg_keys + "lib_name user branch license status min_python audience language".split() 13 | for o in expected: assert o in cfg, "missing expected setting: {}".format(o) 14 | setup_cfg = {o:cfg[o] for o in cfg_keys} 15 | 16 | licenses = { 17 | 'apache2': ('Apache Software License 2.0','OSI Approved :: Apache Software License'), 18 | 'mit': ('MIT License', 'OSI Approved :: MIT License'), 19 | 'gpl2': ('GNU General Public License v2', 'OSI Approved :: GNU General Public License v2 (GPLv2)'), 20 | 'gpl3': ('GNU General Public License v3', 'OSI Approved :: GNU General Public License v3 (GPLv3)'), 21 | 'bsd3': ('BSD License', 'OSI Approved :: BSD License'), 22 | } 23 | statuses = [ '1 - Planning', '2 - Pre-Alpha', '3 - Alpha', 24 | '4 - Beta', '5 - Production/Stable', '6 - Mature', '7 - Inactive' ] 25 | py_versions = '3.6 3.7 3.8 3.9 3.10'.split() 26 | 27 | requirements = cfg.get('requirements','').split() 28 | min_python = cfg['min_python'] 29 | lic = licenses.get(cfg['license'].lower(), (cfg['license'], None)) 30 | dev_requirements = (cfg.get('dev_requirements') or '').split() 31 | 32 | setuptools.setup( 33 | name = cfg['lib_name'], 34 | license = lic[0], 35 | classifiers = [ 36 | 'Development Status :: ' + statuses[int(cfg['status'])], 37 | 'Intended Audience :: ' + cfg['audience'].title(), 38 | 'Natural Language :: ' + cfg['language'].title(), 39 | ] + ['Programming Language :: Python :: '+o for o in py_versions[py_versions.index(min_python):]] + (['License :: ' + lic[1] ] if lic[1] else []), 40 | url = cfg['git_url'], 41 | packages = setuptools.find_packages(), 42 | include_package_data = True, 43 | install_requires = requirements, 44 | extras_require={ 'dev': dev_requirements }, 45 | dependency_links = cfg.get('dep_links','').split(), 46 | python_requires = '>=' + cfg['min_python'], 47 | long_description = open('README.md').read(), 48 | long_description_content_type = 'text/markdown', 49 | zip_safe = False, 50 | entry_points = { 51 | 'console_scripts': cfg.get('console_scripts','').split(), 52 | 'mkdocs.plugins': [ 'rm_num_prefix = nbdev.mkdocs:RmNumPrefix' ], 53 | 'nbdev': [f'{cfg.get("lib_path")}={cfg.get("lib_path")}._modidx:d'] 54 | }, 55 | **setup_cfg) 56 | 57 | 58 | -------------------------------------------------------------------------------- /sidebar.yml: -------------------------------------------------------------------------------- 1 | website: 2 | sidebar: 3 | contents: 4 | - index.ipynb 5 | - 01_APL.ipynb 6 | - 02_functions.ipynb 7 | - 03_operators.ipynb 8 | - 04_competition.ipynb 9 | - 05_the_rest.ipynb 10 | - python.ipynb -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | pre.language-APL { 2 | line-height: 1.05; 3 | } 4 | 5 | .cell-output pre { 6 | padding: 3px 0px 3px 9px; 7 | margin-left: 0.8rem; 8 | margin-top: 0; 9 | background: none; 10 | border-left: 2px solid lightsalmon; 11 | border-top-left-radius: 0; 12 | border-top-right-radius: 0; 13 | } 14 | 15 | .cell-output .sourceCode { 16 | background: none; 17 | margin-top: 0; 18 | } 19 | 20 | .cell > .sourceCode { 21 | margin-bottom: 0; 22 | } 23 | 24 | @font-face { 25 | font-family: 'sax2'; 26 | src: url('www/SAX2.woff2') format('woff2'); 27 | font-weight: normal; 28 | font-style: normal; 29 | } 30 | 31 | pre.language-APL { 32 | font-family: 'sax2' !important; 33 | } 34 | 35 | .apl code { 36 | font-family: 'sax2' !important; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /www/SAX2.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fastai/apl-study/115c5b1468823884889b3eb966ceaf2acfc68266/www/SAX2.ttf -------------------------------------------------------------------------------- /www/SAX2.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fastai/apl-study/115c5b1468823884889b3eb966ceaf2acfc68266/www/SAX2.woff2 --------------------------------------------------------------------------------