Thursday, October 20, 2005

Prolog - Lecture 1

Prolog:
  • Two types of statements:
    • Rules
    • Propositions
  • File extension: .pl (just like Perl)
  • Periods end statements.
  • Avoid using spaces in code with the "gprolog" interpreter/compiler (GNU Prolog 1.2.16).
  • This compiler is very user-unfriendly.
  • Capital letters are "variables".
  • At the interpreter prompt, type "[X]." to load and compile a file named X.pl. Do not type "[X.pl].".
  • Type "trace." to enable trace mode, which will display the steps done by the interpreter.
  • Type "notrace." to turn off trace mode.
With this file:
likes(jake,chocolate).
likes(jake,apricots).
likes(darcie,licorice).
likes(darcie,apricots).

Output of "likes(X,chocolate).":
X = jake ? ; (it waits for command here:
; to show next solution, a for all solutions, to stop)
no

comma (",") is an "and" operator.
Output of "likes(darcie,X),likes(jake,X).":
X = apricots
yes

----
grandmother(X,Y):-mother(X,Z),mother(Z,Y).
grandmother(X,Y):-mother(X,Z),father(Z,Y).
mother(anna,peter).
mother(anna,clara).
mother(mary,anna).
father(joe,peter).
father(jim,clara).
father(tom,joe).

The "grandmother" statements are a propositions. ":-" means "implies".

grandmother(X,peter).
X = mary ? ;
no

Wednesday, October 19, 2005

Algebraic proof that 2=1

x=y
x^2=xy
x^2-y^2=xy-y^2
(x+y)(x-y)=y(x-y)
x+y=y
2y=y
2=1

Saturday, October 15, 2005

Lost in translation

The software is not equipped for 10 consecutive translations of the same piece of text.
-> Which the software of the interior of 10 witnesses turned the similar partial continuation is not equipped.

I want a new car for Christmas
-> I demand loaded a new automobile for them

Time flows like a river. History repeats. Mind your own business.
-> The operations of the time have taste of a river. Retorts of history its material hardly of the guata of the transactions.

The early bird gets the worm. Time flies when you're having fun. The blind are leading the blind.
-> The bird receives the continuous screw soon. The time flies, if you he have the safeguard. The screen of the light bulb executes the screen of the light bulb.

Thursday, October 13, 2005

Haskell - lecture 7

-- isLower, isUpper etc. are not recognized in WinHugs if the prompt says "Main>" (but it is recognized on startup when the prompt is "Prelude>")
kindOfChar :: Char -> String
kindOfChar c =
if (isLower c)
then "lower"
else if isUpper c
then "upper"
else if isDigit c
then "digit"
else "other"
-- Same function implemented with guards:
kindOfChar2 :: Char -> String
kindOfChar2 c -- Notice that there is no "=" before the guards
| isLower c = "lower"
| isUpper c = "upper"
| isDigit c = "digit"
| otherwise = "other"

-- Acts like the prelude (built-in) function 'take'
myTake :: Int -> [a] -> [a]
myTake 0 list = []
myTake m [] = []
myTake m x:xs =
x : (myTake (m-1) xs)
-- Implementation using "case" expression
-- Internally, this is how Haskell resolves multiple function declarations?
myTake2 :: Int -> [a] -> [a]
myTake2 n list = case (n,list) of
(0, list) -> []
(n, []) -> []
(n, x:xs) -> c : myTake2 (n-1)

-- In Haskell
-- Everything exists at the top level (mutually recursive (?))
-- Basic libraries automatically exist in prelude
-- Type synonym
-- Type classes (Ord, Num, Fractional, ...)
-- Read and Show
-- Pattern findings

Haskell - lecture 6

-- I can't figure out what's going on here.
test1 = (\y -> (-) y 1)
-- test2 = (\y -> (-) y (\x -> x)) -- won't compile
test2 z = (\y -> (-) y (\x -> x)) z
test3 z = \y -> (-) y (\x -> x) z
test2b a b = (\y -> (-) y (\x -> x)) a b
test3b a b = \y -> (-) y (\x -> x) a b

-- Prof implied that Haskell has no random-access arrays;
-- e.g. efficient hashtables cannot be created.

-- Data types in Haskell
-- Lists
-- [l] ++ [3,4], a : b
-- Tuple
-- (0, "abc", 'd', 5.0)
-- Enumerated:
-- data Weekday = Sun | Mon | Tue | Wed | Thu | Fri | Sat
-- Recursively defined types
-- data Tree a = Leaf a | Node (Tree a) (Tree a)
-- Lambda abstractions
-- List comprehensions

-- Declaration order doesn't usually matter, but module imports
-- must come first? Also, function signatures' patterns are
-- checked/matched in the order they appear, every time a
-- function is called. For example, out of the four functions below,
-- the first one is always regardless of the arguments. Even so,
-- note that the arguments must be lists, because in Haskell, all
-- functions with the same name share the same data type
-- signature. Try changing the order to see what happens.
orderTest a b = "a b"
orderTest a [] = "a []"
orderTest [] [] = "[] []"
orderTest (x:xs) (y:ys) = "(x:xs) (y:ys)"

-- Control Constructs
-- Patterns: pattern matching on function signatures is implicit flow control
-- Guards
-- "Where" - creates temporary local variables; example below
-- List comprehensions

-- Finds the roots of ax^2 + bx + c
-- Example: roots 1 5 6 -> (-2.0,-3.0)
roots a b c =
if d < 0 then error "imaginary" else (x1, x2)
where
x1 = (-b + (sqrt d)) / twoa
x2 = (-b - (sqrt d)) / twoa
d = b*b - 4*a*c
twoa = 2*a

Saturday, October 08, 2005

Movie Piracy -- oOoOoOo

Maybe I could make a main blog entry on this sort of thing... although to be honest I don't know very much about how the music & film industries screw real artists. All I know is that a lot of people aren't too happy with how bug business runs things.

What's a hoe

I must have laughed for five minutes. But what is a rake?

Thursday, October 06, 2005

Simplified XML?

?sxml version=1.0?
root-element

-- this is a single-line comment. Single-line comments
an-element attribute1="1.0" attribute2=2.0
child-element attribute3=<=>?!"'&sp;& | attribute4="<=>?!"' &"
another-one attribute5="bla" > example text
> this text is part of the "another one" element
> this text is part of an-element
an-element/ -- closing tag is optional.
-- if present, the XML reader would use it for error-checking

Possible useful & unusual morphemes

  • "standard", "predefined idea" - e.g. "standard second month" = febuary, "standard first day" = Sunday. e.g. infix "o" - owundey (sunday), omunth (a month of the year), owik (a week that begins Sunday); not used with 'the'
  • "generalization" or "scope widening" affix - e.g. je
  • "specialization" or "specific" affix - spe
  • "unit distance or step away" affix - ste
  • "the path toward something" affix - e.g. "homtoo"=the path leading home
  • ...which is distinct from "a path or manner", "wey"
  • "direction along a path or axis" affix
  • "movement along a path or axis" affix - rd

Tuesday, October 04, 2005

Haskell - lecture 5


-- Lambda functions are specified with a backslash.
-- (\x -> x*(x-1)) 4 = 12
-- (\x -> (\y -> ((+) y 1))) 2 3 = 4
-- (\x -> (\y -> ((/) x y))) 10 2 = 5.0
-- (\y -> ((+) y x)) 5 = ERROR - Undefined variable "x"
-- (\x -> (\z -> ((/) z 2)) x) 3 = 1.5
-- (\x -> (\z -> ((*) x z)) x) 3 = 9