{{ message }}

Instantly share code, notes, and snippets.

# Ryohji Ikebe ryohji

Last active Feb 10, 2021
umoria roff
View roff.c
 static vtype roffbuf; // Line buffer. static char *roffp = roffbuf; // Pointer into line buffer. static int roffpline = 0; // Place to print line now being loaded. static uint8_t count_previous_non_blank_chars(const char *from); // Print out strings, filling up lines as we go. static void roff(const char *p) { uint8_t count; loop:
Last active Nov 7, 2020
not operator in C
View not.md

C 言語の not 演算子には２種類ある。 `~``!`。論理学では `~` を否定で使うことが多いけれど C 言語での論理否定は `!``~` はビットごとの否定。

# ビットごとの否定

```// bitwise-not.c
#include <stdbool.h>

int main() { return ~false; }```
Created May 2, 2020
(A ⇒ B) ∧ (¬A ⇒ C) = (A ∧ B) ∨ (¬A ∧ C)
View gist:8a54bb046555d703a316d418203ce401
 (A ⇒ B) ∧ (¬A ⇒ C) = (¬A ∨ B) ∧ (¬¬A ∨ C) = (¬A ∨ B) ∧ (A ∨ C) = ((¬A ∨ B) ∧ A) ∨ ((¬A ∨ B) ∧ C) = ((¬A ∧ A) ∨ (B ∧ A)) ∨ ((¬A ∧ C) ∨ (B ∧ C)) =
Last active Apr 25, 2020
Make sense of the apparent gibberish in “A Logical Approach to Discrete Math” Ch.0
View apparent-gibberish.md

Every value in array segment `b[1..n]` that is not in `b[i..j]` is in `b[i..j]`.

Let predicate `p(v)` be "`v` is in `b[i..j]`."

``````  (A k: 0<k<=N: ~p(b[k]) -> p(b[k]))
=
(A k: 0<k<=N: ~~p(b[k]) | p(b[k]))
=
(A k: 0<k<=N: p(b[k]) | p(b[k]))
``````
Created Apr 18, 2020
Equational logic syntax
View EqLogic.g4
 grammar EqLogic; predicate : predicate substitution | LPAREN predicate RPAREN | BOOLEAN | ID | NOT predicate | predicate IMPLY predicate | predicate AND predicate
Created Apr 14, 2020

View equational-theorem.kt
 interface Substitution { fun with(vararg ps: Predicate): Predicate } interface Predicate { fun substitute(vararg xs: Symbol): Substitution } data class Symbol(val name: String) : Predicate { override fun toString(): String = name
Created Dec 13, 2019
2 dimensional image processing (filter)
View ImageProcessing.kt
 object ImageProcessing { fun smoothing(stride: Int, buffer: ByteArray): ByteArray = buffer.toIntList() .convolution(stride) .map { (it / 9).toByte() } .toByteArray() fun sharpen(stride: Int, buffer: ByteArray): ByteArray = buffer.toIntList()
Last active Dec 13, 2019
Convert `YUV_420_888` format image (from Android Camera2 API) into Jpeg ByteArray (can be used with BitmapFactory.decodeByteArray)
View converter.kt
 import android.graphics.ImageFormat.NV21 import android.graphics.Rect import android.graphics.YuvImage import android.media.Image import java.io.ByteArrayOutputStream object Converter { fun jpegByteArrayFrom(yuv420_888: Image): ByteArray = yuv420_888.nv21ByteArray
Created Dec 12, 2019
Partial recursive function (#1 to #3) (from "アンダースタンディング　コンピュテーション")
View partial-recursive-function.md

P.211 ～ 212 の部分再帰関数の実装。名前づけで混乱したので整理しなおしてみた。

```# 部品１
def zero
0
end

# 部品２
def increment(n)
n + 1```
Last active Nov 28, 2019
Direct product in Kotlin
View direct-product.kt
 fun Collection>.directProduct(): List> = if (isEmpty()) { listOf() } else { val (head, rest) = first() to drop(1) head.map(::listOf).let { if (rest.isEmpty()) { it } else { rest.directProduct().flatMap { tail -> it.map { h -> h + tail } }