Skip to content

Instantly share code, notes, and snippets.

View pavly-gerges's full-sized avatar
๐Ÿค–
Electrostat Lab.

Pavly Gerges (pavl_g) pavly-gerges

๐Ÿค–
Electrostat Lab.
View GitHub Profile
@pavly-gerges
pavly-gerges / MATH-C.md
Created October 27, 2024 20:02
A mathematical approach to coding in the C programming language.

A Mathematical Approach to coding in the C programming language: Scientific Coding

Preface:

This document is devoted to showing another perspective into programming, which in its surface is the scientific programming, but in its heart and core is really intricate. The complexity is imparted due to of the incorporation of mathematical models and their implementation to the syntatics of the programming language, unlike the practical OOP and Functional paradigms, the FSA model (Finite-Automata Model) is a theoretical model. However, in this short document, I am willing to show some caveats of using the FSM models in both low-level and high-level engineering and delivering a reliable software based on a true science.

Science behind the FSA models

The scientific basis is all emerged from the scientific modelling which is now a forked entity from the scientific philosophy models.

The Finite-State-Automata Models

// The following code examines multiple routines of definining dynamic buffers in C.
// This file fires a runtime malloc() error due to a HEAP corruption error; because of buffer overflow.
// Two maneuvers are introduced to fix this
#include <stdio.h>
#include <stdlib.h>
int main() {
// buffers
@pavly-gerges
pavly-gerges / graph-algo.md
Last active January 21, 2025 17:41
Graph Algorithms I

Graph Algorithms I

Outline:

  • Prerequisite Terminology.
  • Mathematical Structures for representing graphs.
  • Graph traversal algorithms.

Terminology:

  • Directed graph (Or Digraph): a directed path that is composed of vertexes and edges; where edges are essentially represented by directed arcs from a vertex (known as initial vertex) to another vertex (known as terminating or end vertex).
  • Undirected graph (or Multigraph): a non-directed path that is composed of vertexes and edges; where edges are represented by non-directed arcs from a vertex to another vertex (i.e., orientation of arcs are ignored).
  • Adjacency Matrix Representation:

Fix NTFS Mounting problems

Screenshot from 2025-01-24 10-37-41

pavl-x86-machine@pavl-g:~$ sudo mkdir -p /media/pavl-x86-machine/pavl-g && \ # create a directory for mount
                           sudo mount /dev/sdb2 /media/pavl-x86-machine/pavl-g # mount manually
@pavly-gerges
pavly-gerges / dijkstra-formalism.md
Last active January 24, 2025 20:00
A formalization of the Dijkstra's algorithm

Formalization of Dijkstra's Path finder

Natural English Definition:

Overview: The formal definition describes how to compute the shortest path between two vertices in a graph using a systematic approach. It formalizes the idea of Dijkstra's algorithm, where each vertex is processed step-by-step, and distances are updated to find the shortest path from a starting vertex to a terminal vertex.

Graph Representation: The graph consists of a set of vertices (๐‘‰) and edges (๐ธ). Each edge has a weight that represents the distance between two connected vertices. These distances are stored in a matrix (๐‘€), where the value at position $$๐‘š_๐‘–๐‘—$$ represents the distance from vertex ๐‘– to vertex ๐‘—.

The Shortest Path Problem:

Logical Equivalencies

Preface:

The compound propositions $$p$$ and $$q$$ are said to be logically equivalent if $$p \iff q$$ is a tautology (i.e., all their respective enteries in their truth table are congruent). Example, the compound proposition $$p \iff q$$ is logically equivalent to $$(p \implies q) \land (q \implies p)$$; because both the $$p \implies q$$ and $$q \implies p$$ have the same values in their respective enteries, and $$(p \iff q) \iff ((p \implies q) \land (q \implies p))$$ is a tautology.

Note

  • A compound proposition that is always true, no matter what the truth values of the propositional variables that occur in it, is called a tautology.
  • A compound proposition that is always false, no matter what the truth values of the propositional variables that occur in it, is called a contradication.
  • A compound proposition that is neither a tautology nor a contradiction, is a contingency.
@pavly-gerges
pavly-gerges / counting.md
Last active March 1, 2025 13:03
A formal derivation of the permutations as a principle of counting selected objects into sequences.

Derivation of the permutation formula

Important

Theorems required to prove:

image image

Proof Methodologies:

  • Mathematical Induction and Recursion for theorem.01.
  • Direct deductive proof for theorem.02.

Formal derivation of combinations

Important

Theorems required to prove:

image image

Inclusive OR V.S. Exclusive OR: A deeper look

This guide establishes a deeper proof-based look into the inclusive OR (i.e., Logical Disjunction) and the exclusive OR (i.e., Mutually Exclusive or Mutually Imparted Events).

Note

Before getting started, here is a very quick whiteboard into the intuitionism behind the inclusive operations and the exclusive operations, and logical equivalences for each of them; notice the use of the intermediary formulas (e.g., Disjunctive and Conjunctive Normal Forms):

Inclusive OR Exclusive OR
inclusive-or exclusive-or