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…

Advertisements

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…

APL Keyboard Switching

Recently I’ve been learning a language called APL (A programming language)* and one thing that annoys me is, because APL requires a specific keyboard layout, you have to change between the APL layout and the English layout when switching between pieces of software.

To ease this burden some of the software will automatically switch the keyboard layouts however in some scenarios you may require the APL symbols in software such as Microsoft Office Word.

Word will automatically change your keyboard layout to UK or US English** meaning you will then have to manually navigate to the languages section and again change your keyboard layout.

After doing this many many times while writing documentation notes for myself I decided to write a quick solution.

For this program I used C# and only a small piece of code is needed to change the input language assuming System.Globalization is included:

InputLanguage.CurrentInputLanguage = InputLanguage;

To find the required IME and implement it I used the following code:


foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages)
{
    if (lang.LayoutName == "Dyalog APL IME (en-GB)")
    {
        InputLanguage.CurrentInputLanguage = lang;
    }
}

This small piece of code cycles through all your installed languages and finds the one entitled “Dyalog APL IME (en-GB)”, then it sets your current language to the one it found.

For my program I used listboxes to allow the selection of different keyboard layouts and I also added docking buttons to allow the form to sit comfortably in any corner of the screen,

You can download my program as a small executable from the following link: http://www.mediafire.com/download/35ku6ea39f9pyaq/KeyboardSwitcher.exe

Thanks for reading if you have any questions comment them and I’ll try and respond as quickly as I can,

Callum (flouc001)

* No I’m not joking that’s actually the name of it

** Country / Default language specific