[WSG24] Daily Study Group: Programming Proficiency

A Wolfram U Daily Study Group previewing our upcoming Programming Proficiency course sequence begins on Monday, January 29, 2024. The study group will run for ten days through February 9, and each day will run from 11AM to noon CDT.

Join me, @Abrita Chakravarty and a cohort of fellow enthusiasts to build a strong foundation for any and all sorts of Wolfram Language programming that you’ll do in the future. We’ll cover everything from syntax, definitions, and the underlying structure of expressions to efficient coding, working with various data structures, and even developing packages.

This study group will cover material from our Programming Fundamentals and Practical Programming courses, as well as provide attendees a first look at Programming and Development, the upcoming third and final course in the Programming Proficiency course sequence. Our intent is to provide a setting for this material which not only reaps the benefits of our Daily Study Groups’… well, group nature, but also spreads this material out over two weeks for those who cannot commit to the three-hour blocks required by these courses in their natural habitat.

This study groups aims to get you up and running with Wolfram Language, and as such no prior Wolfram Language or programming experience is necessary.

REGISTER HERE.

We look forward to seeing you there!

10 Likes

I can’t make it at this time on MWF, but can on TTh.

1 Like

Daily recordings will be shared with the group each day, so you can catch up on any sessions you miss. Looking forward to it!

5 Likes

Hi everybody—I’ve added today’s “filled-out” notebook to the materials folder. See you tomorrow!

6 Likes

Hey Arben,

I’ve not used associations before and I am trying to imagine what is their superpower. I’m not really a software writer, I just play one when I’m trying to study or solve engineering problems. One idea that jumps off the page is using a list of variable value assignments that can be summoned in a program without actually defining the variables outside of the context of the operation using them. That’s kind of neat. I’d have to try that out and see if it makes a program easier to write or understand. But I suspect that’s just the tip of the iceberg (as is everything else in the Wolfram language).

What do you say is the superpower in using associations?

The link in the email I received doesn’t work. How do I navigate to the materials folder? I looked around and didn’t see an obvious link.

1 Like

Hi David,
Apologies for the bad link in today’s recording email. The one below should take you right to the folder: https://wolfr.am/WSG48_Programming_Profeciency

1 Like

Hey Carl! Indeed, you can think of associations as constituting some “local map” between keys and values (and indeed, that might be part of the reason why they can be “indexed” with single brackets like functions can, though this is just a wild guess).

The primary value of associations in my view comes from the the organizational structure. For example, suppose I have a nested association:

scores=<|"Bob"-><|"Geography"->100,"Mathematics"->80,"Chemistry"->90|>,
"Alice"-><|"Geography"->90,"Mathematics"->100,"Chemistry"->85|>,
"Carol"-><|"Geography"->Missing["Absent"],"Mathematics"->100,"Chemistry"->95|>|>,

Now, without needing to remember which student or score is where, I can do something like:

scores["Bob"]

or:

scores["Bob","Chemistry"]

or:

scores[[All,"Mathematics"]]

This can be very useful for obvious reasons, especially as datasets get larger and more complicated.

We’ll discuss this more later in the course, but you may recall that pure functions work with numbered, unnamed slots:

#1+#2&[a,b]

returns:

a+b

But this isn’t the only way they can work—they can work with slots named by keys as well:

#cat+#dog&[<|"cat"->1,"dog"->2|>]

will return 3. This lets you write code that not only extracts the appropriate parts very easy, but performs various queries in a super readable and simple way. For example, the following code will select any students who have a chemistry score of 90 or higher:

