Technical notes


Using Ubuntu Linux

posted May 1, 2018, 11:54 PM by Le Tuan Anh   [ updated May 29, 2018, 11:47 PM ]

Installing

Basic fixing

When encounter "no package header" error (e.g. fixing wifi as below), use this command to fix it

sudo rm /var/lib/apt/lists/* -vf
Source: https://askubuntu.com/questions/454895/update-manager-bug-encountered-a-section-with-no-package-header

Fixing wifi problem on Ubuntu Linux

Try these commands

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install linux-headers-generic
sudo apt-get install --reinstall bcmwl-kernel-source

Fixing other server problems

[To be updated]

Using Linux

posted May 1, 2018, 11:52 PM by Le Tuan Anh   [ updated May 1, 2018, 11:54 PM ]

Using PostgreSQL

posted Nov 2, 2017, 12:22 AM by Le Tuan Anh   [ updated Nov 2, 2017, 1:21 AM ]

Installation

dnf install postgresql postgresql-server
# setup DB
postgresql-setup --initdb

Start/stop services

systemctl start postgresql

by default, postgres use ident mode (system user account) for login, so there is no default password. To change this, update this file:
/var/lib/pgsql/data/pg_hba.conf

su - postgres
psql
\password
\q


[TO BE UPDATED]

Node.js and Fedora

posted Nov 2, 2017, 12:11 AM by Le Tuan Anh

Prerequisite

dnf install -y nodejs

To make sure everything is working

node --version

Lorem ipsum

Mathematical and scientific symbols

posted Mar 4, 2017, 6:26 AM by Le Tuan Anh   [ updated Mar 4, 2017, 6:26 AM ]

Source: http://www.uefap.com/speaking/symbols/symbols.htm

Common pronunciations (in British English - Gimson,1981) of mathematical and scientific symbols are given in the list below.

(all the pages in this section need a unicode font installed - e.g. Arial Unicode MS, Doulos SIL Unicode, Lucida Sans Unicode - see: The International Phonetic Alphabet in Unicode).

Symbols

+ plus /'plʌs/
- minus /'maɪnəs/
± plus or minus /'plʌs  ɔ:  'maɪnəs/
x multiplied by /'mʌltɪplaɪd baɪ/
/ over; divided by /'əʊvə/ /dɪ'vaɪdəd/
÷ divided /dɪ'vaɪdəd/
= equals /'ɪ:kwəlz/
approximately, similar /ə'prɒksɪmətlɪ/ /'sɪmɪlə tʊ/
equivalent to; identical /ɪk'wɪvələnt tʊ/ /aɪ'dentɪkl tʊ/
≠  not equal to /'nɒt 'iːkwəl tʊ/
greater than /'greɪtə ðən/
less than /'les ðən/
≥  greater than or equal to /'greɪtə ðən ər 'iːkwəl tʊ/
≤  less than or equal to /'les ðən ər' iːkwəl tʊ/
not greater than /'nɒt 'greɪtə ðən/
not less than /'nɒt 'les ðən/
much greater than /'mʌʧ 'greɪtə ðən/
much less than /'mʌʧ 'les ðən/
perpendicular to /pɜːpən'dɪkjʊlə tʊ/
∣∣ parallel to /'pærəlel tʊ/
not equivalent to, not identical to /'nɒt ɪk'wɪvələnt tʊ/ /'nɒt aɪ'dentɪkl tʊ/
≄≉ not similar to /'nɒt 'sɪmɪlə tʊ/
² squared /'skweəd/
³ cubed /'kju:bd/
4 to the fourth;  to the power four /tə ðə 'fɔːθ/ /te ðə 'pɑʊə fɔː/
n  to the n; to the nth; to the power n /tə ðɪ en; tə dɪ enθ; tə ðə pɑʊər en/
root; square root /ru:t/ /skweə ru:t/
cube root /kju:b ru:t/
fourth root  /fɔːθ ruːt/
! factorial /fæk'tɔːrɪəl/
% percent /pə'sent/
infinity /ɪn'fɪnətɪ/
varies as; proportional to /'vɛərɪz/  /prə'pɔːʃənəl/
˙ dot /dɒt/
¨ double dot /dʌbl dɒt/
: is to, ratio of /reɪʃɪəʊ/
f(x) fx f; function /ef/ /'fʌŋkʃən/
f'(x) f dash; derivative  /dæʃ/ /dɪ'rɪvətɪv/
f''x f double-dash; second derivative /'dʌbl dæʃ/ /'sekənd dɪ'rɪvətɪv/
f'''(x) f triple-dash; f treble-dash; third derivative /'trɪpl dæʃ/ / trebl dæʃ/ /θɜ:d dɪ'rɪvətɪv/
f(4) f four; fourth derivative  /fɔːθ dɪ'rɪvətɪv/
partial derivative, delta /paːʃəl dɪ'rɪvətɪv/ /deltə/
integral /'ɪntɪgrəl/
sum /sʌm/
w.r.t. with respect to /wɪð 'rɪspekt/
log log  /lɒg/
logx log to the base 2 of x /lɒg tə ðə beɪs tu: əv eks/
therefore /'ðɛəfɔː/
because /bɪ'kɒz/
gives, leads to, approaches /gɪvz/ /li:dz tʊ/ /əprəʊʧəz/
/ per /pɜ:/
belongs to; a member of;  an element of /bɪ'lɒŋz/ /'membə/ /'elɪmənt/
does not belong to; is not a member of; is not an element of /nɒt bɪ'lɒŋ/ /nɒt ə 'membə/ /nɒt ən 'elɪmənt/
contained in;  a proper subset of /kən'teɪnd ɪn/ /'prɒpə 'sʌbset/
contained in; subset  /'sʌbset/
intersection /'ɪntəsekʃən/
union /'juːnɪən/
for all /fə rɔ:l/
cos x cos x; cosine x /kɒz/
sin x sine x /saɪn/
tan x tangent x /tan/
cosec x cosec x /'kəʊsek/
sinh x shine x /'ʃaɪn/
cosh x cosh x /'kɒʃ/
tanh x than x /θæn/
|x| mod x; modulus x /mɒd/ /'mɒdjʊləs/
degrees Centigrade /dɪ'gri:z 'sentɪgreɪd/
degrees Fahrenheit /dɪ'gri:z 'færənhaɪt/
°K degrees Kelvin /dɪ'gri:z 'kelvɪn/
0°K, –273.15 °C absolute zero /absəlu:t zi:rəʊ/
mm millimetre /'mɪlɪmiːtə/
cm centimetre /'sentɪmiːtə/
cc, cm³ cubic centimetre, centimetre cubed /'kjuːbɪk 'sentɪmiːtə/ /'sentɪmiːtə 'kju:bd/
m metre /'miːtə/
km kilometre /kɪ'lɒmɪtə/
mg milligram /'mɪlɪgræm/
g gram /græm/
kg kilogram /'kɪləgræm/
AC A.C. /eɪ si:/
DC D.C. /di: si:/

Examples

x + 1 x plus one
x -1 x minus one
x ± 1 x plus or minus one
xy x y;  x times y; x multiplied by y
(x — y)(x + y)  x minus y, x plus y
x/y x over y;  x divided by y;
x ÷ y x divided by y
x = 5 x equals 5;  x is equal to 5
x ≈ y x is approximately equal to y
x ≡ y x is equivalent to y;  x is identical with y
x ≠ y x is not equal to y
x > y  x is greater than y
x < y  x is less than y
x ≥ y x is greater than or equal to y
x ≤ y x is less than or equal to y
0 < x < 1 zero is less than x is less than 1; x is greater than zero and less than 1
0 ≤ x ≤ 1 zero is less than or equal to x is less than or equal to 1; x is greater than or equal to zero and less than or equal to 1
x squared
x cubed
x4 x to the fourth;  x to the power four
xn x to the n; x to the nth;  x to the power n
x-n x to the minus n;  x to the power of minus n
root x; square root x; the square root of x
the cube root of x
the fourth root of x
the nth root of x
(x + y)² x plus y all squared
(x/y)² x over y all squared
n! n factorial; factorial n
x% x percent
infinity
x ∝ y x varies as y; x is (directly) proportional to y
x ∝ 1/y x varies as one over y; x is indirectly proportional to y
x dot
x double dot
f(x) fx f of x; the function of x
f'(x) f dash x; the (first) derivative of with respect to x
f''x f double-dash x; the second derivative of f with respect to x
f'''(x) f triple-dash x; f treble-dash x; the third derivative of f with respect to x
f(4) f four x; the fourth derivative of f with respect to x
∂v the partial derivative of v
∂v
∂θ
delta v by delta theta, the partial derivative of v with respect to θ
²v
∂θ²
delta two v by delta theta squared; the second partial derivative of v with respect to θ
dv the derivative of v
dv
d v by d theta, the derivative of v with respect to theta
d²v
²
d 2 v by d theta squared, the second derivative of v with respect to theta, 
integral
integral integral from zero to infinity
sum
the sum from i equals 1 to n
w.r.t. with respect to
logey log to the base e of y; log y to the base e; natural log (of) y
therefore
because
gives, approaches
Δx → 0 delta x approaches zero
lim
Δx→0
the limit as delta x approaches zero, the limit as delta x tends to zero
Lt
Δx→0
the limit as delta x approaches zero, the limit as delta x tends to zero
m/sec metres per second
x ∈ A x belongs to A; x is a member of A; x is an element of A
x∉ A x does not belong to A; x is not  a member of A; x is not an element of A
A⊂ B A is contained in B; A is a proper subset of B
A ⊆ B A is contained in B; A is a subset of B
A ⋂ B A intersection B
A ⋃ B A union B
cos x cos x; cosine x
sin x sine x
tan x tangent x, tan x
cosec x cosec x
sinh x shine x
cosh x cosh x
tanh x than x
|x| mod x; modulus x
18 ℃ eighteen degrees Centigrade
70 ℉ seventy degrees Fahrenheit

Greek alphabet

Α α alpha /'ælfə/
Β β beta /'bi:tə/
Γ γ gamma /'gæmə/
Δ δ delta /'deltə/
Ε ε epsilon /'epsilən/
Ζ ζ zeta /'ziːtə/
Η η eta /'iːtə/
Θ θ theta /'θiːtə/
Ι ι iota /aɪ'əʊtə/
Κ κ kappa /'kæpə/
Λ λ lamda /'læmdə/
Μ μ mu /'mjuː/
Ν ν nu /'njuː/
Ξ ξ xi /'ksaɪ/
Ο ο omicron /'əʊmɪkrən/
Π π pi /'paɪ/
Ρ ρς rho /'rəʊ/
Σ σ sigma /'sɪgmə/
Τ τ tau /'tɑʊ/
Υ υ upsilon /'jʊpsɪlən/
Φ φ phi /'faɪ/
Χ χ chi /'kaɪ/
Ψ ψ psi /'psaɪ/
Ω ω omega /'əʊmɪgə/

Roman alphabet

A a /'eɪ/
B b /'biː/
C c /'siː/
D d /'diː/
E e /'iː/
F f /'ef/
G g /'ʤiː/
H h /'eɪʧ/
I i /'aɪ/
J j /'ʤeɪ/
K k /'keɪ/
L l /'el/
M m /'em/
N n /'en/
O o /'əʊ/
P p /'piː/
Q q /'kjuː/
R r /'ɑː/
S s /'es/
T t /'ti:/
U u /'ju:/
V v /'vi:/
W w /'dʌbljuː/
X x /'eks/
Y y /'waɪ/
Z z /'zed/

Fractions

½ a half /ə 'hɑ:f/
¼ a quarter /ə 'kwɔːtə/
¾ three quarters /θriː 'kwɔːtəz/
a third /ə 'θɜ:d/
two thirds /tu: 'θɜ:dz/
a fifth /ə 'fɪfθ/
two fifths /tu: 'fɪfθs/
three fifths /θriː 'fɪfθs/
four fifths /fɔː 'fɪfθs/
a sixth /ə 'sɪksθ/
five sixths /faɪv 'sɪksθs/
an eighth /ən 'eɪtθ/
three eighths /θriː 'eɪtθs/
five eighths /faɪv 'eɪtθs/
seven eighths /sevən 'eɪtθs/

Decimal Fractions

0.1 nought point one /nɔ:t pɔɪnt wʌn/
0.01 nought point oh one /nɔ:t pɔɪnt əʊ wʌn/
0.0001 nought point oh oh oh one /ten pɔɪnt əʊ əʊ əʊ wʌn/
1.1 one point one /wʌn pɔɪnt wʌn/
1.2 one point two /wʌn pɔɪnt tu:/
1.23 one point two three /wʌn pɔɪnt tu: θri:/
1.0123 one point oh one two three /wʌn pɔɪnt əʊ wʌn tu: θri:/
10.01 ten point oh one /ten pɔɪnt əʊ wʌn/
21.57 twenty-one point five seven /'twentɪ wʌn pɔɪnt  faɪv 'sevən/
2.6666666666.... two point six recurring /tu: pɔɪnt  sɪks rɪ'kɜ:rɪŋ/
2.612361236123... two point six one two three recurring /tu: pɔɪnt  sɪks wʌn tu: θri: rɪ'kɜ:rɪŋ/
2.5 million two point five million /tu: pɔɪnt  faɪv 'mɪljən/

SI Units: Prefixes

10-24 yocto y /'jɒktəʊ/
10-21 zepto z /'zeptəʊ/
10-18 atto a /'atəʊ/
10-15 femto f /'femtəʊ/
10-12 pico p /'pi:kəʊ/
10-9 nano n /'nanəʊ/
10-6 micro µ /'maɪkrəʊ/
10-3 milli m /'mɪlɪ/
10-2 centi c /'sentɪ/
10-1 deci d /'desɪ/
103 kilo k /'kɪləʊ/
106 mega M /'megə/
109 giga G /'gɪgə/
1012 tera T /'terə/
1015 peta P /'petə/
1018 exa E /'eksə/
1021 zetta Z /'zetə/
1024 yotta Y /'jɒtə/
1027 xona X /'zəʊnə/
1030 weka W /'wekə/
1033 vunda V /'vʊndə/

Cardinal Numbers

1 one /wʌn/
2 two /tu:/
3 three /θri:/
4 four /fɔː/
5 five /faɪv/
6 six /sɪks/
7 seven /'sevən/
8 eight /eɪt/
9 nine /naɪn/
10 ten /ten/
11 eleven /ɪ'levən/
12 twelve /twelv/
13 thirteen /θɜ:'ti:n/
14 fourteen /fɔː'ti:n/
15 fifteen /fɪf'ti:n/
16 sixteen /sɪkst'i:n/
17 seventeen /seven'ti:n/
18 eighteen /eɪ'ti:n/
19 nineteen /naɪn'ti:n/
20 twenty /'twentɪ/
21 twenty-one /twentɪ'wʌn/
22 twenty-two /twentɪ'tu:/
23 twenty-three /twentɪ'θri:/
24 twenty-four /twentɪ'fɔː/
25 twenty-five /twentɪ'faɪv/
26 twenty-six /twentɪ'sɪks/
27 twenty-seven /twentɪ'sevən/
28 twenty-eight /twentɪ'eɪt/
29 twenty-nine /twentɪ'naɪn/
30 thirty /'θɜ:tɪ/
40 forty /'fɔːtɪ/
50 fifty /'fɪftɪ/
60 sixty /'sɪkstɪ/
70 seventy /'sevəntɪ/
80 eighty /'eɪtɪ/
90 ninety /'naɪntɪ/
100 a hundred; one hundred /ə 'hʌndrəd/ /wʌn 'hʌndrəd/
101 a hundred and one /ə 'hʌndrəd ən wʌn/
102 a hundred and two /ə 'hʌndrəd ən tu:/
110 a hundred and ten /ə 'hʌndrəd ən ten/
120 a hundred and twenty /ə 'hʌndrəd ən 'twentɪ/
200 two hundred /tu: 'hʌndrəd/
300 three hundred /θri:  'hʌndrəd/
400 four hundred /fɔː 'hʌndrəd/
500 five hundred /faɪv 'hʌndrəd/
600 six hundred /sɪks 'hʌndrəd/
700 seven hundred /'sevən 'hʌndrəd/
800 eight hundred /eɪt 'hʌndrəd/
900 nine hundred /naɪn 'hʌndrəd/
1 000 a thousand, one thousand /ə θ'ɑʊzənd/ /wʌn 'θɑʊzənd/
1 001 a thousand and one /ə 'θɑʊzənd ən wʌn/
1 010 a thousand and ten /ə 'θɑʊzənd ən ten/
1 020 a thousand and twenty /ə 'θɑʊzənd ən 'twentɪ/
1 100 one thousand, one hunded /wʌn 'θɑʊzənd wʌn 'hʌndrəd/
1 101 one thousand, one hundred and one /wʌn 'θɑʊzənd wʌn 'hʌndrəd ən wʌn/
1 110 one thousand, one hundred and ten /wʌn 'θɑʊzənd wʌn 'hʌndrəd ən ten/
9 999 nine thousand, nine hundred and ninety-nine /naɪn 'θɑʊzənd naɪn 'hʌndrəd ən 'naɪntɪ 'naɪn/
10 000 ten thousand /ten 'θɑʊzənd/
15 356 fifteen thousand, three hundred and fifty six /'fɪfti:n 'θɑʊzənd θri: 'hʌndrəd ən 'fɪftɪ sɪks/
100 000 a hundred thousand /ə 'hʌndrəd 'θɑʊzənd/
1 000 000 a million /ə 'mɪljən/
100 000 000 a hundred million /ə 'hʌndrəd 'mɪljən/
1 000 000 000 a billion /ə 'bɪljən/
100 000 000 000 a hundred billion /ə 'hʌndrəd 'bɪljən/
1 000 000 000 000 a trillion /ə 'trɪljən/
1 000 000 000 000 000 a quadrillion /ə kwɒdrɪljən/
1 000 000 000 000 000 000 a quintillian /ə kwɪn'tɪljən/
1 000 000 000 000 000 000 000 a sextillion /ə seks'tɪljən/
1 000 000 000 000 000 000 000 000 a septillion /ə sep'tɪljən/
1 000 000 000 000 000 000 000 000 000 an ocillion /ən ɒkt'tɪljən/
1 000 000 000 000 000 000 000 000 000 000 a nonillion /ə nɒn'ɪljən/
1 000 000 000 000 000 000 000 000 000 000 000 a decillion /ə de'sɪljən/

Ordinal Numbers

1st first /fɜ:st/
2nd second /'sekənd/
3rd third /θɜ:d/
4th fourth /fɔ:θ/
5th fifth /fɪfθ/
6th sixth /sɪksθ/
7th seventh /'sevənθ/
8th eighth /eɪtθ/
9th ninth /naɪnθ/
10th tenth /tenθ/
11th eleventh /ɪ'levənθ/
12th twelfth /'twelfθ/
13th thirteenth /θɜ:'ti:nθ/
14th fourtheenth /fɔː'ti:nθ/
15th fidteenth /fɪf'ti:nθ/   
16th sixteenth /sɪks'ti:nθ/
17th seventeenth /seven'ti:nθ/
18th eighteenth /eɪ'ti:nθ/
19th nineteenth /naɪn'ti:nθ/
20th twentieth /'twentɪəθ/
21st twenty-first /twentɪ'fɜ:st/
22nd twenty-second /twentɪ'sekənd/
23rd twenty-third /twentɪ'θɜ:d/
24th twenty-fourth /twentɪ'fɔ:θ/
25th twenty-fifth /twentɪ'fɪfθ/
26th twenty-sixth /twentɪ'sɪksθ/
27th twenty-seventh /twentɪ'sevənθ/
28th twenty-eighth /twentɪ'eɪtθ/
29th twenty-ninth /twentɪ'naɪnθ/
30th thirtieth /'θɜːtɪəθ/
31st thirty-first /θɜːtɪ'fɜ:st/
40th fortieth /'fɔ:tɪəθ/
50th fiftieth /'fɪftɪəθ/
100th hundredth /'hʌndrədθ/
1 000th thousandth /'θɑʊzəndθ/
1 000 000th miilionth /'mɪljənθ/

Japanese NLP

posted Nov 1, 2016, 1:46 AM by Le Tuan Anh   [ updated Jan 23, 2018, 7:16 PM ]

Encoding

Convert SHIFT-JIS to UTF-8

iconv --f SHIFT-JIS -t UTF-8 input-shift-jis-file.txt -o output-utf8-file.txt

MeCab

See this post.

Japanese Morphological Analyzer with IGO


Package: https://pypi.python.org/pypi/igo-python/0.9.8

Sample code:
>>> from igo.Tagger import Tagger >>> t = Tagger() # use bundled dictionary >>> for m in t.parse(u'すもももももももものうち'): ... print m.surface, m.feature ... すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ も 助詞,係助詞,*,*,*,*,も,モ,モ もも 名詞,一般,*,*,*,*,もも,モモ,モモ も 助詞,係助詞,*,*,*,*,も,モ,モ もも 名詞,一般,*,*,*,*,もも,モモ,モモ の 助詞,連体化,*,*,*,*,の,ノ,ノ うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ >>>
[TO BE UPDATED]

Using Mecab

posted May 11, 2016, 12:07 AM by Le Tuan Anh   [ updated Sep 25, 2017, 2:59 AM ]

Install Mecab

Download these files

  • mecab-0.996
  • mecab-ipadic-2.7.0-20070801

Make (Source: https://sites.google.com/site/casualconc/utility-programs/install-mecab-ruby---detail)

Note: Make sure that you have installed the gcc-c++ package.

sudo dnf install -y gcc-c++

cd mecab-0.996
./configure --with-charset=utf-8
make
make check
sudo make install

cd mecab-ipadic-2.7.0-20070801
./configure --with-charset=utf-8
make
sudo make install

# mecab-python3
sudo pip install mecab-python3
# for python 2
sudo pip install mecab-python

# (See this as well: http://d.hatena.ne.jp/addition/20130405/1365089276)
# Basically, you should edit the file
/etc/ld.so.conf
# and its content should look like this

include ld.so.conf.d/*.conf
/usr/local/lib
# and then run this command:
sudo ldconfig

# Alternatively, you can add mecab's lib folder to LD_LIBRARY_PATH to tell Python where to find the SO file.
# E.g. Add this to your .bashrc file
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/username/local/mecab/lib

# There are two important executable files for mecab which are mecab-config and mecab.
# These two files can be found in mecab installation folder (by default they are at /usr/bin/mecab and /usr/bin/mecab-config)

Using Mecab

# show help
mecab -h

# analyse a file
mecab sentences.txt

# analyse a sentence
mecab "私は猫が大好きだな。"

# tokenization a sentence
mecab -O wakati "私は猫が大好きだな。"

MeCab-python

Read more here: http://aidiary.hatenablog.com/entry/20101121/1290339360)

mecab = MeCab.Tagger("-O wakati")
print(mecab.parse('私は猫が大好きだな。'))

With JACY/ACE


echo "アブラを売る。" | mecab -O wakati | ace -g jacy.dat -1Tf


In case you don't have permission, download the file mecab-all.tar.gz below, and run install_local.sh to run it locally. The complete script can be found in the download section below.

Using Windows

posted Apr 18, 2016, 2:06 AM by Le Tuan Anh   [ updated Aug 10, 2017, 5:56 PM ]

Setup cygwin environment:

  1. Install cygwin from here: https://cygwin.com/install.html
  2. Install packages
    1. gcc (gcc-g++, gcc-core, make, cmake, automake, etc.)
      1. To use cygwin gcc instead of other Windows' gcc, use:
        export CC=/usr/bin/gcc
    2. geany
    3. emacs
    4. python (lxml, libxslt, libxslt-devel, python-libxml2, tkinter, python-dev, pip), same thing for python3
    5. pygtk
    6. openssh, filezilla, wget
    7. sqliteman
    8. To use X display
      1. Install packges xorg-server and xinit
      2. and run startxwin (or  nohup startxwin >/dev/null 2>&1 &)
        1. To show running jobs, use  jobs -l .
      3. Set display: export DISPLAY=:0.0
    9. To run geany using xwin use:  nohup geany --display=:0.0 >/dev/null 2>&1 & 
  3. You can forward X11 to your local machine by doing:
    1. on cygwin, 
      export DISPLAY=:0.0
    2. start Xwin service
      startxwin
    3. use -XY flags to enable X11 forward in SHH:
      ssh -XY [username]@[host]
    4. Profit!
  4. Editing host file at
    C:\Windows\System32\Drivers\etc\hosts
  5. And more

Working with databases

posted Jan 12, 2016, 12:18 AM by Le Tuan Anh   [ updated May 15, 2017, 8:54 PM ]

SQLite

Execute a script file

Executing a script file $sqlite3 dbfile.db < scriptfile.sql
Executing a command echo "SELECT * FROM atable" | sqlite3 dbfile.db

MySQL


Lorem ipsum

PostgreSQL


Lorem ipsum

Predicate Logic

posted Sep 3, 2015, 10:50 PM by Le Tuan Anh   [ updated Aug 16, 2016, 11:34 PM ]

This weird stuff (predicate logic) is for HG2002 and HG4049. I know it can be really tough for you guys. Don't give up, just read the book and solve the problems after each chapter. If you have any problem solving them just email me what you have done and we'll look into it together.

To be able to solve these problems in quizzes or exams here are few hints for you (it's not an exhausted list, feel free to ask me and I'll update this):

  • Read the book:
    • Focus on 309-327 pp, scan through the text and read the examples.
    • Try your best to solve all 10.x problems. You MUST be able to solve 10.1 to 10.4 by yourself to be ready for quizzes and exams. 
  • Skill check list
    • Be able to build truth tables instead of citing them from memory
    • Be able to identify predicates, relations, constant value, variables, quantifiers, etc.
    • Be able to solve any logical sentence

Build truth table

For more information, see this page: https://en.wikipedia.org/wiki/List_of_logic_symbols

 Symbol Usage
How to remember
 Examples
¬ Negation
Reverse the given value
¬True ≡ False
¬False ≡ True
¬(¬False) ≡ True
Conjunction (AND relation)
True iff both given values are true
 
Disjunction (OR relation)
True as long as one given value is true
 
If and only if
True iff both values are the same
(True≡True) is True
  Exclusive disjunction (XOR, Exclusive OR)
True if two given values are different
True ⊕ False = True
True ⊕ True   = False
Implication (if ... then ...)
P Q
Antecedent (P) IMPLIES consequent (Q)

Hypothesis
True iff either we have consequent (Q≡True) or we don't have antedecent (P≡False)  

[TO BE UPDATED]

Derive logical sentences from English sentences 

WARNING: Read Saeed 2003, section 10.3: Translating English into a Logical Metalanguage. This is a MUST if you want to solve question 6 in tutorial 4.

Hints on how to translate from English sentences to predicate logic sentences

  1. Identify variables, predicates and individual constants. Just list them first, then we will form sentences later.
    1. Variables: place-holder elements, can take quantifiers (universal quantifiers every or existential quantifiers some)
    2. Individual constant: A single individual obviously
    3. Predicates: relations, mostly verbs
  2. Combine what we have listed down to form a sentence. Be careful about scoping.

Examples:

Bill sleeps.

 Bill sleeps.
 N  V
 b (invididual)
S( )
predicate

Answer: S(b)

Dogs sleep.

 Dogs sleep.
 N  V
 x
(variable)
S( )
predicate

This is tricky because we have to scope variable d properly here. There are two ways.

1) For every x which is a dog, that particular x sleeps.
If you go this way, you have:

[∀(x): Dog(x)] Sleep(x)

2) For every individual x, if that individual x is a dog, it sleeps.

Answer: ∀x [ Dog(x) → Sleep(x) ]

Choose the types that you feel easier to remember. And don't worry about the predicate name, what I have wrote and the short form is the same. For example [∀(x): D(x)] S(x) is perfectly fine. I prefer the verbose version because when we have to deal with long sentences, it's hard to remember which is which. It's up to you to decide.

Everybody loves HG2002.

Everybody loves HG2002
N  V N
all person
variable
love( )
predicate
HG2002
individual

Use the same approach as above, we have:

[∀(x): Person(x)] Love(x, hg2002) or if you want to show off as a hardcore logician and confuse people, write: [∀(x): P(x)] L(x, h) and it's perfectly fine.

Every dog chases a cat.

There are two interpretations. If you want to express There is a specific cat that every dog chase, you write

Sane Human Hardcore Logicians    
[∃(x): Cat(x)] ∀y ( Dog(y) → Chase(y,x) )
 [∃(x): C(x)] ∀y ( D(y)→ Ch(y,x) )
[∃(x): Cat(x)] [∀y: Dog(y)] Chase(y,x)
 [∃(x): C(x)] [∀y: D(y)] Ch(y,x)

Now it's your turn, what if you want to express For every dog there must be a cat which that particular dog chases. Solve this and show me your answer so I know that you are understood these problems.

Scope Ambiguity

Many students find that this is very difficult to understand. This slide may help.

1-10 of 23