## Truth

Proposition calculus deals with statements and the relation between statements, where each of them can only be in one of two states; $\vdash p \lor \lnot p$. Therefore, when working with finitely many connected propositions, one can algorithmically determine all possible truth values of all atomic and thus connected propositions.

Truth is command-line tool which was written to precisely perform those computations; computing a logical expression’s truth value. Download link: truth.py
A list of all supportet operators can be seen by invoking the tool with a --help flag.
This project was inspired by Albert Menne’s Einführung in die Logik1; the operator syntax used is similar to his, translated to be 7-bit-ASCII-compatible.

Truth can be used to either verify universally true statements, e.g. tertium non datur and a property of the replication, verum sequitur ex quodlibet.

-(p&-p) <-> 1  ,  1 <- p
1 0010   1  1     1 1  0
1 1001   1  1     1 1  1


Though not only absolute truth, but also complete relational equivalence between two expressions can be shown.

(p->q)|(r>-<s) <-> q|(r|s)&-(r&s)|-p
01 0 1 0 0 0   1  00 000 01 000 110
10 0 0 0 0 0   1  00 000 01 000 001
01 1 1 0 0 0   1  11 000 01 000 110
11 1 1 0 0 0   1  11 000 01 000 101
01 0 1 1 1 0   1  01 110 11 100 110
10 0 1 1 1 0   1  01 110 11 100 101
01 1 1 1 1 0   1  11 110 11 100 110
11 1 1 1 1 0   1  11 110 11 100 101
01 0 1 0 1 1   1  01 011 11 001 110
10 0 1 0 1 1   1  01 011 11 001 101
01 1 1 0 1 1   1  11 011 11 001 110
11 1 1 0 1 1   1  11 011 11 001 101
01 0 1 1 0 1   1  00 111 00 111 110
10 0 0 1 0 1   1  00 111 00 111 001
01 1 1 1 0 1   1  11 111 00 111 110
11 1 1 1 0 1   1  11 111 00 111 101

Complete contravalence can also be shown.

-(p/-p>-<0)|p->q<-r >-< p&-q&r
0 0110 1 0 101 01 0  1  001000
0 1101 1 0 110 01 0  1  111000
0 0110 1 0 101 11 0  1  000100
0 1101 1 0 111 11 0  1  100100
0 0110 1 0 101 01 1  1  001001
0 1101 1 0 010 00 1  1  111011
0 0110 1 0 101 11 1  1  000101
0 1101 1 0 111 11 1  1  100101

1Menne, Albert: Einführung in die Logik. Bern: Franke, 1966. (= Dalp-Taschenbücher; 384 D)

Advertisements

## Third Anniversary

Today marks this blog’s third anniversary. To celebrate and take a look back at the year, I have collected a few image highlights.

17500615947440398742637684298448259300459653195179624088723406481656498345927782897306957959023081425157582777952426879442535942327333206022815634243070984075006080698433225695442819778347008.0

## Pi Day MMXVIII

Today it is the fourteenth of March 2018. Today’s date — when written in the M/D/Y format –, 3/14/18, looks close enough to Archimedes’ constant’s decimal representation for it to be the constant’s celebratory day.
As always on Pi Day, I have implemented an algorithm to generate $\pi$, albeit this year’s accuracy is not the greatest (Try it online).

                        typedef double d;typedef long l;l f(l n
){l f=1;while(n>1)f*=n--;return f;}d ne(d v,
l p){d r=1;for(l k=0;k<p;k++)r*=v;return r;}d
ps(d(*c)(l),l i,d x){d s=0;for(l k=0;k<i;k++)s
+=c(k)*       ne(x,        k);return
s;}           d exc         (     l
n){            return       1./f (n)
; } d         exp(d x
)   {         return
ps(exc        ,20,x);}
d G( d         x){return
exp(-x        *x);}d I
(d a,d         b,d g,d
(* f)(d         )){d cs=
0;for( d         x=a;x<=
b;x +=g)         cs+=f(x)
*g;return          cs ;  }          int
main( ) { d          pi_root         =I(
-2.5, 2.5 ,           1e-4,G);      d pi
= pi_root *            pi_root+(0xf&0xf0
) ; printf(             "%c%c%c%c%c%f%c"
,'p','i',                ' ','=',' ',pi
,'\n'                     ) ; }                           

I use various methods of generating $\pi$ throughout the Pi Days; this time I chose to use an improper integral paired with a power series. $\pi$ is calculated using a famous identity involving infinite continuous sums, roots, $e$, statistics and — of course — $\pi$.

$\int\limits_{-\infty}^\infty e^{-x^2}\mathrm{d}x = \sqrt{\pi}$

Furthermore, to compute $e$, the following identity is used.

$\exp{x} = \sum\limits_{n=0}^\infty\frac{x^n}{n!}$

Both formulae are combined, the approximated value of $\sqrt{\pi}$ is squared and $\pi$ is printed to stdout.

You can download this program’s prettified (some call it obfuscated, see above) source code pi.c and also the (nearly, as #include  is not missing so that the compiler does not need to guess my dependencies) equivalent code in a more traditional source layout tpi.c.

Happy Pi Day!