Thursday, September 29, 2011

LOGICAL REASONING SYSTEMS - CÁC HỆ THỐNG LÝ LUẬN LOGIC (HỢP LÝ)


10
LOGICAL REASONING SYSTEMS
CÁC HỆ THỐNG LÝ LUẬN LOGIC (HỢP LÝ)

In which we show how to build efficient programs that reason with logic.
Trong phần này chúng tôi sẽ cho thấy làm thế nào để xây dựng được các chương trình hiệu quả, đó là lý luận hợp lý!

10.1 INTRODUCTION
10.1 GIỚI THIỆU

We have explained that it is a good idea to build agents as reasoning systems - systems that explicitly represent and reason with knowledge.
Chúng tôi đã giải thích rằng đó là một ý tưởng tốt để xây dựng các tác nhân theo hệ thống lý luận - hệ thống biểu diễn một cách rõ ràng luận có kiến ​​thức.
+
The main advantage of such systems is a high degree of modularity.
Ưu điểm chính của hệ thống như vậy một mức độ cao của modul hóa.
+
The control structure can be isolated from the knowledge, and each piece of  knowledge can be largely independent of the others.
Cấu trúc điều khiển có thể được phân lập từ kiến thức, mỗi phần kiến thức có thể phần lớn của những kiến thức độc lập khác.


10.4 THEOREM PROV
Theorem provers (also known as automated reasoners) differ from logic programming languages in two ways. First, most logic programming languages only handle Horn clauses, whereas theorem provers accept full first-order logic. Second, Prolog programs intertwine logic and control. The programmer's choice in writing A <= B A C instead of A •£= CA B affects the execution of the program. In theorem provers, the user can write either of these, or another form such as -*B •<= C A ->A, and the results will be exactly the same. Theorem provers still need control information to operate efficiently, but this information is kept distinct from the knowledge base,
rather than being part of the knowledge representation itself. Most of the research in theorem provers is in finding control strategies that are generally useful. In Section 9.6 we covered three generic strategies: unit preference, linear input resolution, and set of support.

Design of a theorem prover

In this section, we describe the theorem prover OTTER (Organized Techniques for Theorem-proving and Effective Research) (McCune, 1992), with particular attention to its control strategy.
In preparing a problem for OTTER, the user must divide the knowledge into four parts:

• A set of clauses known as the set of support (or sos), which defines the important facts about the problem. Every resolution step resolves a member of the set of support against another axiom, so the search is focused on the set of support.
• A set of usable axioms that are outside the set of support. These provide background
knowledge about the problem area. The boundary between what is part of the problem
(and thus in sos) and what is background (and thus in the usable axioms) is up to the user's judgment.
• A set of equations known as rewrites or demodulators. Although demodulators are
equations, they are always applied in the left to right direction. Thus, they define a
canonical form into which all terms will be simplified. For example, the demodulator
x + 0 = x say s that every term of the form x + 0 should be replaced by the term x.
• A set of parameters and clauses that defines the control strategy. In particular, the user specifies a heuristic function to control the search and a filtering function that eliminates some subgoals as uninteresting.

OTTER works by continually resolving an element of the set of support against one of the usable axioms. Unlike Prolog, it uses a form of best-first search. Its heuristic function measures the "weight" of each clause, where lighter clauses are preferred. The exact choice of heuristic is up to the user, but generally, the weight of a clause should be correlated with its size and/or difficulty.

Unit clauses are usually treated as very light, so that the search can be seen as a generalization of the unit preference strategy. At each step, OTTER moves the "lightest" clause in the set of support to the usable list, and adds to the usable list some immediate consequences of resolving the lightest clause with elements of the usable list. OTTER halts when it has found a refutation or when there are no more clauses in the set of support. The algorithm is shown in more detail in
Figure 10.5.

        procedure OTTER(sos, usable)
            inputs: sos, a set of support—clauses defining the problem (a global variable)
                usable, background knowledge potentially relevant to the problem
            repeat
                clause <— the lightest member of sos
                move clause from sos to usable
                PROCESS(INFER(clause, usable), sos)
            until sos - [ ] or a refutation has been found
    ____________________________________________________________________________________
        function INFER(clause, usable) returns clauses
            resolve clause with each member of usable
            return the resulting clauses after applying FILTER
    ____________________________________________________________________________________
        procedure PROCESS(clauses, sos)
            for each clause in clauses do
                clause <- SlMPLIFY(clauses)
                merge identical literals
                discard clause if it is a tautology
                sos <— [clause I sos]
                if clause has no literals then a refutation has been found
                if clause has one literal then look for unit refutation
            end

Figure 10.5 Sketch of the OTTER theorem prover. Heuristic control is applied in the selection of the "lightest" clause, and in the FILTER function that eliminates uninteresting clauses from consideration.

Extending Prolog

An alternative way to build a theorem prover is to start with a Prolog compiler and extend it to get a sound and complete reasoner for full first-order logic. This was the approach taken in the Prolog Technology Theorem Prover, or PTTP (Stickel, 1988). PTTP includes five significant changes to Prolog to restore completeness and expressiveness:

• The occurs check is put back into the unification routine to make it sound.
• The depth-first search is replaced by an iterative deepening search. This makes the search strategy complete and takes only a constant factor more time.
• Negated literals (such as ~^P(x)) are allowed. In the implementation, there are two separate routines, one trying to prove P and one trying to prove -iP.
• A clause with n atoms is stored as n different rules. For example, A -4= B A C would also be stored as -A and as ->C <= B A ->A. This technique, known as locking, means that the current goal need only be unified with the head of each clause but still allows for proper handling of negation.

