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

BMP Implementation in C — Graphic Primitives

Continuing development of my C bitmap library, I added basic graphic primitives to augment the library’s functionality beyond simply reading and writing bitmaps and manually manipulating individual pixels. Source code can be seen below and also downloaded — bmp.c.
The underlying implementation of the bitmap file format can be seen in my prior post BMP Implementation in C.
Graphic primitives include drawing lines, rectangles, circles, ellipses; rotating, flipping, cropping, resizing and blitting images. A full list of defined graphic primitives can be seen below, together with a short functionality description.

drw
Test image regarding drawing primitives.
/* === DRAWING PRIMITIVES === */
void hline      (image *img, int x0, int x1, int y , int c               ); // draw horizontal line
void vline      (image *img, int x , int y0, int y1, int c               ); // draw vertical line
void line       (image *img, int x0, int y0, int x1, int y1, int c       ); // draw line
void fillrect   (image *img, int x0, int y0, int x1, int y1, int c       ); // draw filled rectangle
void rect       (image *img, int x0, int y0, int x1, int y1, int c       ); // draw rectangle
void fillcircle (image *img, int x , int y , int r , int c               ); // draw filled circle
void circle     (image *img, int x , int y , int r , int t , int c       ); // draw circle (with certain thickness)
void fillellipse(image *img, int x , int y , int rx, int ry, int c       ); // draw filled ellipse
void ellipse    (image *img, int x , int y , int rx, int ry, int t, int c); // draw ellipse (with certain thickness)

/* === TRANSFORMATION PRIMITIVES === */
image *resize   (image *img, int w , int h                                ); // resize an image
image *hflip    (image *img                                               ); // flip horizontally
image *vflip    (image *img                                               ); // flip vertically
image *rrotate  (image *img                                               ); // rotate clockwise
image *lrotate  (image *img                                               ); // rotate counter-clockwise
image *hrotate  (image *img                                               ); // rotate half a revolution
image *crop     (image *img, int x0, int y0, int x1, int y1               ); // crop an image
void   blit     (image *img, image*, int x , int y                        ); // blit an image onto another one
flp
Test image regarding transformation primitives.

Future plans for this library include performance optimizations regarding the ellipse drawing primitives; circle drawing is already optimized as it uses the shape’s symmetry to save computational cost.
Further primitives that may be added include a flood filling functionality as well as the ability to draw irregular polygons.


/* ================================================== *
 *                GENERAL INFORMATION                 *
 * ================================================== *
 * This C program implements functions for handling   *
 * 24-bit images, drawing and parts of the bitmap     *
 * (.bmp) file format. Supported color models include *
 * rgb hsl. There are also functions for mandelbrot   *
 * set fractal rendering.                             *
 *                                                    *
 * Written by Jonathan Frech.                         *
 *                                                    *
 * Edit history:                                      *
 * 23rd, 24th, 27th, 28th, 29th, 30th of June,        *
 * 1st, 2nd, 3rd, 10th, 11th, 13th, 14th, 15th, 16th, *
 * 17th, 18th, 19th, 20th, 25th, 26th, 27th, 29th of  *
 * July 2017, 21st, 22nd, 23rd of March 2018          */

Continue reading