Pythagoras’ Theorem In APL

Below is Pythagoras’ theorem interpreted into APL. To the left of the function simply enter a 2 element numeric vector for example 3 4 and to the right enter a scalar for example 10.

Pythagoras Theorum APL

A result of 1 means the triangle is right angled, a result of zero means it is not a right angled triangle.

The left vector represents the two shortest legs of the triangle and the right scalar represents the hypotenuse. Below are a couple of examples:

Pythag proof APL

Give it a try…

The Final Day

Sorry for the belated post I was resting my brain. The final day was a learning experience however more to do with implementing the knowledge we had already learnt.

What a journey this course has been. A very challenging experience however I have obtained an incredible amount of understanding in the past 5 days. Our teacher was very knowledgeable and understanding and provided an education that can not be faulted.

Our last day consisted of the following topics:

  • Nested matrix’s and arrays and the bizarre results you sometimes obtain from them.
  • Enclosing and disclosing variables
  • Mixing and splitting variables
  • The lamination symbol and how to use it
  • Using the display function effectively
  • Checking the depth of variables

The course has been intense both in pace and content and in turn we have quickly developed a basic understanding of APL. However we have only scratched the surface in terms of using it and it’s potential. I look forward to learning more and more about this language and how it can be used.

The Fourth Day

Although every day has been interesting today held a particular interest for me. Today we were learning about traditional loops in APL such as For, Repeat Until etc… However before we learnt about these loops we were asked to perform a task seemingly only possible with loops, without any. I found the solution and compared it with a loop version I created. There was no difference. It shows that just because you know how to perform an operation you shouldn’t be narrow minded and should sometimes take a step back to look at the problem.

Anyway. Today produced the most challenging exercises. The culprit being inner and outer products. Here is what we learned today:

  • The jot symbol and how it is used and associated with the outer product.
  • The calculation and meanings of inner products.
  • Expanded on the operators we already used as well as learning new ones.
  • The use of scope with operators.
  • More on the rotation of vectors and matrix’s.
  • How to use dot products effectively.
  • Searching for character vectors in matrix’s and vectors.
  • Putting the idea of a zero populated matrix into use.
  • The unique symbol.

Although the bulleted list is not as populated as other days’ posts the theory behind the concepts that we learnt today required by far the most attention and even more time to implement them in a useful function.

The Third Day

Firstly apologies for the lack of a post summarizing yesterday’s lessons I was enjoying a delicious Chinese buffet. Without further hesitation here is again a summary of the techniques and idea that we learnt today (yesterday):

  • Membership and how it differs to finding items using a binary condition approach. 
  • The dyadic use of iota and how this compares to using membership to find items.
  • The rotational features of APL.
  • The use of AND, OR, NAND, NOR and XOR.
  • How to use comma bar and why it is so useful.
  • The idea of having empty vectors and the zero tilde symbol.
  • The symbols used to quickly operate on the first dimension of a variable.
  • We had a brief introduction to direct functions.
  • Compression using the results of binary expressions.
  • Some more formatting using binary.

That is all I can remember at the moment however as I said in an earlier post I am writing up a complete set of notes which I will publish at the end of the course and will include notes on every symbol I learn.

Also after the course I will start publishing some of the programs written during the course with explanations on how we learnt to optimize them.

Day Two

Day two of training was a steeper learning curve for everyone. Learning to interact with, identify and modify different types of variables opens a whole new bag of tricks. Again I have summarized my learning for today in bullet point form below:

  • We learnt more advanced ways of indexing matrix’s and vectors
  • We learnt the importance of the shape and rank of a variable and the peculiar fact that a scalar has no shape and a rank of 0.
  • Rank proved to be ever more important as we got into more complex variables.
  • We learnt about concatenation and the need for variables to conform to certain requirements in order to be concatenated.
  • The concept of linear mathematics and a small amount of how it is applied in APL and programming languages in general.
  • What a nested array is and why it is sometimes used, also when to use one and when not to use one.
  • The formatting in APL and how this can be used to produce presentations of concatenated arrays.
  • The reshaping of different variable types and why additional steps are necessary for some.
  • A brief history of the APL language.
  • We were tasked with writing functions to find data items and matrix’s and also to display data in an organised and presentable fashion.

That’s all I can remember for now however I did get lost in town for two hours today as well as take a chunk out of my thumb with a rather hefty knife so to say I am slightly tired and forgetful and this moment is an accurate statement. I will continue tomorrow…

First Day Of Training

Today was the first day of training. My teacher was the author of the book Mastering Dyalog APL, Mr. Bernard Legrand. Below is a list of all of the concepts and ideas that I learnt today. I am not aiming to explain any of the actual programming however I will be releasing a detailed write up of the programming and code towards the end of the week when the course finishes. Today I learnt:

• Basic operations such as multiplication and division along with the specialist symbols they use in APL.
• The assignment of variables and how variables may interact with each other using operands.
• Performing simple operations on sets of data.
• How to create a list or matrix and the differences between different types of variables.
• The use of the reshape feature and its purpose in the language.
• How to declare and manipulate multi-dimensional arrays.
• The meaning of shape and rank.
• The standard indexing of an array and vectors.
• The creation of dynamic and traditional functions and passing parameters to them.

Each of these bullet point have intricate implementations and purposes and learning them and when to use them was very insightful however we have only just scratched the surface of their full potential.

More to follow tomorrow…