This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed abstract class Expr | |
case class Variable(name: String) extends Expr | |
case class Const(value: Int) extends Expr | |
case class Add(left: Expr, right: Expr) extends Expr | |
case class Mult(left: Expr, right: Expr) extends Expr | |
object Simplify { | |
def one(e: Expr): Expr = e match { | |
case Add(Const(0), r) => r | |
case Add(l, Const(0)) => l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.core.match :only [match]]) | |
(defn evaluate [env [sym x y]] | |
(match [sym] | |
['Number] x | |
['Add] (+ (evaluate env x) (evaluate env y)) | |
['Multiply] (* (evaluate env x) (evaluate env y)) | |
['Variable] (env x))) | |
(def environment {"a" 3, "b" 4, "c" 5}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <memory> | |
#include <set> | |
#include <boost/variant.hpp> | |
#include <format.h> | |
// Selection of symbols | |
/** A set of symbols for printing / parsing formula. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
auto member_of(const std::vector<char> &cs) { | |
return [=](const char c) -> bool { | |
for (const char &x : cs) if (c == x) return true; | |
return false; | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
function getTerms(t, ts) { | |
if (t) { | |
var arr = []; | |
for (var i = 0; i < ts.length; ++i) { | |
arr.push(ts[i][2]); | |
} | |
return [t].concat(arr); | |
} | |
return []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <memory> | |
#include <unordered_set> | |
#include <unordered_map> | |
#include <boost/functional/hash.hpp> | |
class my_class { | |
std::string m_name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang++ -std=c++11 safe_sqrt.cc | |
#include <iostream> | |
#include <cmath> | |
#include <boost/optional.hpp> | |
auto safe_sqrt(double x) -> boost::optional<double> { | |
if (x >= 0.0) | |
return std::sqrt(x); | |
return boost::none; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load "packages/FsLab/FsLab.fsx" | |
open FSharp.Data | |
open XPlot.GoogleCharts | |
let bondUrl = "https://en.wikipedia.org/w/index.php?title=List_of_James_Bond_films&oldid=688916363" | |
type BondProvider = HtmlProvider<"https://en.wikipedia.org/w/index.php?title=List_of_James_Bond_films&oldid=688916363"> | |
let bondWiki = BondProvider.Load(bondUrl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang++ -std=c++11 permutations.cc -o permutations | |
#include <iostream> | |
#include <ostream> | |
#include <set> | |
#include <vector> | |
template<typename T> | |
auto operator<<(std::ostream &os, const std::set<T> &xs) -> std::ostream& { | |
os << '{'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef EXPRESSION_HH__ | |
#define EXPRESSION_HH__ | |
#include <iostream> | |
#include <string> | |
#include <boost/variant.hpp> | |
#include <boost/lexical_cast.hpp> | |
namespace reasoning { |