Skip to content

Commit

Permalink
init (from darcs)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmchale committed Aug 27, 2022
0 parents commit 72f301b
Show file tree
Hide file tree
Showing 118 changed files with 7,641 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:set -XOverloadedStrings
24 changes: 24 additions & 0 deletions .stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
steps:
- simple_align:
cases: true
top_level_patterns: true
records: true
- imports:
align: global
list_align: after_alias
pad_module_names: true
long_list_align: inline
empty_list_align: inherit
list_padding: 4
separate_lists: true
space_surround: false
- language_pragmas:
style: vertical
align: true
remove_redundant: false

- trailing_whitespace: {}
columns: 180
newline: native
language_extensions: [CPP]
16 changes: 16 additions & 0 deletions ASM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- [ ] floor function: https://stackoverflow.com/a/37573707/11296354
-- check parity: AND with 00010 or w/e
- [ ] note: fused multiply-add etc. for doubles
- [ ] https://disasm.pro/
- [ ] sign by parity: AND with 0x1 to find parity, then use this to set sign bit? lol.
(-1)^n
- [ ] avx512 has: https://www.felixcloutier.com/x86/vexp2pd
- [ ] https://www.felixcloutier.com/x86/f2xm1
- [ ] thence: x^y=s^(y \* (log_2 x))
# Min/max
- [ ] http://web.archive.org/web/20130821015554/http://bob.allegronetwork.com/prog/tricks.html
- [ ] quick absolute value
- [ ] min/max?
- [ ] http://graphics.stanford.edu/~seander/bithacks.html
- [ ] https://stackoverflow.com/questions/227383/how-do-i-programmatically-return-the-max-of-two-integers-without-using-any-compa
- [ ] https://stackoverflow.com/questions/476800/comparing-two-integers-without-any-comparison?noredirect=1&lq=1
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# apple

## 0.1.0.0

Initial release
661 changes: 661 additions & 0 deletions COPYING

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions EXISTENTIAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Notes on existential types:

1. Only introduced by filter, iota (on RHS)