• Inference is made complete (even for non-Horn clauses) by the addition of the linear input resolution rule: If the current goal unifies with the negation of one of the goals on the stack, then the goal can be considered solved. This is a way of reasoning by contradiction. Suppose we are trying to prove P and that the current goal is ->P. This is equivalent to saying that ->P => P, which entails P

Despite these changes, PTTP retains the features that make Prolog fast. Unifications are still done by modifying variables directly, with unbinding done by unwinding the trail during backtracking. The search strategy is still based on input resolution, meaning that every resolution is against one of the clauses given in the original statement of the problem (rather than a derived clause). This makes it feasible to compile all the clauses in the original statement of the problem.

The main drawback of PTTP is that the user has to relinquish all control over the search for solutions. Each inference rule is used by the system both in its original form and in the contrapositive form. This can lead to unintuitive searches. For example, suppose we had the rule

(f(x, y) =f(a, b)) ^.(X = d)/\(y = b)

As a Prolog rule, this is a reasonable way to prove that two/ terms are equal. But PTTP would also generate the contrapositive:

(x#a) <= (f(x,y)#f(a,b)) A (y = b)

It seems that this is a wasteful way to prove that any two terms x and a are different.

Theorem provers as assistants

So far, we have thought of a reasoning system as an independent agent that has to make decisions and act on its own. Another use of theorem provers is as an assistant, providing advice to, say, a mathematician. In this mode the mathematician acts as a supervisor, mapping out the strategy for determining what to do next and asking the theorem prover to fill in the details. This alleviates the problem of semi-decidability to some extent, because the supervisor can cancel a query and try another approach if the query is taking too much time. A theorem prover can also act as a proof-checker, where the proof is given by a human as a series of fairly large steps; the individual inferences required to show that each step is sound are filled in by the system.

A Socratic reasoner is a theorem prover whose ASK function is incomplete, but which can always arrive at a solution if asked the right series of questions. Thus, Socratic reasoners make good assistants, provided there is a supervisor to make the right series of calls to ASK. ONTIC (McAllester, 1989) is an example of a Socratic reasoning system for mathematics. of an agent—on each cycle, we add the percepts to the knowledge base and run the forward chainer, which chooses an action to perform according to a set of condition-action rules.

Theoretically, we could implement a production system with a theorem prover, using
resolution to do forward chaining over a full first-order knowledge base. A more restricted language, on the other hand, can provide greater efficiency because the branching factor is reduced. The typical production system has these features:

• The system maintains a knowledge base called the working memory. This contains a set of positive literals with no variables.
• The system also maintains a separate rule memory. This contains a set of inference rules, each of the form p\ A pi • • • =>• act\ A act^ • • •, where the /?, are literals, and the act, are actions to take when the pi are all satisfied. Allowable actions are adding and deleting elements from the working memory, and possibly other actions (such as printing a value).
• In each cycle, the system computes the subset of rules whose left-hand side is satisfied by the current contents of the working memory. This is called the match phase.
• The system then decides which of the rules should be executed. This is called the conflict resolution phase.
• The final step in each cycle is to execute the action(s) in the chosen rule(s). This is called the act phase.

Match phase

Unification addresses the problem of matching a pair of literals, where either literal can contain variables. We can use unification in a straightforward way to implement a forward-chaining production system, but this is very inefficient. If there are w elements in working memory and r rules each with n elements in the left-hand side, and solving a problem requires c cycles, then the naive match algorithm must perform wrnc unifications. A simple expert system might have w= 100, r = 200, n = 5, c = 1000, so this is a hundred million unifications. The rete algorithm4 used in the OPS-5 production system was the first to seriously address this problem. The rete algorithm is best explained by example. Suppose we have the following rule memory:


and the following working memory:

{A(1),A(2),B(2),B(3),B(4),C(5)}

The rete algorithm first compiles the rule memory into the network shown in Figure 10.6. In this diagram, the circular nodes represent fetches (not unifications) to working memory. Under node A, the working memory elements A(l) and A(2) are fetched and stored. The square nodes indicate unifications. Of the six possible A x B combinations at the A = B node, only A(2) and B(2) satisfy the unification. Finally, rectangular boxes indicate actions. With the initial working

4
 Rete is Latin for net. It rhymes with treaty.


Figure 10.6 A rete network. Circles represent predicate tests. A square containing, for
example, A=B represents a constraint that the solutions to the A and B tests must be equal.
Rectangles are actions.

memory the "add D" rule is the only one that fires, resulting in the addition of the sentence D(2) to working memory.

One obvious advantage of the rete network is that it eliminates duplication between rules. All three of the rules start with a conjunction of A and B, and the network allows that part to be shared. The second advantage of rete networks is in eliminating duplication over time. Most production systems make only a few changes to the knowledge base on each cycle. This means that most of the tests at cycle t+\ will give the same result as at cycle t. The rete network modifies itself after each addition or deletion, but if there are few changes, then the cost of each update will be small relative to the whole job of maintaining the indexing information. The network
thus represents the saved intermediate state in the process of testing for satisfaction of a set of conjuncts. In this case, adding D(2) will result in the activation of the "add E" rule, but will not have any effect on the rest of the network. Adding or deleting an A, however, will have a bigger effect that needs to be propagated through much of the network.

Conflict resolution phase

Some production systems execute the actions of all rules that pass the match phase. Other production systems treat these rules only as suggestions, and use the conflict resolution phase to decide which of the suggestions to accept. This phase can be thought of as the control strategy. Some of the strategies that have been used are as follows:

• No duplication. Do not execute the same rule on the same arguments twice.
• Recency. Prefer rules that refer to recently created working memory elements.

• Specificity. Prefer rules that are more specific.
5
 For example, the second of these two rules
would be preferred:
Mammal(x) => add Legs(x, 4)
Mammal(x) A Human(x) =>• add Legs(x, 2)
• Operation priority. Prefer actions with higher priority, as specified by some ranking. For example, the second of the following two rules should probably have a higher priority:
ControlPanel(p) A Dusty(p) => Action(Dust(p))
ControlPanel(p) A MeltdownLightOn(p) => Action(Evacuate)

Practical uses of production systems


Forward-chaining production systems formed the foundation of much early work in AI. In par-ticular, the XCON system (originally called Rl (McDermott, 1982)) was built using a production system (rule-based) architecture. XCON contains several thousand rules for designing configura-tions of computer components for customers of the Digital Equipment Corporation. It was one of the first clear commercial successes in the emerging field of expert systems. Many other similar systems have been built using the same underlying technology, which has been implemented
in the general-purpose language Ops-5. A good deal of work has gone into designing match-ing algorithms for production system languages, as we have seen; implementations on parallel hardware have also been attempted (Acharya et al., 1992).
ARCHITECTURES Production systems are also popular in cognitive architectures—that is, models of human reasoning—such as ACT (Anderson, 1983) and SOAR (Laird et al., 1987). In such systems, the "working memory" of the system models human short-term memory, and the productions are part of long-term memory. Both ACT and SOAR have sophisticated mechanisms for conflict resolution, and for saving the results of expensive reasoning in the form of new productions. These can be used to avoid reasoning in future situations (see also Section 21.2).

Wednesday, September 28, 2011

Đùa chút chơi - Trẻ con làm xiếc

Đùa chút chơi - toilet công cộng

'Sao' Transformers nhảy 'bốc lửa'



Là nhân vật chính trong loạt phim Transformers, robot Optimus Prime còn có khả năng nhảy điêu luyện...

Friday, September 23, 2011

Monday, September 19, 2011

BeeLine - Dịch vụ SMS " Số Đẹp "


Thỏa mãn mong ước sở hữu số đẹp để thể hiện chính mình? Không phải tốn nhiều thời gian, không cần thay đổi sim, bạn vẫn có thể chuyển số điện thoại đang dùng sang một số đẹp khác với dịch vụ SMS “Số Đẹp” của Beeline.
Bạn có thể kiểm tra số, biết phí chuyển đổi và tự đổi số điện thoại ở bất cứ đâu, bất cứ khi nào bạn muốn chỉ với 2 thao tác đơn giản:

1.Để kiểm tra số đẹp bạn thích và phí đổi số: soạn “KT_099xxxxxxx” hoặc “KT_0199xxxxxxx” gửi 132
       Để kiểm tra dãy số có các con số bạn thích: soạn “KT_YYY” hoặc “KT_YYYY” gửi 132. Trong đó YYY hoặc YYYY là 3 hay 4 con số bạn thích hiện diện trong số điện thoại đẹp.
2. Để giữ số trước khi đổi: soạn “GS_Số ĐT muốn giữ” gửi 132
-          Mỗi thuê bao được giữ 01 số duy nhất mỗi ngày.
-          Thời gian giữ số tối đa là 60 phút. Sau thời gian này, nếu khách hàng không thực hiện việc nhắn tin đối số, số điện thoại được giữ này sẽ được trả về kho số và thuê bao khác có thể thực hiện việc giữ số.
-          Phí giữ số là 1.000 đồng/lần
-          Phí giữ số được trừ trực tiếp vào tài khoản chính của số điện thoại đề nghị giữ số và chỉ được trừ khi thuê bao thực hiện việc giữ số thành công.
-          Trong trường hợp có nhiều thuê bao cùng giữ một số điện thoại, thuê bao nào có tài khoản chính đủ cho phí giữ số và nhắn tin đến sớm nhất sẽ được quyền giữ số.

3. Để đổi sang số đẹp, soạn “DS_mật khẩu_số ĐT cũ_số ĐT mới” gửi 132.
Để tạo mật khẩu, bấm *117*mật khẩu*mật khẩu# .  (*)
 (*) Để đổi sang số đẹp, thuê bao phải tạo mật khẩu. Mật khẩu bao gồm 4 chữ số. Nếu đã có mật khẩu khi sử dụng dịch vụ khác của Beeline thì thuê bao có thể sử dụng lại mật khẩu đó.
-          Miễn phí các tin nhắn gửi đến 132
-          Các số điện thoại trong tin nhắn phải ở dạng số 099xxxxxxx và 0199xxxxxxx
-          Với mỗi SMS yêu cầu kiểm tra dãy số, thuệ bao sẽ nhận được 10 số điện thoại có các con số mà bạn yêu cầu
-          Mỗi thuê bao có thể gửi tối đa 100 SMS trong một ngày đến 132
 Bạn cũng có thể đến bất cứ Cửa Hàng Uỷ Quyền của Beeline gần nhất để đổi số hoặc gọi đến Trung Tâm Chăm sóc khách hàng của chúng tôi 199 để biết thêm thông tin chi tiết.
 Lưu ý:
-          Thuê bao phải ở trong trạng thái hoạt động và tiền trong tài khoản chính phải đủ cho phí đổi số.
-          Phí đổi số được trừ trực tiếp vào tài khoản chính của số điện thoại cũ thực hiện việc giữ số.
-          Số tiền và thời hạn sử dụng còn lại trong tài khoản chính của số cũ được chuyển hòan toàn sang tài khoản của số điện thoại mới
-          Tiền trong tài khoản thưởng của số cũ sẽ bị xóa khi đổi sang số mới.
4. Danh sách số đẹp: xem tại đây
Thể hiện chính mình với  dịch vụ  SMS “Số Đẹp” của Beeline!

Friday, September 16, 2011

Đọc số cải tiến - đọc được số dài thoòng!

Chương trình đọc số tiền! Code được sưu tầm và tổng hợp tùm lum + cải tiến...
http://www.mediafire.com/file/xaccdpt3s5rlv5r/DocSo.rar

Tuesday, September 13, 2011

Trí tuệ nhân tạo - phân chia dịch sách - nhóm Ân Dung Dũng Trung

Chương 10 : http://www.mediafire.com/file/ae42fpv28bss3dd/Chapter10.pdf

10 Logical Reasoning Systems 297
10.1 Introduction ................................... . 297
10.2 Indexing, Retrieval, and Unification ....................... . 299
Implementing sentences and terms ....................... . 299
Store and fetch .................................. . 299
Table-based indexing .............................. . 300
Tree-based indexing ............................... . 301
The unification algorithm ............................ . 302
10.3 Logic Programming Systems .......................... . 304
The Prolog language ............................... . 304
Implementation ................................. . 305
Compilation of logic programs ......................... . 306
Other logic programming languages ...................... . 308
Advanced control facilities ........................... . 308
10.4 Theorem Provers ................................. . 310
Design of a theorem prover ........................... . 310
Extending Prolog .................................31 1
Theorem provers as assistants .......................... . 312
Practical uses of theorem provers ........................ . 313
10.5 Forward-Chaining Production Systems ......................31 3
Match phase ................................... . 314
Conflict resolution phase ............................ . 315
Practical uses of production systems ...................... . 316
10.6 Frame Systems and Semantic Networks . .................... . 316
Syntax and semantics of semantic networks .................. . 317
Inheritance with exceptions ........................... . 319
Multiple inheritance ............................... . 320
Inheritance and change ............................. . 320
Implementation of semantic networks ...................... . 321
Expressiveness of semantic networks ...................... . 323I Contents __________________________________________________ xix
10.7 Description Logics ................................ . 323
Practical uses of description logics ....................... . 325
10.8 Managing Retractions, Assumptions, and Explanations ............ . 325
10.9 Summary ..................................... . 327
Bibliographical and Historical Notes .......................... . 328
Exercises ........................................ . 332

Dung 1 2
Ân 3 4
Dũng 5 6
Trung 7 8
Ai dịch xong phần của mình trước thì xem tiếp phần 9 và phần bài tập, hoặc Ân sẽ phân công sau!

Công cụ chọn text của FoxitReader!

Thursday, September 8, 2011


Lời:
 Ai cũng muốn có người để yêu, một người yêu trời cho để rồi ai cũng yêu như trò chơi, đầy ruổi may.
Sáng đi cùng người tình thứ nhất, tối mơ về người tình thứ hai, rồi ngày mai sẽ bên ai, ta sẽ bên ai.
Ai cũng tốt cũng đẹp cũng xinh, giờ làm sao chọn đây để ngày sau được vui như ngày qua, mình đã mơ.
trót yêu thầm người tình thứ nhất cứ mơ tìm người tình thứ hai rồi mai chẳng bên ai. đắng cay tình đời.

Là người con gái không giống như đàn ông, đàn ông là thế một trái tim nhưng hai lòng.
Thà anh đừng nói câu yêu em, thà em đừng nói câu yêu anh, rồi anh bước đi theo người ta, đàn ông là thế em không tin ai cũng như vậy đâu.
Tình anh chia sớt đâu chỉ riêng mình em, giờ em đã biết người có yêu như ban đầu.
Đàn ông là thế nay em tin đàn ông chỉ biết tham lam thôi, và em sẽ không yêu một ai vì em đã biết như thế là đàn ông.

Giờ thì anh biết anh đã sai nên mất em.
Em hãy thứ tha dù một lần để từng ngày.
Anh sẽ không đau chẳng buồn sầu vì đợi chờ hình bóng của em người yêu hỡi.

Đàn ông đâu phải không biết yêu không biết thương.
Khi vắng em anh lòng thật buồn buồn thật nhiều.
Anh biết nay anh chẳng còn gì còn một điều,
là mong thấy em được yên vui được hạnh phúc cho dù anh đớn đau...

Gi-ia...
Đêm nay cô đơn tôi lang thang...
em ra đi tôi đây mơ màng...
một sự thật thật phũ phàng...
tình đôi ta giờ đã vỡ tan...
ký ức khi xưa là dĩ vãng...
sự hiểu lầm giờ là một phép mang?...
lỗi lầm rồi em sẽ trót mang...
khi em biết đó chỉ là... gi-ia... chỉ là một người bạn! Come on!

Bởi hiểu lầm mà người giận tôi bỏ đi.
Em vô tình nhìn thấy tôi bước bên một người.
Để rồi em xem tôi như người gian giối.
Chỉ vì thế mà người ra đi bỏ tôi.

Những đêm buồn thật buồn vì không có em.
Căn phòng nhỏ đã vắng đi bóng dáng một người.
Và nhiều đêm em cho tôi phải thức trắng.
Sáng vào quán nặng nề bên ly cà phê.
Trưa lang thang cho quên đi mau tháng ngày.
Chiều dần tàn lòng buồn tôi đi tìm mê say

Để xóa hình bóng nay đứng bên người khác
Một phút lầm lỗi em bỏ rơi tình tôi.
Dù đã nhiều lần nói, người đó là bạn thôi.
Mà em không tin, em vô tình hay cố ý.

Cầu chúc người sẽ êm ấm bên người ấy.
Còn tôi ngồi đây đã có ly rượu cay.
Người nhớ một điều nhé, hãy sống thật lòng đó!
Đừng ở bên người ấy mà cứ nhớ cứ suy nghĩ về ai!

Em mặc áo mới chắc giờ này rất vui,
Mong người đừng quên như chiếc áo ngày xưa ấy,
Dù là phải thay nhưng người đừng bỏ đi,
Để áo cô đơn hao mòn vì năm tháng!

Yêu là như thế, thế mới là biết yêu.
Yêu mà chẳng đau như thế chẳng phải yêu.
Giờ thì hiểu ra yêu là phải thứ tha.
Như là chiếc áo em thay rồi mặc lại.

Ai cũng muốn được một người yêu dễ thương.
Ai cũng muốn được một người yêu thật hiền.
Còn chuyện giàu sang mỗi người một suy nghĩ.
Miễn là yêu nhau đi đến hết cuộc đời...
Tôi cũng có được một người yêu dễ thương.
Nhưng em chỉ được ở những phút ban đầu.
Vì người đổi thay xem tình như chiếc áo.
Áo củ đi rồi em vội vàng em thay.

Em mặc áo mới chắc giờ này rất vui,
mong người đừng quên như chiếc áo ngày xưa ấy,
dù là phải thay nhưng người đừng bỏ đi,
Để áo cô đơn hao mòn vì năm tháng!
Yêu là như thế, thế mới là biết yêu.
yêu mà chẳng đau (yêu) như thế chẳng phải yêu.
Giờ thì hiểu ra yêu là phải thứ tha.
Như là chiếc áo em thay rồi mặc lại.

Gi-ia... I love you... Oh baby... giờ anh có níu kéo
em cũng không trở lại
gờ em biết tình anh
yêu em là mãi mãi, chẳng thể nào phôi phai
Oh baby...

Giờ níu kéo cũng thế không làm em quay trở lại.
Khi em chẳng còn như ngày xưa ấy.
Thì anh mong em...?
Giống như anh đã từng đêm ước mong.

Rồi cũng sẽ có lúc em buồn em quay trở lại
Khi em chẳng còn ai ngoài anh nữa.
Vì anh tin không ai yêu em như là anh đã yêu.
Có nhớ những phút ta gần nhau.

Rồi người tìm kiếm những đắm đuối xa hoa với đời.
Đời nhiều gian giối em biến anh trở thành cuộc chơi
Lao đao trong dòng nước cuốn,
Em ơi em còn ước muốn...?



Tình là lầm lỗi nếu cố
Dù gì đi nữa anh vẫn mong em về cùng anh.
Cho anh bao ngày luyến tiếc.
Em xa anh rồi mới biết
Chẳng còn ai nữa em ơi chính anh là người em yêu.

Tình cờ gặp em khi em đang đi trên con đường khuya phố vắng.

Thật là ngạc nhiên như đang trong phim anh như người điên chẳng biết,
Chẳng biết em đang quay phim đóng vai một cô bé đớn đau

Để trái tim anh đây đớn đau

Ngày tháng đêm trôi anh vẫn nhớ, nhớ em biết không người,
phút ban đầu khó phai dẫu chỉ là nắm tay cũng đủ làm tim ta vụn vỡ.

Lòng trót yêu em nhưng không nói, nói ra rất e ngại.
Bởi em là áng mây, anh chỉ là cỏ cây
Giờ ta không sớm nói yêu chỉ thêm đắng cay...

Người đến đến bên ta, đến những khi em cảm thấy buồn....
Và ta cũng như em , đến bên em khi cần em
vài phút rồi mình cũng sẽ chia rẽ ra mỗi người mỗi hướng

Mình đến bên nhau đến những khi ta cảm thấy cần
vì ai cũng như ai, chẳng ai yêu thương ai hết


Nhiều khi suy nghĩ vẫn vơ
về nhiều người và nghĩ về ta
tình yêu luôn mang ngang trái
khi theo tình thì tình lại đi...
rồi tình đến nhưng chẳng phải yêu
Mà chỉ là tình chút cần nhau
Tìn yêu đôi khi như thế
miễn sao là đừng giối gian nhau

Người đến đến bên ta, đến những khi em cảm thấy buồn
Và ta cũng như em, đến bên em khi cần em
Vài phút rồi mình cũng sẽ chia rẽ ra mỗi người một hướng
...xem nhau như là người tình không bao giờ cưới...
Mình đến đến bên nhau đến bên nhau đến những khi ta cảm thấy cần
Vì ai cũng như ai chẳng ai yêu thương ai hết
Chỉ nhớ là tự tìm đến xong sẽ quên như chẳng quen biết
Ngày sau hai đứa chào nhau xem như không có chuyện gì.

Cuộc tình mình đâu biết trước sẽ tan vỡ.
Dẫu tiếng yêu xưa mình trao vẫn còn đây
Mà người đành quay bưới đi không cần chi
Không một tiếng chia ly bởi vì sao
Thà rằng người hãy nói lên câu biệt ly
Em cứ ra đi...

Giờ còn gì đâu em hỡi khi lìa xa
giối gian chi cho lòng ta thêm quặng đau
Dù ngày nào ta khát khao luôn được yêu
Xin được mãi trao về em những lời yêu
để giờ này không thể yêu như vậy đâu
vì em đã giối gian thật nhiều

Người bước đi lặng lẽ quên ngày tháng xưa còn đó
để trái tim rạn vỡ mang một nỗi đau không ngờ
Biết mình đã có nhau bao ngày tháng
mà sao em không yêu như lời em hứa...
Đừng cố nên tìm kiếm khi tình đã không còn nữa
Người cứ đi về với duyên tình mới kia đang chờ
đến ngày sau có vui hay buồn đau cùng ai tôi xin người mãi mãi
chớ nên quay về...

Ngồi một mình bên ly cà phê đắng
và từng giọt lệ buồn cho tình ta đã dỡ
Từng giọt cà phê rớt cho lòng đau
ngọt ngào rồi chát đắng giống như tình ta
bây giờ chỉ là xót xa.

Người vội vàng ra đi vì sao thế
Để lại giọt lệ buồn cho tình ta tan vỡ
cuột tình người trao giống ly cà phê
người lạnh lùng nỡ đã uống xong rồi đi như trò chơi đã không còn gì

từng giọt cà phê rơi trong màn đêm băng giá
nghe nhói trong tim giọt lệ đang tuôn trào
Chỉ một lần yêu cho ta mang bao khổ đau
em giối gian chi cho tình tan vỡ mau...
người nỡ đành tâm quên đi tình xưa nghĩa củ
em quá ham mê bao vui sướng trong đời
bỏ lại nơi đây con tim đau thương lẽ loi
Đêm vắng cô đơn ly cà phê với tôi


Cuột đời là như thế
ai ai cũng ước ai ai cũng mơ
ai cũng mơ mình sẽ , sẽ yêu được một người tốt hơn
thật lòng mình cũng thế, cũng giống như bao người khác.
Chỉ cần một người yêu đừng giối gian,
vậy mà sao em cho tôi bao say đắm đầy trái ngang.

ngước lên trời hỏi rằng cớ sao?
Cớ sao tình đời nhiều trái ngang?
ngày hôm qua người đi bên ai kia rồi mà giờ đay người đi với tôi
vì sao tình hỡi?

ai cũng muốn có người để yêu, một người yêu trời cho
để rồi ai cũng yêu như trò chơi đầy rủi may
sáng đi cùng người tình thứ nhất tối mơ về người tình thứ hai
ngày mai sẽ bên ai, em sẽ bên ai

ai cũng tốt cũng đẹp cũng xinh
giờ làm sao chọn đây
để ngày sau được vui như ngày qua mình đã mơ.

Trót yêu thầm người tình thứ nhất,
cứ mơ tìm người tình thứ hai
rồi mai chẳng bên ai
đắng cay tình đời

ai cũng muốn có người để yêu một người yêu trời cho
để rồi ai cũng yêu như trò chơi đầy rủi may
sáng đi cùng người tình thứ nhất
tối mơ về người tình thứ hai
ngày mai sẽ bên ai ta sẽ bên ai
ai cũng tốt cũng đẹp cũng xinh
giờ làm sao chọn đây
để ngày sau được vui như ngày qua mình đã mơ

trót yêu thầm người tình thứ nhất
cứ mơ tìm người tình thứ hai
rồi mai chẳng bên ai
đắng cay tình đời

Monday, September 5, 2011

Một số hàm đọc số

C sharp:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Ham_doi_so_thanh_chu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static string str = " ";

        public static string ToString(decimal number)
        {
            string s = number.ToString("#");
            string[] so = new string[] { "không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín" };
            string[] hang = new string[] { "", "nghìn", "triệu", "tỷ" };
            int i, j, donvi, chuc, tram;

            bool booAm = false;
            decimal decS = 0;
            //Tung addnew
            try
            {
                decS = Convert.ToDecimal(s.ToString());
            }
            catch
            {
            }
            if (decS < 0)
            {
                decS = -decS;
                s = decS.ToString();
                booAm = true;
            }
            i = s.Length;
            if (i == 0)
                str = so[0] + str;
            else
            {
                j = 0;
                while (i > 0)
                {
                    donvi = Convert.ToInt32(s.Substring(i - 1, 1));
                    i--;
                    if (i > 0)
                        chuc = Convert.ToInt32(s.Substring(i - 1, 1));
                    else
                        chuc = -1;
                    i--;
                    if (i > 0)
                        tram = Convert.ToInt32(s.Substring(i - 1, 1));
                    else
                        tram = -1;
                    i--;
                    if ((donvi > 0) || (chuc > 0) || (tram > 0) || (j == 3))
                        str = hang[j] + str;
                    j++;
                    if (j > 3) j = 1;
                    if ((donvi == 1) && (chuc > 1))
                        str = "một " + str;
                    else
                    {
                        if ((donvi == 5) && (chuc > 0))
                            str = "lăm " + str;
                        else if (donvi > 0)
                            str = so[donvi] + " " + str;
                    }
                    if (chuc < 0)
                        break;
                    else
                    {
                        if ((chuc == 0) && (donvi > 0)) str = "lẻ " + str;
                        if (chuc == 1) str = "mười " + str;
                        if (chuc > 1) str = so[chuc] + " mươi " + str;
                    }
                    if (tram < 0) break;
                    else
                    {
                        if ((tram > 0) || (chuc > 0) || (donvi > 0)) str = so[tram] + " trăm " + str;
                    }
                    str = " " + str;
                }
            }
            if (booAm) str = "Âm " + str;
            return str;// = str+ "đồng chẵn";

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //textBox2.Text = ToString(decimal.Parse(textBox1.Text));
            textBox2.Text = DocTienBangChu(long.Parse(textBox1.Text)," Đồng");
        }


        private string[] ChuSo = new string[10] { " không", " một", " hai", " ba", " bốn", " năm", " sáu", " bẩy", " tám", " chín" };
        private string[] Tien = new string[6] { "", " nghìn", " triệu", " tỷ", " nghìn tỷ", " triệu tỷ" };
        // Hàm đọc số thành chữ
        public string DocTienBangChu(long SoTien, string strTail)
        {
            int lan, i;
            long so;
            string KetQua = "", tmp = "";
            int[] ViTri = new int[6];
            if (SoTien < 0) return "Số tiền âm !";
            if (SoTien == 0) return "Không đồng !";
            if (SoTien > 0)
            {
                so = SoTien;
            }
            else
            {
                so = -SoTien;
            }
            //Kiểm tra số quá lớn
            if (SoTien > 8999999999999999)
            {
                SoTien = 0;
                return "";
            }
            ViTri[5] = (int)(so / 1000000000000000);
            so = so - long.Parse(ViTri[5].ToString()) * 1000000000000000;
            ViTri[4] = (int)(so / 1000000000000);
            so = so - long.Parse(ViTri[4].ToString()) * +1000000000000;
            ViTri[3] = (int)(so / 1000000000);
            so = so - long.Parse(ViTri[3].ToString()) * 1000000000;
            ViTri[2] = (int)(so / 1000000);
            ViTri[1] = (int)((so % 1000000) / 1000);
            ViTri[0] = (int)(so % 1000);
            if (ViTri[5] > 0)
            {
                lan = 5;
            }
            else if (ViTri[4] > 0)
            {
                lan = 4;
            }
            else if (ViTri[3] > 0)
            {
                lan = 3;
            }
            else if (ViTri[2] > 0)
            {
                lan = 2;
            }
            else if (ViTri[1] > 0)
            {
                lan = 1;
            }
            else
            {
                lan = 0;
            }
            for (i = lan; i >= 0; i--)
            {
                tmp = DocSo3ChuSo(ViTri[i]);
                KetQua += tmp;
                if (ViTri[i] != 0) KetQua += Tien[i];
                if ((i > 0) && (!string.IsNullOrEmpty(tmp))) KetQua += ",";//&& (!string.IsNullOrEmpty(tmp))
            }
            if (KetQua.Substring(KetQua.Length - 1, 1) == ",") KetQua = KetQua.Substring(0, KetQua.Length - 1);
            KetQua = KetQua.Trim() + strTail;
            return KetQua.Substring(0, 1).ToUpper() + KetQua.Substring(1);
        }
        // Hàm đọc số có 3 chữ số
        private string DocSo3ChuSo(int baso)
        {
            int tram, chuc, donvi;
            string KetQua = "";
            tram = (int)(baso / 100);
            chuc = (int)((baso % 100) / 10);
            donvi = baso % 10;
            if ((tram == 0) && (chuc == 0) && (donvi == 0)) return "";
            if (tram != 0)
            {
                KetQua += ChuSo[tram] + " trăm";
                if ((chuc == 0) && (donvi != 0)) KetQua += " linh";
            }
            if ((chuc != 0) && (chuc != 1))
            {
                KetQua += ChuSo[chuc] + " mươi";
                if ((chuc == 0) && (donvi != 0)) KetQua = KetQua + " linh";
            }
            if (chuc == 1) KetQua += " mười";
            switch (donvi)
            {
                case 1:
                    if ((chuc != 0) && (chuc != 1))
                    {
                        KetQua += " mốt";
                    }
                    else
                    {
                        KetQua += ChuSo[donvi];
                    }
                    break;
                case 5:
                    if (chuc == 0)
                    {
                        KetQua += ChuSo[donvi];
                    }
                    else
                    {
                        KetQua += " lăm";
                    }
                    break;
                default:
                    if (donvi != 0)
                    {
                        KetQua += ChuSo[donvi];
                    }
                    break;
            }
            return KetQua;
        }
    }
}
VB:Public Function Number2Text(ByVal sNumber As String) As String

        Dim mLen As Long, i As Long

        Dim mDigit As Long, mTemp As String

        Dim mNumText() As String



        mNumText = Split("không;một;hai;ba;bốn;năm;sáu;bảy;t  ám;chín", ";")

        mLen = Len(sNumber)

        For i = 1 To mLen

            mDigit = Mid(sNumber, i, 1)

            mTemp = mTemp & " " & mNumText(mDigit)

            If (mLen = i) Then Exit For

            Select Case (mLen - i) Mod 9

                Case 0

                    mTemp = mTemp & " tỷ"

                    If Mid(sNumber, i + 1, 3) = "000" Then i = i + 3

                    If Mid(sNumber, i + 1, 3) = "000" Then i = i + 3

                    If Mid(sNumber, i + 1, 3) = "000" Then i = i + 3

                Case 6

                    mTemp = mTemp & " triệu"

                    If Mid(sNumber, i + 1, 3) = "000" Then i = i + 3

                    If Mid(sNumber, i + 1, 3) = "000" Then i = i + 3

                Case 3

                    mTemp = mTemp & " nghìn"

                    If Mid(sNumber, i + 1, 3) = "000" Then i = i + 3

                Case Else

                    Select Case (mLen - i) Mod 3

                        Case 2

                            mTemp = mTemp & " trăm"

                        Case 1

                            mTemp = mTemp & " mươi"

                    End Select

            End Select

        Next

        'Loại bỏ trường hợp x00

        mTemp = Replace(mTemp, "không mươi không", "")

        'Loại bỏ trường hợp 00x

        mTemp = Replace(mTemp, "không mươi ", "linh ")

        'Loại bỏ trường hợp x0, x>=2

        mTemp = Replace(mTemp, "mươi không", "mươi")

        'Fix trường hợp 10

        mTemp = Replace(mTemp, "một mươi", "mười")

        'Fix trường hợp x4, x>=2

        mTemp = Replace(mTemp, "mươi bốn", "mươi tư")

        'Fix trường hợp x04 

        mTemp = Replace(mTemp, "linh bốn", "linh tư")

        'Fix trường hợp x5, x>=2

        mTemp = Replace(mTemp, "mươi năm", "mươi nhăm")

        'Fix trường hợp x1, x>=2

        mTemp = Replace(mTemp, "mươi một", "mươi mốt")

        'Fix trường hợp x15

        mTemp = Replace(mTemp, "mười năm", "mười lăm")

        'Bỏ ký tự space

        mTemp = Trim(mTemp)

        'Ucase ký tự đầu tiên

        Return UCase(Left(mTemp, 1)) & Mid(mTemp, 2)

