Skip to content

Instantly share code, notes, and snippets.

@hobwekiva
hobwekiva / Reasoning Tools.clj
Last active February 15, 2024 04:13
Reasoning Tools
;; stage :: (name : String) -> (description : String) -> Stage
;; principle :: (name : String) -> (description : String) -> Principle
;; strategy :: (name : String) -> (description : String) -> (parent_principles: List String) -> Strategy
;; tactic :: (name : String) -> (description : String) -> (parent_strategies_and_principles: List String) -> Tactic
; The Principle-Strategy-Tactic axis represents a hierarchical framework for reasoning and problem-solving, moving from abstract, foundational beliefs to concrete, actionable steps.
; **Principles** are the most abstract level, representing foundational beliefs or philosophies that guide reasoning and decision-making across various contexts. They are timeless and universal, providing a conceptual framework from which strategies and tactics can be developed. Principles are not directly actionable but serve as the bedrock for strategic thinking and tactical execution.
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import matplotlib.pyplot as plt
##########################################################
# Generating training and validation data
import geocoder
import geopy.distance
import requests
import time
import json
def now():
from datetime import timezone
import datetime
dt = datetime.datetime.now(timezone.utc)
sealed class StableName[A] extends Serializable
object StableName {
private[this] final class RefInstance[A <: AnyRef](val value: A) extends StableName[A] {
override def clone(): AnyRef = this
override def equals(obj: Any): Boolean = obj match {
case that: RefInstance[_] => that.value eq this.value
case _ => false
}
#include <iostream>
#include <cmath>
#include <vector>
#include <cassert>
#include <memory>
enum NodeOp {
OP_CONST,
OP_ADD,
OP_MUL,
@numba.jit("i4(i4, i4)", nopython=True, nogil=True)
def gcd(a, b):
while True:
if a == 0: return b
if b == 0: return a
if a == b: return a
if b > a:
a, b = a, b % a
else:
a, b = a % b, b
sealed trait Free[+F[_], A]
object Free {
def eval[F[_], A](fa: Free[F, A])(implicit F: Monad[F]): F[A] = {
type State = (Free[F, Any], List[Any => Free[F, Any]])
def go(s: State): F[Either[State, Any]] = s match {
case (current, stack) =>
current match {
case Done(a) =>
stack match {
case Nil =>
///////////////////////////////////////////////////////////////////
// STEP 1 - Evaluation by need monad
///////////////////////////////////////////////////////////////////
import scala.annotation.unchecked.{ uncheckedVariance => uV }
final class Need[+A](private[this] var thunk: Need.Thunk[A @uV]) { A =>
import Need._
def value: A = thunk match {
case Done(x) => x
  1. def hash(a: A): Int makes me sad. What about hashing to 64 bits or SL2 Fp?
  2. def MapHash[A, B: Hash]: Hash[Map[A, B]] is a bit odd. Why not A: Hash?
  3. reflexiveLaw + symmetryLaw + transitivityLaw is too weak for "equality". This defines a general equivalence relationship only.
  4. val AnyEqual: Equal[Any] is worrisome, considering all the resolution bugs!
  5. val DoubleEqual: Equal[Double] should be implemented using java.lang.Double.doubleToRawLongBits.
  6. A combintation of [trait Ord[-A] extends Equal[A]](https://github.com/zio/zi
// This sums up my understanding of
// https://github.com/lampepfl/dotty/issues/9359
// and https://github.com/lampepfl/dotty/issues/8430
// == on AnyVal does not imply singleton type equality
class Test[A](val x: Int) extends AnyVal
def coerce1[A, B](a: A): B = {
val x = new Test[A](1)
val y = new Test[B](1)