2. Eliminate by pulling out ∃n. int(n) as int(#n). We don't ever need ∃n. int(n)
to check against ∀n. int(n) (say) because we don't allow higher-rank types
(also it wouldn't work).

3. #n unifies with any (universal) type variable as a constant; #n doesn't unify
with 2 (say), ∃n. int(n) shouldn't unify with int(2) (the former being, say,
the result of a filter...)

4. DISPLAY: I think we can restrict so that all #n are on the RHS of the arrow,
then display as ∃n. ...


existential vs. universal:

int(4) checks against ∃n. int(n) BUT it is not an instance of ∀n. int(n)

however, a term of type ∀n. int(n) could be instantiated to type int(4) if
wanted.
term of type ∃n. int(n) does not check against ∀n. int(n)
term of type ∀n. int(n) checks against ∃n. int(n) (can be instantiated etc.)
∃n. int(n) can be used as an argument to a function of type ∀n. int(n) → bool
(instantiate with virtual #n, then #n = n..., treating #n as a constant)

# Python

Note that Python gets this precisely wrong! In Python, an integer can have type
`Any`, and a value of type `Any` can be used as a string.

What *should* happen is that an integer checks against the type ∃a:type. a. Now,
a value of type ∃a:type. a should *not* check against the type string.

HOWEVER, a value of type ∀a:type. a SHOULD check against integer and also
string...
4 changes: 4 additions & 0 deletions IDIOMS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [ ] `+/` and `*/` have SIMD
- [ ] fold-map-reduce and variations
- [ ] https://stackoverflow.com/a/45786422/11296354
- [ ] note ln (simplified)
14 changes: 14 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (C) 2022 Vanessa McHale

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
26 changes: 26 additions & 0 deletions LITERATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- [ ] https://www.lri.fr/~filliatr/ens/compil/x86-64.pdf
- [ ] https://www.cs.princeton.edu/courses/archive/spr16/cos217/lectures/16_MachineLang.pdf
- [ ] https://staffwww.fullcoll.edu/aclifton/cs241/lecture-floating-point-simd.html
- [ ] log https://stackoverflow.com/questions/45785705/logarithm-in-c-and-assembly
- [ ] https://cfallin.org/blog/2022/06/09/cranelift-regalloc2/
- [ ] https://kobzol.github.io/davis/
- [ ] http://asmdebugger.com/
- [ ] https://twitter.com/johncarlosbaez/status/1541812092897861632
- [ ] https://vim.fandom.com/wiki/Folding#Opening_and_closing_folds
- [ ] https://en.wikipedia.org/wiki/Double-precision_floating-point_format

# Haskal
- [ ] https://hackage.haskell.org/package/linearscan-1.0.0/docs/LinearScan.html
- [ ] https://hackage.haskell.org/package/reg-alloc-graph-color

# JIT
- [ ] https://stackoverflow.com/questions/19552158/call-an-absolute-pointer-in-x86-machine-code
- [ ] https://stackoverflow.com/questions/54947302/handling-calls-to-potentially-far-away-ahead-of-time-compiled-functions-from-j
- [ ] https://stackoverflow.com/questions/64852711/how-do-i-call-puts-in-a-jit

# Python?
- [ ] https://github.com/pola-rs/polars/
- [ ] https://docs.python.org/3/extending/extending.html
- [ ] https://numpy.org/doc/stable/reference/c-api/array.html#
- [ ] https://docs.python.org/3/c-api/index.html
- [ ] https://pythonextensionpatterns.readthedocs.io/en/latest/parsing_arguments.html#variable-number-of-arguments
3 changes: 3 additions & 0 deletions LOOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [ ] Loop unrolling
- [ ] Backwards/compare to 0 instead: (`test rax, rax ...`) https://stackoverflow.com/a/13064985
- [ ] https://stackoverflow.com/a/14842140/11296354
4 changes: 4 additions & 0 deletions MEM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [ ] 1: decide when we want to be able to reuse allocations, dispatch that in
type system...
- [ ] liveness analysis (in stmt layer?) -> copy/free should be doable
- [ ] maybe special register type for arrays?
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
HS_SRC := $(shell find src -type f) $(shell find lib -type f) apple.cabal

libapple.so: $(HS_SRC) include/apple.h
cabal build flib:apple -w ghc-9.4.2
cp $$(fd 'libapple\.so$$' dist-newstyle) .

moddeps.svg: $(HS_SRC)
graphmod -i src | dot -Tsvg -o $@

install-lib: libapple.so
cp $^ /usr/local/lib

install:
cabal install -w ghc-9.4.2
strip $$(readlink -f $$(which atc))
strip $$(readlink -f $$(which writeo))
strip $$(readlink -f $$(which arepl))

clean:
make -C pyc clean
rm -rf dist-newstyle tags moddeps.svg *.hp *.prof *.svg *.so
32 changes: 32 additions & 0 deletions POW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Exponentiation with integer exponent:
1. To check parity, `AND` with 0x1 instead of `idiv`

See:

```ats
// Fast integer exponentiation. This performs O(log n) multiplications. This
// function is mostly useful for exponentiation in modular arithmetic, as
// it can overflow.
fun exp {n:nat} .<n>. (x : int, n : int(n)) : int =
case+ x of
| 0 => 0
| x =>>
begin
if n > 0 then
let
var n2 = half(n)
var i2 = n % 2
in
if i2 = 0 then
exp(x * x, n2)
else
let
var y = x * exp(x * x, n2)
in
y
end
end
else
1
end
```
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Apple Array System

## Compiler-As-a-Library

Rather than an environment-based interpreter or a compiler invoked on the
command line and generating object files, Apple generates machine code which can
be used by a JIT compiler or in general.

Thus the same implementation can be used interpreted, compiled, or called from
another language.

## Documentation from Types

Like Haskell's Haddock or Doxygen, one can generate hyperlinked type signatures,
e.g.

```
hypergeometric : Arr (i `Cons` Nil) float -> Arr (j `Cons` Nil) float -> float -> float
```

This saves the author from writing redundant documentation.

Programmatic type inference can be of aid in debugging.

## Dimension As a Functor

This is based on J (and APL?). Looping is replaced by functoriality (map); we
have a family of functors `('n)`

## Linear Memory Allocation

Rather than calling `malloc` to create a new array, arrays

<!-- reuse analysis -->
<!-- no gc etc., comes from array &c. -->

## Special Combinations

Apple takes inspiration from [J's special combinations](https://code.jsoftware.com/wiki/Vocabulary/SpecialCombinations).

## Moving Code vs. Moving Data

> For a computation to take place the data and the program have to be at the
> same point in space-time - this is just physics. You can move the data to the
> program or the program to the data, or both somewhere else. ...
> data movement predominates.
- [Joe Armstrong](https://twitter.com/joeerl/status/1087678726911987712)

## Property Testing

Types act as witnesses, as in [QuickCheck](https://hackage.haskell.org/package/QuickCheck).
115 changes: 115 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
- [ ] Figure out log/exp... eh
- [ ] inspiration: J,Haskell,C?,Remora
- [ ] windows lol
- [ ] apple (array system)
- [ ] serialize (save on disk) REPL states
- [ ] bidirectional type inference (rank-polymorphism aka dimension functor)
- [ ] documentation generated from types
- [ ] "array server" architecture like J? (figure out refcounting, copy-on-write -> efficient polymorphism/(static) reuse analysis?)
- [ ] example `(2&*) "0`
- [ ] idioms... deforestation
- [ ] types... (linear? remora; integer-indexed)
- [x] `.🍎` file extension (`.🍏`)
- [ ] ⍳ (apl iota)
- [ ] remora-like type system
- [ ] ⩪ for filter
- [ ]
- [ ] script f https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols#Latin_letters
- [ ] https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode
- [ ] dfns like k, APL (J)
- [ ] big three: map, reduce, zip (dyadic map)
- [ ] unfold
- [ ] map is naturally functorial, zip then is a bifunctor (etc.) n-functor
over dimension
- [ ] our 'map' is a family of functors... arrays being functorial over
cells
- [ ] mapMaybe hm
- [x] problem: filter (#) (existential types... PITA?)
EXAMPLE: (*2)"0
filt. -> Vec i Bool -> Vec i Int -> ∃n. Vec n Int

- [ ] numpy einstein summation
- [ ] https://ajcr.net/Basic-guide-to-einsum/
- [ ] documentation from types
- [ ] quickcheck!
- [ ] automatic differentiation (pytorch eh)
- [ ] deforestation
- [ ] Note: !-modality is functorial, so we get some polymorphism that way?
# Features
- [ ] allow type signatures in lambdas?
- [ ] mko executable - compile expression into .o file, with some name
- [ ] random number generation
- [ ] lift constants out of loops (precompute)
- [ ] tuples idk.
- [ ] reshape arrays...
- [ ] clz? (count leading zeroes = floor(log) -> digits)
## Syntax
- [ ] https://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode
- [ ] https://www.compart.com/en/unicode/U+1D66
## Optimization
- [ ] `neg` instruction, not `0-`...
- [ ] Back/forward loops (compare to 0 or whatever)
- [ ] Break dependency chains: use e.g. four accumulators per loop cycle when
summing float array (see agner fog)
# Performance
- [ ] `-O2` perhaps (investigate with further pipeline)
- [ ] Modify state (+1) instead of using lazy list to supply e.g. temps
- [ ] Live intervals/linear allocator is stupid as shit
- [ ] need to do backwards/forwards thing and stitch it up at basic block
boundaries
- [ ] entropy: vfmadd231sd could take address directly as argument!
# Modules
- [x] Assembler
- [x] linear register allocator
- [ ] deforestation
# Bugs
- [ ] `gammaln` generates `vaddsd rsp, xmm3, xmm1` lol
- [ ] Pass over to ensure everything is monomorphized
- [ ] `itof (:xs)` - would prefer w/o parens?
- [ ] it would be nice to write `_x%y` instead of `(_x)%y` (parse precedence)
- [ ] x+y-1 parsed as (x + (y - 1))
## Type system
- [ ] Check that bindings are not too polymorphic
- [ ] `LLet` cannot contain functions (lol)
# Checks/Passes
- [ ] Warn if irange or frange will exceed?
- [ ] Sanity check pass to make sure xmm0 doesn't end up target of `movtemp` etc.
# Examples
- [ ] median
- [ ] https://optimized-einsum.readthedocs.io/en/stable/
- [ ] polynomial evaluation
- [ ] modulo
- [ ] http://blog.vmchale.com/article/numba-why
- [ ] https://mathworld.wolfram.com/MotzkinNumber.html
- [ ] perceptual hash
- [ ] elliptic fourier series
- [ ] http://www.sci.utah.edu/~gerig/CS7960-S2010/handouts/Kuhl-Giardina-CGIP1982.pdf
- [ ] Pascal's triangle
- [ ] FFT
- [ ] generating functions
- [ ] continued fractions
- [ ] `+//. y` in J... maybe `/.` takes `∀n. (Arr (n `Cons` Nil)) -> ...`
- [ ] matrix multiplication
- [ ] rearrange: note that I implicitly coerce
`Arr (i `Cons` Nil) (Arr (j `Cons` Nil) a)` into (Arr (i `Cons` j `Cons` Nil) a)
which I guess needs a function (annoying?)
- [ ] my `map` is too underpowered I think... compared to true rank (remora
paper?)
- [ ] could have a matmul builtin lol
- [ ] https://www.labri.fr/perso/nrougier/from-python-to-numpy/
- [ ] neural net!
- [ ] think: inner/outer product, wedge products (?)
- [ ] permutations/indices (determinant...)
- [ ] https://en.wikipedia.org/wiki/Arithmetic–geometric_mean#Complete_elliptic_integral_K(sinα)
- [ ] https://github.com/justin2004/image-processing#image-processing-with-apl
- [ ] http://shvbsle.in/computers-are-fast-but-you-dont-know-it-p1/
- [ ] Python FFI: modify a numpy array or something; regression->matplotlib?
- [ ] SciPy t-test
- [ ] discrete cosine transformation
- [ ] full hypergeometric (analytically extended?)
- [ ] https://www.shamusyoung.com/twentysidedtale/?p=11874
- [ ] ANOVA
- [ ] convolution (image processing)
- [ ] http://www.paulbourke.net/fractals/burnship/
- [ ] kaplan-meier, clopper-pearson?
- [ ] https://forem.julialang.org/inphyt/ann-juliaepi-collaborative-computational-epidemiology-in-julia-19ng
Loading

0 comments on commit 72f301b

Please sign in to comment.