Select[scores,#Chemistry≥90&]

Finally, from a technical perspective, it is faster to add or remove key-value pairs to an association than to add or remove elements with a list. This doesn’t really crop up at the example scales we’re talking about here, but can have an effect at larger sizes.

3 Likes

Thanks for teaching and I look forward to gaining new insight and learning the various facets of the Wolfram Language and learning to code with Mathematica. The course in this series labeled with #34 for the most part was attended, although completion of the course-work is latent. Hastily, without having differentiated or juxtaposed the two sets of files, I’m wondering about the development or difference thereof. Also, is this the appropriate place to provide commentary or share what you are learning or problems that you may be stuck on in the sense of posing a problem that is confounding?

For the sake of convenience, I have the following two lines for reference with the time zone set to GMT-8 for current locale the default being +1 given the supposed original temporal datum or original time where it is that the Vatican City state is presently, as well as central Europe and Scandinavia. This is just for contrasting disparate times along the lines of DateObject[] and use of SolarTime[] and MoonPosition[] for scheduling, thinking with respect to calendrical arithmetic or geo-computation for arranging one’s day according to a plan in the sense of avoiding scheduling conflicts and slotting time around attendance of the course.

Transpose@{Alphabet["Greek"][[1;;10]]//Capitalize,(QuantityMagnitude/@Table[(a-DateObject[List[1,1,11,0,0,0],"Instant","Gregorian",1.`]),{a,{DateObject[{2024,1,29,9,0,0}],DateObject[{2024,1,30,9,0,0}],DateObject[{2024,1,31,9,0,0}],DateObject[{2024,2,1,9,0,0}],DateObject[{2024,2,2,9,0,0}],DateObject[{2024,2,5,9,0,0}],DateObject[{2024,2,6,9,0,0}],DateObject[{2024,2,7,9,0,0}],DateObject[{2024,2,8,9,0,0}],DateObject[{2024,2,9,9,0,0}]}}])//Ceiling//FactorInteger}//Grid

and also

TableForm[Transpose[List[List["Lists and Associations","Assignments, Rules and Patterns","Syntax and Expressions","Writing a Program","Good Coding Practices","Interfaces and Deployment","Working with Data, Part I","Working with Data, Part II", "Developing Packages","Review Session"],List[DateObject[{2024,1,29,9,0,0},"Instant","Gregorian", -8.`],DateObject[{2024,1,30,9,0,0}, "Instant", "Gregorian", -8.`], DateObject[{2024,1,31,9,0,0}, "Instant","Gregorian",-8.`],DateObject[{2024,2,1,9,0,0},"Instant","Gregorian",-8.`],DateObject[{2024,2,2,9,0,0},"Instant","Gregorian",-8.`],DateObject[{2024,2,5,9,0,0},"Instant","Gregorian",-8.`],DateObject[{2024,2,6,9,0,0}, "Instant", "Gregorian", -8.`],DateObject[{2024,2,7,9,0,0}, "Instant", "Gregorian",-8.`],DateObject[{2024,2,8,9,0,0},"Instant","Gregorian",-8.`],DateObject[{2024,2,9,9,0,0}, "Instant","Gregorian", -8.`]]]]]

With respect to this is the question of how to seamlessly integrate sharing of snippets of code like this in and that within Wolfram|One this was drafted and then the sequence was right click the “cell object delineator” (For lack of the proper term, assuming that is the incorrect phrase or string for a potential association) and then through the “drop down menu” “Plain Text” was selected and then “Alt + Tab” to navigate to Notepad and then “Ctrl + V” in the window after left clicking and then copying again via the aforementioned technique and then tabbing or repeatedly using the “Alt + Tab” macro/technique or combined key-press selecting the Microsoft Edge window and then again (As with Notepad via Windows 11) left-clicking and then pasting or using the “Ctrl + V” key-combination after left-clicking. This is rather cumbersome and tedious in the sense of efficacy with respect to the users resource of time (Avoiding philosophical subtleties with respect to the complexity classes and dichotomy in the sense of Kolmogorov & also the power tower or sequential binary operation, to provide an errant opinion in the mode of assumption). Perhaps accessing this page from within the Mathematica console or the Wolfram|One program such as what was mentioned earlier with external APIs in some way navigating a directory safely and in a maximally efficient manner with respect to augmentations such as keypress (Again, lacking the lingo or appropriate terminology with respect to this programming language or the sequence of expressions in the sense of algorithm).

One question is about accessing this course via BigMarker through a secure channel or learning about ports and other nuanced aspects in the sense of being conservative with data and being able to readily upload information through the WDF or contribute in real-time to the Wolfram Function Repository without removing attention from the lecture such as with alternate channels of data in the sense of active execution for formatting and the like.

Hopefully, I can provide less loquacious or verbose inquiries, yet the actual procedure of the computer program (I assume algorithm is correct in the sense of encapsulating it lexically or calling it by one word, as I imagine that I may do if there is audio programming and “calling” the server/use of the kernel involves univocal definitions and sensitivity in terms of attenuation) is what I’m curious about and I’ve deviated from solving the puzzles or producing a solution set, to my own detriment.

Given that so much time is spent with low-level calculations in Mathematica such as the above, a curiosity is with more compact functions such as with the pure function or defining the concept parametrically (Only having a vague notion of that at present, in the sense of a region that may be implicit, explicit, or parametric, according with abstract or universal geometry [rudimentary mathematical constructions and later demonstrations is a crucial project at present with developing thinking methodically or discerning the methodology, which I think that the Documentation Center does a good job of as it is worded, that I’ve noticed up until now, although one curiosity, further still, tangentially, is about the LinkSnooper and modifying the formatting with notebooks for stylesheets and whatnot. CloudDeploy[] was noted at 0713 0750 0203 and APIFunction[] on 0863 that date, although I currently lack knowledge of their utility with respect to rough outline of the aforementioned project, failin to attend/being truent for the course on May 16, 2023 on Programming Fundamentals. There is a wonder from 11439 about notation and Boolean Algebra with nn*ee, b^^nnnn, &&, ||, !, and <> about Element[] for the atomic expressions and use of Distributed[], UndirectedEdge[], DirectedEdge[] for Galois Theory (Which was, FiniteField[] and the related group theoretic constructs, experimental as of version 13.3.0) with there a curiosity about Polynomial Algebra and the S- and K-combinatorics with the Chief Executive Officer expounding work from December 1920 (Find WikipediaData@“Combinatory Logic” for a more concise elaboration) and use of bit-vectors in the aforementioned sense of a directory and efficacious navigation through WolframScript via the command line without a graphical interface.

738904.0199

1 Like

Hi arben,
Yes this is the tip of iceberg. I suggest you hash table as something to know. O(1) as a search algorithm. Hash tree and topology is a rich context to know

1 Like

Anyone grok this list operation: Alphabet[][[;; 10 ;; 4]]

I understand Alphabet[]
I understand Alphabet[] [[;;10]]
I understand Alphabet[] [[;;4]]

I do not grok what’s happening when the 2nd and 3rd statements are combined. I thought the “;;” operation acted like a pipe. The solution {a, e, i} isn’t what I think a pipe should give.

2 Likes

Hey Coe, could you be a little clearer in your description of your inputs, their actual outputs, and the outputs you would expect? In the meantime, let me explain the meaning of each line you’ve included here.

Alphabet\[\][[;;10;;4]]

This is equivalent to Alphabet[][[1;;10;;4]]. This means “starting with the list of all of the letters in the (Latin) alphabet, take the first through the tenth elements in steps of 4.” I.e., that’s elements 1,1+4,1+4,+4===1,5,9. (You don’t go to 13 since the initial list only has 10 elements.) And indeed, that’s what this code does—cf. MapIndexed[#2[[1]] -> #1 &, Alphabet[]] or Thread[Range@26 -> Alphabet[]] to see it directly.

Actually, I see what you were initially asking. I think the above sufficiently clarifies it, but “in order”:

  • Alphabet[] provides a list containing the characters of the Latin alphabet
  • Appending [[;;10]] is the same as appending [[1;;10]] and is extracting the 1st through 10th parts of the list containing the alphabet
  • Similarly, appending [[;;4]] is equivalent to appending [[1;;4]] and is extracting the 1st through 4th parts of the list containing the alphabet

Doing [[a;;b;;c]] is not the same as doing [[a;;b]][[;;c]]. The “sandwich” construction specifically means “go from a to b in jumps of size c”; it’s different from “chaining” ;;/Span commands through [[ ]]/Part.

3 Likes

Hello Coe!

Arben’s explanation made me want to see it in color. This is what came of it. I hope it helps.

PLEASE SEE THE NOTEBOOK ATTACHED TO THIS COMMENT

Have fun!

776682000.nb (16.8 KB)

3 Likes

question = “If Mathematica is a term rewriting system, when I write a programme in Mathematica, am I writing a term rewriting rule, and is the programme a function?”;

If[question==={“yes”, “yes”}, “At what point does a rule become a system?”,“Help!”]

1 Like

Yes! The evaluation system is effectively a huge database of pattern-matching term-rewriting rules. For example, think about:

D[x^3,x]

We know that this is “the derivative of x cubed with respect to x”, and we know that when we see this pattern—the derivative of x^n_, if you will—that we should take the power, drop it to the front, and then subtract 1 from the power.

The Wolfram system is effectively doing the same thing: it sees that something matches the pattern D[x^n_,x] and says what we do: "I know what to do when I see that: D[x_n,x] :> n*x^(n-1) and that’s what’s returned to us.

When you write your own functions, you are effectively adding to this database of term-rewriting rules (and are often using those rules as foundations for your own definition). In this way, any program you write is just about matching patterns and transforming the appropriate ones into something new.

2 Likes

Wonderful explanation! I’m going to give this more thought. I’m trying to get my head around Wolfram engine.

2 Likes

Arben, how do I post without replying to someone else’s post (like I am doing now)?

I do have a question about Riffle[ ].

Riffle[{1,2,3}, {x, y}]

outputs {1,x,2,y,3}, understandably. But

Riffle[{x,y}, {1,2,3}]

outputs {x,1,y}. Why? I would have expected to get {x, 1, y, 2}.

Thanks.

In today’s post-lecture questions “pat2 = _h”
Case tells me that pat2 matches the following elements in exprs:

    {h[], h[a], h[b], h[a, b], h[a, a], h[a, b, c]}

Does this mean that pat2 = h = h? It seems like it, but this seems odd to me in that we are PATTERN MATCHING and, it seems to me, elements in one order should not necessarily be equivalent to elements in a different order.

Comment?

My apologies folks, I mis-wrote the equality that I am asking about. Again -

In today's post-lecture questions "pat2 = _h" Case tells me that pat2 matches the following elements in exprs:

    {h[], h[a], h[b], h[a, b], h[a, a], h[a, b, c]}

Does this mean that **pat2 = _h = h_**? It seems like it, but this seems odd to me in that we are PATTERN MATCHING and, it seems to me, elements in one order should not necessarily be equivalent to elements in a different order.

Comment?

I thought I understood this material during the lecture; most things made sense. Some parts of Problem 1 however just don’t seem right. For example, why does pat3 give the following result?

exprs = {1, h[], h[a], h[b], h[a, b], h[a, a], h[a, b, c], g[h[a, b]]}
pat3 = x_
Cases[ exprs, pat3]
    {1, h[], h[a], h[b], h[a, b], h[a, a], h[a, b, c], g[h[a, b]]}

I see no way to get this result.

Thanks in advance,