End Function
				
Crystal:
'Hàm đọc số thành chữ cú pháp Crystal Report
'21.12.2010
'Sưu tầm by tihonphysics

Dim SoInput As String
SoInput=Replace (CStr ({@tongcongtienthanhtoan}),"," ,"" ) 'thay thế dấu phẩy (,) thành khoảng trắng
Dim SoInputTemp As String
SoInputTemp=SoInput

Dim KetQua As String, SoTien As String, Nhom As String, Dich As String
Dim Chu As String, S1 As String, S2 As String, S3 As String
Dim i , j , Vitri , S
Dim Hang, Doc, Dem
Dim KHONG_DONG,SO_LON,TRU,TRAM,MUOI,GIDO,NGANTY,TY,TRIEU,NGAN,DONG,XU
Dim MOT, HAI, BA, BON, NAM, SAU, BAY, TAM, CHIN ,CHAN, LE, MUOIMOT, MUOIMOTT

KHONG_DONG = "không đồng"
SO_LON = "số quá lớn"
TRU = "âm"
TRAM = "trăm"
MUOI = "mười"
GIDO = "gì đó"
NGANTY = "ngàn tỷ"
TY = "tỷ"
TRIEU = "triệu"
NGAN = "ngàn"
DONG = "đồng"
XU = "xu"
MOT = "một"
HAI = "hai"
BA = "ba"
BON = "bốn"
NAM = "năm"
SAU = "sáu"
BAY = "bảy"
TAM = "tám"
CHIN = "chín" 
CHAN = "chẵn"
LE = "lẽ"
MUOIMOT = "mười một"
MUOIMOTT = "mươi mốt" 

