- Twelf
- Beluga
- awk
- smtlib2
- C++
- Julia
- Perl
- yosys
- xpath
- fstar
- HOL4
- Nix (language)
Twelf
File extension:
.elf
Comment (single line): Starts with
%
Comment (multi-line): between
%{
and%}
Coverage check
Totality check
Adequacy
%name
ʳ
Not mandatory, but makes twelf output messages more readable.
If %name
is given for a type, names of variables of that type which twelf generates will have the prefix indicated by %name
.
Name starts with an uppercase letter. Usually a single letter would do, though multi-character prefixes are fine too.
For example, with the following definitions,
nat: type.
z: nat.
s: nat -> nat.
plus: nat -> nat -> nat -> type.
plus/z: plus z N N.
plus/s: plus (S N1) N2 (S N3) <- plus N1 N2 N3.
% plus/s: plus N1 N2 N3 -> plus (S N1) N2 (S N3).
Twelf gives:
_ = plus/s (plus/s plus/z).
% _ : {X1:nat -> nat} {X2:nat -> nat} {X3:nat} plus (X1 (X2 z)) X3 (X1 (X2 X3))
% = [X1:nat -> nat] [X2:nat -> nat] [X3:nat] plus/s (plus/s plus/z).
But if we add a %name
for ~nat, like
%name nat N.
It would have been:
_ = plus/s (plus/s plus/z).
% _ : {N1:nat -> nat} {N2:nat -> nat} {N3:nat} plus (N1 (N2 z)) N3 (N1 (N2 N3))
% = [N1:nat -> nat] [N2:nat -> nat] [N3:nat] plus/s (plus/s plus/z).
List of keywords
%. |
%abbrev |
%assert |
%block |
%clause |
%covers |
%define |
%deterministic |
%establish |
%freeze |
%infix |
%prefix |
%postfix |
%mode |
%name |
%prove |
%query |
%querytabled |
%reduces |
%solve |
%subord |
%tabled |
%terminates |
%thaw |
%theorem |
%total |
%trustme |
%unique |
%use |
%worlds |
Emacs mode
As of January 2024, twelf.el file for emacs mode needs some brackets removed. Other than that, it should work right out of the box.
(Got to set twelf-root
variable first.)
First, twelf-server needs to be started: M-x twelf-server
(will display a 'Server OK' message).
C-c C-c
: Load a configuration file- Runs all files in the cfg file
C-c C-s
: Load an elf fileC-c C-d
: Type check a specific declaration
First run the cfg file. Afterwards individual elf files can be run as needed.
Configuration file
All files in a twelf project should be listed in a sources.cfg
files. Those files are compiled in the order in which they are listed.
Misc
- Wiki Twelf: like twelf literate programming.
- Elf: Predecessor of twelf
- Delphin: a research project which built on twelf
- To have unproven assertions (for experimentation purposes), twelf needs to be put to 'unsafe mode'.
Beluga
https://github.com/Beluga-lang/Beluga
- File extension:
.bel
- Comment (single line): Starts with
%
- Pure language
- no IO, exception, reference
- There are no:
- built-in tuples, nat, bool
- polymorphism (theory of beluga is inconsistent with it)
- Based on LF, like twelf.
- Feels very similar to twelf, but has major differences.
- Boxing: Data is embedded into computations with
[ |- stuff ]
. - Data and values live at different levels. So 'boxing' and 'unboxing' needed.
- 'Boxing is necessary to ensure we are working with pure data; unboxing is necessary for inspecting what the data looks like' ʳ
Variables:
Data variables will always be within a box
Program variables will never be within a box
Convention:
- Upper-case letters: data variables
- Lower-case letters: computation/program variables
Emacs mode
Key | Description | elisp function |
---|---|---|
C-c C-c | Compile | 'compile |
C-c C-l | Highlight holes | 'beluga-highlight-holes |
C-c C-x | Run command | 'beluga-run-command |
C-c C-t | Get type | 'beluga-get-type |
C-c C-s | Split hole | 'beluga-split-hole |
C-c C-i | Intro hole | 'beluga-intro-hole |
C-c C-j | Jump hole | 'beluga-hole-jump |
C-c C-p | Get hole info | 'beluga-hole-info |
C-c C-e | Erase holes | 'beluga-erase-holes |
harpoon
- For interactive theorem proving with commands.
- Bundled with beluga.
- https://beluga-lang.readthedocs.io/en/latest/getting-started.html
Example:
$ harpoon --sig hello.bel
## Type Reconstruction begin: hello.bel ##
## Type Reconstruction done: hello.bel ##
Configuring theorem #1
Name of theorem (:quit or empty to finish):
smtlib2
smtlib2 is a format for SAT/SMT solvers like z3.
(declare-const a Bool)
is short for
(define-fun b () Bool)
Julia
https://computationalthinking.mit.edu/Fall24/installation/
General
- Import package:
using pkgname
- Packages for drawing plots:
- plots.jl: https://docs.juliaplots.org/stable/
- PGFPlots backend can be used for plots to be used in latex
- Unicodeplots: plots as text
- plotly: plots for webpages
- https://discourse.julialang.org/t/comparison-of-plotting-packages/99860/2
LatexStrings
can be used to write labels in latex syntax
- plots.jl: https://docs.juliaplots.org/stable/
Package management
- Drop to julia repl and type
]
- Prompt will change to
pkg>
Commands:
- add <pkgname>: installation
yosys
Prompt
In interactive mode:
yosys>
: Entire design selectedyosys*>
: Only a part of design selectedyosys [modname]>
: Entire module namedmodname
selectedyosys [modname]*>
: Only a part of module namedmodname
selected
Commands
shell
: enter shellshow
: make diagram (graphviz) for selected designproc
: translate process blocks to netlistsfsm
:memory
:hierarchy
:cd: alias for ~select -module <modname>
- Can do
cd ..
to back to topmost level ??
- Can do
sta
: perform static timing analysisclean
difflibmap
- check
- flattern
- future
- opt
- techmap
printattrs
- readjson, readverilog, writejson, writeverilog: read, write netlist in different formats
xpath
Resources:
- https://developer.mozilla.org/en-US/docs/Web/XPath/Snippets
- https://www.w3schools.com/xml/xpath_syntax.asp
xmlstarlet is a tool that can handle xpath.
- html can be used as input but it (probably) needs to be xml-like. ie, all tags needs to be closed.
. |
Current node |
.. |
Parent node |
@ |
Specify attribute |
/ |
Directly under current node |
// |
Anywhere under current node |
last |
|
starts-with |
/* 2nd node under root */
/root/node[2]
Examples
- Get all hrefs from an html file:
//@href
xmlstarlet sel -t -v "//@href" ../build/html/blog/index.html
- Extract only the contents of
body
tag:xmllint --xpath '/html/body/node()' input.html
xmlstarlet sel -t -v '/html/body/node()' make4ht-vPSgKS.html
(xmlstarlet removed comments, xmllint didn't)
fstar
Theorem prover.
General
- Low*: A subset of F* that can be compiled down to C (using KaRaMeL)
- Low* is a DSL (shallow) within F*
- Dependent types possible
- F* is turing complete, but in a way that doesn't break consistency.
- ie, infinite recursion possible somehow.
- Proofs often involve using SMT solvers like Z3.
- F* programs are extractable to:
- C
- OCaml
- WASM
- F#
- Comments:
- Multiline:
(* comment *)
- Single-line:
// comment
- Multiline:
- File extension:
.fst
- Each file must be a module, apparently
Emacs mode: fstar-mode.el
- C-c v: Load entire buffer for type checking
Interactive mode:
- C-c C-n: Next line
- C-c C-u: Previous line
HOL4
HOL4 theorem prover: https://hol-theorem-prover.org/cheatsheet.html
File extension: .sml
>>
?rw
: rewrite ?tac1 >> tac2
: applytac1
, then usetac2
on all generated goals- Like
tac1; tac2
in coq
- Like
f $ g
: f (g x)- Right associative function application
- Same as in Haskell
Curry
- A functional-logic programming language.
- Kind of like some aspects of Prolog and Haskell mixed together
lst :: Data a => [a] -> [a]
| _:xs =:= l
lst l = xs
where xs free
The where
clause tells that xs
does not appear in l
(is free in l
) so that the compiler can see that it came out of the blue.
=:=
is an equation invoking unification.
Used KICS2 v3.1 for the above snippet. https://www-ps.informatik.uni-kiel.de/kics2/Manual.pdf
lst [1,2,3]
gave this:
-------------------------------------
Executing with KiCS2 3.1 /all-values:
-------------------------------------
[2,3]
KiCS2 compilation time: 1.21s / elapsed: 0:01.54
KiCS2 compilation time: 1.19s / elapsed: 0:01.48
GHC compilation time: 1.64s / elapsed: 0:02.46
Execution time: 0.00s / elapsed: 0:00.01
Looks like lst []
simply doesn't result in any value instead of giving error as in Haskell:
-------------------------------------
Executing with KiCS2 3.1 /all-values:
-------------------------------------
KiCS2 compilation time: 1.22s / elapsed: 0:02.13
KiCS2 compilation time: 1.16s / elapsed: 0:01.50
GHC compilation time: 1.68s / elapsed: 0:06.56
Execution time: 0.00s / elapsed: 0:00.01
- Default rules
Curry lang
- KICS2: Haskell target
- PAKCS: Prolog target
https://curry.pages.ps.informatik.uni-kiel.de/curry-lang.org/
endAsStart :: Data a => [a] -> Bool
| x:(xs ++ [x]) =:= l
endAsStart l = True
where x,xs free
= False endAsStart'default _
Links:
- https://www-ps.informatik.uni-kiel.de/kics2/Manual.pdf
- https://www.informatik.uni-kiel.de/~curry/tutorial/tutorial.pdf
- https://www.informatik.uni-kiel.de/~pakcs/
- https://old.reddit.com/r/haskell/comments/dn1yx5/curry_is_a_functionallogic_pl_and_heres_a_crazy/
Nix (language)
Language associated with NixOS.
References:
- https://nixos.org/manual/nix/stable/language/index.html
- https://nixos.wiki/wiki/Overview_of_the_Nix_Language
- https://nix.dev/tutorials/first-steps/nix-language
- https://nix.dev/tutorials/nix-language.html
General
Nix is like json with functions.
List elements are separated by a space.
Attribute names needn't be within quotes. Can be though.
Derivation: A build task in nix
a.b.c=1
meansa = {b = {c = 1}}
??Comments: starts with
#
nix-repl
: A repl to try out nix expressions- Useful for just getting familiar with nix
- For ease of use, assignment statements are allowed in nix-repl.
- But proper nix only has expressions.
nix-instantiate
: evaluate a nix filenix-instantiate --eval file.nix
Functions
- Functions take only one argument.
- All functions are anonymous. But they can be assigned to a variable though.
Examples:
x: x+1
: Incrementx: y: x+y
: Addition{x, y}: x+y
: Addition
HTML
Tags:
- object
- embed
SystemC
#include <systemc.h>
sc_in
: input port- Eg:
sc_in<bool>
: boolean input
- Eg:
sc_out
: output portsc_bit
: bit typesc_signal
sc_unit<4>
: 4-bit vectorSC_CTOR
: constructorSC_METHOD
: a block with its sensitivity list- Sensitivity list specified with
sensitive
keyword
- Sensitivity list specified with
SC_MODULE
SC_CTHREAD
sc_time_stamp()
wait()
sc_trace
sc_start
: starts simulation- First call: starts scheduler ˡ
- Subsequent calls: resume scheduler
scmain: like
main()
in C
—
- Convert synthesizable systemc to systemverilog: https://github.com/intel/systemc-compiler
—
Links:
- http://www.asic-world.com/systemc/ports_signals5.html#Example_:_Signal_Binding
- https://www.learnsystemc.com/basic/module
Javascript
Variables are global by default
var val = 1;
console.log("Outer val: " + val);
{console.log("Inner val: " + val);
= 2;
va1 console.log("Inner va1: " + va1);
}console.log("Outer va1: " + va1);
// Outer val: 1
// Inner val: 1
// Inner va1: 2
// Outer va1: 2
In the above snippet, va1
was not limited to the inner scope but became a new global variable.
Concatenation vs addition
+
is string concatenation when one of the operands is a string+
is addition when both operands are numbers
var n1 = 3;
var n2 = 5;
var n1n2 = n1+n2
var s1 = "Hi";
var s2 = "Hello";
var n1s1 = n1+s1;
var s1n1 = s1+n1;
var s1s2 = s1+s2;
console.log("n1+n2 = " + (n1 + n2));
console.log("n1+s1 = " + (n1 + s1));
console.log("s1+n1 = " + (s1 + n1));
console.log("s1+s2 = " + (s1 + s2));
// n1+n2 = 8
// n1+s1 = 3Hi
// s1+n1 = Hi3
// s1+s2 = HiHello
Fortran
https://en.wikibooks.org/wiki/Fortran/Hello_world
General
- Case insensitive keywords
- Single line comments start with
!
—
File extension:
.f90
: modern fortran.f95
: another.f77
: old fortran- Needs
-ffixed-form
in gfortran
- Needs
.for
Compier: gfortran
F77
- First 6 columns of each line are 'reserved for special formatting purposes like statement numbers and continuation markers'
- ie, most lines needs to prefixed by 6 spaces
- Relic of punchcard era where lines had to be of a fixed length??
- Max length of line = 72
- Continuation character in column 6 means next line/punchcard can be used
- https://en.wikibooks.org/wiki/Fortran/Beginning_Fortran
Cobol
- An open source compiler: gnucobol
- https://gnucobol.sourceforge.io/
- gnucobol first compiles cobol into C and then to executable
- File extension: cob, cbl, etc
- File name should be same as
PROGRAM-ID
(case sensitive)
Dbts:
- Copy book
- Indexed I/O