Skip to content

Instantly share code, notes, and snippets.

View abrudz's full-sized avatar
🍏

Adám Brudzewsky abrudz

🍏
View GitHub Profile
@abrudz
abrudz / TAO.dyalog
Created December 7, 2017 15:30
Sorting and grading any Dyalog APL array.
Sort←{⎕ML←1 ⍝ Total array ordering (TAO) comparison.
acmp←{ ⍝ array comparison.
≡/⍵:¯1 ⍝ match: equal.
~≡/⍴∘⍴¨⍵:∇ xrnk ⍵ ⍝ ranks differ: reshape with 1-axes.
⊃⊃⍷/⍵:1 ⍝ prefixes precede their continuations.
⊃⊃⍷/⌽⍵:0 ⍝ continuations follow their prefixes.
~≡/⍴¨⍵:∇ xshp ⍵ ⍝ shapes differ: stretch with fills.
0=×/⍴⊃⍵:∇⊃¨⍵ ⍝ null: comparison of proto items.
~⍵≡⊃¨⍵:∇ halves,¨⍵ ⍝ non-atomic: item-wise comparison.
@abrudz
abrudz / Eigen.dyalog
Created December 20, 2017 22:19
Eigen function in as it used to be in old versions of Dyalog APL
Eigen←{⎕IO ⎕ML←1 ⍝ Eigen values⍪vectors
[email protected]
dsyev←{ ⍝ real symmetric:
args←'dsyev_'assoc↓⍉↑⌽{ ⍝ associate external fn.
⍵,⊂' <T1 ' 'V'}{ ⍝ JOBZ
⍵,⊂' <T1 ' 'L'}{ ⍝ UPLO
⍵,⊂' <I4 'n}{ ⍝ N
⍵,⊂' =F8[] '(,mat)}{ ⍝ A
⍵,⊂' <I4 'n}{ ⍝ LDA
⍵,⊂' >F8[] 'n}{ ⍝ W
@abrudz
abrudz / Math.dyalog
Created December 20, 2017 22:25
Eigen function (and its helper functions) as currently shipped with Dyalog APL
∇ vv←Eigen mat;vecs;vals;code;n
n←≢mat
:If Real mat
:If (Sym mat)∧2≠n ⍝ symmetric
(vals vecs code)←Dsyev mat
:Else ⍝ general
(vals vecs code)←Dgeev mat
:EndIf
@abrudz
abrudz / cmpOver.dyalog
Last active September 13, 2018 16:36
cmp with Over operator
cmp←{ ⍝ compare basic arrays, results in ¯1 (⍺ precedes ⍵), 0 (⍺ is identical to ⍵), or 1 (⍺ follows ⍵)
⍝ DEFINITION:
⍝ ┌
⍝ │ ¯1 if ⍺ strictly precedes ⍵
⍝ ⍺ cmp ⍵ = │ 0 if ⍺ exactly matches ⍵
⍝ │ 1 if ⍺ strictly follows ⍵
⍝ └
⍝ AXIOMS:
@abrudz
abrudz / mean.ipynb
Created September 14, 2018 09:31
Webinar file
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@abrudz
abrudz / Mean.ipynb
Created September 17, 2018 13:48
Webinar file
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@abrudz
abrudz / lb.js
Created March 24, 2019 17:22
APL language bar
;(_=>{
let hc={'<':'&lt;','&':'&amp;',"'":'&apos;','"':'&quot;'},he=x=>x.replace(/[<&'"]/g,c=>hc[c]) //html chars and escape fn
,tcs='<-←xx×/\\×:-÷*O⍟[-⌹-]⌹OO○77⌈FF⌈ll⌊LL⌊|_⊥TT⊤-|⊣|-⊢=/≠L-≠<=≤<_≤>=≥>_≥==≡=_≡/_≢L=≢vv∨^^∧^~⍲v~⍱^|↑v|↓((⊂cc⊂(_⊆))⊃[|⌷|]⌷A|⍋V|⍒ii⍳i_⍸ee∊e_⍷'+
'uu∪UU∪nn∩/-⌿\\-⍀,-⍪rr⍴pp⍴O|⌽O-⊖O\\⍉::¨""¨~:⍨~"⍨*:⍣*"⍣oo∘o:⍤o"⍤[\'⍞\']⍞[]⎕[:⍠:]⍠[=⌸=]⌸[<⌺>]⌺o_⍎oT⍕o-⍕<>⋄on⍝->→aa⍺ww⍵VV∇--¯0~⍬'+
'^-∆^=⍙[?⍰?]⍰:V⍢∇"⍢||∥ox¤)_⊇_)⊇O:⍥O"⍥V~⍫\'\'`'
,lbs=['←←\nASSIGN',' ','++\nconjugate\nplus','--\nnegate\nminus','××\ndirection\ntimes','÷÷\nreciprocal\ndivide','**\nexponential\npower','⍟⍟\nnatural logarithm\nlogarithm',
'⌹⌹\nmatrix inverse\nmatrix divide','○○\npi times\ncircular','!!\nfactorial\nbinomial','??\nroll\ndeal',' ','||\nmagnitude\nresidue',
'⌈⌈\nceiling\nmaximum','⌊⌊\nfloor\nminimum','⊥⊥\ndecode','⊤⊤\nencode','⊣⊣\nsame\nleft','⊢⊢\nsame\nright',' ','==\nequal','≠≠\nnot equal',
'≤≤\nless than or equal to','<<\nless than','>>\ngreater than','≥≥\ngreater than or equal to','≡≡\ndepth\nmatch','≢≢\ntally\nnot matc
@abrudz
abrudz / P7S.aplf
Last active December 19, 2019 11:17
Solution to AoC 2015 P7
P7S←{
⍝ Implement recursive topological sort
Segs←#.U.Segs
Trim←#.U.Trim
data←⍉⊃¨@2⍉' 'Segs¨Trim↑'->'∘Segs¨⍵
results←¯1⍴⍨≢data
ToBin←(16⍴2)∘⊤
FromBin←2∘⊥
NOT←=
AND←∧
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 4.
Post Link,Score,AnswerCount,ClosedDate
"{
""id"": 108170,
""title"": ""Totally Cubular""
}","17","0",""
"{
""id"": 101222,
""title"": ""Hexasweep (part 1): The Solver""
}","15","0",""
"{

Background

While the yearly get-togethers are called user meetings (previously known as conferences), I found that the social setting allowed Dyalog's staff to discuss and develop ideas in a way that would not happen in the office setting of Bramley.

I had a vague idea about an operator that would ease working with value tolerances and ranges. During our ride up Mount Etna, I by chance had the pleasure of sitting next to Geoff Streeter. We started discussing some things, and before long I had my laptop out and we were prototyping a new operator.

I discussed my idea with Nick Nickolov, who told me that being a fan of ⎕CT←0, he has considered to denote tolerant equality. I think we then naturally would want , and , and