Skip to content

Instantly share code, notes, and snippets.

View StarGazerM's full-sized avatar
🐶

Sun Yihao StarGazerM

🐶
  • Syracuse NY
View GitHub Profile
@StarGazerM
StarGazerM / reason.rs
Created September 22, 2025 04:04
pyreason in ascent
// monophormism from Ascent to PyReason
use ascent::*;
use ordered_float::OrderedFloat;
use std::cmp::Ordering;
// real number intervel
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Intervel(OrderedFloat<f32>, OrderedFloat<f32>);
// the intervel order in PyReason is reversed:
@StarGazerM
StarGazerM / paring.rs
Created January 27, 2025 21:41
parsing/tokensization in datalog
use std::rc::Rc;
use ascent::{ascent, Lattice};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct DepLattice<T> {
val: T,
ord_num: usize,
@StarGazerM
StarGazerM / gemm.cu
Last active January 3, 2025 21:52
GeMM with tiling
/**
* The core of parallel GeMM (General Matrix Multiply) involves dividing the
* matrices into smaller tiles.
*
* Matrix A has dimensions M x K and matrix B has dimensions K x N. We can
* choose smaller tiles for both A and B:
* - tileA has dimensions blockM x blockK
* - tileB has dimensions blockK x blockN
*
* The matrix A can be divided into (M / blockM) x (N / blockK) tiles, and
@StarGazerM
StarGazerM / longest_valid_parenthese.rs
Last active November 26, 2024 15:51
longest valid parentheses in datalog
use ascent::ascent_run;
// Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses
// substring
// .
// Example 1:
// Input: s = "(()"
// Output: 2
// Explanation: The longest valid parentheses substring is "()".
@StarGazerM
StarGazerM / knapsak.rs
Last active November 24, 2024 19:20
knapsack using Ascent
use ascent::*;
use rayon::{iter::Empty, vec};
use std::{borrow::Borrow, collections::{BTreeMap, BTreeSet}, rc::Rc};
type item_type = i32;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Bag {
@StarGazerM
StarGazerM / ascent-prov.rs
Created June 1, 2024 04:44
Why Provenance for Asecnt
use ascent::ascent;
use std::rc::Rc;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum PathProv {
Null,
Cons(i32, Rc<PathProv>),
}
use crate::PathProv::{Null, Cons};
@StarGazerM
StarGazerM / galen-prov.slog
Last active May 28, 2024 17:04
provenance for galen query
(edb ?(isMainClass C))
(edb ?(isSubClass Y))
(edb ?(subProp R S))
(edb ?(subPropChain S1 S2 S))
(edb ?(ali A B))
(edb ?(exists Y R C))
(edb ?(conj Y D1 D2))
@StarGazerM
StarGazerM / tc_rel.rs
Created April 21, 2024 04:59
Implement union find using monotonic aggregation
use rand::{Rng, RngCore};
use std::fs::read_to_string;
use std::io::Write;
use ascent::aggregators::{max, min};
use ascent::lattice::Dual;
use ascent::*;
ascent_par! {
#![measure_rule_times]
// DDISASM_DEBUG_DIR=/workspace/facts/capstone/ DDISASM_GTIRB_MODULE_NAME=libcapstone.so.5 /usr/bin/time -v /workspace/ddisasm/extacted.bin -j 16 -F /workspace/facts/capstone/disassembly/ -D /workspace/facts/debug/
.type input_reg <: symbol
.type reg_nullable <: symbol
.type register <: reg_nullable
.type address <: unsigned
.type operand_code <: unsigned
.type operand_index <: unsigned
.type limit_type <: symbol
@StarGazerM
StarGazerM / stlc.slog
Created January 2, 2024 07:18
Map as a context for Intuitionistic type checking for STLC
; let's write map in slog!
; we need a global relation map which is similar to list
; it has declartion: (map key value map-id)
; base case: empty map
(foo1 (empty-map 0))
; recursive case: map with one more key-value pair
(foo2 (map 2 4 (map 1 2 (empty-map 0))))