If CDbl(SoInput) = 0 Then
   formula = KHONG_DONG
Else
If Abs(CDbl(SoInput)) >= 1000000000000000 Then
   formula = SO_LON
Else
'If CDbl(SoInput) <= 0 Then
'   SoInput = TRU & Space(1)
'End If
SoTien = ToText(Abs(CDbl(SoInput)),"####################0.00")
SoTien = Right(Space(15) & SoTien, 18)
Hang = Array(TRAM, MUOI, GIDO)
Doc = Array(NGANTY, TY, TRIEU, NGAN, DONG, XU)
Dem = Array(MOT, HAI, BA, BON, NAM, SAU, BAY, TAM, CHIN)
For i = 1 To 6
   Nhom = Mid(SoTien, i * 3 - 2, 3)
   If Nhom <> Space(3) Then
   Select Case Nhom
   Case "000"
      If i = 5 Then
         Chu = DONG & Space(1)
      Else
         Chu = Space(0)
      End If
   Case ".00", ",00"
      Chu = CHAN
   Case Else
      S1 = Left(Nhom, 1)
      S2 = Mid(Nhom, 2, 1)
      S3 = Right(Nhom, 1)
      Chu = Space(0)
      Hang(3) = Doc(i)
      For j = 1 To 3
         Dich = Space(0)
         S = Val(Mid(Nhom, j, 1))
         If S > 0 Then
            Dich = Dem(S) & Space(1) & Hang(j) & Space(1)
         End If
   Select Case j
     Case 2
         if S = 1 then Dich = MUOI & Space(1)
         if S = 0 And S3 <> "0" then
            If ((S1 >= "1") And (S1 <= "9")) Or ((S1 = "0") And (i = 4)) Then
            Dich = LE & Space(1)             End If
         end if
      Case 3
         If S = 0 And Nhom <> Space(2) & "0" then Dich = Hang(j) & Space(1)
         If (S = 5 And S2 <> Space(1) And S2 <> "0") then
            Dich = "l" & Mid(Dich, 2)
         End If
   End Select
   Chu = Chu & Dich
      Next j
   End Select
           Vitri = InStr(1, Chu, MUOIMOT, 1)
            'If Vitri > 0 Then Mid(Chu, Vitri, 9) = MUOIMOTT
            KetQua = KetQua & Chu
         End If
      Next i
   End If
End If
Dim x As String
If CDbl(SoInputTemp) <= 0 Then
   x = TRU & Space(1)
   x=UCase(Left(x,1)) & Mid(x,2)
else
   x=""
End If

if x<>"" then
formula = x & KetQua
else
formula=UCase(Left(KetQua, 1)) & Mid(KetQua, 2)
end if