• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-cqtcocoa誰得pythonphprubygameguibathyscaphec翻訳計画中(planning stage)omegatframeworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版b6c821c54efd7859a51266ef4f8af16b74a59a42 (tree)
时间2022-03-28 15:44:27
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Allow N to be fancy blackboard N in LaTeX.

更改概述

差异

--- a/README.txt
+++ b/README.txt
@@ -1,10 +1,3 @@
1-# Frame
2-
3-The frame is a preprocessor written in OCaml which statically links together
4-multiple Cammy expressions. The frame takes any nullary functor which is not
5-standard, and treats it as a file path into a tree of Cammy expressions. Each
6-path is replaced with the expression at that path.
7-
81 # Jelly
92
103 The jelly optimizer is a Cammy-to-Cammy optimizer which uses e-graphs to
--- a/cammy-rpy/cammylib/sexp.py
+++ b/cammy-rpy/cammylib/sexp.py
@@ -46,7 +46,7 @@ class Atom(SExp):
4646 return False
4747
4848 def extractType(self, extractor, formatter, outerPrecedence):
49- return self.symbol
49+ return formatter.formatN if self.symbol == "N" else self.symbol
5050
5151 def buildArrow(self):
5252 return buildUnary(self.symbol)
--- a/cammy-rpy/rename.py
+++ b/cammy-rpy/rename.py
@@ -1,7 +1,7 @@
11 import os
22 import sys
33
4-from cammylib.hive import Hive
4+from cammylib.hive import Hive, MissingAtom
55 from cammylib.sexp import BASIS_ATOMS, BASIS_FUNCTORS
66
77 def comb(dag):
@@ -28,7 +28,10 @@ def main(argv):
2828 suffix = len(fullpath) - 6
2929 assert suffix >= 0, "proven by .endswith() check above"
3030 atom = fullpath[prefix:suffix]
31- hive.load(atom)
31+ try:
32+ hive.load(atom)
33+ except MissingAtom as ma:
34+ print "Couldn't find", ma.atom, "while trying to load", atom
3235 graph = comb(hive.dag)
3336 write = True
3437 if tatom in graph:
--- a/cammy-rpy/repl.py
+++ b/cammy-rpy/repl.py
@@ -13,6 +13,8 @@ from cammylib.types import ConstraintStore, TypeExtractor, TypeFormatter, Unific
1313 LINE_BUFFER_LENGTH = 1024
1414
1515 class PlaintextTypeFormatter(TypeFormatter):
16+ formatN = "N"
17+
1618 def resetsBracketsFor(self, constructor):
1719 return constructor in ("hom", "list")
1820
@@ -40,7 +42,13 @@ def command(hive, code, line):
4042 sexp = sexp.canonicalize(hive)
4143 sexp = jellify(sexp)
4244 arrow = sexp.buildArrow()
43- print arrow.run(T()).asStr()
45+ cs = ConstraintStore()
46+ domain, codomain = arrow.types(cs)
47+ extractor = TypeExtractor(cs, PlaintextTypeFormatter())
48+ if extractor.extract(domain) != "1":
49+ print "Arrow is not an element"
50+ else:
51+ print arrow.run(T()).asStr()
4452
4553 def repl(hive, stdin, stdout):
4654 while True:
--- a/cammy-rpy/weave.py
+++ b/cammy-rpy/weave.py
@@ -13,6 +13,8 @@ from cammylib.types import ConstraintStore, TypeExtractor, TypeFormatter, Unific
1313 SortFileNames = make_timsort_class()
1414
1515 class LatexTypeFormatter(TypeFormatter):
16+ formatN = r"\mathbb{N}"
17+
1618 def resetsBracketsFor(self, constructor):
1719 return constructor == "list"
1820
--- a/hive/complex-graph.cammy
+++ b/hive/complex-graph.cammy
@@ -1,4 +1,4 @@
1-(comp (pair (f/addpair (f/divpair (comp pair/swap f-atan2) (fun/const (f/mulpair f-pi f/2))) (fun/const (comp f/2 f-recip))) (f/mulpair v2/norm (fun/const f/2))) hv2rgb)
1+(comp (pair (f/addpair (f/divpair (comp pair/swap f-atan2) (fun/const (f/mulpair f-pi f/2))) (fun/const (comp f/2 f-recip))) (f/mulpair v2/complex/norm (fun/const f/2))) hv2rgb)
22
33 Map a complex number to a color. The magnitude is mapped to luminance and the
44 angle is mapped to hue.
--- a/hive/fractal-membership.cammy
+++ b/hive/fractal-membership.cammy
@@ -1,9 +1,4 @@
1-(comp
2- (iter-fractal @0 @1)
3- (comp
4- (list/filter v2/c-mag-2)
5- (comp list/len
6- (f/divpair nat/to-f (fun/const (comp @1 nat/to-f))))))
1+(comp (iter-fractal @0 @1) (comp (list/filter v2/complex/mag-2) (comp list/len (f/divpair nat/to-f (fun/const (comp @1 nat/to-f))))))
72
83 Measure the degree to which a fractal diverges. Given a maximum number of
94 steps, we iterate the IFS for a fractal in the complex plane until its
--- a/hive/mat2/mul.cammy
+++ b/hive/mat2/mul.cammy
@@ -1,3 +1,3 @@
1-(comp (fun/tensor id mat2/trans) (pair (mat2/vecpair fst (comp snd fst)) (mat2/vecpair fst (comp snd snd))))
1+(comp (pair/tensor id mat2/trans) (pair (mat2/vecpair fst (comp snd fst)) (mat2/vecpair fst (comp snd snd))))
22
33 Multiply two matrices.
--- a/hive/sdf2/circle.cammy
+++ b/hive/sdf2/circle.cammy
@@ -1 +1,3 @@
1-(f/subpair v2/norm (fun/const f-one))
1+(f/subpair v2/complex/norm (fun/const f-one))
2+
3+
--- a/hive/sdf2/metaballs.cammy
+++ b/hive/sdf2/metaballs.cammy
@@ -1,13 +1,3 @@
1-(f/subpair
2- (fun/apppair
3- (comp @1 (fold
4- (fun/name (fun/const f-zero))
5- (curry
6- (f/addpair
7- (f/divpair (comp (comp fst fst) snd)
8- (comp (comp
9- (pair (comp (comp fst fst) fst) snd)
10- (v2/map2 f/sub)) v2/norm))
11- (fun/apppair (comp fst snd) snd)))))
12- id)
13- (fun/const @0))
1+(f/subpair (fun/apppair (comp @1 (fold (fun/name (fun/const f-zero)) (curry (f/addpair (f/divpair (comp (comp fst fst) snd) (comp (comp (pair (comp (comp fst fst) fst) snd) (v2/map2 f/sub)) v2/complex/norm)) (fun/apppair (comp fst snd) snd))))) id) (fun/const @0))
2+
3+
--- a/hive/v2/burning-ship.cammy
+++ b/hive/v2/burning-ship.cammy
@@ -1 +1,3 @@
1-(curry (comp (pair fst (comp (comp snd (v2/map f/abs)) v2/c-sqr)) (v2/map2 f-add)))
1+(curry (comp (pair fst (comp (comp snd (v2/map f/abs)) v2/complex/sqr)) (v2/map2 f-add)))
2+
3+An iteration of the Burning Ship fractal, a relative of the Mandelbrot set.
--- a/hive/v2/c-sqr.cammy
+++ /dev/null
@@ -1 +0,0 @@
1-(comp fun/dup v2/c-mul)
--- /dev/null
+++ b/hive/v2/complex/about.md
@@ -0,0 +1,3 @@
1+A two-dimensional vector space can be interpreted as a type of complex
2+numbers via the [Cayley–Dickson
3+construction](https://en.wikipedia.org/wiki/Cayley%E2%80%93Dickson_construction).
--- /dev/null
+++ b/hive/v2/complex/i.cammy
@@ -0,0 +1,4 @@
1+(pair f-zero f-one)
2+
3+The imaginary unit $i$. By convention, multiplication by $i$ corresponds to a
4+quarter turn counterclockwise on the Cartesian plane.
--- a/hive/v2/c-mag-2.cammy
+++ b/hive/v2/complex/mag-2.cammy
@@ -1,3 +1,3 @@
1-(f/ltpair v2/norm (fun/const f/2))
1+(f/ltpair v2/complex/norm (fun/const f/2))
22
33 Whether a complex number's magnitude is less than 2.
--- /dev/null
+++ b/hive/v2/complex/norm.cammy
@@ -0,0 +1,3 @@
1+(comp (comp fun/dup f/dot2) f/sqrt-pos)
2+
3+The norm of a complex number.
--- /dev/null
+++ b/hive/v2/complex/sqr.cammy
@@ -0,0 +1,3 @@
1+(comp fun/dup v2/complex/mul)
2+
3+
--- a/hive/v2/c-sqrt.cammy
+++ b/hive/v2/complex/sqrt.cammy
@@ -1,8 +1,10 @@
11 (comp
22 (comp v2/polar
33 (pair
4- (comp fst (comp f-sqrt (case id f-zero)))
4+ (comp fst f/sqrt-pos)
55 (f/divpair snd (fun/const f/2))))
66 (pair
77 (f/mulpair fst (comp snd f-cos))
88 (f/mulpair fst (comp snd f-sin))))
9+
10+The square root of a complex number.
--- a/hive/v2/mandelbrot.cammy
+++ b/hive/v2/mandelbrot.cammy
@@ -1 +1,4 @@
1-(curry (comp (pair fst (comp snd v2/c-sqr)) (v2/map2 f-add)))
1+(curry (comp (pair fst (comp snd v2/complex/sqr)) (v2/map2 f-add)))
2+
3+Perform a Mandelbrot iteration. The Mandelbrot set is composed of points
4+which do not diverge under iteration.
--- a/hive/v2/map.cammy
+++ b/hive/v2/map.cammy
@@ -1 +1,3 @@
11 (pair (comp fst @0) (comp snd @0))
2+
3+Map over both dimensions of a vector simultaneously.
--- a/hive/v2/map2.cammy
+++ b/hive/v2/map2.cammy
@@ -2,3 +2,5 @@
22 (comp (pair (comp fst fst) (comp snd fst)) @0)
33 (comp (pair (comp fst snd) (comp snd snd)) @0))
44
5+
6+Lift a binary operation to a vector space.
--- a/hive/v2/norm.cammy
+++ /dev/null
@@ -1 +0,0 @@
1-(comp (comp (comp fun/dup f/dot2) f-sqrt) (case id f-zero))
--- a/hive/v2/polar.cammy
+++ b/hive/v2/polar.cammy
@@ -1 +1,4 @@
1-(pair v2/norm f-atan2)
1+(pair v2/complex/norm f-atan2)
2+
3+Convert from rectangular coordinates to polar coordinates on the Cartesian
4+plane.
--- a/hive/v2/scale.cammy
+++ b/hive/v2/scale.cammy
@@ -1,3 +1,5 @@
11 (f/mulpair
22 (comp (f/divpair id (fun/const @1)) @0)
33 (fun/const @2))
4+
5+Scale a vector.
--- a/hive/v2/translate.cammy
+++ b/hive/v2/translate.cammy
@@ -1,3 +1,5 @@
11 (f/addpair
22 (comp (f/subpair id (fun/const @1)) @0)
33 (fun/const @2))
4+
5+Translate a vector.