Skip to content

Instantly share code, notes, and snippets.

data BinaryOp = Plus | Minus | Mult | Div | Pow deriving (Show, Eq)
data UnaryOp = Sin | Cos deriving (Show, Eq)
data Tree a = Empty | BTree (Tree a) BinaryOp (Tree a) | UTree UnaryOp (Tree a) | Const a | Var deriving (Show)
eval :: (Floating a, Eq a) => Tree a -> a -> Maybe a
eval Empty _ = Just 0
eval Var x = Just x
eval (Const a) _ = Just a
eval (BTree left op right) x
| op == Plus = (+) <$> (eval left x) <*> (eval right x)
data BinaryOp = Plus | Minus | Mult | Div | Pow deriving (Show, Eq)
data UnaryOp = Sin | Cos deriving (Show, Eq)
data Tree a = Empty | BTree (Tree a) BinaryOp (Tree a) | UTree UnaryOp (Tree a) | Const a | Var deriving (Show)
eval :: (Floating a) => Tree a -> a -> Maybe a
eval Empty _ = Just 0
eval Var x = Just x
eval (Const a) _ = Just a
eval (BTree left op right) x
| op == Plus = (+) <$> (eval left x) <*> (eval right x)
/* q1 */
SELECT DISTINCT iid
FROM purchase
where pdate='2017-11-24'
ORDER BY iid ASC;
/* q2 */
SELECT DISTINCT cname
FROM customer NATURAL JOIN purchase NATURAL JOIN item
where quantity > 1 and
from itertools import product
best = 0
ta = 0
tb = 0
for a,b in product(range(0,11), range(0,11)):
if (a == 0 and b == 0) or (a == 10 and b == 10):
rate = 0.5
else:
rate = 0.5 * (a/(a+b) + (10-a)/(20-a-b))
if rate > best:
def hinge_loss(w, data, labels):
size = labels.shape
return np.mean(np.maximum(np.zeros(size), np.ones(size) - labels * np.dot(data, w)))
def hinge_loss_deriv(w, data, labels):
deriv_sum = np.zeros()
for x_i, y_i in zip(data, labels):
if (y_i * np.dot(x_i, w)):
deriv_sum -= y_i * x_i
import subprocess
server_args = ['whatsappServer', '8875']
client1_args = ['whatsappClient', 'client1', '127.0.0.1', '8875']
client2_args = ['whatsappClient', 'client2', '127.0.0.1', '8875']
def main():
def is_valid(self):
""" Return whether lines are a valid proof of statement from rules """
# Task 4.6
for i,line in enumerate(self.lines):
# If it doesn't have a rule, we assume it is an assumption
if line.rule is None:
if line.conclusion not in self.statement.assumptions:
return False
else:
continue
""" (c) This file is part of the course
Mathematical Logic through Programming
by Gonczarowski and Nisan.
File name: code/propositions/proofs.py """
from functools import reduce
from propositions.syntax import *
from copy import deepcopy
""" (c) This file is part of the course
Mathematical Logic through Programming
by Gonczarowski and Nisan.
File name: code/propositions/provers.py """
from functools import lru_cache
from propositions.syntax import *
from propositions.proofs import *
def prove_instance(proof, instance):
""" Return a proof of the given instance of the inference rule that proof
proves, via the same inference rules used by proof """
# Task 5.2.1
instantiation_map = dict()
if not instance.is_instance_of(proof.statement, instantiation_map):
return None
my_lines = []
for line in proof.lines:
my_lines.append(